mirror of
https://github.com/apple/pkl.git
synced 2026-03-26 02:51:13 +01:00
Replace ANTLR with hand-rolled parser (#917)
Co-authored-by: Kushal Pisavadia <kushi.p@gmail.com> Co-authored-by: Daniel Chao <daniel.h.chao@gmail.com>
This commit is contained in:
@@ -3196,7 +3196,6 @@ This section discusses language features that are generally more relevant to tem
|
||||
<<glob-patterns,Glob Patterns>> +
|
||||
<<doc-comments,Doc Comments>> +
|
||||
<<name-resolution,Name Resolution>> +
|
||||
<<grammar-definition,Grammar Definition>> +
|
||||
<<reserved-keywords,Reserved Keywords>> +
|
||||
<<blank-identifiers,Blank Identifiers>> +
|
||||
<<projects,Projects>> +
|
||||
@@ -5274,11 +5273,6 @@ For example, the prototype chain of value `42` contains, now listed from top to
|
||||
|
||||
A prototype chain never contains a non-object value, such as `42`.
|
||||
|
||||
[[grammar-definition]]
|
||||
=== Grammar Definition
|
||||
|
||||
Pkl's link:{uri-antlr4}[ANTLR 4] grammar is defined in link:{uri-github-PklLexer}[PklLexer.g4] and link:{uri-github-PklParser}[PklParser.g4].
|
||||
|
||||
[[reserved-keywords]]
|
||||
=== Reserved keywords
|
||||
|
||||
|
||||
@@ -16,15 +16,14 @@ import org.pkl.core.Loggers
|
||||
import org.pkl.core.SecurityManagers
|
||||
import org.pkl.core.StackFrameTransformers
|
||||
import org.pkl.core.module.ModuleKeyFactories
|
||||
import org.pkl.core.parser.LexParseException
|
||||
import org.pkl.core.parser.Parser
|
||||
import org.pkl.core.parser.antlr.PklParser
|
||||
import org.pkl.core.repl.ReplRequest
|
||||
import org.pkl.core.repl.ReplResponse
|
||||
import org.pkl.core.repl.ReplServer
|
||||
import org.pkl.core.util.IoUtils
|
||||
import org.antlr.v4.runtime.ParserRuleContext
|
||||
import org.pkl.core.http.HttpClient
|
||||
import org.pkl.core.parser.Parser
|
||||
import org.pkl.core.parser.ParserError
|
||||
import org.pkl.core.parser.ast.ClassProperty
|
||||
import org.pkl.core.resource.ResourceReaders
|
||||
import java.nio.file.Files
|
||||
import kotlin.io.path.isDirectory
|
||||
@@ -303,7 +302,7 @@ class DocSnippetTestsEngine : HierarchicalTestEngine<DocSnippetTestsEngine.Execu
|
||||
|
||||
override fun getType() = Type.TEST
|
||||
|
||||
private val parsed: ParserRuleContext by lazy {
|
||||
private val parsed: org.pkl.core.parser.ast.Node by lazy {
|
||||
when (language) {
|
||||
"pkl" -> Parser().parseModule(code)
|
||||
"pkl-expr" -> Parser().parseExpressionInput(code)
|
||||
@@ -318,7 +317,7 @@ class DocSnippetTestsEngine : HierarchicalTestEngine<DocSnippetTestsEngine.Execu
|
||||
if (expectError) {
|
||||
throw AssertionError("Expected a parse error, but got none.")
|
||||
}
|
||||
} catch (e: LexParseException) {
|
||||
} catch (e: ParserError) {
|
||||
if (!expectError) {
|
||||
throw AssertionError(e.message)
|
||||
}
|
||||
@@ -335,7 +334,7 @@ class DocSnippetTestsEngine : HierarchicalTestEngine<DocSnippetTestsEngine.Execu
|
||||
)
|
||||
)
|
||||
|
||||
val properties = parsed.children.filterIsInstance<PklParser.ClassPropertyContext>()
|
||||
val properties = parsed.children()?.filterIsInstance<ClassProperty>() ?: emptyList()
|
||||
|
||||
val responses = mutableListOf<ReplResponse>()
|
||||
|
||||
@@ -344,7 +343,7 @@ class DocSnippetTestsEngine : HierarchicalTestEngine<DocSnippetTestsEngine.Execu
|
||||
responses.addAll(context.replServer.handleRequest(
|
||||
ReplRequest.Eval(
|
||||
"snippet",
|
||||
prop.Identifier().text,
|
||||
prop.name.value,
|
||||
false,
|
||||
true
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user