Add initial typechecker for AST #2
@ -54,19 +54,19 @@ testClassWithConstructor = TestCase $
|
||||
parse [CLASS,IDENTIFIER "WithConstructor",LBRACKET,IDENTIFIER "WithConstructor",LBRACE,RBRACE,LBRACKET,RBRACKET,RBRACKET]
|
||||
|
||||
|
||||
testEmptyBlock = TestCase $ assertEqual "expect empty block" (Block []) $ parseBlock [LBRACKET,RBRACKET]
|
||||
testEmptyBlock = TestCase $ assertEqual "expect empty block" [Block []] $ parseStatement [LBRACKET,RBRACKET]
|
||||
testBlockWithLocalVarDecl = TestCase $
|
||||
assertEqual "expect block with local var delcaration" (Block [LocalVariableDeclaration $ VariableDeclaration "int" "localvar" Nothing]) $
|
||||
parseBlock [LBRACKET,INT,IDENTIFIER "localvar",SEMICOLON,RBRACKET]
|
||||
assertEqual "expect block with local var delcaration" [Block [LocalVariableDeclaration $ VariableDeclaration "int" "localvar" Nothing]] $
|
||||
parseStatement [LBRACKET,INT,IDENTIFIER "localvar",SEMICOLON,RBRACKET]
|
||||
testBlockWithMultipleLocalVarDecls = TestCase $
|
||||
assertEqual "expect block with multiple local var declarations" (Block [LocalVariableDeclaration $ VariableDeclaration "int" "var1" Nothing, LocalVariableDeclaration $ VariableDeclaration "boolean" "var2" Nothing]) $
|
||||
parseBlock [LBRACKET,INT,IDENTIFIER "var1",SEMICOLON,BOOLEAN,IDENTIFIER "var2",SEMICOLON,RBRACKET]
|
||||
assertEqual "expect block with multiple local var declarations" [Block [LocalVariableDeclaration $ VariableDeclaration "int" "var1" Nothing, LocalVariableDeclaration $ VariableDeclaration "boolean" "var2" Nothing]] $
|
||||
parseStatement [LBRACKET,INT,IDENTIFIER "var1",SEMICOLON,BOOLEAN,IDENTIFIER "var2",SEMICOLON,RBRACKET]
|
||||
testNestedBlocks = TestCase $
|
||||
assertEqual "expect block with block inside" (Block [Block []]) $
|
||||
parseBlock [LBRACKET,LBRACKET,RBRACKET,RBRACKET]
|
||||
assertEqual "expect block with block inside" [Block [Block []]] $
|
||||
parseStatement [LBRACKET,LBRACKET,RBRACKET,RBRACKET]
|
||||
testBlockWithEmptyStatement = TestCase $
|
||||
assertEqual "expect empty block" (Block []) $
|
||||
parseBlock [LBRACKET,SEMICOLON,SEMICOLON,RBRACKET]
|
||||
assertEqual "expect empty block" [Block []] $
|
||||
parseStatement [LBRACKET,SEMICOLON,SEMICOLON,RBRACKET]
|
||||
|
||||
testExpressionIntLiteral = TestCase $
|
||||
assertEqual "expect IntLiteral" (IntegerLiteral 3) $
|
||||
@ -75,14 +75,14 @@ testFieldWithInitialization = TestCase $
|
||||
assertEqual "expect Class with initialized field" [Class "WithInitField" [] [VariableDeclaration "int" "number" $ Just $ IntegerLiteral 3]] $
|
||||
parse [CLASS,IDENTIFIER "WithInitField",LBRACKET,INT,IDENTIFIER "number",ASSIGN,INTEGERLITERAL 3,SEMICOLON,RBRACKET]
|
||||
testLocalBoolWithInitialization = TestCase $
|
||||
assertEqual "expect block with with initialized local var" (Block [LocalVariableDeclaration $ VariableDeclaration "boolean" "b" $ Just $ BooleanLiteral False]) $
|
||||
parseBlock [LBRACKET,BOOLEAN,IDENTIFIER "b",ASSIGN,BOOLLITERAL False,SEMICOLON,RBRACKET]
|
||||
assertEqual "expect block with with initialized local var" [Block [LocalVariableDeclaration $ VariableDeclaration "boolean" "b" $ Just $ BooleanLiteral False]] $
|
||||
parseStatement [LBRACKET,BOOLEAN,IDENTIFIER "b",ASSIGN,BOOLLITERAL False,SEMICOLON,RBRACKET]
|
||||
testFieldNullWithInitialization = TestCase $
|
||||
assertEqual "expect Class with initialized field" [Class "WithInitField" [] [VariableDeclaration "Object" "bar" $ Just NullLiteral]] $
|
||||
parse [CLASS,IDENTIFIER "WithInitField",LBRACKET,IDENTIFIER "Object",IDENTIFIER "bar",ASSIGN,NULLLITERAL,SEMICOLON,RBRACKET]
|
||||
testReturnVoid = TestCase $
|
||||
assertEqual "expect block with return nothing" (Block [Return Nothing]) $
|
||||
parseBlock [LBRACKET,RETURN,SEMICOLON,RBRACKET]
|
||||
assertEqual "expect block with return nothing" [Block [Return Nothing]] $
|
||||
parseStatement [LBRACKET,RETURN,SEMICOLON,RBRACKET]
|
||||
|
||||
testExpressionNot = TestCase $
|
||||
assertEqual "expect expression not" (UnaryOperation Not (Reference "boar")) $
|
||||
|
@ -1,11 +1,11 @@
|
||||
{
|
||||
module Parser.JavaParser (parse, parseBlock, parseExpression) where
|
||||
module Parser.JavaParser (parse, parseStatement, parseExpression) where
|
||||
import Ast
|
||||
import Parser.Lexer
|
||||
}
|
||||
|
||||
%name parse
|
||||
%name parseBlock block
|
||||
%name parseStatement statement
|
||||
%name parseExpression expression
|
||||
%tokentype { Token }
|
||||
%error { parseError }
|
||||
|
Loading…
Reference in New Issue
Block a user