]> granicus.if.org Git - postgresql/commitdiff
Fix filtered_base_yylex() to save and restore base_yylval and base_yylloc
authorTom Lane <tgl@sss.pgh.pa.us>
Sat, 6 Jan 2007 19:14:17 +0000 (19:14 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Sat, 6 Jan 2007 19:14:17 +0000 (19:14 +0000)
properly when doing a lookahead.  The lack of this was causing various
interesting misbehaviors when one tries to use "with" as a plain identifier.

src/backend/parser/parser.c

index 8490f8ab8b81461d9533caebddda746c13691664..c007613cc4e3148b47d5c691fc8e979d6d852766 100644 (file)
@@ -14,7 +14,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/parser/parser.c,v 1.69 2007/01/05 22:19:34 momjian Exp $
+ *       $PostgreSQL: pgsql/src/backend/parser/parser.c,v 1.70 2007/01/06 19:14:17 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
 
 List      *parsetree;                  /* result of parsing is left here */
 
-static int     lookahead_token;        /* one-token lookahead */
-static bool have_lookahead;            /* lookahead_token set? */
+static bool have_lookahead;                    /* is lookahead info valid? */
+static int     lookahead_token;                /* one-token lookahead */
+static YYSTYPE lookahead_yylval;       /* yylval for lookahead token */
+static YYLTYPE lookahead_yylloc;       /* yylloc for lookahead token */
 
 
 /*
@@ -77,11 +79,16 @@ int
 filtered_base_yylex(void)
 {
        int                     cur_token;
+       int                     next_token;
+       YYSTYPE         cur_yylval;
+       YYLTYPE         cur_yylloc;
 
        /* Get next token --- we might already have it */
        if (have_lookahead)
        {
                cur_token = lookahead_token;
+               base_yylval = lookahead_yylval;
+               base_yylloc = lookahead_yylloc;
                have_lookahead = false;
        }
        else
@@ -102,8 +109,10 @@ filtered_base_yylex(void)
                         * (perhaps for SQL99 recursive queries), come back and simplify
                         * this code.
                         */
-                       lookahead_token = base_yylex();
-                       switch (lookahead_token)
+                       cur_yylval = base_yylval;
+                       cur_yylloc = base_yylloc;
+                       next_token = base_yylex();
+                       switch (next_token)
                        {
                                case CASCADED:
                                        cur_token = WITH_CASCADED;
@@ -115,7 +124,14 @@ filtered_base_yylex(void)
                                        cur_token = WITH_CHECK;
                                        break;
                                default:
+                                       /* save the lookahead token for next time */
+                                       lookahead_token = next_token;
+                                       lookahead_yylval = base_yylval;
+                                       lookahead_yylloc = base_yylloc;
                                        have_lookahead = true;
+                                       /* and back up the output info to cur_token */
+                                       base_yylval = cur_yylval;
+                                       base_yylloc = cur_yylloc;
                                        break;
                        }
                        break;