Thread: PostgreSQL-13.3 parser.y with positional references by named references
PostgreSQL-13.3 parser.y with positional references by named references
From
Domingo Alvarez Duarte
Date:
Here https://gist.github.com/mingodad/49291e0e9505522c66fcd3fcea4a939d I posted the postgresql-13.3/src/backend/parser/gram.y with positional references by named references that is supported by bison for some time now. It was done with a custom script and some comments are missing, if there is any interest in accept it I could try work on it to include the missing comments and a different code layout. It compiles on ubuntu 18.04. I did a similar contribution here https://github.com/facebookincubator/CG-SQL/pull/6 And here is snippet of how it looks like: ==== opt_all_clause: ALL { $opt_all_clause = NIL;} | /*EMPTY*/ { $opt_all_clause = NIL; } ; opt_sort_clause: sort_clause { $opt_sort_clause = $sort_clause;} | /*EMPTY*/ { $opt_sort_clause = NIL; } ; sort_clause: ORDER BY sortby_list { $sort_clause = $sortby_list; } ; sortby_list: sortby { $sortby_list = list_make1($sortby); } | sortby_list[rhs_1] ',' sortby { $$ /* sortby_list */ = lappend($rhs_1, $sortby); } ; sortby: a_expr USING qual_all_Op opt_nulls_order { $sortby = makeNode(SortBy); $sortby->node = $a_expr; $sortby->sortby_dir = SORTBY_USING; $sortby->sortby_nulls = $opt_nulls_order; $sortby->useOp = $qual_all_Op; $sortby->location = @qual_all_Op; } | a_expr opt_asc_desc opt_nulls_order { $sortby = makeNode(SortBy); $sortby->node = $a_expr; $sortby->sortby_dir = $opt_asc_desc; $sortby->sortby_nulls = $opt_nulls_order; $sortby->useOp = NIL; $sortby->location = -1; /* no operator */ } ; ==== Cheers !
Domingo Alvarez Duarte <mingodad@gmail.com> writes: > Here https://gist.github.com/mingodad/49291e0e9505522c66fcd3fcea4a939d I > posted the postgresql-13.3/src/backend/parser/gram.y with positional > references by named references that is supported by bison for some time now. When is "some time now"? Currently, we support bison versions back to 1.875. While we'd be willing to raise that bar as soon as a good reason to do so comes along, I'm not sure that getting rid of $N notation is a sufficient reason. Indeed, I'd say getting rid of $$ is a strict loss; the changes you show make actions much more verbose but certainly not any more readable. Having a special notation for a rule's output seems to me like a good thing not a bad one. The examples of named notation in the Bison docs don't seem like unconditional wins either; they're not very concise, and the contortions you're forced into when the same nonterminal type is used more than once in a rule are just horrid. I do see the point about it being annoying to update $N references when a rule is changed. But this solution has enough downsides that I'm not sure it's a net win. Maybe if it were applied selectively, to just the longer DDL productions, it'd be worth doing? regards, tom lane
Re: PostgreSQL-13.3 parser.y with positional references by named references
From
Peter Eisentraut
Date:
On 04.07.21 17:58, Tom Lane wrote: > Domingo Alvarez Duarte <mingodad@gmail.com> writes: >> Here https://gist.github.com/mingodad/49291e0e9505522c66fcd3fcea4a939d I >> posted the postgresql-13.3/src/backend/parser/gram.y with positional >> references by named references that is supported by bison for some time now. > > When is "some time now"? release 2.5 (2011-05-14) > I do see the point about it being annoying to update $N references > when a rule is changed. But this solution has enough downsides that > I'm not sure it's a net win. Maybe if it were applied selectively, > to just the longer DDL productions, it'd be worth doing? I agree that it should be applied selectively.
Re: PostgreSQL-13.3 parser.y with positional references by named references
From
ilmari@ilmari.org (Dagfinn Ilmari Mannsåker)
Date:
Peter Eisentraut <peter.eisentraut@enterprisedb.com> writes: > On 04.07.21 17:58, Tom Lane wrote: >> Domingo Alvarez Duarte <mingodad@gmail.com> writes: >>> Here https://gist.github.com/mingodad/49291e0e9505522c66fcd3fcea4a939d I >>> posted the postgresql-13.3/src/backend/parser/gram.y with positional >>> references by named references that is supported by bison for some time now. >> >> When is "some time now"? > > release 2.5 (2011-05-14) Do we support building on RHEL6? It only ships bison 2.4, so that would mean people building on that would have to install it seprately. - ilmari
ilmari@ilmari.org (Dagfinn Ilmari =?utf-8?Q?Manns=C3=A5ker?=) writes: > Peter Eisentraut <peter.eisentraut@enterprisedb.com> writes: >> On 04.07.21 17:58, Tom Lane wrote: >>> When is "some time now"? >> release 2.5 (2011-05-14) > Do we support building on RHEL6? It only ships bison 2.4, so that would > mean people building on that would have to install it seprately. A quick look through the buildfarm shows these animals that would be unhappy: sysname | snapshot | l gaur | 2021-07-03 22:56:25 | configure:using bison (GNU Bison) 1.875 prairiedog | 2021-07-07 06:38:15 | configure: using bison (GNU Bison) 1.875 locust | 2021-07-07 07:15:22 | configure: using bison (GNU Bison) 2.3 longfin | 2021-07-07 04:39:09 | configure: using bison (GNU Bison) 2.3 sifaka | 2021-07-07 04:33:58 | configure: using bison (GNU Bison) 2.3 anole | 2021-07-01 15:50:38 | configure: using bison (GNU Bison) 2.4.1 gharial | 2021-07-05 08:00:48 | configure: using bison (GNU Bison) 2.4.1 walleye | 2021-07-07 06:55:35 | configure: using bison (GNU Bison) 2.4.2 jacana | 2021-07-06 03:00:44 | Jul 05 23:00:49 configure: using bison (GNU Bison) 2.4.2 (hmm, almost half of those are mine :-(). The main thing I take away from this is that Apple is still shipping 2.3, which means that requiring 2.5 would completely break the ability to build on macOS without using anything from homebrew or macports. That seems like moving the goalposts pretty far for a minor developer-convenience feature. regards, tom lane
Re: PostgreSQL-13.3 parser.y with positional references by named references
From
Domingo Alvarez Duarte
Date:
I understand the concerns but I would not qualify it as "minor developer-convenience feature". I'm not impartial because the initial suggestion was mine, just to add more options to be considered: What if the generated parser/lexer be present in the tarball distributions ? Cheers ! On 7/7/21 17:14, Tom Lane wrote: > ilmari@ilmari.org (Dagfinn Ilmari =?utf-8?Q?Manns=C3=A5ker?=) writes: >> Peter Eisentraut <peter.eisentraut@enterprisedb.com> writes: >>> On 04.07.21 17:58, Tom Lane wrote: >>>> When is "some time now"? >>> release 2.5 (2011-05-14) >> Do we support building on RHEL6? It only ships bison 2.4, so that would >> mean people building on that would have to install it seprately. > A quick look through the buildfarm shows these animals that would be > unhappy: > > sysname | snapshot | l gaur | 2021-07-03 22:56:25 |configure: using bison (GNU Bison) 1.875 > prairiedog | 2021-07-07 06:38:15 | configure: using bison (GNU Bison) 1.875 > locust | 2021-07-07 07:15:22 | configure: using bison (GNU Bison) 2.3 > longfin | 2021-07-07 04:39:09 | configure: using bison (GNU Bison) 2.3 > sifaka | 2021-07-07 04:33:58 | configure: using bison (GNU Bison) 2.3 > anole | 2021-07-01 15:50:38 | configure: using bison (GNU Bison) 2.4.1 > gharial | 2021-07-05 08:00:48 | configure: using bison (GNU Bison) 2.4.1 > walleye | 2021-07-07 06:55:35 | configure: using bison (GNU Bison) 2.4.2 > jacana | 2021-07-06 03:00:44 | Jul 05 23:00:49 configure: using bison (GNU Bison) 2.4.2 > > (hmm, almost half of those are mine :-(). The main thing I take away > from this is that Apple is still shipping 2.3, which means that requiring > 2.5 would completely break the ability to build on macOS without using > anything from homebrew or macports. That seems like moving the goalposts > pretty far for a minor developer-convenience feature. > > regards, tom lane
Domingo Alvarez Duarte <mingodad@gmail.com> writes: > What if the generated parser/lexer be present in the tarball distributions ? It is. The discussion here is about developer convenience (how painful is it to read or modify a rule) versus developer convenience (what hoops have you got to jump through to install a version of Bison that will work, when building from a git checkout). Note however that the set of developers affected by the second aspect is much larger than those affected by the first. Lots of people who work on PG never mess with the grammar. regards, tom lane