1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
/*-------------------------------------------------------------------------
*
* keywords.c--
* lexical token lookup for reserved words in postgres SQL
*
* Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.3 1996/08/24 20:48:46 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
#include <ctype.h>
#include <string.h>
#include "postgres.h"
#include "nodes/pg_list.h"
#include "nodes/parsenodes.h"
#include "parse.h"
#include "utils/elog.h"
#include "parser/keywords.h"
#include "parser/dbcommands.h" /* createdb, destroydb stop_vacuum */
/*
* List of (keyword-name, keyword-token-value) pairs.
*
* !!WARNING!!: This list must be sorted, because binary
* search is used to locate entries.
*/
static ScanKeyword ScanKeywords[] = {
/* name value */
{ "abort", ABORT_TRANS },
{ "acl", ACL },
{ "add", ADD },
{ "after", AFTER },
{ "aggregate", AGGREGATE },
{ "all", ALL },
{ "alter", ALTER },
{ "and", AND },
{ "append", APPEND },
{ "archIve", ARCHIVE }, /* XXX crooked: I < _ */
{ "arch_store", ARCH_STORE },
{ "archive", ARCHIVE }, /* XXX crooked: i > _ */
{ "as", AS },
{ "asc", ASC },
{ "backward", BACKWARD },
{ "before", BEFORE },
{ "begin", BEGIN_TRANS },
{ "binary", BINARY },
{ "by", BY },
{ "cast", CAST },
{ "change", CHANGE },
{ "close", CLOSE },
{ "cluster", CLUSTER },
{ "column", COLUMN },
{ "commit", COMMIT },
{ "copy", COPY },
{ "create", CREATE },
{ "current", CURRENT },
{ "cursor", CURSOR },
{ "database", DATABASE },
{ "declare", DECLARE },
{ "delete", DELETE },
{ "delimiters", DELIMITERS },
{ "desc", DESC },
{ "distinct", DISTINCT },
{ "do", DO },
{ "drop", DROP },
{ "end", END_TRANS },
{ "execute", EXECUTE },
{ "explain", EXPLAIN },
{ "extend", EXTEND },
{ "fetch", FETCH },
{ "for", FOR },
{ "forward", FORWARD },
{ "from", FROM },
{ "function", FUNCTION },
{ "grant", GRANT },
{ "group", GROUP },
{ "having", HAVING },
{ "heavy", HEAVY },
{ "in", IN },
{ "index", INDEX },
{ "inherits", INHERITS },
{ "insert", INSERT },
{ "instead", INSTEAD },
{ "into", INTO },
{ "is", IS },
{ "isnull", ISNULL },
{ "language", LANGUAGE },
{ "light", LIGHT },
{ "like", LIKE },
{ "listen", LISTEN },
{ "load", LOAD },
{ "merge", MERGE },
{ "move", MOVE },
{ "new", NEW },
{ "none", NONE },
{ "not", NOT },
{ "nothing", NOTHING },
{ "notify", NOTIFY },
{ "notnull", NOTNULL },
{ "null", PNULL },
{ "oids", OIDS },
{ "on", ON },
{ "operator", OPERATOR },
{ "option", OPTION },
{ "or", OR },
{ "order", ORDER },
{ "privileges", PRIVILEGES },
{ "public", PUBLIC },
{ "purge", PURGE },
{ "recipe", RECIPE },
{ "rename", RENAME },
{ "replace", REPLACE },
{ "retrieve", RETRIEVE },
{ "returns", RETURNS },
{ "revoke", REVOKE },
{ "rollback", ROLLBACK },
{ "rule", RULE },
{ "select", SELECT },
{ "set", SET },
{ "setof", SETOF },
{ "stdin", STDIN },
{ "stdout", STDOUT },
{ "store", STORE },
{ "table", TABLE },
{ "to", TO },
{ "transaction", TRANSACTION },
{ "type", P_TYPE },
{ "update", UPDATE },
{ "using", USING },
{ "vacuum", VACUUM },
{ "values", VALUES },
{ "version", VERSION },
{ "view", VIEW },
{ "where", WHERE },
{ "with", WITH },
{ "work", WORK },
};
ScanKeyword *
ScanKeywordLookup(char *text)
{
ScanKeyword *low = &ScanKeywords[0];
ScanKeyword *high = endof(ScanKeywords) - 1;
ScanKeyword *middle;
int difference;
while (low <= high) {
middle = low + (high - low) / 2;
/* keywords case-insensitive (for SQL) -- ay 8/94 */
difference = strcasecmp(middle->name, text);
if (difference == 0)
return (middle);
else if (difference < 0)
low = middle + 1;
else
high = middle - 1;
}
return (NULL);
}
char*
AtomValueGetString(int atomval)
{
ScanKeyword *low = &ScanKeywords[0];
ScanKeyword *high = endof(ScanKeywords) - 1;
int keyword_list_length = (high-low);
int i;
for (i=0; i < keyword_list_length ; i++ )
if (ScanKeywords[i].value == atomval )
return(ScanKeywords[i].name);
elog(WARN,"AtomGetString called with bogus atom # : %d", atomval );
return(NULL);
}
|