Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grammar Syntax For Unordered Groups #1422

Open
DennisAtExpleo opened this issue Jun 14, 2024 · 2 comments
Open

Grammar Syntax For Unordered Groups #1422

DennisAtExpleo opened this issue Jun 14, 2024 · 2 comments

Comments

@DennisAtExpleo
Copy link

Preamble: I've read the docs and searched the issues regarding this topic beforehand and I'm actually kind of surprised it didn't come up yet. So excuse me if I overlooked something here.

Is there a dedicated grammar syntax for unordered groups in lark?
Say I want to define a DSL in Lark grammar and I have a set of qualifiers similar to C/C++ which can precede the declaration of a variable in any order, e.g.

private static int a;
static private int b;

Is there a dedicated syntax for this in lark grammar? At the moment, I am solving it by creating an additional terminal which includes all possible combinations of the unordered elements:

decl: qualifier "int" ID ("=" INTEGER)? ";"

qualifier: ("private"? "static"?) | ("static"? "private"?) 

This gets pretty clumsy as soon as you have more than three elements. If not already implemented, I would suggest a solution similar to the syntax in xText, where unordered groups can be defined by combining them using the "&" operator like this:

decl: ("private"? & "static"?) "int" ID ("=" INTEGER)? ";"
@erezsh
Copy link
Member

erezsh commented Jun 14, 2024

Lark doesn't have this feature.

It was implemented in my previous parsing library: https:/erezsh/plyplus/blob/master/plyplus/plyplus.py#L326

It shouldn't be too hard to port this function into Lark's load_grammar.py

@FruitfulApproach
Copy link

Oh, lol! I thought you meant group theory. As we all know that usually finite groups come without any possible ordering that is compatible with the group law. 😂🤓

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants