1 /*-------------------------------------------------------------------------
2 *
3 * ecpg_keywords.c
4 * lexical token lookup for reserved words in postgres embedded SQL
5 *
6 * IDENTIFICATION
7 * src/interfaces/ecpg/preproc/ecpg_keywords.c
8 *
9 *-------------------------------------------------------------------------
10 */
11
12 #include "postgres_fe.h"
13
14 #include <ctype.h>
15
16 #include "extern.h"
17 #include "preproc.h"
18
19 /*
20 * List of (keyword-name, keyword-token-value) pairs.
21 *
22 * !!WARNING!!: This list must be sorted, because binary
23 * search is used to locate entries.
24 */
25 static const ScanKeyword ECPGScanKeywords[] = {
26 /* name, value, category */
27
28 /*
29 * category is not needed in ecpg, it is only here so we can share the
30 * data structure with the backend
31 */
32 {"allocate", SQL_ALLOCATE, 0},
33 {"autocommit", SQL_AUTOCOMMIT, 0},
34 {"bool", SQL_BOOL, 0},
35 {"break", SQL_BREAK, 0},
36 {"cardinality", SQL_CARDINALITY, 0},
37 {"connect", SQL_CONNECT, 0},
38 {"count", SQL_COUNT, 0},
39 {"datetime_interval_code", SQL_DATETIME_INTERVAL_CODE, 0},
40 {"datetime_interval_precision", SQL_DATETIME_INTERVAL_PRECISION, 0},
41 {"describe", SQL_DESCRIBE, 0},
42 {"descriptor", SQL_DESCRIPTOR, 0},
43 {"disconnect", SQL_DISCONNECT, 0},
44 {"found", SQL_FOUND, 0},
45 {"free", SQL_FREE, 0},
46 {"get", SQL_GET, 0},
47 {"go", SQL_GO, 0},
48 {"goto", SQL_GOTO, 0},
49 {"identified", SQL_IDENTIFIED, 0},
50 {"indicator", SQL_INDICATOR, 0},
51 {"key_member", SQL_KEY_MEMBER, 0},
52 {"length", SQL_LENGTH, 0},
53 {"long", SQL_LONG, 0},
54 {"nullable", SQL_NULLABLE, 0},
55 {"octet_length", SQL_OCTET_LENGTH, 0},
56 {"open", SQL_OPEN, 0},
57 {"output", SQL_OUTPUT, 0},
58 {"reference", SQL_REFERENCE, 0},
59 {"returned_length", SQL_RETURNED_LENGTH, 0},
60 {"returned_octet_length", SQL_RETURNED_OCTET_LENGTH, 0},
61 {"scale", SQL_SCALE, 0},
62 {"section", SQL_SECTION, 0},
63 {"short", SQL_SHORT, 0},
64 {"signed", SQL_SIGNED, 0},
65 {"sqlerror", SQL_SQLERROR, 0},
66 {"sqlprint", SQL_SQLPRINT, 0},
67 {"sqlwarning", SQL_SQLWARNING, 0},
68 {"stop", SQL_STOP, 0},
69 {"struct", SQL_STRUCT, 0},
70 {"unsigned", SQL_UNSIGNED, 0},
71 {"var", SQL_VAR, 0},
72 {"whenever", SQL_WHENEVER, 0},
73 };
74
75 /*
76 * ScanECPGKeywordLookup - see if a given word is a keyword
77 *
78 * Returns a pointer to the ScanKeyword table entry, or NULL if no match.
79 * Keywords are matched using the same case-folding rules as in the backend.
80 */
81 const ScanKeyword *
ScanECPGKeywordLookup(const char * text)82 ScanECPGKeywordLookup(const char *text)
83 {
84 const ScanKeyword *res;
85
86 /* First check SQL symbols defined by the backend. */
87 res = ScanKeywordLookup(text, SQLScanKeywords, NumSQLScanKeywords);
88 if (res)
89 return res;
90
91 /* Try ECPG-specific keywords. */
92 res = ScanKeywordLookup(text, ECPGScanKeywords, lengthof(ECPGScanKeywords));
93 if (res)
94 return res;
95
96 return NULL;
97 }
98