custom language tutorial: move step (IJSDK-1353, 2.3)

This commit is contained in:
Yann Cébron 2022-03-03 16:34:38 +01:00
parent 153d545faa
commit c792692656
2 changed files with 15 additions and 16 deletions

View File

@ -62,10 +62,24 @@ Note that the `SimpleTypes` class in the `elementTypeHolderClass` attribute abov
## Generate a Parser
Now that the grammar is defined, generate a parser with PSI classes via <control>Generate Parser Code</control> from the context menu on the <path>Simple.bnf</path> file.
This step generates a parser and PSI elements in the <path>/src/main/gen</path> folder of the project.
Mark this folder as <control>Generated Sources Root</control> and make sure everything compiles without errors.
> Gradle plugin [gradle-grammarkit-plugin](https://github.com/JetBrains/gradle-grammar-kit-plugin) can be used alternatively.
>
{type="tip"}
![Parser](generated_parser.png){width="800"}
## Add Generated Sources Root
To include the sources generated into <path>/src/main/gen</path>, the project's `sourceSets` must be expanded by inserting the following line in the project's <path>build.gradle</path> file:
```groovy
sourceSets.main.java.srcDirs 'src/main/gen'
```
Or the following line in the project's <path>build.gradle.kts</path> file:
```kotlin
sourceSets["main"].java.srcDirs("src/main/gen")
```
Reload the Gradle project for changes to take effect and build the project.

View File

@ -9,21 +9,6 @@ The easiest way to create a lexer is to use [JFlex](https://jflex.de/).
**Reference**: [](implementing_lexer.md)
## Required Project Configuration Change
The previous tutorial step [Grammar and Parser](grammar_and_parser.md), and this page, generate source files in the directory <path>src/main/gen</path>.
To include those files, the project's `sourceSets` must be expanded by inserting the following line in the project's <path>build.gradle</path> file:
```groovy
sourceSets.main.java.srcDirs 'src/main/gen'
```
Or the following line in the project's <path>build.gradle.kts</path> file:
```kotlin
sourceSets["main"].java.srcDirs("src/main/gen")
```
Reload the Gradle project for changes to take effect.
## Define a Lexer
Define a <path>Simple.flex</path> file with rules for the Simple Language lexer, as demonstrated in `org.intellij.sdk.language.Simple.flex`.