When you look in the generated code where your exception block is placed, you will see that it is part of a method that is meant to parse the section
rule, probably something like:
public final SectionContext section() throws RecognitionException {
SectionContext _localctx = new SectionContext(_ctx, getState());
...
}
As you see there's a parse context (_localctx
) created for this rule, which will get all sub contexts along with references to the first and last token that make up this rule (see ParserRuleContext.start
and ParserRuleContext.stop
. This is where you can get the source info from.
It could be that this SectionContext
instance is not yet finish at the time of the exception. In that case you can use the parent context instead (the _ctx
parameter in the SectionContext
creation call).