]> granicus.if.org Git - postgresql/blob - src/backend/parser/keywords.c
cleanup of keywords.c
[postgresql] / src / backend / parser / keywords.c
1 /*-------------------------------------------------------------------------
2  *
3  * keywords.c--
4  *        lexical token lookup for reserved words in postgres SQL
5  *
6  * Copyright (c) 1994, Regents of the University of California
7  *
8  *
9  * IDENTIFICATION
10  *        $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.48 1998/10/18 23:30:17 momjian Exp $
11  *
12  *-------------------------------------------------------------------------
13  */
14 #include <ctype.h>
15 #include <string.h>
16
17 #include "postgres.h"
18 #include "nodes/parsenodes.h"
19 #include "nodes/pg_list.h"
20 #include "parse.h"
21 #include "parser/keywords.h"
22 #include "utils/elog.h"
23
24 /*
25  * List of (keyword-name, keyword-token-value) pairs.
26  *
27  * !!WARNING!!: This list must be sorted, because binary
28  *               search is used to locate entries.
29  */
30 static ScanKeyword ScanKeywords[] = {
31         /* name, value */
32         {"abort", ABORT_TRANS},
33         {"absolute", ABSOLUTE},
34         {"action", ACTION},
35         {"add", ADD},
36         {"after", AFTER},
37         {"aggregate", AGGREGATE},
38         {"all", ALL},
39         {"alter", ALTER},
40         {"analyze", ANALYZE},
41         {"and", AND},
42         {"any", ANY},
43         {"as", AS},
44         {"asc", ASC},
45         {"backward", BACKWARD},
46         {"before", BEFORE},
47         {"begin", BEGIN_TRANS},
48         {"between", BETWEEN},
49         {"binary", BINARY},
50         {"both", BOTH},
51         {"by", BY},
52         {"cache", CACHE},
53         {"cascade", CASCADE},
54         {"cast", CAST},
55         {"char", CHAR},
56         {"character", CHARACTER},
57         {"check", CHECK},
58         {"close", CLOSE},
59         {"cluster", CLUSTER},
60         {"collate", COLLATE},
61         {"column", COLUMN},
62         {"commit", COMMIT},
63         {"constraint", CONSTRAINT},
64         {"copy", COPY},
65         {"create", CREATE},
66         {"createdb", CREATEDB},
67         {"createuser", CREATEUSER},
68         {"cross", CROSS},
69         {"current", CURRENT},           /* 6.4 to 6.5 is migration time! CURRENT
70                                                                  * will be removed in 6.5! Use OLD keyword
71                                                                  * in rules. Jan */
72         {"current_date", CURRENT_DATE},
73         {"current_time", CURRENT_TIME},
74         {"current_timestamp", CURRENT_TIMESTAMP},
75         {"current_user", CURRENT_USER},
76         {"cursor", CURSOR},
77         {"cycle", CYCLE},
78         {"database", DATABASE},
79         {"day", DAY_P},
80         {"decimal", DECIMAL},
81         {"declare", DECLARE},
82         {"default", DEFAULT},
83         {"delete", DELETE},
84         {"delimiters", DELIMITERS},
85         {"desc", DESC},
86         {"distinct", DISTINCT},
87         {"do", DO},
88         {"double", DOUBLE},
89         {"drop", DROP},
90         {"each", EACH},
91         {"encoding", ENCODING},
92         {"end", END_TRANS},
93         {"execute", EXECUTE},
94         {"exists", EXISTS},
95         {"explain", EXPLAIN},
96         {"extend", EXTEND},
97         {"extract", EXTRACT},
98         {"false", FALSE_P},
99         {"fetch", FETCH},
100         {"float", FLOAT},
101         {"for", FOR},
102         {"foreign", FOREIGN},
103         {"forward", FORWARD},
104         {"from", FROM},
105         {"full", FULL},
106         {"function", FUNCTION},
107         {"grant", GRANT},
108         {"group", GROUP},
109         {"handler", HANDLER},
110         {"having", HAVING},
111         {"hour", HOUR_P},
112         {"in", IN},
113         {"increment", INCREMENT},
114         {"index", INDEX},
115         {"inherits", INHERITS},
116         {"inner", INNER_P},
117         {"insensitive", INSENSITIVE},
118         {"insert", INSERT},
119         {"instead", INSTEAD},
120         {"interval", INTERVAL},
121         {"into", INTO},
122         {"is", IS},
123         {"isnull", ISNULL},
124         {"join", JOIN},
125         {"key", KEY},
126         {"lancompiler", LANCOMPILER},
127         {"language", LANGUAGE},
128         {"leading", LEADING},
129         {"left", LEFT},
130         {"like", LIKE},
131         {"listen", LISTEN},
132         {"load", LOAD},
133         {"local", LOCAL},
134         {"location", LOCATION},
135         {"lock", LOCK_P},
136         {"match", MATCH},
137         {"maxvalue", MAXVALUE},
138         {"minute", MINUTE_P},
139         {"minvalue", MINVALUE},
140         {"month", MONTH_P},
141         {"move", MOVE},
142         {"names", NAMES},
143         {"national", NATIONAL},
144         {"natural", NATURAL},
145         {"nchar", NCHAR},
146         {"new", NEW},
147         {"next", NEXT},
148         {"no", NO},
149         {"nocreatedb", NOCREATEDB},
150         {"nocreateuser", NOCREATEUSER},
151         {"none", NONE},
152         {"not", NOT},
153         {"nothing", NOTHING},
154         {"notify", NOTIFY},
155         {"notnull", NOTNULL},
156         {"null", NULL_P},
157         {"numeric", NUMERIC},
158         {"of", OF},
159         {"oids", OIDS},
160         {"old", CURRENT},
161         {"on", ON},
162         {"only", ONLY},
163         {"operator", OPERATOR},
164         {"option", OPTION},
165         {"or", OR},
166         {"order", ORDER},
167         {"outer", OUTER_P},
168         {"partial", PARTIAL},
169         {"password", PASSWORD},
170         {"position", POSITION},
171         {"precision", PRECISION},
172         {"primary", PRIMARY},
173         {"prior", PRIOR},
174         {"privileges", PRIVILEGES},
175         {"procedural", PROCEDURAL},
176         {"procedure", PROCEDURE},
177         {"public", PUBLIC},
178         {"read", READ},
179         {"recipe", RECIPE},
180         {"references", REFERENCES},
181         {"relative", RELATIVE},
182         {"rename", RENAME},
183         {"reset", RESET},
184         {"returns", RETURNS},
185         {"revoke", REVOKE},
186         {"right", RIGHT},
187         {"rollback", ROLLBACK},
188         {"row", ROW},
189         {"rule", RULE},
190         {"scroll", SCROLL},
191         {"second", SECOND_P},
192         {"select", SELECT},
193         {"sequence", SEQUENCE},
194         {"serial", SERIAL},
195         {"set", SET},
196         {"setof", SETOF},
197         {"show", SHOW},
198         {"start", START},
199         {"statement", STATEMENT},
200         {"stdin", STDIN},
201         {"stdout", STDOUT},
202         {"substring", SUBSTRING},
203         {"table", TABLE},
204         {"time", TIME},
205         {"timestamp", TIMESTAMP},
206         {"timezone_hour", TIMEZONE_HOUR},
207         {"timezone_minute", TIMEZONE_MINUTE},
208         {"to", TO},
209         {"trailing", TRAILING},
210         {"transaction", TRANSACTION},
211         {"trigger", TRIGGER},
212         {"trim", TRIM},
213         {"true", TRUE_P},
214         {"trusted", TRUSTED},
215         {"type", TYPE_P},
216         {"union", UNION},
217         {"unique", UNIQUE},
218         {"unlisten", UNLISTEN},
219         {"until", UNTIL},
220         {"update", UPDATE},
221         {"user", USER},
222         {"using", USING},
223         {"vacuum", VACUUM},
224         {"valid", VALID},
225         {"values", VALUES},
226         {"varchar", VARCHAR},
227         {"varying", VARYING},
228         {"verbose", VERBOSE},
229         {"version", VERSION},
230         {"view", VIEW},
231         {"where", WHERE},
232         {"with", WITH},
233         {"work", WORK},
234         {"year", YEAR_P},
235         {"zone", ZONE},
236 };
237
238 ScanKeyword *
239 ScanKeywordLookup(char *text)
240 {
241         ScanKeyword *low = &ScanKeywords[0];
242         ScanKeyword *high = endof(ScanKeywords) - 1;
243         ScanKeyword *middle;
244         int                     difference;
245
246         while (low <= high)
247         {
248                 middle = low + (high - low) / 2;
249                 difference = strcmp(middle->name, text);
250                 if (difference == 0)
251                         return middle;
252                 else if (difference < 0)
253                         low = middle + 1;
254                 else
255                         high = middle - 1;
256         }
257
258         return NULL;
259 }