[antlr-interest] disabling portions of a rule?
Robert Hill
rob.hill at blueyonder.co.uk
Mon Oct 30 12:22:46 PST 2006
Hi all,
I Have a rule like this
exampleRule
@init {
Symbol s = null;
}
: ^(MAP Identifier { s = Symbol.Resolve($Identifier.text);
if (s==null)
ShowError();
}
({s==null}? Subrule[s]);
)
So , basically if the identifier isn't in the symbol table we don't call the
subrule. The predicate does the job but when a symbol isn't found I get a
whole bunch of errors about mismatched tree nodes.. - how do I either
a) exit the rule early without displaying the antlr errors, or
b) consume the tokens that follow even though I cant call the subrule to get
rid of them?
The subrule assumes it will always be passed a valid symbol, and has quite a
few alts in it, so I don't want to add a if (s!=null) before all of the code
in the subrule.
I'd like to prevent antlr from showing its mismatched tree errors, whilst
preferably not exiting with a null pointer exception from within the
subrule...
Whats the neat/preferable way of handling this?
Cheers!
Rob
More information about the antlr-interest
mailing list