2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 package org.opendaylight.yangtools.xsd.regex;
20 import java.util.Vector;
25 * @version $Id: Op.java 572108 2007-09-02 18:48:31Z mrglavas $
28 static final int DOT = 0;
29 static final int CHAR = 1; // Single character
30 static final int RANGE = 3; // [a-zA-Z]
31 static final int NRANGE = 4; // [^a-zA-Z]
32 static final int ANCHOR = 5; // ^ $ ...
33 static final int STRING = 6; // literal String
34 static final int CLOSURE = 7; // X*
35 static final int NONGREEDYCLOSURE = 8; // X*?
36 static final int QUESTION = 9; // X?
37 static final int NONGREEDYQUESTION = 10; // X??
38 static final int UNION = 11; // X|Y
39 static final int CAPTURE = 15; // ( and )
40 static final int BACKREFERENCE = 16; // \1 \2 ...
41 static final int LOOKAHEAD = 20; // (?=...)
42 static final int NEGATIVELOOKAHEAD = 21; // (?!...)
43 static final int LOOKBEHIND = 22; // (?<=...)
44 static final int NEGATIVELOOKBEHIND = 23; // (?<!...)
45 static final int INDEPENDENT = 24; // (?>...)
46 static final int MODIFIER = 25; // (?ims-ims:...)
47 static final int CONDITION = 26; // (?(..)yes|no)
49 static int nofinstances = 0;
50 static final boolean COUNT = false;
52 static Op createDot() {
56 return new Op(Op.DOT);
58 static CharOp createChar(int data) {
62 return new CharOp(Op.CHAR, data);
64 static CharOp createAnchor(int data) {
68 return new CharOp(Op.ANCHOR, data);
70 static CharOp createCapture(int number, Op next) {
74 CharOp op = new CharOp(Op.CAPTURE, number);
78 static UnionOp createUnion(int size) {
82 //System.err.println("Creates UnionOp");
83 return new UnionOp(Op.UNION, size);
85 static ChildOp createClosure(int id) {
89 return new ModifierOp(Op.CLOSURE, id, -1);
91 static ChildOp createNonGreedyClosure() {
95 return new ChildOp(Op.NONGREEDYCLOSURE);
97 static ChildOp createQuestion(boolean nongreedy) {
101 return new ChildOp(nongreedy ? Op.NONGREEDYQUESTION : Op.QUESTION);
103 static RangeOp createRange(Token tok) {
107 return new RangeOp(Op.RANGE, tok);
109 static ChildOp createLook(int type, Op next, Op branch) {
113 ChildOp op = new ChildOp(type);
118 static CharOp createBackReference(int refno) {
122 return new CharOp(Op.BACKREFERENCE, refno);
124 static StringOp createString(String literal) {
128 return new StringOp(Op.STRING, literal);
130 static ChildOp createIndependent(Op next, Op branch) {
134 ChildOp op = new ChildOp(Op.INDEPENDENT);
139 static ModifierOp createModifier(Op next, Op branch, int add, int mask) {
143 ModifierOp op = new ModifierOp(Op.MODIFIER, add, mask);
148 static ConditionOp createCondition(Op next, int ref, Op conditionflow, Op yesflow, Op noflow) {
152 ConditionOp op = new ConditionOp(Op.CONDITION, ref, conditionflow, yesflow, noflow);
160 protected Op(int type) {
164 int size() { // for UNION
167 Op elementAt(int index) { // for UNIoN
168 throw new RuntimeException("Internal Error: type="+this.type);
170 Op getChild() { // for CLOSURE, QUESTION
171 throw new RuntimeException("Internal Error: type="+this.type);
174 int getData() { // CharOp for CHAR, BACKREFERENCE, CAPTURE, ANCHOR,
175 throw new RuntimeException("Internal Error: type="+this.type);
177 int getData2() { // ModifierOp
178 throw new RuntimeException("Internal Error: type="+this.type);
180 RangeToken getToken() { // RANGE, NRANGE
181 throw new RuntimeException("Internal Error: type="+this.type);
183 String getString() { // STRING
184 throw new RuntimeException("Internal Error: type="+this.type);
187 // ================================================================
188 static class CharOp extends Op {
190 CharOp(int type, int data) {
192 this.charData = data;
196 return this.charData;
200 // ================================================================
201 static class UnionOp extends Op {
202 final Vector<Op> branches;
203 UnionOp(int type, int size) {
205 this.branches = new Vector<>(size);
207 void addElement(Op op) {
208 this.branches.addElement(op);
212 return this.branches.size();
215 Op elementAt(int index) {
216 return this.branches.elementAt(index);
220 // ================================================================
221 static class ChildOp extends Op {
226 void setChild(Op child) {
234 // ================================================================
235 static class ModifierOp extends ChildOp {
238 ModifierOp(int type, int v1, int v2) {
252 // ================================================================
253 static class RangeOp extends Op {
255 RangeOp(int type, Token tok) {
260 RangeToken getToken() {
261 return (RangeToken)this.tok;
264 // ================================================================
265 static class StringOp extends Op {
267 StringOp(int type, String literal) {
269 this.string = literal;
276 // ================================================================
277 static class ConditionOp extends Op {
282 ConditionOp(int type, int refno, Op conditionflow, Op yesflow, Op noflow) {
284 this.refNumber = refno;
285 this.condition = conditionflow;