1.1 --- a/src/com/sun/org/apache/regexp/internal/recompile.java Sat Oct 24 16:18:47 2020 +0800 1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 1.3 @@ -1,137 +0,0 @@ 1.4 -/* 1.5 - * reserved comment block 1.6 - * DO NOT REMOVE OR ALTER! 1.7 - */ 1.8 -/* 1.9 - * Copyright 1999-2004 The Apache Software Foundation. 1.10 - * 1.11 - * Licensed under the Apache License, Version 2.0 (the "License"); 1.12 - * you may not use this file except in compliance with the License. 1.13 - * You may obtain a copy of the License at 1.14 - * 1.15 - * http://www.apache.org/licenses/LICENSE-2.0 1.16 - * 1.17 - * Unless required by applicable law or agreed to in writing, software 1.18 - * distributed under the License is distributed on an "AS IS" BASIS, 1.19 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1.20 - * See the License for the specific language governing permissions and 1.21 - * limitations under the License. 1.22 - */ 1.23 - 1.24 -package com.sun.org.apache.regexp.internal; 1.25 - 1.26 -import com.sun.org.apache.regexp.internal.RECompiler; 1.27 -import com.sun.org.apache.regexp.internal.RESyntaxException; 1.28 - 1.29 -/** 1.30 - * 'recompile' is a command line tool that pre-compiles one or more regular expressions 1.31 - * for use with the regular expression matcher class 'RE'. For example, the command 1.32 - * "java recompile a*b" produces output like this: 1.33 - * 1.34 - * <pre> 1.35 - * 1.36 - * // Pre-compiled regular expression "a*b" 1.37 - * char[] re1Instructions = 1.38 - * { 1.39 - * 0x007c, 0x0000, 0x001a, 0x007c, 0x0000, 0x000d, 0x0041, 1.40 - * 0x0001, 0x0004, 0x0061, 0x007c, 0x0000, 0x0003, 0x0047, 1.41 - * 0x0000, 0xfff6, 0x007c, 0x0000, 0x0003, 0x004e, 0x0000, 1.42 - * 0x0003, 0x0041, 0x0001, 0x0004, 0x0062, 0x0045, 0x0000, 1.43 - * 0x0000, 1.44 - * }; 1.45 - * 1.46 - * REProgram re1 = new REProgram(re1Instructions); 1.47 - * 1.48 - * </pre> 1.49 - * 1.50 - * By pasting this output into your code, you can construct a regular expression matcher 1.51 - * (RE) object directly from the pre-compiled data (the character array re1), thus avoiding 1.52 - * the overhead of compiling the expression at runtime. For example: 1.53 - * 1.54 - * <pre> 1.55 - * 1.56 - * RE r = new RE(re1); 1.57 - * 1.58 - * </pre> 1.59 - * 1.60 - * @see RE 1.61 - * @see RECompiler 1.62 - * 1.63 - * @author <a href="mailto:jonl@muppetlabs.com">Jonathan Locke</a> 1.64 - */ 1.65 -public class recompile 1.66 -{ 1.67 - /** 1.68 - * Main application entrypoint. 1.69 - * @param arg Command line arguments 1.70 - */ 1.71 - static public void main(String[] arg) 1.72 - { 1.73 - // Create a compiler object 1.74 - RECompiler r = new RECompiler(); 1.75 - 1.76 - // Print usage if arguments are incorrect 1.77 - if (arg.length <= 0 || arg.length % 2 != 0) 1.78 - { 1.79 - System.out.println("Usage: recompile <patternname> <pattern>"); 1.80 - System.exit(0); 1.81 - } 1.82 - 1.83 - // Loop through arguments, compiling each 1.84 - for (int i = 0; i < arg.length; i += 2) 1.85 - { 1.86 - try 1.87 - { 1.88 - // Compile regular expression 1.89 - String name = arg[i]; 1.90 - String pattern = arg[i+1]; 1.91 - String instructions = name + "PatternInstructions"; 1.92 - 1.93 - // Output program as a nice, formatted character array 1.94 - System.out.print("\n // Pre-compiled regular expression '" + pattern + "'\n" 1.95 - + " private static char[] " + instructions + " = \n {"); 1.96 - 1.97 - // Compile program for pattern 1.98 - REProgram program = r.compile(pattern); 1.99 - 1.100 - // Number of columns in output 1.101 - int numColumns = 7; 1.102 - 1.103 - // Loop through program 1.104 - char[] p = program.getInstructions(); 1.105 - for (int j = 0; j < p.length; j++) 1.106 - { 1.107 - // End of column? 1.108 - if ((j % numColumns) == 0) 1.109 - { 1.110 - System.out.print("\n "); 1.111 - } 1.112 - 1.113 - // Print character as padded hex number 1.114 - String hex = Integer.toHexString(p[j]); 1.115 - while (hex.length() < 4) 1.116 - { 1.117 - hex = "0" + hex; 1.118 - } 1.119 - System.out.print("0x" + hex + ", "); 1.120 - } 1.121 - 1.122 - // End of program block 1.123 - System.out.println("\n };"); 1.124 - System.out.println("\n private static RE " + name + "Pattern = new RE(new REProgram(" + instructions + "));"); 1.125 - } 1.126 - catch (RESyntaxException e) 1.127 - { 1.128 - System.out.println("Syntax error in expression \"" + arg[i] + "\": " + e.toString()); 1.129 - } 1.130 - catch (Exception e) 1.131 - { 1.132 - System.out.println("Unexpected exception: " + e.toString()); 1.133 - } 1.134 - catch (Error e) 1.135 - { 1.136 - System.out.println("Internal error: " + e.toString()); 1.137 - } 1.138 - } 1.139 - } 1.140 -}