COMMENT
: '/*'
( (~'*' | '*' ~'/') => VALID_CHAR
)*
'*/'
;
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Ranco Marcus
Sent: Tuesday, November 11, 2008 11:47 AM
To: [EMAIL PROTECTED]
Subject: [antlr-interest] fragment and option greedy=false
Hello all,
I would like to know if there are any limitations on the use of
fragments in non-greedy sub rules. In the example below, I would like to
create a lexer rule that matches with a comment (i.e. starts with /*,
has zero or more characters from the given fragment and ends with */).
grammar MulticharComment;
sentence
: COMMENT '.'
;
COMMENT
// : '/*' ( options {greedy=false;} : VALID_CHARS )* '*/'
// option 1
: '/*' ( options {greedy=false;} : ('a'..'z' | '*' | '/') )*
'*/' // option 2
;
fragment
VALID_CHARS
: 'a'..'z' | '*' | '/'
;
If I use the line with the fragment (option 1), I get the following
error (in ANTLRWorks 1.2.1, ANTLR v3.1.1) which I didn't expect.
Input: /*abba*/.
Error: problem matching token at 1:9 NoViableAltException('.'@[()*
loopback of 8:10: ( options {greedy=false; } : VALID_CHARS )*])
Where does '.'@[()* come from and what is meant by 'the loopback'?
In this particular example, I could use the pattern itself (option 2)
and accept a little redundancy. However, if the pattern is more complex
(i.e. consists of Unicode character ranges, escapes, multiple subrules
etc.), this doesn't feel right.
It would be great if any of you could clarify on this matter. Thanks in
advance.
Kind regards, Ranco Marcus
List: http://www.antlr.org:8080/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org:8080/mailman/options/antlr-interest/your-email-addr
ess
List: http://www.antlr.org:8080/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org:8080/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 [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---