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 220 of file parser.c.

221 {
222  if (isxdigit(escape)
223  || escape == '+'
224  || escape == '\''
225  || escape == '"'
226  || ecpg_isspace(escape))
227  return false;
228  else
229  return true;
230 }
static bool ecpg_isspace(char ch)
Definition: parser.c:236

References ecpg_isspace().

Referenced by filtered_base_yylex().

◆ ecpg_isspace()

static bool ecpg_isspace ( char  ch)
static

Definition at line 236 of file parser.c.

237 {
238  if (ch == ' ' ||
239  ch == '\t' ||
240  ch == '\n' ||
241  ch == '\r' ||
242  ch == '\f')
243  return true;
244  return false;
245 }

Referenced by check_uescapechar().

◆ filtered_base_yylex()

int filtered_base_yylex ( void  )

Definition at line 56 of file parser.c.

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  case WITHOUT:
87  break;
88  default:
89  return cur_token;
90  }
91 
92  /* Save and restore lexer output variables around the call */
93  cur_yylval = base_yylval;
94  cur_yylloc = base_yylloc;
95  cur_yytext = base_yytext;
96 
97  /* Get next token, saving outputs into lookahead variables */
99 
101  lookahead_yylval = base_yylval;
102  lookahead_yylloc = base_yylloc;
104 
105  base_yylval = cur_yylval;
106  base_yylloc = cur_yylloc;
107  base_yytext = cur_yytext;
108 
109  have_lookahead = true;
110 
111  /* Replace cur_token if needed, based on lookahead */
112  switch (cur_token)
113  {
114  case NOT:
115  /* Replace NOT by NOT_LA if it's followed by BETWEEN, IN, etc */
116  switch (next_token)
117  {
118  case BETWEEN:
119  case IN_P:
120  case LIKE:
121  case ILIKE:
122  case SIMILAR:
123  cur_token = NOT_LA;
124  break;
125  }
126  break;
127 
128  case NULLS_P:
129  /* Replace NULLS_P by NULLS_LA if it's followed by FIRST or LAST */
130  switch (next_token)
131  {
132  case FIRST_P:
133  case LAST_P:
134  cur_token = NULLS_LA;
135  break;
136  }
137  break;
138 
139  case WITH:
140  /* Replace WITH by WITH_LA if it's followed by TIME or ORDINALITY */
141  switch (next_token)
142  {
143  case TIME:
144  case ORDINALITY:
145  cur_token = WITH_LA;
146  break;
147  case UNIQUE:
148  cur_token = WITH_LA_UNIQUE;
149  break;
150  }
151  break;
152 
153  case WITHOUT:
154  /* Replace WITHOUT by WITHOUT_LA if it's followed by TIME */
155  switch (next_token)
156  {
157  case TIME:
158  cur_token = WITHOUT_LA;
159  break;
160  }
161  break;
162  case UIDENT:
163  case USCONST:
164  /* Look ahead for UESCAPE */
165  if (next_token == UESCAPE)
166  {
167  /* Yup, so get third token, which had better be SCONST */
168  const char *escstr;
169 
170  /*
171  * Again save and restore lexer output variables around the
172  * call
173  */
174  cur_yylval = base_yylval;
175  cur_yylloc = base_yylloc;
176  cur_yytext = base_yytext;
177 
178  /* Get third token */
180 
181  if (next_token != SCONST)
182  mmerror(PARSE_ERROR, ET_ERROR, "UESCAPE must be followed by a simple string literal");
183 
184  /*
185  * Save and check escape string, which the scanner returns
186  * with quotes
187  */
188  escstr = base_yylval.str;
189  if (strlen(escstr) != 3 || !check_uescapechar(escstr[1]))
190  mmerror(PARSE_ERROR, ET_ERROR, "invalid Unicode escape character");
191 
192  base_yylval = cur_yylval;
193  base_yylloc = cur_yylloc;
194  base_yytext = cur_yytext;
195 
196  /* Combine 3 tokens into 1 */
197  base_yylval.str = psprintf("%s UESCAPE %s", base_yylval.str, escstr);
198 
199  /* Clear have_lookahead, thereby consuming all three tokens */
200  have_lookahead = false;
201  }
202 
203  if (cur_token == UIDENT)
204  cur_token = IDENT;
205  else if (cur_token == USCONST)
206  cur_token = SCONST;
207  break;
208  }
209 
210  return cur_token;
211 }
int base_yylex(YYSTYPE *lvalp, YYLTYPE *llocp, core_yyscan_t yyscanner)
Definition: parser.c:111
static bool next_token(char **lineptr, char *buf, int bufsz, bool *initial_quote, bool *terminating_comma, int elevel, char **err_msg)
Definition: hba.c:169
static YYLTYPE lookahead_yylloc
Definition: parser.c:31
static bool have_lookahead
Definition: parser.c:28
static int lookahead_token
Definition: parser.c:29
static YYSTYPE lookahead_yylval
Definition: parser.c:30
static char * lookahead_yytext
Definition: parser.c:32
static bool check_uescapechar(unsigned char escape)
Definition: parser.c:220
#define PARSE_ERROR
char * base_yytext
void mmerror(int errorcode, enum errortype type, const char *error,...) pg_attribute_printf(3
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
#define YYLTYPE
Definition: scanner.h:44
@ ET_ERROR
Definition: type.h:201

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.

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().