PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
parser.c File Reference
#include "postgres_fe.h"
#include "extern.h"
#include "preproc.h"
Include dependency graph for parser.c:

Go to the source code of this file.

Functions

int filtered_base_yylex (void)
 

Variables

static bool have_lookahead
 
static int lookahead_token
 
static YYSTYPE lookahead_yylval
 
static YYLTYPE lookahead_yylloc
 
static char * lookahead_yytext
 
static char * lookahead_end
 
static char lookahead_hold_char
 

Function Documentation

int filtered_base_yylex ( void  )

Definition at line 48 of file parser.c.

References Assert, base_yylex(), base_yytext, have_lookahead, lookahead_end, lookahead_hold_char, lookahead_token, lookahead_yylloc, lookahead_yylval, lookahead_yytext, next_token(), and YYLTYPE.

49 {
50  int cur_token;
51  int next_token;
52  int cur_token_length;
53  YYSTYPE cur_yylval;
54  YYLTYPE cur_yylloc;
55  char *cur_yytext;
56 
57  /* Get next token --- we might already have it */
58  if (have_lookahead)
59  {
60  cur_token = lookahead_token;
61  base_yylval = lookahead_yylval;
62  base_yylloc = lookahead_yylloc;
65  have_lookahead = false;
66  }
67  else
68  cur_token = base_yylex();
69 
70  /*
71  * If this token isn't one that requires lookahead, just return it. If it
72  * does, determine the token length. (We could get that via strlen(), but
73  * since we have such a small set of possibilities, hardwiring seems
74  * feasible and more efficient.)
75  */
76  switch (cur_token)
77  {
78  case NOT:
79  cur_token_length = 3;
80  break;
81  case NULLS_P:
82  cur_token_length = 5;
83  break;
84  case WITH:
85  cur_token_length = 4;
86  break;
87  default:
88  return cur_token;
89  }
90 
91  /*
92  * Identify end+1 of current token. base_yylex() has temporarily stored a
93  * '\0' here, and will undo that when we call it again. We need to redo
94  * it to fully revert the lookahead call for error reporting purposes.
95  */
96  lookahead_end = base_yytext + cur_token_length;
97  Assert(*lookahead_end == '\0');
98 
99  /* Save and restore lexer output variables around the call */
100  cur_yylval = base_yylval;
101  cur_yylloc = base_yylloc;
102  cur_yytext = base_yytext;
103 
104  /* Get next token, saving outputs into lookahead variables */
105  next_token = base_yylex();
106 
108  lookahead_yylval = base_yylval;
109  lookahead_yylloc = base_yylloc;
111 
112  base_yylval = cur_yylval;
113  base_yylloc = cur_yylloc;
114  base_yytext = cur_yytext;
115 
116  /* Now revert the un-truncation of the current token */
118  *lookahead_end = '\0';
119 
120  have_lookahead = true;
121 
122  /* Replace cur_token if needed, based on lookahead */
123  switch (cur_token)
124  {
125  case NOT:
126  /* Replace NOT by NOT_LA if it's followed by BETWEEN, IN, etc */
127  switch (next_token)
128  {
129  case BETWEEN:
130  case IN_P:
131  case LIKE:
132  case ILIKE:
133  case SIMILAR:
134  cur_token = NOT_LA;
135  break;
136  }
137  break;
138 
139  case NULLS_P:
140  /* Replace NULLS_P by NULLS_LA if it's followed by FIRST or LAST */
141  switch (next_token)
142  {
143  case FIRST_P:
144  case LAST_P:
145  cur_token = NULLS_LA;
146  break;
147  }
148  break;
149 
150  case WITH:
151  /* Replace WITH by WITH_LA if it's followed by TIME or ORDINALITY */
152  switch (next_token)
153  {
154  case TIME:
155  case ORDINALITY:
156  cur_token = WITH_LA;
157  break;
158  }
159  break;
160  }
161 
162  return cur_token;
163 }
static char lookahead_hold_char
Definition: parser.c:31
static bool have_lookahead
Definition: parser.c:25
static char * lookahead_end
Definition: parser.c:30
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
static char * lookahead_yytext
Definition: parser.c:29
#define YYLTYPE
Definition: scanner.h:44
int base_yylex(YYSTYPE *lvalp, YYLTYPE *llocp, core_yyscan_t yyscanner)
Definition: parser.c:83
static YYLTYPE lookahead_yylloc
Definition: parser.c:28
#define Assert(condition)
Definition: c.h:671
char * base_yytext
static int lookahead_token
Definition: parser.c:26
static YYSTYPE lookahead_yylval
Definition: parser.c:27

Variable Documentation

bool have_lookahead
static

Definition at line 25 of file parser.c.

Referenced by filtered_base_yylex().

char* lookahead_end
static

Definition at line 30 of file parser.c.

Referenced by filtered_base_yylex().

char lookahead_hold_char
static

Definition at line 31 of file parser.c.

Referenced by filtered_base_yylex().

int lookahead_token
static

Definition at line 26 of file parser.c.

Referenced by filtered_base_yylex().

YYLTYPE lookahead_yylloc
static

Definition at line 28 of file parser.c.

Referenced by filtered_base_yylex().

YYSTYPE lookahead_yylval
static

Definition at line 27 of file parser.c.

Referenced by filtered_base_yylex().

char* lookahead_yytext
static

Definition at line 29 of file parser.c.

Referenced by filtered_base_yylex().