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