20 Commits

Author SHA1 Message Date
Simon Rüegg
7699f297d8 Allow formatting multiple files/directories
This makes it easier to work with tools which return a list of file to
format, e.g. to only handle files which have changed in a PR.
2025-09-19 13:16:16 +02:00
Islon Scherer
618c6243c5 Fix bug in format apply (#1211) 2025-09-19 11:28:40 +02:00
Islon Scherer
222741dccd Fix broken test (#1208) 2025-09-17 13:53:15 -07:00
Islon Scherer
fdc501a35c Implement canonical formatter (#1107)
CLI commands also added: `pkl format check` and `pkl format apply`.
2025-09-17 11:12:04 +02:00
Vladimir Matveev
6a06ab7caa Fixed fallback certificates not working in certain classloader setups (#1198)
In the original implementation the `org/pkl/commons/cli/PklCARoots.pem` resource is resolved relatively to the classloader associated with the class returned by `javaClass`. However, since this is an extension method for `HttpClient.Builder`, it means calling `javaClass` on the builder instance, which is actually defined in the system classpath.

Because of this, if the Pkl class is loaded by a different classloader compared to the one which contains JDK classes, which is totally possible in certain scenarios (e.g. with Gradle), then this resource resolution will fail.

The solution is to resolve `javaClass` against `this@CliCommand`, to use the classloader which loaded the jar with the `CliCommand` class to find the CA resource.
2025-09-04 15:49:43 -07:00
Daniel Chao
a66ac0eb35 Refine documentation for class Any (#1194) 2025-09-02 08:19:39 -07:00
Jen Basch
bef0375285 Improve interrupt handling in pkl repl (#1188) 2025-08-29 13:39:49 -07:00
Jen Basch
44cc154501 Prepare 0.29.1 release (#1192)
Co-authored-by: Daniel Chao <dan.chao@apple.com>
2025-08-27 14:33:25 -07:00
Artem Yarmoliuk
af7057b75f Fix shell completion for paths (#1161) 2025-08-26 10:46:54 -07:00
Jen Basch
a8806416b9 Correctly handle EOF after unmatched backtick (#1187) 2025-08-25 14:31:26 -07:00
Jen Basch
b32039a4f1 Add me as a maintainer (#1185) 2025-08-25 13:17:53 -07:00
Daniel Chao
a779316cc2 Update dependencies (#1184)
Bump test dependencies, and also commonmark
2025-08-21 21:32:56 -07:00
Daniel Chao
d9db939bdc Fix missing resources in native pkldoc, and disable test mode (#1175)
This fixes two issues:

1. Test mode is enabled in pkldoc without the ability to turn it off
2. Native pkldoc is missing required resources

This also adds tests for both `jpkldoc` and `pkldoc`.
2025-08-21 06:44:13 -07:00
Jen Basch
ae5f02b285 Allow trailing commas in comma-separated syntax elements (#1137) 2025-08-21 06:43:38 -07:00
Daniel Chao
3f2f0c3a2b Add docs for installing via winget (#1171) 2025-08-11 17:22:30 -07:00
Daniel Chao
7d50aaeec9 Fix escaping in yaml strings (#1165)
The backslash needs to be escaped when rendering double-quoted YAML strings.

In addition, this escapes the following characters:

* next line (0x85)
* nbsp (0xa0)
2025-08-06 07:57:52 -07:00
Daniel Chao
78ba6bf758 Fix download links (#1162)
* Snapshot repo has changed
* Fix a bug where pkl-codegen-java download link points to Sonatype instead of GitHub

Not in the PR: we also need to fix the snapshot download location;
but haven't figured out yet what the correct link is.
2025-07-31 08:43:24 -07:00
Daniel Chao
20e7e251ec Fix encoding for mapping with local members (#1152)
Fixes an issue where local members are included in
the mapping entry count.

Also: avoid re-computing Mapping.length
2025-07-28 10:13:45 -07:00
Islon Scherer
a3cc2f0ea6 Start next dev iteration 2025-07-24 20:06:01 +02:00
Islon Scherer
e12c655f5c Prepare 0.29.0 release 2025-07-24 20:06:01 +02:00
136 changed files with 6396 additions and 458 deletions

View File

@@ -63,6 +63,7 @@
</option>
<option name="IMPORT_LAYOUT_TABLE">
<value>
<package name="" withSubpackages="true" static="false" module="true" />
<package name="" withSubpackages="true" static="true" />
<emptyLine />
<package name="" withSubpackages="true" static="false" />

View File

@@ -8,4 +8,5 @@ See link:CONTRIBUTING.adoc[] for general contribution guidelines.
* https://github.com/bioball[Daniel Chao]
* https://github.com/stackoverflow[Islon Scherer]
* https://github.com/HT154[Jen Basch]
* https://github.com/holzensp[Philip Hölzenspies]

View File

@@ -5,7 +5,7 @@ net.bytebuddy:byte-buddy:1.15.11=jmh,jmhRuntimeClasspath,testCompileClasspath,te
net.sf.jopt-simple:jopt-simple:5.0.4=jmh,jmhCompileClasspath,jmhImplementationDependenciesMetadata,jmhRuntimeClasspath
org.apache.commons:commons-math3:3.6.1=jmh,jmhCompileClasspath,jmhImplementationDependenciesMetadata,jmhRuntimeClasspath
org.apiguardian:apiguardian-api:1.1.2=jmhCompileClasspath,jmhImplementationDependenciesMetadata,testCompileClasspath,testImplementationDependenciesMetadata
org.assertj:assertj-core:3.27.3=jmh,jmhRuntimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.assertj:assertj-core:3.27.4=jmh,jmhRuntimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.graalvm.compiler:compiler:24.1.2=graal
org.graalvm.polyglot:polyglot:24.1.2=jmh,jmhRuntimeClasspath,truffle
org.graalvm.sdk:collections:24.1.2=graal,jmh,jmhRuntimeClasspath,truffle
@@ -35,13 +35,13 @@ org.jetbrains.kotlin:kotlin-stdlib-jdk8:2.0.21=jmh,jmhCompileClasspath,jmhImplem
org.jetbrains.kotlin:kotlin-stdlib:2.0.21=jmh,jmhCompileClasspath,jmhImplementationDependenciesMetadata,jmhRuntimeClasspath,kotlinBuildToolsApiClasspath,kotlinCompilerClasspath,kotlinCompilerPluginClasspathJmh,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinKlibCommonizerClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.4=kotlinBuildToolsApiClasspath,kotlinCompilerClasspath,kotlinKlibCommonizerClasspath
org.jetbrains:annotations:13.0=jmh,jmhCompileClasspath,jmhRuntimeClasspath,kotlinBuildToolsApiClasspath,kotlinCompilerClasspath,kotlinCompilerPluginClasspathJmh,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinKlibCommonizerClasspath,testCompileClasspath,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-api:5.13.3=jmh,jmhCompileClasspath,jmhImplementationDependenciesMetadata,jmhRuntimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-engine:5.13.3=jmh,jmhCompileClasspath,jmhImplementationDependenciesMetadata,jmhRuntimeClasspath,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-params:5.13.3=jmh,jmhCompileClasspath,jmhImplementationDependenciesMetadata,jmhRuntimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-commons:1.13.3=jmh,jmhCompileClasspath,jmhImplementationDependenciesMetadata,jmhRuntimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-engine:1.13.3=jmh,jmhCompileClasspath,jmhImplementationDependenciesMetadata,jmhRuntimeClasspath,testRuntimeClasspath
org.junit.platform:junit-platform-launcher:1.13.3=testRuntimeClasspath
org.junit:junit-bom:5.13.3=jmh,jmhCompileClasspath,jmhImplementationDependenciesMetadata,jmhRuntimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-api:5.13.4=jmh,jmhCompileClasspath,jmhImplementationDependenciesMetadata,jmhRuntimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-engine:5.13.4=jmh,jmhCompileClasspath,jmhImplementationDependenciesMetadata,jmhRuntimeClasspath,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-params:5.13.4=jmh,jmhCompileClasspath,jmhImplementationDependenciesMetadata,jmhRuntimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-commons:1.13.4=jmh,jmhCompileClasspath,jmhImplementationDependenciesMetadata,jmhRuntimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-engine:1.13.4=jmh,jmhCompileClasspath,jmhImplementationDependenciesMetadata,jmhRuntimeClasspath,testRuntimeClasspath
org.junit.platform:junit-platform-launcher:1.13.4=testRuntimeClasspath
org.junit:junit-bom:5.13.4=jmh,jmhCompileClasspath,jmhImplementationDependenciesMetadata,jmhRuntimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.msgpack:msgpack-core:0.9.8=jmh,jmhRuntimeClasspath
org.openjdk.jmh:jmh-core:1.37=jmh,jmhCompileClasspath,jmhImplementationDependenciesMetadata,jmhRuntimeClasspath
org.openjdk.jmh:jmh-generator-asm:1.37=jmh,jmhCompileClasspath,jmhImplementationDependenciesMetadata,jmhRuntimeClasspath

View File

@@ -1,6 +1,6 @@
name: main
title: Main Project
version: 0.29.1
prerelease: false
version: 0.30.0-dev
prerelease: true
nav:
- nav.adoc

View File

@@ -4,7 +4,7 @@
io.leangen.geantyref:geantyref:1.3.16=testRuntimeClasspath
net.bytebuddy:byte-buddy:1.15.11=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath,testImplementationDependenciesMetadata
org.assertj:assertj-core:3.27.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.assertj:assertj-core:3.27.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.graalvm.polyglot:polyglot:24.1.2=testRuntimeClasspath
org.graalvm.sdk:collections:24.1.2=testRuntimeClasspath
org.graalvm.sdk:graal-sdk:24.1.2=testRuntimeClasspath
@@ -32,13 +32,13 @@ org.jetbrains.kotlin:kotlin-stdlib-jdk8:2.0.21=testCompileClasspath,testImplemen
org.jetbrains.kotlin:kotlin-stdlib:2.0.21=kotlinBuildToolsApiClasspath,kotlinCompilerClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinKlibCommonizerClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.4=kotlinBuildToolsApiClasspath,kotlinCompilerClasspath,kotlinKlibCommonizerClasspath
org.jetbrains:annotations:13.0=kotlinBuildToolsApiClasspath,kotlinCompilerClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinKlibCommonizerClasspath,testCompileClasspath,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-api:5.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-engine:5.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-params:5.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-commons:1.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-engine:1.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-launcher:1.13.3=testRuntimeClasspath
org.junit:junit-bom:5.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-api:5.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-engine:5.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-params:5.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-commons:1.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-engine:1.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-launcher:1.13.4=testRuntimeClasspath
org.junit:junit-bom:5.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.msgpack:msgpack-core:0.9.8=testRuntimeClasspath
org.opentest4j:opentest4j:1.3.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.organicdesign:Paguro:3.10.3=testRuntimeClasspath

View File

@@ -3,10 +3,10 @@
// the following attributes must be updated immediately before a release
// pkl version corresponding to current git commit without -dev suffix or git hash
:pkl-version-no-suffix: 0.29.1
:pkl-version-no-suffix: 0.30.0
// tells whether pkl version corresponding to current git commit
// is a release version (:is-release-version: '') or dev version (:!is-release-version:)
:is-release-version: ''
:!is-release-version:
// the remaining attributes do not need to be updated regularly

View File

@@ -733,6 +733,33 @@ pkl shell-completion bash
pkl shell-completion zsh
----
[[command-format-check]]
=== `pkl format check`
*Synopsis*: `pkl format check <file-or-dir-path>`
This command checks for format violations on the given file or directory and print their names to stdout. +
It returns a non-zero status code in case violations are found.
If the path is a directory, recursively looks for files with a `.pkl` extension, or files named `PklProject`.
[[command-format-apply]]
=== `pkl format apply`
*Synopsis*: `pkl format apply [<options>] <file-or-dir-path>`
This command formats the given files overwriting them.
If the path is a directory, recursively looks for files with a `.pkl` extension, or files named `PklProject`.
==== Options
.-s, --silent
[%collapsible]
====
Do not write the name of wrongly formatted files to stdout.
====
[[common-options]]
=== Common options

View File

@@ -0,0 +1,51 @@
= Pkl 0.30 Release Notes
:version: 0.30
:version-minor: 0.30.0
:release-date: TBD
link:ROOT:partial$component-attributes.adoc[role=include]
Pkl {version} was released on {release-date}. +
[.small]#The latest bugfix release is {version-minor}. (xref:changelog.adoc[All Versions])#
The next release (0.XX) is scheduled for ???..
To see what's coming in the future, follow the {uri-pkl-roadmap}[Pkl Roadmap].
Please send feedback and questions to https://github.com/apple/pkl/discussions[GitHub Discussions], or submit an issue on https://github.com/apple/pkl/issues/new[Github]. +
[small]#Pkl is hosted on https://github.com/apple/pkl[GitHub].
To get started, follow xref:pkl-cli:index.adoc#installation[Installation].#
== Highlights [small]#💖#
News you don't want to miss.
=== XXX
== Noteworthy [small]#🎶#
Ready when you need them.
=== XXX
== Breaking Changes [small]#💔#
Things to watch out for when upgrading.
=== XXX
== Miscellaneous [small]#🐸#
* XXX
== Bugs fixed [small]#🐜#
The following bugs have been fixed.
* XXX (https://github.com/apple/pkl/issues/XXX[XXX])
== Contributors [small]#🙏#
We would like to thank the contributors to this release (in alphabetical order):
* XXX

View File

@@ -1,6 +1,9 @@
= Changelog
include::ROOT:partial$component-attributes.adoc[]
[[release-0.30.0]]
== 0.30.0 (TBD)
[[release-0.29.1]]
== 0.29.1 (2025-08-27)

View File

@@ -2,6 +2,7 @@
The Pkl team aims to release a new version of Pkl in February, June, and October of each year.
* xref:0.30.adoc[0.30 Release Notes]
* xref:0.29.adoc[0.29 Release Notes]
* xref:0.28.adoc[0.28 Release Notes]
* xref:0.27.adoc[0.27 Release Notes]

View File

@@ -41,6 +41,7 @@
* xref:ROOT:evolution-and-roadmap.adoc[Evolution and Roadmap]
* xref:release-notes:index.adoc[Release Notes]
** xref:release-notes:0.30.adoc[0.30 Release Notes]
** xref:release-notes:0.29.adoc[0.29 Release Notes]
** xref:release-notes:0.28.adoc[0.28 Release Notes]
** xref:release-notes:0.27.adoc[0.27 Release Notes]

View File

@@ -1,7 +1,7 @@
# suppress inspection "UnusedProperty" for whole file
group=org.pkl-lang
version=0.29.1
version=0.30.0
# google-java-format requires jdk.compiler exports
org.gradle.jvmargs= \

View File

@@ -49,7 +49,7 @@ org.apache.httpcomponents.client5:httpclient5:5.5=testCompileClasspath,testImple
org.apache.httpcomponents.core5:httpcore5-h2:5.3.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.apache.httpcomponents.core5:httpcore5:5.3.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath,testImplementationDependenciesMetadata
org.assertj:assertj-core:3.27.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.assertj:assertj-core:3.27.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.eclipse.jetty.http2:http2-common:11.0.24=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.eclipse.jetty.http2:http2-hpack:11.0.24=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.eclipse.jetty.http2:http2-server:11.0.24=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
@@ -110,13 +110,13 @@ org.jline:jline-reader:3.23.0=compileClasspath,implementationDependenciesMetadat
org.jline:jline-terminal-jansi:3.23.0=compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.jline:jline-terminal:3.23.0=compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.jspecify:jspecify:1.0.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-api:5.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-engine:5.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-params:5.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-commons:1.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-engine:1.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-launcher:1.13.3=testRuntimeClasspath
org.junit:junit-bom:5.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-api:5.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-engine:5.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-params:5.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-commons:1.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-engine:1.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-launcher:1.13.4=testRuntimeClasspath
org.junit:junit-bom:5.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.msgpack:msgpack-core:0.9.8=runtimeClasspath,testRuntimeClasspath
org.opentest4j:opentest4j:1.3.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.organicdesign:Paguro:3.10.3=runtimeClasspath,testRuntimeClasspath

View File

@@ -61,6 +61,7 @@ dependencies {
implementation(libs.jlineTerminal)
implementation(libs.jlineTerminalJansi)
implementation(projects.pklServer)
implementation(projects.pklFormatter)
implementation(libs.clikt)
testImplementation(projects.pklCommonsTest)

View File

@@ -0,0 +1,57 @@
/*
* 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.cli
import java.io.IOException
import java.nio.file.Files
import java.nio.file.Path
import kotlin.io.path.writeText
import org.pkl.commons.cli.CliBaseOptions
import org.pkl.commons.cli.CliException
class CliFormatterApply(
cliBaseOptions: CliBaseOptions,
paths: List<Path>,
private val silent: Boolean,
) : CliFormatterCommand(cliBaseOptions, paths) {
override fun doRun() {
var status = 0
for (path in paths()) {
val contents = Files.readString(path)
val (formatted, stat) = format(path, contents)
status = if (status == 0) stat else status
if (stat != 0) continue
if (!silent && contents != formatted) {
consoleWriter.write(path.toAbsolutePath().toString())
consoleWriter.appendLine()
consoleWriter.flush()
}
try {
path.writeText(formatted, Charsets.UTF_8)
} catch (e: IOException) {
consoleWriter.write("Could not overwrite `$path`: ${e.message}")
consoleWriter.appendLine()
consoleWriter.flush()
status = 1
}
}
if (status != 0) {
throw CliException("Formatting violations found.", status)
}
}
}

View File

@@ -0,0 +1,44 @@
/*
* 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.cli
import java.nio.file.Files
import java.nio.file.Path
import org.pkl.commons.cli.CliBaseOptions
import org.pkl.commons.cli.CliException
class CliFormatterCheck(cliBaseOptions: CliBaseOptions, paths: List<Path>) :
CliFormatterCommand(cliBaseOptions, paths) {
override fun doRun() {
var status = 0
for (path in paths()) {
val contents = Files.readString(path)
val (formatted, stat) = format(path, contents)
status = if (status == 0) stat else status
if (contents != formatted) {
consoleWriter.write(path.toAbsolutePath().toString())
consoleWriter.appendLine()
consoleWriter.flush()
status = 1
}
}
if (status != 0) {
throw CliException("Formatting violations found.", status)
}
}
}

View File

@@ -0,0 +1,60 @@
/*
* 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.cli
import java.io.Writer
import java.nio.file.Path
import kotlin.io.path.ExperimentalPathApi
import kotlin.io.path.extension
import kotlin.io.path.isDirectory
import kotlin.io.path.name
import kotlin.io.path.walk
import org.pkl.commons.cli.CliBaseOptions
import org.pkl.commons.cli.CliCommand
import org.pkl.formatter.Formatter
import org.pkl.parser.GenericParserError
abstract class CliFormatterCommand
@JvmOverloads
constructor(
options: CliBaseOptions,
protected val paths: List<Path>,
protected val consoleWriter: Writer = System.out.writer(),
) : CliCommand(options) {
protected fun format(file: Path, contents: String): Pair<String, Int> {
try {
return Formatter().format(contents) to 0
} catch (pe: GenericParserError) {
consoleWriter.write("Could not format `$file`: $pe")
consoleWriter.appendLine()
consoleWriter.flush()
return "" to 1
}
}
@OptIn(ExperimentalPathApi::class)
protected fun paths(): Set<Path> {
val allPaths = mutableSetOf<Path>()
for (path in paths) {
if (path.isDirectory()) {
allPaths.addAll(path.walk().filter { it.extension == "pkl" || it.name == "PklProject" })
} else {
allPaths.add(path)
}
}
return allPaths
}
}

View File

@@ -0,0 +1,74 @@
/*
* 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.cli.commands
import com.github.ajalt.clikt.core.Context
import com.github.ajalt.clikt.core.NoOpCliktCommand
import com.github.ajalt.clikt.core.subcommands
import com.github.ajalt.clikt.parameters.arguments.argument
import com.github.ajalt.clikt.parameters.arguments.multiple
import com.github.ajalt.clikt.parameters.options.flag
import com.github.ajalt.clikt.parameters.options.option
import com.github.ajalt.clikt.parameters.types.path
import java.nio.file.Path
import org.pkl.cli.CliFormatterApply
import org.pkl.cli.CliFormatterCheck
import org.pkl.commons.cli.commands.BaseCommand
class FormatterCommand : NoOpCliktCommand(name = "format") {
override fun help(context: Context) = "Run commands related to formatting"
override fun helpEpilog(context: Context) = "For more information, visit $helpLink"
init {
subcommands(FormatterCheckCommand(), FormatterApplyCommand())
}
}
class FormatterCheckCommand : BaseCommand(name = "check", helpLink = helpLink) {
override val helpString: String =
"Check if the given files are properly formatted, printing the file name to stdout in case they are not. Returns non-zero in case of failure."
val paths: List<Path> by
argument(name = "paths", help = "Files or directory to check.")
.path(mustExist = true, canBeDir = true)
.multiple()
override fun run() {
CliFormatterCheck(baseOptions.baseOptions(emptyList()), paths).run()
}
}
class FormatterApplyCommand : BaseCommand(name = "apply", helpLink = helpLink) {
override val helpString: String =
"Overwrite all the files in place with the formatted version. Returns non-zero in case of failure."
val paths: List<Path> by
argument(name = "paths", help = "Files or directory to format.")
.path(mustExist = true, canBeDir = true)
.multiple()
val silent: Boolean by
option(
names = arrayOf("-s", "--silent"),
help = "Do not write the name of the files that failed formatting to stdout.",
)
.flag()
override fun run() {
CliFormatterApply(baseOptions.baseOptions(emptyList()), paths, silent).run()
}
}

View File

@@ -49,6 +49,7 @@ class RootCommand : NoOpCliktCommand(name = "pkl") {
ProjectCommand(),
DownloadPackageCommand(),
AnalyzeCommand(),
FormatterCommand(),
CompletionCommand(
name = "shell-completion",
help = "Generate a completion script for the given shell",

View File

@@ -52,6 +52,7 @@ internal class Repl(workingDir: Path, private val server: ReplServer) {
private var continuation = false
private var quit = false
private var maybeQuit = false
private var nextRequestId = 0
fun run() {
@@ -74,11 +75,23 @@ internal class Repl(workingDir: Path, private val server: ReplServer) {
reader.readLine("pkl$nextRequestId> ")
}
} catch (e: UserInterruptException) {
":quit"
if (!continuation && reader.buffer.length() == 0) {
if (maybeQuit) quit()
else {
maybeQuit = true
println("(To exit, press ^C again or ^D or type :quit)")
}
} else {
maybeQuit = false
}
inputBuffer = ""
continuation = false
continue
} catch (e: EndOfFileException) {
":quit"
}
maybeQuit = false
val input = line.trim()
if (input.isEmpty()) continue

View File

@@ -26,7 +26,7 @@ io.leangen.geantyref:geantyref:1.3.16=testRuntimeClasspath
net.bytebuddy:byte-buddy:1.15.11=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
net.java.dev.jna:jna:5.14.0=runtimeClasspath,testRuntimeClasspath
org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath,testImplementationDependenciesMetadata
org.assertj:assertj-core:3.27.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.assertj:assertj-core:3.27.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.graalvm.polyglot:polyglot:24.1.2=runtimeClasspath,testRuntimeClasspath
org.graalvm.sdk:collections:24.1.2=runtimeClasspath,testRuntimeClasspath
org.graalvm.sdk:graal-sdk:24.1.2=runtimeClasspath,testRuntimeClasspath
@@ -56,13 +56,13 @@ org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.4=kotlinBuildToolsApiClass
org.jetbrains:annotations:13.0=compileClasspath,kotlinBuildToolsApiClasspath,kotlinCompilerClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinKlibCommonizerClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.jetbrains:markdown-jvm:0.7.3=runtimeClasspath,testRuntimeClasspath
org.jetbrains:markdown:0.7.3=runtimeClasspath,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-api:5.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-engine:5.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-params:5.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-commons:1.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-engine:1.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-launcher:1.13.3=testRuntimeClasspath
org.junit:junit-bom:5.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-api:5.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-engine:5.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-params:5.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-commons:1.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-engine:1.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-launcher:1.13.4=testRuntimeClasspath
org.junit:junit-bom:5.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.msgpack:msgpack-core:0.9.8=runtimeClasspath,testRuntimeClasspath
org.opentest4j:opentest4j:1.3.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.organicdesign:Paguro:3.10.3=runtimeClasspath,testRuntimeClasspath

View File

@@ -26,7 +26,7 @@ io.leangen.geantyref:geantyref:1.3.16=testRuntimeClasspath
net.bytebuddy:byte-buddy:1.15.11=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
net.java.dev.jna:jna:5.14.0=runtimeClasspath,testRuntimeClasspath
org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath,testImplementationDependenciesMetadata
org.assertj:assertj-core:3.27.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.assertj:assertj-core:3.27.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.graalvm.polyglot:polyglot:24.1.2=runtimeClasspath,testRuntimeClasspath
org.graalvm.sdk:collections:24.1.2=runtimeClasspath,testRuntimeClasspath
org.graalvm.sdk:graal-sdk:24.1.2=runtimeClasspath,testRuntimeClasspath
@@ -58,13 +58,13 @@ org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.4=kotlinBuildToolsApiClass
org.jetbrains:annotations:13.0=compileClasspath,kotlinBuildToolsApiClasspath,kotlinCompilerClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinKlibCommonizerClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.jetbrains:markdown-jvm:0.7.3=runtimeClasspath,testRuntimeClasspath
org.jetbrains:markdown:0.7.3=runtimeClasspath,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-api:5.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-engine:5.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-params:5.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-commons:1.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-engine:1.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-launcher:1.13.3=testRuntimeClasspath
org.junit:junit-bom:5.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-api:5.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-engine:5.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-params:5.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-commons:1.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-engine:1.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-launcher:1.13.4=testRuntimeClasspath
org.junit:junit-bom:5.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.msgpack:msgpack-core:0.9.8=runtimeClasspath,testRuntimeClasspath
org.opentest4j:opentest4j:1.3.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.organicdesign:Paguro:3.10.3=runtimeClasspath,testRuntimeClasspath

View File

@@ -24,7 +24,7 @@ com.github.ajalt.mordant:mordant:3.0.1=apiDependenciesMetadata,compileClasspath,
net.bytebuddy:byte-buddy:1.15.11=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
net.java.dev.jna:jna:5.14.0=runtimeClasspath,testRuntimeClasspath
org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath,testImplementationDependenciesMetadata
org.assertj:assertj-core:3.27.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.assertj:assertj-core:3.27.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.graalvm.compiler:compiler:24.1.2=svmClasspath
org.graalvm.nativeimage:native-image-base:24.1.2=svmClasspath
org.graalvm.nativeimage:objectfile:24.1.2=svmClasspath
@@ -63,13 +63,13 @@ org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.4=kotlinBuildToolsApiClass
org.jetbrains:annotations:13.0=compileClasspath,kotlinBuildToolsApiClasspath,kotlinCompilerClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathSvm,kotlinCompilerPluginClasspathTest,kotlinKlibCommonizerClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.jetbrains:markdown-jvm:0.7.3=runtimeClasspath,testRuntimeClasspath
org.jetbrains:markdown:0.7.3=implementationDependenciesMetadata,runtimeClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-api:5.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-engine:5.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-params:5.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-commons:1.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-engine:1.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-launcher:1.13.3=testRuntimeClasspath
org.junit:junit-bom:5.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-api:5.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-engine:5.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-params:5.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-commons:1.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-engine:1.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-launcher:1.13.4=testRuntimeClasspath
org.junit:junit-bom:5.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.msgpack:msgpack-core:0.9.8=runtimeClasspath,svmClasspath,testRuntimeClasspath
org.opentest4j:opentest4j:1.3.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.organicdesign:Paguro:3.10.3=runtimeClasspath,svmClasspath,testRuntimeClasspath

View File

@@ -218,8 +218,9 @@ abstract class CliCommand(protected val cliOptions: CliBaseOptions) {
}
if (!certsAdded) {
val defaultCerts =
javaClass.classLoader.getResourceAsStream("org/pkl/commons/cli/PklCARoots.pem")
?: throw CliException("Could not find bundled certificates")
this@CliCommand.javaClass.classLoader.getResourceAsStream(
"org/pkl/commons/cli/PklCARoots.pem"
) ?: throw CliException("Could not find bundled certificates")
addCertificates(defaultCerts.readAllBytes())
}
}

View File

@@ -3,7 +3,7 @@
# This file is expected to be part of source control.
net.bytebuddy:byte-buddy:1.15.11=compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.apiguardian:apiguardian-api:1.1.2=apiDependenciesMetadata,compileClasspath,implementationDependenciesMetadata,testCompileClasspath,testImplementationDependenciesMetadata
org.assertj:assertj-core:3.27.3=compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.assertj:assertj-core:3.27.4=compileClasspath,implementationDependenciesMetadata,runtimeClasspath,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
@@ -25,12 +25,12 @@ org.jetbrains.kotlin:kotlin-stdlib-jdk8:2.0.21=apiDependenciesMetadata,compileCl
org.jetbrains.kotlin:kotlin-stdlib:2.0.21=apiDependenciesMetadata,compileClasspath,implementationDependenciesMetadata,kotlinBuildToolsApiClasspath,kotlinCompilerClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinKlibCommonizerClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.4=kotlinBuildToolsApiClasspath,kotlinCompilerClasspath,kotlinKlibCommonizerClasspath
org.jetbrains:annotations:13.0=compileClasspath,kotlinBuildToolsApiClasspath,kotlinCompilerClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinKlibCommonizerClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-api:5.13.3=apiDependenciesMetadata,compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-engine:5.13.3=apiDependenciesMetadata,compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-params:5.13.3=apiDependenciesMetadata,compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-commons:1.13.3=apiDependenciesMetadata,compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-engine:1.13.3=apiDependenciesMetadata,compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-launcher:1.13.3=testRuntimeClasspath
org.junit:junit-bom:5.13.3=apiDependenciesMetadata,compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-api:5.13.4=apiDependenciesMetadata,compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-engine:5.13.4=apiDependenciesMetadata,compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-params:5.13.4=apiDependenciesMetadata,compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-commons:1.13.4=apiDependenciesMetadata,compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-engine:1.13.4=apiDependenciesMetadata,compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-launcher:1.13.4=testRuntimeClasspath
org.junit:junit-bom:5.13.4=apiDependenciesMetadata,compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.opentest4j:opentest4j:1.3.0=apiDependenciesMetadata,compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
empty=annotationProcessor,compileOnlyDependenciesMetadata,intransitiveDependenciesMetadata,kotlinCompilerPluginClasspath,kotlinNativeCompilerPluginClasspath,kotlinScriptDefExtensions,sourcesJar,testAnnotationProcessor,testApiDependenciesMetadata,testCompileOnlyDependenciesMetadata,testIntransitiveDependenciesMetadata,testKotlinScriptDefExtensions

View File

@@ -3,7 +3,7 @@
# This file is expected to be part of source control.
net.bytebuddy:byte-buddy:1.15.11=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath,testImplementationDependenciesMetadata
org.assertj:assertj-core:3.27.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.assertj:assertj-core:3.27.4=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
@@ -25,12 +25,12 @@ org.jetbrains.kotlin:kotlin-stdlib-jdk8:2.0.21=apiDependenciesMetadata,compileCl
org.jetbrains.kotlin:kotlin-stdlib:2.0.21=apiDependenciesMetadata,compileClasspath,implementationDependenciesMetadata,kotlinBuildToolsApiClasspath,kotlinCompilerClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinKlibCommonizerClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.4=kotlinBuildToolsApiClasspath,kotlinCompilerClasspath,kotlinKlibCommonizerClasspath
org.jetbrains:annotations:13.0=compileClasspath,kotlinBuildToolsApiClasspath,kotlinCompilerClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinKlibCommonizerClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-api:5.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-engine:5.13.3=testRuntimeClasspath
org.junit.jupiter:junit-jupiter-params:5.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-commons:1.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-engine:1.13.3=testRuntimeClasspath
org.junit.platform:junit-platform-launcher:1.13.3=testRuntimeClasspath
org.junit:junit-bom:5.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-api:5.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-engine:5.13.4=testRuntimeClasspath
org.junit.jupiter:junit-jupiter-params:5.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-commons:1.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-engine:1.13.4=testRuntimeClasspath
org.junit.platform:junit-platform-launcher:1.13.4=testRuntimeClasspath
org.junit:junit-bom:5.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.opentest4j:opentest4j:1.3.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
empty=annotationProcessor,compileOnlyDependenciesMetadata,intransitiveDependenciesMetadata,kotlinCompilerPluginClasspath,kotlinNativeCompilerPluginClasspath,kotlinScriptDefExtensions,signatures,sourcesJar,testAnnotationProcessor,testApiDependenciesMetadata,testCompileOnlyDependenciesMetadata,testIntransitiveDependenciesMetadata,testKotlinScriptDefExtensions

View File

@@ -27,7 +27,7 @@ javax.inject:javax.inject:1=testCompileClasspath,testImplementationDependenciesM
net.bytebuddy:byte-buddy:1.15.11=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
net.java.dev.jna:jna:5.14.0=pklCodegenJava
org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath,testImplementationDependenciesMetadata
org.assertj:assertj-core:3.27.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.assertj:assertj-core:3.27.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.graalvm.polyglot:polyglot:24.1.2=pklCodegenJava,runtimeClasspath,testRuntimeClasspath
org.graalvm.sdk:collections:24.1.2=pklCodegenJava,runtimeClasspath,testRuntimeClasspath
org.graalvm.sdk:graal-sdk:24.1.2=pklCodegenJava,runtimeClasspath,testRuntimeClasspath
@@ -57,13 +57,13 @@ org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.4=kotlinBuildToolsApiClass
org.jetbrains:annotations:13.0=kotlinBuildToolsApiClasspath,kotlinCompilerClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinKlibCommonizerClasspath,pklCodegenJava,testCompileClasspath,testRuntimeClasspath
org.jetbrains:markdown-jvm:0.7.3=pklCodegenJava
org.jetbrains:markdown:0.7.3=pklCodegenJava
org.junit.jupiter:junit-jupiter-api:5.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-engine:5.13.3=testRuntimeClasspath
org.junit.jupiter:junit-jupiter-params:5.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-commons:1.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-engine:1.13.3=testRuntimeClasspath
org.junit.platform:junit-platform-launcher:1.13.3=testRuntimeClasspath
org.junit:junit-bom:5.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-api:5.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-engine:5.13.4=testRuntimeClasspath
org.junit.jupiter:junit-jupiter-params:5.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-commons:1.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-engine:1.13.4=testRuntimeClasspath
org.junit.platform:junit-platform-launcher:1.13.4=testRuntimeClasspath
org.junit:junit-bom:5.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.msgpack:msgpack-core:0.9.8=pklCodegenJava,runtimeClasspath,testRuntimeClasspath
org.opentest4j:opentest4j:1.3.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.organicdesign:Paguro:3.10.3=pklCodegenJava,runtimeClasspath,testRuntimeClasspath

View File

@@ -26,7 +26,7 @@ io.leangen.geantyref:geantyref:1.3.16=pklConfigJava,runtimeClasspath,testCompile
net.bytebuddy:byte-buddy:1.15.11=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
net.java.dev.jna:jna:5.14.0=pklCodegenKotlin
org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath,testImplementationDependenciesMetadata
org.assertj:assertj-core:3.27.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.assertj:assertj-core:3.27.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.graalvm.polyglot:polyglot:24.1.2=pklCodegenKotlin,pklConfigJava,runtimeClasspath,testRuntimeClasspath
org.graalvm.sdk:collections:24.1.2=pklCodegenKotlin,pklConfigJava,runtimeClasspath,testRuntimeClasspath
org.graalvm.sdk:graal-sdk:24.1.2=pklCodegenKotlin,pklConfigJava,runtimeClasspath,testRuntimeClasspath
@@ -56,13 +56,13 @@ org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.4=kotlinBuildToolsApiClass
org.jetbrains:annotations:13.0=compileClasspath,kotlinBuildToolsApiClasspath,kotlinCompilerClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinKlibCommonizerClasspath,pklCodegenKotlin,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.jetbrains:markdown-jvm:0.7.3=pklCodegenKotlin
org.jetbrains:markdown:0.7.3=pklCodegenKotlin
org.junit.jupiter:junit-jupiter-api:5.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-engine:5.13.3=testRuntimeClasspath
org.junit.jupiter:junit-jupiter-params:5.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-commons:1.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-engine:1.13.3=testRuntimeClasspath
org.junit.platform:junit-platform-launcher:1.13.3=testRuntimeClasspath
org.junit:junit-bom:5.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-api:5.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-engine:5.13.4=testRuntimeClasspath
org.junit.jupiter:junit-jupiter-params:5.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-commons:1.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-engine:1.13.4=testRuntimeClasspath
org.junit.platform:junit-platform-launcher:1.13.4=testRuntimeClasspath
org.junit:junit-bom:5.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.msgpack:msgpack-core:0.9.8=pklCodegenKotlin,pklConfigJava,runtimeClasspath,testRuntimeClasspath
org.opentest4j:opentest4j:1.3.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.organicdesign:Paguro:3.10.3=pklCodegenKotlin,pklConfigJava,runtimeClasspath,testRuntimeClasspath

View File

@@ -5,7 +5,7 @@ com.google.code.findbugs:jsr305:3.0.2=compileClasspath,compileOnlyDependenciesMe
com.palantir.javapoet:javapoet:0.7.0=generatorCompileClasspath,generatorImplementationDependenciesMetadata,generatorRuntimeClasspath
net.bytebuddy:byte-buddy:1.15.11=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath,testImplementationDependenciesMetadata
org.assertj:assertj-core:3.27.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.assertj:assertj-core:3.27.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.graalvm.polyglot:polyglot:24.1.2=compileClasspath,generatorCompileClasspath,generatorImplementationDependenciesMetadata,generatorRuntimeClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.graalvm.sdk:collections:24.1.2=compileClasspath,generatorCompileClasspath,generatorImplementationDependenciesMetadata,generatorRuntimeClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.graalvm.sdk:graal-sdk:24.1.2=compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
@@ -34,13 +34,13 @@ org.jetbrains.kotlin:kotlin-stdlib-jdk8:2.0.21=generatorCompileClasspath,generat
org.jetbrains.kotlin:kotlin-stdlib:2.0.21=generatorCompileClasspath,generatorImplementationDependenciesMetadata,generatorRuntimeClasspath,kotlinBuildToolsApiClasspath,kotlinCompilerClasspath,kotlinCompilerPluginClasspathGenerator,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinKlibCommonizerClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.4=kotlinBuildToolsApiClasspath,kotlinCompilerClasspath,kotlinKlibCommonizerClasspath
org.jetbrains:annotations:13.0=generatorCompileClasspath,generatorRuntimeClasspath,kotlinBuildToolsApiClasspath,kotlinCompilerClasspath,kotlinCompilerPluginClasspathGenerator,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinKlibCommonizerClasspath,testCompileClasspath,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-api:5.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-engine:5.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-params:5.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-commons:1.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-engine:1.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-launcher:1.13.3=testRuntimeClasspath
org.junit:junit-bom:5.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-api:5.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-engine:5.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-params:5.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-commons:1.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-engine:1.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-launcher:1.13.4=testRuntimeClasspath
org.junit:junit-bom:5.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.msgpack:msgpack-core:0.9.8=compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.opentest4j:opentest4j:1.3.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.organicdesign:Paguro:3.10.3=compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath

View File

@@ -33,7 +33,7 @@ import org.pkl.parser.syntax.Module;
@TruffleLanguage.Registration(
id = "pkl",
name = "Pkl",
version = "0.29.1",
version = "0.30.0-dev",
characterMimeTypes = VmLanguage.MIME_TYPE,
contextPolicy = ContextPolicy.SHARED)
public final class VmLanguage extends TruffleLanguage<VmContext> {

View File

@@ -0,0 +1,9 @@
res1: Int(isEven, isNonZero, isBetween(-10, 10), ) = 6
res2: Int(
isEven, isNonZero, isBetween(-10, 10),
) = 6
res3: Int(
isEven,
isNonZero,
isBetween(-10, 10),
) = 6

View File

@@ -0,0 +1,43 @@
local lA1 = (a, b, c,) -> true
local lA2 = (
a, b, c,
) -> true
local lA3 = (
a,
b,
c,
) -> true
local lB1 = (a: Int, b: Int, c: Int,) -> true
local lB2 = (
a: Int, b: Int, c: Int,
) -> true
local lB3 = (
a: Int,
b: Int,
c: Int,
) -> true
local lC1: (Dynamic,) -> Dynamic = new Mixin { a, -> x = true }
local lC2: (Dynamic,) -> Dynamic = new Mixin { a, ->
x = true
}
local lC3: (Dynamic,) -> Dynamic = new Mixin {
a, -> x = true
}
local lC4: (Dynamic,) -> Dynamic = new Mixin {
a, ->
x = true
}
local lD1: (Dynamic,) -> Dynamic = new Mixin { a: Dynamic, -> x = true }
local lD2: (Dynamic,) -> Dynamic = new Mixin { a: Dynamic, ->
x = true
}
local lD3: (Dynamic,) -> Dynamic = new Mixin {
a: Dynamic, -> x = true
}
local lD4: (Dynamic,) -> Dynamic = new Mixin {
a: Dynamic, ->
x = true
}

View File

@@ -0,0 +1,157 @@
function moduleMethodA1(a, b, c, ) = true
function moduleMethodA2(
a, b, c,
) = true
function moduleMethodA3(
a,
b,
c,
) = true
function moduleMethodB1(a: Int, b: Int, c: Int, ) = true
function moduleMethodB2(
a: Int, b: Int, c: Int,
) = true
function moduleMethodB3(
a: Int,
b: Int,
c: Int,
) = true
class A {
function classMethodA1(a, b, c, ) = true
function classMethodA2(
a, b, c,
) = true
function classMethodA3(
a,
b,
c,
) = true
function classMethodB1(a: Int, b: Int, c: Int, ) = true
function classMethodB2(
a: Int, b: Int, c: Int,
) = true
function classMethodB3(
a: Int,
b: Int,
c: Int,
) = true
}
moduleMethodA1Call1 = moduleMethodA1(1, 2, 3, )
moduleMethodA1Call2 = moduleMethodA1(
1, 2, 3,
)
moduleMethodA1Call3 = moduleMethodA1(
1,
2,
3,
)
moduleMethodA2Call1 = moduleMethodA2(1, 2, 3, )
moduleMethodA2Call2 = moduleMethodA2(
1, 2, 3,
)
moduleMethodA2Call3 = moduleMethodA2(
1,
2,
3,
)
moduleMethodA3Call1 = moduleMethodA3(1, 2, 3, )
moduleMethodA3Call2 = moduleMethodA3(
1, 2, 3,
)
moduleMethodA3Call3 = moduleMethodA3(
1,
2,
3,
)
moduleMethodB1Call1 = moduleMethodB1(1, 2, 3, )
moduleMethodB1Call2 = moduleMethodB1(
1, 2, 3,
)
moduleMethodB1Call3 = moduleMethodB1(
1,
2,
3,
)
moduleMethodB2Call1 = moduleMethodB2(1, 2, 3, )
moduleMethodB2Call2 = moduleMethodB2(
1, 2, 3,
)
moduleMethodB2Call3 = moduleMethodB2(
1,
2,
3,
)
moduleMethodB3Call1 = moduleMethodB3(1, 2, 3, )
moduleMethodB3Call2 = moduleMethodB3(
1, 2, 3,
)
moduleMethodB3Call3 = moduleMethodB3(
1,
2,
3,
)
local a: A = new {}
classMethodA1Call1 = a.classMethodA1(1, 2, 3, )
classMethodA1Call2 = a.classMethodA1(
1, 2, 3,
)
classMethodA1Call3 = a.classMethodA1(
1,
2,
3,
)
classMethodA2Call1 = a.classMethodA2(1, 2, 3, )
classMethodA2Call2 = a.classMethodA2(
1, 2, 3,
)
classMethodA2Call3 = a.classMethodA2(
1,
2,
3,
)
classMethodA3Call1 = a.classMethodA3(1, 2, 3, )
classMethodA3Call2 = a.classMethodA3(
1, 2, 3,
)
classMethodA3Call3 = a.classMethodA3(
1,
2,
3,
)
classMethodB1Call1 = a.classMethodB1(1, 2, 3, )
classMethodB1Call2 = a.classMethodB1(
1, 2, 3,
)
classMethodB1Call3 = a.classMethodB1(
1,
2,
3,
)
classMethodB2Call1 = a.classMethodB2(1, 2, 3, )
classMethodB2Call2 = a.classMethodB2(
1, 2, 3,
)
classMethodB2Call3 = a.classMethodB2(
1,
2,
3,
)
classMethodB3Call1 = a.classMethodB3(1, 2, 3, )
classMethodB3Call2 = a.classMethodB3(
1, 2, 3,
)
classMethodB3Call3 = a.classMethodB3(
1,
2,
3,
)

View File

@@ -0,0 +1,3 @@
res1: Mapping<String, String,>(!isEmpty) = new Mapping<String, String,> {
["hello"] = "world"
}

View File

@@ -0,0 +1,3 @@
res1 = 6
res2 = 6
res3 = 6

View File

@@ -0,0 +1,36 @@
moduleMethodA1Call1 = true
moduleMethodA1Call2 = true
moduleMethodA1Call3 = true
moduleMethodA2Call1 = true
moduleMethodA2Call2 = true
moduleMethodA2Call3 = true
moduleMethodA3Call1 = true
moduleMethodA3Call2 = true
moduleMethodA3Call3 = true
moduleMethodB1Call1 = true
moduleMethodB1Call2 = true
moduleMethodB1Call3 = true
moduleMethodB2Call1 = true
moduleMethodB2Call2 = true
moduleMethodB2Call3 = true
moduleMethodB3Call1 = true
moduleMethodB3Call2 = true
moduleMethodB3Call3 = true
classMethodA1Call1 = true
classMethodA1Call2 = true
classMethodA1Call3 = true
classMethodA2Call1 = true
classMethodA2Call2 = true
classMethodA2Call3 = true
classMethodA3Call1 = true
classMethodA3Call2 = true
classMethodA3Call3 = true
classMethodB1Call1 = true
classMethodB1Call2 = true
classMethodB1Call3 = true
classMethodB2Call1 = true
classMethodB2Call2 = true
classMethodB2Call3 = true
classMethodB3Call1 = true
classMethodB3Call2 = true
classMethodB3Call3 = true

View File

@@ -0,0 +1,3 @@
res1 {
["hello"] = "world"
}

View File

@@ -0,0 +1,82 @@
/*
* 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.core.parser
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.pkl.core.Evaluator
import org.pkl.parser.Parser
// tests type argument and parameter parsing with trailing commas that cannot be tested with
// snippets because these constructs are currently only allowed in the stdlib
class TrailingCommasTest {
private val evaluator = Evaluator.preconfigured()
@Test
fun `class type parameter lists parse correctly`() {
val module =
Parser()
.parseModule(
"""
class Foo<
Key,
Value,
>
class Bar<
Key,
Value,
> {
baz: Key
buzz: Value
}
"""
.trimIndent()
)
val fooClass = module.classes.find { it.name.value == "Foo" }
assertThat(fooClass).isNotNull
assertThat(fooClass!!.typeParameterList?.parameters?.first()?.identifier?.value)
.isEqualTo("Key")
assertThat(fooClass.typeParameterList?.parameters?.last()?.identifier?.value).isEqualTo("Value")
val barClass = module.classes.find { it.name.value == "Bar" }
assertThat(barClass).isNotNull
assertThat(barClass!!.typeParameterList?.parameters?.first()?.identifier?.value)
.isEqualTo("Key")
assertThat(barClass.typeParameterList?.parameters?.last()?.identifier?.value).isEqualTo("Value")
}
@Test
fun `method type parameter lists parse correctly`() {
val module =
Parser()
.parseModule(
"""
function foo<
A,
B,
>(a: A, b: B,): Value? = "\(a):\(b)"
"""
.trimIndent()
)
val fooMethod = module.methods.find { it.name.value == "foo" }
assertThat(fooMethod).isNotNull
assertThat(fooMethod!!.typeParameterList?.parameters?.first()?.identifier?.value).isEqualTo("A")
assertThat(fooMethod.typeParameterList?.parameters?.last()?.identifier?.value).isEqualTo("B")
}
}

View File

@@ -47,9 +47,9 @@ org.apache.httpcomponents:httpcore:4.4=validator
org.apache.logging.log4j:log4j-1.2-api:2.17.1=validator
org.apache.logging.log4j:log4j-api:2.17.1=validator
org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath,testImplementationDependenciesMetadata
org.assertj:assertj-core:3.27.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.commonmark:commonmark-ext-gfm-tables:0.25.0=compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.commonmark:commonmark:0.25.0=compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.assertj:assertj-core:3.27.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.commonmark:commonmark-ext-gfm-tables:0.25.1=compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.commonmark:commonmark:0.25.1=compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.eclipse.jetty:jetty-util-ajax:9.4.18.v20190429=validator
org.eclipse.jetty:jetty-util:9.4.18.v20190429=validator
org.graalvm.js:js-community:24.1.2=testRuntimeClasspath
@@ -99,13 +99,13 @@ org.jetbrains:annotations:13.0=compileClasspath,kotlinBuildToolsApiClasspath,kot
org.jetbrains:markdown-jvm:0.7.3=runtimeClasspath,testRuntimeClasspath
org.jetbrains:markdown:0.7.3=runtimeClasspath,testRuntimeClasspath
org.jspecify:jspecify:1.0.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-api:5.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-engine:5.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-params:5.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-commons:1.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-engine:1.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-launcher:1.13.3=testRuntimeClasspath
org.junit:junit-bom:5.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-api:5.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-engine:5.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-params:5.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-commons:1.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-engine:1.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-launcher:1.13.4=testRuntimeClasspath
org.junit:junit-bom:5.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.msgpack:msgpack-core:0.9.8=runtimeClasspath,testRuntimeClasspath
org.opentest4j:opentest4j:1.3.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.organicdesign:Paguro:3.10.3=runtimeClasspath,testRuntimeClasspath

View File

@@ -3,7 +3,7 @@
# This file is expected to be part of source control.
net.bytebuddy:byte-buddy:1.15.11=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath,testImplementationDependenciesMetadata
org.assertj:assertj-core:3.27.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.assertj:assertj-core:3.27.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.graalvm.polyglot:polyglot:24.1.2=testRuntimeClasspath
org.graalvm.sdk:collections:24.1.2=testRuntimeClasspath
org.graalvm.sdk:graal-sdk:24.1.2=testRuntimeClasspath
@@ -31,13 +31,13 @@ org.jetbrains.kotlin:kotlin-stdlib-jdk8:2.0.21=testCompileClasspath,testImplemen
org.jetbrains.kotlin:kotlin-stdlib:2.0.21=kotlinBuildToolsApiClasspath,kotlinCompilerClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinKlibCommonizerClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.4=kotlinBuildToolsApiClasspath,kotlinCompilerClasspath,kotlinKlibCommonizerClasspath
org.jetbrains:annotations:13.0=kotlinBuildToolsApiClasspath,kotlinCompilerClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinKlibCommonizerClasspath,testCompileClasspath,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-api:5.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-engine:5.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-params:5.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-commons:1.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-engine:1.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-launcher:1.13.3=testRuntimeClasspath
org.junit:junit-bom:5.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-api:5.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-engine:5.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-params:5.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-commons:1.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-engine:1.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-launcher:1.13.4=testRuntimeClasspath
org.junit:junit-bom:5.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.msgpack:msgpack-core:0.9.8=testRuntimeClasspath
org.opentest4j:opentest4j:1.3.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.organicdesign:Paguro:3.10.3=testRuntimeClasspath

View File

@@ -0,0 +1,36 @@
# 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.
net.bytebuddy:byte-buddy:1.15.11=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath,testImplementationDependenciesMetadata
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,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinKlibCommonizerClasspath
org.jetbrains.kotlin:kotlin-scripting-common:2.0.21=kotlinBuildToolsApiClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest
org.jetbrains.kotlin:kotlin-scripting-compiler-embeddable:2.0.21=kotlinBuildToolsApiClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest
org.jetbrains.kotlin:kotlin-scripting-compiler-impl-embeddable:2.0.21=kotlinBuildToolsApiClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest
org.jetbrains.kotlin:kotlin-scripting-jvm:2.0.21=kotlinBuildToolsApiClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest
org.jetbrains.kotlin:kotlin-stdlib-jdk7:2.0.21=apiDependenciesMetadata,compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.jetbrains.kotlin:kotlin-stdlib-jdk8:2.0.21=apiDependenciesMetadata,compileClasspath,implementationDependenciesMetadata,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.jetbrains.kotlin:kotlin-stdlib:2.0.21=apiDependenciesMetadata,compileClasspath,implementationDependenciesMetadata,kotlinBuildToolsApiClasspath,kotlinCompilerClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinKlibCommonizerClasspath,runtimeClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.4=kotlinBuildToolsApiClasspath,kotlinCompilerClasspath,kotlinKlibCommonizerClasspath
org.jetbrains:annotations:13.0=compileClasspath,kotlinBuildToolsApiClasspath,kotlinCompilerClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinKlibCommonizerClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-api:5.13.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-engine:5.13.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-params:5.13.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-commons:1.13.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-engine:1.13.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-launcher:1.13.0=testRuntimeClasspath
org.junit:junit-bom:5.13.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.opentest4j:opentest4j:1.3.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
empty=annotationProcessor,compileOnlyDependenciesMetadata,intransitiveDependenciesMetadata,kotlinCompilerPluginClasspath,kotlinNativeCompilerPluginClasspath,kotlinScriptDefExtensions,sourcesJar,testAnnotationProcessor,testApiDependenciesMetadata,testCompileOnlyDependenciesMetadata,testIntransitiveDependenciesMetadata,testKotlinScriptDefExtensions

View File

@@ -0,0 +1,48 @@
/*
* 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
pklKotlinLibrary
pklPublishLibrary
}
dependencies {
api(projects.pklParser)
testImplementation(projects.pklCommonsTest)
}
tasks.test {
inputs
.dir("src/test/files/FormatterSnippetTests/input")
.withPropertyName("formatterSnippetTestsInput")
.withPathSensitivity(PathSensitivity.RELATIVE)
inputs
.dir("src/test/files/FormatterSnippetTests/output")
.withPropertyName("formatterSnippetTestsOutput")
.withPathSensitivity(PathSensitivity.RELATIVE)
}
publishing {
publications {
named<MavenPublication>("library") {
pom {
url.set("https://github.com/apple/pkl/tree/main/pkl-formatter")
description.set("Formatter for Pkl")
}
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,53 @@
/*
* 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.formatter
import java.nio.file.Files
import java.nio.file.Path
import org.pkl.formatter.ast.ForceLine
import org.pkl.formatter.ast.Nodes
import org.pkl.parser.GenericParser
/** A formatter for Pkl files that applies canonical formatting rules. */
class Formatter {
/**
* Formats a Pkl file from the given file path.
*
* @param path the path to the Pkl file to format
* @return the formatted Pkl source code as a string
* @throws java.io.IOException if the file cannot be read
*/
fun format(path: Path): String {
return format(Files.readString(path))
}
/**
* Formats the given Pkl source code text.
*
* @param text the Pkl source code to format
* @return the formatted Pkl source code as a string
*/
fun format(text: String): String {
val parser = GenericParser()
val builder = Builder(text)
val gen = Generator()
val ast = parser.parseModule(text)
val formatAst = builder.format(ast)
// force a line at the end of the file
gen.generate(Nodes(listOf(formatAst, ForceLine)))
return gen.toString()
}
}

View File

@@ -0,0 +1,149 @@
/*
* 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.formatter
import org.pkl.formatter.ast.Empty
import org.pkl.formatter.ast.ForceLine
import org.pkl.formatter.ast.ForceWrap
import org.pkl.formatter.ast.FormatNode
import org.pkl.formatter.ast.Group
import org.pkl.formatter.ast.IfWrap
import org.pkl.formatter.ast.Indent
import org.pkl.formatter.ast.Line
import org.pkl.formatter.ast.MultilineStringGroup
import org.pkl.formatter.ast.Nodes
import org.pkl.formatter.ast.Space
import org.pkl.formatter.ast.SpaceOrLine
import org.pkl.formatter.ast.Text
import org.pkl.formatter.ast.Wrap
internal class Generator {
private val buf: StringBuilder = StringBuilder()
private var indent: Int = 0
private var size: Int = 0
private val wrapped: MutableSet<Int> = mutableSetOf()
private var shouldAddIndent = false
fun generate(node: FormatNode) {
node(node, Wrap.DETECT)
}
private fun node(node: FormatNode, wrap: Wrap) {
when (node) {
is Empty -> {}
is Nodes -> node.nodes.forEach { node(it, wrap) }
is Group -> {
val width = node.nodes.sumOf { it.width(wrapped) }
val wrap =
if (size + width > MAX) {
wrapped += node.id
Wrap.ENABLED
} else {
Wrap.DETECT
}
node.nodes.forEach { node(it, wrap) }
}
is ForceWrap -> {
wrapped += node.id
val wrap = Wrap.ENABLED
node.nodes.forEach { node(it, wrap) }
}
is IfWrap -> {
if (wrapped.contains(node.id)) {
node(node.ifWrap, Wrap.ENABLED)
} else {
node(node.ifNotWrap, wrap)
}
}
is Text -> text(node.text)
is Line -> {
if (wrap.isEnabled()) {
newline()
}
}
is ForceLine -> newline()
is SpaceOrLine -> {
if (wrap.isEnabled()) {
newline()
} else {
text(" ")
}
}
is Space -> text(" ")
is Indent -> {
if (wrap.isEnabled() && node.nodes.isNotEmpty()) {
size += INDENT.length
indent++
node.nodes.forEach { node(it, wrap) }
indent--
} else {
node.nodes.forEach { node(it, wrap) }
}
}
is MultilineStringGroup -> {
val indentLength = indent * INDENT.length
val offset = (indentLength + 1) - node.endQuoteCol
var previousNewline = false
for ((i, child) in node.nodes.withIndex()) {
when {
child is ForceLine -> newline(shouldIndent = false) // don't indent
child is Text &&
previousNewline &&
child.text.isBlank() &&
child.text.length == indentLength &&
node.nodes[i + 1] is ForceLine -> {}
child is Text && previousNewline && offset != 0 -> text(reposition(child.text, offset))
else -> node(child, Wrap.DETECT) // always detect wrapping
}
previousNewline = child is ForceLine
}
}
}
}
private fun text(value: String) {
if (shouldAddIndent) {
repeat(times = indent) { buf.append(INDENT) }
shouldAddIndent = false
}
size += value.length
buf.append(value)
}
private fun newline(shouldIndent: Boolean = true) {
size = INDENT.length * indent
buf.append('\n')
shouldAddIndent = shouldIndent
}
private fun reposition(text: String, offset: Int): String {
return if (offset > 0) {
" ".repeat(offset) + text
} else {
text.drop(-offset)
}
}
override fun toString(): String {
return buf.toString()
}
companion object {
// max line length
const val MAX = 100
private const val INDENT = " "
}
}

View File

@@ -0,0 +1,66 @@
/*
* 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.formatter
internal class NaturalOrderComparator(private val ignoreCase: Boolean = false) :
Comparator<String> {
override fun compare(s1: String, s2: String): Int {
var i = 0
var j = 0
while (i < s1.length && j < s2.length) {
val c1 = if (ignoreCase) s1[i].lowercaseChar() else s1[i]
val c2 = if (ignoreCase) s2[j].lowercaseChar() else s2[j]
if (c1.isDigit() && c2.isDigit()) {
val (num1, nextI) = getNumber(s1, i)
val (num2, nextJ) = getNumber(s2, j)
val numComparison = num1.compareTo(num2)
if (numComparison != 0) {
return numComparison
}
i = nextI
j = nextJ
} else {
val charComparison = c1.compareTo(c2)
if (charComparison != 0) {
return charComparison
}
i++
j++
}
}
return s1.length.compareTo(s2.length)
}
private fun getNumber(s: String, startIndex: Int): LongAndInt {
var i = startIndex
val start = i
while (i < s.length && s[i].isDigit()) {
i++
}
val numStr = s.substring(start, i)
val number = numStr.toLongOrNull() ?: 0L
return LongAndInt(number, i)
}
// use this instead of Pair to avoid boxing
private data class LongAndInt(val l: Long, var i: Int)
}

View File

@@ -0,0 +1,66 @@
/*
* 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.formatter.ast
import org.pkl.formatter.Generator
enum class Wrap {
ENABLED,
DETECT;
fun isEnabled(): Boolean = this == ENABLED
}
sealed interface FormatNode {
fun width(wrapped: Set<Int>): Int =
when (this) {
is Nodes -> nodes.sumOf { it.width(wrapped) }
is Group -> nodes.sumOf { it.width(wrapped) }
is Indent -> nodes.sumOf { it.width(wrapped) }
is ForceWrap -> nodes.sumOf { it.width(wrapped + id) }
is IfWrap -> if (id in wrapped) ifWrap.width(wrapped) else ifNotWrap.width(wrapped)
is Text -> text.length
is SpaceOrLine,
is Space -> 1
is ForceLine,
is MultilineStringGroup -> Generator.MAX
else -> 0
}
}
data class Text(val text: String) : FormatNode
object Empty : FormatNode
object Line : FormatNode
object ForceLine : FormatNode
object SpaceOrLine : FormatNode
object Space : FormatNode
data class Indent(val nodes: List<FormatNode>) : FormatNode
data class Nodes(val nodes: List<FormatNode>) : FormatNode
data class Group(val id: Int, val nodes: List<FormatNode>) : FormatNode
data class ForceWrap(val id: Int, val nodes: List<FormatNode>) : FormatNode
data class MultilineStringGroup(val endQuoteCol: Int, val nodes: List<FormatNode>) : FormatNode
data class IfWrap(val id: Int, val ifWrap: FormatNode, val ifNotWrap: FormatNode) : FormatNode

View File

@@ -0,0 +1,10 @@
class Foo {
}
class Bar
{
qux = 1
}
class Baz { prop = 0; prop2 = 1 }

View File

@@ -0,0 +1,16 @@
function fun(a, b, c, d) = a
noTrailingCommas = fun(1, 2, 3, 4,)
trailingCommas = fun("loooooooooooooooooooongString", "loooooooooooooooongString", "looooooooooooooooongString", "notTooLong")
noTrailingCommaObjParams {
fooooooooooooooooooooooooooooooooo, baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaar, baaaaaaaaaaaaaaaaaaaaaz ->
1 + 1
}
trailingCommaInLambdas = (fooooooooooooooooooooooooooooooooo, baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaar, baaaaaaaaaaaaaaaaaaaaaz) -> 1
trailingCommaInConstraints: String(isSomethingSomethingSomething, isSomethingElse, isSomethingSomethingSomethingElse)
trailingCommaInTypeParameters: Mapping<SomethingSomethingSomethingSomething, SomethingSomething | SomethingElse>

View File

@@ -0,0 +1,31 @@
module comment.interleaved
local test: Int|String =
if (true)
1 // It's the same as "100%"
else
"8%"
foo: ( // some comment
* String(
// if dtstart is defined and a datetime, until must also be a datetime if defined
true
)
|Int
// trailing comment
)?
foo2: (// some comment
Int, // other comment
String
) ->Int
bar = ( // some comment
10 + 10
// another comment
)
bar2 = ( // some comment
foo, bar
// another comment
) -> foo + bar

View File

@@ -0,0 +1,8 @@
module dangling
/// Doc comment.
///
/// for this field
// sepearted by a stray comment
/// but continues here.
some: String

View File

@@ -0,0 +1,14 @@
//// line 1
///// line 2
foo = 1
/// line 1
///
///
/// line 2
bar = 1
///line 1
///line 2
baz = 1

View File

@@ -0,0 +1,25 @@
foo {
123123123123 + 123123123123 * 123123123123 - 123123123123 / 123123123123 + 123123123123 ** 123123123123
2
3
4
}
bar = clazz.superclass == null || clazz.superclass.reflectee == Module || clazz.superclass.reflectee == Typed
baz =
new Listing {
1
2
} |> mixin1 |> mixin2
qux =
(baz) {
1
2
} {
3
4
}
minus = superLoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongVariable - 100000

View File

@@ -0,0 +1,5 @@
res = myList.map((it) -> it.partition).filter((it) -> someList.contains(it))
res2 = myList.map(lambda1).filter(lambda2)
res3 = myList.map((it) -> it.partition)

View File

@@ -0,0 +1,7 @@
foo =
if (someCondition) 10000
else
if (someOtherCondition) 20000
else
if (someAnotherCondition) 30000
else 4

View File

@@ -0,0 +1,11 @@
foo = let (vaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaariable = 10) 1 * 1
bar = let (someVariable = new Listing {
1
}) 1 * 1
baz =
let (someVariable = 10000000)
let (someOtherVariable = 2000000)
let (someAnotherVariable = 3000000) someVariable + someOtherVariable + someAnotherVariable

View File

@@ -0,0 +1,19 @@
// top level comment
import "@foo/Foo.pkl" as foo
import* "**.pkl"
import "pkl:math"
import "package://example.com/myPackage@1.0.0#/Qux.pkl"
import* "file:///tmp/*.pkl"
import "https://example.com/baz.pkl"
import "module2.pkl"
import "pkl:reflect"
import "..."
import* "@foo/**.pkl"
import "@bar/Bar.pkl"
import "Module12.pkl"
import "module11.pkl"
import "module1.pkl"

View File

@@ -0,0 +1,51 @@
foo = new {
bar = 1
}
class Foo {
baz: Int
}
bar =
new Listing {
1
2
}
baz =
(foo) {
2
3
}
qux =
(x, y) -> new Listing {
x
y
}
forGen = new Listing {
for (someVar in new Listing {
1
2
}) {
[someVar] = someVar
}
}
objParams: Listing<Int> =
new {
default {
key -> key + 1
}
}
objParams2: Listing<Int> = new {
default { someVeryLongParameter1, someVeryLongParameter2, someVeryLongParameter3, someVeryLongParameter4 ->
1
}
}
parenType: (ReaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaalyLongType(reaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaalylongConstraint))
functionType: (ReaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaalyLongType,ReaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaalyLongType2) -> String

View File

@@ -0,0 +1,64 @@
module
foo.bar.baz
amends
"bar.pkl"
import
"@foo/Foo.pkl"
as foo
local
open
class Bar {}
const
local
baz = 10
local
function
fun(x) =
x
const local prooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooperty: String = "foo"
local function function2(parameter1: Parameter1Type, parameter2: Parameter2Type, parameter3: Parameter3Type, parameter4: Parameter4Type): String = ""
local const function function3(parameter1: String|Int, parameter2: String|Int): Mapping<String|Int, String> =
new {}
prop = function2(loooooooooooooooooogParameter1, loooooooooooooooooogParameter2, loooooooooooooooooogParameter3, loooooooooooooooooogParameter4)
prop2: String
|Int
|Boolean
funcParam = fun(
(x, y) -> new Listing {
x
y
})
funcParam2 = aFun(foo, 10 * 10, anotherVariable, if (true) 100000 else 200000, (param1, param2) -> param1 * param2)
funcParam3 = aFun(foo, 10 * 10, anotherVariable, 200000, (param1, param2) -> param1 * param2)
funcParam4 = aFun(foo, 10 * 10, anotherVariable, if (true) 100000 else 200000, new Listing {
1
2
})
open local class SomeReallyInterestingClassName<in SomeInParameter, out SomeOutParameter> extends AnotherInterestingClassName {
foo: Int
}
local function resourceMapping(type): Mapping<String, unknown> =
new Mapping { default = (key) -> (type) { metadata { name = key } } }
local const function biiiiiiiiiiiiiiiiiiiiiiiiigFunction(param1: String, param2: String(!isBlank)): Boolean
local const function someFunction(param1: String, param2: String(!isBlank)): Boolean
local function render(currentIndent: String) =
"\(currentIndent)@\(identifier.render(currentIndent))" +
if (body == null) "" else " " + body.render(currentIndent)

View File

@@ -0,0 +1,20 @@
module reaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaly.loooooooooooooooooooooooooooooooog.naaaaaaaaaaaaaaaaaaaaaaaaaame
extends "reaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaalyLongModule.pkl"
import "reaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaalyLongModule.pkl" as foo
local open class LoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongName {}
local open class ReaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaalyLongName {}
const hidden loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooogName = 99
const hidden reallyLoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooogName = 99
const local function looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooogName(x: Int, y) = x + y
typealias Foo = LooooooooooooooooooooooooongTypeName|AnotherLooooooooooooooooooooooooongTypeName|OtherLooooooooooooooooooooooooongTypeName
bar: Boolean|Mapping<LooooooooooooooooooooooooooooongTypeName, AnotherLooooooooooooooooooooooooooooongTypeName>(loooooooooooooooooooogConstraint)
hidden foobar: LongType(someVeryyyyyyyloooong, requirements.might.be.even_loooooooooooooooooooooooooooooooooooooooooooooooooooooooooonger)

View File

@@ -0,0 +1,18 @@
module reaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaly.loooooooooooooooooooooooooooooooog.naaaaaaaaaaaaaaaaaaaaaaaaaaaaame
extends "reaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaalyLongModule.pkl"
local reallyLongVariableName = true
local anotherReallyLongName = 1
local evenLongerVariableName = 2
/// this property has a reaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaly long doc comment
property = if (reallyLongVariableName) anotherReallyLongName else evenLongerVariableName + anotherReallyLongName
longString = "reaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaly long string"
shortProperty = 1
reaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaalyLongVariableName = 10
reaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaalyLongVariableName2 =
if (reallyLongVariableName) anotherReallyLongName else evenLongerVariableName + anotherReallyLongName

View File

@@ -0,0 +1,4 @@
foo = Map(1000, "some random string", 20000, "another random string", 30000, "yet another random string")
incorrect = Map("This has", 1000000, "an incorrect number", 2000000, "of parameters", 30000000, "passed to Map")

View File

@@ -0,0 +1,3 @@
hidden const foo = 1
open local class Foo {}

View File

@@ -0,0 +1,13 @@
// comment
// one
/// doc comment
open
module
foo
.bar
amends
"baz.pkl"

View File

@@ -0,0 +1,29 @@
foo = """
asd \(new {
bar = 1
}) asd
"""
bar = """
line 1
line 2
line3
"""
baz = """
\n
\(bar)
line
\u{123}
"""
// remove unneeded spaces
qux = """
foo
bar
baz
\(foo)
"""

View File

@@ -0,0 +1,22 @@
foo: Listing<Int> = new {1 2 3; 4;5 6 7}
bar: Listing<Int> = new { 1 2
3
4
}
lineIsTooBig: Listing<Int> = new { 999999; 1000000; 1000001; 1000002; 1000003; 1000004; 1000005; 1000006; 1000007; 1000008; 1000009 }
lineIsTooBig2 { 999999; 1000000; 1000001; 1000002; 1000003; 1000004; 1000005; 1000006; 1000007; 1000008; 1000009; 1000010 }
baz = new Dynamic {
1 2
3 4
["foo"] = 3; bar = 30
baz = true
}
qux = new Dynamic {1 2 3 prop="prop"; [0]=9}

View File

@@ -0,0 +1,12 @@
/// Looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong doc comment
@Annotation { looooooooooooooooooooooooooooooooooooooooooooooooooongVariableName = 10 }
typealias Foo = String
/// Looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong doc comment
@Annotation { looooooooooooooooooooooooooooooooooooooooooooooooooongVariableName = 10 }
foo = "should fit in a single line"
/// Looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong doc comment
@Annotation { looooooooooooooooooooooooooooooooooooooooooooooooooongVariableName = 10 }
function bar(x): String = "result: \(x)"

View File

@@ -0,0 +1,23 @@
import"foo.pkl"
bar=new Listing < Int > ( !isEmpty ){1;2}//a bar
typealias Typealias=(String,Int)->Boolean
///a baz
///returns its parameter
baz = (x,y,z)->x+y+z
function fun ( x:Int ? ,b :Boolean )= if(b)/***return x**/x else x+bar [0 ]
prop = trace (1) + super . foo + module .foo
prop2 {
for(x in List(1)) {
when(x == 1){
x
}
}
}
choices: "foo" | * "bar" | String

View File

@@ -0,0 +1,6 @@
typealias
Foo
=
String
typealias VeryLoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongTypeAlias = String(!isEmpty)

View File

@@ -0,0 +1,9 @@
foo {
when (true)
{
bar = 1
}
else {
bar = 2
}
}

View File

@@ -0,0 +1,11 @@
class Foo {}
class Bar {
qux = 1
}
class Baz {
prop = 0
prop2 = 1
}

View File

@@ -0,0 +1,35 @@
function fun(a, b, c, d) = a
noTrailingCommas = fun(1, 2, 3, 4)
trailingCommas =
fun(
"loooooooooooooooooooongString",
"loooooooooooooooongString",
"looooooooooooooooongString",
"notTooLong",
)
noTrailingCommaObjParams {
fooooooooooooooooooooooooooooooooo,
baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaar,
baaaaaaaaaaaaaaaaaaaaaz ->
1 + 1
}
trailingCommaInLambdas = (
fooooooooooooooooooooooooooooooooo,
baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaar,
baaaaaaaaaaaaaaaaaaaaaz,
) -> 1
trailingCommaInConstraints: String(
isSomethingSomethingSomething,
isSomethingElse,
isSomethingSomethingSomethingElse,
)
trailingCommaInTypeParameters: Mapping<
SomethingSomethingSomethingSomething,
SomethingSomething | SomethingElse,
>

View File

@@ -0,0 +1,34 @@
module comment.interleaved
local test: Int | String =
if (true)
1 // It's the same as "100%"
else
"8%"
foo: ( // some comment
*String(
// if dtstart is defined and a datetime, until must also be a datetime if defined
true,
)
| Int
// trailing comment
)?
foo2: ( // some comment
Int, // other comment
String,
) ->
Int
bar =
( // some comment
10 + 10
// another comment
)
bar2 = ( // some comment
foo,
bar
// another comment
) -> foo + bar

View File

@@ -0,0 +1,8 @@
module dangling
/// Doc comment.
///
/// for this field
// sepearted by a stray comment
/// but continues here.
some: String

View File

@@ -0,0 +1,13 @@
/// / line 1
/// // line 2
foo = 1
/// line 1
///
///
/// line 2
bar = 1
/// line 1
/// line 2
baz = 1

View File

@@ -0,0 +1,34 @@
foo {
123123123123
+ 123123123123 * 123123123123 -
123123123123 / 123123123123
+ 123123123123 ** 123123123123
2
3
4
}
bar =
clazz.superclass == null
|| clazz.superclass.reflectee == Module
|| clazz.superclass.reflectee == Typed
baz =
new Listing {
1
2
}
|> mixin1
|> mixin2
qux = (baz) {
1
2
} {
3
4
}
minus =
superLoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongVariable -
100000

View File

@@ -0,0 +1,8 @@
res =
myList
.map((it) -> it.partition)
.filter((it) -> someList.contains(it))
res2 = myList.map(lambda1).filter(lambda2)
res3 = myList.map((it) -> it.partition)

View File

@@ -0,0 +1,9 @@
foo =
if (someCondition)
10000
else if (someOtherCondition)
20000
else if (someAnotherCondition)
30000
else
4

View File

@@ -0,0 +1,18 @@
foo =
let (vaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaariable =
10
)
1 * 1
bar =
let (someVariable = new Listing {
1
}
)
1 * 1
baz =
let (someVariable = 10000000)
let (someOtherVariable = 2000000)
let (someAnotherVariable = 3000000)
someVariable + someOtherVariable + someAnotherVariable

View File

@@ -0,0 +1,21 @@
// top level comment
import "https://example.com/baz.pkl"
import "package://example.com/myPackage@1.0.0#/Qux.pkl"
import "pkl:math"
import "pkl:reflect"
import "@bar/Bar.pkl"
import "@foo/Foo.pkl" as foo
import "..."
import "module1.pkl"
import "module2.pkl"
import "module11.pkl"
import "Module12.pkl"
import* "file:///tmp/*.pkl"
import* "@foo/**.pkl"
import* "**.pkl"

View File

@@ -0,0 +1,61 @@
foo = new {
bar = 1
}
class Foo {
baz: Int
}
bar = new Listing {
1
2
}
baz = (foo) {
2
3
}
qux = (x, y) -> new Listing {
x
y
}
forGen = new Listing {
for (
someVar in new Listing {
1
2
}
) {
[someVar] = someVar
}
}
objParams: Listing<Int> = new {
default { key ->
key + 1
}
}
objParams2: Listing<Int> = new {
default {
someVeryLongParameter1,
someVeryLongParameter2,
someVeryLongParameter3,
someVeryLongParameter4 ->
1
}
}
parenType: (
ReaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaalyLongType(
reaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaalylongConstraint,
)
)
functionType: (
ReaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaalyLongType,
ReaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaalyLongType2,
) ->
String

View File

@@ -0,0 +1,75 @@
module foo.bar.baz
amends "bar.pkl"
import "@foo/Foo.pkl" as foo
open local class Bar {}
local const baz = 10
local function fun(x) = x
local const prooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooperty: String =
"foo"
local function function2(
parameter1: Parameter1Type,
parameter2: Parameter2Type,
parameter3: Parameter3Type,
parameter4: Parameter4Type,
): String = ""
local const function function3(
parameter1: String | Int,
parameter2: String | Int,
): Mapping<String | Int, String> = new {}
prop =
function2(
loooooooooooooooooogParameter1,
loooooooooooooooooogParameter2,
loooooooooooooooooogParameter3,
loooooooooooooooooogParameter4,
)
prop2: String | Int | Boolean
funcParam =
fun((x, y) -> new Listing {
x
y
})
funcParam2 =
aFun(foo, 10 * 10, anotherVariable, if (true) 100000 else 200000, (param1, param2) ->
param1 * param2
)
funcParam3 = aFun(foo, 10 * 10, anotherVariable, 200000, (param1, param2) -> param1 * param2)
funcParam4 =
aFun(foo, 10 * 10, anotherVariable, if (true) 100000 else 200000, new Listing {
1
2
})
open local class SomeReallyInterestingClassName<in SomeInParameter, out SomeOutParameter>
extends AnotherInterestingClassName {
foo: Int
}
local function resourceMapping(type): Mapping<String, unknown> = new Mapping {
default = (key) -> (type) { metadata { name = key } }
}
local const function biiiiiiiiiiiiiiiiiiiiiiiiigFunction(
param1: String,
param2: String(!isBlank),
): Boolean
local const function someFunction(param1: String, param2: String(!isBlank)): Boolean
local function render(currentIndent: String) =
"\(currentIndent)@\(identifier.render(currentIndent))"
+ if (body == null) "" else " " + body.render(currentIndent)

View File

@@ -0,0 +1,42 @@
module
reaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaly
.loooooooooooooooooooooooooooooooog
.naaaaaaaaaaaaaaaaaaaaaaaaaame
extends
"reaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaalyLongModule.pkl"
import
"reaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaalyLongModule.pkl"
as foo
open local class LoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongName {}
open local class ReaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaalyLongName {}
hidden const loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooogName =
99
hidden const reallyLoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooogName =
99
local const function looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooogName(
x: Int,
y,
) = x + y
typealias Foo =
LooooooooooooooooooooooooongTypeName
| AnotherLooooooooooooooooooooooooongTypeName
| OtherLooooooooooooooooooooooooongTypeName
bar: Boolean
| Mapping<
LooooooooooooooooooooooooooooongTypeName,
AnotherLooooooooooooooooooooooooooooongTypeName,
>(loooooooooooooooooooogConstraint)
hidden foobar: LongType(
someVeryyyyyyyloooong,
requirements.might.be.even_loooooooooooooooooooooooooooooooooooooooooooooooooooooooooonger,
)

View File

@@ -0,0 +1,32 @@
module
reaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaly
.loooooooooooooooooooooooooooooooog
.naaaaaaaaaaaaaaaaaaaaaaaaaaaaame
extends
"reaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaalyLongModule.pkl"
local reallyLongVariableName = true
local anotherReallyLongName = 1
local evenLongerVariableName = 2
/// this property has a reaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaly long doc comment
property =
if (reallyLongVariableName)
anotherReallyLongName
else
evenLongerVariableName + anotherReallyLongName
longString =
"reaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaly long string"
shortProperty = 1
reaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaalyLongVariableName =
10
reaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaalyLongVariableName2 =
if (reallyLongVariableName)
anotherReallyLongName
else
evenLongerVariableName + anotherReallyLongName

View File

@@ -0,0 +1,14 @@
foo =
Map(
1000, "some random string",
20000, "another random string",
30000, "yet another random string",
)
incorrect =
Map(
"This has", 1000000,
"an incorrect number", 2000000,
"of parameters", 30000000,
"passed to Map",
)

View File

@@ -0,0 +1,3 @@
hidden const foo = 1
open local class Foo {}

View File

@@ -0,0 +1,7 @@
// comment
// one
/// doc comment
open module foo.bar
amends "baz.pkl"

View File

@@ -0,0 +1,33 @@
foo =
"""
asd \(new {
bar = 1
}) asd
"""
bar =
"""
line 1
line 2
line3
"""
baz =
"""
\n
\(bar)
line
\u{123}
"""
// remove unneeded spaces
qux =
"""
foo
bar
baz
\(foo)
"""

View File

@@ -0,0 +1,51 @@
foo: Listing<Int> = new { 1; 2; 3; 4; 5; 6; 7 }
bar: Listing<Int> = new {
1
2
3
4
}
lineIsTooBig: Listing<Int> = new {
999999
1000000
1000001
1000002
1000003
1000004
1000005
1000006
1000007
1000008
1000009
}
lineIsTooBig2 {
999999
1000000
1000001
1000002
1000003
1000004
1000005
1000006
1000007
1000008
1000009
1000010
}
baz = new Dynamic {
1
2
3
4
["foo"] = 3
bar = 30
baz = true
}
qux = new Dynamic { 1; 2; 3; prop = "prop"; [0] = 9 }

View File

@@ -0,0 +1,11 @@
/// Looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong doc comment
@Annotation { looooooooooooooooooooooooooooooooooooooooooooooooooongVariableName = 10 }
typealias Foo = String
/// Looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong doc comment
@Annotation { looooooooooooooooooooooooooooooooooooooooooooooooooongVariableName = 10 }
foo = "should fit in a single line"
/// Looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong doc comment
@Annotation { looooooooooooooooooooooooooooooooooooooooooooooooooongVariableName = 10 }
function bar(x): String = "result: \(x)"

View File

@@ -0,0 +1,23 @@
import "foo.pkl"
bar = new Listing<Int>(!isEmpty) { 1; 2 } //a bar
typealias Typealias = (String, Int) -> Boolean
/// a baz
/// returns its parameter
baz = (x, y, z) -> x + y + z
function fun(x: Int?, b: Boolean) = if (b) /***return x**/ x else x + bar[0]
prop = trace(1) + super.foo + module.foo
prop2 {
for (x in List(1)) {
when (x == 1) {
x
}
}
}
choices: "foo" | *"bar" | String

View File

@@ -0,0 +1,4 @@
typealias Foo = String
typealias VeryLoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongTypeAlias =
String(!isEmpty)

View File

@@ -0,0 +1,7 @@
foo {
when (true) {
bar = 1
} else {
bar = 2
}
}

View File

@@ -0,0 +1,20 @@
/*
* 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.formatter
import org.junit.platform.commons.annotation.Testable
@Testable class FormatterSnippetTests

View File

@@ -0,0 +1,73 @@
/*
* 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.formatter
import java.nio.file.Path
import kotlin.io.path.isRegularFile
import kotlin.reflect.KClass
import org.pkl.commons.test.InputOutputTestEngine
import org.pkl.parser.ParserError
abstract class AbstractFormatterSnippetTestsEngine : InputOutputTestEngine() {
private val snippetsDir: Path =
rootProjectDir.resolve("pkl-formatter/src/test/files/FormatterSnippetTests")
private val expectedOutputDir: Path = snippetsDir.resolve("output")
/** Convenience for development; this selects which snippet test(s) to run. */
// language=regexp
internal val selection: String = ""
override val includedTests: List<Regex> = listOf(Regex(".*$selection\\.pkl"))
override val inputDir: Path = snippetsDir.resolve("input")
override val isInputFile: (Path) -> Boolean = { it.isRegularFile() }
override fun expectedOutputFileFor(inputFile: Path): Path {
val relativePath = relativize(inputFile, inputDir).toString()
return expectedOutputDir.resolve(relativePath)
}
companion object {
private fun relativize(path: Path, base: Path): Path {
if (System.getProperty("os.name").contains("Windows")) {
if (path.isAbsolute && base.isAbsolute && (path.root != base.root)) {
return path
}
}
return base.relativize(path)
}
}
}
class FormatterSnippetTestsEngine : AbstractFormatterSnippetTestsEngine() {
override val testClass: KClass<*> = FormatterSnippetTests::class
override fun generateOutputFor(inputFile: Path): Pair<Boolean, String> {
val formatter = Formatter()
val (success, output) =
try {
val res = formatter.format(inputFile)
true to res
} catch (_: ParserError) {
false to ""
}
return success to output
}
}

View File

@@ -0,0 +1,79 @@
/*
* 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.formatter
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import org.pkl.parser.GenericParserError
class FormatterTest {
@Test
fun `multiline string - wrong start quote`() {
val ex =
assertThrows<GenericParserError> {
format(
"""
foo = ""${'"'}line1
line 2
""${'"'}
"""
)
}
assertThat(ex.message).contains("The content of a multi-line string must begin on a new line")
}
@Test
fun `multiline string - wrong end quote`() {
val ex =
assertThrows<GenericParserError> {
format(
"""
foo = ""${'"'}
line1
line 2""${'"'}
"""
)
}
assertThat(ex.message)
.contains("The closing delimiter of a multi-line string must begin on a new line")
}
@Test
fun `multiline string - wrong indentation`() {
val ex =
assertThrows<GenericParserError> {
format(
"""
foo = ""${'"'}
line1
line 2
""${'"'}
"""
)
}
assertThat(ex.message)
.contains("Line must match or exceed indentation of the String's last line.")
}
private fun format(code: String): String {
return Formatter().format(code.trimIndent())
}
}

View File

@@ -0,0 +1 @@
org.pkl.formatter.FormatterSnippetTestsEngine

View File

@@ -13,7 +13,7 @@ com.github.ajalt.mordant:mordant-jvm:3.0.1=compileClasspath
com.github.ajalt.mordant:mordant:3.0.1=compileClasspath,compileOnlyDependenciesMetadata
net.bytebuddy:byte-buddy:1.15.11=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath,testImplementationDependenciesMetadata
org.assertj:assertj-core:3.27.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.assertj:assertj-core:3.27.4=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
@@ -35,12 +35,12 @@ org.jetbrains.kotlin:kotlin-stdlib-jdk8:2.0.21=compileClasspath,compileOnlyDepen
org.jetbrains.kotlin:kotlin-stdlib:2.0.21=compileClasspath,compileOnlyDependenciesMetadata,kotlinBuildToolsApiClasspath,kotlinCompilerClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinKlibCommonizerClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.4=kotlinBuildToolsApiClasspath,kotlinCompilerClasspath,kotlinKlibCommonizerClasspath
org.jetbrains:annotations:13.0=compileClasspath,kotlinBuildToolsApiClasspath,kotlinCompilerClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinKlibCommonizerClasspath,testCompileClasspath,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-api:5.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-engine:5.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-params:5.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-commons:1.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-engine:1.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-launcher:1.13.3=testRuntimeClasspath
org.junit:junit-bom:5.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-api:5.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-engine:5.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-params:5.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-commons:1.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-engine:1.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-launcher:1.13.4=testRuntimeClasspath
org.junit:junit-bom:5.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.opentest4j:opentest4j:1.3.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
empty=annotationProcessor,apiDependenciesMetadata,implementationDependenciesMetadata,intransitiveDependenciesMetadata,kotlinCompilerPluginClasspath,kotlinNativeCompilerPluginClasspath,kotlinScriptDefExtensions,runtimeClasspath,signatures,sourcesJar,testAnnotationProcessor,testApiDependenciesMetadata,testCompileOnlyDependenciesMetadata,testIntransitiveDependenciesMetadata,testKotlinScriptDefExtensions

View File

@@ -4,7 +4,7 @@
com.google.code.findbugs:jsr305:3.0.2=compileClasspath,compileOnlyDependenciesMetadata
net.bytebuddy:byte-buddy:1.15.11=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath,testImplementationDependenciesMetadata
org.assertj:assertj-core:3.27.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.assertj:assertj-core:3.27.4=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
@@ -26,12 +26,12 @@ org.jetbrains.kotlin:kotlin-stdlib-jdk8:2.0.21=testCompileClasspath,testImplemen
org.jetbrains.kotlin:kotlin-stdlib:2.0.21=kotlinBuildToolsApiClasspath,kotlinCompilerClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinKlibCommonizerClasspath,testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.4=kotlinBuildToolsApiClasspath,kotlinCompilerClasspath,kotlinKlibCommonizerClasspath
org.jetbrains:annotations:13.0=kotlinBuildToolsApiClasspath,kotlinCompilerClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinKlibCommonizerClasspath,testCompileClasspath,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-api:5.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-engine:5.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-params:5.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-commons:1.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-engine:1.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-launcher:1.13.3=testRuntimeClasspath
org.junit:junit-bom:5.13.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-api:5.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-engine:5.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-params:5.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-commons:1.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-engine:1.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.junit.platform:junit-platform-launcher:1.13.4=testRuntimeClasspath
org.junit:junit-bom:5.13.4=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.opentest4j:opentest4j:1.3.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
empty=annotationProcessor,apiDependenciesMetadata,implementationDependenciesMetadata,intransitiveDependenciesMetadata,kotlinCompilerPluginClasspath,kotlinNativeCompilerPluginClasspath,kotlinScriptDefExtensions,runtimeClasspath,signatures,sourcesJar,testAnnotationProcessor,testApiDependenciesMetadata,testCompileOnlyDependenciesMetadata,testIntransitiveDependenciesMetadata,testKotlinScriptDefExtensions

Some files were not shown because too many files have changed in this diff Show More