replace parseBlock with parseStatement
This commit is contained in:
parent
c29aa13d69
commit
64829c2086
@ -54,19 +54,19 @@ testClassWithConstructor = TestCase $
|
|||||||
parse [CLASS,IDENTIFIER "WithConstructor",LBRACKET,IDENTIFIER "WithConstructor",LBRACE,RBRACE,LBRACKET,RBRACKET,RBRACKET]
|
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 $
|
testBlockWithLocalVarDecl = TestCase $
|
||||||
assertEqual "expect block with local var delcaration" (Block [LocalVariableDeclaration $ VariableDeclaration "int" "localvar" Nothing]) $
|
assertEqual "expect block with local var delcaration" [Block [LocalVariableDeclaration $ VariableDeclaration "int" "localvar" Nothing]] $
|
||||||
parseBlock [LBRACKET,INT,IDENTIFIER "localvar",SEMICOLON,RBRACKET]
|
parseStatement [LBRACKET,INT,IDENTIFIER "localvar",SEMICOLON,RBRACKET]
|
||||||
testBlockWithMultipleLocalVarDecls = TestCase $
|
testBlockWithMultipleLocalVarDecls = TestCase $
|
||||||
assertEqual "expect block with multiple local var declarations" (Block [LocalVariableDeclaration $ VariableDeclaration "int" "var1" Nothing, LocalVariableDeclaration $ VariableDeclaration "boolean" "var2" Nothing]) $
|
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]
|
parseStatement [LBRACKET,INT,IDENTIFIER "var1",SEMICOLON,BOOLEAN,IDENTIFIER "var2",SEMICOLON,RBRACKET]
|
||||||
testNestedBlocks = TestCase $
|
testNestedBlocks = TestCase $
|
||||||
assertEqual "expect block with block inside" (Block [Block []]) $
|
assertEqual "expect block with block inside" [Block [Block []]] $
|
||||||
parseBlock [LBRACKET,LBRACKET,RBRACKET,RBRACKET]
|
parseStatement [LBRACKET,LBRACKET,RBRACKET,RBRACKET]
|
||||||
testBlockWithEmptyStatement = TestCase $
|
testBlockWithEmptyStatement = TestCase $
|
||||||
assertEqual "expect empty block" (Block []) $
|
assertEqual "expect empty block" [Block []] $
|
||||||
parseBlock [LBRACKET,SEMICOLON,SEMICOLON,RBRACKET]
|
parseStatement [LBRACKET,SEMICOLON,SEMICOLON,RBRACKET]
|
||||||
|
|
||||||
testExpressionIntLiteral = TestCase $
|
testExpressionIntLiteral = TestCase $
|
||||||
assertEqual "expect IntLiteral" (IntegerLiteral 3) $
|
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]] $
|
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]
|
parse [CLASS,IDENTIFIER "WithInitField",LBRACKET,INT,IDENTIFIER "number",ASSIGN,INTEGERLITERAL 3,SEMICOLON,RBRACKET]
|
||||||
testLocalBoolWithInitialization = TestCase $
|
testLocalBoolWithInitialization = TestCase $
|
||||||
assertEqual "expect block with with initialized local var" (Block [LocalVariableDeclaration $ VariableDeclaration "boolean" "b" $ Just $ BooleanLiteral False]) $
|
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]
|
parseStatement [LBRACKET,BOOLEAN,IDENTIFIER "b",ASSIGN,BOOLLITERAL False,SEMICOLON,RBRACKET]
|
||||||
testFieldNullWithInitialization = TestCase $
|
testFieldNullWithInitialization = TestCase $
|
||||||
assertEqual "expect Class with initialized field" [Class "WithInitField" [] [VariableDeclaration "Object" "bar" $ Just NullLiteral]] $
|
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]
|
parse [CLASS,IDENTIFIER "WithInitField",LBRACKET,IDENTIFIER "Object",IDENTIFIER "bar",ASSIGN,NULLLITERAL,SEMICOLON,RBRACKET]
|
||||||
testReturnVoid = TestCase $
|
testReturnVoid = TestCase $
|
||||||
assertEqual "expect block with return nothing" (Block [Return Nothing]) $
|
assertEqual "expect block with return nothing" [Block [Return Nothing]] $
|
||||||
parseBlock [LBRACKET,RETURN,SEMICOLON,RBRACKET]
|
parseStatement [LBRACKET,RETURN,SEMICOLON,RBRACKET]
|
||||||
|
|
||||||
testExpressionNot = TestCase $
|
testExpressionNot = TestCase $
|
||||||
assertEqual "expect expression not" (UnaryOperation Not (Reference "boar")) $
|
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 Ast
|
||||||
import Parser.Lexer
|
import Parser.Lexer
|
||||||
}
|
}
|
||||||
|
|
||||||
%name parse
|
%name parse
|
||||||
%name parseBlock block
|
%name parseStatement statement
|
||||||
%name parseExpression expression
|
%name parseExpression expression
|
||||||
%tokentype { Token }
|
%tokentype { Token }
|
||||||
%error { parseError }
|
%error { parseError }
|
||||||
|
Loading…
Reference in New Issue
Block a user