diff --git a/Test/TestLexer.hs b/Test/TestLexer.hs index ddd55c9..99437e5 100644 --- a/Test/TestLexer.hs +++ b/Test/TestLexer.hs @@ -11,9 +11,9 @@ testEmptyComment = TestCase $ assertEqual "scan '/*x*/'" emptyTokenList $ alex testLineComment = TestCase $ assertEqual "scan '// comment'" emptyTokenList $ alexScanTokens "// comment" testLineCommentEnds = TestCase $ assertEqual "scan '// com\\n'" emptyTokenList $ alexScanTokens "// com\n" -testIdentifier = TestCase $ assertEqual "scan 'identifier'" [Identifier "identifier"] $ alexScanTokens "identifier" -testShortIdentifier = TestCase $ assertEqual "scan 'i'" [Identifier "i"] $ alexScanTokens "i" -testIdentifierWithNumber = TestCase $ assertEqual "scan 'i2'" [Identifier "i2"] $ alexScanTokens "i2" +testIdentifier = TestCase $ assertEqual "scan 'identifier'" [IDENTIFIER "identifier"] $ alexScanTokens "identifier" +testShortIdentifier = TestCase $ assertEqual "scan 'i'" [IDENTIFIER "i"] $ alexScanTokens "i" +testIdentifierWithNumber = TestCase $ assertEqual "scan 'i2'" [IDENTIFIER "i2"] $ alexScanTokens "i2" testKeywordBreak = TestCase $ assertEqual "scan 'break'" [BREAK] $ alexScanTokens "break" testKeywordInt = TestCase $ assertEqual "scan 'int'" [INT] $ alexScanTokens "int" diff --git a/src/Parser/Lexer.x b/src/Parser/Lexer.x index d961036..e8078f4 100644 --- a/src/Parser/Lexer.x +++ b/src/Parser/Lexer.x @@ -65,7 +65,9 @@ tokens :- "volatile" { \_ -> VOLATILE} "while" { \_ -> WHILE} -- end keywords - $JavaLetter$JavaLetterOrDigit* { \s -> Identifier s } + $JavaLetter$JavaLetterOrDigit* { \s -> IDENTIFIER s } + -- Literals + { data Token @@ -119,7 +121,8 @@ data Token | VOID | VOLATILE | WHILE - | Identifier String + | IDENTIFIER String + deriving(Eq,Show) } \ No newline at end of file