23 using System.Collections.Generic;
24 using System.Diagnostics;
25 using System.Globalization;
28 using Lucene.Net.Analysis;
29 using Lucene.Net.Analysis.Tokenattributes;
30 using Lucene.Net.Search;
31 using Lucene.Net.Support;
32 using Lucene.Net.Util;
38 using Term = Lucene.Net.Index.Term;
47 using Query = Lucene.Net.Search.Query;
48 using Single = Lucene.Net.Support.Single;
54 namespace Lucene.Net.QueryParsers
133 private static int CONJ_NONE = 0;
134 private static int CONJ_AND = 1;
135 private static int CONJ_OR = 2;
137 private static int MOD_NONE = 0;
138 private static int MOD_NOT = 10;
139 private static int MOD_REQ = 11;
150 private Operator operator_Renamed = OR_OPERATOR;
152 private bool lowercaseExpandedTerms =
true;
154 private bool allowLeadingWildcard =
false;
155 private bool enablePositionIncrements =
true;
158 private bool _useJavaStyleDateRangeParsing =
false;
161 private String field;
162 private int phraseSlop = 0;
165 private System.Globalization.CultureInfo locale = System.Globalization.CultureInfo.CurrentCulture;
168 private DateTools.Resolution dateResolution = null;
170 private IDictionary<String,
DateTools.Resolution> fieldToDateResolution = null;
174 private System.Globalization.CompareInfo rangeCollator = null;
197 if (matchVersion.OnOrAfter(
Version.LUCENE_29))
199 enablePositionIncrements =
true;
203 enablePositionIncrements =
false;
207 if (matchVersion.OnOrAfter(
Version.LUCENE_30))
209 _useJavaStyleDateRangeParsing =
true;
217 public virtual Query Parse(String query)
223 Query res = TopLevelQuery(field);
224 return res ?? NewBooleanQuery(
false);
237 throw new ParseException(
"Cannot parse '" + query +
"': too many bool clauses", tmc);
244 get {
return analyzer; }
248 public virtual string Field
250 get {
return field; }
257 public virtual float FuzzyMinSim
259 get {
return fuzzyMinSim; }
260 set { this.fuzzyMinSim = value; }
265 public virtual int FuzzyPrefixLength
267 get {
return fuzzyPrefixLength; }
268 set { this.fuzzyPrefixLength = value; }
274 public virtual int PhraseSlop
276 set { this.phraseSlop = value; }
277 get {
return phraseSlop; }
289 public virtual bool AllowLeadingWildcard
291 set { this.allowLeadingWildcard = value; }
292 get {
return allowLeadingWildcard; }
304 public virtual bool EnablePositionIncrements
306 set { this.enablePositionIncrements = value; }
307 get {
return enablePositionIncrements; }
317 public virtual Operator DefaultOperator
319 set { this.operator_Renamed = value; }
320 get {
return operator_Renamed; }
326 public virtual bool LowercaseExpandedTerms
328 set { this.lowercaseExpandedTerms = value; }
329 get {
return lowercaseExpandedTerms; }
344 set { multiTermRewriteMethod = value; }
345 get {
return multiTermRewriteMethod; }
349 public virtual CultureInfo Locale
351 set { this.locale = value; }
352 get {
return locale; }
362 public virtual void SetDateResolution(
DateTools.Resolution dateResolution)
364 this.dateResolution = dateResolution;
374 public virtual void SetDateResolution(String fieldName,
DateTools.Resolution dateResolution)
376 if (fieldName == null)
378 throw new ArgumentException(
"Field cannot be null.");
381 if (fieldToDateResolution == null)
384 fieldToDateResolution =
new HashMap<String,
DateTools.Resolution>();
387 fieldToDateResolution.Add(fieldName, dateResolution);
394 public virtual DateTools.Resolution getDateResolution(String fieldName)
396 if (fieldName == null)
398 throw new ArgumentException(
"Field cannot be null.");
401 if (fieldToDateResolution == null)
404 return this.dateResolution;
407 DateTools.Resolution resolution = fieldToDateResolution[fieldName];
408 if (resolution == null)
411 resolution = this.dateResolution;
428 public virtual CompareInfo RangeCollator
430 set { rangeCollator = value; }
431 get {
return rangeCollator; }
434 protected internal virtual void AddClause(List<BooleanClause> clauses,
int conj,
int mods,
Query q)
436 bool required, prohibited;
440 if (clauses.Count > 0 && conj == CONJ_AND)
447 if (clauses.Count > 0 && operator_Renamed == AND_OPERATOR && conj == CONJ_OR)
463 if (operator_Renamed == OR_OPERATOR)
467 prohibited = (mods == MOD_NOT);
468 required = (mods == MOD_REQ);
469 if (conj == CONJ_AND && !prohibited)
478 prohibited = (mods == MOD_NOT);
479 required = (!prohibited && conj != CONJ_OR);
481 if (required && !prohibited)
482 clauses.Add(NewBooleanClause(q,
Occur.MUST));
483 else if (!required && !prohibited)
484 clauses.Add(NewBooleanClause(q,
Occur.SHOULD));
485 else if (!required && prohibited)
486 clauses.Add(NewBooleanClause(q,
Occur.MUST_NOT));
488 throw new SystemException(
"Clause cannot be both required and prohibited");
494 protected internal virtual Query GetFieldQuery(String field, String queryText)
502 source = analyzer.ReusableTokenStream(field,
new StringReader(queryText));
507 source = analyzer.TokenStream(field,
new StringReader(queryText));
514 bool success =
false;
536 int positionCount = 0;
537 bool severalTokensAtSamePosition =
false;
539 bool hasMoreTokens =
false;
545 while (hasMoreTokens)
549 if (positionIncrement != 0)
551 positionCount += positionIncrement;
555 severalTokensAtSamePosition =
true;
580 else if (numTokens == 1)
586 Debug.Assert(hasNext);
593 return NewTermQuery(
new Term(field, term));
597 if (severalTokensAtSamePosition)
599 if (positionCount == 1)
603 for (
int i = 0; i < numTokens; i++)
609 Debug.Assert(hasNext);
617 Query currentQuery = NewTermQuery(
618 new Term(field, term));
627 mpq.
Slop = phraseSlop;
628 List<Term> multiTerms =
new List<Term>();
630 for (
int i = 0; i < numTokens; i++)
633 int positionIncrement = 1;
637 Debug.Assert(hasNext ==
true);
639 if (posIncrAtt != null)
649 if (positionIncrement > 0 && multiTerms.Count > 0)
651 if (enablePositionIncrements)
653 mpq.
Add(multiTerms.ToArray(), position);
657 mpq.
Add(multiTerms.ToArray());
661 position += positionIncrement;
662 multiTerms.Add(
new Term(field, term));
664 if (enablePositionIncrements)
666 mpq.
Add(multiTerms.ToArray(), position);
670 mpq.
Add(multiTerms.ToArray());
678 pq.
Slop = phraseSlop;
682 for (
int i = 0; i < numTokens; i++)
685 int positionIncrement = 1;
690 Debug.Assert(hasNext ==
true);
692 if (posIncrAtt != null)
702 if (enablePositionIncrements)
704 position += positionIncrement;
705 pq.
Add(
new Term(field, term), position);
725 protected internal virtual Query GetFieldQuery(String field, String queryText,
int slop)
727 Query query = GetFieldQuery(field, queryText);
743 protected internal virtual Query GetRangeQuery(String field,
748 if (lowercaseExpandedTerms)
750 part1 = part1.ToLower();
751 part2 = part2.ToLower();
757 if (_useJavaStyleDateRangeParsing)
764 var shortFormat = locale.DateTimeFormat.ShortDatePattern;
765 d1 = DateTime.ParseExact(part1, shortFormat, locale);
766 d2 = DateTime.ParseExact(part2, shortFormat, locale);
770 d1 = DateTime.Parse(part1, locale);
771 d2 = DateTime.Parse(part2, locale);
779 var cal = locale.Calendar;
780 d2 = cal.AddHours(d2, 23);
781 d2 = cal.AddMinutes(d2, 59);
782 d2 = cal.AddSeconds(d2, 59);
783 d2 = cal.AddMilliseconds(d2, 999);
785 DateTools.Resolution resolution = getDateResolution(field);
786 if (resolution == null)
796 part1 =
DateTools.DateToString(d1, resolution);
797 part2 =
DateTools.DateToString(d2, resolution);
804 return NewRangeQuery(field, part1, part2, inclusive);
812 protected internal virtual BooleanQuery NewBooleanQuery(
bool disableCoord)
834 protected internal virtual Query NewTermQuery(
Term term)
842 protected internal virtual PhraseQuery NewPhraseQuery()
860 protected internal virtual Query NewPrefixQuery(
Term prefix)
874 protected internal virtual Query NewFuzzyQuery(
Term term,
float minimumSimilarity,
int prefixLength)
877 return new FuzzyQuery(term, minimumSimilarity, prefixLength);
891 protected internal virtual Query NewRangeQuery(String field, String part1, String part2,
bool inclusive)
899 protected internal virtual Query NewMatchAllDocsQuery()
909 protected internal virtual Query NewWildcardQuery(
Term t)
929 protected internal virtual Query GetBooleanQuery(IList<BooleanClause> clauses)
931 return GetBooleanQuery(clauses,
false);
951 protected internal virtual Query GetBooleanQuery(IList<BooleanClause> clauses,
bool disableCoord)
953 if (clauses.Count == 0)
958 foreach (var clause
in clauses)
989 protected internal virtual Query GetWildcardQuery(String field, String termStr)
991 if (
"*".Equals(field))
993 if (
"*".Equals(termStr))
return NewMatchAllDocsQuery();
995 if (!allowLeadingWildcard && (termStr.StartsWith(
"*") || termStr.StartsWith(
"?")))
996 throw new ParseException(
"'*' or '?' not allowed as first character in WildcardQuery");
997 if (lowercaseExpandedTerms)
999 termStr = termStr.ToLower();
1002 return NewWildcardQuery(t);
1031 protected internal virtual Query GetPrefixQuery(String field, String termStr)
1033 if (!allowLeadingWildcard && termStr.StartsWith(
"*"))
1034 throw new ParseException(
"'*' not allowed as first character in PrefixQuery");
1035 if (lowercaseExpandedTerms)
1037 termStr = termStr.ToLower();
1040 return NewPrefixQuery(t);
1057 protected internal virtual Query GetFuzzyQuery(String field, String termStr,
float minSimilarity)
1059 if (lowercaseExpandedTerms)
1061 termStr = termStr.ToLower();
1064 return NewFuzzyQuery(t, minSimilarity, fuzzyPrefixLength);
1075 private String DiscardEscapeChar(String input)
1078 char[] output =
new char[input.Length];
1087 bool lastCharWasEscapeChar =
false;
1091 int codePointMultiplier = 0;
1096 for (
int i = 0; i < input.Length; i++)
1098 char curChar = input[i];
1099 if (codePointMultiplier > 0)
1101 codePoint += HexToInt(curChar) * codePointMultiplier;
1102 codePointMultiplier =
Number.
URShift(codePointMultiplier, 4);
1103 if (codePointMultiplier == 0)
1105 output[Length++] = (char)codePoint;
1109 else if (lastCharWasEscapeChar)
1114 codePointMultiplier = 16 * 16 * 16;
1119 output[Length] = curChar;
1122 lastCharWasEscapeChar =
false;
1126 if (curChar ==
'\\')
1128 lastCharWasEscapeChar =
true;
1132 output[Length] = curChar;
1138 if (codePointMultiplier > 0)
1140 throw new ParseException(
"Truncated unicode escape sequence.");
1143 if (lastCharWasEscapeChar)
1145 throw new ParseException(
"Term can not end with escape character.");
1148 return new String(output, 0, Length);
1152 private static int HexToInt(
char c)
1154 if (
'0' <= c && c <=
'9')
1158 else if (
'a' <= c && c <=
'f')
1160 return c -
'a' + 10;
1162 else if (
'A' <= c && c <=
'F')
1164 return c -
'A' + 10;
1168 throw new ParseException(
"None-hex character in unicode escape sequence: " + c);
1175 public static String Escape(String s)
1177 StringBuilder sb =
new StringBuilder();
1178 for (
int i = 0; i < s.Length; i++)
1182 if (c ==
'\\' || c ==
'+' || c ==
'-' || c ==
'!' || c ==
'(' || c ==
')' || c ==
':'
1183 || c ==
'^' || c ==
'[' || c ==
']' || c ==
'\"' || c ==
'{' || c ==
'}' || c ==
'~'
1184 || c ==
'*' || c ==
'?' || c ==
'|' || c ==
'&')
1190 return sb.ToString();
1198 public static void Main(String[] args)
1200 if (args.Length == 0)
1202 Console.WriteLine(
"Usage: java org.apache.lucene.queryParser.QueryParser <input>");
1203 Environment.Exit(0);
1207 Console.WriteLine(q.
ToString(
"field"));
1212 public int Conjunction()
1214 int ret = CONJ_NONE;
1215 switch ((jj_ntk == -1) ? Jj_ntk() : jj_ntk)
1219 switch ((jj_ntk == -1) ? Jj_ntk() : jj_ntk)
1222 Jj_consume_token(AndToken);
1226 Jj_consume_token(OrToken);
1231 Jj_consume_token(-1);
1240 if (
true)
return ret;
1242 throw new ApplicationException(
"Missing return statement in function");
1245 public int Modifiers()
1248 switch ((jj_ntk == -1) ? Jj_ntk() : jj_ntk)
1253 switch ((jj_ntk == -1) ? Jj_ntk() : jj_ntk)
1256 Jj_consume_token(PlusToken);
1260 Jj_consume_token(MinusToken);
1264 Jj_consume_token(NotToken);
1269 Jj_consume_token(-1);
1278 if (
true)
return ret;
1280 throw new Exception(
"Missing return statement in function");
1284 public Query TopLevelQuery(String field)
1288 Jj_consume_token(0);
1292 throw new Exception(
"Missing return statement in function");
1297 List<BooleanClause> clauses =
new List<BooleanClause>();
1298 Query q, firstQuery = null;
1302 AddClause(clauses, CONJ_NONE, mods, q);
1303 if (mods == MOD_NONE)
1307 switch ((jj_ntk == -1) ? Jj_ntk() : jj_ntk)
1318 case PrefixTermToken:
1320 case RangeInStartToken:
1321 case RangeExStartToken:
1329 conj = Conjunction();
1332 AddClause(clauses, conj, mods, q);
1337 if (clauses.Count == 1 && firstQuery != null)
1339 if (
true)
return firstQuery;
1342 return GetBooleanQuery(clauses);
1348 Token fieldToken = null, boost = null;
1351 switch ((jj_ntk == -1) ? Jj_ntk() : jj_ntk)
1354 fieldToken = Jj_consume_token(TermToken);
1355 Jj_consume_token(ColonToken);
1356 field = DiscardEscapeChar(fieldToken.
image);
1359 Jj_consume_token(StarToken);
1360 Jj_consume_token(ColonToken);
1365 Jj_consume_token(-1);
1373 switch ((jj_ntk == -1) ? Jj_ntk() : jj_ntk)
1378 case PrefixTermToken:
1380 case RangeInStartToken:
1381 case RangeExStartToken:
1386 Jj_consume_token(LParanToken);
1388 Jj_consume_token(RParenToken);
1389 switch ((jj_ntk == -1) ? Jj_ntk() : jj_ntk)
1392 Jj_consume_token(CaratToken);
1393 boost = Jj_consume_token(NumberToken);
1402 Jj_consume_token(-1);
1419 throw new Exception(
"Missing return statement in function");
1424 Token term, boost = null, fuzzySlop = null, goop1, goop2;
1425 bool prefix =
false;
1426 bool wildcard =
false;
1429 switch ((jj_ntk == -1) ? Jj_ntk() : jj_ntk)
1433 case PrefixTermToken:
1436 switch ((jj_ntk == -1) ? Jj_ntk() : jj_ntk)
1439 term = Jj_consume_token(TermToken);
1442 term = Jj_consume_token(StarToken);
1445 case PrefixTermToken:
1446 term = Jj_consume_token(PrefixTermToken);
1450 term = Jj_consume_token(WildTermToken);
1454 term = Jj_consume_token(NumberToken);
1458 Jj_consume_token(-1);
1461 switch ((jj_ntk == -1) ? Jj_ntk() : jj_ntk)
1463 case FuzzySlopToken:
1464 fuzzySlop = Jj_consume_token(FuzzySlopToken);
1471 switch ((jj_ntk == -1) ? Jj_ntk() : jj_ntk)
1474 Jj_consume_token(CaratToken);
1475 boost = Jj_consume_token(NumberToken);
1476 switch ((jj_ntk == -1) ? Jj_ntk() : jj_ntk)
1478 case FuzzySlopToken:
1479 fuzzySlop = Jj_consume_token(FuzzySlopToken);
1483 jj_la1[10] = jj_gen;
1488 jj_la1[11] = jj_gen;
1491 String termImage = DiscardEscapeChar(term.
image);
1494 q = GetWildcardQuery(field, termImage);
1498 q = GetPrefixQuery(field,
1499 DiscardEscapeChar(term.
image.Substring(0, (term.
image.Length - 1) - (0))));
1503 float fms = fuzzyMinSim;
1511 if (fms < 0.0f || fms > 1.0f)
1516 "Minimum similarity for a FuzzyQuery has to be between 0.0f and 1.0f !");
1519 q = GetFuzzyQuery(field, termImage, fms);
1523 q = GetFieldQuery(field, termImage);
1526 case RangeInStartToken:
1527 Jj_consume_token(RangeInStartToken);
1528 switch ((jj_ntk == -1) ? Jj_ntk() : jj_ntk)
1530 case RangeInGoopToken:
1531 goop1 = Jj_consume_token(RangeInGoopToken);
1533 case RangeInQuotedToken:
1534 goop1 = Jj_consume_token(RangeInQuotedToken);
1537 jj_la1[12] = jj_gen;
1538 Jj_consume_token(-1);
1541 switch ((jj_ntk == -1) ? Jj_ntk() : jj_ntk)
1543 case RangeInToToken:
1544 Jj_consume_token(RangeInToToken);
1547 jj_la1[13] = jj_gen;
1550 switch ((jj_ntk == -1) ? Jj_ntk() : jj_ntk)
1552 case RangeInGoopToken:
1553 goop2 = Jj_consume_token(RangeInGoopToken);
1555 case RangeInQuotedToken:
1556 goop2 = Jj_consume_token(RangeInQuotedToken);
1559 jj_la1[14] = jj_gen;
1560 Jj_consume_token(-1);
1563 Jj_consume_token(RangeInEndToken);
1564 switch ((jj_ntk == -1) ? Jj_ntk() : jj_ntk)
1567 Jj_consume_token(CaratToken);
1568 boost = Jj_consume_token(NumberToken);
1571 jj_la1[15] = jj_gen;
1574 if (goop1.kind == RangeInQuotedToken)
1576 goop1.image = goop1.image.Substring(1, (goop1.image.Length - 1) - (1));
1578 if (goop2.kind == RangeInQuotedToken)
1580 goop2.image = goop2.image.Substring(1, (goop2.image.Length - 1) - (1));
1582 q = GetRangeQuery(field, DiscardEscapeChar(goop1.image), DiscardEscapeChar(goop2.image),
true);
1584 case RangeExStartToken:
1585 Jj_consume_token(RangeExStartToken);
1586 switch ((jj_ntk == -1) ? Jj_ntk() : jj_ntk)
1588 case RangeExGoopToken:
1589 goop1 = Jj_consume_token(RangeExGoopToken);
1591 case RangeExQuotedToken:
1592 goop1 = Jj_consume_token(RangeExQuotedToken);
1595 jj_la1[16] = jj_gen;
1596 Jj_consume_token(-1);
1599 switch ((jj_ntk == -1) ? Jj_ntk() : jj_ntk)
1601 case RangeExToToken:
1602 Jj_consume_token(RangeExToToken);
1605 jj_la1[17] = jj_gen;
1608 switch ((jj_ntk == -1) ? Jj_ntk() : jj_ntk)
1610 case RangeExGoopToken:
1611 goop2 = Jj_consume_token(RangeExGoopToken);
1613 case RangeExQuotedToken:
1614 goop2 = Jj_consume_token(RangeExQuotedToken);
1617 jj_la1[18] = jj_gen;
1618 Jj_consume_token(-1);
1621 Jj_consume_token(RangeExEndToken);
1622 switch ((jj_ntk == -1) ? Jj_ntk() : jj_ntk)
1625 Jj_consume_token(CaratToken);
1626 boost = Jj_consume_token(NumberToken);
1629 jj_la1[19] = jj_gen;
1632 if (goop1.kind == RangeExQuotedToken)
1634 goop1.image = goop1.image.Substring(1, (goop1.image.Length - 1) - (1));
1636 if (goop2.kind == RangeExQuotedToken)
1638 goop2.image = goop2.image.Substring(1, (goop2.image.Length - 1) - (1));
1641 q = GetRangeQuery(field, DiscardEscapeChar(goop1.image), DiscardEscapeChar(goop2.image),
false);
1644 term = Jj_consume_token(QuotedToken);
1645 switch ((jj_ntk == -1) ? Jj_ntk() : jj_ntk)
1647 case FuzzySlopToken:
1648 fuzzySlop = Jj_consume_token(FuzzySlopToken);
1651 jj_la1[20] = jj_gen;
1654 switch ((jj_ntk == -1) ? Jj_ntk() : jj_ntk)
1657 Jj_consume_token(CaratToken);
1658 boost = Jj_consume_token(NumberToken);
1661 jj_la1[21] = jj_gen;
1666 if (fuzzySlop != null)
1670 s = (int)
Single.
Parse(fuzzySlop.image.Substring(1));
1676 q = GetFieldQuery(field, DiscardEscapeChar(term.
image.Substring(1, (term.
image.Length - 1) - (1))),
1680 jj_la1[22] = jj_gen;
1681 Jj_consume_token(-1);
1686 float f = (float)1.0;
1707 throw new Exception(
"Missing return statement in function");
1710 private bool Jj_2_1(
int xla)
1713 jj_lastpos = jj_scanpos = token;
1718 catch (LookaheadSuccess)
1728 private bool Jj_3R_2()
1730 if (jj_scan_token(TermToken))
return true;
1731 if (jj_scan_token(ColonToken))
return true;
1735 private bool Jj_3_1()
1742 if (Jj_3R_3())
return true;
1747 private bool Jj_3R_3()
1749 if (jj_scan_token(StarToken))
return true;
1750 if (jj_scan_token(ColonToken))
return true;
1761 private Token jj_scanpos, jj_lastpos;
1764 private int[] jj_la1 =
new int[23];
1765 private static int[] jj_la1_0;
1766 private static int[] jj_la1_1;
1768 private static void Jj_la1_init_0()
1770 jj_la1_0 =
new int[]
1772 0x300, 0x300, 0x1c00, 0x1c00, 0x3ed3f00, 0x90000, 0x20000, 0x3ed2000, 0x2690000, 0x100000,
1773 0x100000, 0x20000, 0x30000000, 0x4000000, 0x30000000, 0x20000, 0x0, 0x40000000, 0x0, 0x20000
1774 , 0x100000, 0x20000, 0x3ed0000,
1778 private static void Jj_la1_init_1()
1780 jj_la1_1 =
new int[]
1782 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3, 0x0,
1783 0x3, 0x0, 0x0, 0x0, 0x0,
1787 private JJCalls[] jj_2_rtns =
new JJCalls[1];
1788 private bool jj_rescan =
false;
1789 private int jj_gc = 0;
1792 protected internal QueryParser(ICharStream stream)
1794 token_source =
new QueryParserTokenManager(stream);
1795 token =
new Token();
1798 for (
int i = 0; i < 23; i++) jj_la1[i] = -1;
1799 for (
int i = 0; i < jj_2_rtns.Length; i++) jj_2_rtns[i] =
new JJCalls();
1805 token_source.ReInit(stream);
1806 token =
new Token();
1809 for (
int i = 0; i < 23; i++) jj_la1[i] = -1;
1810 for (
int i = 0; i < jj_2_rtns.Length; i++) jj_2_rtns[i] =
new JJCalls();
1817 token =
new Token();
1820 for (
int i = 0; i < 23; i++) jj_la1[i] = -1;
1821 for (
int i = 0; i < jj_2_rtns.Length; i++) jj_2_rtns[i] =
new JJCalls();
1828 token =
new Token();
1831 for (
int i = 0; i < 23; i++) jj_la1[i] = -1;
1832 for (
int i = 0; i < jj_2_rtns.Length; i++) jj_2_rtns[i] =
new JJCalls();
1835 private Token Jj_consume_token(
int kind)
1838 if ((oldToken = token).next != null) token = token.
next;
1839 else token = token.
next = token_source.GetNextToken();
1841 if (token.kind == kind)
1847 for (
int i = 0; i < jj_2_rtns.Length; i++)
1849 JJCalls c = jj_2_rtns[i];
1852 if (c.gen < jj_gen) c.first = null;
1861 throw GenerateParseException();
1865 private sealed
class LookaheadSuccess : System.Exception
1869 private LookaheadSuccess jj_ls =
new LookaheadSuccess();
1870 private bool jj_scan_token(
int kind)
1872 if (jj_scanpos == jj_lastpos)
1875 if (jj_scanpos.next == null)
1877 jj_lastpos = jj_scanpos = jj_scanpos.next = token_source.GetNextToken();
1881 jj_lastpos = jj_scanpos = jj_scanpos.next;
1886 jj_scanpos = jj_scanpos.next;
1892 while (tok != null && tok != jj_scanpos)
1897 if (tok != null) Jj_add_error_token(kind, i);
1899 if (jj_scanpos.kind != kind)
return true;
1900 if (jj_la == 0 && jj_scanpos == jj_lastpos)
throw jj_ls;
1907 if (token.next != null) token = token.
next;
1908 else token = token.
next = token_source.GetNextToken();
1918 for (
int i = 0; i < index; i++)
1921 else t = t.
next = token_source.GetNextToken();
1926 private int Jj_ntk()
1928 if ((jj_nt = token.next) == null)
1929 return (jj_ntk = (token.next = token_source.GetNextToken()).kind);
1931 return (jj_ntk = jj_nt.kind);
1934 private List<int[]> jj_expentries =
new List<int[]>();
1935 private int[] jj_expentry;
1936 private int jj_kind = -1;
1937 private int[] jj_lasttokens =
new int[100];
1938 private int jj_endpos;
1940 private void Jj_add_error_token(
int kind,
int pos)
1942 if (pos >= 100)
return;
1943 if (pos == jj_endpos + 1)
1945 jj_lasttokens[jj_endpos++] = kind;
1947 else if (jj_endpos != 0)
1949 jj_expentry =
new int[jj_endpos];
1950 for (
int i = 0; i < jj_endpos; i++)
1952 jj_expentry[i] = jj_lasttokens[i];
1955 foreach (var oldentry
in jj_expentries)
1957 if (oldentry.Length == jj_expentry.Length)
1959 for (
int i = 0; i < jj_expentry.Length; i++)
1961 if (oldentry[i] != jj_expentry[i])
1966 jj_expentries.Add(jj_expentry);
1970 if (pos != 0) jj_lasttokens[(jj_endpos = pos) - 1] = kind;
1977 jj_expentries.Clear();
1978 bool[] la1tokens =
new bool[34];
1981 la1tokens[jj_kind] =
true;
1984 for (
int i = 0; i < 23; i++)
1986 if (jj_la1[i] == jj_gen)
1988 for (
int j = 0; j < 32; j++)
1990 if ((jj_la1_0[i] & (1 << j)) != 0)
1992 la1tokens[j] =
true;
1994 if ((jj_la1_1[i] & (1 << j)) != 0)
1996 la1tokens[32 + j] =
true;
2001 for (
int i = 0; i < 34; i++)
2005 jj_expentry =
new int[1];
2007 jj_expentries.Add(jj_expentry);
2012 Jj_add_error_token(0, 0);
2013 int[][] exptokseq =
new int[jj_expentries.Count][];
2014 for (
int i = 0; i < jj_expentries.Count; i++)
2016 exptokseq[i] = jj_expentries[i];
2022 public void Enable_tracing()
2027 public void Disable_tracing()
2031 private void Jj_rescan_token()
2034 for (
int i = 0; i < 1; i++)
2038 JJCalls p = jj_2_rtns[i];
2044 jj_lastpos = jj_scanpos = p.first;
2053 }
while (p != null);
2055 catch (LookaheadSuccess)
2062 private void Jj_save(
int index,
int xla)
2064 JJCalls p = jj_2_rtns[index];
2065 while (p.gen > jj_gen)
2069 p = p.next =
new JJCalls();
2074 p.gen = jj_gen + xla - jj_la;
2079 internal sealed
class JJCalls
2082 internal Token first;
2084 internal JJCalls next;