Re: Grammar-problems with pl/pgsql in gram.y - Mailing list pgsql-hackers
From | Klaus Reger |
---|---|
Subject | Re: Grammar-problems with pl/pgsql in gram.y |
Date | |
Msg-id | 200105161657.f4GGvSa05143@pc01.reger-clan.de Whole thread Raw |
In response to | Re: Grammar-problems with pl/pgsql in gram.y (Jan Wieck <JanWieck@Yahoo.com>) |
Responses |
Re: Grammar-problems with pl/pgsql in gram.y
Re: Grammar-problems with pl/pgsql in gram.y |
List | pgsql-hackers |
Am Mittwoch, 16. Mai 2001 16:10 schrieb Jan Wieck: > Here it is. stmt_else is defined as type <stmts>, not <stmt>. > The PLpgSQL_stmt_if struct has a condition query and two > statement lists (type <stmts>). You're trying to put a single > statement into the else part instead of a list of statements. Thank you for the hint! That was it. > Maybe it'll work if you surround it with another > PLpgSQL_stmts struct where your new PLpgSQL_stmt_if is the > only statement in it's list. Since I have some bigger work > outstanding for PL/pgSQL, send the resulting patch (if you > get it to work) directly to me. The patch follows this message. May you tell me what kind of work it is, cause I'm so curous :-). By the way, the next thing I try is a EXCEPTION WHEN OTHER-clause, like in Oracle. Let's look if I'm successful. Ciao, Klaus ---------------------------------------------------------------------------- diff -Naurb src/gram.y src.elsif/gram.y --- src/gram.y Wed May 16 18:00:53 2001 +++ src.elsif/gram.y Wed May 16 17:39:19 2001 @@ -147,6 +147,7 @@%token K_DIAGNOSTICS%token K_DOTDOT%token K_ELSE +%token K_ELSIF%token K_END%token K_EXCEPTION%token K_EXECUTE @@ -544,6 +545,7 @@ new->stmts[0] = (struct PLpgSQL_stmt *)$1; $$ = new; + } ; @@ -721,8 +723,53 @@ memset(new, 0, sizeof(PLpgSQL_stmts)); $$ = new; } + | K_ELSIF lno expr_until_then proc_sect stmt_else + { + /* + * Translate the structure: into: + * + * IF c1 THEN IF c1 THEN + * ... ... + * ELSIF c2 THEN ELSE + * IF c2 THEN + * ... ... + * ELSE ELSE + * ... ... + * END IF END IF + * END IF + * + */ + + PLpgSQL_stmts *new; + PLpgSQL_stmt_if *new_if; + + /* first create a new if-statement */ + new_if = malloc(sizeof(PLpgSQL_stmt_if)); + memset(new_if, 0, sizeof(PLpgSQL_stmt_if)); + + new_if->cmd_type = PLPGSQL_STMT_IF; + new_if->lineno = $2; + new_if->cond = $3; + new_if->true_body = $4; + new_if->false_body = $5; + + /* this is a 'container' for the if-statement */ + new = malloc(sizeof(PLpgSQL_stmts)); + memset(new, 0, sizeof(PLpgSQL_stmts)); + + new->stmts_alloc = 64; + new->stmts_used = 1; + new->stmts = malloc(sizeof(PLpgSQL_stmt *) * new->stmts_alloc); + new->stmts[0] = (struct PLpgSQL_stmt *)new_if; + + $$ = new; + + } + | K_ELSE proc_sect - { $$ = $2; } + { + $$ = $2; + } ;stmt_loop : opt_label K_LOOP lno loop_body @@ -1271,7 +1318,6 @@ break; } } - expr = malloc(sizeof(PLpgSQL_expr) + sizeof(int) * nparams - sizeof(int)); expr->dtype = PLPGSQL_DTYPE_EXPR; expr->query = strdup(plpgsql_dstring_get(&ds)); diff -Naurb src/scan.l src.elsif/scan.l --- src/scan.l Wed May 16 18:01:36 2001 +++ src.elsif/scan.l Tue May 15 12:49:43 2001 @@ -99,6 +99,7 @@default { return K_DEFAULT; }diagnostics { return K_DIAGNOSTICS; }else { return K_ELSE; } +elsif { return K_ELSIF; }end { return K_END; }exception { returnK_EXCEPTION; }execute { return K_EXECUTE; }
pgsql-hackers by date: