[antlr-interest] Lexing problem
Emond Papegaaij
e.papegaaij at student.utwente.nl
Fri Oct 13 08:34:05 PDT 2006
Hello,
I'm trying to match a multiline c-style comment into a COMMENT token
without the opening and closing '/*' and '*/'. This is how I would do it
in ANTLRv2:
COMMENT: '/*'! ( options {greedy=false;} : . )* '*/'!;
However the '!' does not work in v3. So I tried all of the following:
COMMENT: '/*' contents=(( options {greedy=false;} : . )*) '*/'
{ setText($contents.text); };
COMMENT: '/*' contents=COMMENT_BODY '*/' { setText($contents.text); };
COMMENT_BODY: ( options {greedy=false;} : . )*;
COMMENT: '/*' ( options {greedy=false;} : contents=COMMENT_BODY ) '*/'
{ setText($contents.text); };
COMMENT_BODY: .*;
COMMENT: '/*' contents=COMMENT_BODY '*/' { setText($contents.text); };
COMMENT_BODY: (~'*/')*;
COMMENT: '/*' contents=COMMENT_BODY '*/' { setText($contents.text); };
COMMENT_BODY: ((~'*') | ('*' ~'/'))*;
Non of them work. Some produce syntax errors, others don't match the exit
branch and the last one produces "mismatched char: '/' on line 1:9;
expecting set null" during parsing. Can anybody help me out with this
rule?
Best regards,
Emond Papegaaij
More information about the antlr-interest
mailing list