[antlr-interest] looking for rewrite rule - (UNION | EXCEPT)^ ALL? put in one token

Jim Idle jimi at temporal-wave.com
Tue Jul 27 10:44:32 PDT 2010


The example I gave you yesterday will do all that you need to do without you having to play with the lexer. If you switch to that method, you will be done in 5 minutes. My example only used a sub-rule; it does not change the position of the tokens in the tree. 

Though to be honest I am not sure why you need to have UNIONALL - just detect UNTION in the tree walker and if ALL is the first child, then you know it is UNION ALL before you do anything else. That's by far the easier solution.

Jim

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of S.Eifert
> Sent: Tuesday, July 27, 2010 9:39 AM
> To: antlr-interest at antlr.org
> Subject: Re: [antlr-interest] looking for rewrite rule - (UNION |
> EXCEPT)^ ALL? put in one token
> 
> 
> Hello,
> 
> thanks for the input, jbb.
> 
> What I got now is the following:
> 
> tokens{
>   UNIONALL;
>   EXCEPTALL;
> }
> 
> query_exp
>   : query_term ((UNION | EXCEPT | UNIONALL | EXCEPTALL)^ query_term)*
>   ;
> 
> UNION : U N I O N (WS A L L { $type=UNIONALL; } )? ;
> 
> WS  : (' ' | '\t' | '\n' | '\r')+ {$channel = HIDDEN;};
> 
> This construction almost works. For parsing a sentence with UNION ALL
> the
> result is correct. When I try to use just UNION like "select * from
> table1
> UNION select * from table2;" I get an error "mismatched character 's'
> expecting set null". If I understand correctly it has something to do
> with
> the whitespaces behind the UNION. When I change the UNION lexical rule
> to
> 
> UNION : U N I O N WS (A L L { $type=UNIONALL; } )? ;
> 
> it kind of works. Using Space as a whitespace seems to work. Using a
> newline
> changes the type of the token to "UNION/n/r". Maybe someone has an idea
> what
> I'm overlooking here.
> 
> As a side node: Yes, if I was the one responsible for the whole grammar
> I
> would have used an extra rule to split unionstuff into UNION and
> UNIONALL.
> But I cannot put this information one child down in the tree. That's
> how the
> stuff was implemented before i came to the project. UNION or UNIONALL
> has to
> be at the exact position in the tree.
> 
> Cheers and thanks for the help so far
> Sandro
> --
> View this message in context:
> http://antlr.1301665.n2.nabble.com/looking-for-rewrite-rule-UNION-
> EXCEPT-ALL-put-in-one-token-tp5338034p5342977.html
> Sent from the ANTLR mailing list archive at Nabble.com.
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address





More information about the antlr-interest mailing list