Skip to content

Commit 45775d8

Browse files
committed
feat(java): update Java AST parser for new grammar
Add JavaParserBase with helper methods and adapt listeners to match updated Antlr grammar. Changes include handling new annotation structure, method references, and parameter parsing.
1 parent e60f24f commit 45775d8

File tree

6 files changed

+431
-253
lines changed

6 files changed

+431
-253
lines changed

chapi-ast-java/src/main/antlr/JavaLexer.g4

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -53,26 +53,36 @@ DO : 'do';
5353
DOUBLE : 'double';
5454
ELSE : 'else';
5555
ENUM : 'enum';
56+
EXPORTS : 'exports';
5657
EXTENDS : 'extends';
5758
FINAL : 'final';
5859
FINALLY : 'finally';
5960
FLOAT : 'float';
6061
FOR : 'for';
61-
IF : 'if';
6262
GOTO : 'goto';
63+
IF : 'if';
6364
IMPLEMENTS : 'implements';
6465
IMPORT : 'import';
6566
INSTANCEOF : 'instanceof';
6667
INT : 'int';
6768
INTERFACE : 'interface';
6869
LONG : 'long';
70+
MODULE : 'module';
6971
NATIVE : 'native';
7072
NEW : 'new';
73+
NON_SEALED : 'non-sealed';
74+
OPEN : 'open';
75+
OPENS : 'opens';
7176
PACKAGE : 'package';
77+
PERMITS : 'permits';
7278
PRIVATE : 'private';
7379
PROTECTED : 'protected';
80+
PROVIDES : 'provides';
7481
PUBLIC : 'public';
82+
RECORD: 'record';
83+
REQUIRES : 'requires';
7584
RETURN : 'return';
85+
SEALED : 'sealed';
7686
SHORT : 'short';
7787
STATIC : 'static';
7888
STRICTFP : 'strictfp';
@@ -82,38 +92,19 @@ SYNCHRONIZED : 'synchronized';
8292
THIS : 'this';
8393
THROW : 'throw';
8494
THROWS : 'throws';
95+
TO : 'to';
8596
TRANSIENT : 'transient';
97+
TRANSITIVE : 'transitive';
8698
TRY : 'try';
99+
USES : 'uses';
100+
VAR: 'var'; // reserved type name
87101
VOID : 'void';
88102
VOLATILE : 'volatile';
103+
WHEN : 'when';
89104
WHILE : 'while';
90-
91-
// Module related keywords
92-
MODULE : 'module';
93-
OPEN : 'open';
94-
REQUIRES : 'requires';
95-
EXPORTS : 'exports';
96-
OPENS : 'opens';
97-
TO : 'to';
98-
USES : 'uses';
99-
PROVIDES : 'provides';
100105
WITH : 'with';
101-
TRANSITIVE : 'transitive';
102-
103-
// Local Variable Type Inference
104-
VAR: 'var'; // reserved type name
105-
106-
// Switch Expressions
107106
YIELD: 'yield'; // reserved type name from Java 14
108107

109-
// Records
110-
RECORD: 'record';
111-
112-
// Sealed Classes
113-
SEALED : 'sealed';
114-
PERMITS : 'permits';
115-
NON_SEALED : 'non-sealed';
116-
117108
// Literals
118109

119110
DECIMAL_LITERAL : ('0' | [1-9] (Digits? | '_'+ Digits)) [lL]?;
@@ -213,7 +204,7 @@ IDENTIFIER: Letter LetterOrDigit*;
213204
fragment ExponentPart: [eE] [+-]? Digits;
214205

215206
fragment EscapeSequence:
216-
'\\' 'u005c'? [btnfr"'\\]
207+
'\\' 'u005c'? [bstnfr"'\\]
217208
| '\\' 'u005c'? ([0-3]? [0-7])? [0-7]
218209
| '\\' 'u'+ HexDigit HexDigit HexDigit HexDigit
219210
;

0 commit comments

Comments
 (0)