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

Jim Idle jimi at temporal-wave.com
Mon Jul 26 13:24:54 PDT 2010


: query_term (unionstuff^ | EXCEPT^ ALL?) query_term);

unionstuff
  : UNION
      (   ALL -> UNIONALL
        |     -> UNION
      )
  ;

Also, your lexer is likely going to be really slow if handle case sensitivity like that. It is better to specify in UPPER case then override LA, as per the wiki article.

Jim


> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of S.Eifert
> Sent: Monday, July 26, 2010 6:53 AM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] looking for rewrite rule - (UNION | EXCEPT)^
> ALL? put in one token
> 
> 
> 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.
> 
> 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