JAL-1807 Bob's JalviewJS prototype first commit
[jalviewjs.git] / bin / com / stevesoft / pat / RegexTokenizer.js
1 Clazz.declarePackage ("com.stevesoft.pat");\r
2 Clazz.load (["java.util.Enumeration", "$.Vector"], "com.stevesoft.pat.RegexTokenizer", ["com.stevesoft.pat.Regex"], function () {\r
3 c$ = Clazz.decorateAsClass (function () {\r
4 this.toParse = null;\r
5 this.r = null;\r
6 this.count = 0;\r
7 this.v = null;\r
8 this.vi = null;\r
9 this.pos = 0;\r
10 this.offset = 1;\r
11 Clazz.instantialize (this, arguments);\r
12 }, com.stevesoft.pat, "RegexTokenizer", null, java.util.Enumeration);\r
13 Clazz.prepareFields (c$, function () {\r
14 this.v =  new java.util.Vector ();\r
15 this.vi =  new java.util.Vector ();\r
16 });\r
17 Clazz.defineMethod (c$, "getMore", \r
18 function () {\r
19 var s = this.r.right ();\r
20 if (this.r.searchFrom (this.toParse, this.pos)) {\r
21 this.v.addElement (this.r.left ().substring (this.pos));\r
22 this.vi.addElement ( new Integer (this.r.matchFrom () + this.r.charsMatched ()));\r
23 for (var i = 0; i < this.r.numSubs (); i++) {\r
24 if (this.r.substring () != null) {\r
25 this.v.addElement (this.r.substringI (i + this.offset));\r
26 this.vi.addElement ( new Integer (this.r.matchFromI (i + this.offset) + this.r.charsMatchedI (i + this.offset)));\r
27 }}\r
28 this.pos = this.r.matchFrom () + this.r.charsMatched ();\r
29 } else if (s != null) {\r
30 this.v.addElement (s);\r
31 }});\r
32 Clazz.makeConstructor (c$, \r
33 function (txt, ptrn) {\r
34 this.toParse = txt;\r
35 this.r =  new com.stevesoft.pat.Regex (ptrn, "");\r
36 this.offset = com.stevesoft.pat.Regex.BackRefOffset;\r
37 this.getMore ();\r
38 }, "~S,~S");\r
39 Clazz.makeConstructor (c$, \r
40 function (txt, r) {\r
41 this.toParse = txt;\r
42 this.r = r;\r
43 this.offset = com.stevesoft.pat.Regex.BackRefOffset;\r
44 this.getMore ();\r
45 }, "~S,com.stevesoft.pat.Regex");\r
46 Clazz.overrideMethod (c$, "nextElement", \r
47 function () {\r
48 if (this.count >= this.v.size ()) {\r
49 this.getMore ();\r
50 }return this.v.elementAt (this.count++);\r
51 });\r
52 Clazz.defineMethod (c$, "nextToken", \r
53 function () {\r
54 return this.nextElement ();\r
55 });\r
56 Clazz.defineMethod (c$, "nextToken", \r
57 function (newpat) {\r
58 try {\r
59 this.r.compile (newpat);\r
60 } catch (r_) {\r
61 if (Clazz.exceptionOf (r_, com.stevesoft.pat.RegSyntax)) {\r
62 } else {\r
63 throw r_;\r
64 }\r
65 }\r
66 return this.nextToken (this.r);\r
67 }, "~S");\r
68 Clazz.defineMethod (c$, "nextToken", \r
69 function (nr) {\r
70 this.r = nr;\r
71 if (this.vi.size () > this.count) {\r
72 this.pos = (this.vi.elementAt (this.count)).intValue ();\r
73 this.v.setSize (this.count);\r
74 this.vi.setSize (this.count);\r
75 }this.getMore ();\r
76 return this.nextToken ();\r
77 }, "com.stevesoft.pat.Regex");\r
78 Clazz.overrideMethod (c$, "hasMoreElements", \r
79 function () {\r
80 if (this.count >= this.v.size ()) {\r
81 this.getMore ();\r
82 }return this.count < this.v.size ();\r
83 });\r
84 Clazz.defineMethod (c$, "hasMoreTokens", \r
85 function () {\r
86 return this.hasMoreElements ();\r
87 });\r
88 Clazz.defineMethod (c$, "countTokens", \r
89 function () {\r
90 var _count = this.count;\r
91 while (this.hasMoreTokens ()) {\r
92 this.nextToken ();\r
93 }\r
94 this.count = _count;\r
95 return this.v.size () - this.count;\r
96 });\r
97 Clazz.defineMethod (c$, "allTokens", \r
98 function () {\r
99 this.countTokens ();\r
100 var ret =  new Array (this.v.size ());\r
101 this.v.copyInto (ret);\r
102 return ret;\r
103 });\r
104 });\r