1996-11-08 21:46:33 +01:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* gramparse.h
|
2009-07-12 19:12:34 +02:00
|
|
|
* Shared definitions for the "raw" parser (flex and bison phases only)
|
|
|
|
*
|
|
|
|
* NOTE: this file is only meant to be included in the core parsing files,
|
2022-08-18 04:45:05 +02:00
|
|
|
* i.e., parser.c, gram.y, and scan.l.
|
2016-03-24 01:22:08 +01:00
|
|
|
* Definitions that are needed outside the core parser should be in parser.h.
|
2000-09-12 23:07:18 +02:00
|
|
|
*
|
1996-11-08 21:46:33 +01:00
|
|
|
*
|
2022-01-08 01:04:57 +01:00
|
|
|
* Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-11-08 21:46:33 +01:00
|
|
|
*
|
2010-09-20 22:08:53 +02:00
|
|
|
* src/include/parser/gramparse.h
|
1996-11-08 21:46:33 +01:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GRAMPARSE_H
|
2000-09-12 23:07:18 +02:00
|
|
|
#define GRAMPARSE_H
|
1996-11-08 21:46:33 +01:00
|
|
|
|
2002-05-03 02:32:19 +02:00
|
|
|
#include "nodes/parsenodes.h"
|
2009-11-09 19:38:48 +01:00
|
|
|
#include "parser/scanner.h"
|
2002-04-20 23:56:15 +02:00
|
|
|
|
2006-03-14 23:48:25 +01:00
|
|
|
/*
|
2009-11-09 19:38:48 +01:00
|
|
|
* NB: include gram.h only AFTER including scanner.h, because scanner.h
|
|
|
|
* is what #defines YYLTYPE.
|
2009-07-12 19:12:34 +02:00
|
|
|
*/
|
|
|
|
#include "parser/gram.h"
|
2006-05-11 21:15:36 +02:00
|
|
|
|
2009-07-13 04:02:20 +02:00
|
|
|
/*
|
|
|
|
* The YY_EXTRA data that a flex scanner allows us to pass around. Private
|
|
|
|
* state needed for raw parsing/lexing goes here.
|
|
|
|
*/
|
|
|
|
typedef struct base_yy_extra_type
|
|
|
|
{
|
|
|
|
/*
|
2009-11-09 19:38:48 +01:00
|
|
|
* Fields used by the core scanner.
|
2009-07-13 04:02:20 +02:00
|
|
|
*/
|
2009-11-09 19:38:48 +01:00
|
|
|
core_yy_extra_type core_yy_extra;
|
2009-07-13 04:02:20 +02:00
|
|
|
|
2009-07-14 22:24:10 +02:00
|
|
|
/*
|
2009-11-09 19:38:48 +01:00
|
|
|
* State variables for base_yylex().
|
2009-07-13 04:02:20 +02:00
|
|
|
*/
|
|
|
|
bool have_lookahead; /* is lookahead info valid? */
|
|
|
|
int lookahead_token; /* one-token lookahead */
|
2009-11-09 19:38:48 +01:00
|
|
|
core_YYSTYPE lookahead_yylval; /* yylval for lookahead token */
|
2009-07-13 04:02:20 +02:00
|
|
|
YYLTYPE lookahead_yylloc; /* yylloc for lookahead token */
|
Improve parser's one-extra-token lookahead mechanism.
There are a couple of places in our grammar that fail to be strict LALR(1),
by requiring more than a single token of lookahead to decide what to do.
Up to now we've dealt with that by using a filter between the lexer and
parser that merges adjacent tokens into one in the places where two tokens
of lookahead are necessary. But that creates a number of user-visible
anomalies, for instance that you can't name a CTE "ordinality" because
"WITH ordinality AS ..." triggers folding of WITH and ORDINALITY into one
token. I realized that there's a better way.
In this patch, we still do the lookahead basically as before, but we never
merge the second token into the first; we replace just the first token by
a special lookahead symbol when one of the lookahead pairs is seen.
This requires a couple extra productions in the grammar, but it involves
fewer special tokens, so that the grammar tables come out a bit smaller
than before. The filter logic is no slower than before, perhaps a bit
faster.
I also fixed the filter logic so that when backing up after a lookahead,
the current token's terminator is correctly restored; this eliminates some
weird behavior in error message issuance, as is shown by the one change in
existing regression test outputs.
I believe that this patch entirely eliminates odd behaviors caused by
lookahead for WITH. It doesn't really improve the situation for NULLS
followed by FIRST/LAST unfortunately: those sequences still act like a
reserved word, even though there are cases where they should be seen as two
ordinary identifiers, eg "SELECT nulls first FROM ...". I experimented
with additional grammar hacks but couldn't find any simple solution for
that. Still, this is better than before, and it seems much more likely
that we *could* somehow solve the NULLS case on the basis of this filter
behavior than the previous one.
2015-02-24 23:53:42 +01:00
|
|
|
char *lookahead_end; /* end of current token */
|
|
|
|
char lookahead_hold_char; /* to be put back at *lookahead_end */
|
2009-07-13 04:02:20 +02:00
|
|
|
|
|
|
|
/*
|
2009-11-09 19:38:48 +01:00
|
|
|
* State variables that belong to the grammar.
|
2009-07-13 04:02:20 +02:00
|
|
|
*/
|
|
|
|
List *parsetree; /* final parse result is delivered here */
|
|
|
|
} base_yy_extra_type;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* In principle we should use yyget_extra() to fetch the yyextra field
|
|
|
|
* from a yyscanner struct. However, flex always puts that field first,
|
|
|
|
* and this is sufficiently performance-critical to make it seem worth
|
|
|
|
* cheating a bit to use an inline macro.
|
|
|
|
*/
|
|
|
|
#define pg_yyget_extra(yyscanner) (*((base_yy_extra_type **) (yyscanner)))
|
|
|
|
|
2006-05-11 21:15:36 +02:00
|
|
|
|
2006-05-27 19:38:46 +02:00
|
|
|
/* from parser.c */
|
2009-07-13 04:02:20 +02:00
|
|
|
extern int base_yylex(YYSTYPE *lvalp, YYLTYPE *llocp,
|
2009-11-09 19:38:48 +01:00
|
|
|
core_yyscan_t yyscanner);
|
1996-11-08 21:46:33 +01:00
|
|
|
|
|
|
|
/* from gram.y */
|
2009-07-13 04:02:20 +02:00
|
|
|
extern void parser_init(base_yy_extra_type *yyext);
|
2009-11-09 19:38:48 +01:00
|
|
|
extern int base_yyparse(core_yyscan_t yyscanner);
|
2001-10-28 07:26:15 +01:00
|
|
|
|
1996-11-08 21:46:33 +01:00
|
|
|
#endif /* GRAMPARSE_H */
|