Add keywords as explicit lexer rules; enum and assert are always keywords (could extend JavaLexer and override emit to change this behavior)
This commit is contained in:
parent
62cbab4f86
commit
d9e1289d13
|
@ -170,11 +170,6 @@
|
|||
*/
|
||||
grammar Java;
|
||||
|
||||
@lexer::members {
|
||||
protected boolean enumIsKeyword = true;
|
||||
protected boolean assertIsKeyword = true;
|
||||
}
|
||||
|
||||
// starting point for parsing a java file
|
||||
/* The annotations are separated out to make parsing faster, but must be associated with
|
||||
a packageDeclaration or a typeDeclaration (and not an empty one). */
|
||||
|
@ -837,6 +832,59 @@ arguments
|
|||
|
||||
// LEXER
|
||||
|
||||
// §3.9 Keywords
|
||||
|
||||
ABSTRACT : 'abstract';
|
||||
ASSERT : 'assert';
|
||||
BOOLEAN : 'boolean';
|
||||
BREAK : 'break';
|
||||
BYTE : 'byte';
|
||||
CASE : 'case';
|
||||
CATCH : 'catch';
|
||||
CHAR : 'char';
|
||||
CLASS : 'class';
|
||||
CONST : 'const';
|
||||
CONTINUE : 'continue';
|
||||
DEFAULT : 'default';
|
||||
DO : 'do';
|
||||
DOUBLE : 'double';
|
||||
ELSE : 'else';
|
||||
ENUM : 'enum';
|
||||
EXTENDS : 'extends';
|
||||
FINAL : 'final';
|
||||
FINALLY : 'finally';
|
||||
FLOAT : 'float';
|
||||
FOR : 'for';
|
||||
IF : 'if';
|
||||
GOTO : 'goto';
|
||||
IMPLEMENTS : 'implements';
|
||||
IMPORT : 'import';
|
||||
INSTANCEOF : 'instanceof';
|
||||
INT : 'int';
|
||||
INTERFACE : 'interface';
|
||||
LONG : 'long';
|
||||
NATIVE : 'native';
|
||||
NEW : 'new';
|
||||
PACKAGE : 'package';
|
||||
PRIVATE : 'private';
|
||||
PROTECTED : 'protected';
|
||||
PUBLIC : 'public';
|
||||
RETURN : 'return';
|
||||
SHORT : 'short';
|
||||
STATIC : 'static';
|
||||
STRICTFP : 'strictfp';
|
||||
SUPER : 'super';
|
||||
SWITCH : 'switch';
|
||||
SYNCHRONIZED : 'synchronized';
|
||||
THIS : 'this';
|
||||
THROW : 'throw';
|
||||
THROWS : 'throws';
|
||||
TRANSIENT : 'transient';
|
||||
TRY : 'try';
|
||||
VOID : 'void';
|
||||
VOLATILE : 'volatile';
|
||||
WHILE : 'while';
|
||||
|
||||
HexLiteral : '0' ('x'|'X') HexDigit+ IntegerTypeSuffix? ;
|
||||
|
||||
DecimalLiteral : ('0' | '1'..'9' '0'..'9'*) IntegerTypeSuffix? ;
|
||||
|
@ -890,12 +938,6 @@ OctalEscape
|
|||
| '\\' ('0'..'7')
|
||||
;
|
||||
|
||||
ENUM: 'enum' {enumIsKeyword}?
|
||||
;
|
||||
|
||||
ASSERT
|
||||
: 'assert' {assertIsKeyword}?
|
||||
;
|
||||
|
||||
Identifier
|
||||
: JavaLetter JavaLetterOrDigit*
|
||||
|
|
|
@ -167,11 +167,6 @@
|
|||
*/
|
||||
grammar Java;
|
||||
|
||||
@lexer::members {
|
||||
protected boolean enumIsKeyword = true;
|
||||
protected boolean assertIsKeyword = true;
|
||||
}
|
||||
|
||||
// starting point for parsing a java file
|
||||
/* The annotations are separated out to make parsing faster, but must be associated with
|
||||
a packageDeclaration or a typeDeclaration (and not an empty one). */
|
||||
|
@ -939,6 +934,59 @@ arguments
|
|||
|
||||
// LEXER
|
||||
|
||||
// §3.9 Keywords
|
||||
|
||||
ABSTRACT : 'abstract';
|
||||
ASSERT : 'assert';
|
||||
BOOLEAN : 'boolean';
|
||||
BREAK : 'break';
|
||||
BYTE : 'byte';
|
||||
CASE : 'case';
|
||||
CATCH : 'catch';
|
||||
CHAR : 'char';
|
||||
CLASS : 'class';
|
||||
CONST : 'const';
|
||||
CONTINUE : 'continue';
|
||||
DEFAULT : 'default';
|
||||
DO : 'do';
|
||||
DOUBLE : 'double';
|
||||
ELSE : 'else';
|
||||
ENUM : 'enum';
|
||||
EXTENDS : 'extends';
|
||||
FINAL : 'final';
|
||||
FINALLY : 'finally';
|
||||
FLOAT : 'float';
|
||||
FOR : 'for';
|
||||
IF : 'if';
|
||||
GOTO : 'goto';
|
||||
IMPLEMENTS : 'implements';
|
||||
IMPORT : 'import';
|
||||
INSTANCEOF : 'instanceof';
|
||||
INT : 'int';
|
||||
INTERFACE : 'interface';
|
||||
LONG : 'long';
|
||||
NATIVE : 'native';
|
||||
NEW : 'new';
|
||||
PACKAGE : 'package';
|
||||
PRIVATE : 'private';
|
||||
PROTECTED : 'protected';
|
||||
PUBLIC : 'public';
|
||||
RETURN : 'return';
|
||||
SHORT : 'short';
|
||||
STATIC : 'static';
|
||||
STRICTFP : 'strictfp';
|
||||
SUPER : 'super';
|
||||
SWITCH : 'switch';
|
||||
SYNCHRONIZED : 'synchronized';
|
||||
THIS : 'this';
|
||||
THROW : 'throw';
|
||||
THROWS : 'throws';
|
||||
TRANSIENT : 'transient';
|
||||
TRY : 'try';
|
||||
VOID : 'void';
|
||||
VOLATILE : 'volatile';
|
||||
WHILE : 'while';
|
||||
|
||||
HexLiteral : '0' ('x'|'X') HexDigit+ IntegerTypeSuffix? ;
|
||||
|
||||
DecimalLiteral : ('0' | '1'..'9' '0'..'9'*) IntegerTypeSuffix? ;
|
||||
|
@ -992,12 +1040,6 @@ OctalEscape
|
|||
| '\\' ('0'..'7')
|
||||
;
|
||||
|
||||
ENUM: 'enum' {enumIsKeyword}?
|
||||
;
|
||||
|
||||
ASSERT
|
||||
: 'assert' {assertIsKeyword}?
|
||||
;
|
||||
|
||||
Identifier
|
||||
: JavaLetter JavaLetterOrDigit*
|
||||
|
|
Loading…
Reference in New Issue