Chevrotain / chevrotain

Parser Building Toolkit for JavaScript
https://chevrotain.io
Apache License 2.0
2.44k stars 199 forks source link

How to AT_LEAST_ONE without repeats #2007

Closed timneedham closed 7 months ago

timneedham commented 7 months ago

Hi,

First of all - I very much love Chevrotain, great work thank you! :heart: I've come a little unstuck and not quite sure how to progress, any pointers would be really appreciated.

I'm trying to parse this PostgreSQL command:

https://www.postgresql.org/docs/current/sql-grant.html

For example, in this form:

GRANT { { SELECT | INSERT | UPDATE | DELETE | TRUNCATE | REFERENCES | TRIGGER }
    [, ...] | ALL [ PRIVILEGES ] }
    ON { [ TABLE ] table_name [, ...]
         | ALL TABLES IN SCHEMA schema_name [, ...] }
    TO role_specification [, ...] [ WITH GRANT OPTION ]
    [ GRANTED BY role_specification ]

...we can see this is valid:

GRANT SELECT, INSERT, TRIGGER ON TABLE emp TO me;

However, I'm not sure how to model/express { SELECT | INSERT | UPDATE | DELETE | TRUNCATE | REFERENCES | TRIGGER } [, ...] in Chevrotain (AT_LEAST_ONE_SEP has served me well, but I'm struggling to enforce the "no repeated values" requirement and there can be ambiguity with other forms of the command which have shared values like SELECT).

But to confuse matters I'm separating-out the grammar over multiple files using the "proxy" technique mentioned here by @mtiller - with beginner-level Typescript skills I just can't seem to get the two things to spark (parameter rules don't seem happy using the proxy technique and I'm unclear how to resolve it).

Any pointers warmly welcomed! Thanks