Age Owner Branch data TLA 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-2025, 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
4619 tgl@sss.pgh.pa.us 37 :UBC 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 : :
261 peter@eisentraut.org 76 :CBC 3000 : open { yylval->kw = "open"; return OPEN; }
77 : :
78 : 3200 : close { yylval->kw = "close"; return XCLOSE; }
10651 scrappy@hub.org 79 [ + - ]: 3200 :
261 peter@eisentraut.org 80 : 3200 : create { yylval->kw = "create"; return XCREATE; }
10651 scrappy@hub.org 81 [ + - ]: 3200 :
261 peter@eisentraut.org 82 :UBC 0 : OID { yylval->kw = "OID"; return OBJ_ID; }
261 peter@eisentraut.org 83 [ - - ]:CBC 200 : bootstrap { yylval->kw = "bootstrap"; return XBOOTSTRAP; }
84 : 550 : shared_relation { yylval->kw = "shared_relation"; return XSHARED_RELATION; }
85 [ + - ]: 650 : rowtype_oid { yylval->kw = "rowtype_oid"; return XROWTYPE_OID; }
2681 tgl@sss.pgh.pa.us 86 [ + - ]: 550 :
261 peter@eisentraut.org 87 [ + - ]: 541250 : insert { yylval->kw = "insert"; return INSERT_TUPLE; }
10651 scrappy@hub.org 88 [ + - ]: 540800 :
2681 tgl@sss.pgh.pa.us 89 : 1587741 : _null_ { return NULLVAL; }
10651 scrappy@hub.org 90 [ + - ]: 1587741 :
2942 peter_e@gmx.net 91 : 31050 : "," { return COMMA; }
92 [ + - ]: 61250 : "=" { return EQUALS; }
93 : 550200 : "(" { return LPAREN; }
94 [ + - ]: 580400 : ")" { return RPAREN; }
10651 scrappy@hub.org 95 [ + - ]: 550200 :
261 peter@eisentraut.org 96 [ + - ]: 550200 : [\n] { yylineno++; }
2681 tgl@sss.pgh.pa.us 97 : 594850 : [\r\t ] ;
98 [ + - ]: 9917750 :
1760 peter@eisentraut.org 99 [ + - ]: 9322900 : ^\#[^\n]* ; /* drop everything after "#" for comments */
2681 tgl@sss.pgh.pa.us 100 [ + - ]: 50 :
261 peter@eisentraut.org 101 : 7950 : declare { yylval->kw = "declare"; return XDECLARE; }
102 [ + - ]: 8000 : build { yylval->kw = "build"; return XBUILD; }
103 : 50 : indices { yylval->kw = "indices"; return INDICES; }
104 [ + - ]: 5550 : unique { yylval->kw = "unique"; return UNIQUE; }
105 [ + - ]: 6250 : index { yylval->kw = "index"; return INDEX; }
106 [ + - ]: 13450 : on { yylval->kw = "on"; return ON; }
107 [ + - ]: 12400 : using { yylval->kw = "using"; return USING; }
108 [ + - ]: 9700 : toast { yylval->kw = "toast"; return XTOAST; }
109 [ + - ]: 8100 : FORCE { yylval->kw = "FORCE"; return XFORCE; }
110 [ + - ]: 3450 : NOT { yylval->kw = "NOT"; return XNOT; }
111 [ + - ]: 3800 : NULL { yylval->kw = "NULL"; return XNULL; }
8793 tgl@sss.pgh.pa.us 112 [ + - ]: 1700 :
10225 bruce@momjian.us 113 [ + - ]: 1900 : {id} {
261 peter@eisentraut.org 114 [ + - ]: 6194150 : yylval->str = pstrdup(yytext);
2942 peter_e@gmx.net 115 : 6194150 : return ID;
116 : : }
117 : : {sid} {
1798 tgl@sss.pgh.pa.us 118 : 367659 : /* strip quotes and escapes */
261 peter@eisentraut.org 119 : 367659 : yylval->str = DeescapeQuotedString(yytext);
2942 peter_e@gmx.net 120 [ + - ]: 735318 : return ID;
121 : : }
122 : :
10225 bruce@momjian.us 123 :UBC 0 : . {
261 peter@eisentraut.org 124 [ # # # # ]: 0 : elog(ERROR, "syntax error at line %d: unexpected character \"%s\"", yylineno, yytext);
125 : : }
126 : :
10651 scrappy@hub.org 127 : 0 : %%
128 [ # # ]: 0 :
129 : : /* LCOV_EXCL_STOP */
130 : :
131 : : void
261 peter@eisentraut.org 132 : 0 : boot_yyerror(yyscan_t yyscanner, const char *message)
133 : : {
255 134 : 0 : struct yyguts_t *yyg = (struct yyguts_t *) yyscanner; /* needed for yylineno
135 : : * macro */
136 : :
261 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 *
261 peter@eisentraut.org 146 :CBC 200 : yyalloc(yy_size_t size, yyscan_t yyscanner)
147 : : {
148 : 200 : return palloc(size);
149 : : }
150 : :
151 : : void *
261 peter@eisentraut.org 152 :UBC 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 : : {
255 163 [ # # ]: 0 : if (ptr)
164 : 0 : pfree(ptr);
10651 scrappy@hub.org 165 : 0 : }
|