X-Git-Url: https://granicus.if.org/sourcecode?a=blobdiff_plain;f=src%2Fbackend%2Fparser%2Fkeywords.c;h=49432cb957a83f0a44dc0843d6356037bc253ca1;hb=6261c75014c9948837d9d025493ef18b8f833f70;hp=12b05c6bcd1ce7ffe8b7c0b1ce5ff43edc09c0c2;hpb=8adf56f77aa0cc8cf4af7a19f0d235fc56fbabc7;p=postgresql diff --git a/src/backend/parser/keywords.c b/src/backend/parser/keywords.c index 12b05c6bcd..49432cb957 100644 --- a/src/backend/parser/keywords.c +++ b/src/backend/parser/keywords.c @@ -3,12 +3,12 @@ * keywords.c * lexical token lookup for reserved words in PostgreSQL * - * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group + * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.100 2002/02/18 23:11:18 petere Exp $ + * $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.135 2003/03/11 19:40:23 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -20,15 +20,17 @@ #include "parser/keywords.h" #include "parser/parse.h" +/* NB: This file is also used by pg_dump. */ + /* * List of (keyword-name, keyword-token-value) pairs. * * !!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}, + {"abort", ABORT_P}, {"absolute", ABSOLUTE}, {"access", ACCESS}, {"action", ACTION}, @@ -43,26 +45,32 @@ static ScanKeyword ScanKeywords[] = { {"any", ANY}, {"as", AS}, {"asc", ASC}, + {"assertion", ASSERTION}, + {"assignment", ASSIGNMENT}, {"at", AT}, {"authorization", AUTHORIZATION}, {"backward", BACKWARD}, {"before", BEFORE}, - {"begin", BEGIN_TRANS}, + {"begin", BEGIN_P}, {"between", BETWEEN}, + {"bigint", BIGINT}, {"binary", BINARY}, {"bit", BIT}, + {"boolean", BOOLEAN}, {"both", BOTH}, {"by", BY}, {"cache", CACHE}, + {"called", CALLED}, {"cascade", CASCADE}, {"case", CASE}, {"cast", CAST}, {"chain", CHAIN}, - {"char", CHAR}, + {"char", CHAR_P}, {"character", CHARACTER}, {"characteristics", CHARACTERISTICS}, {"check", CHECK}, {"checkpoint", CHECKPOINT}, + {"class", CLASS}, {"close", CLOSE}, {"cluster", CLUSTER}, {"coalesce", COALESCE}, @@ -73,6 +81,8 @@ static ScanKeyword ScanKeywords[] = { {"committed", COMMITTED}, {"constraint", CONSTRAINT}, {"constraints", CONSTRAINTS}, + {"conversion", CONVERSION_P}, + {"convert", CONVERT}, {"copy", COPY}, {"create", CREATE}, {"createdb", CREATEDB}, @@ -86,34 +96,40 @@ static ScanKeyword ScanKeywords[] = { {"cycle", CYCLE}, {"database", DATABASE}, {"day", DAY_P}, + {"deallocate", DEALLOCATE}, {"dec", DEC}, {"decimal", DECIMAL}, {"declare", DECLARE}, {"default", DEFAULT}, {"deferrable", DEFERRABLE}, {"deferred", DEFERRED}, - {"delete", DELETE}, + {"definer", DEFINER}, + {"delete", DELETE_P}, + {"delimiter", DELIMITER}, {"delimiters", DELIMITERS}, {"desc", DESC}, {"distinct", DISTINCT}, {"do", DO}, + {"domain", DOMAIN_P}, {"double", DOUBLE}, {"drop", DROP}, {"each", EACH}, {"else", ELSE}, {"encoding", ENCODING}, {"encrypted", ENCRYPTED}, - {"end", END_TRANS}, + {"end", END_P}, {"escape", ESCAPE}, {"except", EXCEPT}, {"exclusive", EXCLUSIVE}, {"execute", EXECUTE}, {"exists", EXISTS}, {"explain", EXPLAIN}, + {"external", EXTERNAL}, {"extract", EXTRACT}, {"false", FALSE_P}, {"fetch", FETCH}, - {"float", FLOAT}, + {"first", FIRST_P}, + {"float", FLOAT_P}, {"for", FOR}, {"force", FORCE}, {"foreign", FOREIGN}, @@ -124,25 +140,31 @@ static ScanKeyword ScanKeywords[] = { {"function", FUNCTION}, {"global", GLOBAL}, {"grant", GRANT}, - {"group", GROUP}, + {"group", GROUP_P}, {"handler", HANDLER}, {"having", HAVING}, {"hour", HOUR_P}, {"ilike", ILIKE}, {"immediate", IMMEDIATE}, - {"in", IN}, + {"immutable", IMMUTABLE}, + {"implicit", IMPLICIT_P}, + {"in", IN_P}, {"increment", INCREMENT}, {"index", INDEX}, {"inherits", INHERITS}, {"initially", INITIALLY}, {"inner", INNER_P}, {"inout", INOUT}, + {"input", INPUT}, {"insensitive", INSENSITIVE}, {"insert", INSERT}, {"instead", INSTEAD}, + {"int", INT}, + {"integer", INTEGER}, {"intersect", INTERSECT}, {"interval", INTERVAL}, {"into", INTO}, + {"invoker", INVOKER}, {"is", IS}, {"isnull", ISNULL}, {"isolation", ISOLATION}, @@ -150,6 +172,7 @@ static ScanKeyword ScanKeywords[] = { {"key", KEY}, {"lancompiler", LANCOMPILER}, {"language", LANGUAGE}, + {"last", LAST_P}, {"leading", LEADING}, {"left", LEFT}, {"level", LEVEL}, @@ -158,6 +181,8 @@ static ScanKeyword ScanKeywords[] = { {"listen", LISTEN}, {"load", LOAD}, {"local", LOCAL}, + {"localtime", LOCALTIME}, + {"localtimestamp", LOCALTIMESTAMP}, {"location", LOCATION}, {"lock", LOCK_P}, {"match", MATCH}, @@ -195,23 +220,28 @@ static ScanKeyword ScanKeywords[] = { {"option", OPTION}, {"or", OR}, {"order", ORDER}, - {"out", OUT}, + {"out", OUT_P}, {"outer", OUTER_P}, {"overlaps", OVERLAPS}, + {"overlay", OVERLAY}, {"owner", OWNER}, {"partial", PARTIAL}, {"password", PASSWORD}, {"path", PATH_P}, {"pendant", PENDANT}, + {"placing", PLACING}, {"position", POSITION}, {"precision", PRECISION}, + {"prepare", PREPARE}, + {"preserve", PRESERVE}, {"primary", PRIMARY}, {"prior", PRIOR}, {"privileges", PRIVILEGES}, {"procedural", PROCEDURAL}, {"procedure", PROCEDURE}, - {"public", PUBLIC}, {"read", READ}, + {"real", REAL}, + {"recheck", RECHECK}, {"references", REFERENCES}, {"reindex", REINDEX}, {"relative", RELATIVE}, @@ -224,10 +254,12 @@ static ScanKeyword ScanKeywords[] = { {"right", RIGHT}, {"rollback", ROLLBACK}, {"row", ROW}, + {"rows", ROWS}, {"rule", RULE}, {"schema", SCHEMA}, {"scroll", SCROLL}, {"second", SECOND_P}, + {"security", SECURITY}, {"select", SELECT}, {"sequence", SEQUENCE}, {"serializable", SERIALIZABLE}, @@ -237,12 +269,18 @@ static ScanKeyword ScanKeywords[] = { {"setof", SETOF}, {"share", SHARE}, {"show", SHOW}, + {"similar", SIMILAR}, + {"simple", SIMPLE}, + {"smallint", SMALLINT}, {"some", SOME}, + {"stable", STABLE}, {"start", START}, {"statement", STATEMENT}, {"statistics", STATISTICS}, {"stdin", STDIN}, {"stdout", STDOUT}, + {"storage", STORAGE}, + {"strict", STRICT}, {"substring", SUBSTRING}, {"sysid", SYSID}, {"table", TABLE}, @@ -256,6 +294,7 @@ static ScanKeyword ScanKeywords[] = { {"toast", TOAST}, {"trailing", TRAILING}, {"transaction", TRANSACTION}, + {"treat", TREAT}, {"trigger", TRIGGER}, {"trim", TRIM}, {"true", TRUE_P}, @@ -274,17 +313,20 @@ static ScanKeyword ScanKeywords[] = { {"using", USING}, {"vacuum", VACUUM}, {"valid", VALID}, + {"validator", VALIDATOR}, {"values", VALUES}, {"varchar", VARCHAR}, {"varying", VARYING}, {"verbose", VERBOSE}, {"version", VERSION}, {"view", VIEW}, + {"volatile", VOLATILE}, {"when", WHEN}, {"where", WHERE}, {"with", WITH}, {"without", WITHOUT}, {"work", WORK}, + {"write", WRITE}, {"year", YEAR_P}, {"zone", ZONE}, }; @@ -301,14 +343,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. */ @@ -340,7 +382,7 @@ ScanKeywordLookup(char *text) high = endof(ScanKeywords) - 1; while (low <= high) { - ScanKeyword *middle; + const ScanKeyword *middle; int difference; middle = low + (high - low) / 2; @@ -355,36 +397,3 @@ ScanKeywordLookup(char *text) return NULL; } - - -/* - * This does the reverse mapping from token number to string. - */ -const char * -TokenString(int token) -{ - int i = 0; - static char buf[NAMEDATALEN]; - - while (i < sizeof(ScanKeywords)) - { - if (ScanKeywords[i].value == token) - { - int k; - - /* uppercase */ - for (k = 0; k < NAMEDATALEN; k++) - if (ScanKeywords[i].name[k] >= 'a' - && ScanKeywords[i].name[k] <= 'z') - buf[k] = ScanKeywords[i].name[k] + ('A' - 'a'); - else - buf[k] = ScanKeywords[i].name[k]; - - return buf; - } - - i++; - } - - return NULL; -}