Pragmatic solution
Just delete the public
modifier. Rules are public by default.
Reason public
is not recognized
I don't know! According to the Antlr4 grammar (https://github.com/antlr/grammars-v4/blob/master/antlr4/ANTLRv4Parser.g4), public
should be allowed. However, I am not sure whether this grammar is exactly the one used for Antlr4.
A more severe problem in your spec
AST constructors are no longer supported in Antlr4 so ^(Root global_block)
is not possible anymore. You need a tree visitor (or listener) to build a custom tree:
Run antlr
with the -visitor
option to generate a visitor class. This class is a generic class which has a visit
method for each rule, e.g.,
public class PropertyFileBaseVisitor<T> extends AbstractParseTreeVisitor<T>
implements PropertyFileVisitor<T>
{
@Override public T visitFile(PropertyFileParser.FileContext ctx) { ... }
@Override public T visitProp(PropertyFileParser.PropContext ctx) { ... }
}
It returns any T
, so you can simply write a visitor that builds a tree of your desired type and returns it. For a more in depth discussion of using visitors see If/else statements in ANTLR using listeners