PostgreSQL Source Code git master
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 void * core_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)
 
void scanner_yyerror (const char *message, core_yyscan_t yyscanner) pg_attribute_noreturn()
 

Variables

PGDLLIMPORT const uint16 ScanKeywordTokens []
 

Macro Definition Documentation

◆ YYLTYPE

#define YYLTYPE   int

Definition at line 44 of file scanner.h.

Typedef Documentation

◆ core_yy_extra_type

◆ core_yyscan_t

typedef void* core_yyscan_t

Definition at line 121 of file scanner.h.

◆ core_YYSTYPE

typedef union core_YYSTYPE core_YYSTYPE

◆ ScannerCallbackState

Function Documentation

◆ cancel_scanner_errposition_callback()

void cancel_scanner_errposition_callback ( ScannerCallbackState scbstate)

Definition at line 1203 of file scan.l.

1204{
1205 /* Pop the error context stack */
1207}
ErrorContextCallback * error_context_stack
Definition: elog.c:94
struct ErrorContextCallback * previous
Definition: elog.h:296
ErrorContextCallback errcallback
Definition: scanner.h:128

References ScannerCallbackState::errcallback, error_context_stack, 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 
)

◆ scanner_errposition()

int scanner_errposition ( int  location,
core_yyscan_t  yyscanner 
)

Definition at line 1140 of file scan.l.

1141{
1142 int pos;
1143
1144 if (location < 0)
1145 return 0; /* no-op if location is unknown */
1146
1147 /* Convert byte offset to character number */
1148 pos = pg_mbstrlen_with_len(yyextra->scanbuf, location) + 1;
1149 /* And pass it to the ereport mechanism */
1150 return errposition(pos);
1151}
int errposition(int cursorpos)
Definition: elog.c:1446
int pg_mbstrlen_with_len(const char *mbstr, int limit)
Definition: mbutils.c:1057
#define yyextra
Definition: scan.l:1118

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)

Definition at line 1291 of file scan.l.

1292{
1293 /*
1294 * We don't bother to call yylex_destroy(), because all it would do is
1295 * pfree a small amount of control storage. It's cheaper to leak the
1296 * storage until the parsing context is destroyed. The amount of space
1297 * involved is usually negligible compared to the output parse tree
1298 * anyway.
1299 *
1300 * We do bother to pfree the scanbuf and literal buffer, but only if they
1301 * represent a nontrivial amount of space. The 8K cutoff is arbitrary.
1302 */
1303 if (yyextra->scanbuflen >= 8192)
1304 pfree(yyextra->scanbuf);
1305 if (yyextra->literalalloc >= 8192)
1306 pfree(yyextra->literalbuf);
1307}
void pfree(void *pointer)
Definition: mcxt.c:1521

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 
)

Definition at line 1249 of file scan.l.

1253{
1254 Size slen = strlen(str);
1255 yyscan_t scanner;
1256
1257 if (yylex_init(&scanner) != 0)
1258 elog(ERROR, "yylex_init() failed: %m");
1259
1260 core_yyset_extra(yyext, scanner);
1261
1262 yyext->keywordlist = keywordlist;
1263 yyext->keyword_tokens = keyword_tokens;
1264
1268
1269 /*
1270 * Make a scan buffer with special termination needed by flex.
1271 */
1272 yyext->scanbuf = (char *) palloc(slen + 2);
1273 yyext->scanbuflen = slen;
1274 memcpy(yyext->scanbuf, str, slen);
1275 yyext->scanbuf[slen] = yyext->scanbuf[slen + 1] = YY_END_OF_BUFFER_CHAR;
1276 yy_scan_buffer(yyext->scanbuf, slen + 2, scanner);
1277
1278 /* initialize literal buffer to a reasonable but expansible size */
1279 yyext->literalalloc = 1024;
1280 yyext->literalbuf = (char *) palloc(yyext->literalalloc);
1281 yyext->literallen = 0;
1282
1283 return scanner;
1284}
size_t Size
Definition: c.h:562
void * yyscan_t
Definition: cubedata.h:67
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:225
const char * str
void * palloc(Size size)
Definition: mcxt.c:1317
bool escape_string_warning
Definition: scan.l:69
int backslash_quote
Definition: scan.l:68
bool standard_conforming_strings
Definition: scan.l:70
bool escape_string_warning
Definition: scanner.h:88
char * literalbuf
Definition: scanner.h:98
bool standard_conforming_strings
Definition: scanner.h:89
const ScanKeywordList * keywordlist
Definition: scanner.h:78
char * scanbuf
Definition: scanner.h:72
const uint16 * keyword_tokens
Definition: scanner.h:79

References backslash_quote, core_yy_extra_type::backslash_quote, elog, ERROR, escape_string_warning, core_yy_extra_type::escape_string_warning, core_yy_extra_type::keyword_tokens, core_yy_extra_type::keywordlist, core_yy_extra_type::literalalloc, core_yy_extra_type::literalbuf, core_yy_extra_type::literallen, palloc(), core_yy_extra_type::scanbuf, core_yy_extra_type::scanbuflen, standard_conforming_strings, core_yy_extra_type::standard_conforming_strings, and str.

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

◆ scanner_yyerror()

void scanner_yyerror ( const char *  message,
core_yyscan_t  yyscanner 
)

Definition at line 1222 of file scan.l.

1223{
1224 const char *loc = yyextra->scanbuf + *yylloc;
1225
1226 if (*loc == YY_END_OF_BUFFER_CHAR)
1227 {
1228 ereport(ERROR,
1229 (errcode(ERRCODE_SYNTAX_ERROR),
1230 /* translator: %s is typically the translation of "syntax error" */
1231 errmsg("%s at end of input", _(message)),
1233 }
1234 else
1235 {
1236 ereport(ERROR,
1237 (errcode(ERRCODE_SYNTAX_ERROR),
1238 /* translator: first %s is typically the translation of "syntax error" */
1239 errmsg("%s at or near \"%s\"", _(message), loc),
1241 }
1242}
int errcode(int sqlerrcode)
Definition: elog.c:853
int errmsg(const char *fmt,...)
Definition: elog.c:1070
#define _(x)
Definition: elog.c:90
#define ereport(elevel,...)
Definition: elog.h:149
#define yylloc
Definition: scan.l:1122
#define lexer_errposition()
Definition: scan.l:128

References _, ereport, errcode(), errmsg(), ERROR, 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 
)

Definition at line 1186 of file scan.l.

1189{
1190 /* Setup error traceback support for ereport() */
1191 scbstate->yyscanner = yyscanner;
1192 scbstate->location = location;
1194 scbstate->errcallback.arg = scbstate;
1196 error_context_stack = &scbstate->errcallback;
1197}
static void scb_error_callback(void *arg)
Definition: scan.l:1161
void(* callback)(void *arg)
Definition: elog.h:297
core_yyscan_t yyscanner
Definition: scanner.h:126

References ErrorContextCallback::arg, ErrorContextCallback::callback, ScannerCallbackState::errcallback, error_context_stack, ScannerCallbackState::location, ErrorContextCallback::previous, scb_error_callback(), and ScannerCallbackState::yyscanner.

Referenced by addunicode(), and str_udeescape().

Variable Documentation

◆ ScanKeywordTokens

PGDLLIMPORT const uint16 ScanKeywordTokens[]
extern

Definition at line 81 of file scan.l.

Referenced by fill_in_constant_lengths(), and raw_parser().