Improving the notation for ecpg.addons rules

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Improving the notation for ecpg.addons rules
Date: 2024-08-18 17:13:36
Message-ID: 1185216.1724001216@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I've gotten annoyed by the notation used for ecpg.addons rules,
in which all the tokens of the gram.y rule to be modified
are just concatenated. This is unreadable and potentially
ambiguous:

ECPG: fetch_argsABSOLUTE_PSignedIconstopt_from_incursor_name addon

The attached draft patch changes things so that we can write

ECPG: addon fetch_args ABSOLUTE_P SignedIconst opt_from_in cursor_name

which is a whole lot closer to what actually appears in gram.y:

fetch_args: cursor_name
...
| ABSOLUTE_P SignedIconst opt_from_in cursor_name

(Note that I've also moved the rule type "addon" to the front.
This isn't strictly necessary, but it seems less mistake-prone.)

While I've not done it in the attached, perhaps it would be
an improvement to allow a colon after the target nonterminal:

ECPG: addon fetch_args: ABSOLUTE_P SignedIconst opt_from_in cursor_name

to bring it even closer to what is written in gram.y. You could
imagine going further and writing this case as something like

ECPG: addon fetch_args | ABSOLUTE_P SignedIconst opt_from_in cursor_name

but I think that might be a step too far. IMO it's not adding much
readability, and it seems like introducing an unnecessary dependency
on exactly how the gram.y alternatives are laid out.

BTW, the attached patch won't apply to HEAD, it's meant to apply
after the patch series being discussed at [1]. So I won't stick
this in the CF yet.

Thoughts?

regards, tom lane

[1] https://www.postgresql.org/message-id/flat/2011420(dot)1713493114(at)sss(dot)pgh(dot)pa(dot)us

Attachment Content-Type Size
v1-saner-ecpg.addons-syntax.patch text/x-diff 18.3 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tomas Vondra 2024-08-18 18:04:41 Re: Cirrus CI for macOS branches 16 and 15 broken
Previous Message Alexander Lakhin 2024-08-18 16:00:00 Re: The xversion-upgrade test fails to stop server