1 package org.apache.oro.text.regex; 2 3 59 60 75 public final class Perl5Debug { 76 77 80 private Perl5Debug() { } 81 82 83 99 100 101 public static String printProgram(Perl5Pattern regexp) { 102 StringBuffer buffer; 103 char operator = OpCode._OPEN, prog[]; 104 int offset, next; 105 106 prog = regexp._program; 107 offset = 1; 108 buffer = new StringBuffer (); 109 110 while(operator != OpCode._END) { 111 operator = prog[offset]; 112 buffer.append(offset); 113 _printOperator(prog, offset, buffer); 114 115 next = OpCode._getNext(prog, offset); 116 offset+=OpCode._operandLength[operator]; 117 118 buffer.append("(" + next + ")"); 119 120 offset+=2; 121 122 if(operator == OpCode._ANYOF) { 123 offset += 16; 124 } else if(operator == OpCode._EXACTLY) { 125 ++offset; 126 buffer.append(" <"); 127 128 while(prog[offset] != CharStringPointer._END_OF_STRING) { 130 buffer.append(prog[offset]); 133 ++offset; 134 } 135 buffer.append(">"); 136 ++offset; 137 } 138 139 buffer.append('\n'); 140 } 141 142 if(regexp._startString != null) 144 buffer.append("start `" + new String (regexp._startString) + "' "); 145 if(regexp._startClassOffset != OpCode._NULL_OFFSET) { 146 buffer.append("stclass `"); 147 _printOperator(prog, regexp._startClassOffset, buffer); 148 buffer.append("' "); 149 } 150 if((regexp._anchor & Perl5Pattern._OPT_ANCH) != 0) 151 buffer.append("anchored "); 152 if((regexp._anchor & Perl5Pattern._OPT_SKIP) != 0) 153 buffer.append("plus "); 154 if((regexp._anchor & Perl5Pattern._OPT_IMPLICIT) != 0) 155 buffer.append("implicit "); 156 if(regexp._mustString != null) 157 buffer.append("must have \""+ new String (regexp._mustString) + 158 "\" back " + regexp._back + " "); 159 buffer.append("minlen " + regexp._minLength + '\n'); 160 161 return buffer.toString(); 162 } 163 164 165 static void _printOperator(char[] program, int offset, StringBuffer buffer) { 166 String str = null; 167 168 buffer.append(":"); 169 170 switch(program[offset]) { 171 case OpCode._BOL : str = "BOL"; break; 172 case OpCode._MBOL : str = "MBOL"; break; 173 case OpCode._SBOL : str = "SBOL"; break; 174 case OpCode._EOL : str = "EOL"; break; 175 case OpCode._MEOL : str = "MEOL"; break; 176 case OpCode._ANY : str = "ANY"; break; 177 case OpCode._SANY : str = "SANY"; break; 178 case OpCode._ANYOF : str = "ANYOF"; break; 179 193 case OpCode._BRANCH: str = "BRANCH"; break; 194 case OpCode._EXACTLY: str = "EXACTLY"; break; 195 case OpCode._NOTHING: str = "NOTHING"; break; 196 case OpCode._BACK : str = "BACK"; break; 197 case OpCode._END : str = "END"; break; 198 case OpCode._ALNUM : str = "ALNUM"; break; 199 case OpCode._NALNUM: str = "NALNUM"; break; 200 case OpCode._BOUND : str = "BOUND"; break; 201 case OpCode._NBOUND: str = "NBOUND"; break; 202 case OpCode._SPACE : str = "SPACE"; break; 203 case OpCode._NSPACE: str = "NSPACE"; break; 204 case OpCode._DIGIT : str = "DIGIT"; break; 205 case OpCode._NDIGIT: str = "NDIGIT"; break; 206 case OpCode._CURLY : 207 buffer.append("CURLY {"); 208 buffer.append((int)OpCode._getArg1(program, offset)); 209 buffer.append(','); buffer.append((int)OpCode._getArg2(program, offset)); 210 buffer.append('}'); 211 break; 212 case OpCode._CURLYX: 213 buffer.append("CURLYX {"); 214 buffer.append((int)OpCode._getArg1(program, offset)); 215 buffer.append(','); buffer.append((int)OpCode._getArg2(program, offset)); 216 buffer.append('}'); 217 break; 218 case OpCode._REF: 219 buffer.append("REF"); buffer.append((int)OpCode._getArg1(program, offset)); 220 break; 221 case OpCode._OPEN: 222 buffer.append("OPEN"); buffer.append((int)OpCode._getArg1(program, offset)); 223 break; 224 case OpCode._CLOSE: 225 buffer.append("CLOSE"); buffer.append((int)OpCode._getArg1(program, offset)); 226 break; 227 case OpCode._STAR : str = "STAR"; break; 228 case OpCode._PLUS : str = "PLUS"; break; 229 case OpCode._MINMOD : str = "MINMOD"; break; 230 case OpCode._GBOL : str = "GBOL"; break; 231 case OpCode._UNLESSM: str = "UNLESSM"; break; 232 case OpCode._IFMATCH: str = "IFMATCH"; break; 233 case OpCode._SUCCEED: str = "SUCCEED"; break; 234 case OpCode._WHILEM : str = "WHILEM"; break; 235 default: 236 buffer.append("Operator is unrecognized. Faulty expression code!"); 237 break; 238 } 239 240 if(str != null) 241 buffer.append(str); 242 } 243 } 244 | Popular Tags |