[antlr-interest] templates and question marks (-> '?')

Jens Boeykens jens.boeykens at gmail.com
Tue Jul 1 10:47:06 PDT 2008


Hi,

Consider a grammar:

grammarDef
    :   ^( grammarType ID DOC_COMMENT? optionsSpec? tokensSpec? attrScope* action* rule+ )
    ;

If I want to add a template rewrite rule and use e.g. optionsSpec:

grammarDef
    :   ^( grammarType ID DOC_COMMENT? optionsSpec? tokensSpec? attrScope* action* rule+ ) -> temp(options={$optionsSpec.text})
    ;

This can give nullpointer exceptions when there is no optionsSpec given 
(note the '?').
What is the easiest way to change the rewrite and avoid an exception?

Thanx in advance for any help!


More information about the antlr-interest mailing list