PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
gramparse.h File Reference
#include "nodes/parsenodes.h"
#include "parser/scanner.h"
#include "parser/gram.h"
Include dependency graph for gramparse.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  base_yy_extra_type
 

Macros

#define pg_yyget_extra(yyscanner)   (*((base_yy_extra_type **) (yyscanner)))
 

Typedefs

typedef struct base_yy_extra_type base_yy_extra_type
 

Functions

int base_yylex (YYSTYPE *lvalp, YYLTYPE *llocp, core_yyscan_t yyscanner)
 
void parser_init (base_yy_extra_type *yyext)
 
int base_yyparse (core_yyscan_t yyscanner)
 

Macro Definition Documentation

#define pg_yyget_extra (   yyscanner)    (*((base_yy_extra_type **) (yyscanner)))

Definition at line 64 of file gramparse.h.

Referenced by base_yylex().

Typedef Documentation

Function Documentation

int base_yylex ( YYSTYPE *  lvalp,
YYLTYPE llocp,
core_yyscan_t  yyscanner 
)

Definition at line 83 of file parser.c.

References Assert, base_yy_extra_type::core_yy_extra, core_yylex(), base_yy_extra_type::have_lookahead, base_yy_extra_type::lookahead_end, base_yy_extra_type::lookahead_hold_char, base_yy_extra_type::lookahead_token, base_yy_extra_type::lookahead_yylloc, base_yy_extra_type::lookahead_yylval, next_token(), pg_yyget_extra, core_yy_extra_type::scanbuf, and YYLTYPE.

Referenced by filtered_base_yylex().

84 {
86  int cur_token;
87  int next_token;
88  int cur_token_length;
89  YYLTYPE cur_yylloc;
90 
91  /* Get next token --- we might already have it */
92  if (yyextra->have_lookahead)
93  {
94  cur_token = yyextra->lookahead_token;
95  lvalp->core_yystype = yyextra->lookahead_yylval;
96  *llocp = yyextra->lookahead_yylloc;
97  *(yyextra->lookahead_end) = yyextra->lookahead_hold_char;
98  yyextra->have_lookahead = false;
99  }
100  else
101  cur_token = core_yylex(&(lvalp->core_yystype), llocp, yyscanner);
102 
103  /*
104  * If this token isn't one that requires lookahead, just return it. If it
105  * does, determine the token length. (We could get that via strlen(), but
106  * since we have such a small set of possibilities, hardwiring seems
107  * feasible and more efficient.)
108  */
109  switch (cur_token)
110  {
111  case NOT:
112  cur_token_length = 3;
113  break;
114  case NULLS_P:
115  cur_token_length = 5;
116  break;
117  case WITH:
118  cur_token_length = 4;
119  break;
120  default:
121  return cur_token;
122  }
123 
124  /*
125  * Identify end+1 of current token. core_yylex() has temporarily stored a
126  * '\0' here, and will undo that when we call it again. We need to redo
127  * it to fully revert the lookahead call for error reporting purposes.
128  */
129  yyextra->lookahead_end = yyextra->core_yy_extra.scanbuf +
130  *llocp + cur_token_length;
131  Assert(*(yyextra->lookahead_end) == '\0');
132 
133  /*
134  * Save and restore *llocp around the call. It might look like we could
135  * avoid this by just passing &lookahead_yylloc to core_yylex(), but that
136  * does not work because flex actually holds onto the last-passed pointer
137  * internally, and will use that for error reporting. We need any error
138  * reports to point to the current token, not the next one.
139  */
140  cur_yylloc = *llocp;
141 
142  /* Get next token, saving outputs into lookahead variables */
143  next_token = core_yylex(&(yyextra->lookahead_yylval), llocp, yyscanner);
144  yyextra->lookahead_token = next_token;
145  yyextra->lookahead_yylloc = *llocp;
146 
147  *llocp = cur_yylloc;
148 
149  /* Now revert the un-truncation of the current token */
150  yyextra->lookahead_hold_char = *(yyextra->lookahead_end);
151  *(yyextra->lookahead_end) = '\0';
152 
153  yyextra->have_lookahead = true;
154 
155  /* Replace cur_token if needed, based on lookahead */
156  switch (cur_token)
157  {
158  case NOT:
159  /* Replace NOT by NOT_LA if it's followed by BETWEEN, IN, etc */
160  switch (next_token)
161  {
162  case BETWEEN:
163  case IN_P:
164  case LIKE:
165  case ILIKE:
166  case SIMILAR:
167  cur_token = NOT_LA;
168  break;
169  }
170  break;
171 
172  case NULLS_P:
173  /* Replace NULLS_P by NULLS_LA if it's followed by FIRST or LAST */
174  switch (next_token)
175  {
176  case FIRST_P:
177  case LAST_P:
178  cur_token = NULLS_LA;
179  break;
180  }
181  break;
182 
183  case WITH:
184  /* Replace WITH by WITH_LA if it's followed by TIME or ORDINALITY */
185  switch (next_token)
186  {
187  case TIME:
188  case ORDINALITY:
189  cur_token = WITH_LA;
190  break;
191  }
192  break;
193  }
194 
195  return cur_token;
196 }
char * lookahead_end
Definition: gramparse.h:49
core_YYSTYPE lookahead_yylval
Definition: gramparse.h:47
core_yy_extra_type core_yy_extra
Definition: gramparse.h:40
static bool next_token(char **lineptr, char *buf, int bufsz, bool *initial_quote, bool *terminating_comma, int elevel, char **err_msg)
Definition: hba.c:194
char * scanbuf
Definition: scanner.h:72
#define YYLTYPE
Definition: scanner.h:44
int core_yylex(core_YYSTYPE *lvalp, YYLTYPE *llocp, core_yyscan_t yyscanner)
#define pg_yyget_extra(yyscanner)
Definition: gramparse.h:64
#define Assert(condition)
Definition: c.h:671
YYLTYPE lookahead_yylloc
Definition: gramparse.h:48
char lookahead_hold_char
Definition: gramparse.h:50
static core_yyscan_t yyscanner
Definition: pl_scanner.c:208
int base_yyparse ( core_yyscan_t  yyscanner)

Referenced by main(), and raw_parser().

void parser_init ( base_yy_extra_type yyext)

Referenced by raw_parser().