PostgreSQL Source Code git master
repl_scanner.l File Reference
#include "postgres.h"
#include "nodes/parsenodes.h"
#include "utils/builtins.h"
#include "parser/scansup.h"
#include "replication/walsender_private.h"
#include "repl_gram.h"
Include dependency graph for repl_scanner.l:

Go to the source code of this file.

Data Structures

struct  replication_yy_extra_type
 

Macros

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

Functions

static void fprintf_to_ereport (const char *fmt, const char *msg)
 
static void startlit (yyscan_t yyscanner)
 
static char * litbufdup (yyscan_t yyscanner)
 
static void addlit (char *ytext, int yleng, yyscan_t yyscanner)
 
static void addlitchar (unsigned char ychar, yyscan_t yyscanner)
 
int yylex (YYSTYPE *yylval_param, yyscan_t yyscanner)
 
void replication_yyerror (Node **replication_parse_result_p, yyscan_t yyscanner, const char *message)
 
void replication_scanner_init (const char *str, yyscan_t *yyscannerp)
 
void replication_scanner_finish (yyscan_t yyscanner)
 
bool replication_scanner_is_replication_command (yyscan_t yyscanner)
 
void * yyalloc (yy_size_t size, yyscan_t yyscanner)
 
void * yyrealloc (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 33 of file repl_scanner.l.

Function Documentation

◆ addlit()

static void addlit ( char *  ytext,
int  yleng,
yyscan_t  yyscanner 
)
static

Definition at line 244 of file repl_scanner.l.

245{
246 appendBinaryStringInfo(&yyextra->litbuf, ytext, yleng);
#define yyextra
Definition: scan.l:1118
void appendBinaryStringInfo(StringInfo str, const void *data, int datalen)
Definition: stringinfo.c:281
247}

References appendBinaryStringInfo(), and yyextra.

◆ addlitchar()

static void addlitchar ( unsigned char  ychar,
yyscan_t  yyscanner 
)
static

Definition at line 250 of file repl_scanner.l.

251{
252 appendStringInfoChar(&yyextra->litbuf, ychar);
void appendStringInfoChar(StringInfo str, char ch)
Definition: stringinfo.c:242
253}

References appendStringInfoChar(), and yyextra.

◆ fprintf_to_ereport()

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

Definition at line 36 of file repl_scanner.l.

37{
38 ereport(ERROR, (errmsg_internal("%s", msg)));
int errmsg_internal(const char *fmt,...)
Definition: elog.c:1157
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
39}

References ereport, errmsg_internal(), and ERROR.

◆ litbufdup()

static char * litbufdup ( yyscan_t  yyscanner)
static

Definition at line 238 of file repl_scanner.l.

239{
240 return yyextra->litbuf.data;
241}

References yyextra.

◆ replication_scanner_finish()

void replication_scanner_finish ( yyscan_t  yyscanner)

Definition at line 284 of file repl_scanner.l.

285{
286 pfree(yyextra);
287 yylex_destroy(yyscanner);
void pfree(void *pointer)
Definition: mcxt.c:1521
288}

References pfree(), and yyextra.

Referenced by exec_replication_command().

◆ replication_scanner_init()

void replication_scanner_init ( const char *  str,
yyscan_t yyscannerp 
)

Definition at line 268 of file repl_scanner.l.

269{
270 yyscan_t yyscanner;
void * yyscan_t
Definition: cubedata.h:67
#define palloc0_object(type)
Definition: fe_memutils.h:75
272
273 if (yylex_init(yyscannerp) != 0)
274 elog(ERROR, "yylex_init() failed: %m");
#define elog(elevel,...)
Definition: elog.h:225
275
276 yyscanner = *yyscannerp;
277
278 yyset_extra(yyext, yyscanner);
279
280 yy_scan_string(str, yyscanner);
const char * str
281}

References elog, ERROR, palloc0_object, and str.

Referenced by exec_replication_command().

◆ replication_scanner_is_replication_command()

bool replication_scanner_is_replication_command ( yyscan_t  yyscanner)

Definition at line 299 of file repl_scanner.l.

300{
301 YYSTYPE dummy;
302 int first_token = replication_yylex(&dummy, yyscanner);
int YYSTYPE
Definition: psqlscanslash.l:39
int replication_yylex(union YYSTYPE *yylval_param, yyscan_t yyscanner)
303
304 switch (first_token)
305 {
306 case K_IDENTIFY_SYSTEM:
307 case K_BASE_BACKUP:
308 case K_START_REPLICATION:
309 case K_CREATE_REPLICATION_SLOT:
310 case K_DROP_REPLICATION_SLOT:
311 case K_ALTER_REPLICATION_SLOT:
312 case K_READ_REPLICATION_SLOT:
313 case K_TIMELINE_HISTORY:
314 case K_UPLOAD_MANIFEST:
315 case K_SHOW:
316 /* Yes; push back the first token so we can parse later. */
317 yyextra->repl_pushed_back_token = first_token;
318 return true;
319 default:
320 /* Nope; we don't bother to push back the token. */
321 return false;
322 }
323}

References replication_yylex(), and yyextra.

Referenced by exec_replication_command().

◆ replication_yyerror()

void replication_yyerror ( Node **  replication_parse_result_p,
yyscan_t  yyscanner,
const char *  message 
)

Definition at line 260 of file repl_scanner.l.

261{
263 (errcode(ERRCODE_SYNTAX_ERROR),
264 errmsg_internal("%s", message)));
int errcode(int sqlerrcode)
Definition: elog.c:853
265}

References ereport, errcode(), errmsg_internal(), and ERROR.

◆ startlit()

static void startlit ( yyscan_t  yyscanner)
static

Definition at line 232 of file repl_scanner.l.

233{
234 initStringInfo(&yyextra->litbuf);
void initStringInfo(StringInfo str)
Definition: stringinfo.c:97
235}

References initStringInfo(), and yyextra.

◆ yyalloc()

void * yyalloc ( yy_size_t  size,
yyscan_t  yyscanner 
)

Definition at line 331 of file repl_scanner.l.

332{
333 return palloc(size);
void * palloc(Size size)
Definition: mcxt.c:1317
static pg_noinline void Size size
Definition: slab.c:607
334}

References palloc(), and size.

◆ yyfree()

void yyfree ( void *  ptr,
yyscan_t  yyscanner 
)

Definition at line 346 of file repl_scanner.l.

347{
348 if (ptr)
349 pfree(ptr);
350}

References pfree().

◆ yylex()

int yylex ( YYSTYPE yylval_param,
yyscan_t  yyscanner 
)

Definition at line 111 of file repl_scanner.l.

113 {
114 /* This code is inserted at the start of replication_yylex() */
115
116 /* If we have a pushed-back token, return that. */
117 if (yyextra->repl_pushed_back_token)
118 {
119 int result = yyextra->repl_pushed_back_token;
120
121 yyextra->repl_pushed_back_token = 0;
122 return result;
123 }
124%}
125
126BASE_BACKUP { return K_BASE_BACKUP; }
127IDENTIFY_SYSTEM { return K_IDENTIFY_SYSTEM; }
128READ_REPLICATION_SLOT { return K_READ_REPLICATION_SLOT; }
129SHOW { return K_SHOW; }
130TIMELINE { return K_TIMELINE; }
131START_REPLICATION { return K_START_REPLICATION; }
132CREATE_REPLICATION_SLOT { return K_CREATE_REPLICATION_SLOT; }
133DROP_REPLICATION_SLOT { return K_DROP_REPLICATION_SLOT; }
134ALTER_REPLICATION_SLOT { return K_ALTER_REPLICATION_SLOT; }
135TIMELINE_HISTORY { return K_TIMELINE_HISTORY; }
136PHYSICAL { return K_PHYSICAL; }
137RESERVE_WAL { return K_RESERVE_WAL; }
138LOGICAL { return K_LOGICAL; }
139SLOT { return K_SLOT; }
140TEMPORARY { return K_TEMPORARY; }
141TWO_PHASE { return K_TWO_PHASE; }
142EXPORT_SNAPSHOT { return K_EXPORT_SNAPSHOT; }
143NOEXPORT_SNAPSHOT { return K_NOEXPORT_SNAPSHOT; }
144USE_SNAPSHOT { return K_USE_SNAPSHOT; }
145WAIT { return K_WAIT; }
146UPLOAD_MANIFEST { return K_UPLOAD_MANIFEST; }
147
148{space}+ { /* do nothing */ }
149
150{digit}+ {
151 yylval->uintval = strtoul(yytext, NULL, 10);
152 return UCONST;
153 }
154
155{hexdigit}+\/{hexdigit}+ {
156 uint32 hi,
157 lo;
158 if (sscanf(yytext, "%X/%X", &hi, &lo) != 2)
159 replication_yyerror(NULL, yyscanner, "invalid streaming start location");
160 yylval->recptr = ((uint64) hi) << 32 | lo;
161 return RECPTR;
162 }
uint64_t uint64
Definition: c.h:489
uint32_t uint32
Definition: c.h:488
void replication_yyerror(Node **replication_parse_result_p, yyscan_t yyscanner, const char *message)
Definition: repl_scanner.l:260
163
164{xqstart} {
165 BEGIN(xq);
166 startlit(yyscanner);
167 }
static void startlit(yyscan_t yyscanner)
Definition: repl_scanner.l:232
168
169<xq>{quotestop} {
170 yyless(1);
171 BEGIN(INITIAL);
172 yylval->str = litbufdup(yyscanner);
173 return SCONST;
174 }
static char * litbufdup(yyscan_t yyscanner)
Definition: repl_scanner.l:238
175
176<xq>{xqdouble} {
177 addlitchar('\'', yyscanner);
178 }
static void addlitchar(unsigned char ychar, yyscan_t yyscanner)
Definition: repl_scanner.l:250
179
180<xq>{xqinside} {
181 addlit(yytext, yyleng, yyscanner);
182 }
static void addlit(char *ytext, int yleng, yyscan_t yyscanner)
Definition: repl_scanner.l:244
#define yyleng
Definition: scan.l:1124
183
184{xdstart} {
185 BEGIN(xd);
186 startlit(yyscanner);
187 }
188
189<xd>{xdstop} {
190 int len;
const void size_t len
191
192 yyless(1);
193 BEGIN(INITIAL);
194 yylval->str = litbufdup(yyscanner);
195 len = strlen(yylval->str);
196 truncate_identifier(yylval->str, len, true);
197 return IDENT;
198 }
void truncate_identifier(char *ident, int len, bool warn)
Definition: scansup.c:93
199
200<xd>{xdinside} {
201 addlit(yytext, yyleng, yyscanner);
202 }
203
204{identifier} {
205 int len = strlen(yytext);
206
207 yylval->str = downcase_truncate_identifier(yytext, len, true);
208 return IDENT;
209 }
char * downcase_truncate_identifier(const char *ident, int len, bool warn)
Definition: scansup.c:37
210
211. {
212 /* Any char not recognized above is returned as itself */
213 return yytext[0];
214 }
215
216<xq,xd><<EOF>> { replication_yyerror(NULL, yyscanner, "unterminated quoted string"); }
217
218
219<<EOF>> {
220 yyterminate();
221 }
222
223%%

◆ yyrealloc()

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

Definition at line 337 of file repl_scanner.l.

338{
339 if (ptr)
340 return repalloc(ptr, size);
341 else
342 return palloc(size);
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:1541
343}

References palloc(), repalloc(), and size.