PostgreSQL Source Code git master
Loading...
Searching...
No Matches
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 int base_yylex_location (void)
 
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 charlookahead_yytext
 

Function Documentation

◆ base_yylex_location()

static int base_yylex_location ( void  )
static

Definition at line 239 of file parser.c.

240{
241 int token = base_yylex();
242
243 switch (token)
244 {
245 /* List a token here if pgc.l assigns to base_yylval.str for it */
246 case Op:
247 case CSTRING:
248 case CPP_LINE:
249 case CVARIABLE:
250 case BCONST:
251 case SCONST:
252 case USCONST:
253 case XCONST:
254 case FCONST:
255 case IDENT:
256 case UIDENT:
257 case IP:
258 /* Duplicate the <str> value */
260 break;
261 default:
262 /* Else just use the input, i.e., yytext */
264 /* Apply an ASCII-only downcasing */
265 for (unsigned char *ptr = (unsigned char *) base_yylloc; *ptr; ptr++)
266 {
267 if (*ptr >= 'A' && *ptr <= 'Z')
268 *ptr += 'a' - 'A';
269 }
270 break;
271 }
272 return token;
273}
static uint8 IP[64]
Definition crypt-des.c:74
#define token
YYSTYPE base_yylval
static int fb(int x)
int base_yylex(void)
char * base_yytext
char * loc_strdup(const char *string)
Definition util.c:170

References base_yylex(), base_yylval, base_yytext, fb(), IP, loc_strdup(), and token.

Referenced by filtered_base_yylex().

◆ check_uescapechar()

static bool check_uescapechar ( unsigned char  escape)
static

Definition at line 282 of file parser.c.

283{
284 if (isxdigit(escape)
285 || escape == '+'
286 || escape == '\''
287 || escape == '"'
288 || ecpg_isspace(escape))
289 return false;
290 else
291 return true;
292}
static bool ecpg_isspace(char ch)
Definition parser.c:298

References ecpg_isspace(), and fb().

◆ ecpg_isspace()

static bool ecpg_isspace ( char  ch)
static

Definition at line 298 of file parser.c.

299{
300 if (ch == ' ' ||
301 ch == '\t' ||
302 ch == '\n' ||
303 ch == '\r' ||
304 ch == '\f')
305 return true;
306 return false;
307}

References fb().

Referenced by check_uescapechar().

◆ filtered_base_yylex()

int filtered_base_yylex ( void  )

Definition at line 57 of file parser.c.

58{
59 int cur_token;
60 int next_token;
63 char *cur_yytext;
64
65 /* Get next token --- we might already have it */
67 {
72 have_lookahead = false;
73 }
74 else
76
77 /*
78 * If this token isn't one that requires lookahead, just return it.
79 */
80 switch (cur_token)
81 {
82 case FORMAT:
83 case NOT:
84 case NULLS_P:
85 case WITH:
86 case WITHOUT:
87 case UIDENT:
88 case USCONST:
89 break;
90 default:
91 return cur_token;
92 }
93
94 /* Save and restore lexer output variables around the call */
98
99 /* Get next token, saving outputs into lookahead variables */
101
106
110
111 have_lookahead = true;
112
113 /* Replace cur_token if needed, based on lookahead */
114 switch (cur_token)
115 {
116 case FORMAT:
117 /* Replace FORMAT by FORMAT_LA if it's followed by JSON */
118 switch (next_token)
119 {
120 case JSON:
122 break;
123 }
124 break;
125
126 case NOT:
127 /* Replace NOT by NOT_LA if it's followed by BETWEEN, IN, etc */
128 switch (next_token)
129 {
130 case BETWEEN:
131 case IN_P:
132 case LIKE:
133 case ILIKE:
134 case SIMILAR:
136 break;
137 }
138 break;
139
140 case NULLS_P:
141 /* Replace NULLS_P by NULLS_LA if it's followed by FIRST or LAST */
142 switch (next_token)
143 {
144 case FIRST_P:
145 case LAST_P:
147 break;
148 }
149 break;
150
151 case WITH:
152 /* Replace WITH by WITH_LA if it's followed by TIME or ORDINALITY */
153 switch (next_token)
154 {
155 case TIME:
156 case ORDINALITY:
158 break;
159 }
160 break;
161
162 case WITHOUT:
163 /* Replace WITHOUT by WITHOUT_LA if it's followed by TIME */
164 switch (next_token)
165 {
166 case TIME:
168 break;
169 }
170 break;
171 case UIDENT:
172 case USCONST:
173 /* Look ahead for UESCAPE */
174 if (next_token == UESCAPE)
175 {
176 /* Yup, so get third token, which had better be SCONST */
177 const char *escstr;
178
179 /*
180 * Again save and restore lexer output variables around the
181 * call
182 */
186
187 /* Get third token */
189
190 if (next_token != SCONST)
191 mmerror(PARSE_ERROR, ET_ERROR, "UESCAPE must be followed by a simple string literal");
192
193 /*
194 * Save and check escape string, which the scanner returns
195 * with quotes
196 */
197 escstr = base_yylval.str;
198 if (strlen(escstr) != 3 || !check_uescapechar(escstr[1]))
199 mmerror(PARSE_ERROR, ET_ERROR, "invalid Unicode escape character");
200
204
205 /* Combine 3 tokens into 1 */
207 " UESCAPE ",
208 escstr);
210
211 /* Clear have_lookahead, thereby consuming all three tokens */
212 have_lookahead = false;
213 }
214
215 if (cur_token == UIDENT)
217 else if (cur_token == USCONST)
219 break;
220 }
221
222 return cur_token;
223}
static bool check_uescapechar(unsigned char escape)
Definition parser.c:352
static bool next_token(char **lineptr, StringInfo buf, bool *initial_quote, bool *terminating_comma)
Definition hba.c:184
static YYLTYPE lookahead_yylloc
Definition parser.c:31
static int base_yylex_location(void)
Definition parser.c:239
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
const char * YYLTYPE
void mmerror(int error_code, enum errortype type, const char *error,...) pg_attribute_printf(3
#define PARSE_ERROR
char * make3_str(const char *str1, const char *str2, const char *str3)
Definition util.c:256
int YYSTYPE
@ ET_ERROR
Definition type.h:220

References base_yylex_location(), base_yylval, base_yytext, check_uescapechar(), ET_ERROR, fb(), have_lookahead, loc_strdup(), lookahead_token, lookahead_yylloc, lookahead_yylval, lookahead_yytext, make3_str(), mmerror(), next_token(), and PARSE_ERROR.

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