[antlr-interest] ANTLR 3.0b3 : Bug ? Rule actions executed when
filter=false but not when filter=true...
Kay Roepke
kroepke at classdump.org
Fri Aug 4 03:10:45 PDT 2006
On 4. Aug 2006, at 11:13 Uhr, David CROSSON wrote:
> sorry for posting again this message, but I don't see why
> using the same data, rule and token actions are executed when
> options {filter=false}; but when I use options {filter=true}
> only token actions are executed !
Hi David!
I think this is because the filter option doesn't work for parsers at
the moment, it's on the todo list.
<http://antlr.org/wiki/display/ANTLR3/filters+and+pattern+matching+for
+parser>
When you have a combined grammar, and specify options {filter=true;}
the option gets set in both the parser and lexer grammars,
though for the parser this will generate incorrect code. The action
would only be executed when the parser backtracks, which
is never happening, because it doesn't yet know how to do ;)
From the generated TryIt2Parser.java:
if ( backtracking==1 ) {
System.out.println("CALLED FROM RULE");
}
backtracking will never be incremented in the parser as it is now.
Thus the todo entry...
If you currently want to have a filtering lexer, you would have to do
separate grammars, not combined. I think there's currently
no way to specify options solely for the lexer in a combined grammar,
but I have to check on that. So, e.g. this doesn't work:
-------------------------------------------
grammar foo;
options {
output=AST;
}
lexer::options {
filter=true;
}
a: A+;
A: 'A';
-------------------------------------------
But this does:
-------------------------------------------
parser grammar TryIt2Parser;
options {
output=AST;
}
go : A+ {System.out.println("CALLED FROM RULE"); }
;
-------------------------------------------
lexer grammar TryIt2ParserLexer;
options {
filter=true;
}
A : 'A' {System.out.println("CALLED FROM TOKEN");}
;
-------------------------------------------
But it sure would be nice to have, methinks. Especially one the
parser learns to backtrack and we want to have only the lexer
backtrack, but
still want to write a combined grammar.
-> Ter?
HTH,
-k
--
Kay Röpke <kroepke at classdump.org>
classdump Software
More information about the antlr-interest
mailing list