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