Re: Grammar railroad diagram

2021-07-09 Thread Domingo Alvarez Duarte

Hello Andres !

Another way that I tested and it's working is to use 
https://www.bottlecaps.de/convert/ paste the postgresql grammar there 
and press "convert" and after press "view diagram".


Again optionally manually add the Tokens to a better diagram !



// Tokens from postgresql-13.3/src/include/parser/kwlist.h

ABORT_P ::= "abort"
ABSOLUTE_P ::= "absolute"
ACCESS ::= "access"
ACTION ::= "action"

...



Cheers !

On 9/7/21 4:36, Andres Freund wrote:

Hi,

On 2021-07-03 10:39:02 +0200, Domingo Alvarez Duarte wrote:

I've done a experimental tool to convert bison grammars to a kind of EBNF
understood by https://www.bottlecaps.de/rr/ui

It'd be nice if you could share that tool. The diagrams this can generate
are neat...

Greetings,

Andres Freund





Re: Grammar railroad diagram

2021-07-09 Thread Domingo Alvarez Duarte

Hello Andres !

There is two ways to achieve it:

-1 I just add the bison grammar in CocoR format here 
https://github.com/mingodad/CocoR-CPP in the examples folder.


-2 I created an small extension to Bison to do the same and published 
the patch here 
https://github.com/mingodad/bison/commit/da84329ebe5f4bc111ef34b2d46088b655a217f3 
(bison -e yourgramar.y)


And optionally to have the best railroad diagram we need to add the 
"Tokens" manually.


Cheers !

On 9/7/21 4:36, Andres Freund wrote:

Hi,

On 2021-07-03 10:39:02 +0200, Domingo Alvarez Duarte wrote:

I've done a experimental tool to convert bison grammars to a kind of EBNF
understood by https://www.bottlecaps.de/rr/ui

It'd be nice if you could share that tool. The diagrams this can generate
are neat...

Greetings,

Andres Freund





Re: PostgreSQL-13.3 parser.y with positional references by named references

2021-07-07 Thread Domingo Alvarez Duarte
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:

ilm...@ilmari.org (Dagfinn Ilmari =?utf-8?Q?Manns=C3=A5ker?=) writes:

Peter Eisentraut  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: Grammar railroad diagram

2021-07-06 Thread Domingo Alvarez Duarte

Hello Bruce !

You can download the railroad generator to generate offline using Java 
here -> https://www.bottlecaps.de/rr/download/rr-1.63-java8.zip (link 
from the https://www.bottlecaps.de/rr/ui on tab Welcome).


java -jar rr.war -out:Dafny.atg.xhtml grammar.txt

Cheers !

On 6/7/21 18:51, Bruce Momjian wrote:

On Sat, Jul  3, 2021 at 10:39:02AM +0200, Domingo Alvarez Duarte wrote:

I've done a experimental tool to convert bison grammars to a kind of EBNF
understood by https://www.bottlecaps.de/rr/ui to generate railroad diagrams see
bellow the converted 'postgresql-13.3/src/backend/parser/gram.y' and with some
hand made changes to allow view it at https://www.bottlecaps.de/rr/ui the order
of the rules could be changed to a better view of the railroad diagrams. Copy
and paste the EBNF bellow on https://www.bottlecaps.de/rr/ui tab Edit Grammar
then switch to the tab View Diagram.

That is pretty cool.  I had trouble figuring out how to get it working,
so here are the steps I used:

1.  save my attachment (created by Domingo)
2.  go to https://www.bottlecaps.de/rr/ui
3.  select "Edit Grammar"
4.  choose "Browse" at the bottom
5.  select the attachment you saved in #1
6.  choose "Load" at the bottom
7.  select "View Diagram"

You can even click on the yellow boxes to see the sub-grammar.  People
have asked for railroad diagrams in the past, and this certainly
produces them, and "Options" allows many customizations.

I tried downloading as XHTML+SVG and HTML+PNG but got an error:

HTTP Status 500 – Internal Server Error

Type Exception Report

Message The multi-part request contained parameter data (excluding
uploaded files) that exceeded the limit for maxPostSize set on the
associated connector

Description The server encountered an unexpected condition that
prevented it from fulfilling the request.

It might be nice to download this output and host it on the Postgres
website at some point.






PostgreSQL-13.3 parser.y with positional references by named references

2021-07-04 Thread Domingo Alvarez Duarte
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 !