I am coding an Antlr grammar which matches strings.
My first attempt was:

doc    :    STRINGCONST;

STRINGCONST
    :    ('@"' ( options {greedy=false;} : . )* '"') //Accepts lots of
stuff, including newlines
    |    ('"' (
            (
                '\\' ('\\' | '"' | 'n' | 't' | OCTALCHAR)
            ) | (
                ~('"'|'\\'|LINEBREAK)
            )
        )* '"')
    ;

Which matches correctly "", "\\" and "\na" but fails for "abc"(with
MismatchedTokenException).
However, I can not understand *why* it fails for "abc"!
It gets even weirder since

STRINGCONST
    :    ('@"' ( options {greedy=false;} : . )* '"') //Accepts lots of
stuff, including newlines
    |    ('"' (
            (
                '\\' ('\\' | '"' | 'n' | 't' | OCTALCHAR)
            ) | (
                ~('"'|'\\'|LINEBREAK)
            )
        )+ '"')
    ;

works perfectly. What's happening here? What am I missing?

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

Reply via email to