PostgreSQL Source Code git master
Loading...
Searching...
No Matches
pgpa_scanner.l File Reference
#include "postgres.h"
#include "common/string.h"
#include "nodes/miscnodes.h"
#include "parser/scansup.h"
#include "pgpa_ast.h"
#include "pgpa_parser.h"

Go to the source code of this file.

Data Structures

struct  pgpa_yy_extra_type
 

Macros

#define YY_DECL
 
#define YY_READ_BUF_SIZE   16777216
 
#define fprintf(file, fmt, msg)   fprintf_to_ereport(fmt, msg)
 

Typedefs

typedef struct pgpa_yy_extra_type pgpa_yy_extra_type
 

Functions

static void fprintf_to_ereport (const char *fmt, const char *msg)
 
int yylex (YYSTYPE *yylval_param, yyscan_t yyscanner)
 
void pgpa_yyerror (List **result, char **parse_error_msg_p, yyscan_t yyscanner, const char *message)
 
void pgpa_scanner_init (const char *str, yyscan_t *yyscannerp)
 
void pgpa_scanner_finish (yyscan_t yyscanner)
 
voidyyalloc (yy_size_t size, yyscan_t yyscanner)
 
voidyyrealloc (void *ptr, yy_size_t size, yyscan_t yyscanner)
 
void yyfree (void *ptr, yyscan_t yyscanner)
 

Macro Definition Documentation

◆ fprintf

#define fprintf (   file,
  fmt,
  msg 
)    fprintf_to_ereport(fmt, msg)

Definition at line 43 of file pgpa_scanner.l.

◆ YY_DECL

#define YY_DECL
Value:
extern int pgpa_yylex(union YYSTYPE *yylval_param, List **result, \
char **parse_error_msg_p, yyscan_t yyscanner)
uint32 result
void * yyscan_t
Definition cubedata.h:65
int pgpa_yylex(union YYSTYPE *yylval_param, List **result, char **parse_error_msg_p, yyscan_t yyscanner)
static int fb(int x)
int YYSTYPE
Definition pg_list.h:54

Definition at line 34 of file pgpa_scanner.l.

◆ YY_READ_BUF_SIZE

#define YY_READ_BUF_SIZE   16777216

Definition at line 39 of file pgpa_scanner.l.

Typedef Documentation

◆ pgpa_yy_extra_type

Function Documentation

◆ fprintf_to_ereport()

static void fprintf_to_ereport ( const char fmt,
const char msg 
)
static

Definition at line 46 of file pgpa_scanner.l.

47{
48 ereport(ERROR, (errmsg_internal("%s", msg)));
int int errmsg_internal(const char *fmt,...) pg_attribute_printf(1
#define ERROR
Definition elog.h:40
#define ereport(elevel,...)
Definition elog.h:152
49}

References ereport, errmsg_internal(), and ERROR.

◆ pgpa_scanner_finish()

void pgpa_scanner_finish ( yyscan_t  yyscanner)

Definition at line 268 of file pgpa_scanner.l.

269{
270 yylex_destroy(yyscanner);
271}

References fb().

◆ pgpa_scanner_init()

void pgpa_scanner_init ( const char str,
yyscan_t yyscannerp 
)

Definition at line 245 of file pgpa_scanner.l.

246{
247 yyscan_t yyscanner;
#define palloc0_object(type)
Definition fe_memutils.h:90
249
250 if (yylex_init(yyscannerp) != 0)
251 elog(ERROR, "yylex_init() failed: %m");
#define elog(elevel,...)
Definition elog.h:228
252
253 yyscanner = *yyscannerp;
254
255 initStringInfo(&yyext->litbuf);
256 pgpa_yyset_extra(yyext, yyscanner);
void initStringInfo(StringInfo str)
Definition stringinfo.c:97
257
258 yy_scan_string(str, yyscanner);
const char * str
259}

References elog, ERROR, fb(), initStringInfo(), palloc0_object, and str.

◆ pgpa_yyerror()

void pgpa_yyerror ( List **  result,
char **  parse_error_msg_p,
yyscan_t  yyscanner,
const char message 
)

Definition at line 222 of file pgpa_scanner.l.

224{
225 struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; /* needed for yytext
226 * macro */
227
228
229 /* report only the first error in a parse operation */
231 return;
232
233 if (yytext[0])
234 *parse_error_msg_p = psprintf("%s at or near \"%s\"", message, yytext);
235 else
236 *parse_error_msg_p = psprintf("%s at end of input", message);
char * psprintf(const char *fmt,...)
Definition psprintf.c:43
237}

References fb(), and psprintf().

◆ yyalloc()

void * yyalloc ( yy_size_t  size,
yyscan_t  yyscanner 
)

Definition at line 279 of file pgpa_scanner.l.

280{
281 return palloc(size);
void * palloc(Size size)
Definition mcxt.c:1390
282}

References palloc().

◆ yyfree()

void yyfree ( void ptr,
yyscan_t  yyscanner 
)

Definition at line 294 of file pgpa_scanner.l.

295{
296 if (ptr)
297 pfree(ptr);
void pfree(void *pointer)
Definition mcxt.c:1619
298}

References pfree().

◆ yylex()

int yylex ( YYSTYPE yylval_param,
yyscan_t  yyscanner 
)

Definition at line 99 of file pgpa_scanner.l.

101{whitespace} { /* ignore */ }
102
103{identifier} {
104 char *str;
105 bool fail;
pgpa_advice_tag_type
Definition pgpa_ast.h:81
107
108 /*
109 * Unlike the core scanner, we don't truncate identifiers
110 * here. There is no obvious reason to do so.
111 */
112 str = downcase_identifier(yytext, yyleng, false, false);
113 yylval->str = str;
#define yyleng
Definition scan.l:1108
char * downcase_identifier(const char *ident, int len, bool warn, bool truncate)
Definition scansup.c:47
114
115 /*
116 * If it's not a tag, just return TOK_IDENT; else, return
117 * a token type based on how further parsing should
118 * proceed.
119 */
121 if (fail)
122 return TOK_IDENT;
123 else if (tag == PGPA_TAG_JOIN_ORDER)
124 return TOK_TAG_JOIN_ORDER;
125 else if (tag == PGPA_TAG_INDEX_SCAN ||
127 return TOK_TAG_INDEX;
128 else if (tag == PGPA_TAG_SEQ_SCAN ||
129 tag == PGPA_TAG_TID_SCAN ||
131 tag == PGPA_TAG_NO_GATHER ||
133 return TOK_TAG_SIMPLE;
134 else
135 return TOK_TAG_GENERIC;
136 }
pgpa_advice_tag_type pgpa_parse_advice_tag(const char *tag, bool *fail)
Definition pgpa_ast.c:87
@ PGPA_TAG_INDEX_SCAN
Definition pgpa_ast.h:89
@ PGPA_TAG_BITMAP_HEAP_SCAN
Definition pgpa_ast.h:82
@ PGPA_TAG_NO_GATHER
Definition pgpa_ast.h:96
@ PGPA_TAG_INDEX_ONLY_SCAN
Definition pgpa_ast.h:88
@ PGPA_TAG_SEQ_SCAN
Definition pgpa_ast.h:100
@ PGPA_TAG_DO_NOT_SCAN
Definition pgpa_ast.h:83
@ PGPA_TAG_JOIN_ORDER
Definition pgpa_ast.h:90
@ PGPA_TAG_TID_SCAN
Definition pgpa_ast.h:101
137
138{decinteger} {
139 char *endptr;
140
141 errno = 0;
142 yylval->integer = strtoint(yytext, &endptr, 10);
143 if (*endptr != '\0' || errno == ERANGE)
145 "integer out of range");
146 return TOK_INTEGER;
147 }
void pgpa_yyerror(List **result, char **parse_error_msg_p, yyscan_t yyscanner, const char *message)
int strtoint(const char *pg_restrict str, char **pg_restrict endptr, int base)
Definition string.c:50
148
149{xcstart} {
150 BEGIN(xc);
151 }
152
153{xdstart} {
154 BEGIN(xd);
155 resetStringInfo(&yyextra->litbuf);
156 }
#define yyextra
Definition scan.l:1102
void resetStringInfo(StringInfo str)
Definition stringinfo.c:126
157
158. { return yytext[0]; }
159
160<xc>{xcstop} {
161 BEGIN(INITIAL);
162 }
163
164<xc>{xcinside} {
165 /* discard multiple characters without slash or asterisk */
166 }
167
168<xc>. {
169 /*
170 * Discard any single character. flex prefers longer
171 * matches, so this rule will never be picked when we could
172 * have matched xcstop.
173 *
174 * NB: At present, we don't bother to support nested
175 * C-style comments here, but this logic could be extended
176 * if that restriction poses a problem.
177 */
178 }
179
180<xc><<EOF>> {
181 BEGIN(INITIAL);
183 "unterminated comment");
184 }
185
186<xd>{xdstop} {
187 BEGIN(INITIAL);
188 if (yyextra->litbuf.len == 0)
190 "zero-length delimited identifier");
191 yylval->str = pstrdup(yyextra->litbuf.data);
192 return TOK_IDENT;
193 }
char * pstrdup(const char *in)
Definition mcxt.c:1910
194
195<xd>{xddouble} {
196 appendStringInfoChar(&yyextra->litbuf, '"');
197 }
void appendStringInfoChar(StringInfo str, char ch)
Definition stringinfo.c:242
198
199<xd>{xdinside} {
201 }
void appendBinaryStringInfo(StringInfo str, const void *data, int datalen)
Definition stringinfo.c:281
202
203<xd><<EOF>> {
204 BEGIN(INITIAL);
206 "unterminated quoted identifier");
207 }
208
209%%

◆ yyrealloc()

void * yyrealloc ( void ptr,
yy_size_t  size,
yyscan_t  yyscanner 
)

Definition at line 285 of file pgpa_scanner.l.

286{
287 if (ptr)
288 return repalloc(ptr, size);
289 else
290 return palloc(size);
void * repalloc(void *pointer, Size size)
Definition mcxt.c:1635
291}

References palloc(), and repalloc().