1 16 17 package org.apache.xerces.impl.xpath.regex; 18 19 import java.util.Vector ; 20 21 26 class Op { 27 static final int DOT = 0; 28 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; 48 static int nofinstances = 0; 49 static final boolean COUNT = false; 50 51 static Op createDot() { 52 if (Op.COUNT) Op.nofinstances ++; 53 return new Op(Op.DOT); 54 } 55 static CharOp createChar(int data) { 56 if (Op.COUNT) Op.nofinstances ++; 57 return new CharOp(Op.CHAR, data); 58 } 59 static CharOp createAnchor(int data) { 60 if (Op.COUNT) Op.nofinstances ++; 61 return new CharOp(Op.ANCHOR, data); 62 } 63 static CharOp createCapture(int number, Op next) { 64 if (Op.COUNT) Op.nofinstances ++; 65 CharOp op = new CharOp(Op.CAPTURE, number); 66 op.next = next; 67 return op; 68 } 69 static UnionOp createUnion(int size) { 70 if (Op.COUNT) Op.nofinstances ++; 71 return new UnionOp(Op.UNION, size); 73 } 74 static ChildOp createClosure(int id) { 75 if (Op.COUNT) Op.nofinstances ++; 76 return new ModifierOp(Op.CLOSURE, id, -1); 77 } 78 static ChildOp createNonGreedyClosure() { 79 if (Op.COUNT) Op.nofinstances ++; 80 return new ChildOp(Op.NONGREEDYCLOSURE); 81 } 82 static ChildOp createQuestion(boolean nongreedy) { 83 if (Op.COUNT) Op.nofinstances ++; 84 return new ChildOp(nongreedy ? Op.NONGREEDYQUESTION : Op.QUESTION); 85 } 86 static RangeOp createRange(Token tok) { 87 if (Op.COUNT) Op.nofinstances ++; 88 return new RangeOp(Op.RANGE, tok); 89 } 90 static ChildOp createLook(int type, Op next, Op branch) { 91 if (Op.COUNT) Op.nofinstances ++; 92 ChildOp op = new ChildOp(type); 93 op.setChild(branch); 94 op.next = next; 95 return op; 96 } 97 static CharOp createBackReference(int refno) { 98 if (Op.COUNT) Op.nofinstances ++; 99 return new CharOp(Op.BACKREFERENCE, refno); 100 } 101 static StringOp createString(String literal) { 102 if (Op.COUNT) Op.nofinstances ++; 103 return new StringOp(Op.STRING, literal); 104 } 105 static ChildOp createIndependent(Op next, Op branch) { 106 if (Op.COUNT) Op.nofinstances ++; 107 ChildOp op = new ChildOp(Op.INDEPENDENT); 108 op.setChild(branch); 109 op.next = next; 110 return op; 111 } 112 static ModifierOp createModifier(Op next, Op branch, int add, int mask) { 113 if (Op.COUNT) Op.nofinstances ++; 114 ModifierOp op = new ModifierOp(Op.MODIFIER, add, mask); 115 op.setChild(branch); 116 op.next = next; 117 return op; 118 } 119 static ConditionOp createCondition(Op next, int ref, Op conditionflow, Op yesflow, Op noflow) { 120 if (Op.COUNT) Op.nofinstances ++; 121 ConditionOp op = new ConditionOp(Op.CONDITION, ref, conditionflow, yesflow, noflow); 122 op.next = next; 123 return op; 124 } 125 126 int type; 127 Op next = null; 128 129 protected Op(int type) { 130 this.type = type; 131 } 132 133 int size() { return 0; 135 } 136 Op elementAt(int index) { throw new RuntimeException ("Internal Error: type="+this.type); 138 } 139 Op getChild() { throw new RuntimeException ("Internal Error: type="+this.type); 141 } 142 int getData() { throw new RuntimeException ("Internal Error: type="+this.type); 145 } 146 int getData2() { throw new RuntimeException ("Internal Error: type="+this.type); 148 } 149 RangeToken getToken() { throw new RuntimeException ("Internal Error: type="+this.type); 151 } 152 String getString() { throw new RuntimeException ("Internal Error: type="+this.type); 154 } 155 156 static class CharOp extends Op { 158 int charData; 159 CharOp(int type, int data) { 160 super(type); 161 this.charData = data; 162 } 163 int getData() { 164 return this.charData; 165 } 166 } 167 168 static class UnionOp extends Op { 170 Vector branches; 171 UnionOp(int type, int size) { 172 super(type); 173 this.branches = new Vector (size); 174 } 175 void addElement(Op op) { 176 this.branches.addElement(op); 177 } 178 int size() { 179 return this.branches.size(); 180 } 181 Op elementAt(int index) { 182 return (Op)this.branches.elementAt(index); 183 } 184 } 185 186 static class ChildOp extends Op { 188 Op child; 189 ChildOp(int type) { 190 super(type); 191 } 192 void setChild(Op child) { 193 this.child = child; 194 } 195 Op getChild() { 196 return this.child; 197 } 198 } 199 static class ModifierOp extends ChildOp { 201 int v1; 202 int v2; 203 ModifierOp(int type, int v1, int v2) { 204 super(type); 205 this.v1 = v1; 206 this.v2 = v2; 207 } 208 int getData() { 209 return this.v1; 210 } 211 int getData2() { 212 return this.v2; 213 } 214 } 215 static class RangeOp extends Op { 217 Token tok; 218 RangeOp(int type, Token tok) { 219 super(type); 220 this.tok = tok; 221 } 222 RangeToken getToken() { 223 return (RangeToken)this.tok; 224 } 225 } 226 static class StringOp extends Op { 228 String string; 229 StringOp(int type, String literal) { 230 super(type); 231 this.string = literal; 232 } 233 String getString() { 234 return this.string; 235 } 236 } 237 static class ConditionOp extends Op { 239 int refNumber; 240 Op condition; 241 Op yes; 242 Op no; 243 ConditionOp(int type, int refno, Op conditionflow, Op yesflow, Op noflow) { 244 super(type); 245 this.refNumber = refno; 246 this.condition = conditionflow; 247 this.yes = yesflow; 248 this.no = noflow; 249 } 250 } 251 } 252 | Popular Tags |