1 57 58 package org.enhydra.apache.xerces.utils.regex; 59 60 61 import java.util.Vector ; 62 63 65 class Op { 66 static final int DOT = 0; 67 static final int CHAR = 1; static final int RANGE = 3; static final int NRANGE = 4; static final int ANCHOR = 5; static final int STRING = 6; static final int CLOSURE = 7; static final int NONGREEDYCLOSURE = 8; static final int QUESTION = 9; static final int NONGREEDYQUESTION = 10; static final int UNION = 11; static final int CAPTURE = 15; static final int BACKREFERENCE = 16; static final int LOOKAHEAD = 20; static final int NEGATIVELOOKAHEAD = 21; static final int LOOKBEHIND = 22; static final int NEGATIVELOOKBEHIND = 23; static final int INDEPENDENT = 24; static final int MODIFIER = 25; static final int CONDITION = 26; 87 static int nofinstances = 0; 88 static final boolean COUNT = false; 89 90 static Op createDot() { 91 if (Op.COUNT) Op.nofinstances ++; 92 return new Op(Op.DOT); 93 } 94 static CharOp createChar(int data) { 95 if (Op.COUNT) Op.nofinstances ++; 96 return new CharOp(Op.CHAR, data); 97 } 98 static CharOp createAnchor(int data) { 99 if (Op.COUNT) Op.nofinstances ++; 100 return new CharOp(Op.ANCHOR, data); 101 } 102 static CharOp createCapture(int number, Op next) { 103 if (Op.COUNT) Op.nofinstances ++; 104 CharOp op = new CharOp(Op.CAPTURE, number); 105 op.next = next; 106 return op; 107 } 108 static UnionOp createUnion(int size) { 109 if (Op.COUNT) Op.nofinstances ++; 110 return new UnionOp(Op.UNION, size); 112 } 113 static ChildOp createClosure(int id) { 114 if (Op.COUNT) Op.nofinstances ++; 115 return new ModifierOp(Op.CLOSURE, id, -1); 116 } 117 static ChildOp createNonGreedyClosure() { 118 if (Op.COUNT) Op.nofinstances ++; 119 return new ChildOp(Op.NONGREEDYCLOSURE); 120 } 121 static ChildOp createQuestion(boolean nongreedy) { 122 if (Op.COUNT) Op.nofinstances ++; 123 return new ChildOp(nongreedy ? Op.NONGREEDYQUESTION : Op.QUESTION); 124 } 125 static RangeOp createRange(Token tok) { 126 if (Op.COUNT) Op.nofinstances ++; 127 return new RangeOp(Op.RANGE, tok); 128 } 129 static ChildOp createLook(int type, Op next, Op branch) { 130 if (Op.COUNT) Op.nofinstances ++; 131 ChildOp op = new ChildOp(type); 132 op.setChild(branch); 133 op.next = next; 134 return op; 135 } 136 static CharOp createBackReference(int refno) { 137 if (Op.COUNT) Op.nofinstances ++; 138 return new CharOp(Op.BACKREFERENCE, refno); 139 } 140 static StringOp createString(String literal) { 141 if (Op.COUNT) Op.nofinstances ++; 142 return new StringOp(Op.STRING, literal); 143 } 144 static ChildOp createIndependent(Op next, Op branch) { 145 if (Op.COUNT) Op.nofinstances ++; 146 ChildOp op = new ChildOp(Op.INDEPENDENT); 147 op.setChild(branch); 148 op.next = next; 149 return op; 150 } 151 static ModifierOp createModifier(Op next, Op branch, int add, int mask) { 152 if (Op.COUNT) Op.nofinstances ++; 153 ModifierOp op = new ModifierOp(Op.MODIFIER, add, mask); 154 op.setChild(branch); 155 op.next = next; 156 return op; 157 } 158 static ConditionOp createCondition(Op next, int ref, Op conditionflow, Op yesflow, Op noflow) { 159 if (Op.COUNT) Op.nofinstances ++; 160 ConditionOp op = new ConditionOp(Op.CONDITION, ref, conditionflow, yesflow, noflow); 161 op.next = next; 162 return op; 163 } 164 165 int type; 166 Op next = null; 167 168 protected Op(int type) { 169 this.type = type; 170 } 171 172 int size() { return 0; 174 } 175 Op elementAt(int index) { throw new RuntimeException ("Internal Error: type="+this.type); 177 } 178 Op getChild() { throw new RuntimeException ("Internal Error: type="+this.type); 180 } 181 int getData() { throw new RuntimeException ("Internal Error: type="+this.type); 184 } 185 int getData2() { throw new RuntimeException ("Internal Error: type="+this.type); 187 } 188 RangeToken getToken() { throw new RuntimeException ("Internal Error: type="+this.type); 190 } 191 String getString() { throw new RuntimeException ("Internal Error: type="+this.type); 193 } 194 195 static class CharOp extends Op { 197 int charData; 198 CharOp(int type, int data) { 199 super(type); 200 this.charData = data; 201 } 202 int getData() { 203 return this.charData; 204 } 205 } 206 207 static class UnionOp extends Op { 209 Vector branches; 210 UnionOp(int type, int size) { 211 super(type); 212 this.branches = new Vector (size); 213 } 214 void addElement(Op op) { 215 this.branches.addElement(op); 216 } 217 int size() { 218 return this.branches.size(); 219 } 220 Op elementAt(int index) { 221 return (Op)this.branches.elementAt(index); 222 } 223 } 224 225 static class ChildOp extends Op { 227 Op child; 228 ChildOp(int type) { 229 super(type); 230 } 231 void setChild(Op child) { 232 this.child = child; 233 } 234 Op getChild() { 235 return this.child; 236 } 237 } 238 static class ModifierOp extends ChildOp { 240 int v1; 241 int v2; 242 ModifierOp(int type, int v1, int v2) { 243 super(type); 244 this.v1 = v1; 245 this.v2 = v2; 246 } 247 int getData() { 248 return this.v1; 249 } 250 int getData2() { 251 return this.v2; 252 } 253 } 254 static class RangeOp extends Op { 256 Token tok; 257 RangeOp(int type, Token tok) { 258 super(type); 259 this.tok = tok; 260 } 261 RangeToken getToken() { 262 return (RangeToken)this.tok; 263 } 264 } 265 static class StringOp extends Op { 267 String string; 268 StringOp(int type, String literal) { 269 super(type); 270 this.string = literal; 271 } 272 String getString() { 273 return this.string; 274 } 275 } 276 static class ConditionOp extends Op { 278 int refNumber; 279 Op condition; 280 Op yes; 281 Op no; 282 ConditionOp(int type, int refno, Op conditionflow, Op yesflow, Op noflow) { 283 super(type); 284 this.refNumber = refno; 285 this.condition = conditionflow; 286 this.yes = yesflow; 287 this.no = noflow; 288 } 289 } 290 } 291 | Popular Tags |