PostgreSQL Source Code git master
Loading...
Searching...
No Matches
scanner.h File Reference
#include "common/keywords.h"
Include dependency graph for scanner.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

union  core_YYSTYPE
 
struct  core_yy_extra_type
 
struct  ScannerCallbackState
 

Macros

#define YYLTYPE   int
 

Typedefs

typedef union core_YYSTYPE core_YYSTYPE
 
typedef struct core_yy_extra_type core_yy_extra_type
 
typedef voidcore_yyscan_t
 
typedef struct ScannerCallbackState ScannerCallbackState
 

Functions

core_yyscan_t scanner_init (const char *str, core_yy_extra_type *yyext, const ScanKeywordList *keywordlist, const uint16 *keyword_tokens)
 
void scanner_finish (core_yyscan_t yyscanner)
 
int core_yylex (core_YYSTYPE *yylval_param, YYLTYPE *yylloc_param, core_yyscan_t yyscanner)
 
int scanner_errposition (int location, core_yyscan_t yyscanner)
 
void setup_scanner_errposition_callback (ScannerCallbackState *scbstate, core_yyscan_t yyscanner, int location)
 
void cancel_scanner_errposition_callback (ScannerCallbackState *scbstate)
 
pg_noreturn void scanner_yyerror (const char *message, core_yyscan_t yyscanner)
 

Variables

PGDLLIMPORT const uint16 ScanKeywordTokens []
 

Macro Definition Documentation

◆ YYLTYPE

Definition at line 44 of file scanner.h.

Typedef Documentation

◆ core_yy_extra_type

◆ core_yyscan_t

Definition at line 118 of file scanner.h.

◆ core_YYSTYPE

◆ ScannerCallbackState

Function Documentation

◆ cancel_scanner_errposition_callback()

void cancel_scanner_errposition_callback ( ScannerCallbackState scbstate)
extern

Definition at line 1178 of file scan.l.

1179{
1180 /* Pop the error context stack */
1181 error_context_stack = scbstate->errcallback.previous;
1182}
ErrorContextCallback * error_context_stack
Definition elog.c:95
static int fb(int x)
struct ErrorContextCallback * previous
Definition elog.h:297

References error_context_stack, fb(), and ErrorContextCallback::previous.

Referenced by addunicode(), and str_udeescape().

◆ core_yylex()

int core_yylex ( core_YYSTYPE yylval_param,
YYLTYPE yylloc_param,
core_yyscan_t  yyscanner 
)
extern

◆ scanner_errposition()

int scanner_errposition ( int  location,
core_yyscan_t  yyscanner 
)
extern

Definition at line 1115 of file scan.l.

1116{
1117 int pos;
1118
1119 if (location < 0)
1120 return 0; /* no-op if location is unknown */
1121
1122 /* Convert byte offset to character number */
1123 pos = pg_mbstrlen_with_len(yyextra->scanbuf, location) + 1;
1124 /* And pass it to the ereport mechanism */
1125 return errposition(pos);
1126}
int errposition(int cursorpos)
Definition elog.c:1480
int pg_mbstrlen_with_len(const char *mbstr, int limit)
Definition mbutils.c:1060
#define yyextra
Definition scan.l:1093

References errposition(), pg_mbstrlen_with_len(), and yyextra.

Referenced by scb_error_callback(), and str_udeescape().

◆ scanner_finish()

void scanner_finish ( core_yyscan_t  yyscanner)
extern

Definition at line 1264 of file scan.l.

1265{
1266 /*
1267 * We don't bother to call yylex_destroy(), because all it would do is
1268 * pfree a small amount of control storage. It's cheaper to leak the
1269 * storage until the parsing context is destroyed. The amount of space
1270 * involved is usually negligible compared to the output parse tree
1271 * anyway.
1272 *
1273 * We do bother to pfree the scanbuf and literal buffer, but only if they
1274 * represent a nontrivial amount of space. The 8K cutoff is arbitrary.
1275 */
1276 if (yyextra->scanbuflen >= 8192)
1277 pfree(yyextra->scanbuf);
1278 if (yyextra->literalalloc >= 8192)
1279 pfree(yyextra->literalbuf);
1280}
void pfree(void *pointer)
Definition mcxt.c:1616

References pfree(), and yyextra.

Referenced by fill_in_constant_lengths(), plpgsql_scanner_finish(), and raw_parser().

◆ scanner_init()

core_yyscan_t scanner_init ( const char str,
core_yy_extra_type yyext,
const ScanKeywordList keywordlist,
const uint16 keyword_tokens 
)
extern

Definition at line 1224 of file scan.l.

1228{
1229 Size slen = strlen(str);
1230 yyscan_t scanner;
1231
1232 if (yylex_init(&scanner) != 0)
1233 elog(ERROR, "yylex_init() failed: %m");
1234
1235 core_yyset_extra(yyext, scanner);
1236
1237 yyext->keywordlist = keywordlist;
1238 yyext->keyword_tokens = keyword_tokens;
1239
1240 yyext->backslash_quote = backslash_quote;
1241
1242 /*
1243 * Make a scan buffer with special termination needed by flex.
1244 */
1245 yyext->scanbuf = (char *) palloc(slen + 2);
1246 yyext->scanbuflen = slen;
1247 memcpy(yyext->scanbuf, str, slen);
1248 yyext->scanbuf[slen] = yyext->scanbuf[slen + 1] = YY_END_OF_BUFFER_CHAR;
1249 yy_scan_buffer(yyext->scanbuf, slen + 2, scanner);
1250
1251 /* initialize literal buffer to a reasonable but expansible size */
1252 yyext->literalalloc = 1024;
1253 yyext->literalbuf = (char *) palloc(yyext->literalalloc);
1254 yyext->literallen = 0;
1255
1256 return scanner;
1257}
size_t Size
Definition c.h:619
void * yyscan_t
Definition cubedata.h:65
#define ERROR
Definition elog.h:39
#define elog(elevel,...)
Definition elog.h:226
const char * str
void * palloc(Size size)
Definition mcxt.c:1387
int backslash_quote
Definition scan.l:69

References backslash_quote, elog, ERROR, fb(), palloc(), and str.

Referenced by fill_in_constant_lengths(), plpgsql_scanner_init(), and raw_parser().

◆ scanner_yyerror()

pg_noreturn void scanner_yyerror ( const char message,
core_yyscan_t  yyscanner 
)
extern

Definition at line 1197 of file scan.l.

1198{
1199 const char *loc = yyextra->scanbuf + *yylloc;
1200
1201 if (*loc == YY_END_OF_BUFFER_CHAR)
1202 {
1203 ereport(ERROR,
1205 /* translator: %s is typically the translation of "syntax error" */
1206 errmsg("%s at end of input", _(message)),
1208 }
1209 else
1210 {
1211 ereport(ERROR,
1213 /* translator: first %s is typically the translation of "syntax error" */
1214 errmsg("%s at or near \"%s\"", _(message), loc),
1216 }
1217}
int errcode(int sqlerrcode)
Definition elog.c:863
int errmsg(const char *fmt,...)
Definition elog.c:1080
#define _(x)
Definition elog.c:91
#define ereport(elevel,...)
Definition elog.h:150
#define yylloc
Definition scan.l:1097
#define lexer_errposition()
Definition scan.l:127

References _, ereport, errcode(), errmsg(), ERROR, fb(), lexer_errposition, yyextra, and yylloc.

Referenced by base_yylex().

◆ setup_scanner_errposition_callback()

void setup_scanner_errposition_callback ( ScannerCallbackState scbstate,
core_yyscan_t  yyscanner,
int  location 
)
extern

Definition at line 1161 of file scan.l.

1164{
1165 /* Setup error traceback support for ereport() */
1166 scbstate->yyscanner = yyscanner;
1167 scbstate->location = location;
1168 scbstate->errcallback.callback = scb_error_callback;
1169 scbstate->errcallback.arg = scbstate;
1170 scbstate->errcallback.previous = error_context_stack;
1171 error_context_stack = &scbstate->errcallback;
1172}
static void scb_error_callback(void *arg)
Definition scan.l:1136

References error_context_stack, fb(), and scb_error_callback().

Referenced by addunicode(), and str_udeescape().

Variable Documentation

◆ ScanKeywordTokens

PGDLLIMPORT const uint16 ScanKeywordTokens[]
extern

Definition at line 80 of file scan.l.

80 {
81#include "parser/kwlist.h"
82};

Referenced by fill_in_constant_lengths(), and raw_parser().