コード例 #1
0
ファイル: Parser.cs プロジェクト: BryanApellanes/Naizari
 /// <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;
 }
コード例 #2
0
ファイル: Parser.cs プロジェクト: BryanApellanes/Naizari
 /// <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);
     }
 }
コード例 #3
0
ファイル: Parser.cs プロジェクト: BryanApellanes/Naizari
 /// <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;
 }
コード例 #4
0
ファイル: Parser.cs プロジェクト: BryanApellanes/Naizari
 /// <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";
 }
コード例 #5
0
ファイル: Parser.cs プロジェクト: BryanApellanes/Naizari
 /// <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;
 }
コード例 #6
0
ファイル: Token.cs プロジェクト: BryanApellanes/Naizari
 private bool Equals(Token other)
 {
     return type == other.type && value == other.value;
 }