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 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * 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 @@ ...@@ -26,7 +26,7 @@
* !!WARNING!!: This list must be sorted, because binary * !!WARNING!!: This list must be sorted, because binary
* search is used to locate entries. * search is used to locate entries.
*/ */
static ScanKeyword ScanKeywords[] = { static const ScanKeyword ScanKeywords[] = {
/* name, value */ /* name, value */
{"abort", ABORT_TRANS}, {"abort", ABORT_TRANS},
{"absolute", ABSOLUTE}, {"absolute", ABSOLUTE},
...@@ -303,14 +303,14 @@ static ScanKeyword ScanKeywords[] = { ...@@ -303,14 +303,14 @@ static ScanKeyword ScanKeywords[] = {
* keywords are to be matched in this way even though non-keyword identifiers * keywords are to be matched in this way even though non-keyword identifiers
* receive a different case-normalization mapping. * receive a different case-normalization mapping.
*/ */
ScanKeyword * const ScanKeyword *
ScanKeywordLookup(char *text) ScanKeywordLookup(const char *text)
{ {
int len, int len,
i; i;
char word[NAMEDATALEN]; char word[NAMEDATALEN];
ScanKeyword *low; const ScanKeyword *low;
ScanKeyword *high; const ScanKeyword *high;
len = strlen(text); len = strlen(text);
/* We assume all keywords are shorter than NAMEDATALEN. */ /* We assume all keywords are shorter than NAMEDATALEN. */
...@@ -342,7 +342,7 @@ ScanKeywordLookup(char *text) ...@@ -342,7 +342,7 @@ ScanKeywordLookup(char *text)
high = endof(ScanKeywords) - 1; high = endof(ScanKeywords) - 1;
while (low <= high) while (low <= high)
{ {
ScanKeyword *middle; const ScanKeyword *middle;
int difference; int difference;
middle = low + (high - low) / 2; middle = low + (high - low) / 2;
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * 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 . ...@@ -504,14 +504,17 @@ other .
{identifier} { {identifier} {
ScanKeyword *keyword; const ScanKeyword *keyword;
char *ident; char *ident;
int i; int i;
/* Is it a keyword? */ /* Is it a keyword? */
keyword = ScanKeywordLookup(yytext); keyword = ScanKeywordLookup(yytext);
if (keyword != NULL) if (keyword != NULL)
{
yylval.keyword = keyword->name;
return keyword->value; return keyword->value;
}
/* /*
* No. Convert the identifier to lower case, and truncate * No. Convert the identifier to lower case, and truncate
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* back to source text * back to source text
* *
* IDENTIFICATION * 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. * This software is copyrighted by Jan Wieck - Hamburg.
* *
...@@ -2611,7 +2611,7 @@ quote_identifier(const char *ident) ...@@ -2611,7 +2611,7 @@ quote_identifier(const char *ident)
* Note: ScanKeywordLookup() does case-insensitive comparison, but * Note: ScanKeywordLookup() does case-insensitive comparison, but
* that's fine, since we already know we have all-lower-case. * that's fine, since we already know we have all-lower-case.
*/ */
if (ScanKeywordLookup((char *) ident) != NULL) if (ScanKeywordLookup(ident) != NULL)
safe = false; safe = false;
} }
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * 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 @@ ...@@ -16,10 +16,10 @@
typedef struct ScanKeyword typedef struct ScanKeyword
{ {
char *name; const char *name;
int value; int value;
} ScanKeyword; } ScanKeyword;
extern ScanKeyword *ScanKeywordLookup(char *text); extern const ScanKeyword *ScanKeywordLookup(const char *text);
#endif /* KEYWORDS_H */ #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