1/*-------------------------------------------------------------------------
4 * API for the core scanner (flex machine)
6 * The core scanner is also used by PL/pgSQL, so we provide a public API
7 * for it. However, the rest of the backend is only expected to use the
8 * higher-level API provided by parser.h.
11 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
12 * Portions Copyright (c) 1994, Regents of the University of California
14 * src/include/parser/scanner.h
16 *-------------------------------------------------------------------------
25 * The scanner returns extra data about scanned tokens in this union type.
26 * Note that this is a subset of the fields used in YYSTYPE of the bison
27 * parsers built atop the scanner.
31 int ival;
/* for integer literals */
32 char *
str;
/* for identifiers and non-integer literals */
33 const char *
keyword;
/* canonical spelling of keywords */
37 * We track token locations in terms of byte offsets from the start of the
38 * source string, not the column number/line number representation that
39 * bison uses by default. Also, to minimize overhead we track only one
40 * location (usually the first token location) for each construct, not
41 * the beginning and ending locations as bison does by default. It's
42 * therefore sufficient to make YYLTYPE an int.
47 * Another important component of the scanner's API is the token code numbers.
48 * However, those are not defined in this file, because bison insists on
49 * defining them for itself. The token codes used by the core scanner are
50 * the ASCII characters plus these:
51 * %token <str> IDENT UIDENT FCONST SCONST USCONST BCONST XCONST Op
52 * %token <ival> ICONST PARAM
53 * %token TYPECAST DOT_DOT COLON_EQUALS EQUALS_GREATER
54 * %token LESS_EQUALS GREATER_EQUALS NOT_EQUALS
55 * The above token definitions *must* be the first ones declared in any
56 * bison parser built atop this scanner, so that they will have consistent
57 * numbers assigned to them (specifically, IDENT = 258 and so on).
61 * The YY_EXTRA data that a flex scanner allows us to pass around.
62 * Private state needed by the core scanner goes here. Note that the actual
63 * yy_extra struct may be larger and have this as its first component, thus
64 * allowing the calling parser to keep some fields of its own in YY_EXTRA.
69 * The string the scanner is physically scanning. We keep this mainly so
70 * that we can cheaply compute the offset of the current token (yytext).
76 * The keyword list to use, and the associated grammar token codes.
82 * Scanner settings to use. These are initialized from the corresponding
83 * GUC variables by scanner_init(). Callers can modify them after
84 * scanner_init() if they don't want the scanner's behavior to follow the
85 * prevailing GUC settings.
92 * literalbuf is used to accumulate literal values when multiple rules are
93 * needed to parse a single literal. Call startlit() to reset buffer to
94 * empty, addlit() to add text. NOTE: the string in literalbuf is NOT
95 * necessarily null-terminated, but there always IS room to add a trailing
96 * null at offset literallen. We store a null only when we need it.
103 * Random assorted scanner state.
106 int xcdepth;
/* depth of nesting in slash-star comments */
110 /* first part of UTF16 surrogate pair for Unicode escapes */
113 /* state variables for literal-lexing warnings */
119 * The type of yyscanner is opaque outside scan.l.
123/* Support for scanner_errposition_callback function */
132/* Constant data exported from parser/scan.l */
135/* Entry points in parser/scan.l */
139 const uint16 *keyword_tokens);
150#endif /* SCANNER_H */
int scanner_errposition(int location, core_yyscan_t yyscanner)
core_yyscan_t scanner_init(const char *str, core_yy_extra_type *yyext, const ScanKeywordList *keywordlist, const uint16 *keyword_tokens)
void setup_scanner_errposition_callback(ScannerCallbackState *scbstate, core_yyscan_t yyscanner, int location)
void scanner_finish(core_yyscan_t yyscanner)
PGDLLIMPORT const uint16 ScanKeywordTokens[]
void cancel_scanner_errposition_callback(ScannerCallbackState *scbstate)
union core_YYSTYPE core_YYSTYPE
struct core_yy_extra_type core_yy_extra_type
struct ScannerCallbackState ScannerCallbackState
pg_noreturn void scanner_yyerror(const char *message, core_yyscan_t yyscanner)
int core_yylex(core_YYSTYPE *yylval_param, YYLTYPE *yylloc_param, core_yyscan_t yyscanner)
ErrorContextCallback errcallback