To exclude the /* and */ would something like this work? COMMENT : '/*'! ( options {greedy=false;} : . )* '*/'! ;
-----Original Message----- From: antlr-interest-boun...@antlr.org [mailto:antlr-interest-boun...@antlr.org] On Behalf Of Andreas Volz Sent: September 23, 2009 5:36 PM To: antlr-inter...@antlr.org Subject: [antlr-interest] Question with greedy Hello, I wrote this grammar: startrule : (property comment property)* ; comment : COMMENT { printf("Comment: \%s\n", $COMMENT.text->chars); } ; COMMENT : '/*' ( options {greedy=false;} : . )* '*/' ; property : TOKEN { printf("Property: \%s\n", $TOKEN.text->chars);} TOKEN : (ALPHA | DIGIT)+ fragment DIGIT : '0'..'9' ; fragment ALPHA : 'a'..'z' | 'A'..'Z' |'@'|'.'| ' ' ; The input is: This is a test /* with a comment */ in the middle This is a test /* with a comment */ in the middle This is a test /* with a comment */ in the middle The result looks good, but some errors are print out: test.txt(1) : lexer error 3 : at offset 49, near char(0XA) : This is a test /* w test.txt(2) : lexer error 3 : at offset 50, near char(0XA) : This is a test /* w test.txt(3) : lexer error 3 : at offset 50, near char(0XA) : Property: This is a test Comment: /* with a comment */ Property: in the middle Property: This is a test Comment: /* with a comment */ Property: in the middle Property: This is a test Comment: /* with a comment */ Property: in the middle BTW: The line ending in this file is 0x0A. Could anyone explain this error and how to prevent it? Second question: How do I not include the '/*' and '*/' tags in the comment match? regards Andreas List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "il-antlr-interest" group. To post to this group, send email to il-antlr-interest@googlegroups.com To unsubscribe from this group, send email to il-antlr-interest+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/il-antlr-interest?hl=en -~----------~----~----~----~------~----~------~--~---