pylucene 3.5.0-3
[pylucene.git] / lucene-java-3.5.0 / lucene / contrib / queryparser / src / java / org / apache / lucene / queryParser / surround / parser / QueryParserTokenManager.java
1 /* Generated By:JavaCC: Do not edit this line. QueryParserTokenManager.java */
2 package org.apache.lucene.queryParser.surround.parser;
3 import java.util.ArrayList;
4 import java.util.List;
5 import java.io.StringReader;
6 import org.apache.lucene.analysis.TokenStream;
7 import org.apache.lucene.queryParser.surround.query.SrndQuery;
8 import org.apache.lucene.queryParser.surround.query.FieldsQuery;
9 import org.apache.lucene.queryParser.surround.query.OrQuery;
10 import org.apache.lucene.queryParser.surround.query.AndQuery;
11 import org.apache.lucene.queryParser.surround.query.NotQuery;
12 import org.apache.lucene.queryParser.surround.query.DistanceQuery;
13 import org.apache.lucene.queryParser.surround.query.SrndTermQuery;
14 import org.apache.lucene.queryParser.surround.query.SrndPrefixQuery;
15 import org.apache.lucene.queryParser.surround.query.SrndTruncQuery;
16
17 /** Token Manager. */
18 public class QueryParserTokenManager implements QueryParserConstants
19 {
20
21   /** Debug output. */
22   public  java.io.PrintStream debugStream = System.out;
23   /** Set debug output. */
24   public  void setDebugStream(java.io.PrintStream ds) { debugStream = ds; }
25 private final int jjStopStringLiteralDfa_1(int pos, long active0)
26 {
27    switch (pos)
28    {
29       default :
30          return -1;
31    }
32 }
33 private final int jjStartNfa_1(int pos, long active0)
34 {
35    return jjMoveNfa_1(jjStopStringLiteralDfa_1(pos, active0), pos + 1);
36 }
37 private int jjStopAtPos(int pos, int kind)
38 {
39    jjmatchedKind = kind;
40    jjmatchedPos = pos;
41    return pos + 1;
42 }
43 private int jjMoveStringLiteralDfa0_1()
44 {
45    switch(curChar)
46    {
47       case 40:
48          return jjStopAtPos(0, 13);
49       case 41:
50          return jjStopAtPos(0, 14);
51       case 44:
52          return jjStopAtPos(0, 15);
53       case 58:
54          return jjStopAtPos(0, 16);
55       case 94:
56          return jjStopAtPos(0, 17);
57       default :
58          return jjMoveNfa_1(0, 0);
59    }
60 }
61 static final long[] jjbitVec0 = {
62    0xfffffffffffffffeL, 0xffffffffffffffffL, 0xffffffffffffffffL, 0xffffffffffffffffL
63 };
64 static final long[] jjbitVec2 = {
65    0x0L, 0x0L, 0xffffffffffffffffL, 0xffffffffffffffffL
66 };
67 private int jjMoveNfa_1(int startState, int curPos)
68 {
69    int startsAt = 0;
70    jjnewStateCnt = 38;
71    int i = 1;
72    jjstateSet[0] = startState;
73    int kind = 0x7fffffff;
74    for (;;)
75    {
76       if (++jjround == 0x7fffffff)
77          ReInitRounds();
78       if (curChar < 64)
79       {
80          long l = 1L << curChar;
81          do
82          {
83             switch(jjstateSet[--i])
84             {
85                case 0:
86                   if ((0x7bffe8faffffd9ffL & l) != 0L)
87                   {
88                      if (kind > 22)
89                         kind = 22;
90                      jjCheckNAddStates(0, 4);
91                   }
92                   else if ((0x100002600L & l) != 0L)
93                   {
94                      if (kind > 7)
95                         kind = 7;
96                   }
97                   else if (curChar == 34)
98                      jjCheckNAddStates(5, 7);
99                   if ((0x3fc000000000000L & l) != 0L)
100                      jjCheckNAddStates(8, 11);
101                   else if (curChar == 49)
102                      jjCheckNAddTwoStates(20, 21);
103                   break;
104                case 19:
105                   if ((0x3fc000000000000L & l) != 0L)
106                      jjCheckNAddStates(8, 11);
107                   break;
108                case 20:
109                   if ((0x3ff000000000000L & l) != 0L)
110                      jjCheckNAdd(17);
111                   break;
112                case 21:
113                   if ((0x3ff000000000000L & l) != 0L)
114                      jjCheckNAdd(18);
115                   break;
116                case 22:
117                   if (curChar == 49)
118                      jjCheckNAddTwoStates(20, 21);
119                   break;
120                case 23:
121                   if (curChar == 34)
122                      jjCheckNAddStates(5, 7);
123                   break;
124                case 24:
125                   if ((0xfffffffbffffffffL & l) != 0L)
126                      jjCheckNAddTwoStates(24, 25);
127                   break;
128                case 25:
129                   if (curChar == 34)
130                      jjstateSet[jjnewStateCnt++] = 26;
131                   break;
132                case 26:
133                   if (curChar == 42 && kind > 18)
134                      kind = 18;
135                   break;
136                case 27:
137                   if ((0xfffffffbffffffffL & l) != 0L)
138                      jjCheckNAddStates(12, 14);
139                   break;
140                case 29:
141                   if (curChar == 34)
142                      jjCheckNAddStates(12, 14);
143                   break;
144                case 30:
145                   if (curChar == 34 && kind > 19)
146                      kind = 19;
147                   break;
148                case 31:
149                   if ((0x7bffe8faffffd9ffL & l) == 0L)
150                      break;
151                   if (kind > 22)
152                      kind = 22;
153                   jjCheckNAddStates(0, 4);
154                   break;
155                case 32:
156                   if ((0x7bffe8faffffd9ffL & l) != 0L)
157                      jjCheckNAddTwoStates(32, 33);
158                   break;
159                case 33:
160                   if (curChar == 42 && kind > 20)
161                      kind = 20;
162                   break;
163                case 34:
164                   if ((0x7bffe8faffffd9ffL & l) != 0L)
165                      jjCheckNAddTwoStates(34, 35);
166                   break;
167                case 35:
168                   if ((0x8000040000000000L & l) == 0L)
169                      break;
170                   if (kind > 21)
171                      kind = 21;
172                   jjCheckNAddTwoStates(35, 36);
173                   break;
174                case 36:
175                   if ((0xfbffecfaffffd9ffL & l) == 0L)
176                      break;
177                   if (kind > 21)
178                      kind = 21;
179                   jjCheckNAdd(36);
180                   break;
181                case 37:
182                   if ((0x7bffe8faffffd9ffL & l) == 0L)
183                      break;
184                   if (kind > 22)
185                      kind = 22;
186                   jjCheckNAdd(37);
187                   break;
188                default : break;
189             }
190          } while(i != startsAt);
191       }
192       else if (curChar < 128)
193       {
194          long l = 1L << (curChar & 077);
195          do
196          {
197             switch(jjstateSet[--i])
198             {
199                case 0:
200                   if ((0xffffffffbfffffffL & l) != 0L)
201                   {
202                      if (kind > 22)
203                         kind = 22;
204                      jjCheckNAddStates(0, 4);
205                   }
206                   if ((0x400000004000L & l) != 0L)
207                   {
208                      if (kind > 12)
209                         kind = 12;
210                   }
211                   else if ((0x80000000800000L & l) != 0L)
212                   {
213                      if (kind > 11)
214                         kind = 11;
215                   }
216                   else if (curChar == 97)
217                      jjstateSet[jjnewStateCnt++] = 9;
218                   else if (curChar == 65)
219                      jjstateSet[jjnewStateCnt++] = 6;
220                   else if (curChar == 111)
221                      jjstateSet[jjnewStateCnt++] = 3;
222                   else if (curChar == 79)
223                      jjstateSet[jjnewStateCnt++] = 1;
224                   if (curChar == 110)
225                      jjstateSet[jjnewStateCnt++] = 15;
226                   else if (curChar == 78)
227                      jjstateSet[jjnewStateCnt++] = 12;
228                   break;
229                case 1:
230                   if (curChar == 82 && kind > 8)
231                      kind = 8;
232                   break;
233                case 2:
234                   if (curChar == 79)
235                      jjstateSet[jjnewStateCnt++] = 1;
236                   break;
237                case 3:
238                   if (curChar == 114 && kind > 8)
239                      kind = 8;
240                   break;
241                case 4:
242                   if (curChar == 111)
243                      jjstateSet[jjnewStateCnt++] = 3;
244                   break;
245                case 5:
246                   if (curChar == 68 && kind > 9)
247                      kind = 9;
248                   break;
249                case 6:
250                   if (curChar == 78)
251                      jjstateSet[jjnewStateCnt++] = 5;
252                   break;
253                case 7:
254                   if (curChar == 65)
255                      jjstateSet[jjnewStateCnt++] = 6;
256                   break;
257                case 8:
258                   if (curChar == 100 && kind > 9)
259                      kind = 9;
260                   break;
261                case 9:
262                   if (curChar == 110)
263                      jjstateSet[jjnewStateCnt++] = 8;
264                   break;
265                case 10:
266                   if (curChar == 97)
267                      jjstateSet[jjnewStateCnt++] = 9;
268                   break;
269                case 11:
270                   if (curChar == 84 && kind > 10)
271                      kind = 10;
272                   break;
273                case 12:
274                   if (curChar == 79)
275                      jjstateSet[jjnewStateCnt++] = 11;
276                   break;
277                case 13:
278                   if (curChar == 78)
279                      jjstateSet[jjnewStateCnt++] = 12;
280                   break;
281                case 14:
282                   if (curChar == 116 && kind > 10)
283                      kind = 10;
284                   break;
285                case 15:
286                   if (curChar == 111)
287                      jjstateSet[jjnewStateCnt++] = 14;
288                   break;
289                case 16:
290                   if (curChar == 110)
291                      jjstateSet[jjnewStateCnt++] = 15;
292                   break;
293                case 17:
294                   if ((0x80000000800000L & l) != 0L && kind > 11)
295                      kind = 11;
296                   break;
297                case 18:
298                   if ((0x400000004000L & l) != 0L && kind > 12)
299                      kind = 12;
300                   break;
301                case 24:
302                   jjAddStates(15, 16);
303                   break;
304                case 27:
305                   if ((0xffffffffefffffffL & l) != 0L)
306                      jjCheckNAddStates(12, 14);
307                   break;
308                case 28:
309                   if (curChar == 92)
310                      jjstateSet[jjnewStateCnt++] = 29;
311                   break;
312                case 29:
313                   if (curChar == 92)
314                      jjCheckNAddStates(12, 14);
315                   break;
316                case 31:
317                   if ((0xffffffffbfffffffL & l) == 0L)
318                      break;
319                   if (kind > 22)
320                      kind = 22;
321                   jjCheckNAddStates(0, 4);
322                   break;
323                case 32:
324                   if ((0xffffffffbfffffffL & l) != 0L)
325                      jjCheckNAddTwoStates(32, 33);
326                   break;
327                case 34:
328                   if ((0xffffffffbfffffffL & l) != 0L)
329                      jjCheckNAddTwoStates(34, 35);
330                   break;
331                case 36:
332                   if ((0xffffffffbfffffffL & l) == 0L)
333                      break;
334                   if (kind > 21)
335                      kind = 21;
336                   jjstateSet[jjnewStateCnt++] = 36;
337                   break;
338                case 37:
339                   if ((0xffffffffbfffffffL & l) == 0L)
340                      break;
341                   if (kind > 22)
342                      kind = 22;
343                   jjCheckNAdd(37);
344                   break;
345                default : break;
346             }
347          } while(i != startsAt);
348       }
349       else
350       {
351          int hiByte = (int)(curChar >> 8);
352          int i1 = hiByte >> 6;
353          long l1 = 1L << (hiByte & 077);
354          int i2 = (curChar & 0xff) >> 6;
355          long l2 = 1L << (curChar & 077);
356          do
357          {
358             switch(jjstateSet[--i])
359             {
360                case 0:
361                   if (!jjCanMove_0(hiByte, i1, i2, l1, l2))
362                      break;
363                   if (kind > 22)
364                      kind = 22;
365                   jjCheckNAddStates(0, 4);
366                   break;
367                case 24:
368                   if (jjCanMove_0(hiByte, i1, i2, l1, l2))
369                      jjAddStates(15, 16);
370                   break;
371                case 27:
372                   if (jjCanMove_0(hiByte, i1, i2, l1, l2))
373                      jjAddStates(12, 14);
374                   break;
375                case 32:
376                   if (jjCanMove_0(hiByte, i1, i2, l1, l2))
377                      jjCheckNAddTwoStates(32, 33);
378                   break;
379                case 34:
380                   if (jjCanMove_0(hiByte, i1, i2, l1, l2))
381                      jjCheckNAddTwoStates(34, 35);
382                   break;
383                case 36:
384                   if (!jjCanMove_0(hiByte, i1, i2, l1, l2))
385                      break;
386                   if (kind > 21)
387                      kind = 21;
388                   jjstateSet[jjnewStateCnt++] = 36;
389                   break;
390                case 37:
391                   if (!jjCanMove_0(hiByte, i1, i2, l1, l2))
392                      break;
393                   if (kind > 22)
394                      kind = 22;
395                   jjCheckNAdd(37);
396                   break;
397                default : break;
398             }
399          } while(i != startsAt);
400       }
401       if (kind != 0x7fffffff)
402       {
403          jjmatchedKind = kind;
404          jjmatchedPos = curPos;
405          kind = 0x7fffffff;
406       }
407       ++curPos;
408       if ((i = jjnewStateCnt) == (startsAt = 38 - (jjnewStateCnt = startsAt)))
409          return curPos;
410       try { curChar = input_stream.readChar(); }
411       catch(java.io.IOException e) { return curPos; }
412    }
413 }
414 private int jjMoveStringLiteralDfa0_0()
415 {
416    return jjMoveNfa_0(0, 0);
417 }
418 private int jjMoveNfa_0(int startState, int curPos)
419 {
420    int startsAt = 0;
421    jjnewStateCnt = 3;
422    int i = 1;
423    jjstateSet[0] = startState;
424    int kind = 0x7fffffff;
425    for (;;)
426    {
427       if (++jjround == 0x7fffffff)
428          ReInitRounds();
429       if (curChar < 64)
430       {
431          long l = 1L << curChar;
432          do
433          {
434             switch(jjstateSet[--i])
435             {
436                case 0:
437                   if ((0x3ff000000000000L & l) == 0L)
438                      break;
439                   if (kind > 23)
440                      kind = 23;
441                   jjAddStates(17, 18);
442                   break;
443                case 1:
444                   if (curChar == 46)
445                      jjCheckNAdd(2);
446                   break;
447                case 2:
448                   if ((0x3ff000000000000L & l) == 0L)
449                      break;
450                   if (kind > 23)
451                      kind = 23;
452                   jjCheckNAdd(2);
453                   break;
454                default : break;
455             }
456          } while(i != startsAt);
457       }
458       else if (curChar < 128)
459       {
460          long l = 1L << (curChar & 077);
461          do
462          {
463             switch(jjstateSet[--i])
464             {
465                default : break;
466             }
467          } while(i != startsAt);
468       }
469       else
470       {
471          int hiByte = (int)(curChar >> 8);
472          int i1 = hiByte >> 6;
473          long l1 = 1L << (hiByte & 077);
474          int i2 = (curChar & 0xff) >> 6;
475          long l2 = 1L << (curChar & 077);
476          do
477          {
478             switch(jjstateSet[--i])
479             {
480                default : break;
481             }
482          } while(i != startsAt);
483       }
484       if (kind != 0x7fffffff)
485       {
486          jjmatchedKind = kind;
487          jjmatchedPos = curPos;
488          kind = 0x7fffffff;
489       }
490       ++curPos;
491       if ((i = jjnewStateCnt) == (startsAt = 3 - (jjnewStateCnt = startsAt)))
492          return curPos;
493       try { curChar = input_stream.readChar(); }
494       catch(java.io.IOException e) { return curPos; }
495    }
496 }
497 static final int[] jjnextStates = {
498    32, 33, 34, 35, 37, 24, 27, 28, 20, 17, 21, 18, 27, 28, 30, 24, 
499    25, 0, 1, 
500 };
501 private static final boolean jjCanMove_0(int hiByte, int i1, int i2, long l1, long l2)
502 {
503    switch(hiByte)
504    {
505       case 0:
506          return ((jjbitVec2[i2] & l2) != 0L);
507       default :
508          if ((jjbitVec0[i1] & l1) != 0L)
509             return true;
510          return false;
511    }
512 }
513
514 /** Token literal values. */
515 public static final String[] jjstrLiteralImages = {
516 "", null, null, null, null, null, null, null, null, null, null, null, null, 
517 "\50", "\51", "\54", "\72", "\136", null, null, null, null, null, null, };
518
519 /** Lexer state names. */
520 public static final String[] lexStateNames = {
521    "Boost",
522    "DEFAULT",
523 };
524
525 /** Lex State array. */
526 public static final int[] jjnewLexState = {
527    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, -1, -1, -1, -1, 1, 
528 };
529 static final long[] jjtoToken = {
530    0xffff01L, 
531 };
532 static final long[] jjtoSkip = {
533    0x80L, 
534 };
535 protected CharStream input_stream;
536 private final int[] jjrounds = new int[38];
537 private final int[] jjstateSet = new int[76];
538 protected char curChar;
539 /** Constructor. */
540 public QueryParserTokenManager(CharStream stream){
541    input_stream = stream;
542 }
543
544 /** Constructor. */
545 public QueryParserTokenManager(CharStream stream, int lexState){
546    this(stream);
547    SwitchTo(lexState);
548 }
549
550 /** Reinitialise parser. */
551 public void ReInit(CharStream stream)
552 {
553    jjmatchedPos = jjnewStateCnt = 0;
554    curLexState = defaultLexState;
555    input_stream = stream;
556    ReInitRounds();
557 }
558 private void ReInitRounds()
559 {
560    int i;
561    jjround = 0x80000001;
562    for (i = 38; i-- > 0;)
563       jjrounds[i] = 0x80000000;
564 }
565
566 /** Reinitialise parser. */
567 public void ReInit(CharStream stream, int lexState)
568 {
569    ReInit(stream);
570    SwitchTo(lexState);
571 }
572
573 /** Switch to specified lex state. */
574 public void SwitchTo(int lexState)
575 {
576    if (lexState >= 2 || lexState < 0)
577       throw new TokenMgrError("Error: Ignoring invalid lexical state : " + lexState + ". State unchanged.", TokenMgrError.INVALID_LEXICAL_STATE);
578    else
579       curLexState = lexState;
580 }
581
582 protected Token jjFillToken()
583 {
584    final Token t;
585    final String curTokenImage;
586    final int beginLine;
587    final int endLine;
588    final int beginColumn;
589    final int endColumn;
590    String im = jjstrLiteralImages[jjmatchedKind];
591    curTokenImage = (im == null) ? input_stream.GetImage() : im;
592    beginLine = input_stream.getBeginLine();
593    beginColumn = input_stream.getBeginColumn();
594    endLine = input_stream.getEndLine();
595    endColumn = input_stream.getEndColumn();
596    t = Token.newToken(jjmatchedKind, curTokenImage);
597
598    t.beginLine = beginLine;
599    t.endLine = endLine;
600    t.beginColumn = beginColumn;
601    t.endColumn = endColumn;
602
603    return t;
604 }
605
606 int curLexState = 1;
607 int defaultLexState = 1;
608 int jjnewStateCnt;
609 int jjround;
610 int jjmatchedPos;
611 int jjmatchedKind;
612
613 /** Get the next Token. */
614 public Token getNextToken() 
615 {
616   Token matchedToken;
617   int curPos = 0;
618
619   EOFLoop :
620   for (;;)
621   {
622    try
623    {
624       curChar = input_stream.BeginToken();
625    }
626    catch(java.io.IOException e)
627    {
628       jjmatchedKind = 0;
629       matchedToken = jjFillToken();
630       return matchedToken;
631    }
632
633    switch(curLexState)
634    {
635      case 0:
636        jjmatchedKind = 0x7fffffff;
637        jjmatchedPos = 0;
638        curPos = jjMoveStringLiteralDfa0_0();
639        break;
640      case 1:
641        jjmatchedKind = 0x7fffffff;
642        jjmatchedPos = 0;
643        curPos = jjMoveStringLiteralDfa0_1();
644        break;
645    }
646      if (jjmatchedKind != 0x7fffffff)
647      {
648         if (jjmatchedPos + 1 < curPos)
649            input_stream.backup(curPos - jjmatchedPos - 1);
650         if ((jjtoToken[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L)
651         {
652            matchedToken = jjFillToken();
653        if (jjnewLexState[jjmatchedKind] != -1)
654          curLexState = jjnewLexState[jjmatchedKind];
655            return matchedToken;
656         }
657         else
658         {
659          if (jjnewLexState[jjmatchedKind] != -1)
660            curLexState = jjnewLexState[jjmatchedKind];
661            continue EOFLoop;
662         }
663      }
664      int error_line = input_stream.getEndLine();
665      int error_column = input_stream.getEndColumn();
666      String error_after = null;
667      boolean EOFSeen = false;
668      try { input_stream.readChar(); input_stream.backup(1); }
669      catch (java.io.IOException e1) {
670         EOFSeen = true;
671         error_after = curPos <= 1 ? "" : input_stream.GetImage();
672         if (curChar == '\n' || curChar == '\r') {
673            error_line++;
674            error_column = 0;
675         }
676         else
677            error_column++;
678      }
679      if (!EOFSeen) {
680         input_stream.backup(1);
681         error_after = curPos <= 1 ? "" : input_stream.GetImage();
682      }
683      throw new TokenMgrError(EOFSeen, curLexState, error_line, error_column, error_after, curChar, TokenMgrError.LEXICAL_ERROR);
684   }
685 }
686
687 private void jjCheckNAdd(int state)
688 {
689    if (jjrounds[state] != jjround)
690    {
691       jjstateSet[jjnewStateCnt++] = state;
692       jjrounds[state] = jjround;
693    }
694 }
695 private void jjAddStates(int start, int end)
696 {
697    do {
698       jjstateSet[jjnewStateCnt++] = jjnextStates[start];
699    } while (start++ != end);
700 }
701 private void jjCheckNAddTwoStates(int state1, int state2)
702 {
703    jjCheckNAdd(state1);
704    jjCheckNAdd(state2);
705 }
706
707 private void jjCheckNAddStates(int start, int end)
708 {
709    do {
710       jjCheckNAdd(jjnextStates[start]);
711    } while (start++ != end);
712 }
713
714 }