From 4b6d0d9ea215d632a2ac8da5728dbe0d71b48c4a Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Mon, 22 Apr 2013 17:31:02 -0500 Subject: [PATCH] Support diamond operator, improved support for explicit generic invocations --- tool/test/org/antlr/v4/test/Java-LR.g4 | 27 +++++++++++++++----- tool/test/org/antlr/v4/test/Java.g4 | 35 +++++++++++++++++++------- 2 files changed, 47 insertions(+), 15 deletions(-) diff --git a/tool/test/org/antlr/v4/test/Java-LR.g4 b/tool/test/org/antlr/v4/test/Java-LR.g4 index 68bfb9f22..25e101e9d 100644 --- a/tool/test/org/antlr/v4/test/Java-LR.g4 +++ b/tool/test/org/antlr/v4/test/Java-LR.g4 @@ -732,9 +732,8 @@ expression : primary | expression '.' Identifier | expression '.' 'this' - | expression '.' 'super' '(' expressionList? ')' - | expression '.' 'new' Identifier '(' expressionList? ')' - | expression '.' 'super' '.' Identifier arguments? + | expression '.' 'new' nonWildcardTypeArguments? innerCreator + | expression '.' 'super' superSuffix | expression '.' explicitGenericInvocation | 'new' creator | expression '[' expression ']' @@ -780,6 +779,7 @@ primary | Identifier | type '.' 'class' | 'void' '.' 'class' + | nonWildcardTypeArguments (explicitGenericInvocationSuffix | 'this' arguments) ; creator @@ -788,12 +788,12 @@ creator ; createdName - : classOrInterfaceType + : Identifier typeArgumentsOrDiamond? ('.' Identifier typeArgumentsOrDiamond?)* | primitiveType ; innerCreator - : nonWildcardTypeArguments? Identifier classCreatorRest + : Identifier nonWildcardTypeArgumentsOrDiamond? classCreatorRest ; arrayCreatorRest @@ -808,18 +808,33 @@ classCreatorRest ; explicitGenericInvocation - : nonWildcardTypeArguments Identifier arguments + : nonWildcardTypeArguments explicitGenericInvocationSuffix ; nonWildcardTypeArguments : '<' typeList '>' ; +typeArgumentsOrDiamond + : '<' '>' + | typeArguments + ; + +nonWildcardTypeArgumentsOrDiamond + : '<' '>' + | nonWildcardTypeArguments + ; + superSuffix : arguments | '.' Identifier arguments? ; +explicitGenericInvocationSuffix + : 'super' superSuffix + | Identifier arguments + ; + arguments : '(' expressionList? ')' ; diff --git a/tool/test/org/antlr/v4/test/Java.g4 b/tool/test/org/antlr/v4/test/Java.g4 index 17add4cda..27b94f3e1 100644 --- a/tool/test/org/antlr/v4/test/Java.g4 +++ b/tool/test/org/antlr/v4/test/Java.g4 @@ -854,10 +854,11 @@ castExpression primary : parExpression - | 'this' ('.' Identifier)* identifierSuffix? + | 'this' arguments? | 'super' superSuffix | literal | 'new' creator + | nonWildcardTypeArguments (explicitGenericInvocationSuffix | 'this' arguments) | Identifier ('.' Identifier)* identifierSuffix? | primitiveType ('[' ']')* '.' 'class' | 'void' '.' 'class' @@ -865,13 +866,13 @@ primary identifierSuffix : ('[' ']')+ '.' 'class' - | ('[' expression ']')+ // can also be matched by selector, but do here + | '[' expression ']' | arguments | '.' 'class' | '.' explicitGenericInvocation | '.' 'this' | '.' 'super' arguments - | '.' 'new' innerCreator + | '.' 'new' nonWildcardTypeArguments? innerCreator ; creator @@ -880,12 +881,12 @@ creator ; createdName - : classOrInterfaceType - | primitiveType + : Identifier typeArgumentsOrDiamond? ('.' Identifier typeArgumentsOrDiamond?)* + | primitiveType ; innerCreator - : nonWildcardTypeArguments? Identifier classCreatorRest + : Identifier nonWildcardTypeArgumentsOrDiamond? classCreatorRest ; arrayCreatorRest @@ -900,18 +901,29 @@ classCreatorRest ; explicitGenericInvocation - : nonWildcardTypeArguments Identifier arguments + : nonWildcardTypeArguments explicitGenericInvocationSuffix ; nonWildcardTypeArguments : '<' typeList '>' ; - + +typeArgumentsOrDiamond + : '<' '>' + | typeArguments + ; + +nonWildcardTypeArgumentsOrDiamond + : '<' '>' + | nonWildcardTypeArguments + ; + selector : '.' Identifier arguments? + | '.' explicitGenericInvocation | '.' 'this' | '.' 'super' superSuffix - | '.' 'new' innerCreator + | '.' 'new' nonWildcardTypeArguments? innerCreator | '[' expression ']' ; @@ -920,6 +932,11 @@ superSuffix | '.' Identifier arguments? ; +explicitGenericInvocationSuffix + : 'super' superSuffix + | Identifier arguments + ; + arguments : '(' expressionList? ')' ;