From e4693729dcae31264a1ada75806b577817f085fe Mon Sep 17 00:00:00 2001 From: Marvin Schlegel Date: Fri, 14 Jun 2024 15:08:50 +0200 Subject: [PATCH] fix assignment with this --- Test/TestParser.hs | 7 ++++++- src/Parser/JavaParser.y | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Test/TestParser.hs b/Test/TestParser.hs index 7c180e9..3d05001 100644 --- a/Test/TestParser.hs +++ b/Test/TestParser.hs @@ -206,7 +206,10 @@ testExpressionConstructorCall = TestCase $ testExpresssionExternalMethodCall = TestCase $ assertEqual "expect method call on sub" (StatementExpressionExpression (MethodCall (Reference "Obj") "foo" [])) $ - parseExpression [IDENTIFIER "Obj",IDENTIFIER "foo",LBRACE,RBRACE] + parseExpression [IDENTIFIER "Obj",DOT,IDENTIFIER "foo",LBRACE,RBRACE] +testExpressionAssignWithThis = TestCase $ + assertEqual "expect assignment on Field" (StatementExpressionExpression (Assignment (BinaryOperation NameResolution (Reference "this") (Reference "x")) (Reference "y"))) $ + parseExpression [THIS,DOT,IDENTIFIER "x",ASSIGN,IDENTIFIER "y"] testStatementIfThen = TestCase $ assertEqual "expect empty ifthen" [If (Reference "a") (Block [Block []]) Nothing] $ @@ -296,6 +299,8 @@ tests = TestList [ testExpressionSimpleFieldAccess, testExpressionFieldSubAccess, testExpressionConstructorCall, + testExpresssionExternalMethodCall, + testExpressionAssignWithThis, testStatementIfThen, testStatementIfThenElse, testStatementWhile, diff --git a/src/Parser/JavaParser.y b/src/Parser/JavaParser.y index c3fc42d..d7dc862 100644 --- a/src/Parser/JavaParser.y +++ b/src/Parser/JavaParser.y @@ -265,6 +265,7 @@ conditionalorexpression : conditionalandexpression { $1 } -- | conditionalorexpression LOGICALOR conditionalandexpression{ } lefthandside : name { $1 } + | primary DOT IDENTIFIER { BinaryOperation NameResolution $1 (Reference $3) } assignmentoperator : ASSIGN { Nothing } | TIMESEQUAL { Just Multiplication }