Close
jGuru Forums
Posted By: jeancallisti Posted On: Tuesday, June 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 ;
Re: Why does this simple grammar fail to spot that pattern?
Posted By: jeancallisti Posted On: Thursday, June 28, 2012 04:19 AM
Posted By: franz Posted On: Wednesday, June 27, 2012 02:08 PM