Skip to content

Commit

Permalink
Revise Grammar-Kit configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
JojOatXGME committed Apr 13, 2024
1 parent 12b6105 commit 27d2110
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,3 @@ hs_err_pid*
*.iml
**/.gradle
build
src/gen
24 changes: 13 additions & 11 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,12 @@ grammarKit {
grammarKitRelease = "2021.1.2"
}

val lexerSource = layout.buildDirectory.dir("generated/sources/lexer/java/main")
sourceSets {
main {
java {
srcDir("src/gen/java")
srcDir("src/main/java")
srcDir(lexerSource)
srcDir(tasks.generateParser)
}
}
}
Expand Down Expand Up @@ -104,23 +105,24 @@ tasks {
}

generateLexer {
sourceFile = file("src/main/lang/Nix.flex")
targetOutputDir = file("src/gen/java/org/nixos/idea/lang")
sourceFile = layout.projectDirectory.file("src/main/lang/Nix.flex")
targetOutputDir = lexerSource.map { it.dir("org/nixos/idea/lang") }
purgeOldFiles = true
}

generateParser {
sourceFile = file("src/main/lang/Nix.bnf")
targetRootOutputDir = file("src/gen/java")
pathToParser = "/org/nixos/idea/lang/NixParser"
pathToPsiRoot = "/org/nixos/idea/psi"
sourceFile = layout.projectDirectory.file("src/main/lang/Nix.bnf")
targetRootOutputDir = layout.buildDirectory.dir("generated/sources/parser/java/main")
// Maybe we can remove the following properties in the future
// https://github.com/JetBrains/gradle-grammar-kit-plugin/issues/178
pathToParser = "org/nixos/idea/lang/NixParser.java"
pathToPsiRoot = "org/nixos/idea/psi"
purgeOldFiles = true
// Task :generateLexer deletes files generated by this task when executed afterward.
mustRunAfter(generateLexer)
}

compileJava {
dependsOn(generateLexer, generateParser)
dependsOn(generateLexer)
// dependency to generateParser is implicitly detected by Gradle
}

test {
Expand Down
1 change: 1 addition & 0 deletions src/main/lang/Nix.flex
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import static org.nixos.idea.psi.NixTypes.*;
}
%}

%abstract
%class _NixLexer
%implements FlexLexer
%function advance
Expand Down

0 comments on commit 27d2110

Please sign in to comment.