diff --git a/Test/TestLexer.hs b/Test/TestLexer.hs index 94046da..848cb4d 100644 --- a/Test/TestLexer.hs +++ b/Test/TestLexer.hs @@ -11,11 +11,16 @@ 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" tests = TestList [ TestLabel "TestCommentSomething" testCommentSomething, TestLabel "TestEmptyComment" testEmptyComment, TestLabel "TestLineComment" testLineComment, - TestLabel "TestLineCommentEnds" testLineCommentEnds + TestLabel "TestLineCommentEnds" testLineCommentEnds, + TestLabel "TestIdentifier" testIdentifier, + TestLabel "TestShortIdentifier" testShortIdentifier, + TestLabel "TestIdentifierWithNumber" testIdentifierWithNumber ] \ No newline at end of file diff --git a/src/Parser/Lexer.x b/src/Parser/Lexer.x index d5a472f..d500674 100644 --- a/src/Parser/Lexer.x +++ b/src/Parser/Lexer.x @@ -7,17 +7,19 @@ $digit = 0-9 $alpha = [a-zA-Z] $alphanum = [a-zA-Z0-9] +$JavaLetter = [A-Za-z\_\$] +$JavaLetterOrDigit = [A-Za-z\_\$0-9] tokens :- $white ; "/*"(.|\n)*"*/" ; "//".* ; - + $JavaLetter$JavaLetterOrDigit* { \s -> Identifier s } { data Token - = Different + = Identifier String deriving(Eq,Show) } \ No newline at end of file