Commit 3220fd21 authored by Tom Lane's avatar Tom Lane

Tweak scanner/grammar interface so that the keyword-as-identifier rules

in gram.y can make use of the keywords.c string table, instead of having
their own copies of the keyword strings.  This saves a few kilobytes and
more importantly eliminates an opportunity for cut-and-paste errors.
parent 0041a3d7
This diff is collapsed.
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.107 2002/04/21 19:21:49 thomas Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.108 2002/05/02 18:44:10 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -26,7 +26,7 @@
* !!WARNING!!: This list must be sorted, because binary
* search is used to locate entries.
*/
static ScanKeyword ScanKeywords[] = {
static const ScanKeyword ScanKeywords[] = {
/* name, value */
{"abort", ABORT_TRANS},
{"absolute", ABSOLUTE},
......@@ -303,14 +303,14 @@ static ScanKeyword ScanKeywords[] = {
* keywords are to be matched in this way even though non-keyword identifiers
* receive a different case-normalization mapping.
*/
ScanKeyword *
ScanKeywordLookup(char *text)
const ScanKeyword *
ScanKeywordLookup(const char *text)
{
int len,
i;
char word[NAMEDATALEN];
ScanKeyword *low;
ScanKeyword *high;
const ScanKeyword *low;
const ScanKeyword *high;
len = strlen(text);
/* We assume all keywords are shorter than NAMEDATALEN. */
......@@ -342,7 +342,7 @@ ScanKeywordLookup(char *text)
high = endof(ScanKeywords) - 1;
while (low <= high)
{
ScanKeyword *middle;
const ScanKeyword *middle;
int difference;
middle = low + (high - low) / 2;
......
......@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/scan.l,v 1.93 2002/05/01 17:12:07 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/scan.l,v 1.94 2002/05/02 18:44:10 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -504,14 +504,17 @@ other .
{identifier} {
ScanKeyword *keyword;
const ScanKeyword *keyword;
char *ident;
int i;
/* Is it a keyword? */
keyword = ScanKeywordLookup(yytext);
if (keyword != NULL)
{
yylval.keyword = keyword->name;
return keyword->value;
}
/*
* No. Convert the identifier to lower case, and truncate
......
......@@ -3,7 +3,7 @@
* back to source text
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.100 2002/04/28 00:49:13 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.101 2002/05/02 18:44:11 tgl Exp $
*
* This software is copyrighted by Jan Wieck - Hamburg.
*
......@@ -2611,7 +2611,7 @@ quote_identifier(const char *ident)
* Note: ScanKeywordLookup() does case-insensitive comparison, but
* that's fine, since we already know we have all-lower-case.
*/
if (ScanKeywordLookup((char *) ident) != NULL)
if (ScanKeywordLookup(ident) != NULL)
safe = false;
}
......
......@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: keywords.h,v 1.14 2002/04/21 00:26:44 tgl Exp $
* $Id: keywords.h,v 1.15 2002/05/02 18:44:11 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -16,10 +16,10 @@
typedef struct ScanKeyword
{
char *name;
const char *name;
int value;
} ScanKeyword;
extern ScanKeyword *ScanKeywordLookup(char *text);
extern const ScanKeyword *ScanKeywordLookup(const char *text);
#endif /* KEYWORDS_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment