KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > commons > xml > parser > XMLFragmentParserTokenManager


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19
20 /* Generated By:JavaCC: Do not edit this line. XMLFragmentParserTokenManager.java */
21 package org.openharmonise.commons.xml.parser;
22
23 public class XMLFragmentParserTokenManager implements XMLFragmentParserConstants {
24   public java.io.PrintStream JavaDoc debugStream = System.err;
25   public void setDebugStream(java.io.PrintStream JavaDoc ds) { debugStream = ds; }
26
27   private final int jjStopStringLiteralDfa_0(int pos, long active0) {
28    switch (pos)
29    {
30       case 0:
31          if ((active0 & 0x10L) != 0L)
32          {
33             jjmatchedKind = 13;
34             return 12;
35          }
36          return -1;
37       default :
38          return -1;
39    }
40 }
41 private final int jjStartNfa_0(int pos, long active0)
42 {
43    return jjMoveNfa_0(jjStopStringLiteralDfa_0(pos, active0), pos + 1);
44 }
45 private final int jjStopAtPos(int pos, int kind)
46 {
47    jjmatchedKind = kind;
48    jjmatchedPos = pos;
49    return pos + 1;
50 }
51 private final int jjStartNfaWithStates_0(int pos, int kind, int state)
52 {
53    jjmatchedKind = kind;
54    jjmatchedPos = pos;
55    try { curChar = input_stream.readChar(); }
56    catch(java.io.IOException JavaDoc e) { return pos + 1; }
57    return jjMoveNfa_0(state, pos + 1);
58 }
59 private final int jjMoveStringLiteralDfa0_0()
60 {
61    switch(curChar)
62    {
63       case 47:
64          return jjMoveStringLiteralDfa1_0(0x10L);
65       case 60:
66          jjmatchedKind = 1;
67          return jjMoveStringLiteralDfa1_0(0x8L);
68       case 61:
69          return jjStopAtPos(0, 5);
70       case 62:
71          return jjStopAtPos(0, 2);
72       default :
73          return jjMoveNfa_0(0, 0);
74    }
75 }
76 private final int jjMoveStringLiteralDfa1_0(long active0)
77 {
78    try { curChar = input_stream.readChar(); }
79    catch(java.io.IOException JavaDoc e) {
80       jjStopStringLiteralDfa_0(0, active0);
81       return 1;
82    }
83    switch(curChar)
84    {
85       case 47:
86          if ((active0 & 0x8L) != 0L)
87             return jjStopAtPos(1, 3);
88          break;
89       case 62:
90          if ((active0 & 0x10L) != 0L)
91             return jjStopAtPos(1, 4);
92          break;
93       default :
94          break;
95    }
96    return jjStartNfa_0(0, active0);
97 }
98 private final void jjCheckNAdd(int state)
99 {
100    if (jjrounds[state] != jjround)
101    {
102       jjstateSet[jjnewStateCnt++] = state;
103       jjrounds[state] = jjround;
104    }
105 }
106 private final void jjAddStates(int start, int end)
107 {
108    do {
109       jjstateSet[jjnewStateCnt++] = jjnextStates[start];
110    } while (start++ != end);
111 }
112 private final void jjCheckNAddTwoStates(int state1, int state2)
113 {
114    jjCheckNAdd(state1);
115    jjCheckNAdd(state2);
116 }
117 private final void jjCheckNAddStates(int start, int end)
118 {
119    do {
120       jjCheckNAdd(jjnextStates[start]);
121    } while (start++ != end);
122 }
123 private final void jjCheckNAddStates(int start)
124 {
125    jjCheckNAdd(jjnextStates[start]);
126    jjCheckNAdd(jjnextStates[start + 1]);
127 }
128 static final long[] jjbitVec0 = {
129    0x0L, 0x0L, 0xffffffffffffffffL, 0xffffffffffffffffL
130 };
131 private final int jjMoveNfa_0(int startState, int curPos)
132 {
133    int[] nextStates;
134    int startsAt = 0;
135    jjnewStateCnt = 13;
136    int i = 1;
137    jjstateSet[0] = startState;
138    int j, kind = 0x7fffffff;
139    for (;;)
140    {
141       if (++jjround == 0x7fffffff)
142          ReInitRounds();
143       if (curChar < 64)
144       {
145          long l = 1L << curChar;
146          MatchLoop: do
147          {
148             switch(jjstateSet[--i])
149             {
150                case 0:
151                   if ((0x8ffffffaffffd9ffL & l) != 0L)
152                   {
153                      if (kind > 13)
154                         kind = 13;
155                      jjCheckNAdd(12);
156                   }
157                   else if ((0x100002600L & l) != 0L)
158                   {
159                      if (kind > 7)
160                         kind = 7;
161                      jjCheckNAdd(6);
162                   }
163                   else if (curChar == 34)
164                      jjCheckNAddTwoStates(1, 2);
165                   if (curChar == 39)
166                      jjCheckNAddTwoStates(4, 5);
167                   break;
168                case 1:
169                   if ((0xfffffffbffffffffL & l) != 0L)
170                      jjCheckNAddTwoStates(1, 2);
171                   break;
172                case 2:
173                   if (curChar == 34 && kind > 6)
174                      kind = 6;
175                   break;
176                case 3:
177                   if (curChar == 39)
178                      jjCheckNAddTwoStates(4, 5);
179                   break;
180                case 4:
181                   if ((0xffffff7fffffffffL & l) != 0L)
182                      jjCheckNAddTwoStates(4, 5);
183                   break;
184                case 5:
185                   if (curChar == 39 && kind > 6)
186                      kind = 6;
187                   break;
188                case 6:
189                   if ((0x100002600L & l) == 0L)
190                      break;
191                   if (kind > 7)
192                      kind = 7;
193                   jjCheckNAdd(6);
194                   break;
195                case 8:
196                   if ((0x3ff600000000000L & l) == 0L)
197                      break;
198                   if (kind > 12)
199                      kind = 12;
200                   jjAddStates(0, 1);
201                   break;
202                case 9:
203                   if (curChar == 58)
204                      jjstateSet[jjnewStateCnt++] = 10;
205                   break;
206                case 11:
207                   if ((0x3ff600000000000L & l) == 0L)
208                      break;
209                   if (kind > 12)
210                      kind = 12;
211                   jjstateSet[jjnewStateCnt++] = 11;
212                   break;
213                case 12:
214                   if ((0x8ffffffaffffd9ffL & l) == 0L)
215                      break;
216                   if (kind > 13)
217                      kind = 13;
218                   jjCheckNAdd(12);
219                   break;
220                default : break;
221             }
222          } while(i != startsAt);
223       }
224       else if (curChar < 128)
225       {
226          long l = 1L << (curChar & 077);
227          MatchLoop: do
228          {
229             switch(jjstateSet[--i])
230             {
231                case 0:
232                   if (kind > 13)
233                      kind = 13;
234                   jjCheckNAdd(12);
235                   if ((0x7fffffe87fffffeL & l) != 0L)
236                   {
237                      if (kind > 12)
238                         kind = 12;
239                      jjCheckNAddTwoStates(8, 9);
240                   }
241                   break;
242                case 1:
243                   jjAddStates(2, 3);
244                   break;
245                case 4:
246                   jjAddStates(4, 5);
247                   break;
248                case 7:
249                case 8:
250                   if ((0x7fffffe87fffffeL & l) == 0L)
251                      break;
252                   if (kind > 12)
253                      kind = 12;
254                   jjCheckNAddTwoStates(8, 9);
255                   break;
256                case 10:
257                case 11:
258                   if ((0x7fffffe87fffffeL & l) == 0L)
259                      break;
260                   if (kind > 12)
261                      kind = 12;
262                   jjCheckNAdd(11);
263                   break;
264                case 12:
265                   if (kind > 13)
266                      kind = 13;
267                   jjCheckNAdd(12);
268                   break;
269                default : break;
270             }
271          } while(i != startsAt);
272       }
273       else
274       {
275          int i2 = (curChar & 0xff) >> 6;
276          long l2 = 1L << (curChar & 077);
277          MatchLoop: do
278          {
279             switch(jjstateSet[--i])
280             {
281                case 0:
282                case 12:
283                   if ((jjbitVec0[i2] & l2) == 0L)
284                      break;
285                   if (kind > 13)
286                      kind = 13;
287                   jjCheckNAdd(12);
288                   break;
289                case 1:
290                   if ((jjbitVec0[i2] & l2) != 0L)
291                      jjAddStates(2, 3);
292                   break;
293                case 4:
294                   if ((jjbitVec0[i2] & l2) != 0L)
295                      jjAddStates(4, 5);
296                   break;
297                default : break;
298             }
299          } while(i != startsAt);
300       }
301       if (kind != 0x7fffffff)
302       {
303          jjmatchedKind = kind;
304          jjmatchedPos = curPos;
305          kind = 0x7fffffff;
306       }
307       ++curPos;
308       if ((i = jjnewStateCnt) == (startsAt = 13 - (jjnewStateCnt = startsAt)))
309          return curPos;
310       try { curChar = input_stream.readChar(); }
311       catch(java.io.IOException JavaDoc e) { return curPos; }
312    }
313 }
314 static final int[] jjnextStates = {
315    8, 9, 1, 2, 4, 5,
316 };
317 public static final String JavaDoc[] jjstrLiteralImages = {
318 "", "\74", "\76", "\74\57", "\57\76", "\75", null, null, null, null, null,
319 null, null, null, };
320 public static final String JavaDoc[] lexStateNames = {
321    "DEFAULT",
322 };
323 private SimpleCharStream input_stream;
324 private final int[] jjrounds = new int[13];
325 private final int[] jjstateSet = new int[26];
326 protected char curChar;
327 public XMLFragmentParserTokenManager(SimpleCharStream stream)
328 {
329    if (SimpleCharStream.staticFlag)
330       throw new Error JavaDoc("ERROR: Cannot use a static CharStream class with a non-static lexical analyzer.");
331    input_stream = stream;
332 }
333 public XMLFragmentParserTokenManager(SimpleCharStream stream, int lexState)
334 {
335    this(stream);
336    SwitchTo(lexState);
337 }
338 public void ReInit(SimpleCharStream stream)
339 {
340    jjmatchedPos = jjnewStateCnt = 0;
341    curLexState = defaultLexState;
342    input_stream = stream;
343    ReInitRounds();
344 }
345 private final void ReInitRounds()
346 {
347    int i;
348    jjround = 0x80000001;
349    for (i = 13; i-- > 0;)
350       jjrounds[i] = 0x80000000;
351 }
352 public void ReInit(SimpleCharStream stream, int lexState)
353 {
354    ReInit(stream);
355    SwitchTo(lexState);
356 }
357 public void SwitchTo(int lexState)
358 {
359    if (lexState >= 1 || lexState < 0)
360       throw new TokenMgrError("Error: Ignoring invalid lexical state : " + lexState + ". State unchanged.", TokenMgrError.INVALID_LEXICAL_STATE);
361    else
362       curLexState = lexState;
363 }
364
365 private final Token jjFillToken()
366 {
367    Token t = Token.newToken(jjmatchedKind);
368    t.kind = jjmatchedKind;
369    String JavaDoc im = jjstrLiteralImages[jjmatchedKind];
370    t.image = (im == null) ? input_stream.GetImage() : im;
371    t.beginLine = input_stream.getBeginLine();
372    t.beginColumn = input_stream.getBeginColumn();
373    t.endLine = input_stream.getEndLine();
374    t.endColumn = input_stream.getEndColumn();
375    return t;
376 }
377
378 int curLexState = 0;
379 int defaultLexState = 0;
380 int jjnewStateCnt;
381 int jjround;
382 int jjmatchedPos;
383 int jjmatchedKind;
384
385 public final Token getNextToken()
386 {
387   int kind;
388   Token specialToken = null;
389   Token matchedToken;
390   int curPos = 0;
391
392   EOFLoop :
393   for (;;)
394   {
395    try
396    {
397       curChar = input_stream.BeginToken();
398    }
399    catch(java.io.IOException JavaDoc e)
400    {
401       jjmatchedKind = 0;
402       matchedToken = jjFillToken();
403       return matchedToken;
404    }
405
406    jjmatchedKind = 0x7fffffff;
407    jjmatchedPos = 0;
408    curPos = jjMoveStringLiteralDfa0_0();
409    if (jjmatchedKind != 0x7fffffff)
410    {
411       if (jjmatchedPos + 1 < curPos)
412          input_stream.backup(curPos - jjmatchedPos - 1);
413          matchedToken = jjFillToken();
414          return matchedToken;
415    }
416    int error_line = input_stream.getEndLine();
417    int error_column = input_stream.getEndColumn();
418    String JavaDoc error_after = null;
419    boolean EOFSeen = false;
420    try { input_stream.readChar(); input_stream.backup(1); }
421    catch (java.io.IOException JavaDoc e1) {
422       EOFSeen = true;
423       error_after = curPos <= 1 ? "" : input_stream.GetImage();
424       if (curChar == '\n' || curChar == '\r') {
425          error_line++;
426          error_column = 0;
427       }
428       else
429          error_column++;
430    }
431    if (!EOFSeen) {
432       input_stream.backup(1);
433       error_after = curPos <= 1 ? "" : input_stream.GetImage();
434    }
435    throw new TokenMgrError(EOFSeen, curLexState, error_line, error_column, error_after, curChar, TokenMgrError.LEXICAL_ERROR);
436   }
437 }
438
439 }
440
Popular Tags