I have a problem building AST in ANTLR (I am using ANTLR 3.2, ANTLRWorks 1.4).
This is my grammar:
classDeclaration
:
(
'class' n=IDENTIFIER ('extends' e=IDENTIFIER)?
'{'
β¦
'}'
)
-> ^(CLASSDECLARATION ^(NAME $n) ^(EXTENDS $e)
;
The problem arises with the optional part of the class - ('extends' e=IDENTIFIER)?.
So the grammar works with this class declaration:
class Test1 extends AbstractTest1 {
β¦
}
And it fails if I exclude the part extendsas follows:
class Test2 {
β¦
}
ANTLR just stops before this snippet and gives this exception in the console:
javax.swing.text.BadLocationException: Position not represented by view
How can I point to ANTLR to treat the rewrite rule ^(EXTENDS $e)as optional?
source
share