Skip to content

Commit

Permalink
Finish case-insensitivity recipe, remove syntax recipes for later
Browse files Browse the repository at this point in the history
  • Loading branch information
Lotes committed May 22, 2024
1 parent c7b98de commit bd40bc1
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 14 deletions.
2 changes: 1 addition & 1 deletion hugo/content/docs/recipes/lexis/_index.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
title: Lexis"
title: Lexis
weight: 100
---
50 changes: 41 additions & 9 deletions hugo/content/docs/recipes/lexis/case-insensitive-languages.md
Original file line number Diff line number Diff line change
@@ -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!
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});
```
4 changes: 0 additions & 4 deletions hugo/content/docs/recipes/syntax/_index.md

This file was deleted.

Empty file.
Empty file.

0 comments on commit bd40bc1

Please sign in to comment.