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 1187 of file scan.l.

1188{
1189 /* Pop the error context stack */
1190 error_context_stack = scbstate->errcallback.previous;
1191}
ErrorContextCallback * error_context_stack
Definition elog.c:99
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 1124 of file scan.l.

1125{
1126 int pos;
1127
1128 if (location < 0)
1129 return 0; /* no-op if location is unknown */
1130
1131 /* Convert byte offset to character number */
1132 pos = pg_mbstrlen_with_len(yyextra->scanbuf, location) + 1;
1133 /* And pass it to the ereport mechanism */
1134 return errposition(pos);
1135}
int errposition(int cursorpos)
int pg_mbstrlen_with_len(const char *mbstr, int limit)
Definition mbutils.c:1185
#define yyextra
Definition scan.l:1102

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 1273 of file scan.l.

1274{
1275 /*
1276 * We don't bother to call yylex_destroy(), because all it would do is
1277 * pfree a small amount of control storage. It's cheaper to leak the
1278 * storage until the parsing context is destroyed. The amount of space
1279 * involved is usually negligible compared to the output parse tree
1280 * anyway.
1281 *
1282 * We do bother to pfree the scanbuf and literal buffer, but only if they
1283 * represent a nontrivial amount of space. The 8K cutoff is arbitrary.
1284 */
1285 if (yyextra->scanbuflen >= 8192)
1286 pfree(yyextra->scanbuf);
1287 if (yyextra->literalalloc >= 8192)
1288 pfree(yyextra->literalbuf);
1289}
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 1233 of file scan.l.

1237{
1238 Size slen = strlen(str);
1239 yyscan_t scanner;
1240
1241 if (yylex_init(&scanner) != 0)
1242 elog(ERROR, "yylex_init() failed: %m");
1243
1244 core_yyset_extra(yyext, scanner);
1245
1246 yyext->keywordlist = keywordlist;
1247 yyext->keyword_tokens = keyword_tokens;
1248
1249 yyext->backslash_quote = backslash_quote;
1250
1251 /*
1252 * Make a scan buffer with special termination needed by flex.
1253 */
1254 yyext->scanbuf = (char *) palloc(slen + 2);
1255 yyext->scanbuflen = slen;
1256 memcpy(yyext->scanbuf, str, slen);
1257 yyext->scanbuf[slen] = yyext->scanbuf[slen + 1] = YY_END_OF_BUFFER_CHAR;
1258 yy_scan_buffer(yyext->scanbuf, slen + 2, scanner);
1259
1260 /* initialize literal buffer to a reasonable but expansible size */
1261 yyext->literalalloc = 1024;
1262 yyext->literalbuf = (char *) palloc(yyext->literalalloc);
1263 yyext->literallen = 0;
1264
1265 return scanner;
1266}
size_t Size
Definition c.h:691
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 1206 of file scan.l.

1207{
1208 const char *loc = yyextra->scanbuf + *yylloc;
1209
1210 if (*loc == YY_END_OF_BUFFER_CHAR)
1211 {
1212 ereport(ERROR,
1214 /* translator: %s is typically the translation of "syntax error" */
1215 errmsg("%s at end of input", _(message)),
1217 }
1218 else
1219 {
1220 ereport(ERROR,
1222 /* translator: first %s is typically the translation of "syntax error" */
1223 errmsg("%s at or near \"%s\"", _(message), loc),
1225 }
1226}
int errcode(int sqlerrcode)
Definition elog.c:874
#define _(x)
Definition elog.c:95
#define ereport(elevel,...)
Definition elog.h:150
static char * errmsg
#define yylloc
Definition scan.l:1106
#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 1170 of file scan.l.

1173{
1174 /* Setup error traceback support for ereport() */
1175 scbstate->yyscanner = yyscanner;
1176 scbstate->location = location;
1177 scbstate->errcallback.callback = scb_error_callback;
1178 scbstate->errcallback.arg = scbstate;
1179 scbstate->errcallback.previous = error_context_stack;
1180 error_context_stack = &scbstate->errcallback;
1181}
static void scb_error_callback(void *arg)
Definition scan.l:1145

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