Eric,
Here's the grammar I'm using:
grammar test;
rule : STRING;
RPAREN : ')';
LPAREN : '(';
WS : ( ' '
| '\t'
| '\r'
| '\n'
) {$channel=HIDDEN;}
;
CHAR: '\'' ( ESC_SEQ | ~('\''|'\\') ) '\''
;
STRING
: '\'' ( ESC_SEQ | ~('\\'|'\'') )* '\''
;
fragment
HEX_DIGIT : ('0'..'9'|'a'..'f'|'A'..'F') ;
fragment
ESC_SEQ
: '\\' ('b'|'t'|'n'|'f'|'r'|'\"'|'\''|'\\')
| UNICODE_ESC
| OCTAL_ESC
;
fragment
OCTAL_ESC
: '\\' ('0'..'3') ('0'..'7') ('0'..'7')
| '\\' ('0'..'7') ('0'..'7')
| '\\' ('0'..'7')
;
fragment
UNICODE_ESC
: '\\' 'u' HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT
;
Please not that, apart from the parenthesis, the rest is generated by
ANTLRWorks. Using the interpreter to match the string ' ' (single quotes and
one space, or any letter between the quotes), I get a
MismatchedTokenException(4!=10). It only matches '' (single quote without
space).
I tried removing the CHAR rule and then, for the same input, I get:
MismatchedTokenException(-1!=9)
and in the console
problem matching token at 1:3 NoViableAltException('?'@[()* loopback of
17:13: ( ESC_SEQ |~ ( '\\' | '\'' ) )*])
I tried using the debugger, but on Windows I get a javac, cannot create
process error and In my Mac, I get compile time errors in the generated
classes because it cannot find antlr classes (probably just a classpath
problem). Is there any documentation on how to use AntlrWorks features? The
site documentation is pretty shallow and I cannot find any tutorials.
Regards,
Gabriel MirĂ³
ANTLR Newbie
> -----Original Message-----
> From: [email protected] [mailto:antlr-interest-
> [email protected]] On Behalf Of The Researcher
> Sent: Friday, September 09, 2011 2:46 PM
> To: [email protected]
> Subject: Re: [antlr-interest] How to recognize a String
>
> Hi Gabriel,
>
> It would help if you could post your entire grammar and the exact error
> message here.
>
> Also, don't you mean
>
> LPAREN: '(";
> RPAREN: ')';
>
> Don't worry we have all been there.
>
> Thanks, Eric
>
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 [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.