diff --git a/Test/TestParser.hs b/Test/TestParser.hs index 090fac1..521a615 100644 --- a/Test/TestParser.hs +++ b/Test/TestParser.hs @@ -191,6 +191,15 @@ testExpressionThisMethodCall = TestCase $ testExpressionThisMethodCallParam = TestCase $ assertEqual "expect this methocall" (StatementExpressionExpression (MethodCall (Reference "this") "foo" [Reference "x"])) $ parseExpression [THIS,DOT,IDENTIFIER "foo",LBRACE,IDENTIFIER "x",RBRACE] +testExpressionFieldAccess = TestCase $ + assertEqual "expect NameResolution" (BinaryOperation NameResolution (Reference "this") (Reference "b")) $ + parseExpression [THIS,DOT,IDENTIFIER "b"] +testExpressionSimpleFieldAccess = TestCase $ + assertEqual "expect Reference" (Reference "a") $ + parseExpression [IDENTIFIER "a"] +testExpressionFieldSubAccess = TestCase $ + assertEqual "expect NameResolution without this" (BinaryOperation NameResolution (Reference "a") (Reference "b")) $ + parseExpression [IDENTIFIER "a",DOT,IDENTIFIER "b"] testStatementIfThen = TestCase $ assertEqual "expect empty ifthen" [If (Reference "a") (Block [Block []]) Nothing] $ @@ -267,6 +276,9 @@ tests = TestList [ testExpressionMethodCallTwoParams, testExpressionThisMethodCall, testExpressionThisMethodCallParam, + testExpressionFieldAccess, + testExpressionSimpleFieldAccess, + testExpressionFieldSubAccess, testStatementIfThen, testStatementIfThenElse, testStatementWhile, diff --git a/src/Parser/JavaParser.y b/src/Parser/JavaParser.y index 21d7be1..fd694b6 100644 --- a/src/Parser/JavaParser.y +++ b/src/Parser/JavaParser.y @@ -83,11 +83,11 @@ typedeclarations : typedeclaration { [$1] } | typedeclarations typedeclaration { $1 ++ [$2] } name : simplename { Reference $1 } - -- | qualifiedname { } + | qualifiedname { $1 } typedeclaration : classdeclaration { $1 } -qualifiedname : name DOT IDENTIFIER { } +qualifiedname : name DOT IDENTIFIER { BinaryOperation NameResolution $1 (Reference $3) } simplename : IDENTIFIER { $1 } @@ -297,7 +297,7 @@ classinstancecreationexpression : NEW classtype LBRACE RBRACE { } conditionalandexpression : inclusiveorexpression { $1 } -fieldaccess : primary DOT IDENTIFIER { } +fieldaccess : primary DOT IDENTIFIER { BinaryOperation NameResolution $1 (Reference $3) } unaryexpression : unaryexpressionnotplusminus { $1 } | predecrementexpression { StatementExpressionExpression $1 } @@ -319,7 +319,7 @@ primarynonewarray : literal { $1 } | THIS { Reference "this" } | LBRACE expression RBRACE { $2 } -- | classinstancecreationexpression { } - -- | fieldaccess { } + | fieldaccess { $1 } | methodinvocation { StatementExpressionExpression $1 } unaryexpressionnotplusminus : postfixexpression { $1 }