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

Feature toggles for language features #1350

Open
Lotes opened this issue Jan 22, 2024 · 0 comments
Open

Feature toggles for language features #1350

Lotes opened this issue Jan 22, 2024 · 0 comments
Labels
grammar Grammar language related issue

Comments

@Lotes
Copy link
Contributor

Lotes commented Jan 22, 2024

In detail by Martin Fowler: https://martinfowler.com/articles/feature-toggles.html

Example

Sometimes development of a features takes very long and you do not want to branch out from the main branch for so long. One possible solution for this are feature toggles. You enable or disable a feature depending on a certain condition (for example the current user group is the beta tester or production group).

Depending on this boolean, you branch your programs behavior: Production users get the old implementation, beta testers the new incomplete version.

Feature toggles in Langium

Old syntax

Toggling language features is actually already possible, but based on constants (that are TRUE or FALSE).

Identifier<QuotedStringAsId>: IDENTIFIER | <QuotedStringAsId> STRING;

//use it later with constant
RuleX: 'blubb' name=Identifier<false>; 
RuleY: 'blip' name=Identifier<true>;

terminal IDENTIFIER: /[a-zA-Z_][a-zA-Z_0-9]*/;
terminal STRING: /“[^"]*"/;

You cannot give in a value from outside currently, but it should be a low hanging fruit, since the conditional rules are already part of Langium.

New syntax

What I would like to propose is a new syntax for feature toggles inside the Langium syntax:

//flag name = default value (default should be false)
feature QuotedStringAsId = false;

Identifier: IDENTIFIER | <QuotedStringAsId> STRING;
...

The Langium generator will additionally add an object of feature toggles:

export type MyGrammarFeatureToggles = {
  QuotedStringAsId: boolean;
};
export const DefaultMyGrammarFeatureToggles: MyGrammarFeatureToggles = {
  QuotedStringAsId: false;
};

The toggles can be dynamically set during creation of the services object. Making them accessible through the services, each child service can access the actual values and react properly if needed.

Original problem

This idea came up from a langium-sql issue. LangiumSQL tries to be a SQL solution for multiple dialects. Dialects differ for identifiers:
MySQL likes double-quoted strings as identifiers. For other dialects it can be a string literal, no identifier. A feature toggle was not the original idea, but it would be possible to implement this uncertainty with feature toggles and decide on a dialect when initializing Langium's services object.

@spoenemann spoenemann added the grammar Grammar language related issue label Feb 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
grammar Grammar language related issue
Projects
None yet
Development

No branches or pull requests

2 participants