Skip to content

Commit b526902

Browse files
stackoverflowKushalPbioball
authored
Replace ANTLR with hand-rolled parser (#917)
Co-authored-by: Kushal Pisavadia <[email protected]> Co-authored-by: Daniel Chao <[email protected]>
1 parent 7c3f8ad commit b526902

File tree

197 files changed

+11714
-3310
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

197 files changed

+11714
-3310
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
.gradle/
66
build/
77
generated/
8+
testgenerated/
89

910
# IntelliJ
1011
.idea/

DEVELOPMENT.adoc

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ based on version information from https://search.maven.org, https://plugins.grad
8383

8484
* Truffle code generation is performed by Truffle's annotation processor, which runs as part of task `:pkl-core:compileJava`
8585
** Output dir is `generated/truffle/`
86-
* ANTLR code generation is performed by task `:pkl-core:generateGrammarSource`
87-
** Output dir is `generated/antlr/`
86+
* ANTLR code generation is performed by task `:pkl-core:generateTestGrammarSource`
87+
** Output dir is `testgenerated/antlr/`
8888

8989
== Remote JVM Debugging
9090

@@ -96,12 +96,6 @@ Example: `./gradlew test -Djvmdebug=true`
9696
== Resources
9797
For automated build setup examples see our https://github.com/apple/pkl/blob/main/.circleci/[CircleCI] jobs like our https://github.com/apple/pkl/blob/main/.circleci/jobs/BuildNativeJob.pkl[BuildNativeJob.pkl], where we build Pkl automatically.
9898

99-
=== ANTLR
100-
101-
* https://github.com/antlr/antlr4/blob/master/doc/index.md[Documentation]
102-
* https://groups.google.com/forum/#!forum/antlr-discussion[Forums]
103-
* https://github.com/mobileink/lab.clj.antlr/tree/main/doc[Some third-party docs]
104-
10599
=== Truffle
106100

107101
* http://ssw.jku.at/Research/Projects/JVM/Truffle.html[Homepage]

THIRD-PARTY-NOTICES.txt

Lines changed: 21 additions & 32 deletions
Large diffs are not rendered by default.

bench/bench.gradle.kts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
2+
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,8 +25,6 @@ val graal: Configuration by configurations.creating
2525
@Suppress("UnstableApiUsage")
2626
dependencies {
2727
jmh(projects.pklCore)
28-
// necessary because antlr4-runtime is declared as implementation dependency in pkl-core.gradle
29-
jmh(libs.antlrRuntime)
3028
truffle(libs.truffleApi)
3129
graal(libs.graalCompiler)
3230
}

bench/gradle.lockfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# This is a Gradle generated file for dependency locking.
22
# Manual edits can break the build and are not advised.
33
# This file is expected to be part of source control.
4-
com.tunnelvisionlabs:antlr4-runtime:4.9.0=jmh,jmhCompileClasspath,jmhImplementationDependenciesMetadata,jmhRuntimeClasspath
54
net.bytebuddy:byte-buddy:1.15.11=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
65
net.sf.jopt-simple:jopt-simple:5.0.4=jmh,jmhCompileClasspath,jmhImplementationDependenciesMetadata,jmhRuntimeClasspath
76
org.apache.commons:commons-math3:3.6.1=jmh,jmhCompileClasspath,jmhImplementationDependenciesMetadata,jmhRuntimeClasspath

bench/src/jmh/java/org/pkl/core/parser/ParserBenchmark.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
2+
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

buildSrc/src/main/kotlin/pklFatJar.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ val firstPartySourcesJarsConfiguration: Configuration =
3939
val relocations =
4040
mapOf(
4141
// pkl-core dependencies
42-
"org.antlr.v4." to "org.pkl.thirdparty.antlr.v4.",
4342
"org.organicdesign.fp." to "org.pkl.thirdparty.paguro.",
4443
"org.snakeyaml.engine." to "org.pkl.thirdparty.snakeyaml.engine.",
4544
"org.msgpack." to "org.pkl.thirdparty.msgpack.",

docs/modules/language-reference/pages/index.adoc

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3196,7 +3196,6 @@ This section discusses language features that are generally more relevant to tem
31963196
<<glob-patterns,Glob Patterns>> +
31973197
<<doc-comments,Doc Comments>> +
31983198
<<name-resolution,Name Resolution>> +
3199-
<<grammar-definition,Grammar Definition>> +
32003199
<<reserved-keywords,Reserved Keywords>> +
32013200
<<blank-identifiers,Blank Identifiers>> +
32023201
<<projects,Projects>> +
@@ -5274,11 +5273,6 @@ For example, the prototype chain of value `42` contains, now listed from top to
52745273

52755274
A prototype chain never contains a non-object value, such as `42`.
52765275

5277-
[[grammar-definition]]
5278-
=== Grammar Definition
5279-
5280-
Pkl's link:{uri-antlr4}[ANTLR 4] grammar is defined in link:{uri-github-PklLexer}[PklLexer.g4] and link:{uri-github-PklParser}[PklParser.g4].
5281-
52825276
[[reserved-keywords]]
52835277
=== Reserved keywords
52845278

docs/src/test/kotlin/DocSnippetTests.kt

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,14 @@ import org.pkl.core.Loggers
1616
import org.pkl.core.SecurityManagers
1717
import org.pkl.core.StackFrameTransformers
1818
import org.pkl.core.module.ModuleKeyFactories
19-
import org.pkl.core.parser.LexParseException
20-
import org.pkl.core.parser.Parser
21-
import org.pkl.core.parser.antlr.PklParser
2219
import org.pkl.core.repl.ReplRequest
2320
import org.pkl.core.repl.ReplResponse
2421
import org.pkl.core.repl.ReplServer
2522
import org.pkl.core.util.IoUtils
26-
import org.antlr.v4.runtime.ParserRuleContext
2723
import org.pkl.core.http.HttpClient
24+
import org.pkl.core.parser.Parser
25+
import org.pkl.core.parser.ParserError
26+
import org.pkl.core.parser.ast.ClassProperty
2827
import org.pkl.core.resource.ResourceReaders
2928
import java.nio.file.Files
3029
import kotlin.io.path.isDirectory
@@ -303,7 +302,7 @@ class DocSnippetTestsEngine : HierarchicalTestEngine<DocSnippetTestsEngine.Execu
303302

304303
override fun getType() = Type.TEST
305304

306-
private val parsed: ParserRuleContext by lazy {
305+
private val parsed: org.pkl.core.parser.ast.Node by lazy {
307306
when (language) {
308307
"pkl" -> Parser().parseModule(code)
309308
"pkl-expr" -> Parser().parseExpressionInput(code)
@@ -318,7 +317,7 @@ class DocSnippetTestsEngine : HierarchicalTestEngine<DocSnippetTestsEngine.Execu
318317
if (expectError) {
319318
throw AssertionError("Expected a parse error, but got none.")
320319
}
321-
} catch (e: LexParseException) {
320+
} catch (e: ParserError) {
322321
if (!expectError) {
323322
throw AssertionError(e.message)
324323
}
@@ -335,7 +334,7 @@ class DocSnippetTestsEngine : HierarchicalTestEngine<DocSnippetTestsEngine.Execu
335334
)
336335
)
337336

338-
val properties = parsed.children.filterIsInstance<PklParser.ClassPropertyContext>()
337+
val properties = parsed.children()?.filterIsInstance<ClassProperty>() ?: emptyList()
339338

340339
val responses = mutableListOf<ReplResponse>()
341340

@@ -344,7 +343,7 @@ class DocSnippetTestsEngine : HierarchicalTestEngine<DocSnippetTestsEngine.Execu
344343
responses.addAll(context.replServer.handleRequest(
345344
ReplRequest.Eval(
346345
"snippet",
347-
prop.Identifier().text,
346+
prop.name.value,
348347
false,
349348
true
350349
)

pkl-cli/gradle.lockfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava=test
1919
com.google.j2objc:j2objc-annotations:3.0.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
2020
com.jayway.jsonpath:json-path:2.9.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
2121
com.networknt:json-schema-validator:1.5.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
22-
com.tunnelvisionlabs:antlr4-runtime:4.9.0=runtimeClasspath,testRuntimeClasspath
2322
commons-fileupload:commons-fileupload:1.5=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
2423
commons-io:commons-io:2.11.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
2524
net.bytebuddy:byte-buddy:1.15.11=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath

0 commit comments

Comments
 (0)