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