PostgreSQL Source Code  git master
parser.c File Reference
#include "postgres_fe.h"
#include "preproc_extern.h"
#include "preproc.h"
Include dependency graph for parser.c:

Go to the source code of this file.

Functions

static bool check_uescapechar (unsigned char escape)
 
static bool ecpg_isspace (char ch)
 
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
 

Function Documentation

◆ check_uescapechar()

static bool check_uescapechar ( unsigned char  escape)
static

Definition at line 206 of file parser.c.

References ecpg_isspace().

Referenced by filtered_base_yylex().

207 {
208  if (isxdigit(escape)
209  || escape == '+'
210  || escape == '\''
211  || escape == '"'
212  || ecpg_isspace(escape))
213  return false;
214  else
215  return true;
216 }
static bool ecpg_isspace(char ch)
Definition: parser.c:222

◆ ecpg_isspace()

static bool ecpg_isspace ( char  ch)
static

Definition at line 222 of file parser.c.

Referenced by check_uescapechar().

223 {
224  if (ch == ' ' ||
225  ch == '\t' ||
226  ch == '\n' ||
227  ch == '\r' ||
228  ch == '\f')
229  return true;
230  return false;
231 }

◆ filtered_base_yylex()

int filtered_base_yylex ( void  )

Definition at line 56 of file parser.c.

References base_yylex(), base_yytext, check_uescapechar(), ET_ERROR, have_lookahead, lookahead_token, lookahead_yylloc, lookahead_yylval, lookahead_yytext, mmerror(), next_token(), PARSE_ERROR, psprintf(), and YYLTYPE.

57 {
58  int cur_token;
59  int next_token;
60  YYSTYPE cur_yylval;
61  YYLTYPE cur_yylloc;
62  char *cur_yytext;
63 
64  /* Get next token --- we might already have it */
65  if (have_lookahead)
66  {
67  cur_token = lookahead_token;
68  base_yylval = lookahead_yylval;
69  base_yylloc = lookahead_yylloc;
71  have_lookahead = false;
72  }
73  else
74  cur_token = base_yylex();
75 
76  /*
77  * If this token isn't one that requires lookahead, just return it.
78  */
79  switch (cur_token)
80  {
81  case NOT:
82  case NULLS_P:
83  case WITH:
84  case UIDENT:
85  case USCONST:
86  break;
87  default:
88  return cur_token;
89  }
90 
91  /* Save and restore lexer output variables around the call */
92  cur_yylval = base_yylval;
93  cur_yylloc = base_yylloc;
94  cur_yytext = base_yytext;
95 
96  /* Get next token, saving outputs into lookahead variables */
97  next_token = base_yylex();
98 
100  lookahead_yylval = base_yylval;
101  lookahead_yylloc = base_yylloc;
103 
104  base_yylval = cur_yylval;
105  base_yylloc = cur_yylloc;
106  base_yytext = cur_yytext;
107 
108  have_lookahead = true;
109 
110  /* Replace cur_token if needed, based on lookahead */
111  switch (cur_token)
112  {
113  case NOT:
114  /* Replace NOT by NOT_LA if it's followed by BETWEEN, IN, etc */
115  switch (next_token)
116  {
117  case BETWEEN:
118  case IN_P:
119  case LIKE:
120  case ILIKE:
121  case SIMILAR:
122  cur_token = NOT_LA;
123  break;
124  }
125  break;
126 
127  case NULLS_P:
128  /* Replace NULLS_P by NULLS_LA if it's followed by FIRST or LAST */
129  switch (next_token)
130  {
131  case FIRST_P:
132  case LAST_P:
133  cur_token = NULLS_LA;
134  break;
135  }
136  break;
137 
138  case WITH:
139  /* Replace WITH by WITH_LA if it's followed by TIME or ORDINALITY */
140  switch (next_token)
141  {
142  case TIME:
143  case ORDINALITY:
144  cur_token = WITH_LA;
145  break;
146  }
147  break;
148  case UIDENT:
149  case USCONST:
150  /* Look ahead for UESCAPE */
151  if (next_token == UESCAPE)
152  {
153  /* Yup, so get third token, which had better be SCONST */
154  const char *escstr;
155 
156  /*
157  * Again save and restore lexer output variables around the
158  * call
159  */
160  cur_yylval = base_yylval;
161  cur_yylloc = base_yylloc;
162  cur_yytext = base_yytext;
163 
164  /* Get third token */
165  next_token = base_yylex();
166 
167  if (next_token != SCONST)
168  mmerror(PARSE_ERROR, ET_ERROR, "UESCAPE must be followed by a simple string literal");
169 
170  /*
171  * Save and check escape string, which the scanner returns
172  * with quotes
173  */
174  escstr = base_yylval.str;
175  if (strlen(escstr) != 3 || !check_uescapechar(escstr[1]))
176  mmerror(PARSE_ERROR, ET_ERROR, "invalid Unicode escape character");
177 
178  base_yylval = cur_yylval;
179  base_yylloc = cur_yylloc;
180  base_yytext = cur_yytext;
181 
182  /* Combine 3 tokens into 1 */
183  base_yylval.str = psprintf("%s UESCAPE %s", base_yylval.str, escstr);
184 
185  /* Clear have_lookahead, thereby consuming all three tokens */
186  have_lookahead = false;
187  }
188 
189  if (cur_token == UIDENT)
190  cur_token = IDENT;
191  else if (cur_token == USCONST)
192  cur_token = SCONST;
193  break;
194  }
195 
196  return cur_token;
197 }
Definition: type.h:194
static bool have_lookahead
Definition: parser.c:28
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
static bool next_token(char **lineptr, char *buf, int bufsz, bool *initial_quote, bool *terminating_comma, int elevel, char **err_msg)
Definition: hba.c:195
char * base_yytext
#define PARSE_ERROR
static char * lookahead_yytext
Definition: parser.c:32
#define YYLTYPE
Definition: scanner.h:44
int base_yylex(YYSTYPE *lvalp, YYLTYPE *llocp, core_yyscan_t yyscanner)
Definition: parser.c:93
static YYLTYPE lookahead_yylloc
Definition: parser.c:31
void mmerror(int errorcode, enum errortype type, const char *error,...) pg_attribute_printf(3
static bool check_uescapechar(unsigned char escape)
Definition: parser.c:206
static int lookahead_token
Definition: parser.c:29
static YYSTYPE lookahead_yylval
Definition: parser.c:30

Variable Documentation

◆ have_lookahead

bool have_lookahead
static

Definition at line 28 of file parser.c.

Referenced by filtered_base_yylex().

◆ lookahead_token

int lookahead_token
static

Definition at line 29 of file parser.c.

Referenced by filtered_base_yylex().

◆ lookahead_yylloc

YYLTYPE lookahead_yylloc
static

Definition at line 31 of file parser.c.

Referenced by filtered_base_yylex().

◆ lookahead_yylval

YYSTYPE lookahead_yylval
static

Definition at line 30 of file parser.c.

Referenced by filtered_base_yylex().

◆ lookahead_yytext

char* lookahead_yytext
static

Definition at line 32 of file parser.c.

Referenced by filtered_base_yylex().