Line data Source code
1 : %top{
2 : /*-------------------------------------------------------------------------
3 : *
4 : * bootscanner.l
5 : * a lexical scanner for the bootstrap parser
6 : *
7 : * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
8 : * Portions Copyright (c) 1994, Regents of the University of California
9 : *
10 : *
11 : * IDENTIFICATION
12 : * src/backend/bootstrap/bootscanner.l
13 : *
14 : *-------------------------------------------------------------------------
15 : */
16 : #include "postgres.h"
17 :
18 : /*
19 : * NB: include bootparse.h only AFTER including bootstrap.h, because bootstrap.h
20 : * includes node definitions needed for YYSTYPE.
21 : */
22 : #include "bootstrap/bootstrap.h"
23 : #include "bootparse.h"
24 : #include "utils/guc.h"
25 :
26 : }
27 :
28 : %{
29 :
30 : /* LCOV_EXCL_START */
31 :
32 : /* Avoid exit() on fatal scanner errors (a bit ugly -- see yy_fatal_error) */
33 : #undef fprintf
34 : #define fprintf(file, fmt, msg) fprintf_to_ereport(fmt, msg)
35 :
36 : static void
37 0 : fprintf_to_ereport(const char *fmt, const char *msg)
38 : {
39 0 : ereport(ERROR, (errmsg_internal("%s", msg)));
40 : }
41 :
42 : %}
43 :
44 : %option reentrant
45 : %option bison-bridge
46 : %option 8bit
47 : %option never-interactive
48 : %option nodefault
49 : %option noinput
50 : %option nounput
51 : %option noyywrap
52 : %option noyyalloc
53 : %option noyyrealloc
54 : %option noyyfree
55 : %option warn
56 : %option prefix="boot_yy"
57 :
58 :
59 : id [-A-Za-z0-9_]+
60 : sid \'([^']|\'\')*\'
61 :
62 : /*
63 : * Keyword tokens return the keyword text (as a constant string) in yylval->kw,
64 : * just in case that's needed because we want to treat the keyword as an
65 : * unreserved identifier. Note that _null_ is not treated as a keyword
66 : * for this purpose; it's the one "reserved word" in the bootstrap syntax.
67 : *
68 : * Notice that all the keywords are case-sensitive, and for historical
69 : * reasons some must be upper case.
70 : *
71 : * String tokens return a palloc'd string in yylval->str.
72 : */
73 :
74 : %%
75 :
76 3060 : open { yylval->kw = "open"; return OPEN; }
77 :
78 3264 : close { yylval->kw = "close"; return XCLOSE; }
79 3264 :
80 3264 : create { yylval->kw = "create"; return XCREATE; }
81 3264 :
82 0 : OID { yylval->kw = "OID"; return OBJ_ID; }
83 204 : bootstrap { yylval->kw = "bootstrap"; return XBOOTSTRAP; }
84 561 : shared_relation { yylval->kw = "shared_relation"; return XSHARED_RELATION; }
85 663 : rowtype_oid { yylval->kw = "rowtype_oid"; return XROWTYPE_OID; }
86 561 :
87 556971 : insert { yylval->kw = "insert"; return INSERT_TUPLE; }
88 556512 :
89 1631022 : _null_ { return NULLVAL; }
90 1631022 :
91 32028 : "," { return COMMA; }
92 63189 : "=" { return EQUALS; }
93 566100 : "(" { return LPAREN; }
94 597261 : ")" { return RPAREN; }
95 566100 :
96 566100 : [\n] { yylineno++; }
97 612000 : [\r\t ] ;
98 10207599 :
99 9595599 : ^\#[^\n]* ; /* drop everything after "#" for comments */
100 51 :
101 8109 : declare { yylval->kw = "declare"; return XDECLARE; }
102 8160 : build { yylval->kw = "build"; return XBUILD; }
103 51 : indices { yylval->kw = "indices"; return INDICES; }
104 5661 : unique { yylval->kw = "unique"; return UNIQUE; }
105 6375 : index { yylval->kw = "index"; return INDEX; }
106 13719 : on { yylval->kw = "on"; return ON; }
107 12648 : using { yylval->kw = "using"; return USING; }
108 9894 : toast { yylval->kw = "toast"; return XTOAST; }
109 8313 : FORCE { yylval->kw = "FORCE"; return XFORCE; }
110 3570 : NOT { yylval->kw = "NOT"; return XNOT; }
111 3978 : NULL { yylval->kw = "NULL"; return XNULL; }
112 1785 :
113 1989 : {id} {
114 6375561 : yylval->str = pstrdup(yytext);
115 6375561 : return ID;
116 : }
117 : {sid} {
118 381540 : /* strip quotes and escapes */
119 381540 : yylval->str = DeescapeQuotedString(yytext);
120 763080 : return ID;
121 : }
122 :
123 0 : . {
124 0 : elog(ERROR, "syntax error at line %d: unexpected character \"%s\"", yylineno, yytext);
125 : }
126 :
127 0 : %%
128 0 :
129 : /* LCOV_EXCL_STOP */
130 :
131 : void
132 0 : boot_yyerror(yyscan_t yyscanner, const char *message)
133 : {
134 0 : struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; /* needed for yylineno
135 : * macro */
136 :
137 0 : elog(ERROR, "%s at line %d", message, yylineno);
138 : }
139 :
140 : /*
141 : * Interface functions to make flex use palloc() instead of malloc().
142 : * It'd be better to make these static, but flex insists otherwise.
143 : */
144 :
145 : void *
146 204 : yyalloc(yy_size_t size, yyscan_t yyscanner)
147 : {
148 204 : return palloc(size);
149 : }
150 :
151 : void *
152 0 : yyrealloc(void *ptr, yy_size_t size, yyscan_t yyscanner)
153 : {
154 0 : if (ptr)
155 0 : return repalloc(ptr, size);
156 : else
157 0 : return palloc(size);
158 : }
159 :
160 : void
161 0 : yyfree(void *ptr, yyscan_t yyscanner)
162 : {
163 0 : if (ptr)
164 0 : pfree(ptr);
165 0 : }
|