Proto
Proto

Reputation: 77

Extract grammar definition from ANTLR g file

I have a rather complex ANTLR grammar with a lot of custom handling code (which among other things is used for the creation of internal data structures and handling of data in general). What I'd like to know is if ANTLR provides any capability (or if there is any existing tool) for removing all the custom grammar handling (e.g. Java code, @init, @after sections, parameters, return types, etc) and leave me with the barebones grammar definition. I know that I could do this with some regex handling, but I imagined this could be a recurring task so there may already be something out there that does this.

Example:

rule[String blabla] returns [blabla]
scope{
   blablabal;
}
@init{
   blalbabla;
}
:
   STRING COMMA STRING {blablabla code blablabla;}
;

would return

rule:
   STRING COMMA STRING
;

Upvotes: 1

Views: 172

Answers (1)

Terence Parr
Terence Parr

Reputation: 5962

Have you tried -print option? (v3 only so far)

Upvotes: 1

Related Questions