Skip to content

Commit 8e72a87

Browse files
author
Michael Meskes
committed
Synced preproc.y with gram.y
1 parent 77ac0a8 commit 8e72a87

File tree

2 files changed

+54
-101
lines changed

2 files changed

+54
-101
lines changed

src/interfaces/ecpg/ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -956,5 +956,9 @@ Wed Oct 4 14:36:51 CEST 2000
956956

957957
- Added patch by Christof Petig <christof.petig@wtal.de> to fix
958958
missing NOTICE.
959+
960+
Wed Oct 11 16:49:36 CEST 2000
961+
962+
- Synced preproc.y with gram.y.
959963
- Set ecpg version to 2.8.0.
960964
- Set library version to 3.2.0.

src/interfaces/ecpg/preproc/preproc.y

Lines changed: 50 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ char errortext[128];
2424
char *connection = NULL;
2525
char *input_filename = NULL;
2626

27-
static int QueryIsRule = 0, ForUpdateNotAllowed = 0, FoundInto = 0;
28-
static int FoundSort = 0;
27+
static int QueryIsRule = 0, FoundInto = 0;
2928
static int initializer = 0;
3029
static struct this_type actual_type[STRUCT_DEPTH];
3130
static char *actual_storage[STRUCT_DEPTH];
@@ -300,7 +299,7 @@ make_name(void)
300299
%type <str> opt_decimal Character character opt_varying opt_charset
301300
%type <str> opt_collate datetime opt_timezone opt_interval table_ref
302301
%type <str> row_expr row_descriptor row_list ConstDatetime opt_chain
303-
%type <str> SelectStmt SubSelect result OptTemp ConstraintAttributeSpec
302+
%type <str> SelectStmt select_subclause result OptTemp ConstraintAttributeSpec
304303
%type <str> opt_table opt_all sort_clause sortby_list ConstraintAttr
305304
%type <str> sortby OptUseOp opt_inh_star relation_name_list name_list
306305
%type <str> group_clause having_clause from_clause opt_distinct
@@ -1972,33 +1971,15 @@ func_args_list: func_arg { $$ = $1; }
19721971
{ $$ = cat_str(3, $1, make_str(","), $3); }
19731972
;
19741973

1975-
/* Would be nice to use the full Typename production for these fields,
1976-
* but that one sometimes dives into the catalogs looking for valid types.
1977-
* Arguments like "opaque" are valid when defining functions,
1978-
* so that won't work here. The only thing we give up is array notation,
1979-
* which isn't meaningful in this context anyway.
1980-
* - thomas 2000-03-25
1981-
* The following productions are difficult, since it is difficult to
1982-
* distinguish between TokenId and SimpleTypename:
1983-
opt_arg TokenId SimpleTypename
1984-
{
1985-
$$ = $3;
1986-
}
1987-
| TokenId SimpleTypename
1988-
{
1989-
$$ = $2;
1990-
}
1991-
*/
1992-
1993-
func_arg: opt_arg SimpleTypename
1974+
func_arg: opt_arg Typename
19941975
{
19951976
/* We can catch over-specified arguments here if we want to,
19961977
* but for now better to silently swallow typmod, etc.
19971978
* - thomas 2000-03-22
19981979
*/
19991980
$$ = cat2_str($1, $2);
20001981
}
2001-
| SimpleTypename
1982+
| Typename
20021983
{
20031984
$$ = $1;
20041985
}
@@ -2020,19 +2001,14 @@ opt_arg: IN { $$ = make_str("in"); }
20202001
func_as: Sconst { $$ = $1; }
20212002
| Sconst ',' Sconst { $$ = cat_str(3, $1, make_str(","), $3); }
20222003

2023-
func_return: SimpleTypename
2004+
func_return: Typename
20242005
{
20252006
/* We can catch over-specified arguments here if we want to,
20262007
* but for now better to silently swallow typmod, etc.
20272008
* - thomas 2000-03-22
20282009
*/
20292010
$$ = $1;
20302011
}
2031-
| SETOF SimpleTypename
2032-
{
2033-
2034-
$$ = cat2_str(make_str("setof"), $2);
2035-
}
20362012
;
20372013

20382014
/*****************************************************************************
@@ -2071,7 +2047,7 @@ RemoveAggrStmt: DROP AGGREGATE name aggr_argtype
20712047
}
20722048
;
20732049

2074-
aggr_argtype: name { $$ = $1; }
2050+
aggr_argtype: Typename { $$ = $1; }
20752051
| '*' { $$ = make_str("*"); }
20762052
;
20772053

@@ -2089,15 +2065,15 @@ RemoveOperStmt: DROP OPERATOR all_Op '(' oper_argtypes ')'
20892065
}
20902066
;
20912067

2092-
oper_argtypes: name
2068+
oper_argtypes: Typename
20932069
{
20942070
mmerror(ET_ERROR, "parser: argument type missing (use NONE for unary operators)");
20952071
}
2096-
| name ',' name
2072+
| Typename ',' Typename
20972073
{ $$ = cat_str(3, $1, make_str(","), $3); }
2098-
| NONE ',' name /* left unary */
2074+
| NONE ',' Typename /* left unary */
20992075
{ $$ = cat2_str(make_str("none,"), $3); }
2100-
| name ',' NONE /* right unary */
2076+
| Typename ',' NONE /* right unary */
21012077
{ $$ = cat2_str($1, make_str(", none")); }
21022078
;
21032079

@@ -2471,14 +2447,8 @@ insert_rest: VALUES '(' target_list ')'
24712447
{
24722448
$$ = make_str("default values");
24732449
}
2474-
/* We want the full power of SelectStatements including INTERSECT and EXCEPT
2475-
* for insertion. However, we can't support sort or limit clauses.
2476-
*/
24772450
| SelectStmt
24782451
{
2479-
if (FoundSort != 0)
2480-
mmerror(ET_ERROR, "ORDER BY is not allowed in INSERT/SELECT");
2481-
24822452
$$ = $1;
24832453
}
24842454
| '(' columnList ')' VALUES '(' target_list ')'
@@ -2487,9 +2457,6 @@ insert_rest: VALUES '(' target_list ')'
24872457
}
24882458
| '(' columnList ')' SelectStmt
24892459
{
2490-
if (FoundSort != 0)
2491-
mmerror(ET_ERROR, "ORDER BY is not all owed in INSERT/SELECT");
2492-
24932460
$$ = cat_str(4, make_str("("), $2, make_str(")"), $4);
24942461
}
24952462
;
@@ -2568,9 +2535,7 @@ UpdateStmt: UPDATE opt_only relation_name
25682535
* CURSOR STATEMENTS
25692536
*
25702537
*****************************************************************************/
2571-
CursorStmt: DECLARE name opt_cursor CURSOR FOR
2572-
{ ForUpdateNotAllowed = 1; }
2573-
SelectStmt
2538+
CursorStmt: DECLARE name opt_cursor CURSOR FOR SelectStmt
25742539
{
25752540
struct cursor *ptr, *this;
25762541

@@ -2590,7 +2555,7 @@ CursorStmt: DECLARE name opt_cursor CURSOR FOR
25902555
this->next = cur;
25912556
this->name = $2;
25922557
this->connection = connection;
2593-
this->command = cat_str(5, make_str("declare"), mm_strdup($2), $3, make_str("cursor for"), $7);
2558+
this->command = cat_str(5, make_str("declare"), mm_strdup($2), $3, make_str("cursor for"), $6);
25942559
this->argsinsert = argsinsert;
25952560
this->argsresult = argsresult;
25962561
argsinsert = argsresult = NULL;
@@ -2615,70 +2580,55 @@ opt_cursor: BINARY { $$ = make_str("binary"); }
26152580
*
26162581
*****************************************************************************/
26172582

2618-
/* The new 'SelectStmt' rule adapted for the optional use of INTERSECT EXCEPT a nd UNION
2619-
* accepts the use of '(' and ')' to select an order of set operations.
2620-
* The rule returns a SelectStmt Node having the set operations attached to
2621-
* unionClause and intersectClause (NIL if no set operations were present)
2622-
*/
2623-
2624-
SelectStmt: select_clause
2625-
{ FoundSort = 0; }
2626-
sort_clause for_update_clause opt_select_limit
2583+
SelectStmt: select_clause sort_clause for_update_clause opt_select_limit
26272584
{
2628-
if (strlen($4) > 0 && ForUpdateNotAllowed != 0)
2629-
mmerror(ET_ERROR, "FOR UPDATE is not allowed in this context");
2630-
2631-
ForUpdateNotAllowed = 0;
2632-
$$ = cat_str(4, $1, $3, $4, $5);
2585+
$$ = cat_str(4, $1, $2, $3, $4);
26332586
}
26342587

26352588
/* This rule parses Select statements including UNION INTERSECT and EXCEPT.
26362589
* '(' and ')' can be used to specify the order of the operations
26372590
* (UNION EXCEPT INTERSECT). Without the use of '(' and ')' we want the
26382591
* operations to be ordered per the precedence specs at the head of this file.
26392592
*
2640-
* The sort_clause is not handled here!
2593+
* Since parentheses around SELECTs also appear in the expression grammar,
2594+
* there is a parse ambiguity if parentheses are allowed at the top level of a
2595+
* select_clause: are the parens part of the expression or part of the select?
2596+
* We separate select_clause into two levels to resolve this: select_clause
2597+
* can have top-level parentheses, select_subclause cannot.
2598+
* Note that sort clauses cannot be included at this level --- a sort clau
2599+
* can only appear at the end of the complete Select, and it will be handl
2600+
* by the topmost SelectStmt rule. Likewise FOR UPDATE and LIMIT.
26412601
*/
2642-
select_clause: '(' select_clause ')'
2602+
2603+
select_clause: '(' select_subclause ')'
26432604
{
26442605
$$ = cat_str(3, make_str("("), $2, make_str(")"));
26452606
}
2646-
| SubSelect
2607+
| select_subclause
26472608
{
2648-
FoundInto = 0;
2609+
FoundInto = 0;
26492610
$$ = $1;
26502611
}
2651-
| select_clause EXCEPT opt_all select_clause
2652-
{
2653-
if (strlen($3) != 0)
2654-
mmerror(ET_WARN, "EXCEPT ALL is not implemented yet.");
2655-
2656-
$$ = cat_str(4, $1, make_str("except"), $3, $4);
2657-
ForUpdateNotAllowed = 1;
2658-
}
2659-
| select_clause UNION opt_all select_clause
2660-
{
2661-
$$ = cat_str(4, $1, make_str("union"), $3, $4);
2662-
ForUpdateNotAllowed = 1;
2663-
}
2664-
| select_clause INTERSECT opt_all select_clause
2665-
{
2666-
if (strlen($3) != 0)
2667-
mmerror(ET_WARN, "INTERSECT ALL is not implemented yet.");
2668-
2669-
$$ = cat_str(4, $1, make_str("intersect"), $3, $4);
2670-
ForUpdateNotAllowed = 1;
2671-
}
26722612
;
26732613

2674-
SubSelect: SELECT opt_distinct target_list
2614+
select_subclause: SELECT opt_distinct target_list
26752615
result from_clause where_clause
26762616
group_clause having_clause
26772617
{
2678-
if (strlen($7) > 0 || strlen($8) > 0)
2679-
ForUpdateNotAllowed = 1;
26802618
$$ = cat_str(8, make_str("select"), $2, $3, $4, $5, $6, $7, $8);
26812619
}
2620+
| select_clause UNION opt_all select_clause
2621+
{
2622+
$$ = cat_str(4, $1, make_str("union"), $3, $4);
2623+
}
2624+
| select_clause INTERSECT opt_all select_clause
2625+
{
2626+
$$ = cat_str(4, $1, make_str("intersect"), $3, $4);
2627+
}
2628+
| select_clause EXCEPT opt_all select_clause
2629+
{
2630+
$$ = cat_str(4, $1, make_str("except"), $3, $4);
2631+
}
26822632
;
26832633

26842634
result: INTO OptTempTableName {
@@ -2747,7 +2697,6 @@ opt_distinct: DISTINCT { $$ = make_str("distinct"); }
27472697
;
27482698

27492699
sort_clause: ORDER BY sortby_list {
2750-
FoundSort = 1;
27512700
$$ = cat2_str(make_str("order by"), $3);
27522701
}
27532702
| /*EMPTY*/ { $$ = EMPTY; }
@@ -2880,7 +2829,7 @@ table_ref: relation_expr
28802829
{
28812830
cat2_str($1, $2);
28822831
}
2883-
| '(' select_clause ')' alias_clause
2832+
| '(' select_subclause ')' alias_clause
28842833
{
28852834
cat_str(4, make_str("("), $2, make_str(")"), $4);
28862835
}
@@ -3299,19 +3248,19 @@ opt_interval: datetime { $$ = $1; }
32993248
* Define row_descriptor to allow yacc to break the reduce/reduce conflict
33003249
* with singleton expressions.
33013250
*/
3302-
row_expr: '(' row_descriptor ')' IN '(' SubSelect ')'
3251+
row_expr: '(' row_descriptor ')' IN '(' select_subclause ')'
33033252
{
33043253
$$ = cat_str(5, make_str("("), $2, make_str(") in ("), $6, make_str(")"));
33053254
}
3306-
| '(' row_descriptor ')' NOT IN '(' SubSelect ')'
3255+
| '(' row_descriptor ')' NOT IN '(' select_subclause ')'
33073256
{
33083257
$$ = cat_str(5, make_str("("), $2, make_str(") not in ("), $7, make_str(")"));
33093258
}
3310-
| '(' row_descriptor ')' all_Op sub_type '(' SubSelect ')'
3259+
| '(' row_descriptor ')' all_Op sub_type '(' select_subclause ')'
33113260
{
33123261
$$ = cat_str(8, make_str("("), $2, make_str(")"), $4, $5, make_str("("), $7, make_str(")"));
33133262
}
3314-
| '(' row_descriptor ')' all_Op '(' SubSelect ')'
3263+
| '(' row_descriptor ')' all_Op '(' select_subclause ')'
33153264
{
33163265
$$ = cat_str(7, make_str("("), $2, make_str(")"), $4, make_str("("), $6, make_str(")"));
33173266
}
@@ -3491,7 +3440,7 @@ a_expr: c_expr
34913440
{
34923441
$$ = cat_str(4, $1, make_str(" not in ("), $5, make_str(")"));
34933442
}
3494-
| a_expr all_Op sub_type '(' SubSelect ')'
3443+
| a_expr all_Op sub_type '(' select_subclause ')'
34953444
{
34963445
$$ = cat_str(6, $1, $2, $3, make_str("("), $5, make_str(")"));
34973446
}
@@ -3638,9 +3587,9 @@ c_expr: attr
36383587
{ $$ = cat_str(3, make_str("trim(trailing"), $4, make_str(")")); }
36393588
| TRIM '(' trim_list ')'
36403589
{ $$ = cat_str(3, make_str("trim("), $3, make_str(")")); }
3641-
| '(' SubSelect ')'
3590+
| '(' select_subclause ')'
36423591
{ $$ = cat_str(3, make_str("("), $2, make_str(")")); }
3643-
| EXISTS '(' SubSelect ')'
3592+
| EXISTS '(' select_subclause ')'
36443593
{ $$ = cat_str(3, make_str("exists("), $3, make_str(")")); }
36453594
;
36463595
/*
@@ -3719,7 +3668,7 @@ trim_list: a_expr FROM expr_list
37193668
{ $$ = $1; }
37203669
;
37213670

3722-
in_expr: SubSelect
3671+
in_expr: select_subclause
37233672
{
37243673
$$ = $1;
37253674
}
@@ -5164,6 +5113,7 @@ ECPGColId: ident { $$ = $1; }
51645113
| TokenId { $$ = $1; }
51655114
| INTERVAL { $$ = make_str("interval"); }
51665115
| NATIONAL { $$ = make_str("national"); }
5116+
| NONE { $$ = make_str("none"); }
51675117
| PATH_P { $$ = make_str("path_p"); }
51685118
| SERIAL { $$ = make_str("serial"); }
51695119
| TIME { $$ = make_str("time"); }
@@ -5177,7 +5127,7 @@ ECPGColLabel: ECPGColId { $$ = $1; }
51775127
| ANALYZE { $$ = make_str("analyze"); }
51785128
| ANY { $$ = make_str("any"); }
51795129
| ASC { $$ = make_str("asc"); }
5180-
| BETWEEN { $$ = make_str("between"); }
5130+
| BETWEEN { $$ = make_str("between"); }
51815131
| BINARY { $$ = make_str("binary"); }
51825132
| BIT { $$ = make_str("bit"); }
51835133
| BOTH { $$ = make_str("both"); }
@@ -5236,7 +5186,6 @@ ECPGColLabel: ECPGColId { $$ = $1; }
52365186
| NATURAL { $$ = make_str("natural"); }
52375187
| NCHAR { $$ = make_str("nchar"); }
52385188
| NEW { $$ = make_str("new"); }
5239-
| NONE { $$ = make_str("none"); }
52405189
| NOT { $$ = make_str("not"); }
52415190
| NOTNULL { $$ = make_str("notnull"); }
52425191
| NULLIF { $$ = make_str("nullif"); }

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy