0
Antlr3产生以下输出System.out
,而其他人做正确的一切:这条ANTLR3日志消息的含义是什么?
line 0:0 null
line 0:0 null
line 0:0 null
...
它是什么?
ps。问题是,在解析时,我通过RecognitionException()
。看起来像null
是这样的结果。而不是null
应该有一些有意义的消息,但RecognitionException没有这样的构造函数。该怎么办?
grammar Bar;
document: (CHAR { Foo.validate($CHAR.text); })+ EOF;
CHAR: 'a'..'z';
Foo
类在同一包某处:
public class Foo {
public static void validate(String txt) throws RecognitionException {
if ("q".equals(txt)) {
throw new RecognitionException();
}
}
}
现在一个单元测试:
public class BarTest {
@Test public void testEverything() throws Exception {
this.parse("abc"); // valid
this.parse("abcq"); // invalid
}
private void parse(String txt) {
CharStream input = new ANTLRStringStream(txt);
BarLexer lexer = new BarLexer(input);
TokenStream tokens = new CommonTokenStream(lexer);
BarParser parser = new BarParser(tokens);
parser.document();
}
}
的输出是:
line 0:0 null
嗯,这是相当明显的,不是吗? :-D(我有时会发现antlr3的信息确实可能是神秘的) – 2011-02-17 16:13:14
Nah,根本不明显......你知道这是什么意思吗? – yegor256 2011-02-17 16:16:40