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