Skip to content

Define Grammar AST types explicitly, refine EBNF-based terminals to avoid synthetic capturing groups #1966

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions examples/arithmetics/src/language-server/generated/grammar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,8 @@ export const ArithmeticsGrammar = (): Grammar => loadedArithmeticsGrammar ?? (lo
"name": "WS",
"definition": {
"$type": "RegexToken",
"regex": "/\\\\s+/"
"regex": "/\\\\s+/",
"parenthesized": false
},
"fragment": false
},
Expand All @@ -444,7 +445,8 @@ export const ArithmeticsGrammar = (): Grammar => loadedArithmeticsGrammar ?? (lo
"name": "ID",
"definition": {
"$type": "RegexToken",
"regex": "/[_a-zA-Z][\\\\w_]*/"
"regex": "/[_a-zA-Z][\\\\w_]*/",
"parenthesized": false
},
"fragment": false,
"hidden": false
Expand All @@ -458,7 +460,8 @@ export const ArithmeticsGrammar = (): Grammar => loadedArithmeticsGrammar ?? (lo
},
"definition": {
"$type": "RegexToken",
"regex": "/[0-9]+(\\\\.[0-9]*)?/"
"regex": "/[0-9]+(\\\\.[0-9]*)?/",
"parenthesized": false
},
"fragment": false,
"hidden": false
Expand All @@ -469,7 +472,8 @@ export const ArithmeticsGrammar = (): Grammar => loadedArithmeticsGrammar ?? (lo
"name": "ML_COMMENT",
"definition": {
"$type": "RegexToken",
"regex": "/\\\\/\\\\*[\\\\s\\\\S]*?\\\\*\\\\//"
"regex": "/\\\\/\\\\*[\\\\s\\\\S]*?\\\\*\\\\//",
"parenthesized": false
},
"fragment": false
},
Expand All @@ -479,7 +483,8 @@ export const ArithmeticsGrammar = (): Grammar => loadedArithmeticsGrammar ?? (lo
"name": "SL_COMMENT",
"definition": {
"$type": "RegexToken",
"regex": "/\\\\/\\\\/[^\\\\n\\\\r]*/"
"regex": "/\\\\/\\\\/[^\\\\n\\\\r]*/",
"parenthesized": false
},
"fragment": false
}
Expand Down
12 changes: 8 additions & 4 deletions examples/domainmodel/src/language-server/generated/grammar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,8 @@ export const DomainModelGrammar = (): Grammar => loadedDomainModelGrammar ?? (lo
"name": "WS",
"definition": {
"$type": "RegexToken",
"regex": "/\\\\s+/"
"regex": "/\\\\s+/",
"parenthesized": false
},
"fragment": false
},
Expand All @@ -348,7 +349,8 @@ export const DomainModelGrammar = (): Grammar => loadedDomainModelGrammar ?? (lo
"name": "ID",
"definition": {
"$type": "RegexToken",
"regex": "/[_a-zA-Z][\\\\w_]*/"
"regex": "/[_a-zA-Z][\\\\w_]*/",
"parenthesized": false
},
"fragment": false,
"hidden": false
Expand All @@ -359,7 +361,8 @@ export const DomainModelGrammar = (): Grammar => loadedDomainModelGrammar ?? (lo
"name": "ML_COMMENT",
"definition": {
"$type": "RegexToken",
"regex": "/\\\\/\\\\*[\\\\s\\\\S]*?\\\\*\\\\//"
"regex": "/\\\\/\\\\*[\\\\s\\\\S]*?\\\\*\\\\//",
"parenthesized": false
},
"fragment": false
},
Expand All @@ -369,7 +372,8 @@ export const DomainModelGrammar = (): Grammar => loadedDomainModelGrammar ?? (lo
"name": "SL_COMMENT",
"definition": {
"$type": "RegexToken",
"regex": "/\\\\/\\\\/[^\\\\n\\\\r]*/"
"regex": "/\\\\/\\\\/[^\\\\n\\\\r]*/",
"parenthesized": false
},
"fragment": false
}
Expand Down
36 changes: 24 additions & 12 deletions examples/requirements/src/language-server/generated/grammar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@ export const RequirementsGrammar = (): Grammar => loadedRequirementsGrammar ?? (
"name": "WS",
"definition": {
"$type": "RegexToken",
"regex": "/\\\\s+/"
"regex": "/\\\\s+/",
"parenthesized": false
},
"fragment": false
},
Expand All @@ -243,7 +244,8 @@ export const RequirementsGrammar = (): Grammar => loadedRequirementsGrammar ?? (
"name": "ID",
"definition": {
"$type": "RegexToken",
"regex": "/[_a-zA-Z][\\\\w_]*/"
"regex": "/[_a-zA-Z][\\\\w_]*/",
"parenthesized": false
},
"fragment": false,
"hidden": false
Expand All @@ -257,7 +259,8 @@ export const RequirementsGrammar = (): Grammar => loadedRequirementsGrammar ?? (
},
"definition": {
"$type": "RegexToken",
"regex": "/[0-9]+/"
"regex": "/[0-9]+/",
"parenthesized": false
},
"fragment": false,
"hidden": false
Expand All @@ -267,7 +270,8 @@ export const RequirementsGrammar = (): Grammar => loadedRequirementsGrammar ?? (
"name": "STRING",
"definition": {
"$type": "RegexToken",
"regex": "/\\"(\\\\\\\\.|[^\\"\\\\\\\\])*\\"|'(\\\\\\\\.|[^'\\\\\\\\])*'/"
"regex": "/\\"(\\\\\\\\.|[^\\"\\\\\\\\])*\\"|'(\\\\\\\\.|[^'\\\\\\\\])*'/",
"parenthesized": false
},
"fragment": false,
"hidden": false
Expand All @@ -278,7 +282,8 @@ export const RequirementsGrammar = (): Grammar => loadedRequirementsGrammar ?? (
"name": "ML_COMMENT",
"definition": {
"$type": "RegexToken",
"regex": "/\\\\/\\\\*[\\\\s\\\\S]*?\\\\*\\\\//"
"regex": "/\\\\/\\\\*[\\\\s\\\\S]*?\\\\*\\\\//",
"parenthesized": false
},
"fragment": false
},
Expand All @@ -288,7 +293,8 @@ export const RequirementsGrammar = (): Grammar => loadedRequirementsGrammar ?? (
"name": "SL_COMMENT",
"definition": {
"$type": "RegexToken",
"regex": "/\\\\/\\\\/[^\\\\n\\\\r]*/"
"regex": "/\\\\/\\\\/[^\\\\n\\\\r]*/",
"parenthesized": false
},
"fragment": false
}
Expand Down Expand Up @@ -717,7 +723,8 @@ export const TestsGrammar = (): Grammar => loadedTestsGrammar ?? (loadedTestsGra
"name": "WS",
"definition": {
"$type": "RegexToken",
"regex": "/\\\\s+/"
"regex": "/\\\\s+/",
"parenthesized": false
},
"fragment": false
},
Expand All @@ -726,7 +733,8 @@ export const TestsGrammar = (): Grammar => loadedTestsGrammar ?? (loadedTestsGra
"name": "ID",
"definition": {
"$type": "RegexToken",
"regex": "/[_a-zA-Z][\\\\w_]*/"
"regex": "/[_a-zA-Z][\\\\w_]*/",
"parenthesized": false
},
"fragment": false,
"hidden": false
Expand All @@ -740,7 +748,8 @@ export const TestsGrammar = (): Grammar => loadedTestsGrammar ?? (loadedTestsGra
},
"definition": {
"$type": "RegexToken",
"regex": "/[0-9]+/"
"regex": "/[0-9]+/",
"parenthesized": false
},
"fragment": false,
"hidden": false
Expand All @@ -750,7 +759,8 @@ export const TestsGrammar = (): Grammar => loadedTestsGrammar ?? (loadedTestsGra
"name": "STRING",
"definition": {
"$type": "RegexToken",
"regex": "/\\"(\\\\\\\\.|[^\\"\\\\\\\\])*\\"|'(\\\\\\\\.|[^'\\\\\\\\])*'/"
"regex": "/\\"(\\\\\\\\.|[^\\"\\\\\\\\])*\\"|'(\\\\\\\\.|[^'\\\\\\\\])*'/",
"parenthesized": false
},
"fragment": false,
"hidden": false
Expand All @@ -761,7 +771,8 @@ export const TestsGrammar = (): Grammar => loadedTestsGrammar ?? (loadedTestsGra
"name": "ML_COMMENT",
"definition": {
"$type": "RegexToken",
"regex": "/\\\\/\\\\*[\\\\s\\\\S]*?\\\\*\\\\//"
"regex": "/\\\\/\\\\*[\\\\s\\\\S]*?\\\\*\\\\//",
"parenthesized": false
},
"fragment": false
},
Expand All @@ -771,7 +782,8 @@ export const TestsGrammar = (): Grammar => loadedTestsGrammar ?? (loadedTestsGra
"name": "SL_COMMENT",
"definition": {
"$type": "RegexToken",
"regex": "/\\\\/\\\\/[^\\\\n\\\\r]*/"
"regex": "/\\\\/\\\\/[^\\\\n\\\\r]*/",
"parenthesized": false
},
"fragment": false
}
Expand Down
12 changes: 8 additions & 4 deletions examples/statemachine/src/language-server/generated/grammar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,8 @@ export const StatemachineGrammar = (): Grammar => loadedStatemachineGrammar ?? (
"name": "WS",
"definition": {
"$type": "RegexToken",
"regex": "/\\\\s+/"
"regex": "/\\\\s+/",
"parenthesized": false
},
"fragment": false
},
Expand All @@ -296,7 +297,8 @@ export const StatemachineGrammar = (): Grammar => loadedStatemachineGrammar ?? (
"name": "ID",
"definition": {
"$type": "RegexToken",
"regex": "/[_a-zA-Z][\\\\w_]*/"
"regex": "/[_a-zA-Z][\\\\w_]*/",
"parenthesized": false
},
"fragment": false,
"hidden": false
Expand All @@ -307,7 +309,8 @@ export const StatemachineGrammar = (): Grammar => loadedStatemachineGrammar ?? (
"name": "ML_COMMENT",
"definition": {
"$type": "RegexToken",
"regex": "/\\\\/\\\\*[\\\\s\\\\S]*?\\\\*\\\\//"
"regex": "/\\\\/\\\\*[\\\\s\\\\S]*?\\\\*\\\\//",
"parenthesized": false
},
"fragment": false
},
Expand All @@ -317,7 +320,8 @@ export const StatemachineGrammar = (): Grammar => loadedStatemachineGrammar ?? (
"name": "SL_COMMENT",
"definition": {
"$type": "RegexToken",
"regex": "/\\\\/\\\\/[^\\\\n\\\\r]*/"
"regex": "/\\\\/\\\\/[^\\\\n\\\\r]*/",
"parenthesized": false
},
"fragment": false
}
Expand Down
2 changes: 1 addition & 1 deletion packages/langium-cli/test/generator/ast-generator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ describe('Ast generator', () => {
`, expandToString`
export const TestTerminals = {
WS: /\\s+/,
NUMBER: /([0-9])+/,
NUMBER: /(?:[0-9])+/,
};
`));

Expand Down
Loading