Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
matrix:
os:
- windows-latest
- ubuntu-latest
- ubuntu-24.04
- ubuntu-24.04-arm
- macos-latest

Expand Down Expand Up @@ -46,19 +46,34 @@ jobs:
- name: Compile classes (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: .\gradlew.bat classes --no-daemon --info --console=plain
run: .\gradlew.bat :classes --no-daemon --info --console=plain

- name: Compile classes (Linux/macOS)
if: runner.os != 'Windows'
shell: bash
run: ./gradlew classes --no-daemon --info --console=plain
run: ./gradlew :classes --no-daemon --info --console=plain

- name: Run tests (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: .\gradlew.bat test --no-daemon --info --console=plain
run: .\gradlew.bat :test --no-daemon --info --console=plain

- name: Run tests (Linux/macOS)
if: runner.os != 'Windows'
shell: bash
run: ./gradlew test --no-daemon --info --console=plain
run: ./gradlew :test --no-daemon --info --console=plain

- name: Set up Node.js 24 for explorer-web
if: matrix.os == 'ubuntu-24.04'
uses: actions/setup-node@v6
with:
node-version: "24"

- name: Build and test explorer-web
if: matrix.os == 'ubuntu-24.04'
shell: bash
run: |
node --test explorer-web/src/test/web/controller.test.mjs explorer-web/src/test/web/worker.test.mjs
./gradlew :explorer-web:installExplorerChromium --args="install --with-deps chromium" \
:explorer-web:assemble :explorer-web:test :explorer-web:browserTest \
--no-daemon --info --console=plain
45 changes: 33 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# gdparser

A Java 25 GDScript parser. The primary path is a pure-Java port of Godot's official tokenizer and parser (no native dependencies), producing a parser-agnostic typed AST with diagnostics. The Tree-sitter (`tree-sitter-ng`) path is retained unchanged as the parity reference/fallback and for completion support.
A Java 25 library for parsing Godot 4 GDScript. Its pure-Java port of Godot's tokenizer and parser produces a typed AST with diagnostics and needs no native libraries.

## What This Repo Provides

- Pure-Java GDScript tokenizer + recursive-descent/Pratt parser faithful to Godot: explicit `NEWLINE`/`INDENT`/`DEDENT` semantics, panic-mode recovery with synchronization
- Tolerant and strict parse modes with stable diagnostics on UTF-8 byte-offset spans
- Raw token stream access for tooling and tests
- Syntax-aware completion context (eight kinds, including empty syntactic slots)
- Immutable, parser-agnostic typed AST with canonical S-expression serialization/deserialization
- Dual-path parity testing: both parsers must produce byte-identical ASTs on the shared corpus
- Fixture-based regression tests on real-world GDScript samples

## At a Glance
Expand All @@ -19,23 +19,44 @@ Source -> GdTokenizer -> GdScriptParser -> AST -> (optional) S-expr

## Minimal Usage

```java
var facade = new GdScriptParserFacade(); // stateless, safe to share across threads
The default Maven publication coordinates for 0.8.0 are `dev.superice:gdparser:0.8.0`. In a Gradle Kotlin DSL build:

```kotlin
dependencies {
implementation("dev.superice:gdparser:0.8.0")
}
```

var result = facade.parse(source); // tolerant: AST + diagnostics, never throws
var ast = facade.parseStrict(source); // strict: throws on the first ERROR diagnostic
For example, in a Java 25 application:

```java
import dev.superice.gdparser.frontend.gdscript.GdScriptParserFacade;
import dev.superice.gdparser.frontend.serialize.AstSexprSerializer;

var tokens = facade.tokenize(source); // raw token stream (no parser multiline intervention)
class ParseExample {
static void main() {
var facade = new GdScriptParserFacade();
var source = "func f():\n\tpass\n";
var result = facade.parse(source); // Tolerant: AST plus diagnostics, even on syntax errors.

var serializer = new AstSexprSerializer();
var sexpr = serializer.serialize(result.ast());
System.out.println(result.diagnostics());
System.out.println(new AstSexprSerializer().serialize(result.ast()));
}
}
```

Use `parseStrict(source)` to reject the first `ERROR` diagnostic, `tokenize(source)` for the raw token stream, or `parseCompletionContext(source, byteOffset)` to classify a UTF-8 byte cursor position.

## Upgrading to 0.8.0

The Tree-sitter backend and the deprecated CST and completion APIs have been removed. Replace CST parsing plus mapping with `GdScriptParserFacade.parse(source)`, and use `ast()` and `diagnostics()` on the result. Replace strict mapping with `parseStrict(source)`. For completion, use `frontend.gdscript.CompletionContext` from the same facade and handle all eight kinds.

There is no raw CST, native loader or ABI configuration to migrate, and gdparser does not provide a parser CLI. See the [0.8.0 migration guide](doc/architecture-overview.md#4-migrating-to-080) for the API differences.

## Documentation

- `doc/godot-java-parser-implementation.md` — pure-Java parser contracts, parity rules, known limitations
- `doc/architecture-overview.md` — repository-wide architecture and maintenance guide
- `doc/tree-sitter-ng-gdscript-implementation-plan.md` — Tree-sitter path baseline
- [Pure-Java parser implementation](doc/godot-java-parser-implementation.md): parser contracts and known limitations
- [Architecture overview](doc/architecture-overview.md): architecture and maintenance guide

## License

Expand Down
55 changes: 2 additions & 53 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ import org.gradle.api.publish.maven.MavenPublication
plugins {
id("java")
id("maven-publish")
id("org.gradlex.extra-java-module-info") version "1.9"
}

val defaultProjectGroup = "dev.superice"
val defaultProjectVersion = "0.7.2"
val defaultProjectVersion = "0.8.0"
val requestedGroup = findProperty("group")?.toString()
val requestedVersion = findProperty("version")?.toString()

Expand All @@ -22,26 +21,6 @@ version = when {
else -> requestedVersion
}

fun normalizedOsName(name: String): String = when {
name.contains("win", ignoreCase = true) -> "windows"
name.contains("mac", ignoreCase = true) -> "macos"
name.contains("nux", ignoreCase = true) || name.contains("nix", ignoreCase = true) -> "linux"
else -> "unknown"
}

fun normalizedArchName(name: String): String = when (name.lowercase()) {
"x86_64", "amd64" -> "x86_64"
"aarch64", "arm64" -> "aarch64"
else -> name.lowercase()
}

val detectedOs = normalizedOsName(System.getProperty("os.name"))
val detectedArch = normalizedArchName(System.getProperty("os.arch"))
val defaultNativeResourceDir = layout.projectDirectory.dir("native").asFile.absolutePath
val gdscriptNativeResourceDir = providers.gradleProperty("gdscriptNativeResourceDir").orElse(defaultNativeResourceDir)
val defaultNativeLibDir = layout.projectDirectory.dir("native/$detectedOs-$detectedArch").asFile.absolutePath
val gdscriptNativeLibDir = providers.gradleProperty("gdscriptNativeLibDir").orElse(defaultNativeLibDir)
val treeSitterNgVersion = "0.26.3"
val jetbrainsAnnotationsVersion = "26.0.2"

java {
Expand All @@ -55,16 +34,7 @@ repositories {
mavenCentral()
}

sourceSets {
main {
resources {
srcDirs("src/main/resources", "native")
}
}
}

dependencies {
implementation("io.github.bonede:tree-sitter:$treeSitterNgVersion")
compileOnly("org.jetbrains:annotations:$jetbrainsAnnotationsVersion")
testCompileOnly("org.jetbrains:annotations:$jetbrainsAnnotationsVersion")

Expand All @@ -73,10 +43,6 @@ dependencies {
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}

extraJavaModuleInfo {
automaticModule("tree-sitter-0.26.3.jar", "tree.sitter")
}

publishing {
publications {
create<MavenPublication>("mavenJava") {
Expand All @@ -85,7 +51,7 @@ publishing {

pom {
name.set(rootProject.name)
description.set("A Java 25 GDScript parser pipeline built on Tree-sitter.")
description.set("A pure Java 25 GDScript parser with a typed AST and diagnostics.")
url.set("https://github.com/SuperIceCN/gdparser")

licenses {
Expand All @@ -107,23 +73,6 @@ publishing {

tasks.withType<Test>().configureEach {
useJUnitPlatform()
jvmArgs("--enable-native-access=ALL-UNNAMED")

val resourceDir = gdscriptNativeResourceDir.get()
val nativeLibDir = gdscriptNativeLibDir.get()
systemProperty("gdparser.gdscript.resourceDir", resourceDir)
systemProperty("gdparser.gdscript.nativeLibDir", nativeLibDir)
jvmArgs("-Djava.library.path=$nativeLibDir")
}

tasks.withType<JavaExec>().configureEach {
jvmArgs("--enable-native-access=ALL-UNNAMED")

val resourceDir = gdscriptNativeResourceDir.get()
val nativeLibDir = gdscriptNativeLibDir.get()
systemProperty("gdparser.gdscript.resourceDir", resourceDir)
systemProperty("gdparser.gdscript.nativeLibDir", nativeLibDir)
jvmArgs("-Djava.library.path=$nativeLibDir")
}

tasks.withType<JavaCompile>().configureEach {
Expand Down
Loading
Loading