/// <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> public ParseException(Token currentTokenVal, int[][] expectedTokenSequencesVal, string[] tokenImageVal) : base(Initialize(currentTokenVal, expectedTokenSequencesVal, tokenImageVal)) { CurrentToken = currentTokenVal; ExpectedTokenSequences = expectedTokenSequencesVal; TokenImage = tokenImageVal; }
/// <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> private static string Initialize(Token currentToken, int[][] expectedTokenSequences, string[] tokenImage) { string eol = /*System.getProperty("line.separator", "\n");*/ Environment.NewLine; var 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; }
private void Jj_rescan_token() { jj_rescan = true; for (int i = 0; i < 2; 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; case 1: Jj_3_2(); break; } } p = p.next; } while (p != null); } catch (LookaheadSuccess ls) { } } jj_rescan = false; }
private int Jj_ntk_f() { if ((jj_nt = token.Next) == null) { //return (jj_ntk = (token.next = token_source.getNextToken()).kind); token.Next = token_source.GetNextToken(); jj_ntk = token.Next.Kind; return jj_ntk; } else { return (jj_ntk = jj_nt.Kind); } }
/// <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; }
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; }
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(); }
/// <summary>Reinitialize</summary> public void ReInit(TregexParserTokenManager tm) { token_source = tm; token = new Token(); jj_ntk = -1; jj_gen = 0; for (int i = 0; i < 28; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.Length; i++) jj_2_rtns[i] = new JjCalls(); }
/// <summary>Reinitialize</summary> public void ReInit(TextReader stream) { jj_input_stream.ReInit(stream, 1, 1); token_source.ReInit(jj_input_stream); token = new Token(); jj_ntk = -1; jj_gen = 0; for (int i = 0; i < 28; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.Length; i++) jj_2_rtns[i] = new JjCalls(); }
/// <summary>Constructor</summary> public TregexParser(TextReader stream) { jj_input_stream = new SimpleCharStream(stream, 1, 1); token_source = new TregexParserTokenManager(jj_input_stream); token = new Token(); jj_ntk = -1; jj_gen = 0; for (int i = 0; i < 28; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.Length; i++) jj_2_rtns[i] = new JjCalls(); }
/// <summary>Reinitialize</summary> public void ReInit(Stream stream, string encoding) { try { jj_input_stream.ReInit(stream, encoding, 1, 1); } catch (IOException e) { throw new SystemException("", e); } token_source.ReInit(jj_input_stream); token = new Token(); jj_ntk = -1; jj_gen = 0; for (int i = 0; i < 28; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.Length; i++) jj_2_rtns[i] = new JjCalls(); }
/// <summary> /// Constructor with Stream and supplied encoding /// </summary> public TregexParser(Stream stream, string encoding) { try { jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1); } catch (IOException e) { throw new SystemException("", e); } token_source = new TregexParserTokenManager(jj_input_stream); token = new Token(); jj_ntk = -1; jj_gen = 0; for (int i = 0; i < 28; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.Length; i++) jj_2_rtns[i] = new JjCalls(); }