/// <summary> /// Handler for 1 or more construct /// </summary> /// <param name="separator">the separator token between items</param> /// <param name="terminal">the ending token</param> /// <param name="meth">the method to call to parse an item</param> /// <param name="result">the parsed expression</param> /// <returns>true if match parsed, false otherwise</returns> private bool ReadAhead(Token separator, Token terminal, ExpressionMethod meth, out Expression result) { Token tok = PeekToken(); result = null; if (tok == terminal) { ReadToken(); return false; } else if (tok == separator) { ReadToken(); } result = meth(); return true; }
/// <summary> /// Asserts that the token read is the one expected /// </summary> /// <param name="expected">the expected token</param> /// <param name="actual">the actual token</param> /// <param name="message">message to use in the exception if expected != actual</param> private static void RequireToken(Token expected, Token actual, string message) { if (actual != expected) { throw new ParseException(message + " Expected: " + expected + " got: " + actual); } }
/// <summary> /// Test the token to see if its a quoted string /// </summary> /// <param name="tok">the token to test</param> /// <returns>true if its a quoted string</returns> private static bool IsQuotedString(Token tok) { return tok.type == TokenType.DoubleQuotedString || tok.type == TokenType.SingleQuotedString; }
/// <summary> /// Test the token to see if its a keyword /// </summary> /// <param name="tok">the token to test</param> /// <returns>true if its a keyword</returns> private static bool IsKeyword(Token tok) { // include null? return tok.type == TokenType.Identifier && tok.value == "new"; }
/// <summary> /// Test the token to see if its an identifier /// </summary> /// <param name="tok">the token to test</param> /// <returns>true if its an identifier</returns> private static bool IsIdentifier(Token tok) { return tok.type == TokenType.Identifier; }
private bool Equals(Token other) { return type == other.type && value == other.value; }