Skip to content

Commit d216233

Browse files
committed
fix(grammar): super invocation
1 parent 8a0a459 commit d216233

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/index.spec.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
import { ParseTreeWalker } from 'antlr4ts/tree/ParseTreeWalker';
12
import { parse } from './index';
3+
import { ExpressionContext } from './parser/JavaParser';
4+
import { JavaParserListener } from './parser/JavaParserListener';
25

36
describe('Java AST parser', () => {
47
it('should parse the given Java code and return the AST', () => {
@@ -8,4 +11,26 @@ describe('Java AST parser', () => {
811
`);
912
expect(tree.children[0].getChild(0).getChild(1).text).toEqual('TestClass');
1013
});
14+
15+
it('should handle super invocation with arguments', () => {
16+
const tree = parse(`
17+
class B extends A {
18+
public B() {
19+
super(1);
20+
}
21+
}
22+
`);
23+
24+
const expressions = [];
25+
ParseTreeWalker.DEFAULT.walk(
26+
{
27+
enterExpression(context: ExpressionContext) {
28+
expressions.push(context.text);
29+
},
30+
} as JavaParserListener,
31+
tree,
32+
);
33+
34+
expect(expressions).toContain('super(1)');
35+
});
1136
});

src/parser/JavaParser.g4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ lambdaBody
524524
primary
525525
: '(' expression ')'
526526
| THIS
527-
| SUPER
527+
| SUPER superSuffix
528528
| literal
529529
| IDENTIFIER
530530
| typeTypeOrVoid '.' CLASS

0 commit comments

Comments
 (0)