diff options
| author | Tom Lane <tgl@sss.pgh.pa.us> | 2009-07-14 20:24:10 +0000 |
|---|---|---|
| committer | Tom Lane <tgl@sss.pgh.pa.us> | 2009-07-14 20:24:10 +0000 |
| commit | 1aa58d3a8389fcf8899745049f128f6b8fec7bc9 (patch) | |
| tree | 2e36e9cf65a517ce558fbfe694821da5bb28c131 /src/interfaces/ecpg/preproc/ecpg_keywords.c | |
| parent | 0d4899e448df2b02434d6d423156408cde012707 (diff) | |
| download | postgresql-1aa58d3a8389fcf8899745049f128f6b8fec7bc9.tar.gz | |
Tweak the core scanner so that it can be used by plpgsql too.
Changes:
Pass in the keyword lookup array instead of having it be hardwired.
(This incidentally allows elimination of some duplicate coding in ecpg.)
Re-order the token declarations in gram.y so that non-keyword tokens have
numbers that won't change when keywords are added or removed.
Add ".." and ":=" to the set of tokens recognized by scan.l. (Since these
combinations are nowhere legal in core SQL, this does not change anything
except the precise wording of the error you get when you write this.)
Diffstat (limited to 'src/interfaces/ecpg/preproc/ecpg_keywords.c')
| -rw-r--r-- | src/interfaces/ecpg/preproc/ecpg_keywords.c | 69 |
1 files changed, 8 insertions, 61 deletions
diff --git a/src/interfaces/ecpg/preproc/ecpg_keywords.c b/src/interfaces/ecpg/preproc/ecpg_keywords.c index 0aef816169..c475bf9671 100644 --- a/src/interfaces/ecpg/preproc/ecpg_keywords.c +++ b/src/interfaces/ecpg/preproc/ecpg_keywords.c @@ -4,7 +4,7 @@ * lexical token lookup for reserved words in postgres embedded SQL * * IDENTIFICATION - * $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg_keywords.c,v 1.40 2009/06/11 14:49:13 momjian Exp $ + * $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg_keywords.c,v 1.41 2009/07/14 20:24:10 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -75,79 +75,26 @@ static const ScanKeyword ScanECPGKeywords[] = { {"whenever", SQL_WHENEVER, 0}, }; -/* This is all taken from src/backend/parser/keyword.c and adjusted for our needs. */ -/* - * Do a binary search using plain strcmp() comparison. - */ -const ScanKeyword * -DoLookup(const char *word, const ScanKeyword *low, const ScanKeyword *high) -{ - while (low <= high) - { - const ScanKeyword *middle; - int difference; - - middle = low + (high - low) / 2; - difference = strcmp(middle->name, word); - if (difference == 0) - return middle; - else if (difference < 0) - low = middle + 1; - else - high = middle - 1; - } - - return NULL; -} - /* * ScanECPGKeywordLookup - see if a given word is a keyword * * Returns a pointer to the ScanKeyword table entry, or NULL if no match. - * - * The match is done case-insensitively. Note that we deliberately use a - * dumbed-down case conversion that will only translate 'A'-'Z' into 'a'-'z', - * even if we are in a locale where tolower() would produce more or different - * translations. This is to conform to the SQL99 spec, which says that - * keywords are to be matched in this way even though non-keyword identifiers - * receive a different case-normalization mapping. + * Keywords are matched using the same case-folding rules as in the backend. */ const ScanKeyword * ScanECPGKeywordLookup(const char *text) { - int len, - i; - char word[NAMEDATALEN]; const ScanKeyword *res; /* First check SQL symbols defined by the backend. */ - - res = ScanKeywordLookup(text); + res = ScanKeywordLookup(text, ScanKeywords, NumScanKeywords); if (res) return res; - len = strlen(text); - /* We assume all keywords are shorter than NAMEDATALEN. */ - if (len >= NAMEDATALEN) - return NULL; - - /* - * Apply an ASCII-only downcasing. We must not use tolower() since it may - * produce the wrong translation in some locales (eg, Turkish). - */ - for (i = 0; i < len; i++) - { - char ch = text[i]; - - if (ch >= 'A' && ch <= 'Z') - ch += 'a' - 'A'; - word[i] = ch; - } - word[len] = '\0'; - - /* - * Now do a binary search using plain strcmp() comparison. - */ + /* Try ECPG-specific keywords. */ + res = ScanKeywordLookup(text, ScanECPGKeywords, lengthof(ScanECPGKeywords)); + if (res) + return res; - return DoLookup(word, &ScanECPGKeywords[0], endof(ScanECPGKeywords) - 1); + return NULL; } |
