]> granicus.if.org Git - postgresql/blob - src/backend/parser/keywords.c
Implement nested block comments in the backend and in psql.
[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  *        $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.79 2000/07/14 15:43:32 thomas Exp $
12  *
13  *-------------------------------------------------------------------------
14  */
15 #include <ctype.h>
16
17 #include "postgres.h"
18
19 #include "nodes/parsenodes.h"
20 #include "nodes/pg_list.h"
21 #include "parser/keywords.h"
22 #include "parser/parse.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         {"characteristics", CHARACTERISTICS},
61         {"check", CHECK},
62         {"close", CLOSE},
63         {"cluster", CLUSTER},
64         {"coalesce", COALESCE},
65         {"collate", COLLATE},
66         {"column", COLUMN},
67         {"comment", COMMENT},
68         {"commit", COMMIT},
69         {"committed", COMMITTED},
70         {"constraint", CONSTRAINT},
71         {"constraints", CONSTRAINTS},
72         {"copy", COPY},
73         {"create", CREATE},
74         {"createdb", CREATEDB},
75         {"createuser", CREATEUSER},
76         {"cross", CROSS},
77         /* for portability with old rules bjm 2000-06-12 */
78         {"current", OLD},
79         {"current_date", CURRENT_DATE},
80         {"current_time", CURRENT_TIME},
81         {"current_timestamp", CURRENT_TIMESTAMP},
82         {"current_user", CURRENT_USER},
83         {"cursor", CURSOR},
84         {"cycle", CYCLE},
85         {"database", DATABASE},
86         {"day", DAY_P},
87         {"dec", DEC},
88         {"decimal", DECIMAL},
89         {"declare", DECLARE},
90         {"default", DEFAULT},
91         {"deferrable", DEFERRABLE},
92         {"deferred", DEFERRED},
93         {"delete", DELETE},
94         {"delimiters", DELIMITERS},
95         {"desc", DESC},
96         {"distinct", DISTINCT},
97         {"do", DO},
98         {"double", DOUBLE},
99         {"drop", DROP},
100         {"each", EACH},
101         {"else", ELSE},
102         {"encoding", ENCODING},
103         {"end", END_TRANS},
104         {"except", EXCEPT},
105         {"exclusive", EXCLUSIVE},
106         {"execute", EXECUTE},
107         {"exists", EXISTS},
108         {"explain", EXPLAIN},
109         {"extend", EXTEND},
110         {"extract", EXTRACT},
111         {"false", FALSE_P},
112         {"fetch", FETCH},
113         {"float", FLOAT},
114         {"for", FOR},
115         {"force", FORCE},
116         {"foreign", FOREIGN},
117         {"forward", FORWARD},
118         {"from", FROM},
119         {"full", FULL},
120         {"function", FUNCTION},
121         {"global", GLOBAL},
122         {"grant", GRANT},
123         {"group", GROUP},
124         {"handler", HANDLER},
125         {"having", HAVING},
126         {"hour", HOUR_P},
127         {"immediate", IMMEDIATE},
128         {"in", IN},
129         {"increment", INCREMENT},
130         {"index", INDEX},
131         {"inherits", INHERITS},
132         {"initially", INITIALLY},
133         {"inner", INNER_P},
134         {"inout", INOUT},
135         {"insensitive", INSENSITIVE},
136         {"insert", INSERT},
137         {"instead", INSTEAD},
138         {"intersect", INTERSECT},
139         {"interval", INTERVAL},
140         {"into", INTO},
141         {"is", IS},
142         {"isnull", ISNULL},
143         {"isolation", ISOLATION},
144         {"join", JOIN},
145         {"key", KEY},
146         {"lancompiler", LANCOMPILER},
147         {"language", LANGUAGE},
148         {"leading", LEADING},
149         {"left", LEFT},
150         {"level", LEVEL},
151         {"like", LIKE},
152         {"limit", LIMIT},
153         {"listen", LISTEN},
154         {"load", LOAD},
155         {"local", LOCAL},
156         {"location", LOCATION},
157         {"lock", LOCK_P},
158         {"match", MATCH},
159         {"maxvalue", MAXVALUE},
160         {"minute", MINUTE_P},
161         {"minvalue", MINVALUE},
162         {"mode", MODE},
163         {"month", MONTH_P},
164         {"move", MOVE},
165         {"names", NAMES},
166         {"national", NATIONAL},
167         {"natural", NATURAL},
168         {"nchar", NCHAR},
169         {"new", NEW},
170         {"next", NEXT},
171         {"no", NO},
172         {"nocreatedb", NOCREATEDB},
173         {"nocreateuser", NOCREATEUSER},
174         {"none", NONE},
175         {"not", NOT},
176         {"nothing", NOTHING},
177         {"notify", NOTIFY},
178         {"notnull", NOTNULL},
179         {"null", NULL_P},
180         {"nullif", NULLIF},
181         {"numeric", NUMERIC},
182         {"of", OF},
183         {"off", OFF},
184         {"offset", OFFSET},
185         {"oids", OIDS},
186         {"old", OLD},
187         {"on", ON},
188         {"only", ONLY},
189         {"operator", OPERATOR},
190         {"option", OPTION},
191         {"or", OR},
192         {"order", ORDER},
193         {"out", OUT},
194         {"outer", OUTER_P},
195         {"overlaps", OVERLAPS},
196         {"partial", PARTIAL},
197         {"password", PASSWORD},
198         {"path", PATH_P},
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         {"schema", SCHEMA},
222         {"scroll", SCROLL},
223         {"second", SECOND_P},
224         {"select", SELECT},
225         {"sequence", SEQUENCE},
226         {"serial", SERIAL},
227         {"serializable", SERIALIZABLE},
228         {"session", SESSION},
229         {"session_user", SESSION_USER},
230         {"set", SET},
231         {"setof", SETOF},
232         {"share", SHARE},
233         {"show", SHOW},
234         {"some", SOME},
235         {"start", START},
236         {"statement", STATEMENT},
237         {"stdin", STDIN},
238         {"stdout", STDOUT},
239         {"substring", SUBSTRING},
240         {"sysid", SYSID},
241         {"table", TABLE},
242         {"temp", TEMP},
243         {"temporary", TEMPORARY},
244         {"then", THEN},
245         {"time", TIME},
246         {"timestamp", TIMESTAMP},
247         {"timezone_hour", TIMEZONE_HOUR},
248         {"timezone_minute", TIMEZONE_MINUTE},
249         {"to", TO},
250         {"toast", TOAST},
251         {"trailing", TRAILING},
252         {"transaction", TRANSACTION},
253         {"trigger", TRIGGER},
254         {"trim", TRIM},
255         {"true", TRUE_P},
256         {"truncate", TRUNCATE},
257         {"trusted", TRUSTED},
258         {"type", TYPE_P},
259         {"under", UNDER},
260         {"union", UNION},
261         {"unique", UNIQUE},
262         {"unlisten", UNLISTEN},
263         {"until", UNTIL},
264         {"update", UPDATE},
265         {"user", USER},
266         {"using", USING},
267         {"vacuum", VACUUM},
268         {"valid", VALID},
269         {"values", VALUES},
270         {"varchar", VARCHAR},
271         {"varying", VARYING},
272         {"verbose", VERBOSE},
273         {"version", VERSION},
274         {"view", VIEW},
275         {"when", WHEN},
276         {"where", WHERE},
277         {"with", WITH},
278         {"without", WITHOUT},
279         {"work", WORK},
280         {"year", YEAR_P},
281         {"zone", ZONE},
282 };
283
284 ScanKeyword *
285 ScanKeywordLookup(char *text)
286 {
287         ScanKeyword *low = &ScanKeywords[0];
288         ScanKeyword *high = endof(ScanKeywords) - 1;
289         ScanKeyword *middle;
290         int                     difference;
291
292         while (low <= high)
293         {
294                 middle = low + (high - low) / 2;
295                 difference = strcmp(middle->name, text);
296                 if (difference == 0)
297                         return middle;
298                 else if (difference < 0)
299                         low = middle + 1;
300                 else
301                         high = middle - 1;
302         }
303
304         return NULL;
305 }