Exemplo n.º 1
0
 /// <summary>
 /// This constructor is used by the method "GenerateParseException"
 /// in the generated parser.  Calling this constructor generates
 /// a new object of this type with the fields "currentToken",
 /// "expectedTokenSequences", and "tokenImage" set.
 /// </summary>
 /// <param name="currentTokenVal"></param>
 /// <param name="expectedTokenSequencesVal"></param>
 /// <param name="tokenImageVal"></param>
 public ParseException(Token currentTokenVal,
     int[][] expectedTokenSequencesVal,
     string[] tokenImageVal)
     : base(Initialize(currentTokenVal, expectedTokenSequencesVal, tokenImageVal))
 {
     currentToken = currentTokenVal;
     expectedTokenSequences = expectedTokenSequencesVal;
     tokenImage = tokenImageVal;
 }
Exemplo n.º 2
0
 /// <summary>
 /// This constructor is used by the method "GenerateParseException"
 /// in the generated parser.  Calling this constructor generates
 /// a new object of this type with the fields <paramref name="currentToken"/>,
 /// <paramref name="expectedTokenSequences"/>, and <paramref name="tokenImage"/> set.
 /// </summary>
 public ParseException(Token currentToken,
                 int[][] expectedTokenSequences,
                 string[] tokenImage)
     : base(Initialize(currentToken, expectedTokenSequences, tokenImage))
 {
     this.currentToken = currentToken;
     this.expectedTokenSequences = expectedTokenSequences;
     this.tokenImage = tokenImage;
 }
Exemplo n.º 3
0
 private void Jj_rescan_token()
 {
     jj_rescan = true;
     for (int i = 0; i < 1; i++)
     {
         try
         {
             JJCalls p = jj_2_rtns[i];
             do
             {
                 if (p.gen > jj_gen)
                 {
                     jj_la = p.arg; jj_lastpos = jj_scanpos = p.first;
                     switch (i)
                     {
                         case 0: Jj_3_1(); break;
                     }
                 }
                 p = p.next;
             } while (p != null);
         }
         catch (LookaheadSuccess /*ls*/) { }
     }
     jj_rescan = false;
 }
Exemplo n.º 4
0
 private int Jj_ntk()
 {
     if ((jj_nt = token.next) == null)
         return (jj_ntk = (token.next = token_source.GetNextToken()).kind);
     else
         return (jj_ntk = jj_nt.kind);
 }
Exemplo n.º 5
0
 /// <summary>Get the next Token.</summary>
 public Token GetNextToken()
 {
     if (token.next != null) token = token.next;
     else token = token.next = token_source.GetNextToken();
     jj_ntk = -1;
     jj_gen++;
     return token;
 }
Exemplo n.º 6
0
 private bool Jj_scan_token(int kind)
 {
     if (jj_scanpos == jj_lastpos)
     {
         jj_la--;
         if (jj_scanpos.next == null)
         {
             jj_lastpos = jj_scanpos = jj_scanpos.next = token_source.GetNextToken();
         }
         else
         {
             jj_lastpos = jj_scanpos = jj_scanpos.next;
         }
     }
     else
     {
         jj_scanpos = jj_scanpos.next;
     }
     if (jj_rescan)
     {
         int i = 0; Token tok = token;
         while (tok != null && tok != jj_scanpos) { i++; tok = tok.next; }
         if (tok != null) Jj_add_error_token(kind, i);
     }
     if (jj_scanpos.kind != kind) return true;
     if (jj_la == 0 && jj_scanpos == jj_lastpos) throw jj_ls;
     return false;
 }
Exemplo n.º 7
0
 private Token Jj_consume_token(int kind)
 {
     Token oldToken;
     if ((oldToken = token).next != null) token = token.next;
     else token = token.next = token_source.GetNextToken();
     jj_ntk = -1;
     if (token.kind == kind)
     {
         jj_gen++;
         if (++jj_gc > 100)
         {
             jj_gc = 0;
             for (int i = 0; i < jj_2_rtns.Length; i++)
             {
                 JJCalls c = jj_2_rtns[i];
                 while (c != null)
                 {
                     if (c.gen < jj_gen) c.first = null;
                     c = c.next;
                 }
             }
         }
         return token;
     }
     token = oldToken;
     jj_kind = kind;
     throw GenerateParseException();
 }
Exemplo n.º 8
0
 /// <summary>Reinitialize.</summary>
 public virtual void ReInit(QueryParserTokenManager tm)
 {
     token_source = tm;
     token = new Token();
     jj_ntk = -1;
     jj_gen = 0;
     for (int i = 0; i < 10; i++) jj_la1[i] = -1;
     for (int i = 0; i < jj_2_rtns.Length; i++) jj_2_rtns[i] = new JJCalls();
 }
Exemplo n.º 9
0
 /// <summary>Reinitialize.</summary>
 public virtual void ReInit(ICharStream stream)
 {
     token_source.ReInit(stream);
     token = new Token();
     jj_ntk = -1;
     jj_gen = 0;
     for (int i = 0; i < 10; i++) jj_la1[i] = -1;
     for (int i = 0; i < jj_2_rtns.Length; i++) jj_2_rtns[i] = new JJCalls();
 }
Exemplo n.º 10
0
 /// <summary>Constructor with user supplied <see cref="ICharStream"/>.</summary>
 public QueryParser(ICharStream stream)
 {
     token_source = new QueryParserTokenManager(stream);
     token = new Token();
     jj_ntk = -1;
     jj_gen = 0;
     for (int i = 0; i < 10; i++) jj_la1[i] = -1;
     for (int i = 0; i < jj_2_rtns.Length; i++) jj_2_rtns[i] = new JJCalls();
 }
Exemplo n.º 11
0
 protected virtual SrndQuery GetDistanceQuery(
     IEnumerable<SrndQuery> queries,
     bool infix,
     Token dToken,
     bool ordered)
 {
     DistanceQuery dq = new DistanceQuery(queries,
                                         infix,
                                         GetOpDistance(dToken.image),
                                         dToken.image,
                                         ordered);
     CheckDistanceSubQueries(dq, dToken.image);
     return dq;
 }
Exemplo n.º 12
0
 protected virtual SrndQuery GetNotQuery(IEnumerable<SrndQuery> queries, Token notToken)
 {
     return new NotQuery(queries, notToken.image);
 }
Exemplo n.º 13
0
 protected virtual SrndQuery GetAndQuery(IEnumerable<SrndQuery> queries, bool infix, Token andToken)
 {
     return new AndQuery(queries, infix, andToken.image);
 }
Exemplo n.º 14
0
 protected virtual SrndQuery GetOrQuery(IEnumerable<SrndQuery> queries, bool infix, Token orToken)
 {
     return new OrQuery(queries, infix, orToken.image);
 }
Exemplo n.º 15
0
 /// <summary>
 /// It uses "currentToken" and "expectedTokenSequences" to generate a parse
 /// error message and returns it.  If this object has been created
 /// due to a parse error, and you do not catch it (it gets thrown
 /// from the parser) the correct error message
 /// gets displayed.
 /// </summary>
 /// <param name="currentToken"></param>
 /// <param name="expectedTokenSequences"></param>
 /// <param name="tokenImage"></param>
 /// <returns></returns>
 private static string Initialize(Token currentToken,
     int[][] expectedTokenSequences,
     string[] tokenImage)
 {
     StringBuilder expected = new StringBuilder();
     int maxSize = 0;
     for (int i = 0; i < expectedTokenSequences.Length; i++)
     {
         if (maxSize < expectedTokenSequences[i].Length)
         {
             maxSize = expectedTokenSequences[i].Length;
         }
         for (int j = 0; j < expectedTokenSequences[i].Length; j++)
         {
             expected.Append(tokenImage[expectedTokenSequences[i][j]]).Append(' ');
         }
         if (expectedTokenSequences[i][expectedTokenSequences[i].Length - 1] != 0)
         {
             expected.Append("...");
         }
         expected.Append(eol).Append("    ");
     }
     string retval = "Encountered \"";
     Token tok = currentToken.next;
     for (int i = 0; i < maxSize; i++)
     {
         if (i != 0)
             retval += " ";
         if (tok.kind == 0)
         {
             retval += tokenImage[0];
             break;
         }
         retval += (" " + tokenImage[tok.kind]);
         retval += " \"";
         retval += Add_escapes(tok.image);
         retval += " \"";
         tok = tok.next;
     }
     retval += ("\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn);
     retval += ("." + eol);
     if (expectedTokenSequences.Length == 1)
     {
         retval += ("Was expecting:" + eol + "    ");
     }
     else
     {
         retval += ("Was expecting one of:" + eol + "    ");
     }
     retval += expected.ToString();
     return retval;
 }
Exemplo n.º 16
0
 private bool Jj_2_1(int xla)
 {
     jj_la = xla; jj_lastpos = jj_scanpos = token;
     try { return !Jj_3_1(); }
     catch (LookaheadSuccess) { return true; }
     finally { Jj_save(0, xla); }
 }