Commit 2a4660f5 authored by Tom Lane's avatar Tom Lane

Update keyword lists per suggestions by Peter. There are now four

mutually exclusive keyword lists spanning all known keywords ---
including AS.  Moved COALESCE and a few other ColLabels into the
can-be-ColId list.
parent 7e422ac0
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.274 2001/11/12 21:04:45 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.275 2001/11/16 04:08:33 tgl Exp $
* *
* HISTORY * HISTORY
* AUTHOR DATE MAJOR EVENT * AUTHOR DATE MAJOR EVENT
...@@ -268,7 +268,8 @@ static void doNegateFloat(Value *v); ...@@ -268,7 +268,8 @@ static void doNegateFloat(Value *v);
%type <ival> Iconst %type <ival> Iconst
%type <str> Sconst, comment_text %type <str> Sconst, comment_text
%type <str> UserId, opt_boolean, var_value, ColId_or_Sconst %type <str> UserId, opt_boolean, var_value, ColId_or_Sconst
%type <str> ColId, TypeFuncId, ColLabel %type <str> ColId, ColLabel, type_name, func_name_keyword
%type <str> col_name_keyword, unreserved_keyword, reserved_keyword
%type <node> zone_value %type <node> zone_value
%type <node> TableConstraint %type <node> TableConstraint
...@@ -296,8 +297,8 @@ static void doNegateFloat(Value *v); ...@@ -296,8 +297,8 @@ static void doNegateFloat(Value *v);
* This gets annoying when trying to also retain Postgres' nice * This gets annoying when trying to also retain Postgres' nice
* type-extensible features, but we don't really have a choice. * type-extensible features, but we don't really have a choice.
* - thomas 1997-10-11 * - thomas 1997-10-11
* NOTE: Whenever possible, try to add new keywords to the ColId list, * NOTE: don't forget to add new keywords to the appropriate one of
* or failing that, at least to the ColLabel list. * the reserved-or-not-so-reserved keyword lists, below.
*/ */
/* Keywords (in SQL92 reserved words) */ /* Keywords (in SQL92 reserved words) */
...@@ -2631,13 +2632,13 @@ func_return: func_type ...@@ -2631,13 +2632,13 @@ func_return: func_type
/* /*
* We would like to make the second production here be ColId '.' ColId etc, * We would like to make the second production here be ColId '.' ColId etc,
* but that causes reduce/reduce conflicts. TypeFuncId is next best choice. * but that causes reduce/reduce conflicts. type_name is next best choice.
*/ */
func_type: Typename func_type: Typename
{ {
$$ = $1; $$ = $1;
} }
| TypeFuncId '.' ColId '%' TYPE_P | type_name '.' ColId '%' TYPE_P
{ {
$$ = makeNode(TypeName); $$ = makeNode(TypeName);
$$->name = $1; $$->name = $1;
...@@ -4073,7 +4074,7 @@ ConstTypename: GenericType ...@@ -4073,7 +4074,7 @@ ConstTypename: GenericType
| ConstDatetime | ConstDatetime
; ;
GenericType: TypeFuncId GenericType: type_name
{ {
$$ = makeNode(TypeName); $$ = makeNode(TypeName);
$$->name = xlateSqlType($1); $$->name = xlateSqlType($1);
...@@ -5658,22 +5659,61 @@ Iconst: ICONST { $$ = $1; }; ...@@ -5658,22 +5659,61 @@ Iconst: ICONST { $$ = $1; };
Sconst: SCONST { $$ = $1; }; Sconst: SCONST { $$ = $1; };
UserId: ColId { $$ = $1; }; UserId: ColId { $$ = $1; };
/*
* Name classification hierarchy.
*
* IDENT is the lexeme returned by the lexer for identifiers that match
* no known keyword. In most cases, we can accept certain keywords as
* names, not only IDENTs. We prefer to accept as many such keywords
* as possible to minimize the impact of "reserved words" on programmers.
* So, we divide names into several possible classes. The classification
* is chosen in part to make keywords acceptable as names wherever possible.
*/
/* Column identifier --- names that can be column, table, etc names.
*/
ColId: IDENT { $$ = $1; }
| unreserved_keyword { $$ = $1; }
| col_name_keyword { $$ = $1; }
;
/* Type identifier --- names that can be type names.
*/
type_name: IDENT { $$ = $1; }
| unreserved_keyword { $$ = $1; }
;
/* Function identifier --- names that can be function names.
*/
func_name: IDENT { $$ = xlateSqlFunc($1); }
| unreserved_keyword { $$ = xlateSqlFunc($1); }
| func_name_keyword { $$ = xlateSqlFunc($1); }
;
/* Column label --- allowed labels in "AS" clauses.
* This presently includes *all* Postgres keywords.
*/
ColLabel: IDENT { $$ = $1; }
| unreserved_keyword { $$ = $1; }
| col_name_keyword { $$ = $1; }
| func_name_keyword { $$ = $1; }
| reserved_keyword { $$ = $1; }
;
/* /*
* Keyword classification lists. Generally, every keyword present in * Keyword classification lists. Generally, every keyword present in
* the Postgres grammar should be in one of these lists. (Presently, * the Postgres grammar should appear in exactly one of these lists.
* "AS" is the sole exception: it is our only completely-reserved word.)
* *
* Put a new keyword into the earliest list (of TypeFuncId, ColId, ColLabel) * Put a new keyword into the first list that it can go into without causing
* that it can go into without creating shift or reduce conflicts. The * shift or reduce conflicts. The earlier lists define "less reserved"
* earlier lists define "less reserved" categories of keywords. Notice that * categories of keywords.
* each list includes by reference the ones before it.
*/ */
/* Type/func identifier --- names that can be type and function names /* "Unreserved" keywords --- available for use as any kind of name.
* (as well as ColIds --- ie, these are completely unreserved keywords).
*/ */
TypeFuncId: IDENT { $$ = $1; } unreserved_keyword:
| ABORT_TRANS { $$ = "abort"; } ABORT_TRANS { $$ = "abort"; }
| ABSOLUTE { $$ = "absolute"; } | ABSOLUTE { $$ = "absolute"; }
| ACCESS { $$ = "access"; } | ACCESS { $$ = "access"; }
| ACTION { $$ = "action"; } | ACTION { $$ = "action"; }
...@@ -5829,58 +5869,94 @@ TypeFuncId: IDENT { $$ = $1; } ...@@ -5829,58 +5869,94 @@ TypeFuncId: IDENT { $$ = $1; }
| ZONE { $$ = "zone"; } | ZONE { $$ = "zone"; }
; ;
/* Column identifier --- names that can be column, table, etc names. /* Column identifier --- keywords that can be column, table, etc names.
* *
* This contains the TypeFuncId list plus those keywords that conflict * Many of these keywords will in fact be recognized as type or function
* only with typename productions, not with other uses. Note that * names too; but they have special productions for the purpose, and so
* most of these keywords will in fact be recognized as type names too; * can't be treated as "generic" type or function names.
* they just have to have special productions for the purpose.
* *
* Most of these cannot be in TypeFuncId (ie, are not also usable as function * The type names appearing here are not usable as function names
* names) because they can be followed by '(' in typename productions, which * because they can be followed by '(' in typename productions, which
* looks too much like a function call for a LALR(1) parser. * looks too much like a function call for an LR(1) parser.
*/ */
ColId: TypeFuncId { $$ = $1; } col_name_keyword:
| BIT { $$ = "bit"; } BIT { $$ = "bit"; }
| CHAR { $$ = "char"; } | CHAR { $$ = "char"; }
| CHARACTER { $$ = "character"; } | CHARACTER { $$ = "character"; }
| COALESCE { $$ = "coalesce"; }
| DEC { $$ = "dec"; } | DEC { $$ = "dec"; }
| DECIMAL { $$ = "decimal"; } | DECIMAL { $$ = "decimal"; }
| EXISTS { $$ = "exists"; }
| EXTRACT { $$ = "extract"; }
| FLOAT { $$ = "float"; } | FLOAT { $$ = "float"; }
| INTERVAL { $$ = "interval"; } | INTERVAL { $$ = "interval"; }
| NCHAR { $$ = "nchar"; } | NCHAR { $$ = "nchar"; }
| NONE { $$ = "none"; } | NONE { $$ = "none"; }
| NULLIF { $$ = "nullif"; }
| NUMERIC { $$ = "numeric"; } | NUMERIC { $$ = "numeric"; }
| POSITION { $$ = "position"; }
| SETOF { $$ = "setof"; } | SETOF { $$ = "setof"; }
| SUBSTRING { $$ = "substring"; }
| TIME { $$ = "time"; } | TIME { $$ = "time"; }
| TIMESTAMP { $$ = "timestamp"; } | TIMESTAMP { $$ = "timestamp"; }
| TRIM { $$ = "trim"; }
| VARCHAR { $$ = "varchar"; } | VARCHAR { $$ = "varchar"; }
; ;
/* Column label --- allowed labels in "AS" clauses. /* Function identifier --- keywords that can be function names.
*
* Most of these are keywords that are used as operators in expressions;
* in general such keywords can't be column names because they would be
* ambiguous with variables, but they are unambiguous as function identifiers.
*
* Do not include POSITION, SUBSTRING, etc here since they have explicit
* productions in a_expr to support the goofy SQL9x argument syntax.
* - thomas 2000-11-28
*/
func_name_keyword:
BETWEEN { $$ = "between"; }
| BINARY { $$ = "binary"; }
| CROSS { $$ = "cross"; }
| FREEZE { $$ = "freeze"; }
| FULL { $$ = "full"; }
| ILIKE { $$ = "ilike"; }
| IN { $$ = "in"; }
| INNER_P { $$ = "inner"; }
| IS { $$ = "is"; }
| ISNULL { $$ = "isnull"; }
| JOIN { $$ = "join"; }
| LEFT { $$ = "left"; }
| LIKE { $$ = "like"; }
| NATURAL { $$ = "natural"; }
| NOTNULL { $$ = "notnull"; }
| OUTER_P { $$ = "outer"; }
| OVERLAPS { $$ = "overlaps"; }
| PUBLIC { $$ = "public"; }
| RIGHT { $$ = "right"; }
| VERBOSE { $$ = "verbose"; }
;
/* Reserved keyword --- these keywords are usable only as a ColLabel.
* *
* Keywords appear here if they could not be distinguished from variable, * Keywords appear here if they could not be distinguished from variable,
* type, or function names in some contexts. * type, or function names in some contexts. Don't put things here unless
* When adding a ColLabel, consider whether it can be added to func_name. * forced to.
*/ */
ColLabel: ColId { $$ = $1; } reserved_keyword:
| ALL { $$ = "all"; } ALL { $$ = "all"; }
| ANALYSE { $$ = "analyse"; } /* British */ | ANALYSE { $$ = "analyse"; } /* British */
| ANALYZE { $$ = "analyze"; } | ANALYZE { $$ = "analyze"; }
| AND { $$ = "and"; } | AND { $$ = "and"; }
| ANY { $$ = "any"; } | ANY { $$ = "any"; }
| AS { $$ = "as"; }
| ASC { $$ = "asc"; } | ASC { $$ = "asc"; }
| BETWEEN { $$ = "between"; }
| BINARY { $$ = "binary"; }
| BOTH { $$ = "both"; } | BOTH { $$ = "both"; }
| CASE { $$ = "case"; } | CASE { $$ = "case"; }
| CAST { $$ = "cast"; } | CAST { $$ = "cast"; }
| CHECK { $$ = "check"; } | CHECK { $$ = "check"; }
| COALESCE { $$ = "coalesce"; }
| COLLATE { $$ = "collate"; } | COLLATE { $$ = "collate"; }
| COLUMN { $$ = "column"; } | COLUMN { $$ = "column"; }
| CONSTRAINT { $$ = "constraint"; } | CONSTRAINT { $$ = "constraint"; }
| CROSS { $$ = "cross"; }
| CURRENT_DATE { $$ = "current_date"; } | CURRENT_DATE { $$ = "current_date"; }
| CURRENT_TIME { $$ = "current_time"; } | CURRENT_TIME { $$ = "current_time"; }
| CURRENT_TIMESTAMP { $$ = "current_timestamp"; } | CURRENT_TIMESTAMP { $$ = "current_timestamp"; }
...@@ -5893,34 +5969,19 @@ ColLabel: ColId { $$ = $1; } ...@@ -5893,34 +5969,19 @@ ColLabel: ColId { $$ = $1; }
| ELSE { $$ = "else"; } | ELSE { $$ = "else"; }
| END_TRANS { $$ = "end"; } | END_TRANS { $$ = "end"; }
| EXCEPT { $$ = "except"; } | EXCEPT { $$ = "except"; }
| EXISTS { $$ = "exists"; }
| EXTRACT { $$ = "extract"; }
| FALSE_P { $$ = "false"; } | FALSE_P { $$ = "false"; }
| FOR { $$ = "for"; } | FOR { $$ = "for"; }
| FOREIGN { $$ = "foreign"; } | FOREIGN { $$ = "foreign"; }
| FREEZE { $$ = "freeze"; }
| FROM { $$ = "from"; } | FROM { $$ = "from"; }
| FULL { $$ = "full"; }
| GROUP { $$ = "group"; } | GROUP { $$ = "group"; }
| HAVING { $$ = "having"; } | HAVING { $$ = "having"; }
| ILIKE { $$ = "ilike"; }
| IN { $$ = "in"; }
| INITIALLY { $$ = "initially"; } | INITIALLY { $$ = "initially"; }
| INNER_P { $$ = "inner"; }
| INTERSECT { $$ = "intersect"; } | INTERSECT { $$ = "intersect"; }
| INTO { $$ = "into"; } | INTO { $$ = "into"; }
| IS { $$ = "is"; }
| ISNULL { $$ = "isnull"; }
| JOIN { $$ = "join"; }
| LEADING { $$ = "leading"; } | LEADING { $$ = "leading"; }
| LEFT { $$ = "left"; }
| LIKE { $$ = "like"; }
| LIMIT { $$ = "limit"; } | LIMIT { $$ = "limit"; }
| NATURAL { $$ = "natural"; }
| NEW { $$ = "new"; } | NEW { $$ = "new"; }
| NOT { $$ = "not"; } | NOT { $$ = "not"; }
| NOTNULL { $$ = "notnull"; }
| NULLIF { $$ = "nullif"; }
| NULL_P { $$ = "null"; } | NULL_P { $$ = "null"; }
| OFF { $$ = "off"; } | OFF { $$ = "off"; }
| OFFSET { $$ = "offset"; } | OFFSET { $$ = "offset"; }
...@@ -5929,65 +5990,24 @@ ColLabel: ColId { $$ = $1; } ...@@ -5929,65 +5990,24 @@ ColLabel: ColId { $$ = $1; }
| ONLY { $$ = "only"; } | ONLY { $$ = "only"; }
| OR { $$ = "or"; } | OR { $$ = "or"; }
| ORDER { $$ = "order"; } | ORDER { $$ = "order"; }
| OUTER_P { $$ = "outer"; }
| OVERLAPS { $$ = "overlaps"; }
| POSITION { $$ = "position"; }
| PRIMARY { $$ = "primary"; } | PRIMARY { $$ = "primary"; }
| PUBLIC { $$ = "public"; }
| REFERENCES { $$ = "references"; } | REFERENCES { $$ = "references"; }
| RIGHT { $$ = "right"; }
| SELECT { $$ = "select"; } | SELECT { $$ = "select"; }
| SESSION_USER { $$ = "session_user"; } | SESSION_USER { $$ = "session_user"; }
| SOME { $$ = "some"; } | SOME { $$ = "some"; }
| SUBSTRING { $$ = "substring"; }
| TABLE { $$ = "table"; } | TABLE { $$ = "table"; }
| THEN { $$ = "then"; } | THEN { $$ = "then"; }
| TO { $$ = "to"; } | TO { $$ = "to"; }
| TRAILING { $$ = "trailing"; } | TRAILING { $$ = "trailing"; }
| TRIM { $$ = "trim"; }
| TRUE_P { $$ = "true"; } | TRUE_P { $$ = "true"; }
| UNION { $$ = "union"; } | UNION { $$ = "union"; }
| UNIQUE { $$ = "unique"; } | UNIQUE { $$ = "unique"; }
| USER { $$ = "user"; } | USER { $$ = "user"; }
| USING { $$ = "using"; } | USING { $$ = "using"; }
| VERBOSE { $$ = "verbose"; }
| WHEN { $$ = "when"; } | WHEN { $$ = "when"; }
| WHERE { $$ = "where"; } | WHERE { $$ = "where"; }
; ;
/* Function identifier --- names that can be function names.
*
* This contains the TypeFuncId list plus some ColLabel keywords
* that are used as operators in expressions; in general such keywords
* can't be ColId because they would be ambiguous with variable names,
* but they are unambiguous as function identifiers.
*
* Do not include POSITION, SUBSTRING, etc here since they have explicit
* productions in a_expr to support the goofy SQL9x argument syntax.
* - thomas 2000-11-28
*/
func_name: TypeFuncId { $$ = xlateSqlFunc($1); }
| BETWEEN { $$ = xlateSqlFunc("between"); }
| BINARY { $$ = xlateSqlFunc("binary"); }
| CROSS { $$ = xlateSqlFunc("cross"); }
| FREEZE { $$ = xlateSqlFunc("freeze"); }
| FULL { $$ = xlateSqlFunc("full"); }
| ILIKE { $$ = xlateSqlFunc("ilike"); }
| IN { $$ = xlateSqlFunc("in"); }
| INNER_P { $$ = xlateSqlFunc("inner"); }
| IS { $$ = xlateSqlFunc("is"); }
| ISNULL { $$ = xlateSqlFunc("isnull"); }
| JOIN { $$ = xlateSqlFunc("join"); }
| LEFT { $$ = xlateSqlFunc("left"); }
| LIKE { $$ = xlateSqlFunc("like"); }
| NATURAL { $$ = xlateSqlFunc("natural"); }
| NOTNULL { $$ = xlateSqlFunc("notnull"); }
| OUTER_P { $$ = xlateSqlFunc("outer"); }
| OVERLAPS { $$ = xlateSqlFunc("overlaps"); }
| PUBLIC { $$ = xlateSqlFunc("public"); }
| RIGHT { $$ = xlateSqlFunc("right"); }
| VERBOSE { $$ = xlateSqlFunc("verbose"); }
;
SpecialRuleRelation: OLD SpecialRuleRelation: OLD
{ {
......
...@@ -279,7 +279,7 @@ make_name(void) ...@@ -279,7 +279,7 @@ make_name(void)
%type <str> key_match ColLabel SpecialRuleRelation ColId columnDef %type <str> key_match ColLabel SpecialRuleRelation ColId columnDef
%type <str> ColConstraint ColConstraintElem drop_type Bitconst %type <str> ColConstraint ColConstraintElem drop_type Bitconst
%type <str> OptTableElementList OptTableElement TableConstraint %type <str> OptTableElementList OptTableElement TableConstraint
%type <str> ConstraintElem key_actions ColQualList TypeFuncId DropSchemaStmt %type <str> ConstraintElem key_actions ColQualList type_name DropSchemaStmt
%type <str> target_list target_el update_target_list alias_clause %type <str> target_list target_el update_target_list alias_clause
%type <str> update_target_el opt_id relation_name database_name %type <str> update_target_el opt_id relation_name database_name
%type <str> access_method attr_name class index_name name func_name %type <str> access_method attr_name class index_name name func_name
...@@ -357,7 +357,9 @@ make_name(void) ...@@ -357,7 +357,9 @@ make_name(void)
%type <str> struct_type s_struct declaration declarations variable_declarations %type <str> struct_type s_struct declaration declarations variable_declarations
%type <str> s_union union_type ECPGSetAutocommit on_off %type <str> s_union union_type ECPGSetAutocommit on_off
%type <str> ECPGAllocateDescr ECPGDeallocateDescr symbol opt_symbol %type <str> ECPGAllocateDescr ECPGDeallocateDescr symbol opt_symbol
%type <str> ECPGGetDescriptorHeader ECPGTypeFuncId ECPGColId ECPGColLabel %type <str> ECPGGetDescriptorHeader ECPGColLabel
%type <str> reserved_keyword unreserved_keyword
%type <str> col_name_keyword func_name_keyword
%type <str> ECPGTypeName variablelist cvariable %type <str> ECPGTypeName variablelist cvariable
%type <descriptor> ECPGGetDescriptor %type <descriptor> ECPGGetDescriptor
...@@ -1964,7 +1966,7 @@ func_type: Typename ...@@ -1964,7 +1966,7 @@ func_type: Typename
{ {
$$ = $1; $$ = $1;
} }
| TypeFuncId '.' ColId '%' TYPE_P | type_name '.' ColId '%' TYPE_P
{ {
$$ = cat_str(4, $1, make_str("."), $3, make_str("% type")); $$ = cat_str(4, $1, make_str("."), $3, make_str("% type"));
} }
...@@ -2978,8 +2980,7 @@ ConstTypename: Generic { $$ = $1; } ...@@ -2978,8 +2980,7 @@ ConstTypename: Generic { $$ = $1; }
| Character { $$ = $1; } | Character { $$ = $1; }
; ;
Generic: TypeFuncId { $$ = $1; } Generic: type_name { $$ = $1; }
| ECPGTypeName { $$ = $1; }
; ;
/* SQL92 numeric data types /* SQL92 numeric data types
...@@ -4874,7 +4875,7 @@ action : SQL_CONTINUE ...@@ -4874,7 +4875,7 @@ action : SQL_CONTINUE
/* some other stuff for ecpg */ /* some other stuff for ecpg */
/* additional ColId entries */ /* additional unreserved keywords */
ECPGKeywords: SQL_BREAK { $$ = make_str("break"); } ECPGKeywords: SQL_BREAK { $$ = make_str("break"); }
| SQL_CALL { $$ = make_str("call"); } | SQL_CALL { $$ = make_str("call"); }
| SQL_CARDINALITY { $$ = make_str("cardinality"); } | SQL_CARDINALITY { $$ = make_str("cardinality"); }
...@@ -4909,9 +4910,9 @@ ECPGKeywords: SQL_BREAK { $$ = make_str("break"); } ...@@ -4909,9 +4910,9 @@ ECPGKeywords: SQL_BREAK { $$ = make_str("break"); }
| SQL_STOP { $$ = make_str("stop"); } | SQL_STOP { $$ = make_str("stop"); }
| SQL_VAR { $$ = make_str("var"); } | SQL_VAR { $$ = make_str("var"); }
| SQL_WHENEVER { $$ = make_str("whenever"); } | SQL_WHENEVER { $$ = make_str("whenever"); }
/* | ECPGTypeName { $$ = $1 }*/
; ;
/* additional keywords that can be SQL type names (but not ECPGColLabels) */
ECPGTypeName: SQL_BOOL { $$ = make_str("bool"); } ECPGTypeName: SQL_BOOL { $$ = make_str("bool"); }
| SQL_INT { $$ = make_str("int"); } | SQL_INT { $$ = make_str("int"); }
| SQL_LONG { $$ = make_str("long"); } | SQL_LONG { $$ = make_str("long"); }
...@@ -4928,25 +4929,72 @@ opt_symbol: symbol { $$ = $1; } ...@@ -4928,25 +4929,72 @@ opt_symbol: symbol { $$ = $1; }
symbol: ColLabel { $$ = $1; }; symbol: ColLabel { $$ = $1; };
/* /*
* Keyword classification lists. Generally, every keyword present in * Name classification hierarchy.
* the Postgres grammar should be in one of these lists. (Presently, *
* "AS" is the sole exception: it is our only completely-reserved word.) * IDENT is the lexeme returned by the lexer for identifiers that match
* * no known keyword. In most cases, we can accept certain keywords as
* Put a new keyword into the earliest list (of TypeFuncId, ColId, ColLabel) * names, not only IDENTs. We prefer to accept as many such keywords
* that it can go into without creating shift or reduce conflicts. The * as possible to minimize the impact of "reserved words" on programmers.
* earlier lists define "less reserved" categories of keywords. Notice that * So, we divide names into several possible classes. The classification
* each list includes by reference the ones before it. * is chosen in part to make keywords acceptable as names wherever possible.
*/ */
/* Type/func identifier --- names that can be type and function names /* Column identifier --- names that can be column, table, etc names.
* (as well as ColIds --- ie, these are completely unreserved keywords).
*/ */
TypeFuncId: ECPGTypeFuncId { $$ = $1; } ColId: ident { $$ = $1; }
| unreserved_keyword { $$ = $1; }
| col_name_keyword { $$ = $1; }
| ECPGKeywords { $$ = $1; } | ECPGKeywords { $$ = $1; }
| CHAR { $$ = make_str("char"); }
; ;
ECPGTypeFuncId: ident { $$ = $1; } /* Type identifier --- names that can be type names.
| ABORT_TRANS { $$ = make_str("abort"); } */
type_name: ident { $$ = $1; }
| unreserved_keyword { $$ = $1; }
| ECPGKeywords { $$ = $1; }
| ECPGTypeName { $$ = $1; }
;
/* Function identifier --- names that can be function names.
*/
func_name: ident { $$ = $1; }
| unreserved_keyword { $$ = $1; }
| func_name_keyword { $$ = $1; }
| ECPGKeywords { $$ = $1; }
;
/* Column label --- allowed labels in "AS" clauses.
* This presently includes *all* Postgres keywords.
*/
ColLabel: ECPGColLabel { $$ = $1; }
| ECPGTypeName { $$ = $1; }
| CHAR { $$ = make_str("char"); }
| UNION { $$ = make_str("union"); }
;
ECPGColLabel: ident { $$ = $1; }
| unreserved_keyword { $$ = $1; }
| col_name_keyword { $$ = $1; }
| func_name_keyword { $$ = $1; }
| reserved_keyword { $$ = $1; }
| ECPGKeywords { $$ = $1; }
;
/*
* Keyword classification lists. Generally, every keyword present in
* the Postgres grammar should appear in exactly one of these lists.
*
* Put a new keyword into the first list that it can go into without causing
* shift or reduce conflicts. The earlier lists define "less reserved"
* categories of keywords.
*/
/* "Unreserved" keywords --- available for use as any kind of name.
*/
unreserved_keyword:
ABORT_TRANS { $$ = make_str("abort"); }
| ABSOLUTE { $$ = make_str("absolute"); } | ABSOLUTE { $$ = make_str("absolute"); }
| ACCESS { $$ = make_str("access"); } | ACCESS { $$ = make_str("access"); }
| ACTION { $$ = make_str("action"); } | ACTION { $$ = make_str("action"); }
...@@ -5102,69 +5150,96 @@ ECPGTypeFuncId: ident { $$ = $1; } ...@@ -5102,69 +5150,96 @@ ECPGTypeFuncId: ident { $$ = $1; }
| ZONE { $$ = make_str("zone"); } | ZONE { $$ = make_str("zone"); }
; ;
/* Column identifier --- names that can be column, table, etc names. /* Column identifier --- keywords that can be column, table, etc names.
* *
* This contains the TypeFuncId list plus those keywords that conflict * Many of these keywords will in fact be recognized as type or function
* only with typename productions, not with other uses. Note that * names too; but they have special productions for the purpose, and so
* most of these keywords will in fact be recognized as type names too; * can't be treated as "generic" type or function names.
* they just have to have special productions for the purpose.
* *
* Most of these cannot be in TypeFuncId (ie, are not also usable as function * The type names appearing here are not usable as function names
* names) because they can be followed by '(' in typename productions, which * because they can be followed by '(' in typename productions, which
* looks too much like a function call for a LALR(1) parser. * looks too much like a function call for an LR(1) parser.
*/ */
ColId: ECPGColId { $$ = $1; } col_name_keyword:
| CHAR { $$ = make_str("char"); } BIT { $$ = make_str("bit"); }
;
ECPGColId: TypeFuncId { $$ = $1; }
| BIT { $$ = make_str("bit"); }
/* CHAR must be excluded from ECPGColLabel because of conflict with UNSIGNED /* CHAR must be excluded from ECPGColLabel because of conflict with UNSIGNED
| CHAR { $$ = make_str("char"); } | CHAR { $$ = make_str("char"); }
*/ */
| CHARACTER { $$ = make_str("character"); } | CHARACTER { $$ = make_str("character"); }
| COALESCE { $$ = make_str("coalesce"); }
| DEC { $$ = make_str("dec"); } | DEC { $$ = make_str("dec"); }
| DECIMAL { $$ = make_str("decimal"); } | DECIMAL { $$ = make_str("decimal"); }
| EXISTS { $$ = make_str("exists"); }
| EXTRACT { $$ = make_str("extract"); }
| FLOAT { $$ = make_str("float"); } | FLOAT { $$ = make_str("float"); }
| INTERVAL { $$ = make_str("interval"); } | INTERVAL { $$ = make_str("interval"); }
| NCHAR { $$ = make_str("nchar"); } | NCHAR { $$ = make_str("nchar"); }
| NONE { $$ = make_str("none"); } | NONE { $$ = make_str("none"); }
| NULLIF { $$ = make_str("nullif"); }
| NUMERIC { $$ = make_str("numeric"); } | NUMERIC { $$ = make_str("numeric"); }
| POSITION { $$ = make_str("position"); }
| SETOF { $$ = make_str("setof"); } | SETOF { $$ = make_str("setof"); }
| SUBSTRING { $$ = make_str("substring"); }
| TIME { $$ = make_str("time"); } | TIME { $$ = make_str("time"); }
| TIMESTAMP { $$ = make_str("timestamp"); } | TIMESTAMP { $$ = make_str("timestamp"); }
| TRIM { $$ = make_str("trim"); }
| VARCHAR { $$ = make_str("varchar"); } | VARCHAR { $$ = make_str("varchar"); }
; ;
/* Column label --- allowed labels in "AS" clauses. /* Function identifier --- keywords that can be function names.
* *
* Keywords appear here if they could not be distinguished from variable, * Most of these are keywords that are used as operators in expressions;
* type, or function names in some contexts. * in general such keywords can't be column names because they would be
* When adding a ColLabel, consider whether it can be added to func_name. * ambiguous with variables, but they are unambiguous as function identifiers.
*
* Do not include POSITION, SUBSTRING, etc here since they have explicit
* productions in a_expr to support the goofy SQL9x argument syntax.
* - thomas 2000-11-28
*/ */
ColLabel: ECPGColLabel { $$ = $1; } func_name_keyword:
| CHAR { $$ = make_str("char"); } BETWEEN { $$ = make_str("between"); }
| UNION { $$ = make_str("union"); } | BINARY { $$ = make_str("binary"); }
| CROSS { $$ = make_str("cross"); }
| FREEZE { $$ = make_str("freeze"); }
| FULL { $$ = make_str("full"); }
| ILIKE { $$ = make_str("ilike"); }
| IN { $$ = make_str("in"); }
| INNER_P { $$ = make_str("inner"); }
| IS { $$ = make_str("is"); }
| ISNULL { $$ = make_str("isnull"); }
| JOIN { $$ = make_str("join"); }
| LEFT { $$ = make_str("left"); }
| LIKE { $$ = make_str("like"); }
| NATURAL { $$ = make_str("natural"); }
| NOTNULL { $$ = make_str("notnull"); }
| OUTER_P { $$ = make_str("outer"); }
| OVERLAPS { $$ = make_str("overlaps"); }
| PUBLIC { $$ = make_str("public"); }
| RIGHT { $$ = make_str("right"); }
| VERBOSE { $$ = make_str("verbose"); }
; ;
ECPGColLabel: ECPGColId { $$ = $1; } /* Reserved keyword --- these keywords are usable only as a ColLabel.
| ALL { $$ = make_str("all"); } *
* Keywords appear here if they could not be distinguished from variable,
* type, or function names in some contexts. Don't put things here unless
* forced to.
*/
reserved_keyword:
ALL { $$ = make_str("all"); }
| ANALYSE { $$ = make_str("analyse"); } /* British */ | ANALYSE { $$ = make_str("analyse"); } /* British */
| ANALYZE { $$ = make_str("analyze"); } | ANALYZE { $$ = make_str("analyze"); }
| AND { $$ = make_str("and"); } | AND { $$ = make_str("and"); }
| ANY { $$ = make_str("any"); } | ANY { $$ = make_str("any"); }
| AS { $$ = make_str("as"); }
| ASC { $$ = make_str("asc"); } | ASC { $$ = make_str("asc"); }
| BETWEEN { $$ = make_str("between"); }
| BINARY { $$ = make_str("binary"); }
| BOTH { $$ = make_str("both"); } | BOTH { $$ = make_str("both"); }
| CASE { $$ = make_str("case"); } | CASE { $$ = make_str("case"); }
| CAST { $$ = make_str("cast"); } | CAST { $$ = make_str("cast"); }
| CHECK { $$ = make_str("check"); } | CHECK { $$ = make_str("check"); }
| COALESCE { $$ = make_str("coalesce"); }
| COLLATE { $$ = make_str("collate"); } | COLLATE { $$ = make_str("collate"); }
| COLUMN { $$ = make_str("column"); } | COLUMN { $$ = make_str("column"); }
| CONSTRAINT { $$ = make_str("constraint"); } | CONSTRAINT { $$ = make_str("constraint"); }
| CROSS { $$ = make_str("cross"); }
| CURRENT_DATE { $$ = make_str("current_date"); } | CURRENT_DATE { $$ = make_str("current_date"); }
| CURRENT_TIME { $$ = make_str("current_time"); } | CURRENT_TIME { $$ = make_str("current_time"); }
| CURRENT_TIMESTAMP { $$ = make_str("current_timestamp"); } | CURRENT_TIMESTAMP { $$ = make_str("current_timestamp"); }
...@@ -5177,34 +5252,19 @@ ECPGColLabel: ECPGColId { $$ = $1; } ...@@ -5177,34 +5252,19 @@ ECPGColLabel: ECPGColId { $$ = $1; }
| ELSE { $$ = make_str("else"); } | ELSE { $$ = make_str("else"); }
| END_TRANS { $$ = make_str("end"); } | END_TRANS { $$ = make_str("end"); }
| EXCEPT { $$ = make_str("except"); } | EXCEPT { $$ = make_str("except"); }
| EXISTS { $$ = make_str("exists"); }
| EXTRACT { $$ = make_str("extract"); }
| FALSE_P { $$ = make_str("false"); } | FALSE_P { $$ = make_str("false"); }
| FOR { $$ = make_str("for"); } | FOR { $$ = make_str("for"); }
| FOREIGN { $$ = make_str("foreign"); } | FOREIGN { $$ = make_str("foreign"); }
| FREEZE { $$ = make_str("freeze"); }
| FROM { $$ = make_str("from"); } | FROM { $$ = make_str("from"); }
| FULL { $$ = make_str("full"); }
| GROUP { $$ = make_str("group"); } | GROUP { $$ = make_str("group"); }
| HAVING { $$ = make_str("having"); } | HAVING { $$ = make_str("having"); }
| ILIKE { $$ = make_str("ilike"); }
| IN { $$ = make_str("in"); }
| INITIALLY { $$ = make_str("initially"); } | INITIALLY { $$ = make_str("initially"); }
| INNER_P { $$ = make_str("inner"); }
| INTERSECT { $$ = make_str("intersect"); } | INTERSECT { $$ = make_str("intersect"); }
| INTO { $$ = make_str("into"); } | INTO { $$ = make_str("into"); }
| IS { $$ = make_str("is"); }
| ISNULL { $$ = make_str("isnull"); }
| JOIN { $$ = make_str("join"); }
| LEADING { $$ = make_str("leading"); } | LEADING { $$ = make_str("leading"); }
| LEFT { $$ = make_str("left"); }
| LIKE { $$ = make_str("like"); }
| LIMIT { $$ = make_str("limit"); } | LIMIT { $$ = make_str("limit"); }
| NATURAL { $$ = make_str("natural"); }
| NEW { $$ = make_str("new"); } | NEW { $$ = make_str("new"); }
| NOT { $$ = make_str("not"); } | NOT { $$ = make_str("not"); }
| NOTNULL { $$ = make_str("notnull"); }
| NULLIF { $$ = make_str("nullif"); }
| NULL_P { $$ = make_str("null"); } | NULL_P { $$ = make_str("null"); }
| OFF { $$ = make_str("off"); } | OFF { $$ = make_str("off"); }
| OFFSET { $$ = make_str("offset"); } | OFFSET { $$ = make_str("offset"); }
...@@ -5213,22 +5273,15 @@ ECPGColLabel: ECPGColId { $$ = $1; } ...@@ -5213,22 +5273,15 @@ ECPGColLabel: ECPGColId { $$ = $1; }
| ONLY { $$ = make_str("only"); } | ONLY { $$ = make_str("only"); }
| OR { $$ = make_str("or"); } | OR { $$ = make_str("or"); }
| ORDER { $$ = make_str("order"); } | ORDER { $$ = make_str("order"); }
| OUTER_P { $$ = make_str("outer"); }
| OVERLAPS { $$ = make_str("overlaps"); }
| POSITION { $$ = make_str("position"); }
| PRIMARY { $$ = make_str("primary"); } | PRIMARY { $$ = make_str("primary"); }
| PUBLIC { $$ = make_str("public"); }
| REFERENCES { $$ = make_str("references"); } | REFERENCES { $$ = make_str("references"); }
| RIGHT { $$ = make_str("right"); }
| SELECT { $$ = make_str("select"); } | SELECT { $$ = make_str("select"); }
| SESSION_USER { $$ = make_str("session_user"); } | SESSION_USER { $$ = make_str("session_user"); }
| SOME { $$ = make_str("some"); } | SOME { $$ = make_str("some"); }
| SUBSTRING { $$ = make_str("substring"); }
| TABLE { $$ = make_str("table"); } | TABLE { $$ = make_str("table"); }
| THEN { $$ = make_str("then"); } | THEN { $$ = make_str("then"); }
| TO { $$ = make_str("to"); } | TO { $$ = make_str("to"); }
| TRAILING { $$ = make_str("trailing"); } | TRAILING { $$ = make_str("trailing"); }
| TRIM { $$ = make_str("trim"); }
| TRUE_P { $$ = make_str("true"); } | TRUE_P { $$ = make_str("true"); }
/* UNION must be excluded from ECPGColLabel because of conflict with s_union /* UNION must be excluded from ECPGColLabel because of conflict with s_union
| UNION { $$ = make_str("union"); } | UNION { $$ = make_str("union"); }
...@@ -5236,44 +5289,10 @@ ECPGColLabel: ECPGColId { $$ = $1; } ...@@ -5236,44 +5289,10 @@ ECPGColLabel: ECPGColId { $$ = $1; }
| UNIQUE { $$ = make_str("unique"); } | UNIQUE { $$ = make_str("unique"); }
| USER { $$ = make_str("user"); } | USER { $$ = make_str("user"); }
| USING { $$ = make_str("using"); } | USING { $$ = make_str("using"); }
| VERBOSE { $$ = make_str("verbose"); }
| WHEN { $$ = make_str("when"); } | WHEN { $$ = make_str("when"); }
| WHERE { $$ = make_str("where"); } | WHERE { $$ = make_str("where"); }
; ;
/* Function identifier --- names that can be function names.
*
* This contains the TypeFuncId list plus some ColLabel keywords
* that are used as operators in expressions; in general such keywords
* can't be ColId because they would be ambiguous with variable names,
* but they are unambiguous as function identifiers.
*
* Do not include POSITION, SUBSTRING, etc here since they have explicit
* productions in a_expr to support the goofy SQL9x argument syntax.
* - thomas 2000-11-28
*/
func_name: TypeFuncId { $$ = $1; }
| BETWEEN { $$ = make_str("between"); }
| BINARY { $$ = make_str("binary"); }
| CROSS { $$ = make_str("cross"); }
| FREEZE { $$ = make_str("freeze"); }
| FULL { $$ = make_str("full"); }
| ILIKE { $$ = make_str("ilike"); }
| IN { $$ = make_str("in"); }
| INNER_P { $$ = make_str("inner"); }
| IS { $$ = make_str("is"); }
| ISNULL { $$ = make_str("isnull"); }
| JOIN { $$ = make_str("join"); }
| LEFT { $$ = make_str("left"); }
| LIKE { $$ = make_str("like"); }
| NATURAL { $$ = make_str("natural"); }
| NOTNULL { $$ = make_str("notnull"); }
| OUTER_P { $$ = make_str("outer"); }
| OVERLAPS { $$ = make_str("overlaps"); }
| PUBLIC { $$ = make_str("public"); }
| RIGHT { $$ = make_str("right"); }
| VERBOSE { $$ = make_str("verbose"); }
;
into_list : coutputvariable | into_list ',' coutputvariable; into_list : coutputvariable | into_list ',' coutputvariable;
......
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