diff --git a/Test/TestParser.hs b/Test/TestParser.hs index e97d793..c22968c 100644 --- a/Test/TestParser.hs +++ b/Test/TestParser.hs @@ -173,6 +173,12 @@ testExpressionPrecedence = TestCase $ testExpressionMethodCallNoParams = TestCase $ assertEqual "expect methodcall no params" (StatementExpressionExpression (MethodCall (Reference "this") "foo" [])) $ parseExpression [IDENTIFIER "foo",LBRACE,RBRACE] +testExpressionMethodCallOneParam = TestCase $ + assertEqual "expect methodcall one param" (StatementExpressionExpression (MethodCall (Reference "this") "foo" [Reference "a"])) $ + parseExpression [IDENTIFIER "foo",LBRACE,IDENTIFIER "a",RBRACE] +testExpressionMethodCallTwoParams = TestCase $ + assertEqual "expect methocall two params" (StatementExpressionExpression (MethodCall (Reference "this") "foo" [Reference "a", IntegerLiteral 5])) $ + parseExpression [IDENTIFIER "foo",LBRACE,IDENTIFIER "a",COMMA,INTEGERLITERAL 5,RBRACE] testStatementIfThen = TestCase $ assertEqual "expect empty ifthen" [If (Reference "a") (Block [Block []]) Nothing] $ @@ -243,6 +249,8 @@ tests = TestList [ testExpressionThis, testExpressionPrecedence, testExpressionMethodCallNoParams, + testExpressionMethodCallOneParam, + testExpressionMethodCallTwoParams, testStatementIfThen, testStatementIfThenElse, testStatementWhile, diff --git a/src/Parser/JavaParser.y b/src/Parser/JavaParser.y index 07c11b5..068a821 100644 --- a/src/Parser/JavaParser.y +++ b/src/Parser/JavaParser.y @@ -189,8 +189,8 @@ blockstatement : localvariabledeclarationstatement { $1 } -- expected ty formalparameter : type variabledeclaratorid { ParameterDeclaration $1 $2 } -argumentlist : expression { } - | argumentlist COMMA expression { } +argumentlist : expression { [$1] } + | argumentlist COMMA expression { $1 ++ [$3] } numerictype : integraltype { $1 } @@ -288,7 +288,7 @@ postincrementexpression : postfixexpression INCREMENT { UnaryOperation PostIncre postdecrementexpression : postfixexpression DECREMENT { UnaryOperation PostDecrement $1 } methodinvocation : simplename LBRACE RBRACE { MethodCall (Reference "this") $1 [] } - -- | name LBRACE argumentlist RBRACE { } + | simplename LBRACE argumentlist RBRACE { MethodCall (Reference "this") $1 $3 } -- | primary DOT IDENTIFIER LBRACE RBRACE { } -- | primary DOT IDENTIFIER LBRACE argumentlist RBRACE { }