[antlr-interest] looking for rewrite rule - (UNION | EXCEPT)^ ALL? put in one token
S.Eifert
athavar at web.de
Mon Jul 26 06:52:57 PDT 2010
Hi everyone,
I'm working on an existing project with a SQL-Grammar. So I have strict
limitations to watch while I have to enhance the functions.
There's one rule which I just cant figure out how to solve. The following is
in the grammar so far.
query_exp
: query_term ((UNION | EXCEPT)^ ALL? query_term)*
;
- query_term can reference back on query_exp
- UNION etc. are lexical rules to ignore casesensivity
example:
UNION : U N I O N;
EXCEP : E X C E P T;
The single letters are matched to their upper and lower counterpart.
I now need to change the way a UNION ALL is parsed. If I use the structure
above ALL will be a child of UNION. But I need a single Token named
UNIONALL. The rest of the structure needs to be the same. The treehandling
is in a part I can not touch.
What I tried:
query_exp
: query_term ((UNION | UNIONALL | EXCEPT | EXCEPTALL)^ query_term)*
;
- This does not work, because the lexical rules for UNION / UNIONALL
conflict each other. At least that seems to be the problem.
I tried to use a rewrite rule. I used an Integer to keep track of which
option (UNION/EXCEPT, maybe ALL) was chosen and put several conditioned
rewrite rules. The problem was the Integer in the Parser was inside an
if-clause and could not be read.
if ( state.backtracking==0 ) {
int MYINTEGER = 0;
}
Finally I tinkered with an additional rule where I build a String for the
option taken (EXCEPT ALL, EXCEPT.. etc) and tried to return this. I think I
was on the wrong track there.. it did not work at all.
Probably the solution is very simple and I just cant find. I would be very
thankfull for some input.
I'm using ANTLR 3.1.2
Cheers
Sandro
--
View this message in context: http://antlr.1301665.n2.nabble.com/looking-for-rewrite-rule-UNION-EXCEPT-ALL-put-in-one-token-tp5338034p5338034.html
Sent from the ANTLR mailing list archive at Nabble.com.
More information about the antlr-interest
mailing list