diff --git a/Test/TestParser.hs b/Test/TestParser.hs index c000d6b..53a08a6 100644 --- a/Test/TestParser.hs +++ b/Test/TestParser.hs @@ -64,7 +64,9 @@ testBlockWithMultipleLocalVarDecls = TestCase $ testNestedBlocks = TestCase $ assertEqual "expect block with block inside" (Block [Block []]) $ parseBlock [LBRACKET,LBRACKET,RBRACKET,RBRACKET] - +testBlockWithEmptyStatement = TestCase $ + assertEqual "expect empty block" (Block []) $ + parseBlock [LBRACKET,SEMICOLON,SEMICOLON,RBRACKET] tests = TestList [ testSingleEmptyClass, @@ -84,5 +86,6 @@ tests = TestList [ testEmptyBlock, testBlockWithLocalVarDecl, testBlockWithMultipleLocalVarDecls, - testNestedBlocks + testNestedBlocks, + testBlockWithEmptyStatement ] \ No newline at end of file diff --git a/src/Parser/JavaParser.y b/src/Parser/JavaParser.y index fe309da..d2cf382 100644 --- a/src/Parser/JavaParser.y +++ b/src/Parser/JavaParser.y @@ -136,7 +136,7 @@ fielddeclaration : type variabledeclarators SEMICOLON { FieldDecls $ map (conve methoddeclaration : methodheader methodbody { case $1 of (returnType, (name, parameters)) -> MethodDecl (MethodDeclaration returnType name parameters $2) } block : LBRACKET RBRACKET { Block [] } - | LBRACKET blockstatements RBRACKET { $2 } + | LBRACKET blockstatements RBRACKET { Block $2 } constructordeclarator : simplename LBRACE RBRACE { ($1, []) } | simplename LBRACE formalparameterlist RBRACE { ($1, $3) } @@ -160,8 +160,8 @@ variabledeclarators : variabledeclarator { [$1] } methodbody : block { $1 } | SEMICOLON { Block [] } -blockstatements : blockstatement { Block $1 } - | blockstatements blockstatement { case $1 of Block stmts -> Block (stmts ++ $2)} +blockstatements : blockstatement { $1 } + | blockstatements blockstatement { $1 ++ $2} formalparameterlist : formalparameter { [$1] } | formalparameterlist COMMA formalparameter { $1 ++ [$3] } @@ -185,7 +185,7 @@ variabledeclarator : variabledeclaratorid { Declarator $1 Nothing } -- | variabledeclaratorid ASSIGN variableinitializer { Declarator $1 Nothing } -- TODO blockstatement : localvariabledeclarationstatement { $1 } - | statement { [$1] } + | statement { $1 } formalparameter : type variabledeclaratorid { ParameterDeclaration $1 $2 } @@ -213,8 +213,8 @@ integraltype : INT { "int" } localvariabledeclaration : type variabledeclarators { map LocalVariableDeclaration $ map (convertDeclarator $1) $2 } -statementwithouttrailingsubstatement : block { $1 } - -- | emptystatement { } +statementwithouttrailingsubstatement : block { [$1] } + | emptystatement { [] } -- | expressionstatement { } -- | returnstatement { } @@ -227,7 +227,7 @@ whilestatement : WHILE LBRACE expression RBRACE statement { } assignmentexpression : conditionalexpression { } | assignment{ } -emptystatement : SEMICOLON { } +emptystatement : SEMICOLON { Block [] } expressionstatement : statementexpression SEMICOLON { } @@ -338,8 +338,8 @@ andexpression : equalityexpression { } | andexpression AND equalityexpression { } equalityexpression : relationalexpression { } - | equalityexpression EQUAL relationalexpression { } - | equalityexpression NOTEQUAL relationalexpression { } + -- | equalityexpression EQUAL relationalexpression { } + -- | equalityexpression NOTEQUAL relationalexpression { } relationalexpression : shiftexpression { } | relationalexpression LESS shiftexpression { }