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 !



Reply via email to