Skip to content

Allow %empty followed by %prec#538

Merged
ltratt merged 1 commit intosoftdevteam:masterfrom
ratmice:issue_473_empty_prec
Mar 22, 2025
Merged

Allow %empty followed by %prec#538
ltratt merged 1 commit intosoftdevteam:masterfrom
ratmice:issue_473_empty_prec

Conversation

@ratmice
Copy link
Collaborator

@ratmice ratmice commented Mar 22, 2025

If one applies the following patch to the grammar in the zip archive linked from #473
to uncomment the %prec directives, and run the file through nimbleparse.

--- postgresql-16-naked.y       2024-11-21 10:36:08.000000000 -0800
+++ postgresql-16-naked.uncommented.y   2025-03-22 10:20:37.708582643 -0700
@@ -4572,7 +4572,7 @@

 opt_existing_window_name :
        ColId
-       | %empty //%prec Op /*16L*/
+       | %empty %prec Op /*16L*/
        ;

 opt_partition_clause :
@@ -4842,7 +4842,7 @@
        | WITH /*13N*/ UNIQUE /*11N*/
        | WITHOUT /*13N*/ UNIQUE /*11N*/ KEYS /*12N*/
        | WITHOUT /*13N*/ UNIQUE /*11N*/
-       | %empty //%prec KEYS /*12N*/
+       | %empty %prec KEYS /*12N*/
        ;

 json_name_and_value_list :

You currently get an error "%empty used in non-empty production".

[Error] in postgresql-16-naked.uncommented.y
    4575|       | %empty %prec Op /*16L*/
              %empty used in non-empty production

    554|        | MODE_PLPGSQL_EXPR PLpgSQL_Expr
                              ^^^^^^^^^^^^ Unknown reference to rule 'PLpgSQL_Expr'

This relaxes that error message so that %prec is accepted after %empty.
in #453 there was also a question about whether %prec x should be accepted without quotes around 'x'.
I believe that the usage of %prec Op here seems to confirm that.

I wasn't able to test this with the provided input.txt, the lexer seems to be missing the necessary tokens.
but with this change I was able to run the modified grammar over the empty string. Producing an empty parse tree.

echo -n '' | ./target/release/nimbleparse -y original postgresql-16-naked.l postgresql-16-naked.uncommented.y -
[Warning] in postgresql-16-naked.uncommented.y
    3686|       select_no_parens %prec UMINUS /*22R*/
                                  ^^^^^^ Unused token


parse_toplevel
 stmtmulti
  toplevel_stmt
   stmt

@ltratt
Copy link
Member

ltratt commented Mar 22, 2025

I think this is an improvement, even though I'm sure we could improve things further again.

@ltratt ltratt added this pull request to the merge queue Mar 22, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 22, 2025
@ratmice
Copy link
Collaborator Author

ratmice commented Mar 22, 2025

Needed a rustfmt (Should I just automatically squash for changes like this?).

@ltratt
Copy link
Member

ltratt commented Mar 22, 2025

Yes for small changes like this, please feel free to squash directly (but don't rebase because the makes the compare button in github useless).

@ratmice ratmice force-pushed the issue_473_empty_prec branch from 70f1b94 to ecb81c1 Compare March 22, 2025 21:24
@ratmice
Copy link
Collaborator Author

ratmice commented Mar 22, 2025

Squashed.

@ltratt ltratt added this pull request to the merge queue Mar 22, 2025
Merged via the queue into softdevteam:master with commit e2e5c5b Mar 22, 2025
2 checks passed
@ratmice ratmice deleted the issue_473_empty_prec branch March 22, 2025 21:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants