Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit dbedc46

Browse files
committed
ecpg: invent a saner syntax for ecpg.addons entries.
Put the rule type at the start not the end, and put spaces between the constitutent token names instead of smashing them into an illegible mess. This has no functional impact but I think it makes the rules a great deal more readable. Discussion: https://postgr.es/m/1185216.1724001216@sss.pgh.pa.us
1 parent 143e3a1 commit dbedc46

File tree

3 files changed

+107
-98
lines changed

3 files changed

+107
-98
lines changed

src/interfaces/ecpg/preproc/README.parser

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,19 @@ continue to use the normal Bison notations.)
4040

4141

4242
ecpg.addons contains entries that begin with a line like
43-
ECPG: concattokens ruletype
43+
ECPG: ruletype tokenlist
4444
and typically have one or more following lines that are the code
4545
for a grammar action. Any line not starting with "ECPG:" is taken
4646
to be part of the code block for the preceding "ECPG:" line.
4747

48-
"concattokens" identifies which gram.y production this entry affects.
49-
It is simply the target nonterminal and the tokens from the gram.y rule
50-
concatenated together. For example, to modify the action for a gram.y
51-
rule like this:
48+
"tokenlist" identifies which gram.y production this entry affects.
49+
It is simply a list of the target nonterminal and the input tokens
50+
from the gram.y rule. For example, to modify the action for a
51+
gram.y rule like this:
5252
target: tokenA tokenB tokenC {...}
53-
"concattokens" would be "targettokenAtokenBtokenC". If we want to
53+
"tokenlist" would be "target tokenA tokenB tokenC". If we want to
5454
modify a non-first alternative for a nonterminal, we still write the
55-
nonterminal. For example, "concattokens" should be "targettokenDtokenE"
55+
nonterminal. For example, "tokenlist" should be "target tokenD tokenE"
5656
to affect the second alternative in:
5757
target: tokenA tokenB tokenC {...}
5858
| tokenD tokenE {...}
@@ -72,7 +72,7 @@ c) "rule" - the automatic action is emitted, but then the entry's
7272
code block is added verbatim afterwards. This typically is
7373
used to add new alternatives to a nonterminal of the core grammar.
7474
For example, given the entry:
75-
ECPG: targettokenAtokenBtokenC rule
75+
ECPG: rule target tokenA tokenB tokenC
7676
| tokenD tokenE { custom_action; }
7777
what will be emitted is
7878
target: tokenA tokenB tokenC { automatic_action; }

src/interfaces/ecpg/preproc/ecpg.addons

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* src/interfaces/ecpg/preproc/ecpg.addons */
2-
ECPG: stmtClosePortalStmt block
2+
ECPG: block stmt ClosePortalStmt
33
{
44
if (INFORMIX_MODE)
55
{
@@ -16,23 +16,23 @@ ECPG: stmtClosePortalStmt block
1616

1717
output_statement(@1, 0, ECPGst_normal);
1818
}
19-
ECPG: stmtDeallocateStmt block
19+
ECPG: block stmt DeallocateStmt
2020
{
2121
output_deallocate_prepare_statement(@1);
2222
}
23-
ECPG: stmtDeclareCursorStmt block
23+
ECPG: block stmt DeclareCursorStmt
2424
{
2525
output_simple_statement(@1, (strncmp(@1, "ECPGset_var", strlen("ECPGset_var")) == 0) ? 4 : 0);
2626
}
27-
ECPG: stmtDiscardStmt block
28-
ECPG: stmtFetchStmt block
27+
ECPG: block stmt DiscardStmt
28+
ECPG: block stmt FetchStmt
2929
{ output_statement(@1, 1, ECPGst_normal); }
30-
ECPG: stmtDeleteStmt block
31-
ECPG: stmtInsertStmt block
32-
ECPG: stmtSelectStmt block
33-
ECPG: stmtUpdateStmt block
30+
ECPG: block stmt DeleteStmt
31+
ECPG: block stmt InsertStmt
32+
ECPG: block stmt SelectStmt
33+
ECPG: block stmt UpdateStmt
3434
{ output_statement(@1, 1, ECPGst_prepnormal); }
35-
ECPG: stmtExecuteStmt block
35+
ECPG: block stmt ExecuteStmt
3636
{
3737
check_declared_list($1.name);
3838
if ($1.type == NULL || strlen($1.type) == 0)
@@ -57,7 +57,7 @@ ECPG: stmtExecuteStmt block
5757
output_statement(cat_str(3, "execute", "$0", $1.type), 0, ECPGst_exec_with_exprlist);
5858
}
5959
}
60-
ECPG: stmtPrepareStmt block
60+
ECPG: block stmt PrepareStmt
6161
{
6262
check_declared_list($1.name);
6363
if ($1.type == NULL)
@@ -87,17 +87,17 @@ ECPG: stmtPrepareStmt block
8787
output_statement(cat_str(5, "prepare", "$0", $1.type, "as", $1.stmt), 0, ECPGst_prepare);
8888
}
8989
}
90-
ECPG: stmtTransactionStmt block
90+
ECPG: block stmt TransactionStmt
9191
{
9292
fprintf(base_yyout, "{ ECPGtrans(__LINE__, %s, \"%s\");", connection ? connection : "NULL", @1);
9393
whenever_action(2);
9494
}
95-
ECPG: toplevel_stmtTransactionStmtLegacy block
95+
ECPG: block toplevel_stmt TransactionStmtLegacy
9696
{
9797
fprintf(base_yyout, "{ ECPGtrans(__LINE__, %s, \"%s\");", connection ? connection : "NULL", @1);
9898
whenever_action(2);
9999
}
100-
ECPG: stmtViewStmt rule
100+
ECPG: rule stmt ViewStmt
101101
| ECPGAllocateDescr
102102
{
103103
fprintf(base_yyout, "ECPGallocate_desc(__LINE__, %s);", @1);
@@ -231,45 +231,45 @@ ECPG: stmtViewStmt rule
231231

232232
output_simple_statement(@1, 0);
233233
}
234-
ECPG: where_or_current_clauseWHERECURRENT_POFcursor_name block
234+
ECPG: block where_or_current_clause WHERE CURRENT_P OF cursor_name
235235
{
236236
const char *cursor_marker = @4[0] == ':' ? "$0" : @4;
237237

238238
@$ = cat_str(2, "where current of", cursor_marker);
239239
}
240-
ECPG: CopyStmtCOPYopt_binaryqualified_nameopt_column_listcopy_fromopt_programcopy_file_namecopy_delimiteropt_withcopy_optionswhere_clause addon
240+
ECPG: addon CopyStmt COPY opt_binary qualified_name opt_column_list copy_from opt_program copy_file_name copy_delimiter opt_with copy_options where_clause
241241
if (strcmp(@6, "from") == 0 &&
242242
(strcmp(@7, "stdin") == 0 || strcmp(@7, "stdout") == 0))
243243
mmerror(PARSE_ERROR, ET_WARNING, "COPY FROM STDIN is not implemented");
244-
ECPG: var_valueNumericOnly addon
244+
ECPG: addon var_value NumericOnly
245245
if (@1[0] == '$')
246246
@$ = "$0";
247-
ECPG: fetch_argscursor_name addon
247+
ECPG: addon fetch_args cursor_name
248248
struct cursor *ptr = add_additional_variables(@1, false);
249249

250250
if (ptr->connection)
251251
connection = mm_strdup(ptr->connection);
252252
if (@1[0] == ':')
253253
@$ = "$0";
254-
ECPG: fetch_argsfrom_incursor_name addon
254+
ECPG: addon fetch_args from_in cursor_name
255255
struct cursor *ptr = add_additional_variables(@2, false);
256256

257257
if (ptr->connection)
258258
connection = mm_strdup(ptr->connection);
259259
if (@2[0] == ':')
260260
@$ = cat2_str(@1, "$0");
261-
ECPG: fetch_argsNEXTopt_from_incursor_name addon
262-
ECPG: fetch_argsPRIORopt_from_incursor_name addon
263-
ECPG: fetch_argsFIRST_Popt_from_incursor_name addon
264-
ECPG: fetch_argsLAST_Popt_from_incursor_name addon
265-
ECPG: fetch_argsALLopt_from_incursor_name addon
261+
ECPG: addon fetch_args NEXT opt_from_in cursor_name
262+
ECPG: addon fetch_args PRIOR opt_from_in cursor_name
263+
ECPG: addon fetch_args FIRST_P opt_from_in cursor_name
264+
ECPG: addon fetch_args LAST_P opt_from_in cursor_name
265+
ECPG: addon fetch_args ALL opt_from_in cursor_name
266266
struct cursor *ptr = add_additional_variables(@3, false);
267267

268268
if (ptr->connection)
269269
connection = mm_strdup(ptr->connection);
270270
if (@3[0] == ':')
271271
@$ = cat_str(3, @1, @2, "$0");
272-
ECPG: fetch_argsSignedIconstopt_from_incursor_name addon
272+
ECPG: addon fetch_args SignedIconst opt_from_in cursor_name
273273
struct cursor *ptr = add_additional_variables(@3, false);
274274
bool replace = false;
275275

@@ -287,18 +287,18 @@ ECPG: fetch_argsSignedIconstopt_from_incursor_name addon
287287
}
288288
if (replace)
289289
@$ = cat_str(3, @1, @2, @3);
290-
ECPG: fetch_argsFORWARDALLopt_from_incursor_name addon
291-
ECPG: fetch_argsBACKWARDALLopt_from_incursor_name addon
290+
ECPG: addon fetch_args FORWARD ALL opt_from_in cursor_name
291+
ECPG: addon fetch_args BACKWARD ALL opt_from_in cursor_name
292292
struct cursor *ptr = add_additional_variables(@4, false);
293293

294294
if (ptr->connection)
295295
connection = mm_strdup(ptr->connection);
296296
if (@4[0] == ':')
297297
@$ = cat_str(4, @1, @2, @3, "$0");
298-
ECPG: fetch_argsABSOLUTE_PSignedIconstopt_from_incursor_name addon
299-
ECPG: fetch_argsRELATIVE_PSignedIconstopt_from_incursor_name addon
300-
ECPG: fetch_argsFORWARDSignedIconstopt_from_incursor_name addon
301-
ECPG: fetch_argsBACKWARDSignedIconstopt_from_incursor_name addon
298+
ECPG: addon fetch_args ABSOLUTE_P SignedIconst opt_from_in cursor_name
299+
ECPG: addon fetch_args RELATIVE_P SignedIconst opt_from_in cursor_name
300+
ECPG: addon fetch_args FORWARD SignedIconst opt_from_in cursor_name
301+
ECPG: addon fetch_args BACKWARD SignedIconst opt_from_in cursor_name
302302
struct cursor *ptr = add_additional_variables(@4, false);
303303
bool replace = false;
304304

@@ -316,19 +316,19 @@ ECPG: fetch_argsBACKWARDSignedIconstopt_from_incursor_name addon
316316
}
317317
if (replace)
318318
@$ = cat_str(4, @1, @2, @3, @4);
319-
ECPG: cursor_namename block
319+
ECPG: block cursor_name name
320320
| char_civar
321321
{
322322
char *curname = loc_alloc(strlen(@1) + 2);
323323

324324
sprintf(curname, ":%s", @1);
325325
@$ = curname;
326326
}
327-
ECPG: ExplainableStmtExecuteStmt block
327+
ECPG: block ExplainableStmt ExecuteStmt
328328
{
329329
@$ = $1.name;
330330
}
331-
ECPG: PrepareStmtPREPAREprepared_nameprep_type_clauseASPreparableStmt block
331+
ECPG: block PrepareStmt PREPARE prepared_name prep_type_clause AS PreparableStmt
332332
{
333333
$$.name = @2;
334334
$$.type = @3;
@@ -340,20 +340,20 @@ ECPG: PrepareStmtPREPAREprepared_nameprep_type_clauseASPreparableStmt block
340340
$$.type = NULL;
341341
$$.stmt = @4;
342342
}
343-
ECPG: ExecuteStmtEXECUTEprepared_nameexecute_param_clauseexecute_rest block
343+
ECPG: block ExecuteStmt EXECUTE prepared_name execute_param_clause execute_rest
344344
{
345345
$$.name = @2;
346346
$$.type = @3;
347347
}
348-
ECPG: ExecuteStmtCREATEOptTempTABLEcreate_as_targetASEXECUTEprepared_nameexecute_param_clauseopt_with_dataexecute_rest block
348+
ECPG: block ExecuteStmt CREATE OptTemp TABLE create_as_target AS EXECUTE prepared_name execute_param_clause opt_with_data execute_rest
349349
{
350350
$$.name = @$;
351351
}
352-
ECPG: ExecuteStmtCREATEOptTempTABLEIF_PNOTEXISTScreate_as_targetASEXECUTEprepared_nameexecute_param_clauseopt_with_dataexecute_rest block
352+
ECPG: block ExecuteStmt CREATE OptTemp TABLE IF_P NOT EXISTS create_as_target AS EXECUTE prepared_name execute_param_clause opt_with_data execute_rest
353353
{
354354
$$.name = @$;
355355
}
356-
ECPG: DeclareCursorStmtDECLAREcursor_namecursor_optionsCURSORopt_holdFORSelectStmt block
356+
ECPG: block DeclareCursorStmt DECLARE cursor_name cursor_options CURSOR opt_hold FOR SelectStmt
357357
{
358358
struct cursor *ptr,
359359
*this;
@@ -403,7 +403,7 @@ ECPG: DeclareCursorStmtDECLAREcursor_namecursor_optionsCURSORopt_holdFORSelectSt
403403

404404
@$ = cat2_str(adjust_outofscope_cursor_vars(this), comment);
405405
}
406-
ECPG: ClosePortalStmtCLOSEcursor_name block
406+
ECPG: block ClosePortalStmt CLOSE cursor_name
407407
{
408408
const char *cursor_marker = @2[0] == ':' ? "$0" : @2;
409409
struct cursor *ptr = NULL;
@@ -419,14 +419,14 @@ ECPG: ClosePortalStmtCLOSEcursor_name block
419419
}
420420
@$ = cat2_str("close", cursor_marker);
421421
}
422-
ECPG: opt_hold block
422+
ECPG: block opt_hold
423423
{
424424
if (compat == ECPG_COMPAT_INFORMIX_SE && autocommit)
425425
@$ = "with hold";
426426
else
427427
@$ = "";
428428
}
429-
ECPG: into_clauseINTOOptTempTableName block
429+
ECPG: block into_clause INTO OptTempTableName
430430
{
431431
FoundInto = 1;
432432
@$ = cat2_str("into", @2);
@@ -435,15 +435,15 @@ ECPG: into_clauseINTOOptTempTableName block
435435
{
436436
@$ = "";
437437
}
438-
ECPG: TypenameSimpleTypenameopt_array_bounds block
438+
ECPG: block Typename SimpleTypename opt_array_bounds
439439
{
440440
@$ = cat2_str(@1, $2.str);
441441
}
442-
ECPG: TypenameSETOFSimpleTypenameopt_array_bounds block
442+
ECPG: block Typename SETOF SimpleTypename opt_array_bounds
443443
{
444444
@$ = cat_str(3, "setof", @2, $3.str);
445445
}
446-
ECPG: opt_array_boundsopt_array_bounds'['']' block
446+
ECPG: block opt_array_bounds opt_array_bounds '[' ']'
447447
{
448448
$$.index1 = $1.index1;
449449
$$.index2 = $1.index2;
@@ -463,20 +463,20 @@ ECPG: opt_array_boundsopt_array_bounds'['']' block
463463
$$.index2 = @3;
464464
$$.str = cat_str(4, $1.str, "[", @3, "]");
465465
}
466-
ECPG: opt_array_bounds block
466+
ECPG: block opt_array_bounds
467467
{
468468
$$.index1 = "-1";
469469
$$.index2 = "-1";
470470
$$.str = "";
471471
}
472-
ECPG: AexprConstNULL_P rule
472+
ECPG: rule AexprConst NULL_P
473473
| civar
474474
| civarind
475-
ECPG: VariableShowStmtSHOWALL block
475+
ECPG: block VariableShowStmt SHOW ALL
476476
{
477477
mmerror(PARSE_ERROR, ET_ERROR, "SHOW ALL is not implemented");
478478
}
479-
ECPG: FetchStmtMOVEfetch_args rule
479+
ECPG: rule FetchStmt MOVE fetch_args
480480
| FETCH fetch_args ecpg_fetch_into
481481
| FETCH FORWARD cursor_name opt_ecpg_fetch_into
482482
{
@@ -558,9 +558,9 @@ ECPG: FetchStmtMOVEfetch_args rule
558558

559559
@$ = cat_str(2, "move backward from", cursor_marker);
560560
}
561-
ECPG: limit_clauseLIMITselect_limit_value','select_offset_value block
561+
ECPG: block limit_clause LIMIT select_limit_value ',' select_offset_value
562562
{
563563
mmerror(PARSE_ERROR, ET_WARNING, "no longer supported LIMIT #,# syntax passed to server");
564564
}
565-
ECPG: SignedIconstIconst rule
565+
ECPG: rule SignedIconst Iconst
566566
| civar

0 commit comments

Comments
 (0)