[antlr-interest] Antlr 4 grammar options

mat dodgson mat at mad.id.au
Wed Dec 28 21:47:53 PST 2011

Hi folks!

First let me say that I've been using Antlr for a short time but it's
great! I'm particularly excited about the new Java listener mechanism - it
makes life much simpler in certain scenarios!

I downloaded the latest antlr4 and stringtemplate4 today from github and
compiled them. I'm having a problem with an options block for a multi line
comment. Has the syntax for options changed in antlr v4 grammars?

Here's the comment rule from my grammar:

    :   '//' ~('\n'|'\r')* '\r'? '\n' {$channel=HIDDEN;}
    |   '/*' ( options {greedy=false;} : . )* '*/' {$channel=HIDDEN;}

The COMMENT rule was auto generated by antlrworks. The error I'm getting is
related to the options block on the multiline comment. It just looks like
it's not expecting the options block at that point:

error(15): LTM_ParseTree.g:43:15: required (...)+ loop did not match
anything at input 'options {' while looking for lexer rule element
error(15): LTM_ParseTree.g:43:37: '}' came as a complete surprise to me

line 43 is the multiline comment.

If I remove the options block and the colon the grammar works however I
don't want a greedy comment block in my grammar.

I know antlr v4 hasn't been released yet: have options like this been
implemented yet? Can anyone suggest anything?


Mat Dodgson

More information about the antlr-interest mailing list