mirror of
https://github.com/apple/pkl.git
synced 2026-04-09 18:33:40 +02:00
move parser out of pkl-core (#1024)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -49,7 +49,7 @@ idea {
|
||||
testRunner = PLATFORM
|
||||
}
|
||||
configure<TaskTriggersConfig> {
|
||||
afterSync(provider { project(":pkl-core").tasks.named("makeIntelliJAntlrPluginHappy") })
|
||||
afterSync(provider { project(":pkl-parser").tasks.named("makeIntelliJAntlrPluginHappy") })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -37,6 +37,7 @@ dependencies {
|
||||
testImplementation(projects.pklConfigJava)
|
||||
testImplementation(projects.pklConfigKotlin)
|
||||
testImplementation(projects.pklCommonsTest)
|
||||
testImplementation(projects.pklParser)
|
||||
testImplementation(libs.junitEngine)
|
||||
testImplementation(libs.antlrRuntime)
|
||||
}
|
||||
|
||||
@@ -21,9 +21,9 @@ import org.pkl.core.repl.ReplResponse
|
||||
import org.pkl.core.repl.ReplServer
|
||||
import org.pkl.core.util.IoUtils
|
||||
import org.pkl.core.http.HttpClient
|
||||
import org.pkl.core.parser.Parser
|
||||
import org.pkl.core.parser.ParserError
|
||||
import org.pkl.core.parser.syntax.ClassProperty
|
||||
import org.pkl.parser.Parser
|
||||
import org.pkl.parser.ParserError
|
||||
import org.pkl.parser.syntax.ClassProperty
|
||||
import org.pkl.core.resource.ResourceReaders
|
||||
import java.nio.file.Files
|
||||
import kotlin.io.path.isDirectory
|
||||
@@ -302,7 +302,7 @@ class DocSnippetTestsEngine : HierarchicalTestEngine<DocSnippetTestsEngine.Execu
|
||||
|
||||
override fun getType() = Type.TEST
|
||||
|
||||
private val parsed: org.pkl.core.parser.syntax.Node by lazy {
|
||||
private val parsed: org.pkl.parser.syntax.Node by lazy {
|
||||
when (language) {
|
||||
"pkl" -> Parser().parseModule(code)
|
||||
"pkl-expr" -> Parser().parseExpressionInput(code)
|
||||
|
||||
@@ -3,13 +3,7 @@
|
||||
# This file is expected to be part of source control.
|
||||
com.google.code.findbugs:jsr305:3.0.2=compileClasspath,compileOnlyDependenciesMetadata
|
||||
com.palantir.javapoet:javapoet:0.6.0=generatorCompileClasspath,generatorImplementationDependenciesMetadata,generatorRuntimeClasspath
|
||||
com.tunnelvisionlabs:antlr4-annotations:4.9.0=antlr
|
||||
com.tunnelvisionlabs:antlr4-runtime:4.9.0=antlr,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
com.tunnelvisionlabs:antlr4:4.9.0=antlr
|
||||
net.bytebuddy:byte-buddy:1.15.11=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.abego.treelayout:org.abego.treelayout.core:1.0.1=antlr
|
||||
org.antlr:ST4:4.3=antlr
|
||||
org.antlr:antlr-runtime:3.5.2=antlr
|
||||
org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath,testImplementationDependenciesMetadata,testJdk17CompileClasspath,testJdk17ImplementationDependenciesMetadata,testRuntimeOnlyDependenciesMetadata
|
||||
org.assertj:assertj-core:3.27.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.graalvm.polyglot:polyglot:24.1.2=compileClasspath,generatorCompileClasspath,generatorImplementationDependenciesMetadata,generatorRuntimeClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
|
||||
@@ -21,42 +21,30 @@ plugins {
|
||||
pklJavaLibrary
|
||||
pklPublishLibrary
|
||||
pklNativeBuild
|
||||
antlr
|
||||
idea
|
||||
}
|
||||
|
||||
val generatorSourceSet = sourceSets.register("generator")
|
||||
|
||||
sourceSets { test { java { srcDir(file("testgenerated/antlr")) } } }
|
||||
|
||||
idea {
|
||||
module {
|
||||
// mark src/test/antlr as source dir
|
||||
// mark generated/antlr as generated source dir
|
||||
// mark generated/truffle as generated source dir
|
||||
sourceDirs = sourceDirs + files("generated/truffle")
|
||||
generatedSourceDirs = generatedSourceDirs + files("testgenerated/antlr", "generated/truffle")
|
||||
testSources.from(files("src/test/antlr", "testgenerated/antlr"))
|
||||
generatedSourceDirs = generatedSourceDirs + files("generated/truffle")
|
||||
}
|
||||
}
|
||||
|
||||
val javaExecutableConfiguration: Configuration = configurations.create("javaExecutable")
|
||||
|
||||
// workaround for https://github.com/gradle/gradle/issues/820
|
||||
configurations.api.get().let { apiConfig ->
|
||||
apiConfig.setExtendsFrom(apiConfig.extendsFrom.filter { it.name != "antlr" })
|
||||
}
|
||||
|
||||
dependencies {
|
||||
annotationProcessor(libs.truffleDslProcessor)
|
||||
annotationProcessor(generatorSourceSet.get().runtimeClasspath)
|
||||
|
||||
antlr(libs.antlr)
|
||||
|
||||
compileOnly(libs.jsr305)
|
||||
// pkl-core implements pkl-executor's ExecutorSpi, but the SPI doesn't ship with pkl-core
|
||||
compileOnly(projects.pklExecutor)
|
||||
|
||||
implementation(projects.pklParser)
|
||||
implementation(libs.msgpack)
|
||||
implementation(libs.truffleApi)
|
||||
implementation(libs.graalSdk)
|
||||
@@ -65,7 +53,6 @@ dependencies {
|
||||
|
||||
implementation(libs.snakeYaml)
|
||||
|
||||
testImplementation(libs.antlrRuntime)
|
||||
testImplementation(projects.pklCommonsTest)
|
||||
|
||||
add("generatorImplementation", libs.javaPoet)
|
||||
@@ -93,35 +80,6 @@ publishing {
|
||||
}
|
||||
}
|
||||
|
||||
tasks.generateTestGrammarSource {
|
||||
maxHeapSize = "64m"
|
||||
|
||||
// generate only visitor
|
||||
arguments = arguments + listOf("-visitor", "-no-listener")
|
||||
|
||||
// Due to https://github.com/antlr/antlr4/issues/2260,
|
||||
// we can't put .g4 files into src/test/antlr/org/pkl/core/parser/antlr.
|
||||
// Instead, we put .g4 files into src/test/antlr, adapt output dir below,
|
||||
// and use @header directives in .g4 files (instead of setting `-package` argument here)
|
||||
// and task makeIntelliJAntlrPluginHappy to fix up the IDE story.
|
||||
outputDirectory = file("testgenerated/antlr/org/pkl/core/parser/antlr")
|
||||
}
|
||||
|
||||
tasks.generateGrammarSource { enabled = false }
|
||||
|
||||
tasks.named("generateGeneratorGrammarSource") { enabled = false }
|
||||
|
||||
tasks.compileTestKotlin { dependsOn(tasks.generateTestGrammarSource) }
|
||||
|
||||
// Satisfy expectations of IntelliJ ANTLR plugin,
|
||||
// which can't otherwise cope with our ANTLR setup.
|
||||
val makeIntelliJAntlrPluginHappy by
|
||||
tasks.registering(Copy::class) {
|
||||
dependsOn(tasks.generateGrammarSource)
|
||||
into("test/antlr")
|
||||
from("testgenerated/antlr/org/pkl/core/parser/antlr") { include("PklLexer.tokens") }
|
||||
}
|
||||
|
||||
tasks.processResources {
|
||||
inputs.property("version", buildInfo.pklVersion)
|
||||
inputs.property("commitId", buildInfo.commitId)
|
||||
@@ -245,13 +203,6 @@ tasks.clean {
|
||||
delete(layout.buildDirectory.dir("test-packages"))
|
||||
}
|
||||
|
||||
spotless {
|
||||
antlr4 {
|
||||
licenseHeaderFile(rootProject.file("buildSrc/src/main/resources/license-header.star-block.txt"))
|
||||
target(files("src/test/antlr/PklParser.g4", "src/test/antlr/PklLexer.g4"))
|
||||
}
|
||||
}
|
||||
|
||||
private fun Test.configureTest() {
|
||||
inputs
|
||||
.dir("src/test/files/LanguageSnippetTests/input")
|
||||
|
||||
@@ -19,7 +19,7 @@ import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
import org.pkl.core.parser.Lexer;
|
||||
import org.pkl.parser.Lexer;
|
||||
|
||||
// To instantiate this class, use ValueRenderers.pcf().
|
||||
final class PcfRenderer implements ValueRenderer {
|
||||
|
||||
@@ -18,14 +18,14 @@ package org.pkl.core.ast.builder;
|
||||
import com.oracle.truffle.api.source.Source;
|
||||
import com.oracle.truffle.api.source.SourceSection;
|
||||
import java.util.List;
|
||||
import org.pkl.core.parser.BaseParserVisitor;
|
||||
import org.pkl.core.parser.Span;
|
||||
import org.pkl.core.parser.syntax.DocComment;
|
||||
import org.pkl.core.parser.syntax.Modifier;
|
||||
import org.pkl.core.parser.syntax.Modifier.ModifierValue;
|
||||
import org.pkl.core.parser.syntax.Node;
|
||||
import org.pkl.core.runtime.VmExceptionBuilder;
|
||||
import org.pkl.core.util.Nullable;
|
||||
import org.pkl.parser.BaseParserVisitor;
|
||||
import org.pkl.parser.Span;
|
||||
import org.pkl.parser.syntax.DocComment;
|
||||
import org.pkl.parser.syntax.Modifier;
|
||||
import org.pkl.parser.syntax.Modifier.ModifierValue;
|
||||
import org.pkl.parser.syntax.Node;
|
||||
|
||||
public abstract class AbstractAstBuilder<T> extends BaseParserVisitor<T> {
|
||||
|
||||
|
||||
@@ -157,81 +157,6 @@ import org.pkl.core.module.ModuleKey;
|
||||
import org.pkl.core.module.ModuleKeys;
|
||||
import org.pkl.core.module.ResolvedModuleKey;
|
||||
import org.pkl.core.packages.PackageLoadError;
|
||||
import org.pkl.core.parser.Span;
|
||||
import org.pkl.core.parser.syntax.Annotation;
|
||||
import org.pkl.core.parser.syntax.ArgumentList;
|
||||
import org.pkl.core.parser.syntax.Class;
|
||||
import org.pkl.core.parser.syntax.ClassMethod;
|
||||
import org.pkl.core.parser.syntax.ClassProperty;
|
||||
import org.pkl.core.parser.syntax.Expr;
|
||||
import org.pkl.core.parser.syntax.Expr.AmendsExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.BinaryOperatorExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.BoolLiteralExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.FloatLiteralExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.FunctionLiteralExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.IfExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.ImportExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.IntLiteralExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.LetExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.LogicalNotExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.ModuleExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.MultiLineStringLiteralExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.NewExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.NonNullExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.NullLiteralExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.OuterExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.ParenthesizedExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.QualifiedAccessExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.ReadExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.SingleLineStringLiteralExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.SubscriptExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.SuperAccessExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.SuperSubscriptExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.ThisExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.ThrowExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.TraceExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.TypeCastExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.TypeCheckExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.UnaryMinusExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.UnqualifiedAccessExpr;
|
||||
import org.pkl.core.parser.syntax.ExtendsOrAmendsClause;
|
||||
import org.pkl.core.parser.syntax.Identifier;
|
||||
import org.pkl.core.parser.syntax.ImportClause;
|
||||
import org.pkl.core.parser.syntax.Modifier;
|
||||
import org.pkl.core.parser.syntax.Modifier.ModifierValue;
|
||||
import org.pkl.core.parser.syntax.Module;
|
||||
import org.pkl.core.parser.syntax.Node;
|
||||
import org.pkl.core.parser.syntax.ObjectBody;
|
||||
import org.pkl.core.parser.syntax.ObjectMember.ForGenerator;
|
||||
import org.pkl.core.parser.syntax.ObjectMember.MemberPredicate;
|
||||
import org.pkl.core.parser.syntax.ObjectMember.ObjectElement;
|
||||
import org.pkl.core.parser.syntax.ObjectMember.ObjectEntry;
|
||||
import org.pkl.core.parser.syntax.ObjectMember.ObjectMethod;
|
||||
import org.pkl.core.parser.syntax.ObjectMember.ObjectProperty;
|
||||
import org.pkl.core.parser.syntax.ObjectMember.ObjectSpread;
|
||||
import org.pkl.core.parser.syntax.ObjectMember.WhenGenerator;
|
||||
import org.pkl.core.parser.syntax.Parameter;
|
||||
import org.pkl.core.parser.syntax.Parameter.TypedIdentifier;
|
||||
import org.pkl.core.parser.syntax.ParameterList;
|
||||
import org.pkl.core.parser.syntax.QualifiedIdentifier;
|
||||
import org.pkl.core.parser.syntax.StringConstant;
|
||||
import org.pkl.core.parser.syntax.StringPart;
|
||||
import org.pkl.core.parser.syntax.StringPart.StringChars;
|
||||
import org.pkl.core.parser.syntax.StringPart.StringInterpolation;
|
||||
import org.pkl.core.parser.syntax.Type;
|
||||
import org.pkl.core.parser.syntax.Type.ConstrainedType;
|
||||
import org.pkl.core.parser.syntax.Type.DeclaredType;
|
||||
import org.pkl.core.parser.syntax.Type.FunctionType;
|
||||
import org.pkl.core.parser.syntax.Type.ModuleType;
|
||||
import org.pkl.core.parser.syntax.Type.NothingType;
|
||||
import org.pkl.core.parser.syntax.Type.NullableType;
|
||||
import org.pkl.core.parser.syntax.Type.ParenthesizedType;
|
||||
import org.pkl.core.parser.syntax.Type.StringConstantType;
|
||||
import org.pkl.core.parser.syntax.Type.UnionType;
|
||||
import org.pkl.core.parser.syntax.Type.UnknownType;
|
||||
import org.pkl.core.parser.syntax.TypeAlias;
|
||||
import org.pkl.core.parser.syntax.TypeAnnotation;
|
||||
import org.pkl.core.parser.syntax.TypeParameterList;
|
||||
import org.pkl.core.runtime.BaseModule;
|
||||
import org.pkl.core.runtime.ModuleInfo;
|
||||
import org.pkl.core.runtime.ModuleResolver;
|
||||
@@ -256,6 +181,81 @@ import org.pkl.core.util.EconomicMaps;
|
||||
import org.pkl.core.util.IoUtils;
|
||||
import org.pkl.core.util.Nullable;
|
||||
import org.pkl.core.util.Pair;
|
||||
import org.pkl.parser.Span;
|
||||
import org.pkl.parser.syntax.Annotation;
|
||||
import org.pkl.parser.syntax.ArgumentList;
|
||||
import org.pkl.parser.syntax.Class;
|
||||
import org.pkl.parser.syntax.ClassMethod;
|
||||
import org.pkl.parser.syntax.ClassProperty;
|
||||
import org.pkl.parser.syntax.Expr;
|
||||
import org.pkl.parser.syntax.Expr.AmendsExpr;
|
||||
import org.pkl.parser.syntax.Expr.BinaryOperatorExpr;
|
||||
import org.pkl.parser.syntax.Expr.BoolLiteralExpr;
|
||||
import org.pkl.parser.syntax.Expr.FloatLiteralExpr;
|
||||
import org.pkl.parser.syntax.Expr.FunctionLiteralExpr;
|
||||
import org.pkl.parser.syntax.Expr.IfExpr;
|
||||
import org.pkl.parser.syntax.Expr.ImportExpr;
|
||||
import org.pkl.parser.syntax.Expr.IntLiteralExpr;
|
||||
import org.pkl.parser.syntax.Expr.LetExpr;
|
||||
import org.pkl.parser.syntax.Expr.LogicalNotExpr;
|
||||
import org.pkl.parser.syntax.Expr.ModuleExpr;
|
||||
import org.pkl.parser.syntax.Expr.MultiLineStringLiteralExpr;
|
||||
import org.pkl.parser.syntax.Expr.NewExpr;
|
||||
import org.pkl.parser.syntax.Expr.NonNullExpr;
|
||||
import org.pkl.parser.syntax.Expr.NullLiteralExpr;
|
||||
import org.pkl.parser.syntax.Expr.OuterExpr;
|
||||
import org.pkl.parser.syntax.Expr.ParenthesizedExpr;
|
||||
import org.pkl.parser.syntax.Expr.QualifiedAccessExpr;
|
||||
import org.pkl.parser.syntax.Expr.ReadExpr;
|
||||
import org.pkl.parser.syntax.Expr.SingleLineStringLiteralExpr;
|
||||
import org.pkl.parser.syntax.Expr.SubscriptExpr;
|
||||
import org.pkl.parser.syntax.Expr.SuperAccessExpr;
|
||||
import org.pkl.parser.syntax.Expr.SuperSubscriptExpr;
|
||||
import org.pkl.parser.syntax.Expr.ThisExpr;
|
||||
import org.pkl.parser.syntax.Expr.ThrowExpr;
|
||||
import org.pkl.parser.syntax.Expr.TraceExpr;
|
||||
import org.pkl.parser.syntax.Expr.TypeCastExpr;
|
||||
import org.pkl.parser.syntax.Expr.TypeCheckExpr;
|
||||
import org.pkl.parser.syntax.Expr.UnaryMinusExpr;
|
||||
import org.pkl.parser.syntax.Expr.UnqualifiedAccessExpr;
|
||||
import org.pkl.parser.syntax.ExtendsOrAmendsClause;
|
||||
import org.pkl.parser.syntax.Identifier;
|
||||
import org.pkl.parser.syntax.ImportClause;
|
||||
import org.pkl.parser.syntax.Modifier;
|
||||
import org.pkl.parser.syntax.Modifier.ModifierValue;
|
||||
import org.pkl.parser.syntax.Module;
|
||||
import org.pkl.parser.syntax.Node;
|
||||
import org.pkl.parser.syntax.ObjectBody;
|
||||
import org.pkl.parser.syntax.ObjectMember.ForGenerator;
|
||||
import org.pkl.parser.syntax.ObjectMember.MemberPredicate;
|
||||
import org.pkl.parser.syntax.ObjectMember.ObjectElement;
|
||||
import org.pkl.parser.syntax.ObjectMember.ObjectEntry;
|
||||
import org.pkl.parser.syntax.ObjectMember.ObjectMethod;
|
||||
import org.pkl.parser.syntax.ObjectMember.ObjectProperty;
|
||||
import org.pkl.parser.syntax.ObjectMember.ObjectSpread;
|
||||
import org.pkl.parser.syntax.ObjectMember.WhenGenerator;
|
||||
import org.pkl.parser.syntax.Parameter;
|
||||
import org.pkl.parser.syntax.Parameter.TypedIdentifier;
|
||||
import org.pkl.parser.syntax.ParameterList;
|
||||
import org.pkl.parser.syntax.QualifiedIdentifier;
|
||||
import org.pkl.parser.syntax.StringConstant;
|
||||
import org.pkl.parser.syntax.StringPart;
|
||||
import org.pkl.parser.syntax.StringPart.StringChars;
|
||||
import org.pkl.parser.syntax.StringPart.StringInterpolation;
|
||||
import org.pkl.parser.syntax.Type;
|
||||
import org.pkl.parser.syntax.Type.ConstrainedType;
|
||||
import org.pkl.parser.syntax.Type.DeclaredType;
|
||||
import org.pkl.parser.syntax.Type.FunctionType;
|
||||
import org.pkl.parser.syntax.Type.ModuleType;
|
||||
import org.pkl.parser.syntax.Type.NothingType;
|
||||
import org.pkl.parser.syntax.Type.NullableType;
|
||||
import org.pkl.parser.syntax.Type.ParenthesizedType;
|
||||
import org.pkl.parser.syntax.Type.StringConstantType;
|
||||
import org.pkl.parser.syntax.Type.UnionType;
|
||||
import org.pkl.parser.syntax.Type.UnknownType;
|
||||
import org.pkl.parser.syntax.TypeAlias;
|
||||
import org.pkl.parser.syntax.TypeAnnotation;
|
||||
import org.pkl.parser.syntax.TypeParameterList;
|
||||
|
||||
public class AstBuilder extends AbstractAstBuilder<Object> {
|
||||
private final VmLanguage language;
|
||||
@@ -1097,7 +1097,7 @@ public class AstBuilder extends AbstractAstBuilder<Object> {
|
||||
return Pair.of(elementNodes, isConstantNodes);
|
||||
}
|
||||
|
||||
public GeneratorMemberNode visitObjectMember(org.pkl.core.parser.syntax.ObjectMember member) {
|
||||
public GeneratorMemberNode visitObjectMember(org.pkl.parser.syntax.ObjectMember member) {
|
||||
return (GeneratorMemberNode) member.accept(this);
|
||||
}
|
||||
|
||||
@@ -2375,7 +2375,7 @@ public class AstBuilder extends AbstractAstBuilder<Object> {
|
||||
}
|
||||
|
||||
private GeneratorMemberNode[] doVisitGeneratorMemberNodes(
|
||||
List<? extends org.pkl.core.parser.syntax.ObjectMember> members) {
|
||||
List<? extends org.pkl.parser.syntax.ObjectMember> members) {
|
||||
var result = new GeneratorMemberNode[members.size()];
|
||||
for (var i = 0; i < result.length; i++) {
|
||||
result[i] = visitObjectMember(members.get(i));
|
||||
@@ -2666,7 +2666,7 @@ public class AstBuilder extends AbstractAstBuilder<Object> {
|
||||
}
|
||||
var forExprCtx = ctx.parent();
|
||||
while (forExprCtx != null
|
||||
&& forExprCtx.getClass() != org.pkl.core.parser.syntax.ObjectMember.ForGenerator.class) {
|
||||
&& forExprCtx.getClass() != org.pkl.parser.syntax.ObjectMember.ForGenerator.class) {
|
||||
forExprCtx = forExprCtx.parent();
|
||||
}
|
||||
assert forExprCtx != null;
|
||||
@@ -2674,7 +2674,7 @@ public class AstBuilder extends AbstractAstBuilder<Object> {
|
||||
.evalError(errorMessageKey)
|
||||
.withSourceSection(
|
||||
createSourceSection(
|
||||
((org.pkl.core.parser.syntax.ObjectMember.ForGenerator) forExprCtx).forSpan()))
|
||||
((org.pkl.parser.syntax.ObjectMember.ForGenerator) forExprCtx).forSpan()))
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -24,21 +24,21 @@ import java.util.List;
|
||||
import org.pkl.core.ast.builder.ImportsAndReadsParser.Entry;
|
||||
import org.pkl.core.module.ModuleKey;
|
||||
import org.pkl.core.module.ResolvedModuleKey;
|
||||
import org.pkl.core.parser.Parser;
|
||||
import org.pkl.core.parser.ParserError;
|
||||
import org.pkl.core.parser.syntax.Expr;
|
||||
import org.pkl.core.parser.syntax.Expr.ImportExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.ReadExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.ReadType;
|
||||
import org.pkl.core.parser.syntax.Expr.SingleLineStringLiteralExpr;
|
||||
import org.pkl.core.parser.syntax.ExtendsOrAmendsClause;
|
||||
import org.pkl.core.parser.syntax.ExtendsOrAmendsClause.Type;
|
||||
import org.pkl.core.parser.syntax.ImportClause;
|
||||
import org.pkl.core.parser.syntax.StringPart.StringChars;
|
||||
import org.pkl.core.runtime.VmExceptionBuilder;
|
||||
import org.pkl.core.runtime.VmUtils;
|
||||
import org.pkl.core.util.IoUtils;
|
||||
import org.pkl.core.util.Nullable;
|
||||
import org.pkl.parser.Parser;
|
||||
import org.pkl.parser.ParserError;
|
||||
import org.pkl.parser.syntax.Expr;
|
||||
import org.pkl.parser.syntax.Expr.ImportExpr;
|
||||
import org.pkl.parser.syntax.Expr.ReadExpr;
|
||||
import org.pkl.parser.syntax.Expr.ReadType;
|
||||
import org.pkl.parser.syntax.Expr.SingleLineStringLiteralExpr;
|
||||
import org.pkl.parser.syntax.ExtendsOrAmendsClause;
|
||||
import org.pkl.parser.syntax.ExtendsOrAmendsClause.Type;
|
||||
import org.pkl.parser.syntax.ImportClause;
|
||||
import org.pkl.parser.syntax.StringPart.StringChars;
|
||||
|
||||
/**
|
||||
* Collects module uris and resource uris imported within a module.
|
||||
|
||||
@@ -24,12 +24,12 @@ import org.pkl.core.ast.ConstantNode;
|
||||
import org.pkl.core.ast.ExpressionNode;
|
||||
import org.pkl.core.ast.expression.generator.GeneratorMemberNode;
|
||||
import org.pkl.core.ast.member.ObjectMember;
|
||||
import org.pkl.core.parser.Lexer;
|
||||
import org.pkl.core.runtime.Identifier;
|
||||
import org.pkl.core.runtime.ModuleInfo;
|
||||
import org.pkl.core.runtime.VmDataSize;
|
||||
import org.pkl.core.runtime.VmDuration;
|
||||
import org.pkl.core.util.Nullable;
|
||||
import org.pkl.parser.Lexer;
|
||||
|
||||
public final class SymbolTable {
|
||||
private Scope currentScope;
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
@NonnullByDefault
|
||||
package org.pkl.core.parser;
|
||||
|
||||
import org.pkl.core.util.NonnullByDefault;
|
||||
@@ -1,4 +0,0 @@
|
||||
@NonnullByDefault
|
||||
package org.pkl.core.parser.syntax;
|
||||
|
||||
import org.pkl.core.util.NonnullByDefault;
|
||||
@@ -35,14 +35,6 @@ import org.pkl.core.ast.type.TypeNode;
|
||||
import org.pkl.core.http.HttpClient;
|
||||
import org.pkl.core.module.*;
|
||||
import org.pkl.core.packages.PackageResolver;
|
||||
import org.pkl.core.parser.Parser;
|
||||
import org.pkl.core.parser.ParserError;
|
||||
import org.pkl.core.parser.syntax.Class;
|
||||
import org.pkl.core.parser.syntax.ClassProperty;
|
||||
import org.pkl.core.parser.syntax.Expr;
|
||||
import org.pkl.core.parser.syntax.ImportClause;
|
||||
import org.pkl.core.parser.syntax.ModuleDecl;
|
||||
import org.pkl.core.parser.syntax.ReplInput;
|
||||
import org.pkl.core.project.DeclaredDependencies;
|
||||
import org.pkl.core.repl.ReplRequest.Eval;
|
||||
import org.pkl.core.repl.ReplRequest.Load;
|
||||
@@ -56,6 +48,14 @@ import org.pkl.core.util.EconomicMaps;
|
||||
import org.pkl.core.util.IoUtils;
|
||||
import org.pkl.core.util.MutableReference;
|
||||
import org.pkl.core.util.Nullable;
|
||||
import org.pkl.parser.Parser;
|
||||
import org.pkl.parser.ParserError;
|
||||
import org.pkl.parser.syntax.Class;
|
||||
import org.pkl.parser.syntax.ClassProperty;
|
||||
import org.pkl.parser.syntax.Expr;
|
||||
import org.pkl.parser.syntax.ImportClause;
|
||||
import org.pkl.parser.syntax.ModuleDecl;
|
||||
import org.pkl.parser.syntax.ReplInput;
|
||||
|
||||
public class ReplServer implements AutoCloseable {
|
||||
private final IndirectCallNode callNode = Truffle.getRuntime().createIndirectCallNode();
|
||||
@@ -222,9 +222,9 @@ public class ReplServer implements AutoCloseable {
|
||||
}
|
||||
} else if (tree instanceof Class clazz) {
|
||||
addStaticModuleProperty(builder.visitClass(clazz));
|
||||
} else if (tree instanceof org.pkl.core.parser.syntax.TypeAlias typeAlias) {
|
||||
} else if (tree instanceof org.pkl.parser.syntax.TypeAlias typeAlias) {
|
||||
addStaticModuleProperty(builder.visitTypeAlias(typeAlias));
|
||||
} else if (tree instanceof org.pkl.core.parser.syntax.ClassMethod classMethod) {
|
||||
} else if (tree instanceof org.pkl.parser.syntax.ClassMethod classMethod) {
|
||||
addModuleMethodDef(builder.visitClassMethod(classMethod));
|
||||
} else if (tree instanceof ModuleDecl) {
|
||||
// do nothing for now
|
||||
|
||||
@@ -18,11 +18,11 @@ package org.pkl.core.runtime;
|
||||
import com.oracle.truffle.api.nodes.Node;
|
||||
import org.pkl.core.Release;
|
||||
import org.pkl.core.Version;
|
||||
import org.pkl.core.parser.syntax.Module;
|
||||
import org.pkl.core.parser.syntax.ObjectMember.ObjectProperty;
|
||||
import org.pkl.core.parser.syntax.Type;
|
||||
import org.pkl.core.parser.syntax.Type.DeclaredType;
|
||||
import org.pkl.core.util.Nullable;
|
||||
import org.pkl.parser.syntax.Module;
|
||||
import org.pkl.parser.syntax.ObjectMember.ObjectProperty;
|
||||
import org.pkl.parser.syntax.Type;
|
||||
import org.pkl.parser.syntax.Type.DeclaredType;
|
||||
|
||||
final class MinPklVersionChecker {
|
||||
private static final Version currentVersion = Release.current().version();
|
||||
|
||||
@@ -24,11 +24,11 @@ import com.oracle.truffle.api.source.Source;
|
||||
import org.pkl.core.ast.builder.AstBuilder;
|
||||
import org.pkl.core.module.ModuleKey;
|
||||
import org.pkl.core.module.ResolvedModuleKey;
|
||||
import org.pkl.core.parser.Parser;
|
||||
import org.pkl.core.parser.ParserError;
|
||||
import org.pkl.core.parser.syntax.Module;
|
||||
import org.pkl.core.util.IoUtils;
|
||||
import org.pkl.core.util.Nullable;
|
||||
import org.pkl.parser.Parser;
|
||||
import org.pkl.parser.ParserError;
|
||||
import org.pkl.parser.syntax.Module;
|
||||
|
||||
@TruffleLanguage.Registration(
|
||||
id = "pkl",
|
||||
|
||||
@@ -22,8 +22,8 @@ import java.util.Deque;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.pkl.core.StackFrame;
|
||||
import org.pkl.core.parser.Lexer;
|
||||
import org.pkl.core.util.Nullable;
|
||||
import org.pkl.parser.Lexer;
|
||||
|
||||
public final class VmUndefinedValueException extends VmEvalException {
|
||||
private final @Nullable Object receiver;
|
||||
|
||||
@@ -56,11 +56,11 @@ import org.pkl.core.ast.type.UnresolvedTypeNode;
|
||||
import org.pkl.core.module.ModuleKey;
|
||||
import org.pkl.core.module.ModuleKeys;
|
||||
import org.pkl.core.module.ResolvedModuleKey;
|
||||
import org.pkl.core.parser.Parser;
|
||||
import org.pkl.core.parser.ParserError;
|
||||
import org.pkl.core.parser.syntax.Expr;
|
||||
import org.pkl.core.util.EconomicMaps;
|
||||
import org.pkl.core.util.Nullable;
|
||||
import org.pkl.parser.Parser;
|
||||
import org.pkl.parser.ParserError;
|
||||
import org.pkl.parser.syntax.Expr;
|
||||
|
||||
public final class VmUtils {
|
||||
/** See {@link VmUtils#shouldRunTypeCheck(VirtualFrame)}. */
|
||||
|
||||
@@ -18,8 +18,8 @@ package org.pkl.core.runtime;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Deque;
|
||||
import org.pkl.core.ValueFormatter;
|
||||
import org.pkl.core.parser.Lexer;
|
||||
import org.pkl.core.util.MutableBoolean;
|
||||
import org.pkl.parser.Lexer;
|
||||
|
||||
/**
|
||||
* Renders values for use in REPL and error messages. Does not force values to avoid consecutive
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
package org.pkl.core.stdlib.base;
|
||||
|
||||
import org.pkl.core.ValueFormatter;
|
||||
import org.pkl.core.parser.Lexer;
|
||||
import org.pkl.core.runtime.Identifier;
|
||||
import org.pkl.core.runtime.VmDataSize;
|
||||
import org.pkl.core.runtime.VmDuration;
|
||||
@@ -37,6 +36,7 @@ import org.pkl.core.runtime.VmUtils;
|
||||
import org.pkl.core.stdlib.AbstractRenderer;
|
||||
import org.pkl.core.stdlib.PklConverter;
|
||||
import org.pkl.core.util.LateInit;
|
||||
import org.pkl.parser.Lexer;
|
||||
|
||||
public final class PcfRenderer extends AbstractRenderer {
|
||||
private final ValueFormatter valueFormatter;
|
||||
|
||||
@@ -99,11 +99,6 @@ A local property definition cannot be amended.\n\
|
||||
\n\
|
||||
Use definition syntax instead, for example `local person = new { ... }` instead of `local person { ... }`.
|
||||
|
||||
unexpectedCurlyProbablyAmendsExpression=\
|
||||
Unexpected token: `'{'`.\n\
|
||||
\n\
|
||||
If you meant to write an amends expression, wrap the parent in parentheses. Try: `({0}) '{' ... '}'`
|
||||
|
||||
moduleCannotExtendSelf=\
|
||||
Module `{0}` cannot extend itself.
|
||||
|
||||
@@ -217,35 +212,6 @@ Expected {0} type argument(s) but got {1}.
|
||||
duplicateDefinition=\
|
||||
Duplicate definition of member `{0}`.
|
||||
|
||||
invalidCharacterEscapeSequence=\
|
||||
Invalid character escape sequence `{0}`.\n\
|
||||
\n\
|
||||
Valid character escape sequences are: {1}n {1}r {1}t {1}" {1}\\
|
||||
|
||||
unterminatedUnicodeEscapeSequence=\
|
||||
Unterminated Unicode escape sequence `{0}`.\n\
|
||||
\n\
|
||||
Unicode escape sequences must end with `}`.
|
||||
|
||||
invalidUnicodeEscapeSequence=\
|
||||
Invalid Unicode escape sequence `{0}`.\n\
|
||||
\n\
|
||||
Valid Unicode escape sequences are {1}'{'0'}' to {1}'{'10FFFF'}' (1-6 hexadecimal characters).
|
||||
|
||||
invalidSeparatorPosition=\
|
||||
Unexpected separator character.\n\
|
||||
\n\
|
||||
The separator character (`_`) cannot follow `0x`, `0b`, `.`, `e`, or 'E' in a number literal.
|
||||
|
||||
stringContentMustBeginOnNewLine=\
|
||||
The content of a multi-line string must begin on a new line.
|
||||
|
||||
closingStringDelimiterMustBeginOnNewLine=\
|
||||
The closing delimiter of a multi-line string must begin on a new line.
|
||||
|
||||
stringIndentationMustMatchLastLine=\
|
||||
Line must match or exceed indentation of the String's last line.
|
||||
|
||||
floatTooLarge=\
|
||||
Float literal `{0}` is too large.
|
||||
|
||||
@@ -704,11 +670,6 @@ Cannot resolve a triple-dot import from module URI `{0}`.\n\
|
||||
\n\
|
||||
Triple-dot imports may only be resolved by module schemes that are considered local, and have hierarchical URIs.
|
||||
|
||||
moduleDoesNotSupportDependencies=\
|
||||
Module `{0}` does not support importing dependencies.\n\
|
||||
\n\
|
||||
Dependencies can only be imported in modules that belong to a project, or within a package.
|
||||
|
||||
cannotHaveRelativeImport=\
|
||||
Module `{0}` cannot have a relative import URI.
|
||||
|
||||
@@ -764,18 +725,6 @@ A value of type `{0}` cannot be exported.
|
||||
incompatiblePklVersion=\
|
||||
Module `{0}` requires Pkl version {1} or higher, but your Pkl version is {2}.
|
||||
|
||||
missingDelimiter=\
|
||||
Missing `{0}` delimiter.
|
||||
|
||||
wrongDelimiter=\
|
||||
Expected delimiter `{0}`, but got `{1}`.
|
||||
|
||||
danglingDelimiter=\
|
||||
Unmatched delimiter `{0}`.
|
||||
|
||||
missingCommaSeparator=\
|
||||
Missing `,` separator.
|
||||
|
||||
missingFixedModifier=\
|
||||
Missing modifier `fixed`.\n\
|
||||
\n\
|
||||
@@ -855,12 +804,6 @@ The problematic cycles are those declared as local dependencies.\n\
|
||||
\n\
|
||||
{0}
|
||||
|
||||
multipleUnionDefaults=\
|
||||
A type union cannot have more than one default type.
|
||||
|
||||
notAUnion=\
|
||||
Only type unions can have a default marker (*).
|
||||
|
||||
invalidModuleOutput=\
|
||||
Expected `{0}` of module `{3}` to be of type `{1}`, but got type `{2}`.
|
||||
|
||||
@@ -878,11 +821,6 @@ Cannot find a dependency named `{0}`, because it is not declared in the current
|
||||
\n\
|
||||
To fix this, add it to the `dependencies` section of your `PklProject` file, and resolve your dependencies.
|
||||
|
||||
cannotResolveDependencyFromReaderWithOpaqueUris=\
|
||||
Cannot resolve dependencies from module reader with opaque URIs.\n\
|
||||
\n\
|
||||
Module reader for scheme `{0}` does not support hierarchical URIs.
|
||||
|
||||
cannotFindDependencyInPackage=\
|
||||
Cannot find dependency named `{0}`, because it was not declared in package `{1}`.
|
||||
|
||||
@@ -1080,14 +1018,6 @@ The only supported checksum algorithm is sha256.
|
||||
testsFailed=\
|
||||
Tests failed.
|
||||
|
||||
expectedJarOrFileUrl=\
|
||||
Certificates can only be loaded from `jar:` or `file:` URLs, but got:\n\
|
||||
{0}
|
||||
|
||||
cannotFindBuiltInCertificates=\
|
||||
Cannot find Pkl's trusted CA certificates on the class path.\n\
|
||||
To fix this problem, add dependency `org.pkl:pkl-certs`.
|
||||
|
||||
# suppress inspection "HttpUrlsUsage"
|
||||
malformedProxyAddress=\
|
||||
Malformed proxy URI (expecting `http://<host>[:<port>]`): `{0}`.
|
||||
@@ -1127,58 +1057,3 @@ External {0} reader does not support scheme `{1}`.
|
||||
|
||||
externalReaderAlreadyTerminated=\
|
||||
External reader process has already terminated.
|
||||
|
||||
keywordNotAllowedHere=\
|
||||
Keyword `{0}` is not allowed here.\n\
|
||||
\n\
|
||||
If you must use this name as identifier, enclose it in backticks.
|
||||
|
||||
unexpectedEndOfFile=\
|
||||
Unexpected end of file.
|
||||
|
||||
wrongHeaders=\
|
||||
{0} cannot have doc comments, annotations or modifiers.
|
||||
|
||||
invalidTopLevelToken=\
|
||||
Invalid token at position. Expected a class, typealias, method, or property.
|
||||
|
||||
interpolationInConstant=\
|
||||
String constant cannot have interpolated values.
|
||||
|
||||
unexpectedToken=\
|
||||
Unexpected token `{0}`. Expected `{1}`.
|
||||
|
||||
unexpectedToken2=\
|
||||
Unexpected token `{0}`. Expected `{1}` or `{2}`.
|
||||
|
||||
unexpectedTokenForExpression=\
|
||||
Unexpected token `{0}`.
|
||||
|
||||
unexpectedTokenForType=\
|
||||
Unexpected token `{0}`. Expected a type.
|
||||
|
||||
unexpectedTokenForType2=\
|
||||
Unexpected token `{0}`. Expected a type or `{1}`.
|
||||
|
||||
typeAnnotationInAmends=\
|
||||
Properties with type annotations cannot have object bodies.\n\
|
||||
\n\
|
||||
To define both a type annotation and an object body, try using assignment instead.\n\
|
||||
For example: `obj: Bird = new { ... }`.
|
||||
|
||||
invalidProperty=\
|
||||
Invalid property definition. Expected a type annotation, `=` or `{`.
|
||||
|
||||
unexpectedCharacter=\
|
||||
Unexpected character `{0}`. Did you mean `{1}`?
|
||||
|
||||
unexpectedCharacter3=\
|
||||
Unexpected character `{0}`. Did you mean `{1}`, `{2}` or `{3}`?
|
||||
|
||||
invalidCharacter=\
|
||||
Invalid identifier `{0}`.
|
||||
|
||||
danglingDocComment=\
|
||||
Dangling documentation comment.\n\
|
||||
\n\
|
||||
Documentation comments must be attached to modules, classes, typealiases, methods, or properties.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -26,6 +26,7 @@ dependencies {
|
||||
implementation(projects.pklCore)
|
||||
implementation(projects.pklCommonsCli)
|
||||
implementation(projects.pklCommons)
|
||||
implementation(projects.pklParser)
|
||||
implementation(libs.commonMark)
|
||||
implementation(libs.commonMarkTables)
|
||||
implementation(libs.kotlinxHtml)
|
||||
|
||||
@@ -22,9 +22,9 @@ import kotlin.io.path.bufferedWriter
|
||||
import kotlin.io.path.createParentDirectories
|
||||
import kotlin.io.path.outputStream
|
||||
import org.pkl.core.*
|
||||
import org.pkl.core.parser.Lexer
|
||||
import org.pkl.core.util.IoUtils
|
||||
import org.pkl.core.util.json.JsonWriter
|
||||
import org.pkl.parser.Lexer
|
||||
|
||||
// overwrites any existing file
|
||||
internal fun copyResource(resourceName: String, targetDir: Path) {
|
||||
|
||||
51
pkl-parser/gradle.lockfile
Normal file
51
pkl-parser/gradle.lockfile
Normal file
@@ -0,0 +1,51 @@
|
||||
# This is a Gradle generated file for dependency locking.
|
||||
# Manual edits can break the build and are not advised.
|
||||
# This file is expected to be part of source control.
|
||||
com.google.code.findbugs:jsr305:3.0.2=compileClasspath,compileOnlyDependenciesMetadata
|
||||
com.tunnelvisionlabs:antlr4-annotations:4.9.0=antlr
|
||||
com.tunnelvisionlabs:antlr4-runtime:4.9.0=antlr,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
com.tunnelvisionlabs:antlr4:4.9.0=antlr
|
||||
net.bytebuddy:byte-buddy:1.15.11=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.abego.treelayout:org.abego.treelayout.core:1.0.1=antlr
|
||||
org.antlr:ST4:4.3=antlr
|
||||
org.antlr:antlr-runtime:3.5.2=antlr
|
||||
org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath,testImplementationDependenciesMetadata,testJdk17CompileClasspath,testJdk17ImplementationDependenciesMetadata
|
||||
org.assertj:assertj-core:3.27.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.jetbrains.intellij.deps:trove4j:1.0.20200330=kotlinBuildToolsApiClasspath,kotlinCompilerClasspath,kotlinKlibCommonizerClasspath
|
||||
org.jetbrains.kotlin:kotlin-build-common:2.0.21=kotlinBuildToolsApiClasspath
|
||||
org.jetbrains.kotlin:kotlin-build-tools-api:2.0.21=kotlinBuildToolsApiClasspath
|
||||
org.jetbrains.kotlin:kotlin-build-tools-impl:2.0.21=kotlinBuildToolsApiClasspath
|
||||
org.jetbrains.kotlin:kotlin-compiler-embeddable:2.0.21=kotlinBuildToolsApiClasspath,kotlinCompilerClasspath,kotlinKlibCommonizerClasspath
|
||||
org.jetbrains.kotlin:kotlin-compiler-runner:2.0.21=kotlinBuildToolsApiClasspath
|
||||
org.jetbrains.kotlin:kotlin-daemon-client:2.0.21=kotlinBuildToolsApiClasspath
|
||||
org.jetbrains.kotlin:kotlin-daemon-embeddable:2.0.21=kotlinBuildToolsApiClasspath,kotlinCompilerClasspath,kotlinKlibCommonizerClasspath
|
||||
org.jetbrains.kotlin:kotlin-klib-commonizer-embeddable:2.0.21=kotlinKlibCommonizerClasspath
|
||||
org.jetbrains.kotlin:kotlin-native-prebuilt:2.0.21=kotlinNativeBundleConfiguration
|
||||
org.jetbrains.kotlin:kotlin-reflect:2.0.21=kotlinBuildToolsApiClasspath,kotlinCompilerClasspath,kotlinKlibCommonizerClasspath
|
||||
org.jetbrains.kotlin:kotlin-script-runtime:2.0.21=kotlinBuildToolsApiClasspath,kotlinCompilerClasspath,kotlinCompilerPluginClasspathGenerator,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinCompilerPluginClasspathTestJdk17,kotlinKlibCommonizerClasspath
|
||||
org.jetbrains.kotlin:kotlin-scripting-common:2.0.21=kotlinBuildToolsApiClasspath,kotlinCompilerPluginClasspathGenerator,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinCompilerPluginClasspathTestJdk17
|
||||
org.jetbrains.kotlin:kotlin-scripting-compiler-embeddable:2.0.21=kotlinBuildToolsApiClasspath,kotlinCompilerPluginClasspathGenerator,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinCompilerPluginClasspathTestJdk17
|
||||
org.jetbrains.kotlin:kotlin-scripting-compiler-impl-embeddable:2.0.21=kotlinBuildToolsApiClasspath,kotlinCompilerPluginClasspathGenerator,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinCompilerPluginClasspathTestJdk17
|
||||
org.jetbrains.kotlin:kotlin-scripting-jvm:2.0.21=kotlinBuildToolsApiClasspath,kotlinCompilerPluginClasspathGenerator,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinCompilerPluginClasspathTestJdk17
|
||||
org.jetbrains.kotlin:kotlin-stdlib-jdk7:2.0.21=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.jetbrains.kotlin:kotlin-stdlib-jdk8:2.0.21=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.jetbrains.kotlin:kotlin-stdlib:2.0.21=kotlinBuildToolsApiClasspath,kotlinCompilerClasspath,kotlinCompilerPluginClasspathGenerator,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinCompilerPluginClasspathTestJdk17,kotlinKlibCommonizerClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.4=kotlinBuildToolsApiClasspath,kotlinCompilerClasspath,kotlinKlibCommonizerClasspath
|
||||
org.jetbrains:annotations:13.0=kotlinBuildToolsApiClasspath,kotlinCompilerClasspath,kotlinCompilerPluginClasspathGenerator,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinCompilerPluginClasspathTestJdk17,kotlinKlibCommonizerClasspath,testCompileClasspath,testRuntimeClasspath
|
||||
org.junit.jupiter:junit-jupiter-api:5.11.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath,testRuntimeOnlyDependenciesMetadata
|
||||
org.junit.jupiter:junit-jupiter-api:5.8.2=testJdk17CompileClasspath,testJdk17ImplementationDependenciesMetadata,testJdk17RuntimeClasspath
|
||||
org.junit.jupiter:junit-jupiter-engine:5.11.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath,testRuntimeOnlyDependenciesMetadata
|
||||
org.junit.jupiter:junit-jupiter-engine:5.8.2=testJdk17RuntimeClasspath
|
||||
org.junit.jupiter:junit-jupiter-params:5.11.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
org.junit.jupiter:junit-jupiter-params:5.8.2=testJdk17CompileClasspath,testJdk17ImplementationDependenciesMetadata,testJdk17RuntimeClasspath
|
||||
org.junit.jupiter:junit-jupiter:5.8.2=testJdk17CompileClasspath,testJdk17ImplementationDependenciesMetadata,testJdk17RuntimeClasspath
|
||||
org.junit.platform:junit-platform-commons:1.11.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath,testRuntimeOnlyDependenciesMetadata
|
||||
org.junit.platform:junit-platform-commons:1.8.2=testJdk17CompileClasspath,testJdk17ImplementationDependenciesMetadata,testJdk17RuntimeClasspath
|
||||
org.junit.platform:junit-platform-engine:1.11.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath,testRuntimeOnlyDependenciesMetadata
|
||||
org.junit.platform:junit-platform-engine:1.8.2=testJdk17RuntimeClasspath
|
||||
org.junit.platform:junit-platform-launcher:1.8.2=testJdk17RuntimeClasspath
|
||||
org.junit:junit-bom:5.11.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath,testRuntimeOnlyDependenciesMetadata
|
||||
org.junit:junit-bom:5.8.2=testJdk17CompileClasspath,testJdk17ImplementationDependenciesMetadata,testJdk17RuntimeClasspath
|
||||
org.opentest4j:opentest4j:1.2.0=testJdk17CompileClasspath,testJdk17ImplementationDependenciesMetadata,testJdk17RuntimeClasspath
|
||||
org.opentest4j:opentest4j:1.3.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
|
||||
empty=annotationProcessor,apiDependenciesMetadata,generatorAnnotationProcessor,generatorApiDependenciesMetadata,generatorCompileClasspath,generatorCompileOnlyDependenciesMetadata,generatorImplementationDependenciesMetadata,generatorIntransitiveDependenciesMetadata,generatorKotlinScriptDefExtensions,generatorRuntimeClasspath,implementationDependenciesMetadata,intransitiveDependenciesMetadata,kotlinCompilerPluginClasspath,kotlinNativeCompilerPluginClasspath,kotlinScriptDefExtensions,runtimeClasspath,sourcesJar,testAnnotationProcessor,testApiDependenciesMetadata,testCompileOnlyDependenciesMetadata,testIntransitiveDependenciesMetadata,testJdk17AnnotationProcessor,testJdk17ApiDependenciesMetadata,testJdk17CompileOnlyDependenciesMetadata,testJdk17IntransitiveDependenciesMetadata,testJdk17KotlinScriptDefExtensions,testKotlinScriptDefExtensions
|
||||
85
pkl-parser/pkl-parser.gradle.kts
Normal file
85
pkl-parser/pkl-parser.gradle.kts
Normal file
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright © 2025 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
plugins {
|
||||
pklAllProjects
|
||||
pklJavaLibrary
|
||||
pklPublishLibrary
|
||||
antlr
|
||||
idea
|
||||
}
|
||||
|
||||
sourceSets { test { java { srcDir(file("testgenerated/antlr")) } } }
|
||||
|
||||
idea {
|
||||
module {
|
||||
// mark src/test/antlr as source dir
|
||||
// mark generated/antlr as generated source dir
|
||||
generatedSourceDirs = generatedSourceDirs + files("testgenerated/antlr")
|
||||
testSources.from(files("src/test/antlr", "testgenerated/antlr"))
|
||||
}
|
||||
}
|
||||
|
||||
// workaround for https://github.com/gradle/gradle/issues/820
|
||||
configurations.api.get().let { apiConfig ->
|
||||
apiConfig.setExtendsFrom(apiConfig.extendsFrom.filter { it.name != "antlr" })
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly(libs.jsr305)
|
||||
|
||||
antlr(libs.antlr)
|
||||
|
||||
testImplementation(projects.pklCommonsTest)
|
||||
testImplementation(libs.antlrRuntime)
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
named<MavenPublication>("library") {
|
||||
pom {
|
||||
url.set("https://github.com/apple/pkl/tree/main/pkl-parser")
|
||||
description.set("The parser for the Pkl language.")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tasks.generateTestGrammarSource {
|
||||
maxHeapSize = "64m"
|
||||
|
||||
// generate only visitor
|
||||
arguments = arguments + listOf("-visitor", "-no-listener")
|
||||
|
||||
// Due to https://github.com/antlr/antlr4/issues/2260,
|
||||
// we can't put .g4 files into src/test/antlr/org/pkl/parser/antlr.
|
||||
// Instead, we put .g4 files into src/test/antlr, adapt output dir below,
|
||||
// and use @header directives in .g4 files (instead of setting `-package` argument here)
|
||||
// and task makeIntelliJAntlrPluginHappy to fix up the IDE story.
|
||||
outputDirectory = file("testgenerated/antlr/org/pkl/parser/antlr")
|
||||
}
|
||||
|
||||
tasks.generateGrammarSource { enabled = false }
|
||||
|
||||
tasks.compileTestKotlin { dependsOn(tasks.generateTestGrammarSource) }
|
||||
|
||||
// Satisfy expectations of IntelliJ ANTLR plugin,
|
||||
// which can't otherwise cope with our ANTLR setup.
|
||||
val makeIntelliJAntlrPluginHappy by
|
||||
tasks.registering(Copy::class) {
|
||||
dependsOn(tasks.generateGrammarSource)
|
||||
into("test/antlr")
|
||||
from("testgenerated/antlr/org/pkl/parser/antlr") { include("PklLexer.tokens") }
|
||||
}
|
||||
@@ -13,82 +13,82 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.core.parser;
|
||||
package org.pkl.parser;
|
||||
|
||||
import org.pkl.core.parser.syntax.Annotation;
|
||||
import org.pkl.core.parser.syntax.ArgumentList;
|
||||
import org.pkl.core.parser.syntax.Class;
|
||||
import org.pkl.core.parser.syntax.ClassBody;
|
||||
import org.pkl.core.parser.syntax.ClassMethod;
|
||||
import org.pkl.core.parser.syntax.ClassProperty;
|
||||
import org.pkl.core.parser.syntax.DocComment;
|
||||
import org.pkl.core.parser.syntax.Expr.AmendsExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.BinaryOperatorExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.BoolLiteralExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.FloatLiteralExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.FunctionLiteralExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.IfExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.ImportExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.IntLiteralExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.LetExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.LogicalNotExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.ModuleExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.MultiLineStringLiteralExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.NewExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.NonNullExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.NullLiteralExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.OuterExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.ParenthesizedExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.QualifiedAccessExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.ReadExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.SingleLineStringLiteralExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.SubscriptExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.SuperAccessExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.SuperSubscriptExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.ThisExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.ThrowExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.TraceExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.TypeCastExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.TypeCheckExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.UnaryMinusExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.UnqualifiedAccessExpr;
|
||||
import org.pkl.core.parser.syntax.ExtendsOrAmendsClause;
|
||||
import org.pkl.core.parser.syntax.Identifier;
|
||||
import org.pkl.core.parser.syntax.ImportClause;
|
||||
import org.pkl.core.parser.syntax.Keyword;
|
||||
import org.pkl.core.parser.syntax.Modifier;
|
||||
import org.pkl.core.parser.syntax.ModuleDecl;
|
||||
import org.pkl.core.parser.syntax.Node;
|
||||
import org.pkl.core.parser.syntax.ObjectBody;
|
||||
import org.pkl.core.parser.syntax.ObjectMember.ForGenerator;
|
||||
import org.pkl.core.parser.syntax.ObjectMember.MemberPredicate;
|
||||
import org.pkl.core.parser.syntax.ObjectMember.ObjectElement;
|
||||
import org.pkl.core.parser.syntax.ObjectMember.ObjectEntry;
|
||||
import org.pkl.core.parser.syntax.ObjectMember.ObjectMethod;
|
||||
import org.pkl.core.parser.syntax.ObjectMember.ObjectProperty;
|
||||
import org.pkl.core.parser.syntax.ObjectMember.ObjectSpread;
|
||||
import org.pkl.core.parser.syntax.ObjectMember.WhenGenerator;
|
||||
import org.pkl.core.parser.syntax.Parameter;
|
||||
import org.pkl.core.parser.syntax.ParameterList;
|
||||
import org.pkl.core.parser.syntax.QualifiedIdentifier;
|
||||
import org.pkl.core.parser.syntax.ReplInput;
|
||||
import org.pkl.core.parser.syntax.StringConstant;
|
||||
import org.pkl.core.parser.syntax.StringPart;
|
||||
import org.pkl.core.parser.syntax.Type.ConstrainedType;
|
||||
import org.pkl.core.parser.syntax.Type.DeclaredType;
|
||||
import org.pkl.core.parser.syntax.Type.FunctionType;
|
||||
import org.pkl.core.parser.syntax.Type.ModuleType;
|
||||
import org.pkl.core.parser.syntax.Type.NothingType;
|
||||
import org.pkl.core.parser.syntax.Type.NullableType;
|
||||
import org.pkl.core.parser.syntax.Type.ParenthesizedType;
|
||||
import org.pkl.core.parser.syntax.Type.StringConstantType;
|
||||
import org.pkl.core.parser.syntax.Type.UnionType;
|
||||
import org.pkl.core.parser.syntax.Type.UnknownType;
|
||||
import org.pkl.core.parser.syntax.TypeAlias;
|
||||
import org.pkl.core.parser.syntax.TypeAnnotation;
|
||||
import org.pkl.core.parser.syntax.TypeArgumentList;
|
||||
import org.pkl.core.parser.syntax.TypeParameter;
|
||||
import org.pkl.core.parser.syntax.TypeParameterList;
|
||||
import org.pkl.parser.syntax.Annotation;
|
||||
import org.pkl.parser.syntax.ArgumentList;
|
||||
import org.pkl.parser.syntax.Class;
|
||||
import org.pkl.parser.syntax.ClassBody;
|
||||
import org.pkl.parser.syntax.ClassMethod;
|
||||
import org.pkl.parser.syntax.ClassProperty;
|
||||
import org.pkl.parser.syntax.DocComment;
|
||||
import org.pkl.parser.syntax.Expr.AmendsExpr;
|
||||
import org.pkl.parser.syntax.Expr.BinaryOperatorExpr;
|
||||
import org.pkl.parser.syntax.Expr.BoolLiteralExpr;
|
||||
import org.pkl.parser.syntax.Expr.FloatLiteralExpr;
|
||||
import org.pkl.parser.syntax.Expr.FunctionLiteralExpr;
|
||||
import org.pkl.parser.syntax.Expr.IfExpr;
|
||||
import org.pkl.parser.syntax.Expr.ImportExpr;
|
||||
import org.pkl.parser.syntax.Expr.IntLiteralExpr;
|
||||
import org.pkl.parser.syntax.Expr.LetExpr;
|
||||
import org.pkl.parser.syntax.Expr.LogicalNotExpr;
|
||||
import org.pkl.parser.syntax.Expr.ModuleExpr;
|
||||
import org.pkl.parser.syntax.Expr.MultiLineStringLiteralExpr;
|
||||
import org.pkl.parser.syntax.Expr.NewExpr;
|
||||
import org.pkl.parser.syntax.Expr.NonNullExpr;
|
||||
import org.pkl.parser.syntax.Expr.NullLiteralExpr;
|
||||
import org.pkl.parser.syntax.Expr.OuterExpr;
|
||||
import org.pkl.parser.syntax.Expr.ParenthesizedExpr;
|
||||
import org.pkl.parser.syntax.Expr.QualifiedAccessExpr;
|
||||
import org.pkl.parser.syntax.Expr.ReadExpr;
|
||||
import org.pkl.parser.syntax.Expr.SingleLineStringLiteralExpr;
|
||||
import org.pkl.parser.syntax.Expr.SubscriptExpr;
|
||||
import org.pkl.parser.syntax.Expr.SuperAccessExpr;
|
||||
import org.pkl.parser.syntax.Expr.SuperSubscriptExpr;
|
||||
import org.pkl.parser.syntax.Expr.ThisExpr;
|
||||
import org.pkl.parser.syntax.Expr.ThrowExpr;
|
||||
import org.pkl.parser.syntax.Expr.TraceExpr;
|
||||
import org.pkl.parser.syntax.Expr.TypeCastExpr;
|
||||
import org.pkl.parser.syntax.Expr.TypeCheckExpr;
|
||||
import org.pkl.parser.syntax.Expr.UnaryMinusExpr;
|
||||
import org.pkl.parser.syntax.Expr.UnqualifiedAccessExpr;
|
||||
import org.pkl.parser.syntax.ExtendsOrAmendsClause;
|
||||
import org.pkl.parser.syntax.Identifier;
|
||||
import org.pkl.parser.syntax.ImportClause;
|
||||
import org.pkl.parser.syntax.Keyword;
|
||||
import org.pkl.parser.syntax.Modifier;
|
||||
import org.pkl.parser.syntax.ModuleDecl;
|
||||
import org.pkl.parser.syntax.Node;
|
||||
import org.pkl.parser.syntax.ObjectBody;
|
||||
import org.pkl.parser.syntax.ObjectMember.ForGenerator;
|
||||
import org.pkl.parser.syntax.ObjectMember.MemberPredicate;
|
||||
import org.pkl.parser.syntax.ObjectMember.ObjectElement;
|
||||
import org.pkl.parser.syntax.ObjectMember.ObjectEntry;
|
||||
import org.pkl.parser.syntax.ObjectMember.ObjectMethod;
|
||||
import org.pkl.parser.syntax.ObjectMember.ObjectProperty;
|
||||
import org.pkl.parser.syntax.ObjectMember.ObjectSpread;
|
||||
import org.pkl.parser.syntax.ObjectMember.WhenGenerator;
|
||||
import org.pkl.parser.syntax.Parameter;
|
||||
import org.pkl.parser.syntax.ParameterList;
|
||||
import org.pkl.parser.syntax.QualifiedIdentifier;
|
||||
import org.pkl.parser.syntax.ReplInput;
|
||||
import org.pkl.parser.syntax.StringConstant;
|
||||
import org.pkl.parser.syntax.StringPart;
|
||||
import org.pkl.parser.syntax.Type.ConstrainedType;
|
||||
import org.pkl.parser.syntax.Type.DeclaredType;
|
||||
import org.pkl.parser.syntax.Type.FunctionType;
|
||||
import org.pkl.parser.syntax.Type.ModuleType;
|
||||
import org.pkl.parser.syntax.Type.NothingType;
|
||||
import org.pkl.parser.syntax.Type.NullableType;
|
||||
import org.pkl.parser.syntax.Type.ParenthesizedType;
|
||||
import org.pkl.parser.syntax.Type.StringConstantType;
|
||||
import org.pkl.parser.syntax.Type.UnionType;
|
||||
import org.pkl.parser.syntax.Type.UnknownType;
|
||||
import org.pkl.parser.syntax.TypeAlias;
|
||||
import org.pkl.parser.syntax.TypeAnnotation;
|
||||
import org.pkl.parser.syntax.TypeArgumentList;
|
||||
import org.pkl.parser.syntax.TypeParameter;
|
||||
import org.pkl.parser.syntax.TypeParameterList;
|
||||
|
||||
public abstract class BaseParserVisitor<T> implements ParserVisitor<T> {
|
||||
|
||||
@@ -338,7 +338,7 @@ public abstract class BaseParserVisitor<T> implements ParserVisitor<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public T visitModule(org.pkl.core.parser.syntax.Module module) {
|
||||
public T visitModule(org.pkl.parser.syntax.Module module) {
|
||||
return visitChildren(module);
|
||||
}
|
||||
|
||||
@@ -13,12 +13,12 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.core.parser;
|
||||
package org.pkl.parser;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Arrays;
|
||||
import java.util.Deque;
|
||||
import org.pkl.core.util.ErrorMessages;
|
||||
import org.pkl.parser.util.ErrorMessages;
|
||||
|
||||
public class Lexer {
|
||||
|
||||
@@ -13,18 +13,18 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.core.parser;
|
||||
package org.pkl.parser;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.pkl.core.parser.syntax.Expr;
|
||||
import org.pkl.core.parser.syntax.Expr.BinaryOperatorExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.OperatorExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.TypeCastExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.TypeCheckExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.TypeExpr;
|
||||
import org.pkl.core.parser.syntax.Operator;
|
||||
import org.pkl.core.util.Nullable;
|
||||
import org.pkl.parser.syntax.Expr;
|
||||
import org.pkl.parser.syntax.Expr.BinaryOperatorExpr;
|
||||
import org.pkl.parser.syntax.Expr.OperatorExpr;
|
||||
import org.pkl.parser.syntax.Expr.TypeCastExpr;
|
||||
import org.pkl.parser.syntax.Expr.TypeCheckExpr;
|
||||
import org.pkl.parser.syntax.Expr.TypeExpr;
|
||||
import org.pkl.parser.syntax.Operator;
|
||||
import org.pkl.parser.util.Nullable;
|
||||
|
||||
class OperatorResolver {
|
||||
private OperatorResolver() {}
|
||||
@@ -13,80 +13,79 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.core.parser;
|
||||
package org.pkl.parser;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
import org.pkl.core.PklBugException;
|
||||
import org.pkl.core.parser.syntax.Annotation;
|
||||
import org.pkl.core.parser.syntax.ArgumentList;
|
||||
import org.pkl.core.parser.syntax.Class;
|
||||
import org.pkl.core.parser.syntax.ClassBody;
|
||||
import org.pkl.core.parser.syntax.ClassMethod;
|
||||
import org.pkl.core.parser.syntax.ClassProperty;
|
||||
import org.pkl.core.parser.syntax.DocComment;
|
||||
import org.pkl.core.parser.syntax.Expr;
|
||||
import org.pkl.core.parser.syntax.Expr.AmendsExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.BoolLiteralExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.FloatLiteralExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.FunctionLiteralExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.IfExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.IntLiteralExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.LetExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.LogicalNotExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.ModuleExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.MultiLineStringLiteralExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.NewExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.NonNullExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.NullLiteralExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.OperatorExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.OuterExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.ParenthesizedExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.QualifiedAccessExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.ReadExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.ReadType;
|
||||
import org.pkl.core.parser.syntax.Expr.SingleLineStringLiteralExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.SubscriptExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.SuperAccessExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.SuperSubscriptExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.ThisExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.ThrowExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.TraceExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.UnaryMinusExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.UnqualifiedAccessExpr;
|
||||
import org.pkl.core.parser.syntax.ExtendsOrAmendsClause;
|
||||
import org.pkl.core.parser.syntax.Identifier;
|
||||
import org.pkl.core.parser.syntax.ImportClause;
|
||||
import org.pkl.core.parser.syntax.Keyword;
|
||||
import org.pkl.core.parser.syntax.Modifier;
|
||||
import org.pkl.core.parser.syntax.Module;
|
||||
import org.pkl.core.parser.syntax.ModuleDecl;
|
||||
import org.pkl.core.parser.syntax.Node;
|
||||
import org.pkl.core.parser.syntax.ObjectBody;
|
||||
import org.pkl.core.parser.syntax.ObjectMember;
|
||||
import org.pkl.core.parser.syntax.Operator;
|
||||
import org.pkl.core.parser.syntax.Parameter;
|
||||
import org.pkl.core.parser.syntax.Parameter.TypedIdentifier;
|
||||
import org.pkl.core.parser.syntax.ParameterList;
|
||||
import org.pkl.core.parser.syntax.QualifiedIdentifier;
|
||||
import org.pkl.core.parser.syntax.ReplInput;
|
||||
import org.pkl.core.parser.syntax.StringConstant;
|
||||
import org.pkl.core.parser.syntax.StringPart;
|
||||
import org.pkl.core.parser.syntax.StringPart.StringChars;
|
||||
import org.pkl.core.parser.syntax.Type;
|
||||
import org.pkl.core.parser.syntax.Type.DeclaredType;
|
||||
import org.pkl.core.parser.syntax.Type.ParenthesizedType;
|
||||
import org.pkl.core.parser.syntax.Type.StringConstantType;
|
||||
import org.pkl.core.parser.syntax.TypeAlias;
|
||||
import org.pkl.core.parser.syntax.TypeAnnotation;
|
||||
import org.pkl.core.parser.syntax.TypeArgumentList;
|
||||
import org.pkl.core.parser.syntax.TypeParameter;
|
||||
import org.pkl.core.parser.syntax.TypeParameterList;
|
||||
import org.pkl.core.util.ErrorMessages;
|
||||
import org.pkl.core.util.Nullable;
|
||||
import org.pkl.parser.syntax.Annotation;
|
||||
import org.pkl.parser.syntax.ArgumentList;
|
||||
import org.pkl.parser.syntax.Class;
|
||||
import org.pkl.parser.syntax.ClassBody;
|
||||
import org.pkl.parser.syntax.ClassMethod;
|
||||
import org.pkl.parser.syntax.ClassProperty;
|
||||
import org.pkl.parser.syntax.DocComment;
|
||||
import org.pkl.parser.syntax.Expr;
|
||||
import org.pkl.parser.syntax.Expr.AmendsExpr;
|
||||
import org.pkl.parser.syntax.Expr.BoolLiteralExpr;
|
||||
import org.pkl.parser.syntax.Expr.FloatLiteralExpr;
|
||||
import org.pkl.parser.syntax.Expr.FunctionLiteralExpr;
|
||||
import org.pkl.parser.syntax.Expr.IfExpr;
|
||||
import org.pkl.parser.syntax.Expr.IntLiteralExpr;
|
||||
import org.pkl.parser.syntax.Expr.LetExpr;
|
||||
import org.pkl.parser.syntax.Expr.LogicalNotExpr;
|
||||
import org.pkl.parser.syntax.Expr.ModuleExpr;
|
||||
import org.pkl.parser.syntax.Expr.MultiLineStringLiteralExpr;
|
||||
import org.pkl.parser.syntax.Expr.NewExpr;
|
||||
import org.pkl.parser.syntax.Expr.NonNullExpr;
|
||||
import org.pkl.parser.syntax.Expr.NullLiteralExpr;
|
||||
import org.pkl.parser.syntax.Expr.OperatorExpr;
|
||||
import org.pkl.parser.syntax.Expr.OuterExpr;
|
||||
import org.pkl.parser.syntax.Expr.ParenthesizedExpr;
|
||||
import org.pkl.parser.syntax.Expr.QualifiedAccessExpr;
|
||||
import org.pkl.parser.syntax.Expr.ReadExpr;
|
||||
import org.pkl.parser.syntax.Expr.ReadType;
|
||||
import org.pkl.parser.syntax.Expr.SingleLineStringLiteralExpr;
|
||||
import org.pkl.parser.syntax.Expr.SubscriptExpr;
|
||||
import org.pkl.parser.syntax.Expr.SuperAccessExpr;
|
||||
import org.pkl.parser.syntax.Expr.SuperSubscriptExpr;
|
||||
import org.pkl.parser.syntax.Expr.ThisExpr;
|
||||
import org.pkl.parser.syntax.Expr.ThrowExpr;
|
||||
import org.pkl.parser.syntax.Expr.TraceExpr;
|
||||
import org.pkl.parser.syntax.Expr.UnaryMinusExpr;
|
||||
import org.pkl.parser.syntax.Expr.UnqualifiedAccessExpr;
|
||||
import org.pkl.parser.syntax.ExtendsOrAmendsClause;
|
||||
import org.pkl.parser.syntax.Identifier;
|
||||
import org.pkl.parser.syntax.ImportClause;
|
||||
import org.pkl.parser.syntax.Keyword;
|
||||
import org.pkl.parser.syntax.Modifier;
|
||||
import org.pkl.parser.syntax.Module;
|
||||
import org.pkl.parser.syntax.ModuleDecl;
|
||||
import org.pkl.parser.syntax.Node;
|
||||
import org.pkl.parser.syntax.ObjectBody;
|
||||
import org.pkl.parser.syntax.ObjectMember;
|
||||
import org.pkl.parser.syntax.Operator;
|
||||
import org.pkl.parser.syntax.Parameter;
|
||||
import org.pkl.parser.syntax.Parameter.TypedIdentifier;
|
||||
import org.pkl.parser.syntax.ParameterList;
|
||||
import org.pkl.parser.syntax.QualifiedIdentifier;
|
||||
import org.pkl.parser.syntax.ReplInput;
|
||||
import org.pkl.parser.syntax.StringConstant;
|
||||
import org.pkl.parser.syntax.StringPart;
|
||||
import org.pkl.parser.syntax.StringPart.StringChars;
|
||||
import org.pkl.parser.syntax.Type;
|
||||
import org.pkl.parser.syntax.Type.DeclaredType;
|
||||
import org.pkl.parser.syntax.Type.ParenthesizedType;
|
||||
import org.pkl.parser.syntax.Type.StringConstantType;
|
||||
import org.pkl.parser.syntax.TypeAlias;
|
||||
import org.pkl.parser.syntax.TypeAnnotation;
|
||||
import org.pkl.parser.syntax.TypeArgumentList;
|
||||
import org.pkl.parser.syntax.TypeParameter;
|
||||
import org.pkl.parser.syntax.TypeParameterList;
|
||||
import org.pkl.parser.util.ErrorMessages;
|
||||
import org.pkl.parser.util.Nullable;
|
||||
|
||||
@SuppressWarnings("DuplicatedCode")
|
||||
public class Parser {
|
||||
@@ -1480,7 +1479,7 @@ public class Parser {
|
||||
case HIDDEN -> new Modifier(Modifier.ModifierValue.HIDDEN, next().span);
|
||||
case FIXED -> new Modifier(Modifier.ModifierValue.FIXED, next().span);
|
||||
case CONST -> new Modifier(Modifier.ModifierValue.CONST, next().span);
|
||||
default -> throw PklBugException.unreachableCode();
|
||||
default -> throw new RuntimeException("Unreacheable code");
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1617,7 +1616,7 @@ public class Parser {
|
||||
}
|
||||
case INTERPOLATION_START -> throw parserError("interpolationInConstant");
|
||||
// the lexer makes sure we only get the above tokens inside a string
|
||||
default -> throw PklBugException.unreachableCode();
|
||||
default -> throw new RuntimeException("Unreacheable code");
|
||||
}
|
||||
}
|
||||
var end = next().span;
|
||||
@@ -1632,7 +1631,7 @@ public class Parser {
|
||||
case STRING_ESCAPE_TAB -> "\t";
|
||||
case STRING_ESCAPE_RETURN -> "\r";
|
||||
case STRING_ESCAPE_UNICODE -> parseUnicodeEscape(tk);
|
||||
default -> throw PklBugException.unreachableCode();
|
||||
default -> throw new RuntimeException("Unreacheable code");
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1797,8 +1796,7 @@ public class Parser {
|
||||
precededBySemicolon = precededBySemicolon || tk == Token.SEMICOLON;
|
||||
tk = lexer.next();
|
||||
}
|
||||
return new FullToken(
|
||||
tk, lexer.span(), lexer.sCursor, lexer.cursor - lexer.sCursor, lexer.newLinesBetween);
|
||||
return new FullToken(tk, lexer.span(), lexer.newLinesBetween);
|
||||
}
|
||||
|
||||
// Like next, but don't ignore comments
|
||||
@@ -1817,8 +1815,7 @@ public class Parser {
|
||||
precededBySemicolon = true;
|
||||
tk = lexer.next();
|
||||
}
|
||||
return new FullToken(
|
||||
tk, lexer.span(), lexer.sCursor, lexer.cursor - lexer.sCursor, lexer.newLinesBetween);
|
||||
return new FullToken(tk, lexer.span(), lexer.newLinesBetween);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1840,10 +1837,9 @@ public class Parser {
|
||||
}
|
||||
}
|
||||
|
||||
private record FullToken(
|
||||
Token token, Span span, int textOffset, int textSize, int newLinesBetween) {
|
||||
private record FullToken(Token token, Span span, int newLinesBetween) {
|
||||
String text(Lexer lexer) {
|
||||
return lexer.textFor(textOffset, textSize);
|
||||
return lexer.textFor(span.charIndex(), span.length());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,10 +13,10 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.core.parser;
|
||||
package org.pkl.parser;
|
||||
|
||||
import org.pkl.core.parser.syntax.Module;
|
||||
import org.pkl.core.util.Nullable;
|
||||
import org.pkl.parser.syntax.Module;
|
||||
import org.pkl.parser.util.Nullable;
|
||||
|
||||
public class ParserError extends RuntimeException {
|
||||
private final Span span;
|
||||
@@ -13,66 +13,66 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.core.parser;
|
||||
package org.pkl.parser;
|
||||
|
||||
import org.pkl.core.parser.syntax.Annotation;
|
||||
import org.pkl.core.parser.syntax.ArgumentList;
|
||||
import org.pkl.core.parser.syntax.Class;
|
||||
import org.pkl.core.parser.syntax.ClassBody;
|
||||
import org.pkl.core.parser.syntax.ClassMethod;
|
||||
import org.pkl.core.parser.syntax.ClassProperty;
|
||||
import org.pkl.core.parser.syntax.DocComment;
|
||||
import org.pkl.core.parser.syntax.Expr;
|
||||
import org.pkl.core.parser.syntax.Expr.AmendsExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.BinaryOperatorExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.BoolLiteralExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.FloatLiteralExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.FunctionLiteralExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.IfExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.IntLiteralExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.LetExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.LogicalNotExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.ModuleExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.MultiLineStringLiteralExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.NewExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.NonNullExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.NullLiteralExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.OuterExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.ParenthesizedExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.QualifiedAccessExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.ReadExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.SingleLineStringLiteralExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.SubscriptExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.SuperAccessExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.SuperSubscriptExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.ThisExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.ThrowExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.TraceExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.TypeCastExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.TypeCheckExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.UnaryMinusExpr;
|
||||
import org.pkl.core.parser.syntax.Expr.UnqualifiedAccessExpr;
|
||||
import org.pkl.core.parser.syntax.ExtendsOrAmendsClause;
|
||||
import org.pkl.core.parser.syntax.Identifier;
|
||||
import org.pkl.core.parser.syntax.ImportClause;
|
||||
import org.pkl.core.parser.syntax.Keyword;
|
||||
import org.pkl.core.parser.syntax.Modifier;
|
||||
import org.pkl.core.parser.syntax.Module;
|
||||
import org.pkl.core.parser.syntax.ModuleDecl;
|
||||
import org.pkl.core.parser.syntax.ObjectBody;
|
||||
import org.pkl.core.parser.syntax.ObjectMember;
|
||||
import org.pkl.core.parser.syntax.Parameter;
|
||||
import org.pkl.core.parser.syntax.ParameterList;
|
||||
import org.pkl.core.parser.syntax.QualifiedIdentifier;
|
||||
import org.pkl.core.parser.syntax.ReplInput;
|
||||
import org.pkl.core.parser.syntax.StringConstant;
|
||||
import org.pkl.core.parser.syntax.StringPart;
|
||||
import org.pkl.core.parser.syntax.Type;
|
||||
import org.pkl.core.parser.syntax.TypeAlias;
|
||||
import org.pkl.core.parser.syntax.TypeAnnotation;
|
||||
import org.pkl.core.parser.syntax.TypeArgumentList;
|
||||
import org.pkl.core.parser.syntax.TypeParameter;
|
||||
import org.pkl.core.parser.syntax.TypeParameterList;
|
||||
import org.pkl.parser.syntax.Annotation;
|
||||
import org.pkl.parser.syntax.ArgumentList;
|
||||
import org.pkl.parser.syntax.Class;
|
||||
import org.pkl.parser.syntax.ClassBody;
|
||||
import org.pkl.parser.syntax.ClassMethod;
|
||||
import org.pkl.parser.syntax.ClassProperty;
|
||||
import org.pkl.parser.syntax.DocComment;
|
||||
import org.pkl.parser.syntax.Expr;
|
||||
import org.pkl.parser.syntax.Expr.AmendsExpr;
|
||||
import org.pkl.parser.syntax.Expr.BinaryOperatorExpr;
|
||||
import org.pkl.parser.syntax.Expr.BoolLiteralExpr;
|
||||
import org.pkl.parser.syntax.Expr.FloatLiteralExpr;
|
||||
import org.pkl.parser.syntax.Expr.FunctionLiteralExpr;
|
||||
import org.pkl.parser.syntax.Expr.IfExpr;
|
||||
import org.pkl.parser.syntax.Expr.IntLiteralExpr;
|
||||
import org.pkl.parser.syntax.Expr.LetExpr;
|
||||
import org.pkl.parser.syntax.Expr.LogicalNotExpr;
|
||||
import org.pkl.parser.syntax.Expr.ModuleExpr;
|
||||
import org.pkl.parser.syntax.Expr.MultiLineStringLiteralExpr;
|
||||
import org.pkl.parser.syntax.Expr.NewExpr;
|
||||
import org.pkl.parser.syntax.Expr.NonNullExpr;
|
||||
import org.pkl.parser.syntax.Expr.NullLiteralExpr;
|
||||
import org.pkl.parser.syntax.Expr.OuterExpr;
|
||||
import org.pkl.parser.syntax.Expr.ParenthesizedExpr;
|
||||
import org.pkl.parser.syntax.Expr.QualifiedAccessExpr;
|
||||
import org.pkl.parser.syntax.Expr.ReadExpr;
|
||||
import org.pkl.parser.syntax.Expr.SingleLineStringLiteralExpr;
|
||||
import org.pkl.parser.syntax.Expr.SubscriptExpr;
|
||||
import org.pkl.parser.syntax.Expr.SuperAccessExpr;
|
||||
import org.pkl.parser.syntax.Expr.SuperSubscriptExpr;
|
||||
import org.pkl.parser.syntax.Expr.ThisExpr;
|
||||
import org.pkl.parser.syntax.Expr.ThrowExpr;
|
||||
import org.pkl.parser.syntax.Expr.TraceExpr;
|
||||
import org.pkl.parser.syntax.Expr.TypeCastExpr;
|
||||
import org.pkl.parser.syntax.Expr.TypeCheckExpr;
|
||||
import org.pkl.parser.syntax.Expr.UnaryMinusExpr;
|
||||
import org.pkl.parser.syntax.Expr.UnqualifiedAccessExpr;
|
||||
import org.pkl.parser.syntax.ExtendsOrAmendsClause;
|
||||
import org.pkl.parser.syntax.Identifier;
|
||||
import org.pkl.parser.syntax.ImportClause;
|
||||
import org.pkl.parser.syntax.Keyword;
|
||||
import org.pkl.parser.syntax.Modifier;
|
||||
import org.pkl.parser.syntax.Module;
|
||||
import org.pkl.parser.syntax.ModuleDecl;
|
||||
import org.pkl.parser.syntax.ObjectBody;
|
||||
import org.pkl.parser.syntax.ObjectMember;
|
||||
import org.pkl.parser.syntax.Parameter;
|
||||
import org.pkl.parser.syntax.ParameterList;
|
||||
import org.pkl.parser.syntax.QualifiedIdentifier;
|
||||
import org.pkl.parser.syntax.ReplInput;
|
||||
import org.pkl.parser.syntax.StringConstant;
|
||||
import org.pkl.parser.syntax.StringPart;
|
||||
import org.pkl.parser.syntax.Type;
|
||||
import org.pkl.parser.syntax.TypeAlias;
|
||||
import org.pkl.parser.syntax.TypeAnnotation;
|
||||
import org.pkl.parser.syntax.TypeArgumentList;
|
||||
import org.pkl.parser.syntax.TypeParameter;
|
||||
import org.pkl.parser.syntax.TypeParameterList;
|
||||
|
||||
public interface ParserVisitor<Result> {
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.core.parser;
|
||||
package org.pkl.parser;
|
||||
|
||||
public record Span(int charIndex, int length) {
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.core.parser;
|
||||
package org.pkl.parser;
|
||||
|
||||
public enum Token {
|
||||
ABSTRACT,
|
||||
@@ -0,0 +1,4 @@
|
||||
@NonnullByDefault
|
||||
package org.pkl.parser;
|
||||
|
||||
import org.pkl.parser.util.NonnullByDefault;
|
||||
@@ -13,13 +13,13 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.core.parser.syntax;
|
||||
package org.pkl.parser.syntax;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import org.pkl.core.parser.Span;
|
||||
import org.pkl.core.util.Nullable;
|
||||
import org.pkl.parser.Span;
|
||||
import org.pkl.parser.util.Nullable;
|
||||
|
||||
public abstract class AbstractNode implements Node {
|
||||
protected final Span span;
|
||||
@@ -13,12 +13,12 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.core.parser.syntax;
|
||||
package org.pkl.parser.syntax;
|
||||
|
||||
import java.util.List;
|
||||
import org.pkl.core.parser.ParserVisitor;
|
||||
import org.pkl.core.parser.Span;
|
||||
import org.pkl.core.util.Nullable;
|
||||
import org.pkl.parser.ParserVisitor;
|
||||
import org.pkl.parser.Span;
|
||||
import org.pkl.parser.util.Nullable;
|
||||
|
||||
public class Annotation extends AbstractNode {
|
||||
public Annotation(List<Node> nodes, Span span) {
|
||||
@@ -13,12 +13,12 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.core.parser.syntax;
|
||||
package org.pkl.parser.syntax;
|
||||
|
||||
import java.util.List;
|
||||
import org.pkl.core.parser.ParserVisitor;
|
||||
import org.pkl.core.parser.Span;
|
||||
import org.pkl.core.util.Nullable;
|
||||
import org.pkl.parser.ParserVisitor;
|
||||
import org.pkl.parser.Span;
|
||||
import org.pkl.parser.util.Nullable;
|
||||
|
||||
public class ArgumentList extends AbstractNode {
|
||||
|
||||
@@ -13,12 +13,12 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.core.parser.syntax;
|
||||
package org.pkl.parser.syntax;
|
||||
|
||||
import java.util.List;
|
||||
import org.pkl.core.parser.ParserVisitor;
|
||||
import org.pkl.core.parser.Span;
|
||||
import org.pkl.core.util.Nullable;
|
||||
import org.pkl.parser.ParserVisitor;
|
||||
import org.pkl.parser.Span;
|
||||
import org.pkl.parser.util.Nullable;
|
||||
|
||||
public final class Class extends AbstractNode {
|
||||
private final int modifiersOffset;
|
||||
@@ -13,13 +13,13 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.core.parser.syntax;
|
||||
package org.pkl.parser.syntax;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.pkl.core.parser.ParserVisitor;
|
||||
import org.pkl.core.parser.Span;
|
||||
import org.pkl.core.util.Nullable;
|
||||
import org.pkl.parser.ParserVisitor;
|
||||
import org.pkl.parser.Span;
|
||||
import org.pkl.parser.util.Nullable;
|
||||
|
||||
public class ClassBody extends AbstractNode {
|
||||
|
||||
@@ -13,12 +13,12 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.core.parser.syntax;
|
||||
package org.pkl.parser.syntax;
|
||||
|
||||
import java.util.List;
|
||||
import org.pkl.core.parser.ParserVisitor;
|
||||
import org.pkl.core.parser.Span;
|
||||
import org.pkl.core.util.Nullable;
|
||||
import org.pkl.parser.ParserVisitor;
|
||||
import org.pkl.parser.Span;
|
||||
import org.pkl.parser.util.Nullable;
|
||||
|
||||
public class ClassMethod extends AbstractNode {
|
||||
private final int modifiersOffset;
|
||||
@@ -13,12 +13,12 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.core.parser.syntax;
|
||||
package org.pkl.parser.syntax;
|
||||
|
||||
import java.util.List;
|
||||
import org.pkl.core.parser.ParserVisitor;
|
||||
import org.pkl.core.parser.Span;
|
||||
import org.pkl.core.util.Nullable;
|
||||
import org.pkl.parser.ParserVisitor;
|
||||
import org.pkl.parser.Span;
|
||||
import org.pkl.parser.util.Nullable;
|
||||
|
||||
public final class ClassProperty extends AbstractNode {
|
||||
private final int modifiersOffset;
|
||||
@@ -13,12 +13,12 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.core.parser.syntax;
|
||||
package org.pkl.parser.syntax;
|
||||
|
||||
import java.util.List;
|
||||
import org.pkl.core.parser.ParserVisitor;
|
||||
import org.pkl.core.parser.Span;
|
||||
import org.pkl.core.util.Nullable;
|
||||
import org.pkl.parser.ParserVisitor;
|
||||
import org.pkl.parser.Span;
|
||||
import org.pkl.parser.util.Nullable;
|
||||
|
||||
public final class DocComment extends AbstractNode {
|
||||
private final List<Span> spans;
|
||||
@@ -13,15 +13,14 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.core.parser.syntax;
|
||||
package org.pkl.parser.syntax;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import org.pkl.core.PklBugException;
|
||||
import org.pkl.core.parser.ParserVisitor;
|
||||
import org.pkl.core.parser.Span;
|
||||
import org.pkl.core.util.Nullable;
|
||||
import org.pkl.parser.ParserVisitor;
|
||||
import org.pkl.parser.Span;
|
||||
import org.pkl.parser.util.Nullable;
|
||||
|
||||
public abstract sealed class Expr extends AbstractNode {
|
||||
|
||||
@@ -681,7 +680,7 @@ public abstract sealed class Expr extends AbstractNode {
|
||||
@Override
|
||||
public <T> T accept(ParserVisitor<? extends T> visitor) {
|
||||
// should never be called
|
||||
throw PklBugException.unreachableCode();
|
||||
throw new RuntimeException("Unreacheable code");
|
||||
}
|
||||
|
||||
public Operator getOp() {
|
||||
@@ -721,7 +720,7 @@ public abstract sealed class Expr extends AbstractNode {
|
||||
@Override
|
||||
public <T> T accept(ParserVisitor<? extends T> visitor) {
|
||||
// should never be called
|
||||
throw PklBugException.unreachableCode();
|
||||
throw new RuntimeException("Unreacheable code");
|
||||
}
|
||||
|
||||
public Type getType() {
|
||||
@@ -13,13 +13,13 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.core.parser.syntax;
|
||||
package org.pkl.parser.syntax;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import org.pkl.core.parser.ParserVisitor;
|
||||
import org.pkl.core.parser.Span;
|
||||
import org.pkl.core.util.Nullable;
|
||||
import org.pkl.parser.ParserVisitor;
|
||||
import org.pkl.parser.Span;
|
||||
import org.pkl.parser.util.Nullable;
|
||||
|
||||
public class ExtendsOrAmendsClause extends AbstractNode {
|
||||
private final Type type;
|
||||
@@ -13,11 +13,11 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.core.parser.syntax;
|
||||
package org.pkl.parser.syntax;
|
||||
|
||||
import java.util.Objects;
|
||||
import org.pkl.core.parser.ParserVisitor;
|
||||
import org.pkl.core.parser.Span;
|
||||
import org.pkl.parser.ParserVisitor;
|
||||
import org.pkl.parser.Span;
|
||||
|
||||
public final class Identifier extends AbstractNode {
|
||||
private final String value;
|
||||
@@ -13,13 +13,13 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.core.parser.syntax;
|
||||
package org.pkl.parser.syntax;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
import org.pkl.core.parser.ParserVisitor;
|
||||
import org.pkl.core.parser.Span;
|
||||
import org.pkl.core.util.Nullable;
|
||||
import org.pkl.parser.ParserVisitor;
|
||||
import org.pkl.parser.Span;
|
||||
import org.pkl.parser.util.Nullable;
|
||||
|
||||
public final class ImportClause extends AbstractNode {
|
||||
private final boolean isGlob;
|
||||
@@ -13,10 +13,10 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.core.parser.syntax;
|
||||
package org.pkl.parser.syntax;
|
||||
|
||||
import org.pkl.core.parser.ParserVisitor;
|
||||
import org.pkl.core.parser.Span;
|
||||
import org.pkl.parser.ParserVisitor;
|
||||
import org.pkl.parser.Span;
|
||||
|
||||
public class Keyword extends AbstractNode {
|
||||
|
||||
@@ -13,11 +13,11 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.core.parser.syntax;
|
||||
package org.pkl.parser.syntax;
|
||||
|
||||
import java.util.Objects;
|
||||
import org.pkl.core.parser.ParserVisitor;
|
||||
import org.pkl.core.parser.Span;
|
||||
import org.pkl.parser.ParserVisitor;
|
||||
import org.pkl.parser.Span;
|
||||
|
||||
public final class Modifier extends AbstractNode {
|
||||
private final ModifierValue value;
|
||||
@@ -13,13 +13,13 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.core.parser.syntax;
|
||||
package org.pkl.parser.syntax;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.pkl.core.parser.ParserVisitor;
|
||||
import org.pkl.core.parser.Span;
|
||||
import org.pkl.core.util.Nullable;
|
||||
import org.pkl.parser.ParserVisitor;
|
||||
import org.pkl.parser.Span;
|
||||
import org.pkl.parser.util.Nullable;
|
||||
|
||||
public final class Module extends AbstractNode {
|
||||
public Module(List<Node> nodes, Span span) {
|
||||
@@ -52,8 +52,8 @@ public final class Module extends AbstractNode {
|
||||
return res;
|
||||
}
|
||||
|
||||
public List<Class> getClasses() {
|
||||
var res = new ArrayList<Class>();
|
||||
public List<org.pkl.parser.syntax.Class> getClasses() {
|
||||
var res = new ArrayList<org.pkl.parser.syntax.Class>();
|
||||
assert children != null;
|
||||
for (var child : children) {
|
||||
if (child instanceof Class clazz) {
|
||||
@@ -13,12 +13,12 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.core.parser.syntax;
|
||||
package org.pkl.parser.syntax;
|
||||
|
||||
import java.util.List;
|
||||
import org.pkl.core.parser.ParserVisitor;
|
||||
import org.pkl.core.parser.Span;
|
||||
import org.pkl.core.util.Nullable;
|
||||
import org.pkl.parser.ParserVisitor;
|
||||
import org.pkl.parser.Span;
|
||||
import org.pkl.parser.util.Nullable;
|
||||
|
||||
public final class ModuleDecl extends AbstractNode {
|
||||
private final int modifiersOffset;
|
||||
@@ -13,12 +13,12 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.core.parser.syntax;
|
||||
package org.pkl.parser.syntax;
|
||||
|
||||
import java.util.List;
|
||||
import org.pkl.core.parser.ParserVisitor;
|
||||
import org.pkl.core.parser.Span;
|
||||
import org.pkl.core.util.Nullable;
|
||||
import org.pkl.parser.ParserVisitor;
|
||||
import org.pkl.parser.Span;
|
||||
import org.pkl.parser.util.Nullable;
|
||||
|
||||
public interface Node {
|
||||
Span span();
|
||||
@@ -13,11 +13,11 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.core.parser.syntax;
|
||||
package org.pkl.parser.syntax;
|
||||
|
||||
import java.util.List;
|
||||
import org.pkl.core.parser.ParserVisitor;
|
||||
import org.pkl.core.parser.Span;
|
||||
import org.pkl.parser.ParserVisitor;
|
||||
import org.pkl.parser.Span;
|
||||
|
||||
public final class ObjectBody extends AbstractNode {
|
||||
private final int membersOffset;
|
||||
@@ -13,14 +13,14 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.core.parser.syntax;
|
||||
package org.pkl.parser.syntax;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import org.pkl.core.parser.ParserVisitor;
|
||||
import org.pkl.core.parser.Span;
|
||||
import org.pkl.core.util.Nullable;
|
||||
import org.pkl.parser.ParserVisitor;
|
||||
import org.pkl.parser.Span;
|
||||
import org.pkl.parser.util.Nullable;
|
||||
|
||||
public abstract sealed class ObjectMember extends AbstractNode {
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.core.parser.syntax;
|
||||
package org.pkl.parser.syntax;
|
||||
|
||||
public enum Operator {
|
||||
POW,
|
||||
@@ -13,13 +13,13 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.core.parser.syntax;
|
||||
package org.pkl.parser.syntax;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import org.pkl.core.parser.ParserVisitor;
|
||||
import org.pkl.core.parser.Span;
|
||||
import org.pkl.core.util.Nullable;
|
||||
import org.pkl.parser.ParserVisitor;
|
||||
import org.pkl.parser.Span;
|
||||
import org.pkl.parser.util.Nullable;
|
||||
|
||||
public abstract sealed class Parameter extends AbstractNode {
|
||||
|
||||
@@ -13,12 +13,12 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.core.parser.syntax;
|
||||
package org.pkl.parser.syntax;
|
||||
|
||||
import java.util.List;
|
||||
import org.pkl.core.parser.ParserVisitor;
|
||||
import org.pkl.core.parser.Span;
|
||||
import org.pkl.core.util.Nullable;
|
||||
import org.pkl.parser.ParserVisitor;
|
||||
import org.pkl.parser.Span;
|
||||
import org.pkl.parser.util.Nullable;
|
||||
|
||||
public class ParameterList extends AbstractNode {
|
||||
public ParameterList(List<Parameter> parameters, Span span) {
|
||||
@@ -13,11 +13,11 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.core.parser.syntax;
|
||||
package org.pkl.parser.syntax;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import org.pkl.core.parser.ParserVisitor;
|
||||
import org.pkl.parser.ParserVisitor;
|
||||
|
||||
public final class QualifiedIdentifier extends AbstractNode {
|
||||
public QualifiedIdentifier(List<Identifier> identifiers) {
|
||||
@@ -13,12 +13,12 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.core.parser.syntax;
|
||||
package org.pkl.parser.syntax;
|
||||
|
||||
import java.util.List;
|
||||
import org.pkl.core.parser.ParserVisitor;
|
||||
import org.pkl.core.parser.Span;
|
||||
import org.pkl.core.util.Nullable;
|
||||
import org.pkl.parser.ParserVisitor;
|
||||
import org.pkl.parser.Span;
|
||||
import org.pkl.parser.util.Nullable;
|
||||
|
||||
public class ReplInput extends AbstractNode {
|
||||
public ReplInput(List<Node> nodes, Span span) {
|
||||
@@ -13,12 +13,12 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.core.parser.syntax;
|
||||
package org.pkl.parser.syntax;
|
||||
|
||||
import java.util.Objects;
|
||||
import org.pkl.core.parser.ParserVisitor;
|
||||
import org.pkl.core.parser.Span;
|
||||
import org.pkl.core.util.Nullable;
|
||||
import org.pkl.parser.ParserVisitor;
|
||||
import org.pkl.parser.Span;
|
||||
import org.pkl.parser.util.Nullable;
|
||||
|
||||
public class StringConstant extends AbstractNode {
|
||||
private final String string;
|
||||
@@ -13,13 +13,13 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.core.parser.syntax;
|
||||
package org.pkl.parser.syntax;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import org.pkl.core.parser.ParserVisitor;
|
||||
import org.pkl.core.parser.Span;
|
||||
import org.pkl.core.util.Nullable;
|
||||
import org.pkl.parser.ParserVisitor;
|
||||
import org.pkl.parser.Span;
|
||||
import org.pkl.parser.util.Nullable;
|
||||
|
||||
public abstract sealed class StringPart extends AbstractNode {
|
||||
|
||||
@@ -13,14 +13,14 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.core.parser.syntax;
|
||||
package org.pkl.parser.syntax;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import org.pkl.core.parser.ParserVisitor;
|
||||
import org.pkl.core.parser.Span;
|
||||
import org.pkl.core.util.Nullable;
|
||||
import org.pkl.parser.ParserVisitor;
|
||||
import org.pkl.parser.Span;
|
||||
import org.pkl.parser.util.Nullable;
|
||||
|
||||
public abstract sealed class Type extends AbstractNode {
|
||||
|
||||
@@ -13,12 +13,12 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.core.parser.syntax;
|
||||
package org.pkl.parser.syntax;
|
||||
|
||||
import java.util.List;
|
||||
import org.pkl.core.parser.ParserVisitor;
|
||||
import org.pkl.core.parser.Span;
|
||||
import org.pkl.core.util.Nullable;
|
||||
import org.pkl.parser.ParserVisitor;
|
||||
import org.pkl.parser.Span;
|
||||
import org.pkl.parser.util.Nullable;
|
||||
|
||||
public final class TypeAlias extends AbstractNode {
|
||||
private final int modifiersOffset;
|
||||
@@ -13,12 +13,12 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.core.parser.syntax;
|
||||
package org.pkl.parser.syntax;
|
||||
|
||||
import java.util.List;
|
||||
import org.pkl.core.parser.ParserVisitor;
|
||||
import org.pkl.core.parser.Span;
|
||||
import org.pkl.core.util.Nullable;
|
||||
import org.pkl.parser.ParserVisitor;
|
||||
import org.pkl.parser.Span;
|
||||
import org.pkl.parser.util.Nullable;
|
||||
|
||||
public class TypeAnnotation extends AbstractNode {
|
||||
public TypeAnnotation(Type type, Span span) {
|
||||
@@ -13,11 +13,11 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.core.parser.syntax;
|
||||
package org.pkl.parser.syntax;
|
||||
|
||||
import java.util.List;
|
||||
import org.pkl.core.parser.ParserVisitor;
|
||||
import org.pkl.core.parser.Span;
|
||||
import org.pkl.parser.ParserVisitor;
|
||||
import org.pkl.parser.Span;
|
||||
|
||||
public class TypeArgumentList extends AbstractNode {
|
||||
|
||||
@@ -13,13 +13,13 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.core.parser.syntax;
|
||||
package org.pkl.parser.syntax;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import org.pkl.core.parser.ParserVisitor;
|
||||
import org.pkl.core.parser.Span;
|
||||
import org.pkl.core.util.Nullable;
|
||||
import org.pkl.parser.ParserVisitor;
|
||||
import org.pkl.parser.Span;
|
||||
import org.pkl.parser.util.Nullable;
|
||||
|
||||
public final class TypeParameter extends AbstractNode {
|
||||
private final @Nullable Variance variance;
|
||||
@@ -13,12 +13,12 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.core.parser.syntax;
|
||||
package org.pkl.parser.syntax;
|
||||
|
||||
import java.util.List;
|
||||
import org.pkl.core.parser.ParserVisitor;
|
||||
import org.pkl.core.parser.Span;
|
||||
import org.pkl.core.util.Nullable;
|
||||
import org.pkl.parser.ParserVisitor;
|
||||
import org.pkl.parser.Span;
|
||||
import org.pkl.parser.util.Nullable;
|
||||
|
||||
public class TypeParameterList extends AbstractNode {
|
||||
public TypeParameterList(List<TypeParameter> parameters, Span span) {
|
||||
@@ -0,0 +1,4 @@
|
||||
@NonnullByDefault
|
||||
package org.pkl.parser.syntax;
|
||||
|
||||
import org.pkl.parser.util.NonnullByDefault;
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright © 2025 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.parser.util;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Locale;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public final class ErrorMessages {
|
||||
private ErrorMessages() {}
|
||||
|
||||
public static String create(String messageName, Object... args) {
|
||||
var locale = Locale.getDefault();
|
||||
var errorMessage =
|
||||
ResourceBundle.getBundle("org.pkl.parser.errorMessages", locale).getString(messageName);
|
||||
|
||||
// only format if `errorMessage` is a format string
|
||||
if (args.length == 0) return errorMessage;
|
||||
|
||||
var formatter = new MessageFormat(errorMessage, locale);
|
||||
return formatter.format(args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright © 2025 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.parser.util;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import javax.annotation.meta.TypeQualifierDefault;
|
||||
|
||||
/**
|
||||
* Indicates that method return types and method parameters in the annotated package are Nonnull
|
||||
* unless explicitly annotated with {@link Nullable}.
|
||||
*
|
||||
* <p>This annotation is a generalization of {@link javax.annotation.ParametersAreNonnullByDefault}.
|
||||
* All Pkl packages containing Java code should carry this annotation.
|
||||
*
|
||||
* <p>Ideally, this default would apply to every {@link ElementType#TYPE_USE}, but I haven't been
|
||||
* able to make this work reasonably in <a
|
||||
* href="https://youtrack.jetbrains.com/issue/IDEA-278618">IntelliJ</a>.
|
||||
*/
|
||||
@Documented
|
||||
@TypeQualifierDefault({ElementType.METHOD, ElementType.PARAMETER, ElementType.TYPE_PARAMETER})
|
||||
@javax.annotation.Nonnull
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.PACKAGE)
|
||||
public @interface NonnullByDefault {}
|
||||
38
pkl-parser/src/main/java/org/pkl/parser/util/Nullable.java
Normal file
38
pkl-parser/src/main/java/org/pkl/parser/util/Nullable.java
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.parser.util;
|
||||
|
||||
import static javax.annotation.meta.When.MAYBE;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import javax.annotation.meta.TypeQualifierNickname;
|
||||
|
||||
@Target({
|
||||
ElementType.TYPE_PARAMETER,
|
||||
ElementType.TYPE_USE,
|
||||
ElementType.PARAMETER,
|
||||
ElementType.FIELD,
|
||||
ElementType.METHOD
|
||||
})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@javax.annotation.Nonnull(when = MAYBE)
|
||||
@TypeQualifierNickname
|
||||
public @interface Nullable {}
|
||||
@@ -0,0 +1,97 @@
|
||||
unexpectedCharacter=\
|
||||
Unexpected character `{0}`. Did you mean `{1}`?
|
||||
|
||||
unexpectedCharacter3=\
|
||||
Unexpected character `{0}`. Did you mean `{1}`, `{2}` or `{3}`?
|
||||
|
||||
unexpectedToken=\
|
||||
Unexpected token `{0}`. Expected `{1}`.
|
||||
|
||||
unexpectedToken2=\
|
||||
Unexpected token `{0}`. Expected `{1}` or `{2}`.
|
||||
|
||||
unexpectedTokenForExpression=\
|
||||
Unexpected token `{0}`.
|
||||
|
||||
unexpectedTokenForType=\
|
||||
Unexpected token `{0}`. Expected a type.
|
||||
|
||||
unexpectedTokenForType2=\
|
||||
Unexpected token `{0}`. Expected a type or `{1}`.
|
||||
|
||||
unexpectedCurlyProbablyAmendsExpression=\
|
||||
Unexpected token: `'{'`.\n\
|
||||
\n\
|
||||
If you meant to write an amends expression, wrap the parent in parentheses. Try: `({0}) '{' ... '}'`
|
||||
|
||||
unexpectedEndOfFile=\
|
||||
Unexpected end of file.
|
||||
|
||||
invalidCharacter=\
|
||||
Invalid identifier `{0}`.
|
||||
|
||||
invalidTopLevelToken=\
|
||||
Invalid token at position. Expected a class, typealias, method, or property.
|
||||
|
||||
invalidProperty=\
|
||||
Invalid property definition. Expected a type annotation, `=` or `{`.
|
||||
|
||||
invalidSeparatorPosition=\
|
||||
Unexpected separator character.\n\
|
||||
\n\
|
||||
The separator character (`_`) cannot follow `0x`, `0b`, `.`, `e`, or 'E' in a number literal.
|
||||
|
||||
invalidCharacterEscapeSequence=\
|
||||
Invalid character escape sequence `{0}`.\n\
|
||||
\n\
|
||||
Valid character escape sequences are: {1}n {1}r {1}t {1}" {1}\\
|
||||
|
||||
invalidUnicodeEscapeSequence=\
|
||||
Invalid Unicode escape sequence `{0}`.\n\
|
||||
\n\
|
||||
Valid Unicode escape sequences are {1}'{'0'}' to {1}'{'10FFFF'}' (1-6 hexadecimal characters).
|
||||
|
||||
missingDelimiter=\
|
||||
Missing `{0}` delimiter.
|
||||
|
||||
unterminatedUnicodeEscapeSequence=\
|
||||
Unterminated Unicode escape sequence `{0}`.\n\
|
||||
\n\
|
||||
Unicode escape sequences must end with `}`.
|
||||
|
||||
keywordNotAllowedHere=\
|
||||
Keyword `{0}` is not allowed here.\n\
|
||||
\n\
|
||||
If you must use this name as identifier, enclose it in backticks.
|
||||
|
||||
typeAnnotationInAmends=\
|
||||
Properties with type annotations cannot have object bodies.\n\
|
||||
\n\
|
||||
To define both a type annotation and an object body, try using assignment instead.\n\
|
||||
For example: `obj: Bird = new { ... }`.
|
||||
|
||||
stringContentMustBeginOnNewLine=\
|
||||
The content of a multi-line string must begin on a new line.
|
||||
|
||||
stringIndentationMustMatchLastLine=\
|
||||
Line must match or exceed indentation of the String's last line.
|
||||
|
||||
closingStringDelimiterMustBeginOnNewLine=\
|
||||
The closing delimiter of a multi-line string must begin on a new line.
|
||||
|
||||
interpolationInConstant=\
|
||||
String constant cannot have interpolated values.
|
||||
|
||||
multipleUnionDefaults=\
|
||||
A type union cannot have more than one default type.
|
||||
|
||||
notAUnion=\
|
||||
Only type unions can have a default marker (*).
|
||||
|
||||
wrongHeaders=\
|
||||
{0} cannot have doc comments, annotations or modifiers.
|
||||
|
||||
danglingDocComment=\
|
||||
Dangling documentation comment.\n\
|
||||
\n\
|
||||
Documentation comments must be attached to modules, classes, typealiases, methods, or properties.
|
||||
@@ -16,7 +16,7 @@
|
||||
lexer grammar PklLexer;
|
||||
|
||||
@header {
|
||||
package org.pkl.core.parser.antlr;
|
||||
package org.pkl.parser.antlr;
|
||||
}
|
||||
|
||||
@members {
|
||||
@@ -16,7 +16,7 @@
|
||||
parser grammar PklParser;
|
||||
|
||||
@header {
|
||||
package org.pkl.core.parser.antlr;
|
||||
package org.pkl.parser.antlr;
|
||||
}
|
||||
|
||||
@members {
|
||||
@@ -13,11 +13,11 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.core.parser
|
||||
package org.pkl.parser
|
||||
|
||||
import org.antlr.v4.runtime.ParserRuleContext
|
||||
import org.pkl.core.parser.antlr.PklLexer
|
||||
import org.pkl.core.parser.antlr.PklParser.*
|
||||
import org.pkl.parser.antlr.PklLexer
|
||||
import org.pkl.parser.antlr.PklParser.*
|
||||
|
||||
@Suppress("MemberVisibilityCanBePrivate")
|
||||
class ANTLRSexpRenderer {
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.core.parser
|
||||
package org.pkl.parser
|
||||
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.jupiter.api.Test
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.core.parser
|
||||
package org.pkl.parser
|
||||
|
||||
import java.nio.file.Path
|
||||
import kotlin.io.path.Path
|
||||
@@ -60,7 +60,7 @@ class ParserComparisonTest : ParserComparisonTestInterface {
|
||||
}
|
||||
|
||||
override fun getSnippets(): List<Path> {
|
||||
return Path("src/test/files/LanguageSnippetTests/input")
|
||||
return Path("../pkl-core/src/test/files/LanguageSnippetTests/input")
|
||||
.walk()
|
||||
.filter { path ->
|
||||
val pathStr = path.toString().replace("\\", "/")
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.core.parser
|
||||
package org.pkl.parser
|
||||
|
||||
import java.nio.file.Path
|
||||
import kotlin.io.path.pathString
|
||||
@@ -25,8 +25,8 @@ import org.assertj.core.api.SoftAssertions
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.parallel.Execution
|
||||
import org.junit.jupiter.api.parallel.ExecutionMode
|
||||
import org.pkl.core.parser.antlr.PklLexer
|
||||
import org.pkl.core.parser.antlr.PklParser
|
||||
import org.pkl.parser.antlr.PklLexer
|
||||
import org.pkl.parser.antlr.PklParser
|
||||
|
||||
@Execution(ExecutionMode.CONCURRENT)
|
||||
interface ParserComparisonTestInterface {
|
||||
@@ -13,29 +13,29 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.core.parser
|
||||
package org.pkl.parser
|
||||
|
||||
import org.pkl.core.parser.syntax.*
|
||||
import org.pkl.core.parser.syntax.Annotation
|
||||
import org.pkl.core.parser.syntax.Expr.*
|
||||
import org.pkl.core.parser.syntax.Expr.ModuleExpr
|
||||
import org.pkl.core.parser.syntax.ObjectMember.*
|
||||
import org.pkl.core.parser.syntax.Parameter.TypedIdentifier
|
||||
import org.pkl.core.parser.syntax.Type.*
|
||||
import org.pkl.parser.syntax.*
|
||||
import org.pkl.parser.syntax.Annotation
|
||||
import org.pkl.parser.syntax.Expr.*
|
||||
import org.pkl.parser.syntax.Expr.ModuleExpr
|
||||
import org.pkl.parser.syntax.ObjectMember.*
|
||||
import org.pkl.parser.syntax.Parameter.TypedIdentifier
|
||||
import org.pkl.parser.syntax.Type.*
|
||||
|
||||
@Suppress("MemberVisibilityCanBePrivate")
|
||||
class SexpRenderer {
|
||||
private var tab = ""
|
||||
private var buf = StringBuilder()
|
||||
|
||||
fun render(mod: org.pkl.core.parser.syntax.Module): String {
|
||||
fun render(mod: org.pkl.parser.syntax.Module): String {
|
||||
renderModule(mod)
|
||||
val res = buf.toString()
|
||||
reset()
|
||||
return res
|
||||
}
|
||||
|
||||
fun renderModule(mod: org.pkl.core.parser.syntax.Module) {
|
||||
fun renderModule(mod: org.pkl.parser.syntax.Module) {
|
||||
buf.append(tab)
|
||||
buf.append("(module")
|
||||
val oldTab = increaseTab()
|
||||
@@ -1055,7 +1055,7 @@ class SexpRenderer {
|
||||
}
|
||||
|
||||
companion object {
|
||||
private fun sortModuleEntries(mod: org.pkl.core.parser.syntax.Module): List<Node> {
|
||||
private fun sortModuleEntries(mod: org.pkl.parser.syntax.Module): List<Node> {
|
||||
val res = mutableListOf<Node>()
|
||||
res += mod.classes
|
||||
res += mod.typeAliases
|
||||
@@ -13,53 +13,53 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.core.parser
|
||||
package org.pkl.parser
|
||||
|
||||
import org.antlr.v4.runtime.ParserRuleContext
|
||||
import org.antlr.v4.runtime.tree.TerminalNode
|
||||
import org.assertj.core.api.SoftAssertions
|
||||
import org.pkl.core.parser.antlr.PklParser.*
|
||||
import org.pkl.core.parser.syntax.*
|
||||
import org.pkl.core.parser.syntax.Annotation
|
||||
import org.pkl.core.parser.syntax.Expr.AmendsExpr
|
||||
import org.pkl.core.parser.syntax.Expr.BinaryOperatorExpr
|
||||
import org.pkl.core.parser.syntax.Expr.FunctionLiteralExpr
|
||||
import org.pkl.core.parser.syntax.Expr.IfExpr
|
||||
import org.pkl.core.parser.syntax.Expr.ImportExpr
|
||||
import org.pkl.core.parser.syntax.Expr.LetExpr
|
||||
import org.pkl.core.parser.syntax.Expr.LogicalNotExpr
|
||||
import org.pkl.core.parser.syntax.Expr.MultiLineStringLiteralExpr
|
||||
import org.pkl.core.parser.syntax.Expr.NewExpr
|
||||
import org.pkl.core.parser.syntax.Expr.NonNullExpr
|
||||
import org.pkl.core.parser.syntax.Expr.ParenthesizedExpr
|
||||
import org.pkl.core.parser.syntax.Expr.QualifiedAccessExpr
|
||||
import org.pkl.core.parser.syntax.Expr.ReadExpr
|
||||
import org.pkl.core.parser.syntax.Expr.SingleLineStringLiteralExpr
|
||||
import org.pkl.core.parser.syntax.Expr.SubscriptExpr
|
||||
import org.pkl.core.parser.syntax.Expr.SuperAccessExpr
|
||||
import org.pkl.core.parser.syntax.Expr.SuperSubscriptExpr
|
||||
import org.pkl.core.parser.syntax.Expr.ThrowExpr
|
||||
import org.pkl.core.parser.syntax.Expr.TraceExpr
|
||||
import org.pkl.core.parser.syntax.Expr.TypeCastExpr
|
||||
import org.pkl.core.parser.syntax.Expr.TypeCheckExpr
|
||||
import org.pkl.core.parser.syntax.Expr.UnaryMinusExpr
|
||||
import org.pkl.core.parser.syntax.Expr.UnqualifiedAccessExpr
|
||||
import org.pkl.core.parser.syntax.ObjectMember.ForGenerator
|
||||
import org.pkl.core.parser.syntax.ObjectMember.MemberPredicate
|
||||
import org.pkl.core.parser.syntax.ObjectMember.ObjectElement
|
||||
import org.pkl.core.parser.syntax.ObjectMember.ObjectEntry
|
||||
import org.pkl.core.parser.syntax.ObjectMember.ObjectMethod
|
||||
import org.pkl.core.parser.syntax.ObjectMember.ObjectProperty
|
||||
import org.pkl.core.parser.syntax.ObjectMember.ObjectSpread
|
||||
import org.pkl.core.parser.syntax.ObjectMember.WhenGenerator
|
||||
import org.pkl.core.parser.syntax.Parameter.TypedIdentifier
|
||||
import org.pkl.core.parser.syntax.Type.ConstrainedType
|
||||
import org.pkl.core.parser.syntax.Type.DeclaredType
|
||||
import org.pkl.core.parser.syntax.Type.FunctionType
|
||||
import org.pkl.core.parser.syntax.Type.NullableType
|
||||
import org.pkl.core.parser.syntax.Type.ParenthesizedType
|
||||
import org.pkl.core.parser.syntax.Type.StringConstantType
|
||||
import org.pkl.core.parser.syntax.Type.UnionType
|
||||
import org.pkl.parser.antlr.PklParser.*
|
||||
import org.pkl.parser.syntax.*
|
||||
import org.pkl.parser.syntax.Annotation
|
||||
import org.pkl.parser.syntax.Expr.AmendsExpr
|
||||
import org.pkl.parser.syntax.Expr.BinaryOperatorExpr
|
||||
import org.pkl.parser.syntax.Expr.FunctionLiteralExpr
|
||||
import org.pkl.parser.syntax.Expr.IfExpr
|
||||
import org.pkl.parser.syntax.Expr.ImportExpr
|
||||
import org.pkl.parser.syntax.Expr.LetExpr
|
||||
import org.pkl.parser.syntax.Expr.LogicalNotExpr
|
||||
import org.pkl.parser.syntax.Expr.MultiLineStringLiteralExpr
|
||||
import org.pkl.parser.syntax.Expr.NewExpr
|
||||
import org.pkl.parser.syntax.Expr.NonNullExpr
|
||||
import org.pkl.parser.syntax.Expr.ParenthesizedExpr
|
||||
import org.pkl.parser.syntax.Expr.QualifiedAccessExpr
|
||||
import org.pkl.parser.syntax.Expr.ReadExpr
|
||||
import org.pkl.parser.syntax.Expr.SingleLineStringLiteralExpr
|
||||
import org.pkl.parser.syntax.Expr.SubscriptExpr
|
||||
import org.pkl.parser.syntax.Expr.SuperAccessExpr
|
||||
import org.pkl.parser.syntax.Expr.SuperSubscriptExpr
|
||||
import org.pkl.parser.syntax.Expr.ThrowExpr
|
||||
import org.pkl.parser.syntax.Expr.TraceExpr
|
||||
import org.pkl.parser.syntax.Expr.TypeCastExpr
|
||||
import org.pkl.parser.syntax.Expr.TypeCheckExpr
|
||||
import org.pkl.parser.syntax.Expr.UnaryMinusExpr
|
||||
import org.pkl.parser.syntax.Expr.UnqualifiedAccessExpr
|
||||
import org.pkl.parser.syntax.ObjectMember.ForGenerator
|
||||
import org.pkl.parser.syntax.ObjectMember.MemberPredicate
|
||||
import org.pkl.parser.syntax.ObjectMember.ObjectElement
|
||||
import org.pkl.parser.syntax.ObjectMember.ObjectEntry
|
||||
import org.pkl.parser.syntax.ObjectMember.ObjectMethod
|
||||
import org.pkl.parser.syntax.ObjectMember.ObjectProperty
|
||||
import org.pkl.parser.syntax.ObjectMember.ObjectSpread
|
||||
import org.pkl.parser.syntax.ObjectMember.WhenGenerator
|
||||
import org.pkl.parser.syntax.Parameter.TypedIdentifier
|
||||
import org.pkl.parser.syntax.Type.ConstrainedType
|
||||
import org.pkl.parser.syntax.Type.DeclaredType
|
||||
import org.pkl.parser.syntax.Type.FunctionType
|
||||
import org.pkl.parser.syntax.Type.NullableType
|
||||
import org.pkl.parser.syntax.Type.ParenthesizedType
|
||||
import org.pkl.parser.syntax.Type.StringConstantType
|
||||
import org.pkl.parser.syntax.Type.UnionType
|
||||
|
||||
class SpanComparison(val path: String, private val softly: SoftAssertions) {
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.core.parser
|
||||
package org.pkl.parser
|
||||
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.jupiter.api.Test
|
||||
@@ -43,6 +43,8 @@ include("pkl-executor")
|
||||
|
||||
include("pkl-gradle")
|
||||
|
||||
include("pkl-parser")
|
||||
|
||||
include("pkl-server")
|
||||
|
||||
include("pkl-tools")
|
||||
|
||||
Reference in New Issue
Block a user