[antlr-interest] Antlr 4 grammar options

Terence Parr parrt at cs.usfca.edu
Thu Dec 29 09:23:28 PST 2011


Hi Mat. .* is nongreedy by default in v4.
Ter
On Dec 28, 2011, at 9:47 PM, mat dodgson wrote:

> 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:
> 
> COMMENT
>    :   '//' ~('\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?
> 
> Thanks
> 
> Mat Dodgson
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address



More information about the antlr-interest mailing list