parser implement nested blocks
This commit is contained in:
parent
98321fa162
commit
b82e205bcd
@ -61,6 +61,9 @@ testBlockWithLocalVarDecl = TestCase $
|
|||||||
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]
|
parseBlock [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]
|
||||||
|
|
||||||
|
|
||||||
tests = TestList [
|
tests = TestList [
|
||||||
@ -80,5 +83,6 @@ tests = TestList [
|
|||||||
testClassWithConstructor,
|
testClassWithConstructor,
|
||||||
testEmptyBlock,
|
testEmptyBlock,
|
||||||
testBlockWithLocalVarDecl,
|
testBlockWithLocalVarDecl,
|
||||||
testBlockWithMultipleLocalVarDecls
|
testBlockWithMultipleLocalVarDecls,
|
||||||
|
testNestedBlocks
|
||||||
]
|
]
|
@ -185,7 +185,7 @@ variabledeclarator : variabledeclaratorid { Declarator $1 Nothing }
|
|||||||
-- | variabledeclaratorid ASSIGN variableinitializer { Declarator $1 Nothing } -- TODO
|
-- | variabledeclaratorid ASSIGN variableinitializer { Declarator $1 Nothing } -- TODO
|
||||||
|
|
||||||
blockstatement : localvariabledeclarationstatement { $1 }
|
blockstatement : localvariabledeclarationstatement { $1 }
|
||||||
-- | statement { }
|
| statement { [$1] }
|
||||||
|
|
||||||
formalparameter : type variabledeclaratorid { ParameterDeclaration $1 $2 }
|
formalparameter : type variabledeclaratorid { ParameterDeclaration $1 $2 }
|
||||||
|
|
||||||
@ -200,10 +200,10 @@ variableinitializer : expression { }
|
|||||||
|
|
||||||
localvariabledeclarationstatement : localvariabledeclaration SEMICOLON { $1 }
|
localvariabledeclarationstatement : localvariabledeclaration SEMICOLON { $1 }
|
||||||
|
|
||||||
statement : statementwithouttrailingsubstatement{ }
|
statement : statementwithouttrailingsubstatement{ $1 }
|
||||||
| ifthenstatement { }
|
-- | ifthenstatement { }
|
||||||
| ifthenelsestatement { }
|
-- | ifthenelsestatement { }
|
||||||
| whilestatement { }
|
-- | whilestatement { }
|
||||||
|
|
||||||
|
|
||||||
expression : assignmentexpression { }
|
expression : assignmentexpression { }
|
||||||
@ -213,10 +213,10 @@ integraltype : INT { "int" }
|
|||||||
|
|
||||||
localvariabledeclaration : type variabledeclarators { map LocalVariableDeclaration $ map (convertDeclarator $1) $2 }
|
localvariabledeclaration : type variabledeclarators { map LocalVariableDeclaration $ map (convertDeclarator $1) $2 }
|
||||||
|
|
||||||
statementwithouttrailingsubstatement : block { }
|
statementwithouttrailingsubstatement : block { $1 }
|
||||||
| emptystatement { }
|
-- | emptystatement { }
|
||||||
| expressionstatement { }
|
-- | expressionstatement { }
|
||||||
| returnstatement { }
|
-- | returnstatement { }
|
||||||
|
|
||||||
ifthenstatement : IF LBRACE expression RBRACE statement { }
|
ifthenstatement : IF LBRACE expression RBRACE statement { }
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user