3 using Lucene
.Net
.Index
;
4 using Lucene
.Net
.Analysis
;
5 using Lucene
.Net
.Documents
;
6 using Lucene
.Net
.Search
;
8 namespace Lucene
.Net
.QueryParsers
10 public class QueryParserTokenManager
: QueryParserConstants
12 public TextWriter debugStream
= Console
.Out
;
13 public void setDebugStream(TextWriter ds
) { debugStream = ds; }
14 private int jjStopStringLiteralDfa_3(int pos
, long active0
)
22 private int jjStartNfa_3(int pos
, long active0
)
24 return jjMoveNfa_3(jjStopStringLiteralDfa_3(pos
, active0
), pos
+ 1);
26 private int jjStopAtPos(int pos
, int kind
)
32 private int jjStartNfaWithStates_3(int pos
, int kind
, int state
)
36 try { curChar = input_stream.ReadChar(); }
37 catch(IOException
) { return pos + 1; }
38 return jjMoveNfa_3(state
, pos
+ 1);
40 private int jjMoveStringLiteralDfa0_3()
45 return jjStopAtPos(0, 12);
47 return jjStopAtPos(0, 13);
49 return jjStopAtPos(0, 10);
51 return jjStopAtPos(0, 11);
53 return jjStopAtPos(0, 14);
55 return jjStopAtPos(0, 22);
57 return jjStopAtPos(0, 15);
59 return jjStopAtPos(0, 23);
61 return jjStartNfaWithStates_3(0, 18, 18);
63 return jjMoveNfa_3(0, 0);
66 private void jjCheckNAdd(int state
)
68 if (jjrounds
[state
] != jjround
)
70 jjstateSet
[jjnewStateCnt
++] = state
;
71 jjrounds
[state
] = jjround
;
74 private void jjAddStates(int start
, int end
)
78 jjstateSet
[jjnewStateCnt
++] = jjnextStates
[start
];
79 } while (start
++ != end
);
81 private void jjCheckNAddTwoStates(int state1
, int state2
)
86 private void jjCheckNAddStates(int start
, int end
)
90 jjCheckNAdd(jjnextStates
[start
]);
91 } while (start
++ != end
);
93 private void jjCheckNAddStates(int start
)
95 jjCheckNAdd(jjnextStates
[start
]);
96 jjCheckNAdd(jjnextStates
[start
+ 1]);
98 static ulong[] jjbitVec0
= {
99 0xfffffffffffffffeUL
, 0xffffffffffffffffUL
, 0xffffffffffffffffUL
, 0xffffffffffffffffUL
101 static ulong[] jjbitVec2
= {
102 0x0UL
, 0x0UL
, 0xffffffffffffffffUL
, 0xffffffffffffffffUL
104 private int jjMoveNfa_3(int startState
, int curPos
)
109 jjstateSet
[0] = startState
;
110 int kind
= 0x7fffffff;
113 if (++jjround
== 0x7fffffff)
117 ulong l
= 1ul << curChar
;
120 switch(jjstateSet
[--i
])
123 if ((0x7bffd0f8fffffdffL
& l
) != 0UL)
127 jjCheckNAddStates(0, 6);
129 else if ((0x100000200L
& l
) != 0UL)
134 else if (curChar
== 34)
136 else if (curChar
== 33)
142 jjstateSet
[jjnewStateCnt
++] = 4;
145 if (curChar
== 38 && kind
> 7)
150 jjstateSet
[jjnewStateCnt
++] = 4;
153 if (curChar
== 33 && kind
> 9)
161 if ((0xfffffffbffffffffUL
& l
) != 0UL)
162 jjCheckNAddTwoStates(15, 16);
165 if (curChar
== 34 && kind
> 16)
169 if ((0x3ff000000000000UL
& l
) == 0UL)
173 jjstateSet
[jjnewStateCnt
++] = 18;
176 if ((0x7bffd0f8fffffdffUL
& l
) == 0UL)
180 jjCheckNAddStates(0, 6);
183 if ((0x7bffd0f8fffffdffUL
& l
) == 0UL)
187 jjCheckNAddTwoStates(20, 21);
190 if ((0x84002f0600000000UL
& l
) == 0UL)
194 jjCheckNAddTwoStates(20, 21);
197 if ((0x7bffd0f8fffffdffUL
& l
) != 0UL)
198 jjCheckNAddStates(7, 9);
201 if (curChar
== 42 && kind
> 20)
205 if ((0x84002f0600000000UL
& l
) != 0UL)
206 jjCheckNAddStates(7, 9);
209 if ((0xfbffd4f8fffffdffUL
& l
) == 0UL)
213 jjCheckNAddTwoStates(27, 28);
216 if ((0x84002f0600000000UL
& l
) == 0UL)
220 jjCheckNAddTwoStates(27, 28);
224 } while(i
!= startsAt
);
226 else if (curChar
< 128)
228 ulong l
= 1ul << (curChar
& 63);
231 switch(jjstateSet
[--i
])
234 if ((0x97ffffff97ffffffUL
& l
) != 0UL)
238 jjCheckNAddStates(0, 6);
240 else if (curChar
== 126)
241 jjstateSet
[jjnewStateCnt
++] = 18;
243 jjCheckNAddStates(10, 12);
244 else if (curChar
== 78)
245 jjstateSet
[jjnewStateCnt
++] = 11;
246 else if (curChar
== 124)
247 jjstateSet
[jjnewStateCnt
++] = 8;
248 else if (curChar
== 79)
249 jjstateSet
[jjnewStateCnt
++] = 6;
250 else if (curChar
== 65)
251 jjstateSet
[jjnewStateCnt
++] = 2;
254 if (curChar
== 68 && kind
> 7)
259 jjstateSet
[jjnewStateCnt
++] = 1;
263 jjstateSet
[jjnewStateCnt
++] = 2;
266 if (curChar
== 82 && kind
> 8)
271 jjstateSet
[jjnewStateCnt
++] = 6;
274 if (curChar
== 124 && kind
> 8)
279 jjstateSet
[jjnewStateCnt
++] = 8;
282 if (curChar
== 84 && kind
> 9)
287 jjstateSet
[jjnewStateCnt
++] = 10;
291 jjstateSet
[jjnewStateCnt
++] = 11;
298 jjstateSet
[jjnewStateCnt
++] = 18;
301 if ((0x97ffffff97ffffffUL
& l
) == 0UL)
305 jjCheckNAddStates(0, 6);
308 if ((0x97ffffff97ffffffUL
& l
) == 0UL)
312 jjCheckNAddTwoStates(20, 21);
316 jjCheckNAddTwoStates(22, 22);
319 if ((0x6800000078000000UL
& l
) == 0UL)
323 jjCheckNAddTwoStates(20, 21);
326 if ((0x97ffffff97ffffffUL
& l
) != 0UL)
327 jjCheckNAddStates(7, 9);
331 jjCheckNAddTwoStates(26, 26);
334 if ((0x6800000078000000UL
& l
) != 0UL)
335 jjCheckNAddStates(7, 9);
338 if ((0x97ffffff97ffffffUL
& l
) == 0UL)
342 jjCheckNAddTwoStates(27, 28);
346 jjCheckNAddTwoStates(29, 29);
349 if ((0x6800000078000000UL
& l
) == 0UL)
353 jjCheckNAddTwoStates(27, 28);
357 jjCheckNAddStates(10, 12);
361 } while(i
!= startsAt
);
365 int hiByte
= (int)(curChar
>> 8);
366 int i1
= hiByte
>> 6;
367 long l1
= 1L << (hiByte
& 63);
368 int i2
= (curChar
& 0xff) >> 6;
369 long l2
= 1L << (curChar
& 63);
372 switch(jjstateSet
[--i
])
375 if (!jjCanMove_0(hiByte
, i1
, i2
, l1
, l2
))
379 jjCheckNAddStates(0, 6);
382 if (jjCanMove_0(hiByte
, i1
, i2
, l1
, l2
))
386 if (!jjCanMove_0(hiByte
, i1
, i2
, l1
, l2
))
390 jjCheckNAddTwoStates(20, 21);
393 if (jjCanMove_0(hiByte
, i1
, i2
, l1
, l2
))
394 jjCheckNAddStates(7, 9);
397 if (!jjCanMove_0(hiByte
, i1
, i2
, l1
, l2
))
401 jjCheckNAddTwoStates(27, 28);
405 } while(i
!= startsAt
);
407 if (kind
!= 0x7fffffff)
409 jjmatchedKind
= kind
;
410 jjmatchedPos
= curPos
;
414 if ((i
= jjnewStateCnt
) == (startsAt
= 31 - (jjnewStateCnt
= startsAt
)))
416 try { curChar = input_stream.ReadChar(); }
417 catch(IOException
) { return curPos; }
420 private int jjStopStringLiteralDfa_1(int pos
, long active0
)
425 if ((active0
& 0x20000000L
) != 0L)
435 private int jjStartNfa_1(int pos
, long active0
)
437 return jjMoveNfa_1(jjStopStringLiteralDfa_1(pos
, active0
), pos
+ 1);
439 private int jjStartNfaWithStates_1(int pos
, int kind
, int state
)
441 jjmatchedKind
= kind
;
443 try { curChar = input_stream.ReadChar(); }
444 catch(IOException
) { return pos + 1; }
445 return jjMoveNfa_1(state
, pos
+ 1);
447 private int jjMoveStringLiteralDfa0_1()
452 return jjMoveStringLiteralDfa1_1(0x20000000L
);
454 return jjStopAtPos(0, 30);
456 return jjMoveNfa_1(0, 0);
459 private int jjMoveStringLiteralDfa1_1(long active0
)
461 try { curChar = input_stream.ReadChar(); }
464 jjStopStringLiteralDfa_1(0, active0
);
470 if ((active0
& 0x20000000L
) != 0L)
471 return jjStartNfaWithStates_1(1, 29, 4);
476 return jjStartNfa_1(0, active0
);
478 private int jjMoveNfa_1(int startState
, int curPos
)
483 jjstateSet
[0] = startState
;
484 int kind
= 0x7fffffff;
487 if (++jjround
== 0x7fffffff)
491 ulong l
= 1ul << curChar
;
494 switch(jjstateSet
[--i
])
497 if ((0xfffffffeffffffffUL
& l
) != 0UL)
503 if ((0x100000200UL
& l
) != 0UL)
508 else if (curChar
== 34)
516 if ((0xfffffffbffffffffUL
& l
) != 0UL)
517 jjCheckNAddTwoStates(2, 3);
520 if (curChar
== 34 && kind
> 31)
524 if ((0xfffffffeffffffffUL
& l
) == 0UL)
532 } while(i
!= startsAt
);
534 else if (curChar
< 128)
536 ulong l
= 1ul << (curChar
& 63);
539 switch(jjstateSet
[--i
])
543 if ((0xdfffffffffffffffUL
& l
) == 0UL)
554 } while(i
!= startsAt
);
558 int hiByte
= (int)(curChar
>> 8);
559 int i1
= hiByte
>> 6;
560 long l1
= 1L << (hiByte
& 63);
561 int i2
= (curChar
& 0xff) >> 6;
562 long l2
= 1L << (curChar
& 63);
565 switch(jjstateSet
[--i
])
569 if (!jjCanMove_0(hiByte
, i1
, i2
, l1
, l2
))
576 if (jjCanMove_0(hiByte
, i1
, i2
, l1
, l2
))
581 } while(i
!= startsAt
);
583 if (kind
!= 0x7fffffff)
585 jjmatchedKind
= kind
;
586 jjmatchedPos
= curPos
;
590 if ((i
= jjnewStateCnt
) == (startsAt
= 5 - (jjnewStateCnt
= startsAt
)))
592 try { curChar = input_stream.ReadChar(); }
593 catch(IOException
) { return curPos; }
596 private int jjMoveStringLiteralDfa0_0()
598 return jjMoveNfa_0(0, 0);
600 private int jjMoveNfa_0(int startState
, int curPos
)
605 jjstateSet
[0] = startState
;
606 int kind
= 0x7fffffff;
609 if (++jjround
== 0x7fffffff)
613 ulong l
= 1ul << curChar
;
616 switch(jjstateSet
[--i
])
619 if ((0x3ff000000000000UL
& l
) == 0UL)
630 if ((0x3ff000000000000UL
& l
) == 0UL)
638 } while(i
!= startsAt
);
640 else if (curChar
< 128)
642 ulong l
= 1ul << (curChar
& 63);
645 switch(jjstateSet
[--i
])
649 } while(i
!= startsAt
);
653 int hiByte
= (int)(curChar
>> 8);
654 int i1
= hiByte
>> 6;
655 long l1
= 1L << (hiByte
& 63);
656 int i2
= (curChar
& 0xff) >> 6;
657 long l2
= 1L << (curChar
& 63);
660 switch(jjstateSet
[--i
])
664 } while(i
!= startsAt
);
666 if (kind
!= 0x7fffffff)
668 jjmatchedKind
= kind
;
669 jjmatchedPos
= curPos
;
673 if ((i
= jjnewStateCnt
) == (startsAt
= 3 - (jjnewStateCnt
= startsAt
)))
675 try { curChar = input_stream.ReadChar(); }
676 catch(IOException
) { return curPos; }
679 private int jjStopStringLiteralDfa_2(int pos
, long active0
)
684 if ((active0
& 0x2000000L
) != 0L)
694 private int jjStartNfa_2(int pos
, long active0
)
696 return jjMoveNfa_2(jjStopStringLiteralDfa_2(pos
, active0
), pos
+ 1);
698 private int jjStartNfaWithStates_2(int pos
, int kind
, int state
)
700 jjmatchedKind
= kind
;
702 try { curChar = input_stream.ReadChar(); }
703 catch(IOException
) { return pos + 1; }
704 return jjMoveNfa_2(state
, pos
+ 1);
706 private int jjMoveStringLiteralDfa0_2()
711 return jjMoveStringLiteralDfa1_2(0x2000000L
);
713 return jjStopAtPos(0, 26);
715 return jjMoveNfa_2(0, 0);
718 private int jjMoveStringLiteralDfa1_2(long active0
)
720 try { curChar = input_stream.ReadChar(); }
723 jjStopStringLiteralDfa_2(0, active0
);
729 if ((active0
& 0x2000000L
) != 0L)
730 return jjStartNfaWithStates_2(1, 25, 4);
735 return jjStartNfa_2(0, active0
);
737 private int jjMoveNfa_2(int startState
, int curPos
)
742 jjstateSet
[0] = startState
;
743 int kind
= 0x7fffffff;
746 if (++jjround
== 0x7fffffff)
750 ulong l
= 1ul << curChar
;
753 switch(jjstateSet
[--i
])
756 if ((0xfffffffeffffffffUL
& l
) != 0UL)
762 if ((0x100000200UL
& l
) != 0UL)
767 else if (curChar
== 34)
775 if ((0xfffffffbffffffffUL
& l
) != 0UL)
776 jjCheckNAddTwoStates(2, 3);
779 if (curChar
== 34 && kind
> 27)
783 if ((0xfffffffeffffffffUL
& l
) == 0UL)
791 } while(i
!= startsAt
);
793 else if (curChar
< 128)
795 ulong l
= 1ul << (curChar
& 63);
798 switch(jjstateSet
[--i
])
802 if ((0xffffffffdfffffffUL
& l
) == 0UL)
813 } while(i
!= startsAt
);
817 int hiByte
= (int)(curChar
>> 8);
818 int i1
= hiByte
>> 6;
819 long l1
= 1L << (hiByte
& 63);
820 int i2
= (curChar
& 0xff) >> 6;
821 long l2
= 1L << (curChar
& 63);
824 switch(jjstateSet
[--i
])
828 if (!jjCanMove_0(hiByte
, i1
, i2
, l1
, l2
))
835 if (jjCanMove_0(hiByte
, i1
, i2
, l1
, l2
))
840 } while(i
!= startsAt
);
842 if (kind
!= 0x7fffffff)
844 jjmatchedKind
= kind
;
845 jjmatchedPos
= curPos
;
849 if ((i
= jjnewStateCnt
) == (startsAt
= 5 - (jjnewStateCnt
= startsAt
)))
851 try { curChar = input_stream.ReadChar(); }
852 catch(IOException
) { return curPos; }
855 readonly int[] jjnextStates
= new int[]
857 20, 23, 24, 27, 28, 25, 21, 23, 24, 25, 22, 26, 29, 15, 16, 2,
860 private static bool jjCanMove_0(int hiByte
, int i1
, int i2
, long l1
, long l2
)
865 return ((jjbitVec2
[i2
] & (ulong)l2
) != 0UL);
867 if ((jjbitVec0
[i1
] & (ulong)l1
) != 0UL)
872 public readonly String
[] jjstrLiteralImages
= new String
[]
874 "", null, null, null, null, null, null, null, null, null, "\u0053", "\u0055", "\u0050",
875 "\u0051", "\u0072", "\u0136", null, null, "\u0176", null, null, null, "\u0133", "\u0173", null,
876 "\u0124\u0117", "\u0135", null, null, "\u0124\u0117", "\u0175", null, null, };
877 public static readonly String
[] lexStateNames
=
884 public readonly int[] jjnewLexState
= new int[]
886 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, -1, -1, -1, -1, -1, 2, 1, 3,
887 -1, 3, -1, -1, -1, 3, -1, -1,
889 static readonly long[] jjtoToken
= new long[]
893 static readonly long[] jjtoSkip
= new long[]
897 protected CharStream input_stream
;
898 private readonly uint[] jjrounds
= new uint[31];
899 private readonly int[] jjstateSet
= new int[62];
900 protected char curChar
;
901 public QueryParserTokenManager(CharStream stream
)
903 input_stream
= stream
;
905 public QueryParserTokenManager(CharStream stream
, int lexState
)
910 public void ReInit(CharStream stream
)
912 jjmatchedPos
= jjnewStateCnt
= 0;
913 curLexState
= defaultLexState
;
914 input_stream
= stream
;
917 private void ReInitRounds()
920 jjround
= 0x80000001;
921 for (i
= 31; i
-- > 0;)
922 jjrounds
[i
] = 0x80000000;
924 public void ReInit(CharStream stream
, int lexState
)
929 public void SwitchTo(int lexState
)
931 if (lexState
>= 4 || lexState
< 0)
932 throw new TokenMgrError("Error: Ignoring invalid lexical state : " + lexState
+ ". State unchanged.", TokenMgrError
.INVALID_LEXICAL_STATE
);
934 curLexState
= lexState
;
937 protected Token
jjFillToken()
939 Token t
= Token
.NewToken(jjmatchedKind
);
940 t
.kind
= jjmatchedKind
;
941 String im
= jjstrLiteralImages
[jjmatchedKind
];
942 t
.image
= (im
== null) ? input_stream
.GetImage() : im
;
943 t
.beginLine
= input_stream
.GetBeginLine();
944 t
.beginColumn
= input_stream
.GetBeginColumn();
945 t
.endLine
= input_stream
.GetEndLine();
946 t
.endColumn
= input_stream
.GetEndColumn();
951 int defaultLexState
= 3;
957 public Token
getNextToken()
967 curChar
= input_stream
.BeginToken();
972 matchedToken
= jjFillToken();
979 jjmatchedKind
= 0x7fffffff;
981 curPos
= jjMoveStringLiteralDfa0_0();
984 jjmatchedKind
= 0x7fffffff;
986 curPos
= jjMoveStringLiteralDfa0_1();
989 jjmatchedKind
= 0x7fffffff;
991 curPos
= jjMoveStringLiteralDfa0_2();
994 jjmatchedKind
= 0x7fffffff;
996 curPos
= jjMoveStringLiteralDfa0_3();
999 if (jjmatchedKind
!= 0x7fffffff)
1001 if (jjmatchedPos
+ 1 < curPos
)
1002 input_stream
.Backup(curPos
- jjmatchedPos
- 1);
1003 if ((jjtoToken
[jjmatchedKind
>> 6] & (1L << (jjmatchedKind
& 63))) != 0L)
1005 matchedToken
= jjFillToken();
1006 if (jjnewLexState
[jjmatchedKind
] != -1)
1007 curLexState
= jjnewLexState
[jjmatchedKind
];
1008 return matchedToken
;
1012 if (jjnewLexState
[jjmatchedKind
] != -1)
1013 curLexState
= jjnewLexState
[jjmatchedKind
];
1017 int error_line
= input_stream
.GetEndLine();
1018 int error_column
= input_stream
.GetEndColumn();
1019 String error_after
= null;
1020 bool EOFSeen
= false;
1021 try { input_stream.ReadChar(); input_stream.Backup(1); }
1025 error_after
= curPos
<= 1 ? "" : input_stream
.GetImage();
1026 if (curChar
== '\n' || curChar
== '\r')
1036 input_stream
.Backup(1);
1037 error_after
= curPos
<= 1 ? "" : input_stream
.GetImage();
1039 throw new TokenMgrError(EOFSeen
, curLexState
, error_line
, error_column
, error_after
, curChar
, TokenMgrError
.LEXICAL_ERROR
);