1 /* Generated By:JavaCC: Do not edit this line. QueryParserTokenManager.java */
2 package org.apache.lucene.queryParser;
3 import java.io.IOException;
4 import java.io.StringReader;
5 import java.text.Collator;
6 import java.text.DateFormat;
7 import java.util.ArrayList;
8 import java.util.Calendar;
10 import java.util.HashMap;
11 import java.util.List;
12 import java.util.Locale;
14 import org.apache.lucene.analysis.Analyzer;
15 import org.apache.lucene.analysis.CachingTokenFilter;
16 import org.apache.lucene.analysis.TokenStream;
17 import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute;
18 import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
19 import org.apache.lucene.document.DateField;
20 import org.apache.lucene.document.DateTools;
21 import org.apache.lucene.index.Term;
22 import org.apache.lucene.search.BooleanClause;
23 import org.apache.lucene.search.BooleanQuery;
24 import org.apache.lucene.search.FuzzyQuery;
25 import org.apache.lucene.search.MultiTermQuery;
26 import org.apache.lucene.search.MatchAllDocsQuery;
27 import org.apache.lucene.search.MultiPhraseQuery;
28 import org.apache.lucene.search.PhraseQuery;
29 import org.apache.lucene.search.PrefixQuery;
30 import org.apache.lucene.search.Query;
31 import org.apache.lucene.search.TermRangeQuery;
32 import org.apache.lucene.search.TermQuery;
33 import org.apache.lucene.search.WildcardQuery;
34 import org.apache.lucene.util.Version;
35 import org.apache.lucene.util.VirtualMethod;
38 public class QueryParserTokenManager implements QueryParserConstants
42 public java.io.PrintStream debugStream = System.out;
43 /** Set debug output. */
44 public void setDebugStream(java.io.PrintStream ds) { debugStream = ds; }
45 private final int jjStopStringLiteralDfa_3(int pos, long active0)
53 private final int jjStartNfa_3(int pos, long active0)
55 return jjMoveNfa_3(jjStopStringLiteralDfa_3(pos, active0), pos + 1);
57 private int jjStopAtPos(int pos, int kind)
63 private int jjMoveStringLiteralDfa0_3()
68 return jjStopAtPos(0, 13);
70 return jjStopAtPos(0, 14);
72 return jjStartNfaWithStates_3(0, 16, 36);
74 return jjStopAtPos(0, 11);
76 return jjStopAtPos(0, 12);
78 return jjStopAtPos(0, 15);
80 return jjStopAtPos(0, 23);
82 return jjStopAtPos(0, 17);
84 return jjStopAtPos(0, 24);
86 return jjMoveNfa_3(0, 0);
89 private int jjStartNfaWithStates_3(int pos, int kind, int state)
93 try { curChar = input_stream.readChar(); }
94 catch(java.io.IOException e) { return pos + 1; }
95 return jjMoveNfa_3(state, pos + 1);
97 static final long[] jjbitVec0 = {
98 0x1L, 0x0L, 0x0L, 0x0L
100 static final long[] jjbitVec1 = {
101 0xfffffffffffffffeL, 0xffffffffffffffffL, 0xffffffffffffffffL, 0xffffffffffffffffL
103 static final long[] jjbitVec3 = {
104 0x0L, 0x0L, 0xffffffffffffffffL, 0xffffffffffffffffL
106 static final long[] jjbitVec4 = {
107 0xfffefffffffffffeL, 0xffffffffffffffffL, 0xffffffffffffffffL, 0xffffffffffffffffL
109 private int jjMoveNfa_3(int startState, int curPos)
114 jjstateSet[0] = startState;
115 int kind = 0x7fffffff;
118 if (++jjround == 0x7fffffff)
122 long l = 1L << curChar;
125 switch(jjstateSet[--i])
129 if ((0xfbfffcf8ffffd9ffL & l) == 0L)
133 jjCheckNAddTwoStates(25, 26);
136 if ((0xfbffd4f8ffffd9ffL & l) != 0L)
140 jjCheckNAddTwoStates(25, 26);
142 else if ((0x100002600L & l) != 0L)
147 else if (curChar == 34)
148 jjCheckNAddStates(0, 2);
149 else if (curChar == 33)
154 if ((0x7bffd0f8ffffd9ffL & l) != 0L)
158 jjCheckNAddStates(3, 7);
160 else if (curChar == 42)
166 jjstateSet[jjnewStateCnt++] = 4;
169 if (curChar == 38 && kind > 8)
174 jjstateSet[jjnewStateCnt++] = 4;
177 if (curChar == 33 && kind > 10)
182 jjCheckNAddStates(0, 2);
185 if ((0xfffffffbffffffffL & l) != 0L)
186 jjCheckNAddStates(0, 2);
189 jjCheckNAddStates(0, 2);
192 if (curChar == 34 && kind > 18)
196 if ((0x3ff000000000000L & l) == 0L)
207 if ((0x3ff000000000000L & l) == 0L)
214 if (curChar == 42 && kind > 21)
218 if ((0xfbffd4f8ffffd9ffL & l) == 0L)
222 jjCheckNAddTwoStates(25, 26);
227 jjCheckNAddTwoStates(25, 26);
230 if ((0x7bffd0f8ffffd9ffL & l) == 0L)
234 jjCheckNAddStates(3, 7);
237 if ((0x7bfff8f8ffffd9ffL & l) == 0L)
241 jjCheckNAddTwoStates(29, 30);
246 jjCheckNAddTwoStates(29, 30);
249 if ((0x7bfff8f8ffffd9ffL & l) != 0L)
250 jjCheckNAddStates(10, 12);
253 jjCheckNAddStates(10, 12);
257 } while(i != startsAt);
259 else if (curChar < 128)
261 long l = 1L << (curChar & 077);
264 switch(jjstateSet[--i])
267 if ((0x97ffffff87ffffffL & l) != 0L)
271 jjCheckNAddTwoStates(25, 26);
273 else if (curChar == 92)
274 jjCheckNAddTwoStates(27, 27);
277 if ((0x97ffffff87ffffffL & l) != 0L)
281 jjCheckNAddStates(3, 7);
283 else if (curChar == 92)
284 jjCheckNAddStates(13, 15);
285 else if (curChar == 126)
289 jjstateSet[jjnewStateCnt++] = 20;
291 if ((0x97ffffff87ffffffL & l) != 0L)
295 jjCheckNAddTwoStates(25, 26);
298 jjstateSet[jjnewStateCnt++] = 11;
299 else if (curChar == 124)
300 jjstateSet[jjnewStateCnt++] = 8;
301 else if (curChar == 79)
302 jjstateSet[jjnewStateCnt++] = 6;
303 else if (curChar == 65)
304 jjstateSet[jjnewStateCnt++] = 2;
307 if (curChar == 68 && kind > 8)
312 jjstateSet[jjnewStateCnt++] = 1;
316 jjstateSet[jjnewStateCnt++] = 2;
319 if (curChar == 82 && kind > 9)
324 jjstateSet[jjnewStateCnt++] = 6;
327 if (curChar == 124 && kind > 9)
332 jjstateSet[jjnewStateCnt++] = 8;
335 if (curChar == 84 && kind > 10)
340 jjstateSet[jjnewStateCnt++] = 10;
344 jjstateSet[jjnewStateCnt++] = 11;
347 if ((0xffffffffefffffffL & l) != 0L)
348 jjCheckNAddStates(0, 2);
352 jjstateSet[jjnewStateCnt++] = 17;
355 jjCheckNAddStates(0, 2);
362 jjstateSet[jjnewStateCnt++] = 20;
365 if ((0x97ffffff87ffffffL & l) == 0L)
369 jjCheckNAddTwoStates(25, 26);
372 if ((0x97ffffff87ffffffL & l) == 0L)
376 jjCheckNAddTwoStates(25, 26);
380 jjCheckNAddTwoStates(27, 27);
385 jjCheckNAddTwoStates(25, 26);
388 if ((0x97ffffff87ffffffL & l) == 0L)
392 jjCheckNAddStates(3, 7);
395 if ((0x97ffffff87ffffffL & l) == 0L)
399 jjCheckNAddTwoStates(29, 30);
403 jjCheckNAddTwoStates(31, 31);
408 jjCheckNAddTwoStates(29, 30);
411 if ((0x97ffffff87ffffffL & l) != 0L)
412 jjCheckNAddStates(10, 12);
416 jjCheckNAddTwoStates(34, 34);
419 jjCheckNAddStates(10, 12);
423 jjCheckNAddStates(13, 15);
427 } while(i != startsAt);
431 int hiByte = (int)(curChar >> 8);
432 int i1 = hiByte >> 6;
433 long l1 = 1L << (hiByte & 077);
434 int i2 = (curChar & 0xff) >> 6;
435 long l2 = 1L << (curChar & 077);
438 switch(jjstateSet[--i])
442 if (!jjCanMove_2(hiByte, i1, i2, l1, l2))
446 jjCheckNAddTwoStates(25, 26);
449 if (jjCanMove_0(hiByte, i1, i2, l1, l2))
454 if (jjCanMove_2(hiByte, i1, i2, l1, l2))
458 jjCheckNAddTwoStates(25, 26);
460 if (jjCanMove_2(hiByte, i1, i2, l1, l2))
464 jjCheckNAddStates(3, 7);
469 if (jjCanMove_1(hiByte, i1, i2, l1, l2))
470 jjCheckNAddStates(0, 2);
473 if (!jjCanMove_2(hiByte, i1, i2, l1, l2))
477 jjCheckNAddTwoStates(25, 26);
480 if (!jjCanMove_1(hiByte, i1, i2, l1, l2))
484 jjCheckNAddTwoStates(25, 26);
487 if (!jjCanMove_2(hiByte, i1, i2, l1, l2))
491 jjCheckNAddStates(3, 7);
494 if (!jjCanMove_2(hiByte, i1, i2, l1, l2))
498 jjCheckNAddTwoStates(29, 30);
501 if (!jjCanMove_1(hiByte, i1, i2, l1, l2))
505 jjCheckNAddTwoStates(29, 30);
508 if (jjCanMove_2(hiByte, i1, i2, l1, l2))
509 jjCheckNAddStates(10, 12);
512 if (jjCanMove_1(hiByte, i1, i2, l1, l2))
513 jjCheckNAddStates(10, 12);
517 } while(i != startsAt);
519 if (kind != 0x7fffffff)
521 jjmatchedKind = kind;
522 jjmatchedPos = curPos;
526 if ((i = jjnewStateCnt) == (startsAt = 36 - (jjnewStateCnt = startsAt)))
528 try { curChar = input_stream.readChar(); }
529 catch(java.io.IOException e) { return curPos; }
532 private final int jjStopStringLiteralDfa_1(int pos, long active0)
537 if ((active0 & 0x40000000L) != 0L)
547 private final int jjStartNfa_1(int pos, long active0)
549 return jjMoveNfa_1(jjStopStringLiteralDfa_1(pos, active0), pos + 1);
551 private int jjMoveStringLiteralDfa0_1()
556 return jjMoveStringLiteralDfa1_1(0x40000000L);
558 return jjStopAtPos(0, 31);
560 return jjMoveNfa_1(0, 0);
563 private int jjMoveStringLiteralDfa1_1(long active0)
565 try { curChar = input_stream.readChar(); }
566 catch(java.io.IOException e) {
567 jjStopStringLiteralDfa_1(0, active0);
573 if ((active0 & 0x40000000L) != 0L)
574 return jjStartNfaWithStates_1(1, 30, 6);
579 return jjStartNfa_1(0, active0);
581 private int jjStartNfaWithStates_1(int pos, int kind, int state)
583 jjmatchedKind = kind;
585 try { curChar = input_stream.readChar(); }
586 catch(java.io.IOException e) { return pos + 1; }
587 return jjMoveNfa_1(state, pos + 1);
589 private int jjMoveNfa_1(int startState, int curPos)
594 jjstateSet[0] = startState;
595 int kind = 0x7fffffff;
598 if (++jjround == 0x7fffffff)
602 long l = 1L << curChar;
605 switch(jjstateSet[--i])
608 if ((0xfffffffeffffffffL & l) != 0L)
614 if ((0x100002600L & l) != 0L)
619 else if (curChar == 34)
620 jjCheckNAddTwoStates(2, 4);
624 jjCheckNAddTwoStates(2, 4);
627 if ((0xfffffffbffffffffL & l) != 0L)
628 jjCheckNAddStates(16, 18);
632 jjCheckNAddStates(16, 18);
635 if (curChar == 34 && kind > 32)
639 if ((0xfffffffeffffffffL & l) == 0L)
647 } while(i != startsAt);
649 else if (curChar < 128)
651 long l = 1L << (curChar & 077);
654 switch(jjstateSet[--i])
658 if ((0xdfffffffffffffffL & l) == 0L)
669 jjstateSet[jjnewStateCnt++] = 3;
673 } while(i != startsAt);
677 int hiByte = (int)(curChar >> 8);
678 int i1 = hiByte >> 6;
679 long l1 = 1L << (hiByte & 077);
680 int i2 = (curChar & 0xff) >> 6;
681 long l2 = 1L << (curChar & 077);
684 switch(jjstateSet[--i])
687 if (jjCanMove_0(hiByte, i1, i2, l1, l2))
692 if (jjCanMove_1(hiByte, i1, i2, l1, l2))
700 if (jjCanMove_1(hiByte, i1, i2, l1, l2))
704 if (!jjCanMove_1(hiByte, i1, i2, l1, l2))
712 } while(i != startsAt);
714 if (kind != 0x7fffffff)
716 jjmatchedKind = kind;
717 jjmatchedPos = curPos;
721 if ((i = jjnewStateCnt) == (startsAt = 7 - (jjnewStateCnt = startsAt)))
723 try { curChar = input_stream.readChar(); }
724 catch(java.io.IOException e) { return curPos; }
727 private int jjMoveStringLiteralDfa0_0()
729 return jjMoveNfa_0(0, 0);
731 private int jjMoveNfa_0(int startState, int curPos)
736 jjstateSet[0] = startState;
737 int kind = 0x7fffffff;
740 if (++jjround == 0x7fffffff)
744 long l = 1L << curChar;
747 switch(jjstateSet[--i])
750 if ((0x3ff000000000000L & l) == 0L)
761 if ((0x3ff000000000000L & l) == 0L)
769 } while(i != startsAt);
771 else if (curChar < 128)
773 long l = 1L << (curChar & 077);
776 switch(jjstateSet[--i])
780 } while(i != startsAt);
784 int hiByte = (int)(curChar >> 8);
785 int i1 = hiByte >> 6;
786 long l1 = 1L << (hiByte & 077);
787 int i2 = (curChar & 0xff) >> 6;
788 long l2 = 1L << (curChar & 077);
791 switch(jjstateSet[--i])
795 } while(i != startsAt);
797 if (kind != 0x7fffffff)
799 jjmatchedKind = kind;
800 jjmatchedPos = curPos;
804 if ((i = jjnewStateCnt) == (startsAt = 3 - (jjnewStateCnt = startsAt)))
806 try { curChar = input_stream.readChar(); }
807 catch(java.io.IOException e) { return curPos; }
810 private final int jjStopStringLiteralDfa_2(int pos, long active0)
815 if ((active0 & 0x4000000L) != 0L)
825 private final int jjStartNfa_2(int pos, long active0)
827 return jjMoveNfa_2(jjStopStringLiteralDfa_2(pos, active0), pos + 1);
829 private int jjMoveStringLiteralDfa0_2()
834 return jjMoveStringLiteralDfa1_2(0x4000000L);
836 return jjStopAtPos(0, 27);
838 return jjMoveNfa_2(0, 0);
841 private int jjMoveStringLiteralDfa1_2(long active0)
843 try { curChar = input_stream.readChar(); }
844 catch(java.io.IOException e) {
845 jjStopStringLiteralDfa_2(0, active0);
851 if ((active0 & 0x4000000L) != 0L)
852 return jjStartNfaWithStates_2(1, 26, 6);
857 return jjStartNfa_2(0, active0);
859 private int jjStartNfaWithStates_2(int pos, int kind, int state)
861 jjmatchedKind = kind;
863 try { curChar = input_stream.readChar(); }
864 catch(java.io.IOException e) { return pos + 1; }
865 return jjMoveNfa_2(state, pos + 1);
867 private int jjMoveNfa_2(int startState, int curPos)
872 jjstateSet[0] = startState;
873 int kind = 0x7fffffff;
876 if (++jjround == 0x7fffffff)
880 long l = 1L << curChar;
883 switch(jjstateSet[--i])
886 if ((0xfffffffeffffffffL & l) != 0L)
892 if ((0x100002600L & l) != 0L)
897 else if (curChar == 34)
898 jjCheckNAddTwoStates(2, 4);
902 jjCheckNAddTwoStates(2, 4);
905 if ((0xfffffffbffffffffL & l) != 0L)
906 jjCheckNAddStates(16, 18);
910 jjCheckNAddStates(16, 18);
913 if (curChar == 34 && kind > 28)
917 if ((0xfffffffeffffffffL & l) == 0L)
925 } while(i != startsAt);
927 else if (curChar < 128)
929 long l = 1L << (curChar & 077);
932 switch(jjstateSet[--i])
936 if ((0xffffffffdfffffffL & l) == 0L)
947 jjstateSet[jjnewStateCnt++] = 3;
951 } while(i != startsAt);
955 int hiByte = (int)(curChar >> 8);
956 int i1 = hiByte >> 6;
957 long l1 = 1L << (hiByte & 077);
958 int i2 = (curChar & 0xff) >> 6;
959 long l2 = 1L << (curChar & 077);
962 switch(jjstateSet[--i])
965 if (jjCanMove_0(hiByte, i1, i2, l1, l2))
970 if (jjCanMove_1(hiByte, i1, i2, l1, l2))
978 if (jjCanMove_1(hiByte, i1, i2, l1, l2))
982 if (!jjCanMove_1(hiByte, i1, i2, l1, l2))
990 } while(i != startsAt);
992 if (kind != 0x7fffffff)
994 jjmatchedKind = kind;
995 jjmatchedPos = curPos;
999 if ((i = jjnewStateCnt) == (startsAt = 7 - (jjnewStateCnt = startsAt)))
1001 try { curChar = input_stream.readChar(); }
1002 catch(java.io.IOException e) { return curPos; }
1005 static final int[] jjnextStates = {
1006 15, 16, 18, 29, 32, 23, 33, 30, 20, 21, 32, 23, 33, 31, 34, 27,
1009 private static final boolean jjCanMove_0(int hiByte, int i1, int i2, long l1, long l2)
1014 return ((jjbitVec0[i2] & l2) != 0L);
1019 private static final boolean jjCanMove_1(int hiByte, int i1, int i2, long l1, long l2)
1024 return ((jjbitVec3[i2] & l2) != 0L);
1026 if ((jjbitVec1[i1] & l1) != 0L)
1031 private static final boolean jjCanMove_2(int hiByte, int i1, int i2, long l1, long l2)
1036 return ((jjbitVec3[i2] & l2) != 0L);
1038 return ((jjbitVec1[i2] & l2) != 0L);
1040 if ((jjbitVec4[i1] & l1) != 0L)
1046 /** Token literal values. */
1047 public static final String[] jjstrLiteralImages = {
1048 "", null, null, null, null, null, null, null, null, null, null, "\53", "\55",
1049 "\50", "\51", "\72", "\52", "\136", null, null, null, null, null, "\133", "\173",
1050 null, "\124\117", "\135", null, null, "\124\117", "\175", null, null, };
1052 /** Lexer state names. */
1053 public static final String[] lexStateNames = {
1060 /** Lex State array. */
1061 public static final int[] jjnewLexState = {
1062 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, -1, -1, -1, -1, 2, 1,
1063 3, -1, 3, -1, -1, -1, 3, -1, -1,
1065 static final long[] jjtoToken = {
1068 static final long[] jjtoSkip = {
1071 protected CharStream input_stream;
1072 private final int[] jjrounds = new int[36];
1073 private final int[] jjstateSet = new int[72];
1074 protected char curChar;
1076 public QueryParserTokenManager(CharStream stream){
1077 input_stream = stream;
1081 public QueryParserTokenManager(CharStream stream, int lexState){
1086 /** Reinitialise parser. */
1087 public void ReInit(CharStream stream)
1089 jjmatchedPos = jjnewStateCnt = 0;
1090 curLexState = defaultLexState;
1091 input_stream = stream;
1094 private void ReInitRounds()
1097 jjround = 0x80000001;
1098 for (i = 36; i-- > 0;)
1099 jjrounds[i] = 0x80000000;
1102 /** Reinitialise parser. */
1103 public void ReInit(CharStream stream, int lexState)
1109 /** Switch to specified lex state. */
1110 public void SwitchTo(int lexState)
1112 if (lexState >= 4 || lexState < 0)
1113 throw new TokenMgrError("Error: Ignoring invalid lexical state : " + lexState + ". State unchanged.", TokenMgrError.INVALID_LEXICAL_STATE);
1115 curLexState = lexState;
1118 protected Token jjFillToken()
1121 final String curTokenImage;
1122 final int beginLine;
1124 final int beginColumn;
1125 final int endColumn;
1126 String im = jjstrLiteralImages[jjmatchedKind];
1127 curTokenImage = (im == null) ? input_stream.GetImage() : im;
1128 beginLine = input_stream.getBeginLine();
1129 beginColumn = input_stream.getBeginColumn();
1130 endLine = input_stream.getEndLine();
1131 endColumn = input_stream.getEndColumn();
1132 t = Token.newToken(jjmatchedKind, curTokenImage);
1134 t.beginLine = beginLine;
1135 t.endLine = endLine;
1136 t.beginColumn = beginColumn;
1137 t.endColumn = endColumn;
1142 int curLexState = 3;
1143 int defaultLexState = 3;
1149 /** Get the next Token. */
1150 public Token getNextToken()
1160 curChar = input_stream.BeginToken();
1162 catch(java.io.IOException e)
1165 matchedToken = jjFillToken();
1166 return matchedToken;
1172 jjmatchedKind = 0x7fffffff;
1174 curPos = jjMoveStringLiteralDfa0_0();
1177 jjmatchedKind = 0x7fffffff;
1179 curPos = jjMoveStringLiteralDfa0_1();
1182 jjmatchedKind = 0x7fffffff;
1184 curPos = jjMoveStringLiteralDfa0_2();
1187 jjmatchedKind = 0x7fffffff;
1189 curPos = jjMoveStringLiteralDfa0_3();
1192 if (jjmatchedKind != 0x7fffffff)
1194 if (jjmatchedPos + 1 < curPos)
1195 input_stream.backup(curPos - jjmatchedPos - 1);
1196 if ((jjtoToken[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L)
1198 matchedToken = jjFillToken();
1199 if (jjnewLexState[jjmatchedKind] != -1)
1200 curLexState = jjnewLexState[jjmatchedKind];
1201 return matchedToken;
1205 if (jjnewLexState[jjmatchedKind] != -1)
1206 curLexState = jjnewLexState[jjmatchedKind];
1210 int error_line = input_stream.getEndLine();
1211 int error_column = input_stream.getEndColumn();
1212 String error_after = null;
1213 boolean EOFSeen = false;
1214 try { input_stream.readChar(); input_stream.backup(1); }
1215 catch (java.io.IOException e1) {
1217 error_after = curPos <= 1 ? "" : input_stream.GetImage();
1218 if (curChar == '\n' || curChar == '\r') {
1226 input_stream.backup(1);
1227 error_after = curPos <= 1 ? "" : input_stream.GetImage();
1229 throw new TokenMgrError(EOFSeen, curLexState, error_line, error_column, error_after, curChar, TokenMgrError.LEXICAL_ERROR);
1233 private void jjCheckNAdd(int state)
1235 if (jjrounds[state] != jjround)
1237 jjstateSet[jjnewStateCnt++] = state;
1238 jjrounds[state] = jjround;
1241 private void jjAddStates(int start, int end)
1244 jjstateSet[jjnewStateCnt++] = jjnextStates[start];
1245 } while (start++ != end);
1247 private void jjCheckNAddTwoStates(int state1, int state2)
1249 jjCheckNAdd(state1);
1250 jjCheckNAdd(state2);
1253 private void jjCheckNAddStates(int start, int end)
1256 jjCheckNAdd(jjnextStates[start]);
1257 } while (start++ != end);