Merge branch 'master' of https://source.jalview.org/git/jalviewjs.git
[jalviewjs.git] / site / j2s / com / stevesoft / pat / Multi_stage2.js
1 Clazz.declarePackage ("com.stevesoft.pat");
2 Clazz.load (["com.stevesoft.pat.PatternSub"], "com.stevesoft.pat.Multi_stage2", ["com.stevesoft.pat.RegSyntaxError", "$.patInt"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.nextRet = null;
5 this.count = null;
6 this.matchMin = null;
7 this.matchMax = null;
8 this.matchFewest = false;
9 this.pos_old = -1;
10 Clazz.instantialize (this, arguments);
11 }, com.stevesoft.pat, "Multi_stage2", com.stevesoft.pat.PatternSub);
12 Clazz.defineMethod (c$, "toString", 
13 function () {
14 var ret = "";
15 ret += this.sub.toString ();
16 ret += "{" + this.matchMin + "," + this.matchMax + "}";
17 if (this.matchFewest) {
18 ret += "?";
19 }ret += this.parent.nextString ();
20 return ret;
21 });
22 Clazz.makeConstructor (c$, 
23 function (a, b, p) {
24 Clazz.superConstructor (this, com.stevesoft.pat.Multi_stage2, []);
25 if (p == null) {
26 com.stevesoft.pat.RegSyntaxError.endItAll ("Multiple match of Null pattern requested.");
27 }this.sub = p;
28 this.nextRet = this;
29 this.sub.setParent (this);
30 this.matchMin = a;
31 this.matchMax = b;
32 this.count =  new com.stevesoft.pat.patInt (0);
33 if (!a.lessEq (b)) {
34 com.stevesoft.pat.RegSyntaxError.endItAll ("Bad Multi Args: " + a + ">" + b);
35 }var i =  new com.stevesoft.pat.patInt (-1);
36 if (a.lessEq (i)) {
37 com.stevesoft.pat.RegSyntaxError.endItAll ("Bad Multi Args: " + a + "< 0");
38 }}, "com.stevesoft.pat.patInt,com.stevesoft.pat.patInt,com.stevesoft.pat.Pattern");
39 Clazz.defineMethod (c$, "getNext", 
40 function () {
41 return this.nextRet;
42 });
43 Clazz.overrideMethod (c$, "matchInternal", 
44 function (pos, pt) {
45 this.sub.setParent (this);
46 var canUse = -1;
47 if (this.pos_old >= 0 && pos == this.pos_old) {
48 return -1;
49 }this.pos_old = pos;
50 if (this.matchMin.lessEq (this.count)) {
51 canUse = pos;
52 }if (!this.count.lessEq (this.matchMax) || pos > pt.src.length ()) {
53 return -1;
54 }if ((this.matchFewest || this.count.equals (this.matchMax)) && canUse >= 0) {
55 var n = Clazz.superCall (this, com.stevesoft.pat.Multi_stage2, "getNext", []);
56 if (n == null) {
57 return canUse;
58 }var ret = this.testMatch (n, pos, pt);
59 if (ret >= 0) {
60 return ret;
61 } else {
62 canUse = -1;
63 }}this.count.inc ();
64 try {
65 if (this.count.lessEq (this.matchMax)) {
66 var r = this.testMatch (this.sub, pos, pt);
67 if (r >= 0) {
68 return r;
69 }}} finally {
70 this.count.dec ();
71 }
72 if (!this.matchFewest && canUse >= 0) {
73 var n = Clazz.superCall (this, com.stevesoft.pat.Multi_stage2, "getNext", []);
74 if (n == null) {
75 return canUse;
76 }var ret = this.testMatch (n, pos, pt);
77 return ret;
78 } else {
79 return canUse;
80 }}, "~N,com.stevesoft.pat.Pthings");
81 Clazz.overrideMethod (c$, "clone1", 
82 function (h) {
83 try {
84 var m =  new com.stevesoft.pat.Multi_stage2 (this.matchMin, this.matchMax, this.sub.clone (h));
85 m.matchFewest = this.matchFewest;
86 return m;
87 } catch (rs) {
88 if (Clazz.exceptionOf (rs, com.stevesoft.pat.RegSyntax)) {
89 return null;
90 } else {
91 throw rs;
92 }
93 }
94 }, "java.util.Hashtable");
95 });