*** pgsql/src/backend/parser/parser.c 2009/07/12 17:12:34 1.79 --- pgsql/src/backend/parser/parser.c 2009/07/13 02:02:20 1.80 *************** *** 14,20 **** * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION ! * $PostgreSQL: pgsql/src/backend/parser/parser.c,v 1.78 2009/06/11 14:49:00 momjian Exp $ * *------------------------------------------------------------------------- */ --- 14,20 ---- * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION ! * $PostgreSQL: pgsql/src/backend/parser/parser.c,v 1.79 2009/07/12 17:12:34 tgl Exp $ * *------------------------------------------------------------------------- */ *************** *** 25,38 **** #include "parser/parser.h" - List *parsetree; /* result of parsing is left here */ - - 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 */ - - /* * raw_parser * Given a query in string form, do lexical and grammatical analysis. --- 25,30 ---- *************** static YYLTYPE lookahead_yylloc; /* yyll *** 42,63 **** List * raw_parser(const char *str) { int yyresult; ! parsetree = NIL; /* in case grammar forgets to set it */ ! have_lookahead = false; ! scanner_init(str); ! parser_init(); ! yyresult = base_yyparse(); ! scanner_finish(); if (yyresult) /* error */ return NIL; ! return parsetree; } --- 34,62 ---- List * raw_parser(const char *str) { + base_yyscan_t yyscanner; + base_yy_extra_type yyextra; int yyresult; ! /* initialize the flex scanner */ ! yyscanner = scanner_init(str, &yyextra); ! ! /* filtered_base_yylex() only needs this much initialization */ ! yyextra.have_lookahead = false; ! /* initialize the bison parser */ ! parser_init(&yyextra); ! /* Parse! */ ! yyresult = base_yyparse(yyscanner); ! /* Clean up (release memory) */ ! scanner_finish(yyscanner); if (yyresult) /* error */ return NIL; ! return yyextra.parsetree; } *************** raw_parser(const char *str) *** 69,93 **** * passed string does represent one single string literal. * * We export this function to avoid having plpgsql depend on internal details ! * of the core grammar (such as the token code assigned to SCONST). Note ! * that since the scanner isn't presently re-entrant, this cannot be used ! * during use of the main parser/scanner. */ char * pg_parse_string_token(const char *token) { int ctoken; ! scanner_init(token); ! ctoken = base_yylex(); if (ctoken != SCONST) /* caller error */ elog(ERROR, "expected string constant, got token code %d", ctoken); ! scanner_finish(); ! return base_yylval.str; } --- 68,94 ---- * passed string does represent one single string literal. * * We export this function to avoid having plpgsql depend on internal details ! * of the core grammar (such as the token code assigned to SCONST). */ char * pg_parse_string_token(const char *token) { + base_yyscan_t yyscanner; + base_yy_extra_type yyextra; int ctoken; + YYSTYPE yylval; + YYLTYPE yylloc; ! yyscanner = scanner_init(token, &yyextra); ! ctoken = base_yylex(&yylval, &yylloc, yyscanner); if (ctoken != SCONST) /* caller error */ elog(ERROR, "expected string constant, got token code %d", ctoken); ! scanner_finish(yyscanner); ! return yylval.str; } *************** pg_parse_string_token(const char *token) *** 105,127 **** * layer does. */ 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 ! cur_token = base_yylex(); /* Do we need to look ahead for a possible multiword token? */ switch (cur_token) --- 106,129 ---- * layer does. */ int ! filtered_base_yylex(YYSTYPE *lvalp, YYLTYPE *llocp, base_yyscan_t yyscanner) { + base_yy_extra_type *yyextra = pg_yyget_extra(yyscanner); int cur_token; int next_token; YYSTYPE cur_yylval; YYLTYPE cur_yylloc; /* Get next token --- we might already have it */ ! if (yyextra->have_lookahead) { ! cur_token = yyextra->lookahead_token; ! *lvalp = yyextra->lookahead_yylval; ! *llocp = yyextra->lookahead_yylloc; ! yyextra->have_lookahead = false; } else ! cur_token = base_yylex(lvalp, llocp, yyscanner); /* Do we need to look ahead for a possible multiword token? */ switch (cur_token) *************** filtered_base_yylex(void) *** 131,139 **** /* * NULLS FIRST and NULLS LAST must be reduced to one token */ ! cur_yylval = base_yylval; ! cur_yylloc = base_yylloc; ! next_token = base_yylex(); switch (next_token) { case FIRST_P: --- 133,141 ---- /* * NULLS FIRST and NULLS LAST must be reduced to one token */ ! cur_yylval = *lvalp; ! cur_yylloc = *llocp; ! next_token = base_yylex(lvalp, llocp, yyscanner); switch (next_token) { case FIRST_P: *************** filtered_base_yylex(void) *** 144,156 **** 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; --- 146,158 ---- break; default: /* save the lookahead token for next time */ ! yyextra->lookahead_token = next_token; ! yyextra->lookahead_yylval = *lvalp; ! yyextra->lookahead_yylloc = *llocp; ! yyextra->have_lookahead = true; /* and back up the output info to cur_token */ ! *lvalp = cur_yylval; ! *llocp = cur_yylloc; break; } break; *************** filtered_base_yylex(void) *** 160,168 **** /* * WITH TIME must be reduced to one token */ ! cur_yylval = base_yylval; ! cur_yylloc = base_yylloc; ! next_token = base_yylex(); switch (next_token) { case TIME: --- 162,170 ---- /* * WITH TIME must be reduced to one token */ ! cur_yylval = *lvalp; ! cur_yylloc = *llocp; ! next_token = base_yylex(lvalp, llocp, yyscanner); switch (next_token) { case TIME: *************** filtered_base_yylex(void) *** 170,182 **** 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; --- 172,184 ---- break; default: /* save the lookahead token for next time */ ! yyextra->lookahead_token = next_token; ! yyextra->lookahead_yylval = *lvalp; ! yyextra->lookahead_yylloc = *llocp; ! yyextra->have_lookahead = true; /* and back up the output info to cur_token */ ! *lvalp = cur_yylval; ! *llocp = cur_yylloc; break; } break;