parser implement varibale initialization
This commit is contained in:
parent
ebf54bf4cb
commit
90fa658c8f
@ -74,6 +74,12 @@ testExpressionIntLiteral = TestCase $
|
|||||||
testFieldWithInitialization = TestCase $
|
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 $
|
||||||
|
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]
|
||||||
|
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]
|
||||||
|
|
||||||
tests = TestList [
|
tests = TestList [
|
||||||
testSingleEmptyClass,
|
testSingleEmptyClass,
|
||||||
@ -96,5 +102,7 @@ tests = TestList [
|
|||||||
testNestedBlocks,
|
testNestedBlocks,
|
||||||
testBlockWithEmptyStatement,
|
testBlockWithEmptyStatement,
|
||||||
testExpressionIntLiteral,
|
testExpressionIntLiteral,
|
||||||
testFieldWithInitialization
|
testFieldWithInitialization,
|
||||||
|
testLocalBoolWithInitialization,
|
||||||
|
testFieldNullWithInitialization
|
||||||
]
|
]
|
@ -328,9 +328,9 @@ exclusiveorexpression : andexpression { $1 }
|
|||||||
-- | exclusiveorexpression XOR andexpression { }
|
-- | exclusiveorexpression XOR andexpression { }
|
||||||
|
|
||||||
literal : INTLITERAL { IntegerLiteral $1 }
|
literal : INTLITERAL { IntegerLiteral $1 }
|
||||||
-- | BOOLLITERAL { }
|
| BOOLLITERAL { BooleanLiteral $1 }
|
||||||
-- | CHARLITERAL { }
|
| CHARLITERAL { CharacterLiteral $1 }
|
||||||
-- | JNULL { }
|
| JNULL { NullLiteral }
|
||||||
|
|
||||||
castexpression : LBRACE primitivetype RBRACE unaryexpression { }
|
castexpression : LBRACE primitivetype RBRACE unaryexpression { }
|
||||||
| LBRACE expression RBRACE unaryexpressionnotplusminus{ }
|
| LBRACE expression RBRACE unaryexpressionnotplusminus{ }
|
||||||
|
Loading…
Reference in New Issue
Block a user