]> granicus.if.org Git - postgresql/blob - src/backend/bootstrap/bootscanner.l
Make all our flex and bison files use %option prefix or %name-prefix
[postgresql] / src / backend / bootstrap / bootscanner.l
1 %{
2 /*-------------------------------------------------------------------------
3  *
4  * bootscanner.l
5  *        a lexical scanner for the bootstrap parser
6  *
7  * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  *
11  * IDENTIFICATION
12  *        $PostgreSQL: pgsql/src/backend/bootstrap/bootscanner.l,v 1.42 2006/03/07 01:03:12 tgl Exp $
13  *
14  *-------------------------------------------------------------------------
15  */
16 #include "postgres.h"
17
18 #include "access/attnum.h"
19 #include "access/htup.h"
20 #include "access/itup.h"
21 #include "access/skey.h"
22 #include "access/tupdesc.h"
23 #include "bootstrap/bootstrap.h"
24 #include "catalog/pg_am.h"
25 #include "catalog/pg_attribute.h"
26 #include "catalog/pg_class.h"
27 #include "nodes/nodes.h"
28 #include "nodes/parsenodes.h"
29 #include "nodes/pg_list.h"
30 #include "nodes/primnodes.h"
31 #include "parser/scansup.h"
32 #include "rewrite/prs2lock.h"
33 #include "storage/block.h"
34 #include "storage/fd.h"
35 #include "storage/itemptr.h"
36 #include "storage/off.h"
37 #include "utils/rel.h"
38
39 /* Not needed now that this file is compiled as part of bootparse. */
40 /* #include "bootstrap_tokens.h" */
41
42
43 /* Avoid exit() on fatal scanner errors (a bit ugly -- see yy_fatal_error) */
44 #undef fprintf
45 #define fprintf(file, fmt, msg)  ereport(ERROR, (errmsg_internal("%s", msg)))
46
47
48 static int      yyline = 1;                     /* line number for error reporting */
49
50 %}
51
52 %option 8bit
53 %option never-interactive
54 %option nodefault
55 %option nounput
56 %option noyywrap
57 %option prefix="boot_yy"
58
59
60 D               [0-9]
61 oct             \\{D}{D}{D}
62 Exp             [Ee][-+]?{D}+
63 id              ([A-Za-z0-9_]|{oct}|\-)+
64 sid             \"([^\"])*\"
65 arrayid [A-Za-z0-9_]+\[{D}*\]
66
67 %%
68
69 open                    { return(OPEN); }
70
71 close                   { return(XCLOSE); }
72
73 create                  { return(XCREATE); }
74
75 OID                             { return(OBJ_ID); }
76 bootstrap               { return(XBOOTSTRAP); }
77 "shared_relation"       { return(XSHARED_RELATION); }
78 "without_oids"  { return(XWITHOUT_OIDS); }
79 _null_                  { return(NULLVAL); }
80
81 insert                  { return(INSERT_TUPLE); }
82
83 ","                             { return(COMMA); }
84 "="                             { return(EQUALS); }
85 "("                             { return(LPAREN); }
86 ")"                             { return(RPAREN); }
87
88 [\n]                    { yyline++; }
89 [\t]                    ;
90 " "                             ;
91
92 ^\#[^\n]* ; /* drop everything after "#" for comments */
93
94
95 "declare"               { return(XDECLARE); }
96 "build"                 { return(XBUILD); }
97 "indices"               { return(INDICES); }
98 "unique"                { return(UNIQUE); }
99 "index"                 { return(INDEX); }
100 "on"                    { return(ON); }
101 "using"                 { return(USING); }
102
103 {arrayid}               {
104                                         yylval.ival = EnterString(MapArrayTypeName((char*)yytext));
105                                         return(ID);
106                                 }
107 {id}                    {
108                                         char   *newid = scanstr((char*)yytext);
109                                         yylval.ival = EnterString(newid);
110                                         pfree(newid);
111                                         return(ID);
112                                 }
113 {sid}                   {
114                                         char   *newid;
115                                         yytext[strlen(yytext)-1] = '\0'; /* strip off quotes */
116                                         newid = scanstr((char*)yytext+1);
117                                         yylval.ival = EnterString(newid);
118                                         pfree(newid);
119                                         yytext[strlen(yytext)] = '"'; /* restore quotes */
120                                         return(ID);
121                                 }
122
123 (-)?{D}+"."{D}*({Exp})? |
124 (-)?{D}*"."{D}+({Exp})? |
125 (-)?{D}+{Exp}                   {
126                                                         yylval.ival = EnterString((char*)yytext);
127                                                         return(CONST_P);
128                                                 }
129
130 .                               {
131                                         elog(ERROR, "syntax error at line %d: unexpected character \"%s\"", yyline, yytext);
132                                 }
133
134
135
136 %%
137
138 void
139 yyerror(const char *message)
140 {
141         elog(ERROR, "%s at line %d", message, yyline);
142 }