-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finish case-insensitivity recipe, remove syntax recipes for later
- Loading branch information
Showing
5 changed files
with
42 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
50
hugo/content/docs/recipes/lexis/case-insensitive-languages.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}); | ||
``` |
This file was deleted.
Oops, something went wrong.
Empty file.
Empty file.