Skip to content

Commit

Permalink
Allow record to be used as an identifier like the compiler does.
Browse files Browse the repository at this point in the history
  • Loading branch information
gchallen committed Jun 30, 2021
1 parent a3cc94f commit 484ca4e
Show file tree
Hide file tree
Showing 12 changed files with 147 additions and 109 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=2021.6.9
version=2021.6.10
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ parser grammar JavaParser;

options { tokenVocab=JavaLexer; }

identifier
: IDENTIFIER | RECORD;

compilationUnit
: packageDeclaration? importDeclaration* typeDeclaration* EOF
;
Expand Down Expand Up @@ -74,13 +77,13 @@ variableModifier
;

recordDeclaration
: RECORD IDENTIFIER formalParameters
: RECORD identifier formalParameters
(IMPLEMENTS typeList)?
classBody
;

classDeclaration
: CLASS IDENTIFIER typeParameters?
: CLASS identifier typeParameters?
(EXTENDS typeType)?
(IMPLEMENTS typeList)?
classBody
Expand All @@ -91,31 +94,31 @@ typeParameters
;

typeParameter
: annotation* IDENTIFIER (EXTENDS typeBound)?
: annotation* identifier (EXTENDS typeBound)?
;

typeBound
: typeType ('&' typeType)*
;

enumDeclaration
: ENUM IDENTIFIER (IMPLEMENTS typeList)? '{' enumConstants? ','? enumBodyDeclarations? '}'
: ENUM identifier (IMPLEMENTS typeList)? '{' enumConstants? ','? enumBodyDeclarations? '}'
;

enumConstants
: enumConstant (',' enumConstant)*
;

enumConstant
: annotation* IDENTIFIER arguments? classBody?
: annotation* identifier arguments? classBody?
;

enumBodyDeclarations
: ';' classBodyDeclaration*
;

interfaceDeclaration
: INTERFACE IDENTIFIER typeParameters? (EXTENDS typeList)? interfaceBody
: INTERFACE identifier typeParameters? (EXTENDS typeList)? interfaceBody
;

classBody
Expand Down Expand Up @@ -151,7 +154,7 @@ memberDeclaration
for invalid return type after parsing.
*/
methodDeclaration
: typeTypeOrVoid IDENTIFIER formalParameters ('[' ']')*
: typeTypeOrVoid identifier formalParameters ('[' ']')*
(THROWS qualifiedNameList)?
methodBody
;
Expand All @@ -175,11 +178,11 @@ genericConstructorDeclaration
;

constructorDeclaration
: IDENTIFIER formalParameters (THROWS qualifiedNameList)? constructorBody=block
: identifier formalParameters (THROWS qualifiedNameList)? constructorBody=block
;

recordConstructorDeclaration
: IDENTIFIER (THROWS qualifiedNameList)? constructorBody=block
: identifier (THROWS qualifiedNameList)? constructorBody=block
;

fieldDeclaration
Expand All @@ -206,14 +209,14 @@ constDeclaration
;

constantDeclarator
: IDENTIFIER ('[' ']')* '=' variableInitializer
: identifier ('[' ']')* '=' variableInitializer
;

// see matching of [] comment in methodDeclaratorRest
// methodBody from Java8
interfaceMethodDeclaration
: interfaceMethodModifier* (typeTypeOrVoid | typeParameters annotation* typeTypeOrVoid)
IDENTIFIER formalParameters ('[' ']')* (THROWS qualifiedNameList)? methodBody
identifier formalParameters ('[' ']')* (THROWS qualifiedNameList)? methodBody
;

// Java8
Expand All @@ -239,7 +242,7 @@ variableDeclarator
;

variableDeclaratorId
: IDENTIFIER ('[' ']')*
: identifier ('[' ']')*
;

variableInitializer
Expand All @@ -252,7 +255,7 @@ arrayInitializer
;

classOrInterfaceType
: IDENTIFIER typeArguments? ('.' IDENTIFIER typeArguments?)*
: identifier typeArguments? ('.' identifier typeArguments?)*
;

typeArgument
Expand Down Expand Up @@ -282,7 +285,7 @@ lastFormalParameter
;

qualifiedName
: IDENTIFIER ('.' IDENTIFIER)*
: identifier ('.' identifier)*
;

literal
Expand Down Expand Up @@ -318,7 +321,7 @@ elementValuePairs
;

elementValuePair
: IDENTIFIER '=' elementValue
: identifier '=' elementValue
;

elementValue
Expand All @@ -332,7 +335,7 @@ elementValueArrayInitializer
;

annotationTypeDeclaration
: '@' INTERFACE IDENTIFIER annotationTypeBody
: '@' INTERFACE identifier annotationTypeBody
;

annotationTypeBody
Expand All @@ -358,7 +361,7 @@ annotationMethodOrConstantRest
;

annotationMethodRest
: IDENTIFIER '(' ')' defaultValue?
: identifier '(' ')' defaultValue?
;

annotationConstantRest
Expand Down Expand Up @@ -406,15 +409,15 @@ statement
| RETURN expression? ';'
| YIELD expression ';'
| THROW expression ';'
| BREAK IDENTIFIER? ';'
| CONTINUE IDENTIFIER? ';'
| BREAK identifier? ';'
| CONTINUE identifier? ';'
| SEMI
| statementExpression=expression ';'
| identifierLabel=IDENTIFIER ':' statement
| identifierLabel=identifier ':' statement
;

catchClause
: CATCH '(' variableModifier* catchType IDENTIFIER ')' block
: CATCH '(' variableModifier* catchType identifier ')' block
;

catchType
Expand Down Expand Up @@ -445,7 +448,7 @@ switchBlockStatementGroup
;

switchLabel
: CASE (constantExpression=expression | enumConstantName=IDENTIFIER) ':'
: CASE (constantExpression=expression | enumConstantName=identifier) ':'
| DEFAULT ':'
;

Expand All @@ -454,7 +457,7 @@ switchExpressionBlockStatementGroup
;

switchExpressionLabel
: CASE (constantExpression=expression | enumConstantName=IDENTIFIER) '->'
: CASE (constantExpression=expression | enumConstantName=identifier) '->'
| DEFAULT '->'
;

Expand Down Expand Up @@ -483,15 +486,15 @@ expressionList
;

methodCall
: IDENTIFIER '(' expressionList? ')'
: identifier '(' expressionList? ')'
| THIS '(' expressionList? ')'
| SUPER '(' expressionList? ')'
;

expression
: primary
| expression bop='.'
( IDENTIFIER
( identifier
| methodCall
| THIS
| NEW nonWildcardTypeArguments? innerCreator
Expand All @@ -509,7 +512,7 @@ expression
| expression bop=('+'|'-') expression
| expression ('<' '<' | '>' '>' '>' | '>' '>') expression
| expression bop=('<=' | '>=' | '>' | '<') expression
| expression bop=INSTANCEOF typeType IDENTIFIER?
| expression bop=INSTANCEOF typeType identifier?
| expression bop=('==' | '!=') expression
| expression bop='&' expression
| expression bop='^' expression
Expand All @@ -523,8 +526,8 @@ expression
| lambdaExpression // Java8

// Java 8 methodReference
| expression '::' typeArguments? IDENTIFIER
| typeType '::' (typeArguments? IDENTIFIER | NEW)
| expression '::' typeArguments? identifier
| typeType '::' (typeArguments? identifier | NEW)
| classType '::' typeArguments? NEW
// Java 14 switch
| SWITCH parExpression '{' switchExpressionBlockStatementGroup* switchLabel* '}'
Expand All @@ -537,9 +540,9 @@ lambdaExpression

// Java8
lambdaParameters
: IDENTIFIER
: identifier
| '(' formalParameterList? ')'
| '(' IDENTIFIER (',' IDENTIFIER)* ')'
| '(' identifier (',' identifier)* ')'
;

// Java8
Expand All @@ -553,13 +556,13 @@ primary
| THIS
| SUPER
| literal
| IDENTIFIER
| identifier
| typeTypeOrVoid '.' CLASS
| nonWildcardTypeArguments (explicitGenericInvocationSuffix | THIS arguments)
;

classType
: (classOrInterfaceType '.')? annotation* IDENTIFIER typeArguments?
: (classOrInterfaceType '.')? annotation* identifier typeArguments?
;

creator
Expand All @@ -568,12 +571,12 @@ creator
;

createdName
: IDENTIFIER typeArgumentsOrDiamond? ('.' IDENTIFIER typeArgumentsOrDiamond?)*
: identifier typeArgumentsOrDiamond? ('.' identifier typeArgumentsOrDiamond?)*
| primitiveType
;

innerCreator
: IDENTIFIER nonWildcardTypeArgumentsOrDiamond? classCreatorRest
: identifier nonWildcardTypeArgumentsOrDiamond? classCreatorRest
;

arrayCreatorRest
Expand Down Expand Up @@ -627,12 +630,12 @@ typeArguments

superSuffix
: arguments
| '.' IDENTIFIER arguments?
| '.' identifier arguments?
;

explicitGenericInvocationSuffix
: SUPER superSuffix
| IDENTIFIER arguments
| identifier arguments
;

arguments
Expand Down
Loading

0 comments on commit 484ca4e

Please sign in to comment.