Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 063560b

Browse files
committed
Fix filtered_base_yylex() to save and restore base_yylval and base_yylloc
properly when doing a lookahead. The lack of this was causing various interesting misbehaviors when one tries to use "with" as a plain identifier.
1 parent e85ef6e commit 063560b

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

src/backend/parser/parser.c

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* Portions Copyright (c) 1994, Regents of the University of California
1515
*
1616
* IDENTIFICATION
17-
* $PostgreSQL: pgsql/src/backend/parser/parser.c,v 1.69 2007/01/05 22:19:34 momjian Exp $
17+
* $PostgreSQL: pgsql/src/backend/parser/parser.c,v 1.70 2007/01/06 19:14:17 tgl Exp $
1818
*
1919
*-------------------------------------------------------------------------
2020
*/
@@ -28,8 +28,10 @@
2828

2929
List *parsetree; /* result of parsing is left here */
3030

31-
static int lookahead_token; /* one-token lookahead */
32-
static bool have_lookahead; /* lookahead_token set? */
31+
static bool have_lookahead; /* is lookahead info valid? */
32+
static int lookahead_token; /* one-token lookahead */
33+
static YYSTYPE lookahead_yylval; /* yylval for lookahead token */
34+
static YYLTYPE lookahead_yylloc; /* yylloc for lookahead token */
3335

3436

3537
/*
@@ -77,11 +79,16 @@ int
7779
filtered_base_yylex(void)
7880
{
7981
int cur_token;
82+
int next_token;
83+
YYSTYPE cur_yylval;
84+
YYLTYPE cur_yylloc;
8085

8186
/* Get next token --- we might already have it */
8287
if (have_lookahead)
8388
{
8489
cur_token = lookahead_token;
90+
base_yylval = lookahead_yylval;
91+
base_yylloc = lookahead_yylloc;
8592
have_lookahead = false;
8693
}
8794
else
@@ -102,8 +109,10 @@ filtered_base_yylex(void)
102109
* (perhaps for SQL99 recursive queries), come back and simplify
103110
* this code.
104111
*/
105-
lookahead_token = base_yylex();
106-
switch (lookahead_token)
112+
cur_yylval = base_yylval;
113+
cur_yylloc = base_yylloc;
114+
next_token = base_yylex();
115+
switch (next_token)
107116
{
108117
case CASCADED:
109118
cur_token = WITH_CASCADED;
@@ -115,7 +124,14 @@ filtered_base_yylex(void)
115124
cur_token = WITH_CHECK;
116125
break;
117126
default:
127+
/* save the lookahead token for next time */
128+
lookahead_token = next_token;
129+
lookahead_yylval = base_yylval;
130+
lookahead_yylloc = base_yylloc;
118131
have_lookahead = true;
132+
/* and back up the output info to cur_token */
133+
base_yylval = cur_yylval;
134+
base_yylloc = cur_yylloc;
119135
break;
120136
}
121137
break;

0 commit comments

Comments
 (0)