| 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 "preproc_extern.h" |
| 17 | #include "preproc.h" |
| 18 | |
| 19 | /* ScanKeywordList lookup data for ECPG keywords */ |
| 20 | #include "ecpg_kwlist_d.h" |
| 21 | |
| 22 | /* Token codes for ECPG keywords */ |
| 23 | #define PG_KEYWORD(kwname, value) value, |
| 24 | |
| 25 | static const uint16 ECPGScanKeywordTokens[] = { |
| 26 | #include "ecpg_kwlist.h" |
| 27 | }; |
| 28 | |
| 29 | #undef PG_KEYWORD |
| 30 | |
| 31 | |
| 32 | /* |
| 33 | * ScanECPGKeywordLookup - see if a given word is a keyword |
| 34 | * |
| 35 | * Returns the token value of the keyword, or -1 if no match. |
| 36 | * |
| 37 | * Keywords are matched using the same case-folding rules as in the backend. |
| 38 | */ |
| 39 | int |
| 40 | ScanECPGKeywordLookup(const char *text) |
| 41 | { |
| 42 | int kwnum; |
| 43 | |
| 44 | /* First check SQL symbols defined by the backend. */ |
| 45 | kwnum = ScanKeywordLookup(text, &ScanKeywords); |
| 46 | if (kwnum >= 0) |
| 47 | return SQLScanKeywordTokens[kwnum]; |
| 48 | |
| 49 | /* Try ECPG-specific keywords. */ |
| 50 | kwnum = ScanKeywordLookup(text, &ScanECPGKeywords); |
| 51 | if (kwnum >= 0) |
| 52 | return ECPGScanKeywordTokens[kwnum]; |
| 53 | |
| 54 | return -1; |
| 55 | } |
| 56 | |