PostgreSQL Source Code git master
Loading...
Searching...
No Matches
pgpa_scanner.l File Reference
#include "postgres.h"
#include "nodes/miscnodes.h"
#include "parser/scansup.h"
#include "utils/builtins.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 275 of file pgpa_scanner.l.

276{
277 yylex_destroy(yyscanner);
278}

References fb().

◆ pgpa_scanner_init()

void pgpa_scanner_init ( const char str,
yyscan_t yyscannerp 
)

Definition at line 252 of file pgpa_scanner.l.

253{
254 yyscan_t yyscanner;
#define palloc0_object(type)
Definition fe_memutils.h:90
256
257 if (yylex_init(yyscannerp) != 0)
258 elog(ERROR, "yylex_init() failed: %m");
#define elog(elevel,...)
Definition elog.h:228
259
260 yyscanner = *yyscannerp;
261
262 initStringInfo(&yyext->litbuf);
263 pgpa_yyset_extra(yyext, yyscanner);
void initStringInfo(StringInfo str)
Definition stringinfo.c:97
264
265 yy_scan_string(str, yyscanner);
const char * str
266}

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 229 of file pgpa_scanner.l.

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

References fb(), and psprintf().

◆ yyalloc()

void * yyalloc ( yy_size_t  size,
yyscan_t  yyscanner 
)

Definition at line 286 of file pgpa_scanner.l.

287{
288 return palloc(size);
void * palloc(Size size)
Definition mcxt.c:1390
289}

References palloc().

◆ yyfree()

void yyfree ( void ptr,
yyscan_t  yyscanner 
)

Definition at line 301 of file pgpa_scanner.l.

302{
303 if (ptr)
304 pfree(ptr);
void pfree(void *pointer)
Definition mcxt.c:1619
305}

References pfree().

◆ yylex()

int yylex ( YYSTYPE yylval_param,
yyscan_t  yyscanner 
)

Definition at line 100 of file pgpa_scanner.l.

102{whitespace} { /* ignore */ }
103
104{identifier} {
105 char *str;
106 bool fail;
pgpa_advice_tag_type
Definition pgpa_ast.h:81
108
109 /*
110 * Unlike the core scanner, we don't truncate identifiers
111 * here. There is no obvious reason to do so.
112 */
113 str = downcase_identifier(yytext, yyleng, false, false);
114 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
115
116 /*
117 * If it's not a tag, just return TOK_IDENT; else, return
118 * a token type based on how further parsing should
119 * proceed.
120 */
122 if (fail)
123 return TOK_IDENT;
124 else if (tag == PGPA_TAG_JOIN_ORDER)
125 return TOK_TAG_JOIN_ORDER;
126 else if (tag == PGPA_TAG_INDEX_SCAN ||
128 return TOK_TAG_INDEX;
129 else if (tag == PGPA_TAG_SEQ_SCAN ||
130 tag == PGPA_TAG_TID_SCAN ||
132 tag == PGPA_TAG_NO_GATHER ||
134 return TOK_TAG_SIMPLE;
135 else
136 return TOK_TAG_GENERIC;
137 }
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
138
139{decinteger} {
141
143 (Node *) &escontext);
144 if (escontext.error_occurred)
146 "integer out of range");
147 return TOK_INTEGER;
148 }
int32 pg_strtoint32_safe(const char *s, Node *escontext)
Definition numutils.c:388
void pgpa_yyerror(List **result, char **parse_error_msg_p, yyscan_t yyscanner, const char *message)
Definition nodes.h:133
149
150{integer_junk} {
151 BEGIN(INITIAL);
153 "trailing junk after numeric literal");
154 }
155
156{xcstart} {
157 BEGIN(xc);
158 }
159
160{xdstart} {
161 BEGIN(xd);
162 resetStringInfo(&yyextra->litbuf);
163 }
#define yyextra
Definition scan.l:1102
void resetStringInfo(StringInfo str)
Definition stringinfo.c:126
164
165. { return yytext[0]; }
166
167<xc>{xcstop} {
168 BEGIN(INITIAL);
169 }
170
171<xc>{xcinside} {
172 /* discard multiple characters without slash or asterisk */
173 }
174
175<xc>. {
176 /*
177 * Discard any single character. flex prefers longer
178 * matches, so this rule will never be picked when we could
179 * have matched xcstop.
180 *
181 * NB: At present, we don't bother to support nested
182 * C-style comments here, but this logic could be extended
183 * if that restriction poses a problem.
184 */
185 }
186
187<xc><<EOF>> {
188 BEGIN(INITIAL);
190 "unterminated comment");
191 }
192
193<xd>{xdstop} {
194 BEGIN(INITIAL);
195 if (yyextra->litbuf.len == 0)
197 "zero-length delimited identifier");
198 yylval->str = pstrdup(yyextra->litbuf.data);
199 return TOK_IDENT;
200 }
char * pstrdup(const char *in)
Definition mcxt.c:1910
201
202<xd>{xddouble} {
203 appendStringInfoChar(&yyextra->litbuf, '"');
204 }
void appendStringInfoChar(StringInfo str, char ch)
Definition stringinfo.c:242
205
206<xd>{xdinside} {
208 }
void appendBinaryStringInfo(StringInfo str, const void *data, int datalen)
Definition stringinfo.c:281
209
210<xd><<EOF>> {
211 BEGIN(INITIAL);
213 "unterminated quoted identifier");
214 }
215
216%%

◆ yyrealloc()

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

Definition at line 292 of file pgpa_scanner.l.

293{
294 if (ptr)
295 return repalloc(ptr, size);
296 else
297 return palloc(size);
void * repalloc(void *pointer, Size size)
Definition mcxt.c:1635
298}

References palloc(), and repalloc().