Skip to content

Commit

Permalink
build: integrate GkPatcher into intellij-aya
Browse files Browse the repository at this point in the history
  • Loading branch information
ice1000 committed Dec 25, 2024
1 parent 3a87053 commit 3eb79c9
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 16 deletions.
21 changes: 19 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import org.aya.gradle.BuildUtil
import org.aya.grammarkit.GkParser
import org.aya.grammarkit.GkPatcher
import org.aya.intellij.MarkerNodeWrapper
import org.jetbrains.changelog.Changelog
import org.jetbrains.changelog.markdownToHTML
import org.jetbrains.grammarkit.tasks.GenerateParserTask
import org.jetbrains.intellij.platform.gradle.TestFrameworkType
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.net.URI
import java.util.*

fun properties(key: String) = providers.gradleProperty(key)
Expand Down Expand Up @@ -65,9 +69,11 @@ sourceSets.main {
java.srcDirs(genDir)
}

val ayaPsiParserFile = file("src/main/grammar/AyaPsiParser.bnf")

val genAyaPsiParser = tasks.register<GenerateParserTask>("genAyaParser") {
group = "build setup"
sourceFile.set(file("src/main/grammar/AyaPsiParser.bnf"))
sourceFile.set(ayaPsiParserFile)
targetRootOutputDir.set(file("src/main/gen"))
pathToParser.set("org/aya/parser/AyaPsiParser.java")
pathToPsiRoot.set("org/aya/intellij/psi")
Expand Down Expand Up @@ -104,6 +110,18 @@ tasks {
dependsOn(genAyaPsiParser)
}

register("updateAyaParser") {
group = "build setup"
doLast {
val fileName = ayaPsiParserFile.name
val url = URI("https://raw.githubusercontent.com/aya-prover/aya-dev/refs/heads/main/parser/src/main/grammar/$fileName").toURL()
val text = url.openStream().use { it.reader().readText() }
val syntaxNode = object : GkParser() {}.parse(text)
val patchedBNF = GkPatcher.forPlugin(MarkerNodeWrapper(text, syntaxNode))
ayaPsiParserFile.writeText(patchedBNF.toString())
}
}

withType<JavaCompile>().configureEach {
modularity.inferModulePath.set(true)
options.apply {
Expand Down Expand Up @@ -193,7 +211,6 @@ dependencies {
intellijPlatform {
intellijIdeaCommunity("2024.3")
bundledPlugin("com.intellij.java")
instrumentationTools()
testFramework(TestFrameworkType.Platform)
}

Expand Down
14 changes: 5 additions & 9 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import java.util.*

plugins {
java
groovy
}

repositories {
mavenCentral()
}
plugins { java }
repositories { mavenCentral() }

val rootDir = projectDir.parentFile!!

dependencies {
val deps = Properties()
deps.load(rootDir.resolve("gradle/deps.properties").reader())
api("org.aya-prover.upstream", "build-util", deps.getProperty("version.aya-upstream"))
val buildUtilVersion = deps.getProperty("version.aya-upstream")
api("org.aya-prover.upstream", "build-util", buildUtilVersion)
api("org.aya-prover.upstream", "ij-gk-parser", buildUtilVersion)
}
4 changes: 2 additions & 2 deletions gradle/deps.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
version.project=0.0.1-SNAPSHOT
version.aya=0.36.0
version.aya-upstream=0.0.31
version.aya=0.37.0-SNAPSHOT
version.aya-upstream=0.0.32
7 changes: 4 additions & 3 deletions src/main/grammar/AyaPsiParser.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
* Use of this source code is governed by the MIT license that can be found in the LICENSE.md file.
*/

//noinspection BnfResolveForFile
{
// only for the compiler, not the IDE
generate=[
java='11'
// psi-factory='no'
// visitor='no'
psi-factory='yes'
visitor='yes'
]
// generatePsi=false
generatePsi=true

// we only need the parser and element types.
parserClass='org.aya.parser.AyaPsiParser'
Expand Down

0 comments on commit 3eb79c9

Please sign in to comment.