From 09e4c94251a7c71deee797c3aac0c627e465498a Mon Sep 17 00:00:00 2001 From: Markus Rudolph Date: Wed, 22 May 2024 09:13:23 +0200 Subject: [PATCH] Finish case-insensitivity recipe, remove syntax recipes for later --- hugo/content/docs/recipes/lexis/_index.md | 2 +- .../lexis/case-insensitive-languages.md | 50 +++++++++++++++---- hugo/content/docs/recipes/syntax/_index.md | 4 -- .../docs/recipes/syntax/left-factors.md | 0 .../docs/recipes/syntax/left-recursion.md | 0 5 files changed, 42 insertions(+), 14 deletions(-) delete mode 100644 hugo/content/docs/recipes/syntax/_index.md delete mode 100644 hugo/content/docs/recipes/syntax/left-factors.md delete mode 100644 hugo/content/docs/recipes/syntax/left-recursion.md diff --git a/hugo/content/docs/recipes/lexis/_index.md b/hugo/content/docs/recipes/lexis/_index.md index 73416731..442c7fa7 100644 --- a/hugo/content/docs/recipes/lexis/_index.md +++ b/hugo/content/docs/recipes/lexis/_index.md @@ -1,4 +1,4 @@ --- -title: Lexis" +title: Lexis weight: 100 --- \ No newline at end of file diff --git a/hugo/content/docs/recipes/lexis/case-insensitive-languages.md b/hugo/content/docs/recipes/lexis/case-insensitive-languages.md index cb5728f5..7e75e6ec 100644 --- a/hugo/content/docs/recipes/lexis/case-insensitive-languages.md +++ b/hugo/content/docs/recipes/lexis/case-insensitive-languages.md @@ -1,18 +1,50 @@ --- -title: "Case-insensitive languages" +title: Case-insensitive languages weight: 100 --- -* case-insensitive languages are more suitable for beginners, because they don't have to worry about the case of identifiers and keywords -* there are basically two options you can choose from: - * you can either make Langium case-insensitive by configuration - * or you can include case-insensitivity only where you need it +Case-insensitive languages are more suitable for beginners, because they don't have to worry about the case of identifiers and keywords. -## Case-insensitive Langium +In Langium, there are basically two options you can choose from: -* to make Langium case-insensitive, you have to set the `caseInsensitive` option in the `LangiumConfig` object +* you can either make Langium case-insensitive by configuration +* or you can include case-insensitivity only where you need it + +In both ways you need to take care of identifiers and cross-references. + +## Case-insensitivity by Langium + +To make Langium case-insensitive, you have to set the `caseInsensitive` option to `true` in the `LangiumConfig` object which is located in the `langium-config.json` file at the root of your Langium project. You can set this up for every single language. + +```json +{ + "projectName": "HelloWorld", + "languages": [{ + "id": "hello-world", + "caseInsensitive": true, //here + //... + }], + //... +} +``` ## Case-insensitivity on demand -* if you want to include case-insensitivity only where you need it, you can use the `i` flag inside of your grammar regexes -* do not forget to adjust your scoping as well! \ No newline at end of file +If you want to include case-insensitivity only where you need it, you can use the `i` flag inside of your grammar's regular expressions + +```ts +//instead of +Rule: 'keyword'; +//use +Rule: /keyword/i; +``` + +## Case-insensitivity for identifiers and cross-references + +But be aware of that both ways will only take care of all the keywords in your grammar. If you want identifiers and cross-references to be case-insensitive as well, you have to adjust your scoping for each cross-reference case. This can be accomplished by setting the `caseInsensitive` option to `true` within the options when you are creating a new scope object. + +There are several implementations of scopes. One is `MapScope`: + +```ts +new MapScope(descriptions, parentScope, {caseInsensitive: true}); +``` diff --git a/hugo/content/docs/recipes/syntax/_index.md b/hugo/content/docs/recipes/syntax/_index.md deleted file mode 100644 index c2bb0bb7..00000000 --- a/hugo/content/docs/recipes/syntax/_index.md +++ /dev/null @@ -1,4 +0,0 @@ ---- -title: "Syntax" -weight: 200 ---- \ No newline at end of file diff --git a/hugo/content/docs/recipes/syntax/left-factors.md b/hugo/content/docs/recipes/syntax/left-factors.md deleted file mode 100644 index e69de29b..00000000 diff --git a/hugo/content/docs/recipes/syntax/left-recursion.md b/hugo/content/docs/recipes/syntax/left-recursion.md deleted file mode 100644 index e69de29b..00000000