1 package com.sun.org.apache.regexp.internal; 2 3 59 60 import com.sun.org.apache.regexp.internal.RECompiler; 61 import com.sun.org.apache.regexp.internal.RESyntaxException; 62 63 100 public class recompile 101 { 102 106 static public void _main(String [] arg) 107 { 108 RECompiler r = new RECompiler(); 110 111 if (arg.length <= 0 || arg.length % 2 != 0) 113 { 114 System.out.println("Usage: recompile <patternname> <pattern>"); 115 System.exit(0); 116 } 117 118 for (int i = 0; i < arg.length; i += 2) 120 { 121 try 122 { 123 String name = arg[i]; 125 String pattern = arg[i+1]; 126 String instructions = name + "PatternInstructions"; 127 128 System.out.print("\n // Pre-compiled regular expression '" + pattern + "'\n" 130 + " private static char[] " + instructions + " = \n {"); 131 132 REProgram program = r.compile(pattern); 134 135 int numColumns = 7; 137 138 char[] p = program.getInstructions(); 140 for (int j = 0; j < p.length; j++) 141 { 142 if ((j % numColumns) == 0) 144 { 145 System.out.print("\n "); 146 } 147 148 String hex = Integer.toHexString(p[j]); 150 while (hex.length() < 4) 151 { 152 hex = "0" + hex; 153 } 154 System.out.print("0x" + hex + ", "); 155 } 156 157 System.out.println("\n };"); 159 System.out.println("\n private static RE " + name + "Pattern = new RE(new REProgram(" + instructions + "));"); 160 } 161 catch (RESyntaxException e) 162 { 163 System.out.println("Syntax error in expression \"" + arg[i] + "\": " + e.toString()); 164 } 165 catch (Exception e) 166 { 167 System.out.println("Unexpected exception: " + e.toString()); 168 } 169 catch (Error e) 170 { 171 System.out.println("Internal error: " + e.toString()); 172 } 173 } 174 } 175 } 176 | Popular Tags |