Skip to content

Can't finish or takes forever with postgres16 grammar #473

@mingodad

Description

@mingodad

While testing this project with a fresh clone and build with a postgres16 grammar the nimbleparse takes forever (I've killed it) see attached grammar/lexer/input.

/usr/bin/time ../target/release/nimbleparse postgresql-16-naked.l postgresql-16-naked.y input.txt

This is the output of bison :

/usr/bin/time bison-nb postgresql-16-naked.y
>/usr/bin/time bison-nb postgresql-16-naked.y
postgresql-16-naked.y: warning: 8 shift/reduce conflicts [-Wconflicts-sr]
postgresql-16-naked.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
1.37user 0.02system 0:01.37elapsed 101%CPU (0avgtext+0avgdata 17944maxresident)k
0inputs+4016outputs (0major+10957minor)pagefaults 0swaps

Notice that the 8 shift/reduce conflicts are due to the changes in the grammar to be accepted by nimbleparse that doesn't accept empty rules with %prec that are used in the postgres16 grammar:

...
opt_existing_window_name :
	ColId
	| %empty //%prec Op /*16L*/
	;
...
json_key_uniqueness_constraint_opt :
	WITH /*13N*/ UNIQUE /*11N*/ KEYS /*12N*/
	| WITH /*13N*/ UNIQUE /*11N*/
	| WITHOUT /*13N*/ UNIQUE /*11N*/ KEYS /*12N*/
	| WITHOUT /*13N*/ UNIQUE /*11N*/
	| %empty //%prec KEYS /*12N*/
	;
...

You can also see how https://github.com/BenHanson/parsertl14 handle it and several others with wasm in the browser here https://mingodad.github.io/parsertl-playground/playground/ (select Postgresql parser (be patient) from Examples then click Parse to see a parse tree for the content in Input source).

build master parser -> Time taken : 70ms
parse user grammar -> Time taken : 6ms
start build user grammar -> Time taken : 2ms
build user parser -> Time taken : 1077ms
dump input parser tree -> Time taken : 10ms

postgres16.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions