1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-21 00:42:43 +03:00

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.)
This commit is contained in:
Tom Lane
2009-07-14 20:24:10 +00:00
parent 0d4899e448
commit 1aa58d3a83
15 changed files with 139 additions and 116 deletions

View File

@@ -1,10 +1,10 @@
/*-------------------------------------------------------------------------
*
* keywords.c
* c_keywords.c
* lexical token lookup for reserved words in postgres embedded SQL
*
* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/c_keywords.c,v 1.23 2009/06/11 14:49:13 momjian Exp $
* §
* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/c_keywords.c,v 1.24 2009/07/14 20:24:10 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include "postgres_fe.h"
@@ -55,8 +55,31 @@ static const ScanKeyword ScanCKeywords[] = {
{"year", YEAR_P, 0},
};
/*
* Do a binary search using plain strcmp() comparison. This is much like
* ScanKeywordLookup(), except we want case-sensitive matching.
*/
const ScanKeyword *
ScanCKeywordLookup(const char *text)
{
return DoLookup(text, &ScanCKeywords[0], endof(ScanCKeywords) - 1);
const ScanKeyword *low = &ScanCKeywords[0];
const ScanKeyword *high = &ScanCKeywords[lengthof(ScanCKeywords) - 1];
while (low <= high)
{
const ScanKeyword *middle;
int difference;
middle = low + (high - low) / 2;
difference = strcmp(middle->name, text);
if (difference == 0)
return middle;
else if (difference < 0)
low = middle + 1;
else
high = middle - 1;
}
return NULL;
}