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