From f8a4cbd4d6f1f480d32517d90db2a2c1b25a4895 Mon Sep 17 00:00:00 2001 From: Patrick Lioi Date: Thu, 11 Apr 2013 19:41:46 -0500 Subject: [PATCH] Identifiers may include _underscore_characters. --- src/Rook.Compiling/Syntax/RookLexer.cs | 2 +- src/Rook.Test/Compiling/Syntax/RookLexerTests.cs | 1 + src/Rook.Test/Compiling/Syntax/TokenParserTests.cs | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Rook.Compiling/Syntax/RookLexer.cs b/src/Rook.Compiling/Syntax/RookLexer.cs index 5452365..589a59c 100644 --- a/src/Rook.Compiling/Syntax/RookLexer.cs +++ b/src/Rook.Compiling/Syntax/RookLexer.cs @@ -41,7 +41,7 @@ public class RookLexer : Lexer # Close quote: "" "); - public static readonly Pattern Identifier = new Pattern("identifier", @"[a-zA-Z]+[a-zA-Z0-9]*"); + public static readonly Pattern Identifier = new Pattern("identifier", @"[_a-zA-Z]+[_a-zA-Z0-9]*"); public static readonly Operator Semicolon = new Operator(";"); public static readonly Operator LeftParen = new Operator("("); public static readonly Operator RightParen = new Operator(")"); diff --git a/src/Rook.Test/Compiling/Syntax/RookLexerTests.cs b/src/Rook.Test/Compiling/Syntax/RookLexerTests.cs index 9528088..d18ca4b 100644 --- a/src/Rook.Test/Compiling/Syntax/RookLexerTests.cs +++ b/src/Rook.Test/Compiling/Syntax/RookLexerTests.cs @@ -64,6 +64,7 @@ public void ShouldRecognizeIdentifiers() Tokenize("a").Single().ShouldEqual(RookLexer.Identifier, "a"); Tokenize("ab").Single().ShouldEqual(RookLexer.Identifier, "ab"); Tokenize("a0").Single().ShouldEqual(RookLexer.Identifier, "a0"); + Tokenize("_true_").Single().ShouldEqual(RookLexer.Identifier, "_true_"); } public void ShouldRecognizeOperatorsGreedily() diff --git a/src/Rook.Test/Compiling/Syntax/TokenParserTests.cs b/src/Rook.Test/Compiling/Syntax/TokenParserTests.cs index 46eb2d3..7652b32 100644 --- a/src/Rook.Test/Compiling/Syntax/TokenParserTests.cs +++ b/src/Rook.Test/Compiling/Syntax/TokenParserTests.cs @@ -48,6 +48,7 @@ public void ParsesIdentifiers() identifier.Parses("ab").WithValue(Token(RookLexer.Identifier, "ab")); identifier.Parses("a0").WithValue(Token(RookLexer.Identifier, "a0")); identifier.Parses("a01").WithValue(Token(RookLexer.Identifier, "a01")); + identifier.Parses("_true_").WithValue(Token(RookLexer.Identifier, "_true_")); var keywords = new[] {"true", "false", "int", "bool", "string", "void", "null", "if", "else", "fn", "class", "new"};