]> granicus.if.org Git - postgresql/blob - src/backend/parser/keywords.c
OK, folks, here is the pgindent output.
[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.44 1998/09/01 04:30:23 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         {"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},           /* 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         {"insert", INSERT},
118         {"instead", INSTEAD},
119         {"interval", INTERVAL},
120         {"into", INTO},
121         {"is", IS},
122         {"isnull", ISNULL},
123         {"join", JOIN},
124         {"key", KEY},
125         {"lancompiler", LANCOMPILER},
126         {"language", LANGUAGE},
127         {"leading", LEADING},
128         {"left", LEFT},
129         {"like", LIKE},
130         {"listen", LISTEN},
131         {"load", LOAD},
132         {"local", LOCAL},
133         {"location", LOCATION},
134         {"lock", LOCK_P},
135         {"match", MATCH},
136         {"maxvalue", MAXVALUE},
137         {"minute", MINUTE_P},
138         {"minvalue", MINVALUE},
139         {"month", MONTH_P},
140         {"move", MOVE},
141         {"names", NAMES},
142         {"national", NATIONAL},
143         {"natural", NATURAL},
144         {"nchar", NCHAR},
145         {"new", NEW},
146         {"no", NO},
147         {"nocreatedb", NOCREATEDB},
148         {"nocreateuser", NOCREATEUSER},
149         {"none", NONE},
150         {"not", NOT},
151         {"nothing", NOTHING},
152         {"notify", NOTIFY},
153         {"notnull", NOTNULL},
154         {"null", NULL_P},
155         {"numeric", NUMERIC},
156         {"oids", OIDS},
157         {"old", CURRENT},
158         {"on", ON},
159         {"operator", OPERATOR},
160         {"option", OPTION},
161         {"or", OR},
162         {"order", ORDER},
163         {"outer", OUTER_P},
164         {"partial", PARTIAL},
165         {"password", PASSWORD},
166         {"position", POSITION},
167         {"precision", PRECISION},
168         {"primary", PRIMARY},
169         {"privileges", PRIVILEGES},
170         {"procedural", PROCEDURAL},
171         {"procedure", PROCEDURE},
172         {"public", PUBLIC},
173         {"recipe", RECIPE},
174         {"references", REFERENCES},
175         {"rename", RENAME},
176         {"reset", RESET},
177         {"returns", RETURNS},
178         {"revoke", REVOKE},
179         {"right", RIGHT},
180         {"rollback", ROLLBACK},
181         {"row", ROW},
182         {"rule", RULE},
183         {"second", SECOND_P},
184         {"select", SELECT},
185         {"sequence", SEQUENCE},
186         {"serial", SERIAL},
187         {"set", SET},
188         {"setof", SETOF},
189         {"show", SHOW},
190         {"start", START},
191         {"statement", STATEMENT},
192         {"stdin", STDIN},
193         {"stdout", STDOUT},
194         {"substring", SUBSTRING},
195         {"table", TABLE},
196         {"time", TIME},
197         {"timezone_hour", TIMEZONE_HOUR},
198         {"timezone_minute", TIMEZONE_MINUTE},
199         {"to", TO},
200         {"trailing", TRAILING},
201         {"transaction", TRANSACTION},
202         {"trigger", TRIGGER},
203         {"trim", TRIM},
204         {"true", TRUE_P},
205         {"trusted", TRUSTED},
206         {"type", TYPE_P},
207         {"union", UNION},
208         {"unique", UNIQUE},
209         {"unlisten", UNLISTEN},
210         {"until", UNTIL},
211         {"update", UPDATE},
212         {"user", USER},
213         {"using", USING},
214         {"vacuum", VACUUM},
215         {"valid", VALID},
216         {"values", VALUES},
217         {"varchar", VARCHAR},
218         {"varying", VARYING},
219         {"verbose", VERBOSE},
220         {"version", VERSION},
221         {"view", VIEW},
222         {"where", WHERE},
223         {"with", WITH},
224         {"work", WORK},
225         {"year", YEAR_P},
226         {"zone", ZONE},
227 };
228
229 ScanKeyword *
230 ScanKeywordLookup(char *text)
231 {
232         ScanKeyword *low = &ScanKeywords[0];
233         ScanKeyword *high = endof(ScanKeywords) - 1;
234         ScanKeyword *middle;
235         int                     difference;
236
237         while (low <= high)
238         {
239                 middle = low + (high - low) / 2;
240                 difference = strcmp(middle->name, text);
241                 if (difference == 0)
242                         return middle;
243                 else if (difference < 0)
244                         low = middle + 1;
245                 else
246                         high = middle - 1;
247         }
248
249         return NULL;
250 }