static void expectTokenType(Token t, Token.TokenType type) { if (t.type != type) { throw new ParserErrorExpected(type.ToString(), t.type.ToString(), t); } }
public virtual Token match(Token.TokenType expectedTokenType) { Token matchedToken = lookAhead(1); if (lookAheadType(1) == expectedTokenType) { #if WRITE_DEBUG_INFO Console.WriteLine("MATCHED TOKEN " + lookAhead(1).getTokenString() + " (line " + lookAhead(1).LineNr + ")"); #endif consumeCurrentToken(); } else { #if WRITE_DEBUG_INFO Console.WriteLine("FAILED TO MATCH TOKEN OF TYPE " + expectedTokenType.ToString() + " ...FOUND " + lookAhead(1).getTokenString() + " (line " + lookAhead(1).LineNr + ")"); #endif throw new Error( "The code word '" + lookAhead(1).getTokenString() + "'" + " does not compute. Expected " + expectedTokenType, Error.ErrorType.SYNTAX, lookAhead(1).LineNr, lookAhead(1).LinePosition); } return(matchedToken); }
/// <summary> /// 次に出現するトークンが特定の種類であることを確認し、読みます。<para /> /// 読めなかった場合はリワインドします。 /// </summary> /// <param name="reader">トークン リーダー</param> /// <param name="type">トークンの種類</param> private static Token AssertNext(ref TokenReader reader, Token.TokenType type) { if (!reader.IsRemainToken) { reader.PushError("クエリが解析の途中で終了しました。" + "ここには " + type.ToString() + " が存在しなければなりません。"); } var ntoken = reader.Get(); if (ntoken.Type != type) { reader.PushError("不明な文字です: " + reader.LookAhead() + " (インデックス:" + reader.LookAhead().DebugIndex + ")" + "ここには " + type.ToString() + " が存在しなければなりません。"); return(new Token() { Type = type, Value = null, DebugIndex = -1 }); } return(ntoken); }
public UnexpectedTokenException(Token offender, Token.TokenType expected) : base( "Unexpected Token: " + offender.ToString() + " (expected " + expected.ToString() + ")" ) { //Environment.Exit(1); }