diff --git a/Test/TestParser.hs b/Test/TestParser.hs index 4a18581..1caec8f 100644 --- a/Test/TestParser.hs +++ b/Test/TestParser.hs @@ -80,6 +80,9 @@ testLocalBoolWithInitialization = TestCase $ 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] +testReturnVoid = TestCase $ + assertEqual "expect block with return nothing" (Block [Return Nothing]) $ + parseBlock [LBRACKET,RETURN,SEMICOLON,RBRACKET] tests = TestList [ testSingleEmptyClass, @@ -104,5 +107,6 @@ tests = TestList [ testExpressionIntLiteral, testFieldWithInitialization, testLocalBoolWithInitialization, - testFieldNullWithInitialization + testFieldNullWithInitialization, + testReturnVoid ] \ No newline at end of file diff --git a/src/Parser/JavaParser.y b/src/Parser/JavaParser.y index b0a8173..c92f6f1 100644 --- a/src/Parser/JavaParser.y +++ b/src/Parser/JavaParser.y @@ -217,7 +217,7 @@ localvariabledeclaration : type variabledeclarators { map LocalVariableDeclarati statementwithouttrailingsubstatement : block { [$1] } | emptystatement { [] } -- | expressionstatement { } - -- | returnstatement { } + | returnstatement { [$1] } ifthenstatement : IF LBRACE expression RBRACE statement { } @@ -232,8 +232,8 @@ emptystatement : SEMICOLON { Block [] } expressionstatement : statementexpression SEMICOLON { } -returnstatement : RETURN SEMICOLON { } - | RETURN expression SEMICOLON { } +returnstatement : RETURN SEMICOLON { Return Nothing } + | RETURN expression SEMICOLON { Return $ Just $2 } statementnoshortif : statementwithouttrailingsubstatement { } | ifthenelsestatementnoshortif { }