Close
jGuru Forums
Expand All | Collapse All
Why does this simple grammar fail to spot that pat... jeancallistiTue Jun 26, 2012 07:21 AM
Hello people, I know there are newbies (like me) asking all the time why a grammar fails, or how to disambiguate, etc., and that must be utterly boring/irritating. But I really can't figure out why it does that. My complete grammar is actually much more complex, but I've stripped it down to the simplest version (one single rule) to find the cause of the issue, and still can't find it. ======== on to the issue ========== Below you'll find a simple grammar. Yet, when I feed it with this (a text file containing nothing else), it fails to recognize it : /** @pluginName: agsMyPlugin2 **/ The error message is : line 1:0 no viable alternative at input '/** @pluginName: agsMyPlugin2 **/ ' The grammar is below. ========== actual grammar ============= grammar EasyPluginGrammar; options { language = Java; output = AST; //we tell ANTLR that we want to produce a crawlable tree ASTLabelType = CommonTree; // each node of the tree will be of type "CommonTree" } tokens { SPECIALCOMMENTTAG; RAWSPECIALCOMMENT; NOSPECIALCOMMENT; } plugin : specialComment EOF! ; specialComment : '/**' '@' scTag ':' scValue '**/' -> SPECIALCOMMENTTAG scTag scValue | -> NOSPECIALCOMMENT ; scTag : IDENT ; scValue : RSC_TEXT //I also tried with "IDENT" instead of "RSC_TEXT" ; fragment LETTER : 'a'..'z'|'A'..'Z' ; fragment DIGIT : '0'..'9' ; IDENT : ( LETTER ) ( LETTER | DIGIT )* ; INTEGER : DIGIT + ; RSC_TEXT : ( ASCII_EXCEPT_BACKSLASH )+ ; fragment ASCII_EXCEPT_BACKSLASH : ' '..'[' | ']'..'~' ; WS : ( ' ' | '\t' | '\r' | '\n' ) {$channel=HIDDEN;}; fragment EXPONENT : ('e'|'E') ('+'|'-')? ('0'..'9')+ ; fragment HEX_DIGIT : (DIGIT|'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 ;
Report | Quote This | Reply | Print
I think the problem is the lexer doesn't know what...
I think the problem is the lexer doesn't know what to match after '@'. From the lexers view pluginName could be IDENT or RSC_NAME. But i've to admit I'm also new to ANTLR, but i tested with
Thanks a lot for your suggestion, I will let you k...
Thanks a lot for your suggestion, I will let you know asap.