]> granicus.if.org Git - postgresql/blob - src/backend/parser/keywords.c
I really hope that I haven't missed anything in this one...
[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.38 1998/07/24 03:31:24 scrappy 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         {"action", ACTION},
34         {"add", ADD},
35         {"after", AFTER},
36         {"aggregate", AGGREGATE},
37         {"all", ALL},
38         {"alter", ALTER},
39         {"analyze", ANALYZE},
40         {"and", AND},
41         {"any", ANY},
42         {"archive", ARCHIVE},
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},
70         {"current_date", CURRENT_DATE},
71         {"current_time", CURRENT_TIME},
72         {"current_timestamp", CURRENT_TIMESTAMP},
73         {"current_user", CURRENT_USER},
74         {"cursor", CURSOR},
75         {"cycle", CYCLE},
76         {"database", DATABASE},
77         {"day", DAY_P},
78         {"decimal", DECIMAL},
79         {"declare", DECLARE},
80         {"default", DEFAULT},
81         {"delete", DELETE},
82         {"delimiters", DELIMITERS},
83         {"desc", DESC},
84         {"distinct", DISTINCT},
85         {"do", DO},
86         {"double", DOUBLE},
87         {"drop", DROP},
88         {"each", EACH},
89         {"encoding", ENCODING},
90         {"end", END_TRANS},
91         {"execute", EXECUTE},
92         {"exists", EXISTS},
93         {"explain", EXPLAIN},
94         {"extend", EXTEND},
95         {"extract", EXTRACT},
96         {"false", FALSE_P},
97         {"fetch", FETCH},
98         {"float", FLOAT},
99         {"for", FOR},
100         {"foreign", FOREIGN},
101         {"forward", FORWARD},
102         {"from", FROM},
103         {"full", FULL},
104         {"function", FUNCTION},
105         {"grant", GRANT},
106         {"group", GROUP},
107         {"handler", HANDLER},
108         {"having", HAVING},
109         {"hour", HOUR_P},
110         {"in", IN},
111         {"increment", INCREMENT},
112         {"index", INDEX},
113         {"inherits", INHERITS},
114         {"inner", INNER_P},
115         {"insert", INSERT},
116         {"instead", INSTEAD},
117         {"interval", INTERVAL},
118         {"into", INTO},
119         {"is", IS},
120         {"isnull", ISNULL},
121         {"join", JOIN},
122         {"key", KEY},
123         {"lancompiler", LANCOMPILER},
124         {"language", LANGUAGE},
125         {"leading", LEADING},
126         {"left", LEFT},
127         {"like", LIKE},
128         {"listen", LISTEN},
129         {"load", LOAD},
130         {"local", LOCAL},
131         {"location", LOCATION},
132         {"lock", LOCK_P},
133         {"match", MATCH},
134         {"maxvalue", MAXVALUE},
135         {"minute", MINUTE_P},
136         {"minvalue", MINVALUE},
137         {"month", MONTH_P},
138         {"move", MOVE},
139         {"names", NAMES},
140         {"national", NATIONAL},
141         {"natural", NATURAL},
142         {"nchar", NCHAR},
143         {"new", NEW},
144         {"no", NO},
145         {"nocreatedb", NOCREATEDB},
146         {"nocreateuser", NOCREATEUSER},
147         {"none", NONE},
148         {"not", NOT},
149         {"nothing", NOTHING},
150         {"notify", NOTIFY},
151         {"notnull", NOTNULL},
152         {"null", NULL_P},
153         {"numeric", NUMERIC},
154         {"oids", OIDS},
155         {"on", ON},
156         {"operator", OPERATOR},
157         {"option", OPTION},
158         {"or", OR},
159         {"order", ORDER},
160         {"outer", OUTER_P},
161         {"partial", PARTIAL},
162         {"password", PASSWORD},
163         {"position", POSITION},
164         {"precision", PRECISION},
165         {"primary", PRIMARY},
166         {"privileges", PRIVILEGES},
167         {"procedural", PROCEDURAL},
168         {"procedure", PROCEDURE},
169         {"public", PUBLIC},
170         {"recipe", RECIPE},
171         {"references", REFERENCES},
172         {"rename", RENAME},
173         {"reset", RESET},
174         {"returns", RETURNS},
175         {"revoke", REVOKE},
176         {"right", RIGHT},
177         {"rollback", ROLLBACK},
178         {"row", ROW},
179         {"rule", RULE},
180         {"second", SECOND_P},
181         {"select", SELECT},
182         {"sequence", SEQUENCE},
183         {"set", SET},
184         {"setof", SETOF},
185         {"show", SHOW},
186         {"start", START},
187         {"statement", STATEMENT},
188         {"stdin", STDIN},
189         {"stdout", STDOUT},
190         {"substring", SUBSTRING},
191         {"table", TABLE},
192         {"time", TIME},
193         {"timezone_hour", TIMEZONE_HOUR},
194         {"timezone_minute", TIMEZONE_MINUTE},
195         {"to", TO},
196         {"trailing", TRAILING},
197         {"transaction", TRANSACTION},
198         {"trigger", TRIGGER},
199         {"trim", TRIM},
200         {"true", TRUE_P},
201         {"trusted", TRUSTED},
202         {"type", TYPE_P},
203         {"union", UNION},
204         {"unique", UNIQUE},
205         {"until", UNTIL},
206         {"update", UPDATE},
207         {"user", USER},
208         {"using", USING},
209         {"vacuum", VACUUM},
210         {"valid", VALID},
211         {"values", VALUES},
212         {"varchar", VARCHAR},
213         {"varying", VARYING},
214         {"verbose", VERBOSE},
215         {"version", VERSION},
216         {"view", VIEW},
217         {"where", WHERE},
218         {"with", WITH},
219         {"work", WORK},
220         {"year", YEAR_P},
221         {"zone", ZONE},
222 };
223
224 ScanKeyword *
225 ScanKeywordLookup(char *text)
226 {
227         ScanKeyword *low = &ScanKeywords[0];
228         ScanKeyword *high = endof(ScanKeywords) - 1;
229         ScanKeyword *middle;
230         int                     difference;
231
232         while (low <= high)
233         {
234                 middle = low + (high - low) / 2;
235                 difference = strcmp(middle->name, text);
236                 if (difference == 0)
237                         return (middle);
238                 else if (difference < 0)
239                         low = middle + 1;
240                 else
241                         high = middle - 1;
242         }
243
244         return (NULL);
245 }