1 /////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2009-2014 Alan Wright. All rights reserved.
3 // Distributable under the terms of either the Apache License (Version 2.0)
4 // or the GNU Lesser General Public License.
5 /////////////////////////////////////////////////////////////////////////////
6
7 #include "LuceneInc.h"
8 #include "QueryParserTokenManager.h"
9 #include "QueryParserCharStream.h"
10 #include "QueryParserToken.h"
11 #include "QueryParseError.h"
12 #include "InfoStream.h"
13 #include "StringUtils.h"
14
15 namespace Lucene {
16
17 const int64_t QueryParserTokenManager::jjbitVec0[] = {0x1LL, 0x0LL, 0x0LL, 0x0LL};
18 const int64_t QueryParserTokenManager::jjbitVec1[] = {static_cast<int64_t>(0xfffffffffffffffeLL), static_cast<int64_t>(0xffffffffffffffffLL), static_cast<int64_t>(0xffffffffffffffffLL), static_cast<int64_t>(0xffffffffffffffffLL)};
19 const int64_t QueryParserTokenManager::jjbitVec3[] = {0x0LL, 0x0LL, static_cast<int64_t>(0xffffffffffffffffLL), static_cast<int64_t>(0xffffffffffffffffLL)};
20 const int64_t QueryParserTokenManager::jjbitVec4[] = {static_cast<int64_t>(0xfffefffffffffffeLL), static_cast<int64_t>(0xffffffffffffffffLL), static_cast<int64_t>(0xffffffffffffffffLL), static_cast<int64_t>(0xffffffffffffffffLL)};
21
22 const int32_t QueryParserTokenManager::jjnextStates[] = {15, 16, 18, 29, 32, 23, 33, 30, 20, 21, 32, 23, 33, 31, 34, 27, 2, 4, 5, 0, 1};
23
24 /// Token literal values.
25 const wchar_t* QueryParserTokenManager::jjstrLiteralImages[] = {
26 L"", L"", L"", L"", L"", L"", L"", L"", L"", L"", L"", L"\53", L"\55",
27 L"\50", L"\51", L"\72", L"\52", L"\136", L"", L"", L"", L"", L"", L"\133",
28 L"\173", L"", L"\124\117", L"\135", L"", L"", L"\124\117", L"\175", L"", L""
29 };
30
31 /// Lexer state names.
32 const wchar_t* QueryParserTokenManager::lexStateNames[] = {
33 L"Boost", L"RangeEx", L"RangeIn", L"DEFAULT"
34 };
35
36 /// Lex State array.
37 const int32_t QueryParserTokenManager::jjnewLexState[] = {
38 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0,
39 -1, -1, -1, -1, -1, 2, 1, 3, -1, 3, -1, -1, -1, 3, -1, -1
40 };
41
42 const int64_t QueryParserTokenManager::jjtoToken[] = {0x3ffffff01LL};
43 const int64_t QueryParserTokenManager::jjtoSkip[] = {0x80LL};
44
QueryParserTokenManager(const QueryParserCharStreamPtr & stream)45 QueryParserTokenManager::QueryParserTokenManager(const QueryParserCharStreamPtr& stream) {
46 debugStream = newLucene<InfoStreamOut>();
47 jjrounds = IntArray::newInstance(36);
48 jjstateSet = IntArray::newInstance(72);
49 curChar = 0;
50 curLexState = 3;
51 defaultLexState = 3;
52 jjnewStateCnt = 0;
53 jjround = 0;
54 jjmatchedPos = 0;
55 jjmatchedKind = 0;
56 input_stream = stream;
57 }
58
QueryParserTokenManager(const QueryParserCharStreamPtr & stream,int32_t lexState)59 QueryParserTokenManager::QueryParserTokenManager(const QueryParserCharStreamPtr& stream, int32_t lexState) {
60 debugStream = newLucene<InfoStreamOut>();
61 jjrounds = IntArray::newInstance(36);
62 jjstateSet = IntArray::newInstance(72);
63 input_stream = stream;
64 curChar = 0;
65 curLexState = 3;
66 defaultLexState = 3;
67 jjnewStateCnt = 0;
68 jjround = 0;
69 jjmatchedPos = 0;
70 jjmatchedKind = 0;
71 SwitchTo(lexState);
72 }
73
~QueryParserTokenManager()74 QueryParserTokenManager::~QueryParserTokenManager() {
75 }
76
setDebugStream(const InfoStreamPtr & debugStream)77 void QueryParserTokenManager::setDebugStream(const InfoStreamPtr& debugStream) {
78 this->debugStream = debugStream;
79 }
80
jjStopStringLiteralDfa_3(int32_t pos,int64_t active0)81 int32_t QueryParserTokenManager::jjStopStringLiteralDfa_3(int32_t pos, int64_t active0) {
82 return -1;
83 }
84
jjStartNfa_3(int32_t pos,int64_t active0)85 int32_t QueryParserTokenManager::jjStartNfa_3(int32_t pos, int64_t active0) {
86 return jjMoveNfa_3(jjStopStringLiteralDfa_3(pos, active0), pos + 1);
87 }
88
jjStopAtPos(int32_t pos,int32_t kind)89 int32_t QueryParserTokenManager::jjStopAtPos(int32_t pos, int32_t kind) {
90 jjmatchedKind = kind;
91 jjmatchedPos = pos;
92 return pos + 1;
93 }
94
jjMoveStringLiteralDfa0_3()95 int32_t QueryParserTokenManager::jjMoveStringLiteralDfa0_3() {
96 switch (curChar) {
97 case 40:
98 return jjStopAtPos(0, 13);
99 case 41:
100 return jjStopAtPos(0, 14);
101 case 42:
102 return jjStartNfaWithStates_3(0, 16, 36);
103 case 43:
104 return jjStopAtPos(0, 11);
105 case 45:
106 return jjStopAtPos(0, 12);
107 case 58:
108 return jjStopAtPos(0, 15);
109 case 91:
110 return jjStopAtPos(0, 23);
111 case 94:
112 return jjStopAtPos(0, 17);
113 case 123:
114 return jjStopAtPos(0, 24);
115 default:
116 return jjMoveNfa_3(0, 0);
117 }
118 }
119
jjStartNfaWithStates_3(int32_t pos,int32_t kind,int32_t state)120 int32_t QueryParserTokenManager::jjStartNfaWithStates_3(int32_t pos, int32_t kind, int32_t state) {
121 jjmatchedKind = kind;
122 jjmatchedPos = pos;
123 try {
124 curChar = input_stream->readChar();
125 } catch (IOException&) {
126 return pos + 1;
127 }
128 return jjMoveNfa_3(state, pos + 1);
129 }
130
jjMoveNfa_3(int32_t startState,int32_t curPos)131 int32_t QueryParserTokenManager::jjMoveNfa_3(int32_t startState, int32_t curPos) {
132 int32_t startsAt = 0;
133 jjnewStateCnt = 36;
134 int32_t i = 1;
135 jjstateSet[0] = startState;
136 int32_t kind = 0x7fffffff;
137 while (true) {
138 if (++jjround == 0x7fffffff) {
139 ReInitRounds();
140 }
141 if (curChar < 64) {
142 int64_t l = (int64_t)1 << curChar;
143 do {
144 switch (jjstateSet[--i]) {
145 case 36:
146 case 25:
147 if ((0xfbfffcf8ffffd9ffLL & l) == 0) {
148 break;
149 }
150 if (kind > 22) {
151 kind = 22;
152 }
153 jjCheckNAddTwoStates(25, 26);
154 break;
155 case 0:
156 if ((0xfbffd4f8ffffd9ffLL & l) != 0) {
157 if (kind > 22) {
158 kind = 22;
159 }
160 jjCheckNAddTwoStates(25, 26);
161 } else if ((0x100002600LL & l) != 0) {
162 if (kind > 7) {
163 kind = 7;
164 }
165 } else if (curChar == 34) {
166 jjCheckNAddStates(0, 2);
167 } else if (curChar == 33) {
168 if (kind > 10) {
169 kind = 10;
170 }
171 }
172 if ((0x7bffd0f8ffffd9ffLL & l) != 0) {
173 if (kind > 19) {
174 kind = 19;
175 }
176 jjCheckNAddStates(3, 7);
177 } else if (curChar == 42) {
178 if (kind > 21) {
179 kind = 21;
180 }
181 }
182 if (curChar == 38) {
183 jjstateSet[jjnewStateCnt++] = 4;
184 }
185 break;
186 case 4:
187 if (curChar == 38 && kind > 8) {
188 kind = 8;
189 }
190 break;
191 case 5:
192 if (curChar == 38) {
193 jjstateSet[jjnewStateCnt++] = 4;
194 }
195 break;
196 case 13:
197 if (curChar == 33 && kind > 10) {
198 kind = 10;
199 }
200 break;
201 case 14:
202 if (curChar == 34) {
203 jjCheckNAddStates(0, 2);
204 }
205 break;
206 case 15:
207 if ((0xfffffffbffffffffLL & l) != 0) {
208 jjCheckNAddStates(0, 2);
209 }
210 break;
211 case 17:
212 jjCheckNAddStates(0, 2);
213 break;
214 case 18:
215 if (curChar == 34 && kind > 18) {
216 kind = 18;
217 }
218 break;
219 case 20:
220 if ((0x3ff000000000000LL & l) == 0) {
221 break;
222 }
223 if (kind > 20) {
224 kind = 20;
225 }
226 jjAddStates(8, 9);
227 break;
228 case 21:
229 if (curChar == 46) {
230 jjCheckNAdd(22);
231 }
232 break;
233 case 22:
234 if ((0x3ff000000000000LL & l) == 0) {
235 break;
236 }
237 if (kind > 20) {
238 kind = 20;
239 }
240 jjCheckNAdd(22);
241 break;
242 case 23:
243 if (curChar == 42 && kind > 21) {
244 kind = 21;
245 }
246 break;
247 case 24:
248 if ((0xfbffd4f8ffffd9ffLL & l) == 0) {
249 break;
250 }
251 if (kind > 22) {
252 kind = 22;
253 }
254 jjCheckNAddTwoStates(25, 26);
255 break;
256 case 27:
257 if (kind > 22) {
258 kind = 22;
259 }
260 jjCheckNAddTwoStates(25, 26);
261 break;
262 case 28:
263 if ((0x7bffd0f8ffffd9ffLL & l) == 0) {
264 break;
265 }
266 if (kind > 19) {
267 kind = 19;
268 }
269 jjCheckNAddStates(3, 7);
270 break;
271 case 29:
272 if ((0x7bfff8f8ffffd9ffLL & l) == 0) {
273 break;
274 }
275 if (kind > 19) {
276 kind = 19;
277 }
278 jjCheckNAddTwoStates(29, 30);
279 break;
280 case 31:
281 if (kind > 19) {
282 kind = 19;
283 }
284 jjCheckNAddTwoStates(29, 30);
285 break;
286 case 32:
287 if ((0x7bfff8f8ffffd9ffLL & l) != 0) {
288 jjCheckNAddStates(10, 12);
289 }
290 break;
291 case 34:
292 jjCheckNAddStates(10, 12);
293 break;
294 default:
295 break;
296 }
297 } while (i != startsAt);
298 } else if (curChar < 128) {
299 int64_t l = (int64_t)1 << (curChar & 077);
300 do {
301 switch (jjstateSet[--i]) {
302 case 36:
303 if ((0x97ffffff87ffffffLL & l) != 0) {
304 if (kind > 22) {
305 kind = 22;
306 }
307 jjCheckNAddTwoStates(25, 26);
308 } else if (curChar == 92) {
309 jjCheckNAddTwoStates(27, 27);
310 }
311 break;
312 case 0:
313 if ((0x97ffffff87ffffffLL & l) != 0) {
314 if (kind > 19) {
315 kind = 19;
316 }
317 jjCheckNAddStates(3, 7);
318 } else if (curChar == 92) {
319 jjCheckNAddStates(13, 15);
320 } else if (curChar == 126) {
321 if (kind > 20) {
322 kind = 20;
323 }
324 jjstateSet[jjnewStateCnt++] = 20;
325 }
326 if ((0x97ffffff87ffffffLL & l) != 0) {
327 if (kind > 22) {
328 kind = 22;
329 }
330 jjCheckNAddTwoStates(25, 26);
331 }
332 if (curChar == 78) {
333 jjstateSet[jjnewStateCnt++] = 11;
334 } else if (curChar == 124) {
335 jjstateSet[jjnewStateCnt++] = 8;
336 } else if (curChar == 79) {
337 jjstateSet[jjnewStateCnt++] = 6;
338 } else if (curChar == 65) {
339 jjstateSet[jjnewStateCnt++] = 2;
340 }
341 break;
342 case 1:
343 if (curChar == 68 && kind > 8) {
344 kind = 8;
345 }
346 break;
347 case 2:
348 if (curChar == 78) {
349 jjstateSet[jjnewStateCnt++] = 1;
350 }
351 break;
352 case 3:
353 if (curChar == 65) {
354 jjstateSet[jjnewStateCnt++] = 2;
355 }
356 break;
357 case 6:
358 if (curChar == 82 && kind > 9) {
359 kind = 9;
360 }
361 break;
362 case 7:
363 if (curChar == 79) {
364 jjstateSet[jjnewStateCnt++] = 6;
365 }
366 break;
367 case 8:
368 if (curChar == 124 && kind > 9) {
369 kind = 9;
370 }
371 break;
372 case 9:
373 if (curChar == 124) {
374 jjstateSet[jjnewStateCnt++] = 8;
375 }
376 break;
377 case 10:
378 if (curChar == 84 && kind > 10) {
379 kind = 10;
380 }
381 break;
382 case 11:
383 if (curChar == 79) {
384 jjstateSet[jjnewStateCnt++] = 10;
385 }
386 break;
387 case 12:
388 if (curChar == 78) {
389 jjstateSet[jjnewStateCnt++] = 11;
390 }
391 break;
392 case 15:
393 if ((0xffffffffefffffffLL & l) != 0) {
394 jjCheckNAddStates(0, 2);
395 }
396 break;
397 case 16:
398 if (curChar == 92) {
399 jjstateSet[jjnewStateCnt++] = 17;
400 }
401 break;
402 case 17:
403 jjCheckNAddStates(0, 2);
404 break;
405 case 19:
406 if (curChar != 126) {
407 break;
408 }
409 if (kind > 20) {
410 kind = 20;
411 }
412 jjstateSet[jjnewStateCnt++] = 20;
413 break;
414 case 24:
415 if ((0x97ffffff87ffffffLL & l) == 0) {
416 break;
417 }
418 if (kind > 22) {
419 kind = 22;
420 }
421 jjCheckNAddTwoStates(25, 26);
422 break;
423 case 25:
424 if ((0x97ffffff87ffffffLL & l) == 0) {
425 break;
426 }
427 if (kind > 22) {
428 kind = 22;
429 }
430 jjCheckNAddTwoStates(25, 26);
431 break;
432 case 26:
433 if (curChar == 92) {
434 jjCheckNAddTwoStates(27, 27);
435 }
436 break;
437 case 27:
438 if (kind > 22) {
439 kind = 22;
440 }
441 jjCheckNAddTwoStates(25, 26);
442 break;
443 case 28:
444 if ((0x97ffffff87ffffffLL & l) == 0) {
445 break;
446 }
447 if (kind > 19) {
448 kind = 19;
449 }
450 jjCheckNAddStates(3, 7);
451 break;
452 case 29:
453 if ((0x97ffffff87ffffffLL & l) == 0) {
454 break;
455 }
456 if (kind > 19) {
457 kind = 19;
458 }
459 jjCheckNAddTwoStates(29, 30);
460 break;
461 case 30:
462 if (curChar == 92) {
463 jjCheckNAddTwoStates(31, 31);
464 }
465 break;
466 case 31:
467 if (kind > 19) {
468 kind = 19;
469 }
470 jjCheckNAddTwoStates(29, 30);
471 break;
472 case 32:
473 if ((0x97ffffff87ffffffLL & l) != 0) {
474 jjCheckNAddStates(10, 12);
475 }
476 break;
477 case 33:
478 if (curChar == 92) {
479 jjCheckNAddTwoStates(34, 34);
480 }
481 break;
482 case 34:
483 jjCheckNAddStates(10, 12);
484 break;
485 case 35:
486 if (curChar == 92) {
487 jjCheckNAddStates(13, 15);
488 }
489 break;
490 default:
491 break;
492 }
493 } while (i != startsAt);
494 } else {
495 int32_t hiByte = (int32_t)(curChar >> 8);
496 int32_t i1 = hiByte >> 6;
497 int64_t l1 = (int64_t)1 << (hiByte & 077);
498 int32_t i2 = (curChar & 0xff) >> 6;
499 int64_t l2 = (int64_t)1 << (curChar & 077);
500 do {
501 switch (jjstateSet[--i]) {
502 case 36:
503 case 25:
504 if (!jjCanMove_2(hiByte, i1, i2, l1, l2)) {
505 break;
506 }
507 if (kind > 22) {
508 kind = 22;
509 }
510 jjCheckNAddTwoStates(25, 26);
511 break;
512 case 0:
513 if (jjCanMove_0(hiByte, i1, i2, l1, l2)) {
514 if (kind > 7) {
515 kind = 7;
516 }
517 }
518 if (jjCanMove_2(hiByte, i1, i2, l1, l2)) {
519 if (kind > 22) {
520 kind = 22;
521 }
522 jjCheckNAddTwoStates(25, 26);
523 }
524 if (jjCanMove_2(hiByte, i1, i2, l1, l2)) {
525 if (kind > 19) {
526 kind = 19;
527 }
528 jjCheckNAddStates(3, 7);
529 }
530 break;
531 case 15:
532 case 17:
533 if (jjCanMove_1(hiByte, i1, i2, l1, l2)) {
534 jjCheckNAddStates(0, 2);
535 }
536 break;
537 case 24:
538 if (!jjCanMove_2(hiByte, i1, i2, l1, l2)) {
539 break;
540 }
541 if (kind > 22) {
542 kind = 22;
543 }
544 jjCheckNAddTwoStates(25, 26);
545 break;
546 case 27:
547 if (!jjCanMove_1(hiByte, i1, i2, l1, l2)) {
548 break;
549 }
550 if (kind > 22) {
551 kind = 22;
552 }
553 jjCheckNAddTwoStates(25, 26);
554 break;
555 case 28:
556 if (!jjCanMove_2(hiByte, i1, i2, l1, l2)) {
557 break;
558 }
559 if (kind > 19) {
560 kind = 19;
561 }
562 jjCheckNAddStates(3, 7);
563 break;
564 case 29:
565 if (!jjCanMove_2(hiByte, i1, i2, l1, l2)) {
566 break;
567 }
568 if (kind > 19) {
569 kind = 19;
570 }
571 jjCheckNAddTwoStates(29, 30);
572 break;
573 case 31:
574 if (!jjCanMove_1(hiByte, i1, i2, l1, l2)) {
575 break;
576 }
577 if (kind > 19) {
578 kind = 19;
579 }
580 jjCheckNAddTwoStates(29, 30);
581 break;
582 case 32:
583 if (jjCanMove_2(hiByte, i1, i2, l1, l2)) {
584 jjCheckNAddStates(10, 12);
585 }
586 break;
587 case 34:
588 if (jjCanMove_1(hiByte, i1, i2, l1, l2)) {
589 jjCheckNAddStates(10, 12);
590 }
591 break;
592 default:
593 break;
594 }
595 } while (i != startsAt);
596 }
597 if (kind != 0x7fffffff) {
598 jjmatchedKind = kind;
599 jjmatchedPos = curPos;
600 kind = 0x7fffffff;
601 }
602 ++curPos;
603 i = jjnewStateCnt;
604 jjnewStateCnt = startsAt;
605 if (i == (startsAt = 36 - jjnewStateCnt)) {
606 return curPos;
607 }
608 try {
609 curChar = input_stream->readChar();
610 } catch (IOException&) {
611 return curPos;
612 }
613 }
614 }
615
jjStopStringLiteralDfa_1(int32_t pos,int64_t active0)616 int32_t QueryParserTokenManager::jjStopStringLiteralDfa_1(int32_t pos, int64_t active0) {
617 switch (pos) {
618 case 0:
619 if ((active0 & 0x40000000LL) != 0) {
620 jjmatchedKind = 33;
621 return 6;
622 }
623 return -1;
624 default:
625 return -1;
626 }
627 }
628
jjStartNfa_1(int32_t pos,int64_t active0)629 int32_t QueryParserTokenManager::jjStartNfa_1(int32_t pos, int64_t active0) {
630 return jjMoveNfa_1(jjStopStringLiteralDfa_1(pos, active0), pos + 1);
631 }
632
jjMoveStringLiteralDfa0_1()633 int32_t QueryParserTokenManager::jjMoveStringLiteralDfa0_1() {
634 switch (curChar) {
635 case 84:
636 return jjMoveStringLiteralDfa1_1(0x40000000LL);
637 case 125:
638 return jjStopAtPos(0, 31);
639 default:
640 return jjMoveNfa_1(0, 0);
641 }
642 }
643
jjMoveStringLiteralDfa1_1(int64_t active0)644 int32_t QueryParserTokenManager::jjMoveStringLiteralDfa1_1(int64_t active0) {
645 try {
646 curChar = input_stream->readChar();
647 } catch (IOException&) {
648 jjStopStringLiteralDfa_1(0, active0);
649 return 1;
650 }
651 switch (curChar) {
652 case 79:
653 if ((active0 & 0x40000000LL) != 0) {
654 return jjStartNfaWithStates_1(1, 30, 6);
655 }
656 break;
657 default:
658 break;
659 }
660 return jjStartNfa_1(0, active0);
661 }
662
jjStartNfaWithStates_1(int32_t pos,int32_t kind,int32_t state)663 int32_t QueryParserTokenManager::jjStartNfaWithStates_1(int32_t pos, int32_t kind, int32_t state) {
664 jjmatchedKind = kind;
665 jjmatchedPos = pos;
666 try {
667 curChar = input_stream->readChar();
668 } catch (IOException&) {
669 return pos + 1;
670 }
671 return jjMoveNfa_1(state, pos + 1);
672 }
673
jjMoveNfa_1(int32_t startState,int32_t curPos)674 int32_t QueryParserTokenManager::jjMoveNfa_1(int32_t startState, int32_t curPos) {
675 int32_t startsAt = 0;
676 jjnewStateCnt = 7;
677 int32_t i = 1;
678 jjstateSet[0] = startState;
679 int32_t kind = 0x7fffffff;
680 while (true) {
681 if (++jjround == 0x7fffffff) {
682 ReInitRounds();
683 }
684 if (curChar < 64) {
685 int64_t l = (int64_t)1 << curChar;
686 do {
687 switch (jjstateSet[--i]) {
688 case 0:
689 if ((0xfffffffeffffffffLL & l) != 0) {
690 if (kind > 33) {
691 kind = 33;
692 }
693 jjCheckNAdd(6);
694 }
695 if ((0x100002600LL & l) != 0) {
696 if (kind > 7) {
697 kind = 7;
698 }
699 } else if (curChar == 34) {
700 jjCheckNAddTwoStates(2, 4);
701 }
702 break;
703 case 1:
704 if (curChar == 34) {
705 jjCheckNAddTwoStates(2, 4);
706 }
707 break;
708 case 2:
709 if ((0xfffffffbffffffffLL & l) != 0) {
710 jjCheckNAddStates(16, 18);
711 }
712 break;
713 case 3:
714 if (curChar == 34) {
715 jjCheckNAddStates(16, 18);
716 }
717 break;
718 case 5:
719 if (curChar == 34 && kind > 32) {
720 kind = 32;
721 }
722 break;
723 case 6:
724 if ((0xfffffffeffffffffLL & l) == 0) {
725 break;
726 }
727 if (kind > 33) {
728 kind = 33;
729 }
730 jjCheckNAdd(6);
731 break;
732 default:
733 break;
734 }
735 } while (i != startsAt);
736 } else if (curChar < 128) {
737 int64_t l = (int64_t)1 << (curChar & 077);
738 do {
739 switch (jjstateSet[--i]) {
740 case 0:
741 case 6:
742 if ((0xdfffffffffffffffLL & l) == 0) {
743 break;
744 }
745 if (kind > 33) {
746 kind = 33;
747 }
748 jjCheckNAdd(6);
749 break;
750 case 2:
751 jjAddStates(16, 18);
752 break;
753 case 4:
754 if (curChar == 92) {
755 jjstateSet[jjnewStateCnt++] = 3;
756 }
757 break;
758 default:
759 break;
760 }
761 } while (i != startsAt);
762 } else {
763 int32_t hiByte = (int32_t)(curChar >> 8);
764 int32_t i1 = hiByte >> 6;
765 int64_t l1 = (int64_t)1 << (hiByte & 077);
766 int32_t i2 = (curChar & 0xff) >> 6;
767 int64_t l2 = (int64_t)1 << (curChar & 077);
768 do {
769 switch (jjstateSet[--i]) {
770 case 0:
771 if (jjCanMove_0(hiByte, i1, i2, l1, l2)) {
772 if (kind > 7) {
773 kind = 7;
774 }
775 }
776 if (jjCanMove_1(hiByte, i1, i2, l1, l2)) {
777 if (kind > 33) {
778 kind = 33;
779 }
780 jjCheckNAdd(6);
781 }
782 break;
783 case 2:
784 if (jjCanMove_1(hiByte, i1, i2, l1, l2)) {
785 jjAddStates(16, 18);
786 }
787 break;
788 case 6:
789 if (!jjCanMove_1(hiByte, i1, i2, l1, l2)) {
790 break;
791 }
792 if (kind > 33) {
793 kind = 33;
794 }
795 jjCheckNAdd(6);
796 break;
797 default:
798 break;
799 }
800 } while (i != startsAt);
801 }
802 if (kind != 0x7fffffff) {
803 jjmatchedKind = kind;
804 jjmatchedPos = curPos;
805 kind = 0x7fffffff;
806 }
807 ++curPos;
808 i = jjnewStateCnt;
809 jjnewStateCnt = startsAt;
810 if (i == (startsAt = 7 - jjnewStateCnt)) {
811 return curPos;
812 }
813 try {
814 curChar = input_stream->readChar();
815 } catch (IOException&) {
816 return curPos;
817 }
818 }
819 }
820
jjMoveStringLiteralDfa0_0()821 int32_t QueryParserTokenManager::jjMoveStringLiteralDfa0_0() {
822 return jjMoveNfa_0(0, 0);
823 }
824
jjMoveNfa_0(int32_t startState,int32_t curPos)825 int32_t QueryParserTokenManager::jjMoveNfa_0(int32_t startState, int32_t curPos) {
826 int32_t startsAt = 0;
827 jjnewStateCnt = 3;
828 int32_t i = 1;
829 jjstateSet[0] = startState;
830 int32_t kind = 0x7fffffff;
831 while (true) {
832 if (++jjround == 0x7fffffff) {
833 ReInitRounds();
834 }
835 if (curChar < 64) {
836 int64_t l = (int64_t)1 << curChar;
837 do {
838 switch (jjstateSet[--i]) {
839 case 0:
840 if ((0x3ff000000000000LL & l) == 0) {
841 break;
842 }
843 if (kind > 25) {
844 kind = 25;
845 }
846 jjAddStates(19, 20);
847 break;
848 case 1:
849 if (curChar == 46) {
850 jjCheckNAdd(2);
851 }
852 break;
853 case 2:
854 if ((0x3ff000000000000LL & l) == 0) {
855 break;
856 }
857 if (kind > 25) {
858 kind = 25;
859 }
860 jjCheckNAdd(2);
861 break;
862 default:
863 break;
864 }
865 } while (i != startsAt);
866 } else if (curChar < 128) {
867 int64_t l = (int64_t)1 << (curChar & 077);
868 do {
869 jjstateSet[--i];
870 } while (i != startsAt);
871 } else {
872 int32_t hiByte = (int32_t)(curChar >> 8);
873 int32_t i1 = hiByte >> 6;
874 int64_t l1 = (int64_t)1 << (hiByte & 077);
875 int32_t i2 = (curChar & 0xff) >> 6;
876 int64_t l2 = (int64_t)1 << (curChar & 077);
877 do {
878 jjstateSet[--i];
879 } while (i != startsAt);
880 }
881 if (kind != 0x7fffffff) {
882 jjmatchedKind = kind;
883 jjmatchedPos = curPos;
884 kind = 0x7fffffff;
885 }
886 ++curPos;
887 i = jjnewStateCnt;
888 jjnewStateCnt = startsAt;
889 if (i == (startsAt = 3 - jjnewStateCnt)) {
890 return curPos;
891 }
892 try {
893 curChar = input_stream->readChar();
894 } catch (IOException&) {
895 return curPos;
896 }
897 }
898 }
899
jjStopStringLiteralDfa_2(int32_t pos,int64_t active0)900 int32_t QueryParserTokenManager::jjStopStringLiteralDfa_2(int32_t pos, int64_t active0) {
901 switch (pos) {
902 case 0:
903 if ((active0 & 0x4000000LL) != 0) {
904 jjmatchedKind = 29;
905 return 6;
906 }
907 return -1;
908 default:
909 return -1;
910 }
911 }
912
jjStartNfa_2(int32_t pos,int64_t active0)913 int32_t QueryParserTokenManager::jjStartNfa_2(int32_t pos, int64_t active0) {
914 return jjMoveNfa_2(jjStopStringLiteralDfa_2(pos, active0), pos + 1);
915 }
916
jjMoveStringLiteralDfa0_2()917 int32_t QueryParserTokenManager::jjMoveStringLiteralDfa0_2() {
918 switch (curChar) {
919 case 84:
920 return jjMoveStringLiteralDfa1_2(0x4000000LL);
921 case 93:
922 return jjStopAtPos(0, 27);
923 default:
924 return jjMoveNfa_2(0, 0);
925 }
926 }
927
jjMoveStringLiteralDfa1_2(int64_t active0)928 int32_t QueryParserTokenManager::jjMoveStringLiteralDfa1_2(int64_t active0) {
929 try {
930 curChar = input_stream->readChar();
931 } catch (IOException&) {
932 jjStopStringLiteralDfa_2(0, active0);
933 return 1;
934 }
935 switch (curChar) {
936 case 79:
937 if ((active0 & 0x4000000LL) != 0) {
938 return jjStartNfaWithStates_2(1, 26, 6);
939 }
940 break;
941 default:
942 break;
943 }
944 return jjStartNfa_2(0, active0);
945 }
946
jjStartNfaWithStates_2(int32_t pos,int32_t kind,int32_t state)947 int32_t QueryParserTokenManager::jjStartNfaWithStates_2(int32_t pos, int32_t kind, int32_t state) {
948 jjmatchedKind = kind;
949 jjmatchedPos = pos;
950 try {
951 curChar = input_stream->readChar();
952 } catch (IOException&) {
953 return pos + 1;
954 }
955 return jjMoveNfa_2(state, pos + 1);
956 }
957
jjMoveNfa_2(int32_t startState,int32_t curPos)958 int32_t QueryParserTokenManager::jjMoveNfa_2(int32_t startState, int32_t curPos) {
959 int32_t startsAt = 0;
960 jjnewStateCnt = 7;
961 int32_t i = 1;
962 jjstateSet[0] = startState;
963 int32_t kind = 0x7fffffff;
964 while (true) {
965 if (++jjround == 0x7fffffff) {
966 ReInitRounds();
967 }
968 if (curChar < 64) {
969 int64_t l = (int64_t)1 << curChar;
970 do {
971 switch (jjstateSet[--i]) {
972 case 0:
973 if ((0xfffffffeffffffffLL & l) != 0) {
974 if (kind > 29) {
975 kind = 29;
976 }
977 jjCheckNAdd(6);
978 }
979 if ((0x100002600LL & l) != 0) {
980 if (kind > 7) {
981 kind = 7;
982 }
983 } else if (curChar == 34) {
984 jjCheckNAddTwoStates(2, 4);
985 }
986 break;
987 case 1:
988 if (curChar == 34) {
989 jjCheckNAddTwoStates(2, 4);
990 }
991 break;
992 case 2:
993 if ((0xfffffffbffffffffLL & l) != 0) {
994 jjCheckNAddStates(16, 18);
995 }
996 break;
997 case 3:
998 if (curChar == 34) {
999 jjCheckNAddStates(16, 18);
1000 }
1001 break;
1002 case 5:
1003 if (curChar == 34 && kind > 28) {
1004 kind = 28;
1005 }
1006 break;
1007 case 6:
1008 if ((0xfffffffeffffffffLL & l) == 0) {
1009 break;
1010 }
1011 if (kind > 29) {
1012 kind = 29;
1013 }
1014 jjCheckNAdd(6);
1015 break;
1016 default:
1017 break;
1018 }
1019 } while (i != startsAt);
1020 } else if (curChar < 128) {
1021 int64_t l = (int64_t)1 << (curChar & 077);
1022 do {
1023 switch (jjstateSet[--i]) {
1024 case 0:
1025 case 6:
1026 if ((0xffffffffdfffffffLL & l) == 0) {
1027 break;
1028 }
1029 if (kind > 29) {
1030 kind = 29;
1031 }
1032 jjCheckNAdd(6);
1033 break;
1034 case 2:
1035 jjAddStates(16, 18);
1036 break;
1037 case 4:
1038 if (curChar == 92) {
1039 jjstateSet[jjnewStateCnt++] = 3;
1040 }
1041 break;
1042 default:
1043 break;
1044 }
1045 } while (i != startsAt);
1046 } else {
1047 int32_t hiByte = (int32_t)(curChar >> 8);
1048 int32_t i1 = hiByte >> 6;
1049 int64_t l1 = (int64_t)1 << (hiByte & 077);
1050 int32_t i2 = (curChar & 0xff) >> 6;
1051 int64_t l2 = (int64_t)1 << (curChar & 077);
1052 do {
1053 switch (jjstateSet[--i]) {
1054 case 0:
1055 if (jjCanMove_0(hiByte, i1, i2, l1, l2)) {
1056 if (kind > 7) {
1057 kind = 7;
1058 }
1059 }
1060 if (jjCanMove_1(hiByte, i1, i2, l1, l2)) {
1061 if (kind > 29) {
1062 kind = 29;
1063 }
1064 jjCheckNAdd(6);
1065 }
1066 break;
1067 case 2:
1068 if (jjCanMove_1(hiByte, i1, i2, l1, l2)) {
1069 jjAddStates(16, 18);
1070 }
1071 break;
1072 case 6:
1073 if (!jjCanMove_1(hiByte, i1, i2, l1, l2)) {
1074 break;
1075 }
1076 if (kind > 29) {
1077 kind = 29;
1078 }
1079 jjCheckNAdd(6);
1080 break;
1081 default:
1082 break;
1083 }
1084 } while (i != startsAt);
1085 }
1086 if (kind != 0x7fffffff) {
1087 jjmatchedKind = kind;
1088 jjmatchedPos = curPos;
1089 kind = 0x7fffffff;
1090 }
1091 ++curPos;
1092 i = jjnewStateCnt;
1093 jjnewStateCnt = startsAt;
1094 if (i == (startsAt = 7 - jjnewStateCnt)) {
1095 return curPos;
1096 }
1097 try {
1098 curChar = input_stream->readChar();
1099 } catch (IOException&) {
1100 return curPos;
1101 }
1102 }
1103 }
1104
jjCanMove_0(int32_t hiByte,int32_t i1,int32_t i2,int64_t l1,int64_t l2)1105 bool QueryParserTokenManager::jjCanMove_0(int32_t hiByte, int32_t i1, int32_t i2, int64_t l1, int64_t l2) {
1106 switch (hiByte) {
1107 case 48:
1108 return ((jjbitVec0[i2] & l2) != 0);
1109 default:
1110 return false;
1111 }
1112 }
1113
jjCanMove_1(int32_t hiByte,int32_t i1,int32_t i2,int64_t l1,int64_t l2)1114 bool QueryParserTokenManager::jjCanMove_1(int32_t hiByte, int32_t i1, int32_t i2, int64_t l1, int64_t l2) {
1115 switch (hiByte) {
1116 case 0:
1117 return ((jjbitVec3[i2] & l2) != 0);
1118 default:
1119 if ((jjbitVec1[i1] & l1) != 0) {
1120 return true;
1121 }
1122 return false;
1123 }
1124 }
1125
jjCanMove_2(int32_t hiByte,int32_t i1,int32_t i2,int64_t l1,int64_t l2)1126 bool QueryParserTokenManager::jjCanMove_2(int32_t hiByte, int32_t i1, int32_t i2, int64_t l1, int64_t l2) {
1127 switch (hiByte) {
1128 case 0:
1129 return ((jjbitVec3[i2] & l2) != 0);
1130 case 48:
1131 return ((jjbitVec1[i2] & l2) != 0);
1132 default:
1133 if ((jjbitVec4[i1] & l1) != 0) {
1134 return true;
1135 }
1136 return false;
1137 }
1138 }
1139
ReInit(const QueryParserCharStreamPtr & stream)1140 void QueryParserTokenManager::ReInit(const QueryParserCharStreamPtr& stream) {
1141 jjmatchedPos = 0;
1142 jjnewStateCnt = 0;
1143 curLexState = defaultLexState;
1144 input_stream = stream;
1145 ReInitRounds();
1146 }
1147
ReInitRounds()1148 void QueryParserTokenManager::ReInitRounds() {
1149 jjround = 0x80000001;
1150 for (int32_t i = 36; i-- > 0;) {
1151 jjrounds[i] = 0x80000000;
1152 }
1153 }
1154
ReInit(const QueryParserCharStreamPtr & stream,int32_t lexState)1155 void QueryParserTokenManager::ReInit(const QueryParserCharStreamPtr& stream, int32_t lexState) {
1156 ReInit(stream);
1157 SwitchTo(lexState);
1158 }
1159
SwitchTo(int32_t lexState)1160 void QueryParserTokenManager::SwitchTo(int32_t lexState) {
1161 if (lexState >= 4 || lexState < 0) {
1162 boost::throw_exception(QueryParserError(L"Error: Ignoring invalid lexical state : " +
1163 StringUtils::toString(lexState) + L". State unchanged."));
1164 } else {
1165 curLexState = lexState;
1166 }
1167 }
1168
jjFillToken()1169 QueryParserTokenPtr QueryParserTokenManager::jjFillToken() {
1170 String im(jjstrLiteralImages[jjmatchedKind]);
1171 String curTokenImage(im.empty() ? input_stream->GetImage() : im);
1172 int32_t beginLine = input_stream->getBeginLine();
1173 int32_t beginColumn = input_stream->getBeginColumn();
1174 int32_t endLine = input_stream->getEndLine();
1175 int32_t endColumn = input_stream->getEndColumn();
1176 QueryParserTokenPtr t(QueryParserToken::newToken(jjmatchedKind, curTokenImage));
1177
1178 t->beginLine = beginLine;
1179 t->endLine = endLine;
1180 t->beginColumn = beginColumn;
1181 t->endColumn = endColumn;
1182
1183 return t;
1184 }
1185
getNextToken()1186 QueryParserTokenPtr QueryParserTokenManager::getNextToken() {
1187 QueryParserTokenPtr matchedToken;
1188 int32_t curPos = 0;
1189
1190 while (true) {
1191 try {
1192 curChar = input_stream->BeginToken();
1193 } catch (IOException&) {
1194 jjmatchedKind = 0;
1195 matchedToken = jjFillToken();
1196 return matchedToken;
1197 }
1198
1199 switch (curLexState) {
1200 case 0:
1201 jjmatchedKind = 0x7fffffff;
1202 jjmatchedPos = 0;
1203 curPos = jjMoveStringLiteralDfa0_0();
1204 break;
1205 case 1:
1206 jjmatchedKind = 0x7fffffff;
1207 jjmatchedPos = 0;
1208 curPos = jjMoveStringLiteralDfa0_1();
1209 break;
1210 case 2:
1211 jjmatchedKind = 0x7fffffff;
1212 jjmatchedPos = 0;
1213 curPos = jjMoveStringLiteralDfa0_2();
1214 break;
1215 case 3:
1216 jjmatchedKind = 0x7fffffff;
1217 jjmatchedPos = 0;
1218 curPos = jjMoveStringLiteralDfa0_3();
1219 break;
1220 }
1221
1222 if (jjmatchedKind != 0x7fffffff) {
1223 if (jjmatchedPos + 1 < curPos) {
1224 input_stream->backup(curPos - jjmatchedPos - 1);
1225 }
1226 if ((jjtoToken[jjmatchedKind >> 6] & ((int64_t)1 << (jjmatchedKind & 077))) != 0) {
1227 matchedToken = jjFillToken();
1228 if (jjnewLexState[jjmatchedKind] != -1) {
1229 curLexState = jjnewLexState[jjmatchedKind];
1230 }
1231 return matchedToken;
1232 } else {
1233 if (jjnewLexState[jjmatchedKind] != -1) {
1234 curLexState = jjnewLexState[jjmatchedKind];
1235 }
1236 continue;
1237 }
1238 }
1239 int32_t error_line = input_stream->getEndLine();
1240 int32_t error_column = input_stream->getEndColumn();
1241 String error_after;
1242 bool EOFSeen = false;
1243 try {
1244 input_stream->readChar();
1245 input_stream->backup(1);
1246 } catch (IOException&) {
1247 EOFSeen = true;
1248 error_after = curPos <= 1 ? L"" : input_stream->GetImage();
1249 if (curChar == L'\n' || curChar == L'\r') {
1250 ++error_line;
1251 error_column = 0;
1252 } else {
1253 ++error_column;
1254 }
1255 }
1256
1257 if (!EOFSeen) {
1258 input_stream->backup(1);
1259 error_after = curPos <= 1 ? L"" : input_stream->GetImage();
1260 }
1261
1262 boost::throw_exception(QueryParserError(QueryParseError::lexicalError(EOFSeen, curLexState, error_line, error_column, error_after, curChar)));
1263 }
1264 }
1265
jjCheckNAdd(int32_t state)1266 void QueryParserTokenManager::jjCheckNAdd(int32_t state) {
1267 if (jjrounds[state] != jjround) {
1268 jjstateSet[jjnewStateCnt++] = state;
1269 jjrounds[state] = jjround;
1270 }
1271 }
1272
jjAddStates(int32_t start,int32_t end)1273 void QueryParserTokenManager::jjAddStates(int32_t start, int32_t end) {
1274 do {
1275 jjstateSet[jjnewStateCnt++] = jjnextStates[start];
1276 } while (start++ != end);
1277 }
1278
jjCheckNAddTwoStates(int32_t state1,int32_t state2)1279 void QueryParserTokenManager::jjCheckNAddTwoStates(int32_t state1, int32_t state2) {
1280 jjCheckNAdd(state1);
1281 jjCheckNAdd(state2);
1282 }
1283
jjCheckNAddStates(int32_t start,int32_t end)1284 void QueryParserTokenManager::jjCheckNAddStates(int32_t start, int32_t end) {
1285 do {
1286 jjCheckNAdd(jjnextStates[start]);
1287 } while (start++ != end);
1288 }
1289
1290 }
1291