[antlr-interest] Comment

Michael micha-1 at fantasymail.de
Thu May 7 07:45:35 PDT 2009


Am Thursday 07 May 2009 14:10:22 schrieb Thomas Dill:
>
>
> In the syntax, I want to parse, a comment line starts with "-*" and ends at
> the end of the line. It's possible that an asterisk can appear in a "text",
> too.

this is a simpler grammar,but it seems it does what you want:

grammar Xx;
start: report EOF;
report: (comment { System.out.println("comment: " + $comment.text);} 
           | text { System.out.println("text: " + $text.text);} )+; 

comment: COMMENT;
text: TEXTCHR+;

fragment NEWLINE: ('\n' | '\r');
COMMENT: '-*' (~NEWLINE)* NEWLINE;
TEXTCHR: (  ~('-') 
	|  ('-') ~'*') => '-'
         );



 Michael


More information about the antlr-interest mailing list