From c771d7c481b2fc647525b12ca79bacd161af84c3 Mon Sep 17 00:00:00 2001 From: rfscholte Date: Sat, 23 Oct 2021 12:57:59 +0200 Subject: [PATCH] Add UnqualifiedClassInstanceCreationExpression --- src/grammar/parser.y | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/src/grammar/parser.y b/src/grammar/parser.y index ae1b5b0d..c3fec330 100644 --- a/src/grammar/parser.y +++ b/src/grammar/parser.y @@ -60,7 +60,7 @@ import java.util.Stack; %type Expression Literal Annotation ElementValue ElementValueArrayInitializer %type ConditionalExpression ConditionalOrExpression ConditionalAndExpression InclusiveOrExpression ExclusiveOrExpression AndExpression %type EqualityExpression RelationalExpression ShiftExpression AdditiveExpression MultiplicativeExpression -%type UnaryExpression UnaryExpressionNotPlusMinus PreIncrementExpression PreDecrementExpression Primary PrimaryNoNewArray ArrayCreationExpression MethodInvocation MethodReference ClassInstanceCreationExpression +%type UnaryExpression UnaryExpressionNotPlusMinus PreIncrementExpression PreDecrementExpression Primary PrimaryNoNewArray ArrayCreationExpression MethodInvocation MethodReference ClassInstanceCreationExpression UnqualifiedClassInstanceCreationExpression %type PostfixExpression PostIncrementExpression PostDecrementExpression CastExpression Assignment LeftHandSide AssignmentExpression %type Dims Dims_opt %type QualifiedIdentifier TypeDeclSpecifier MethodBody AssignmentOperator ModuleName @@ -1013,24 +1013,31 @@ PrimaryNoNewArray: Literal ; // ClassInstanceCreationExpression: -// new [TypeArguments] {Annotation} Identifier [TypeArgumentsOrDiamond] ( [ArgumentList] ) [ClassBody] -// ExpressionName . new [TypeArguments] {Annotation} Identifier [TypeArgumentsOrDiamond] ( [ArgumentList] ) [ClassBody] -// Primary . new [TypeArguments] {Annotation} Identifier [TypeArgumentsOrDiamond] ( [ArgumentList] ) [ClassBody] -//// TypeArguments_opt confuses parser -ClassInstanceCreationExpression: NEW TypeArguments IDENTIFIER TypeArgumentsOrDiamond_opt PARENOPEN ArgumentList_opt PARENCLOSE CODEBLOCK_opt - { - CreatorDef creator = new CreatorDef(); - creator.setCreatedName( $3 ); - $$ = creator; - } - | NEW IDENTIFIER TypeArgumentsOrDiamond_opt PARENOPEN ArgumentList_opt PARENCLOSE CODEBLOCK_opt - { - CreatorDef creator = new CreatorDef(); - creator.setCreatedName( $2 ); - $$ = creator; - } +// UnqualifiedClassInstanceCreationExpression +// ExpressionName . UnqualifiedClassInstanceCreationExpression +// Primary . UnqualifiedClassInstanceCreationExpression +ClassInstanceCreationExpression: UnqualifiedClassInstanceCreationExpression + | ExpressionName DOT UnqualifiedClassInstanceCreationExpression + | Primary DOT UnqualifiedClassInstanceCreationExpression ; +// UnqualifiedClassInstanceCreationExpression: +// new [TypeArguments] ClassOrInterfaceTypeToInstantiate ( [ArgumentList] ) [ClassBody] +//// TypeArguments_opt confuses parser +UnqualifiedClassInstanceCreationExpression: NEW TypeArguments IDENTIFIER TypeArgumentsOrDiamond_opt PARENOPEN ArgumentList_opt PARENCLOSE CODEBLOCK_opt + { + CreatorDef creator = new CreatorDef(); + creator.setCreatedName( $3 ); + $$ = creator; + } + | NEW IDENTIFIER TypeArgumentsOrDiamond_opt PARENOPEN ArgumentList_opt PARENCLOSE CODEBLOCK_opt + { + CreatorDef creator = new CreatorDef(); + creator.setCreatedName( $2 ); + $$ = creator; + } + ; + CODEBLOCK_opt: | CODEBLOCK ;