[antlr-interest] This is driving me crazy .. please help !
Ymo
ymo.mail at gmail.com
Fri Apr 4 07:01:32 PDT 2008
I already have file defined i dont understand why the parser still cant see
this rule !
error:
public void initTemplates() {
}
BR.recoverFromMismatchedToken
line 23:7 mismatched input 'file ${fname} »\r\n ' expecting EOF
input:
package org.idezk.xmm.xmmt.parser.templates;
import org.antlr.runtime.ANTLRFileStream;
import org.antlr.runtime.CharStream;
import org.antlr.runtime.CommonTokenStream;
import org.antlr.runtime.RecognitionException;
import org.antlr.runtime.tree.CommonTreeNodeStream;
import org.antlr.runtime.tree.Tree;
import org.idezk.xmm.xmmt.parser.grammar.XTemplateLexer;
import org.idezk.xmm.xmmt.parser.grammar.XTemplateParser;
public class BasicDriver {
public static void main(String[] args) {
String fname = args[0];
new BasicDriver().compile(fname);
}
public void initTemplates() {
}
«file ${fname} »
«/file»
/*
«file ${fname} »
if(){
«print»
testing «${}»
«/print»
}
else if(){
«print»«/print»
}
«/file»
*/
}
grammar :
templateFile
: templateBlock
EOF
;
templateBlock //returns [AstTemplateBlock tb]
@init{List fBlocks=new ArrayList() , eBlocks=new ArrayList(); }
: textBlock LG
( fb=fileBlock eb=elementBlock )*
;
fileBlock //returns [AstFileBlock afb]
: 'file' codeBlock
(elementBlock (printBlock elementBlock)* )*
'/file'
;
printBlock //returns [AstPrintBlock apb]
: 'print'
( elementBlock
(cb=codeBlock eb=elementBlock )* )*
'/print'
;
codeBlock //returns [AstCodeBlock cb]
: '$' '{' textBlock '}'
;
elementBlock //returns [AstElementBlock aeb]
: RG textBlock LG?
;
textBlock //returns [AstTextBlock cb]
: tb=TextBlock { System.out.println("tb:"+tb.getText()); }
;
//LEXER
WS : (' '|'\r'|'\t'|'\u000C'|'\n') {$channel=HIDDEN;}
;
ML_COMMENT
: '/*' ( options {greedy=false;} : . )* '*/' {$channel=HIDDEN;}
;
LINE_COMMENT
: '//' ~('\n'|'\r')* '\r'? '\n' {$channel=HIDDEN;}
;
LG : '\u00AB';
fragment
RG: '\u00BB';
TextBlock //returns [AstTextBlock atb]
: ~(LG)*
;
// a dummy rule to force vocabulary to be all characters (except special
// ones that ANTLR uses internally (0 to 2) and the guillemot characters
fragment
VOCAB :
('\3'..'\u00aa'|'\u00ac'..'\u00ba'|'\u00bc'..'\ufffe')
;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080404/a611700c/attachment-0001.html
More information about the antlr-interest
mailing list