mirror of
https://github.com/apple/pkl.git
synced 2026-03-17 23:03:54 +01:00
Apply pkl formatter to codebase (#1236)
This applies the Pkl formatter to `stdlib/` and `.circleci/`
This commit is contained in:
@@ -17,8 +17,8 @@
|
||||
amends "package://pkg.pkl-lang.org/pkl-project-commons/pkl.impl.circleci@1.2.0#/PklCI.pkl"
|
||||
|
||||
import "jobs/BuildNativeJob.pkl"
|
||||
import "jobs/GradleCheckJob.pkl"
|
||||
import "jobs/DeployJob.pkl"
|
||||
import "jobs/GradleCheckJob.pkl"
|
||||
import "jobs/SimpleGradleJob.pkl"
|
||||
|
||||
local prbJobs: Listing<String> = gradleCheckJobs.keys.toListing()
|
||||
@@ -130,18 +130,21 @@ jobs {
|
||||
[jobName] = job.job
|
||||
}
|
||||
["bench"] = new SimpleGradleJob { command = "bench:jmh" }.job
|
||||
["gradle-compatibility"] = new SimpleGradleJob {
|
||||
name = "gradle compatibility"
|
||||
command = #"""
|
||||
:pkl-gradle:build \
|
||||
:pkl-gradle:compatibilityTestReleases
|
||||
"""#
|
||||
}.job
|
||||
["gradle-compatibility"] =
|
||||
new SimpleGradleJob {
|
||||
name = "gradle compatibility"
|
||||
command =
|
||||
#"""
|
||||
:pkl-gradle:build \
|
||||
:pkl-gradle:compatibilityTestReleases
|
||||
"""#
|
||||
}.job
|
||||
["deploy-snapshot"] = new DeployJob { command = "publishToSonatype" }.job
|
||||
["deploy-release"] = new DeployJob {
|
||||
isRelease = true
|
||||
command = "publishToSonatype closeAndReleaseSonatypeStagingRepository"
|
||||
}.job
|
||||
["deploy-release"] =
|
||||
new DeployJob {
|
||||
isRelease = true
|
||||
command = "publishToSonatype closeAndReleaseSonatypeStagingRepository"
|
||||
}.job
|
||||
["github-release"] {
|
||||
docker {
|
||||
new { image = "maniator/gh:v2.40.1" }
|
||||
@@ -150,7 +153,8 @@ jobs {
|
||||
new AttachWorkspaceStep { at = "." }
|
||||
new RunStep {
|
||||
name = "Publish release on GitHub"
|
||||
command = #"""
|
||||
command =
|
||||
#"""
|
||||
# exclude build_artifacts.txt from publish
|
||||
rm -f */build/executable/*.build_artifacts.txt
|
||||
find */build/executable/* -type d | xargs rm -rf
|
||||
|
||||
@@ -19,7 +19,7 @@ extends "GradleJob.pkl"
|
||||
import "package://pkg.pkl-lang.org/pkl-pantry/com.circleci.v2@1.5.0#/Config.pkl"
|
||||
|
||||
/// The architecture to use
|
||||
arch: "amd64"|"aarch64"
|
||||
arch: "amd64" | "aarch64"
|
||||
|
||||
/// Whether to link to musl. Otherwise, links to glibc.
|
||||
musl: Boolean = false
|
||||
@@ -44,40 +44,45 @@ local setupLinuxEnvironment: Config.RunStep =
|
||||
new {
|
||||
name = "Set up environment"
|
||||
shell = "#!/bin/bash -exo pipefail"
|
||||
command = new Listing {
|
||||
#"""
|
||||
sed -ie '/\[ol8_codeready_builder\]/,/^$/s/enabled=0/enabled=1/g' /etc/yum.repos.d/oracle-linux-ol8.repo \
|
||||
&& microdnf -y install util-linux tree coreutils-single findutils curl tar gzip git zlib-devel gcc-c++ make openssl glibc-langpack-en libstdc++-static \
|
||||
&& microdnf clean all \
|
||||
&& rm -rf /var/cache/dnf
|
||||
command =
|
||||
new Listing {
|
||||
#"""
|
||||
sed -ie '/\[ol8_codeready_builder\]/,/^$/s/enabled=0/enabled=1/g' /etc/yum.repos.d/oracle-linux-ol8.repo \
|
||||
&& microdnf -y install util-linux tree coreutils-single findutils curl tar gzip git zlib-devel gcc-c++ make openssl glibc-langpack-en libstdc++-static \
|
||||
&& microdnf clean all \
|
||||
&& rm -rf /var/cache/dnf
|
||||
|
||||
# install jdk
|
||||
curl -Lf \
|
||||
https://github.com/adoptium/temurin\#(module.majorJdkVersion)-binaries/releases/download/\#(module.jdkGitHubReleaseName)/OpenJDK\#(module.majorJdkVersion)U-jdk_\#(if (arch == "amd64") "x64" else "aarch64")_linux_hotspot_\#(module.jdkVersionAlt).tar.gz -o /tmp/jdk.tar.gz
|
||||
# install jdk
|
||||
curl -Lf \
|
||||
https://github.com/adoptium/temurin\#(module.majorJdkVersion)-binaries/releases/download/\#(module
|
||||
.jdkGitHubReleaseName)/OpenJDK\#(module.majorJdkVersion)U-jdk_\#(if (arch == "amd64")
|
||||
"x64"
|
||||
else
|
||||
"aarch64")_linux_hotspot_\#(module.jdkVersionAlt).tar.gz -o /tmp/jdk.tar.gz
|
||||
|
||||
mkdir /jdk \
|
||||
&& cd /jdk \
|
||||
&& cat /tmp/jdk.tar.gz | tar --strip-components=1 -xzC .
|
||||
mkdir /jdk \
|
||||
&& cd /jdk \
|
||||
&& cat /tmp/jdk.tar.gz | tar --strip-components=1 -xzC .
|
||||
|
||||
mkdir -p ~/staticdeps/bin
|
||||
mkdir -p ~/staticdeps/bin
|
||||
|
||||
cp /usr/lib/gcc/\#(if (arch == "amd64") "x86_64" else "aarch64")-redhat-linux/8/libstdc++.a ~/staticdeps
|
||||
cp /usr/lib/gcc/\#(if (arch == "amd64") "x86_64" else "aarch64")-redhat-linux/8/libstdc++.a ~/staticdeps
|
||||
|
||||
# install zlib
|
||||
if [[ ! -f ~/staticdeps/include/zlib.h ]]; then
|
||||
curl -Lf https://github.com/madler/zlib/releases/download/v\#(zlibVersion)/zlib-\#(zlibVersion).tar.gz -o /tmp/zlib.tar.gz
|
||||
# install zlib
|
||||
if [[ ! -f ~/staticdeps/include/zlib.h ]]; then
|
||||
curl -Lf https://github.com/madler/zlib/releases/download/v\#(zlibVersion)/zlib-\#(zlibVersion).tar.gz -o /tmp/zlib.tar.gz
|
||||
|
||||
mkdir -p /tmp/dep_zlib-\#(zlibVersion) \
|
||||
&& cd /tmp/dep_zlib-\#(zlibVersion) \
|
||||
&& cat /tmp/zlib.tar.gz | tar --strip-components=1 -xzC . \
|
||||
&& echo "zlib-\#(zlibVersion): configure..." && ./configure --static --prefix="$HOME"/staticdeps > /dev/null \
|
||||
&& echo "zlib-\#(zlibVersion): make..." && make -s -j4 \
|
||||
&& echo "zlib-\#(zlibVersion): make install..." && make -s install \
|
||||
&& rm -rf /tmp/dep_zlib-\#(zlibVersion)
|
||||
fi
|
||||
"""#
|
||||
// don't need musl on aarch because GraalVM only supports musl builds on x86
|
||||
when (arch == "amd64") {
|
||||
mkdir -p /tmp/dep_zlib-\#(zlibVersion) \
|
||||
&& cd /tmp/dep_zlib-\#(zlibVersion) \
|
||||
&& cat /tmp/zlib.tar.gz | tar --strip-components=1 -xzC . \
|
||||
&& echo "zlib-\#(zlibVersion): configure..." && ./configure --static --prefix="$HOME"/staticdeps > /dev/null \
|
||||
&& echo "zlib-\#(zlibVersion): make..." && make -s -j4 \
|
||||
&& echo "zlib-\#(zlibVersion): make install..." && make -s install \
|
||||
&& rm -rf /tmp/dep_zlib-\#(zlibVersion)
|
||||
fi
|
||||
"""#
|
||||
// don't need musl on aarch because GraalVM only supports musl builds on x86
|
||||
when (arch == "amd64") {
|
||||
#"""
|
||||
# install musl
|
||||
if [[ ! -f ~/staticdeps/bin/x86_64-linux-musl-gcc ]]; then
|
||||
@@ -95,25 +100,28 @@ local setupLinuxEnvironment: Config.RunStep =
|
||||
ln -s ~/staticdeps/bin/musl-gcc ~/staticdeps/bin/x86_64-linux-musl-gcc
|
||||
fi
|
||||
"""#
|
||||
}
|
||||
}.join("\n\n")
|
||||
}
|
||||
}.join("\n\n")
|
||||
}
|
||||
|
||||
local setupMacEnvironment: Config.RunStep =
|
||||
new {
|
||||
name = "Set up environment"
|
||||
shell = "#!/bin/bash -exo pipefail"
|
||||
command =
|
||||
#"""
|
||||
# install jdk
|
||||
curl -Lf \
|
||||
https://github.com/adoptium/temurin\#(module.majorJdkVersion)-binaries/releases/download/\#(module.jdkGitHubReleaseName)/OpenJDK\#(module.majorJdkVersion)U-jdk_\#(if (arch == "amd64") "x64" else "aarch64")_mac_hotspot_\#(module.jdkVersionAlt).tar.gz -o /tmp/jdk.tar.gz
|
||||
local setupMacEnvironment: Config.RunStep = new {
|
||||
name = "Set up environment"
|
||||
shell = "#!/bin/bash -exo pipefail"
|
||||
command =
|
||||
#"""
|
||||
# install jdk
|
||||
curl -Lf \
|
||||
https://github.com/adoptium/temurin\#(module.majorJdkVersion)-binaries/releases/download/\#(module
|
||||
.jdkGitHubReleaseName)/OpenJDK\#(module.majorJdkVersion)U-jdk_\#(if (arch == "amd64")
|
||||
"x64"
|
||||
else
|
||||
"aarch64")_mac_hotspot_\#(module.jdkVersionAlt).tar.gz -o /tmp/jdk.tar.gz
|
||||
|
||||
mkdir $HOME/jdk \
|
||||
&& cd $HOME/jdk \
|
||||
&& cat /tmp/jdk.tar.gz | tar --strip-components=1 -xzC .
|
||||
"""#
|
||||
}
|
||||
mkdir $HOME/jdk \
|
||||
&& cd $HOME/jdk \
|
||||
&& cat /tmp/jdk.tar.gz | tar --strip-components=1 -xzC .
|
||||
"""#
|
||||
}
|
||||
|
||||
steps {
|
||||
when (os == "linux") {
|
||||
@@ -134,7 +142,8 @@ steps {
|
||||
when (arch == "amd64") {
|
||||
new Config.RunStep {
|
||||
name = "Installing Rosetta 2"
|
||||
command = """
|
||||
command =
|
||||
"""
|
||||
/usr/sbin/softwareupdate --install-rosetta --agree-to-license
|
||||
"""
|
||||
}
|
||||
@@ -146,7 +155,8 @@ steps {
|
||||
when (module.os == "windows") {
|
||||
shell = "bash.exe"
|
||||
}
|
||||
command = #"""
|
||||
command =
|
||||
#"""
|
||||
export PATH=~/staticdeps/bin:$PATH
|
||||
./gradlew \#(module.gradleArgs) \#(project):buildNative
|
||||
"""#
|
||||
|
||||
@@ -22,14 +22,12 @@ import "package://pkg.pkl-lang.org/pkl-pantry/pkl.experimental.uri@1.0.3#/URI.pk
|
||||
isRelease: Boolean = false
|
||||
|
||||
/// The OS to run on
|
||||
os: "macOS"|"linux"|"windows"
|
||||
os: "macOS" | "linux" | "windows"
|
||||
|
||||
/// The version of Java to use.
|
||||
javaVersion: "17.0"|"21.0"
|
||||
javaVersion: "17.0" | "21.0"
|
||||
|
||||
fixed javaVersionFull =
|
||||
if (javaVersion == "17.0") "17.0.9+9"
|
||||
else "21.0.5+11"
|
||||
fixed javaVersionFull = if (javaVersion == "17.0") "17.0.9+9" else "21.0.5+11"
|
||||
|
||||
fixed jdkVersionAlt = javaVersionFull.replaceLast("+", "_")
|
||||
|
||||
@@ -38,21 +36,24 @@ fixed majorJdkVersion = javaVersionFull.split(".").first
|
||||
fixed jdkGitHubReleaseName =
|
||||
let (ver =
|
||||
// 17.0.9+9 is missing some binaries (see https://github.com/adoptium/adoptium-support/issues/994)
|
||||
if (javaVersionFull == "17.0.9+9" && os == "windows") "jdk-17.0.9+9.1"
|
||||
else "jdk-\(javaVersionFull)"
|
||||
if (javaVersionFull == "17.0.9+9" && os == "windows")
|
||||
"jdk-17.0.9+9.1"
|
||||
else
|
||||
"jdk-\(javaVersionFull)"
|
||||
)
|
||||
URI.encodeComponent(ver)
|
||||
|
||||
fixed gradleArgs = new Listing {
|
||||
"--info"
|
||||
"--stacktrace"
|
||||
"-DtestReportsDir=${HOME}/test-results"
|
||||
"-DpklMultiJdkTesting=true"
|
||||
when (isRelease) {
|
||||
"-DreleaseBuild=true"
|
||||
}
|
||||
...extraGradleArgs
|
||||
}.join(" ")
|
||||
fixed gradleArgs =
|
||||
new Listing {
|
||||
"--info"
|
||||
"--stacktrace"
|
||||
"-DtestReportsDir=${HOME}/test-results"
|
||||
"-DpklMultiJdkTesting=true"
|
||||
when (isRelease) {
|
||||
"-DreleaseBuild=true"
|
||||
}
|
||||
...extraGradleArgs
|
||||
}.join(" ")
|
||||
|
||||
extraGradleArgs: Listing<String>
|
||||
|
||||
@@ -84,7 +85,8 @@ job: Config.Job = new {
|
||||
new Config.RunStep {
|
||||
name = "Set up environment"
|
||||
shell = "bash.exe"
|
||||
command = #"""
|
||||
command =
|
||||
#"""
|
||||
# install jdk
|
||||
curl -Lf \
|
||||
https://github.com/adoptium/temurin\#(majorJdkVersion)-binaries/releases/download/\#(jdkGitHubReleaseName)/OpenJDK\#(majorJdkVersion)U-jdk_x64_windows_hotspot_\#(jdkVersionAlt).zip -o /tmp/jdk.zip
|
||||
|
||||
@@ -28,7 +28,8 @@ javaVersion = "21.0"
|
||||
steps {
|
||||
new Config.RunStep {
|
||||
name = module.name
|
||||
command = """
|
||||
command =
|
||||
"""
|
||||
./gradlew \(module.gradleArgs) \(module.command)
|
||||
"""
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,9 +1,9 @@
|
||||
–– Pkl Error ––
|
||||
Expected value of type `*RemoteDependency|Project(isValidLoadDependency)`, but got a different `pkl.Project`.
|
||||
Expected value of type `*RemoteDependency | Project(isValidLoadDependency)`, but got a different `pkl.Project`.
|
||||
Value: new ModuleClass { package = null; tests {}; dependencies {}; evaluatorSetting...
|
||||
|
||||
xxx | dependencies: Mapping<String(!contains("/")), *RemoteDependency|Project(isValidLoadDependency)>
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
xxx | dependencies: Mapping<String(!contains("/")), *RemoteDependency | Project(isValidLoadDependency)>
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
at pkl.Project#dependencies (pkl:Project)
|
||||
|
||||
* Value is not of type `Project(isValidLoadDependency)` because:
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
/// * amends this template
|
||||
/// * is named _doc-package-info.pkl_
|
||||
/// * is passed to the _pkldoc_ command together with the modules to generate documentation for.
|
||||
///
|
||||
///
|
||||
/// Each module to generate documentation must declare a module name that starts with a package [name].
|
||||
/// For example, the following are valid module declarations for package _com.example_:
|
||||
/// * `module com.example.Birds`
|
||||
@@ -66,11 +66,11 @@
|
||||
@ModuleInfo { minPklVersion = "0.30.0" }
|
||||
module pkl.DocPackageInfo
|
||||
|
||||
// used by doc comments
|
||||
import "pkl:DocPackageInfo"
|
||||
import "pkl:Project"
|
||||
import "pkl:reflect"
|
||||
import "pkl:semver"
|
||||
// used by doc comments
|
||||
import "pkl:Project"
|
||||
import "pkl:DocPackageInfo"
|
||||
|
||||
/// The name of this package.
|
||||
name: PackageName
|
||||
@@ -173,19 +173,20 @@ class PackageDependency {
|
||||
}
|
||||
|
||||
/// A package name.
|
||||
typealias PackageName =
|
||||
String(!contains("/"))
|
||||
typealias PackageName = String(!contains("/"))
|
||||
|
||||
/// A package version.
|
||||
typealias PackageVersion =
|
||||
String(semver.isValid(this))
|
||||
typealias PackageVersion = String(semver.isValid(this))
|
||||
|
||||
@Unlisted
|
||||
fixed overview: String(!isBlank) = moduleMirror.docComment ??
|
||||
throw("""
|
||||
fixed overview: String(!isBlank) =
|
||||
moduleMirror.docComment
|
||||
?? throw(
|
||||
"""
|
||||
Missing overview documentation for package `\(name)`.
|
||||
To fix this problem, add a doc comment to `doc-package-info.pkl` (above `amends "pkl:DocPackageInfo"`).
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
@Unlisted
|
||||
fixed overviewImports: Map<String, Uri> = moduleMirror.imports
|
||||
|
||||
@@ -75,7 +75,7 @@ allowedResources: Listing<String(isRegex)>?
|
||||
/// - `"auto"`: Format if the process' stdin, stdout, or stderr are connected to a console.
|
||||
/// - `"always"`: Always format
|
||||
@Since { version = "0.27.0" }
|
||||
color: ("never"|"auto"|"always")?
|
||||
color: ("never" | "auto" | "always")?
|
||||
|
||||
/// Disables the file system cache for `package:` modules.
|
||||
///
|
||||
@@ -116,21 +116,17 @@ externalResourceReaders: Mapping<String, ExternalReader>?
|
||||
/// - `"compact"`: All structures passed to trace() will be emitted on a single line.
|
||||
/// - `"pretty"`: All structures passed to trace() will be indented and emitted across multiple lines.
|
||||
@Since { version = "0.30.0" }
|
||||
traceMode: ("compact"|"pretty")?
|
||||
traceMode: ("compact" | "pretty")?
|
||||
|
||||
const local hostnameRegex = Regex(#"https?://([^/?#]*)"#)
|
||||
local const hostnameRegex = Regex(#"https?://([^/?#]*)"#)
|
||||
|
||||
const local hasNonEmptyHostname = (it: String) ->
|
||||
local const hasNonEmptyHostname = (it: String) ->
|
||||
let (hostname = hostnameRegex.findMatchesIn(it).getOrNull(0)?.groups?.getOrNull(1)?.value)
|
||||
hostname != null && hostname.length > 0
|
||||
|
||||
/// A key or value in [Http.rewrites].
|
||||
@Since { version = "0.29.0" }
|
||||
typealias HttpRewrite = String(
|
||||
startsWith(Regex("https?://")),
|
||||
endsWith("/"),
|
||||
hasNonEmptyHostname
|
||||
)
|
||||
typealias HttpRewrite = String(startsWith(Regex("https?://")), endsWith("/"), hasNonEmptyHostname)
|
||||
|
||||
/// Settings that control how Pkl talks to HTTP(S) servers.
|
||||
class Http {
|
||||
@@ -226,7 +222,7 @@ class Proxy {
|
||||
@Since { version = "0.27.0" }
|
||||
class ExternalReader {
|
||||
/// The external reader executable.
|
||||
///
|
||||
///
|
||||
/// Will be spawned with the same environment variables and working directory as the Pkl process.
|
||||
/// Executable is resolved according to the operating system's process spawning rules.
|
||||
/// On macOS, Linux, and Windows platforms, this may be:
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
/// 2. Set [projectFileUri] to the enclosing module's URI.
|
||||
/// This is necessary to determine the correct project directory, as well as for resolving
|
||||
/// local project dependencies correctly.
|
||||
///
|
||||
///
|
||||
/// The [newInstance()] helper method exists as a convenient way to set this when embedding
|
||||
/// project definitions.
|
||||
///
|
||||
@@ -95,11 +95,11 @@ tests: Listing<String>(isDistinct)
|
||||
/// Tells if the project is a local module named `PklProject`, is not self, and has a [package] section
|
||||
local isValidLoadDependency = (it: Project) ->
|
||||
isUriLocal(projectFileUri, it.projectFileUri)
|
||||
&& it.projectFileUri.endsWith("/PklProject")
|
||||
&& it != module
|
||||
&& it.package != null
|
||||
&& it.projectFileUri.endsWith("/PklProject")
|
||||
&& it != module
|
||||
&& it.package != null
|
||||
|
||||
const local function isUriLocal(uri1: Uri, uri2: Uri): Boolean =
|
||||
local const function isUriLocal(uri1: Uri, uri2: Uri): Boolean =
|
||||
// This is an imperfect check; should also check that the URIs have the same authority.
|
||||
// We should improve this if/when there is a URI library in the stdlib.
|
||||
uri1.substring(0, uri1.indexOf(":")) == uri2.substring(0, uri2.indexOf(":"))
|
||||
@@ -125,7 +125,7 @@ const local function isUriLocal(uri1: Uri, uri2: Uri): Boolean =
|
||||
///
|
||||
/// ```
|
||||
/// import "@birds/canary.pkl" // Import a module from the `birds` dependency
|
||||
///
|
||||
///
|
||||
/// birdIndex = read("@birds/index.txt") // Read a file from the `birds` dependency
|
||||
/// ```
|
||||
///
|
||||
@@ -139,7 +139,7 @@ const local function isUriLocal(uri1: Uri, uri2: Uri): Boolean =
|
||||
///
|
||||
/// 1. `GET https://example.com/foo@0.5.0` to retrieve the metadata JSON file.
|
||||
/// 2. Given the metadata JSON file, make a GET request to the package URI ZIP archive.
|
||||
///
|
||||
///
|
||||
/// If this project is published as a package, these dependencies are included within the published
|
||||
/// package metadata.
|
||||
///
|
||||
@@ -149,7 +149,7 @@ const local function isUriLocal(uri1: Uri, uri2: Uri): Boolean =
|
||||
/// This is useful when structuring a single repository that publishes multiple packages.
|
||||
///
|
||||
/// To specify a local project dependency, import the relative `PklProject` file.
|
||||
///
|
||||
///
|
||||
/// The local project dependency must define its own [package].
|
||||
///
|
||||
/// Example:
|
||||
@@ -176,7 +176,7 @@ const local function isUriLocal(uri1: Uri, uri2: Uri): Boolean =
|
||||
/// 1. Gather all dependencies, both direct and transitive.
|
||||
/// 2. For each package's major version, determine the highest declared minor version.
|
||||
/// 3. Write each resolved dependency to sibling file `PklProject.deps.json`.
|
||||
dependencies: Mapping<String(!contains("/")), *RemoteDependency|Project(isValidLoadDependency)>
|
||||
dependencies: Mapping<String(!contains("/")), *RemoteDependency | Project(isValidLoadDependency)>
|
||||
|
||||
local isFileBasedProject = projectFileUri.startsWith("file:")
|
||||
|
||||
@@ -196,12 +196,12 @@ local isFileBasedProject = projectFileUri.startsWith("file:")
|
||||
/// - [modulePath][EvaluatorSettings.modulePath]
|
||||
/// - [rootDir][EvaluatorSettings.rootDir]
|
||||
/// - [moduleCacheDir][EvaluatorSettings.moduleCacheDir]
|
||||
///
|
||||
///
|
||||
/// For each of these, relative paths are resolved against the project's enclosing directory.
|
||||
evaluatorSettings: EvaluatorSettingsModule(
|
||||
(modulePath != null).implies(isFileBasedProject),
|
||||
(rootDir != null).implies(isFileBasedProject),
|
||||
(moduleCacheDir != null).implies(isFileBasedProject)
|
||||
(moduleCacheDir != null).implies(isFileBasedProject),
|
||||
)
|
||||
|
||||
/// The URI of the PklProject file.
|
||||
@@ -224,11 +224,12 @@ function newInstance(enclosingModule: Module): Project = new {
|
||||
projectFileUri = reflect.Module(enclosingModule).uri
|
||||
}
|
||||
|
||||
const local hasVersion = (it: Uri) ->
|
||||
local const hasVersion = (it: Uri) ->
|
||||
let (versionSep = it.lastIndexOf("@"))
|
||||
if (versionSep == -1) false
|
||||
else let (version = it.drop(versionSep + 1))
|
||||
semver.parseOrNull(version) != null
|
||||
if (versionSep == -1)
|
||||
false
|
||||
else
|
||||
let (version = it.drop(versionSep + 1)) semver.parseOrNull(version) != null
|
||||
|
||||
typealias PackageUri = Uri(startsWith("package:"), hasVersion)
|
||||
|
||||
@@ -368,7 +369,7 @@ class Package {
|
||||
/// ```
|
||||
/// license = "Apache-2.0"
|
||||
/// ```
|
||||
license: (CommonSpdxLicenseIdentifier|String)?
|
||||
license: (CommonSpdxLicenseIdentifier | String)?
|
||||
|
||||
/// The full text of the license associated with this package.
|
||||
licenseText: String?
|
||||
@@ -412,30 +413,30 @@ typealias EvaluatorSettings = EvaluatorSettingsModule
|
||||
/// Common software licenses in the [SPDX License List](https://spdx.org/licenses/).
|
||||
typealias CommonSpdxLicenseIdentifier =
|
||||
"Apache-2.0"
|
||||
|"MIT"
|
||||
|"BSD-2-Clause"
|
||||
|"BSD-3-Clause"
|
||||
|"ISC"
|
||||
|"GPL-3.0"
|
||||
|"GPL-2.0"
|
||||
|"MPL-2.0"
|
||||
|"MPL-1.1"
|
||||
|"MPL-1.0"
|
||||
|"AGPL-1.0-only"
|
||||
|"AGPL-1.0-or-later"
|
||||
|"AGPL-3.0-only"
|
||||
|"AGPL-3.0-or-later"
|
||||
|"LGPL-2.0-only"
|
||||
|"LGPL-2.0-or-later"
|
||||
|"LGPL-2.1-only"
|
||||
|"LGPL-2.1-or-later"
|
||||
|"LGPL-3.0-only"
|
||||
|"LGPL-3.0-or-later"
|
||||
|"EPL-1.0"
|
||||
|"EPL-2.0"
|
||||
|"UPL-1.0"
|
||||
|"BSL-1.0"
|
||||
|"Unlicense"
|
||||
| "MIT"
|
||||
| "BSD-2-Clause"
|
||||
| "BSD-3-Clause"
|
||||
| "ISC"
|
||||
| "GPL-3.0"
|
||||
| "GPL-2.0"
|
||||
| "MPL-2.0"
|
||||
| "MPL-1.1"
|
||||
| "MPL-1.0"
|
||||
| "AGPL-1.0-only"
|
||||
| "AGPL-1.0-or-later"
|
||||
| "AGPL-3.0-only"
|
||||
| "AGPL-3.0-or-later"
|
||||
| "LGPL-2.0-only"
|
||||
| "LGPL-2.0-or-later"
|
||||
| "LGPL-2.1-only"
|
||||
| "LGPL-2.1-or-later"
|
||||
| "LGPL-3.0-only"
|
||||
| "LGPL-3.0-or-later"
|
||||
| "EPL-1.0"
|
||||
| "EPL-2.0"
|
||||
| "UPL-1.0"
|
||||
| "BSL-1.0"
|
||||
| "Unlicense"
|
||||
|
||||
@Unlisted
|
||||
@Since { version = "0.27.0" }
|
||||
|
||||
280
stdlib/base.pkl
280
stdlib/base.pkl
@@ -21,8 +21,8 @@
|
||||
module pkl.base
|
||||
|
||||
import "pkl:jsonnet"
|
||||
import "pkl:xml"
|
||||
import "pkl:protobuf"
|
||||
import "pkl:xml"
|
||||
|
||||
/// The top type of the type hierarchy.
|
||||
///
|
||||
@@ -96,15 +96,26 @@ abstract external class Module {
|
||||
value = outer
|
||||
renderer =
|
||||
let (format = read?("prop:pkl.outputFormat") ?? "pcf")
|
||||
if (format == "json") new JsonRenderer {}
|
||||
else if (format == "jsonnet") new jsonnet.Renderer {}
|
||||
else if (format == "pcf") new PcfRenderer {}
|
||||
else if (format == "plist") new PListRenderer {}
|
||||
else if (format == "properties") new PropertiesRenderer {}
|
||||
else if (format == "textproto") new protobuf.Renderer {}
|
||||
else if (format == "xml") new xml.Renderer {}
|
||||
else if (format == "yaml") new YamlRenderer {}
|
||||
else throw("Unknown output format: `\(format)`. Supported formats are `json`, `jsonnet`, `pcf`, `plist`, `properties`, `textproto`, `xml`, `yaml`.")
|
||||
if (format == "json")
|
||||
new JsonRenderer {}
|
||||
else if (format == "jsonnet")
|
||||
new jsonnet.Renderer {}
|
||||
else if (format == "pcf")
|
||||
new PcfRenderer {}
|
||||
else if (format == "plist")
|
||||
new PListRenderer {}
|
||||
else if (format == "properties")
|
||||
new PropertiesRenderer {}
|
||||
else if (format == "textproto")
|
||||
new protobuf.Renderer {}
|
||||
else if (format == "xml")
|
||||
new xml.Renderer {}
|
||||
else if (format == "yaml")
|
||||
new YamlRenderer {}
|
||||
else
|
||||
throw(
|
||||
"Unknown output format: `\(format)`. Supported formats are `json`, `jsonnet`, `pcf`, `plist`, `properties`, `textproto`, `xml`, `yaml`."
|
||||
)
|
||||
text = renderer.renderDocument(value)
|
||||
bytes = text.encodeToBytes("UTF-8")
|
||||
}
|
||||
@@ -179,7 +190,18 @@ class SourceCode extends Annotation {
|
||||
/// - `"x = 42"` is valid source code for language `"Pkl"`.
|
||||
/// - `"42"` is valid source code for language `"PklExpr"`.
|
||||
/// - `"42"` is valid source code for language `"Pkl"` with [prefix] `"x = "`.
|
||||
language: "Go"|"HTML"|"Java"|"JavaScript"|"Markdown"|"Pkl"|"PklExpr"|"Python"|"Ruby"|"SQL"|"Swift"|String
|
||||
language: "Go"
|
||||
| "HTML"
|
||||
| "Java"
|
||||
| "JavaScript"
|
||||
| "Markdown"
|
||||
| "Pkl"
|
||||
| "PklExpr"
|
||||
| "Python"
|
||||
| "Ruby"
|
||||
| "SQL"
|
||||
| "Swift"
|
||||
| String
|
||||
|
||||
/// A source code prefix to help tools understand the source code.
|
||||
///
|
||||
@@ -307,7 +329,7 @@ abstract class ValueRenderer {
|
||||
/// Paths are matched against path specs component-wise in reverse order.
|
||||
/// For example, paths `server.timeout` and `racks[*].server.timeout`
|
||||
/// both match path spec `server.timeout`, whereas path `server.timeout.millis` does not.
|
||||
converters: Mapping<Class|String, (unknown) -> Any>
|
||||
converters: Mapping<Class | String, (unknown) -> Any>
|
||||
|
||||
/// The file extension associated with this output format,
|
||||
/// or [null] if this format does not have an extension.
|
||||
@@ -426,7 +448,7 @@ class YamlRenderer extends ValueRenderer {
|
||||
/// At present, the mode only affects which String values are quoted in YAML.
|
||||
/// For example, `x = "yes"` is rendered as `x: 'yes'` in modes `"compat"` and `"1.1"`,
|
||||
/// and as `x: yes` in mode `"1.2"`.
|
||||
mode: "compat"|"1.1"|"1.2" = "compat"
|
||||
mode: "compat" | "1.1" | "1.2" = "compat"
|
||||
|
||||
/// The number of spaces to use for indenting output.
|
||||
indentWidth: Int(this > 1) = 2
|
||||
@@ -965,7 +987,7 @@ typealias UInt32 = Int(isBetween(0, 4294967295))
|
||||
typealias UInt = Int(isPositive)
|
||||
|
||||
/// A value that can be compared to another value of the same type with `<`, `>`, `<=`, and `>=`.
|
||||
typealias Comparable = String|Number|Duration|DataSize
|
||||
typealias Comparable = String | Number | Duration | DataSize
|
||||
|
||||
/// A 64-bit floating-point number conforming to the IEEE 754 binary64 format.
|
||||
///
|
||||
@@ -1266,37 +1288,37 @@ external class String extends Any {
|
||||
external function repeat(count: UInt): String
|
||||
|
||||
/// Tells whether this string contains [pattern].
|
||||
external function contains(pattern: String|Regex): Boolean
|
||||
external function contains(pattern: String | Regex): Boolean
|
||||
|
||||
/// Tells whether this string matches [regex] in its entirety.
|
||||
@AlsoKnownAs { names { "test" } }
|
||||
external function matches(regex: Regex): Boolean
|
||||
|
||||
/// Tells whether this string starts with [pattern].
|
||||
external function startsWith(pattern: String|Regex): Boolean
|
||||
external function startsWith(pattern: String | Regex): Boolean
|
||||
|
||||
/// Tells whether this string ends with [pattern].
|
||||
external function endsWith(pattern: String|Regex): Boolean
|
||||
external function endsWith(pattern: String | Regex): Boolean
|
||||
|
||||
/// Returns the zero-based index of the first occurrence of [pattern]
|
||||
/// in this string.
|
||||
///
|
||||
/// Throws if [pattern] does not occur in this string.
|
||||
external function indexOf(pattern: String|Regex): Int
|
||||
external function indexOf(pattern: String | Regex): Int
|
||||
|
||||
/// Returns the zero-based index of the first occurrence of [pattern]
|
||||
/// in this string, or [null] if [pattern] does not occur in this string.
|
||||
external function indexOfOrNull(pattern: String|Regex): Int?
|
||||
external function indexOfOrNull(pattern: String | Regex): Int?
|
||||
|
||||
/// Returns the zero-based index of the last occurrence of [pattern]
|
||||
/// in this string.
|
||||
///
|
||||
/// Throws if [pattern] does not occur in this string.
|
||||
external function lastIndexOf(pattern: String|Regex): Int
|
||||
external function lastIndexOf(pattern: String | Regex): Int
|
||||
|
||||
/// Returns the zero-based index of the last occurrence of [pattern]
|
||||
/// in this string, or [null] if [pattern] does not occur in this string.
|
||||
external function lastIndexOfOrNull(pattern: String|Regex): Int?
|
||||
external function lastIndexOfOrNull(pattern: String | Regex): Int?
|
||||
|
||||
/// Returns the first [n] characters of this string.
|
||||
///
|
||||
@@ -1338,32 +1360,41 @@ external class String extends Any {
|
||||
/// Replaces the first occurrence of [pattern] in this string with [replacement].
|
||||
///
|
||||
/// Returns this string unchanged if [pattern] does not occur in this string.
|
||||
external function replaceFirst(pattern: String|Regex, replacement: String): String
|
||||
external function replaceFirst(pattern: String | Regex, replacement: String): String
|
||||
|
||||
/// Replaces the last occurrence of [pattern] in this string with [replacement].
|
||||
///
|
||||
/// Returns this string unchanged if [pattern] does not occur in this string.
|
||||
external function replaceLast(pattern: String|Regex, replacement: String): String
|
||||
external function replaceLast(pattern: String | Regex, replacement: String): String
|
||||
|
||||
/// Replaces all occurrences of [pattern] in this string with [replacement].
|
||||
///
|
||||
/// Returns this string unchanged if [pattern] does not occur in this string.
|
||||
external function replaceAll(pattern: String|Regex, replacement: String): String
|
||||
external function replaceAll(pattern: String | Regex, replacement: String): String
|
||||
|
||||
/// Replaces the first occurrence of [pattern] in this string with the return value of [mapper].
|
||||
///
|
||||
/// Returns this string unchanged if [pattern] does not occur in this string.
|
||||
external function replaceFirstMapped(pattern: String|Regex, mapper: (RegexMatch) -> String): String
|
||||
external function replaceFirstMapped(
|
||||
pattern: String | Regex,
|
||||
mapper: (RegexMatch) -> String,
|
||||
): String
|
||||
|
||||
/// Replaces the last occurrence of [pattern] in this string with the return value of [mapper].
|
||||
///
|
||||
/// Returns this string unchanged if [pattern] does not occur in this string.
|
||||
external function replaceLastMapped(pattern: String|Regex, mapper: (RegexMatch) -> String): String
|
||||
external function replaceLastMapped(
|
||||
pattern: String | Regex,
|
||||
mapper: (RegexMatch) -> String,
|
||||
): String
|
||||
|
||||
/// Replaces all occurrences of [pattern] in this string with the return value of [mapper].
|
||||
///
|
||||
/// Returns this string unchanged if [pattern] does not occur in this string.
|
||||
external function replaceAllMapped(pattern: String|Regex, mapper: (RegexMatch) -> String): String
|
||||
external function replaceAllMapped(
|
||||
pattern: String | Regex,
|
||||
mapper: (RegexMatch) -> String,
|
||||
): String
|
||||
|
||||
/// Replaces the characters between [start] and [exclusiveEnd] with [replacement].
|
||||
///
|
||||
@@ -1404,10 +1435,10 @@ external class String extends Any {
|
||||
external function padEnd(width: Int, char: Char)
|
||||
|
||||
/// Splits this string around matches of [pattern].
|
||||
external function split(pattern: String|Regex): List<String>
|
||||
external function split(pattern: String | Regex): List<String>
|
||||
|
||||
/// Splits this string matches of [pattern], up to [limit] substrings.
|
||||
///
|
||||
///
|
||||
/// Returns a [List] with at most [limit] elements.
|
||||
/// If the limit has been reached, the last entry will contain the un-split remainder of this string.
|
||||
///
|
||||
@@ -1418,8 +1449,8 @@ external class String extends Any {
|
||||
/// "a.b.c".splitLimit(".", 50) == List("a", "b", "c")
|
||||
/// "a.b:c".splitLimit(Regex("[.:]"), 3) == List("a", "b", "c")
|
||||
/// ```
|
||||
@Since { version = "0.27.0" }
|
||||
external function splitLimit(pattern: String|Regex, limit: Int(this > 0)): List<String>
|
||||
@Since { version = "0.27.0" }
|
||||
external function splitLimit(pattern: String | Regex, limit: Int(this > 0)): List<String>
|
||||
|
||||
/// Converts the first character of this string to title case.
|
||||
///
|
||||
@@ -1489,7 +1520,7 @@ external class String extends Any {
|
||||
/// * `"UTF-16"`: <https://en.wikipedia.org/wiki/UTF-16>
|
||||
/// * `"ISO-8859-1"` (also known as latin1): <https://en.wikipedia.org/wiki/ISO/IEC_8859-1>
|
||||
@Since { version = "0.29.0" }
|
||||
typealias Charset = "UTF-8"|"UTF-16"|"ISO-8859-1"
|
||||
typealias Charset = "UTF-8" | "UTF-16" | "ISO-8859-1"
|
||||
|
||||
/// A string representing a [URI](https://en.wikipedia.org/wiki/Uniform_Resource_Identifier).
|
||||
typealias Uri = String
|
||||
@@ -1556,7 +1587,7 @@ class RegexMatch {
|
||||
}
|
||||
|
||||
/// The unit of a [Duration].
|
||||
typealias DurationUnit = "ns"|"us"|"ms"|"s"|"min"|"h"|"d"
|
||||
typealias DurationUnit = "ns" | "us" | "ms" | "s" | "min" | "h" | "d"
|
||||
|
||||
/// A quantity of elapsed time, represented as a [value] (e.g. `30.5`) and [unit] (e.g. `min`).
|
||||
external class Duration extends Any {
|
||||
@@ -1630,7 +1661,8 @@ external class Duration extends Any {
|
||||
}
|
||||
|
||||
/// The unit of a [DataSize].
|
||||
typealias DataSizeUnit = "b"|"kb"|"kib"|"mb"|"mib"|"gb"|"gib"|"tb"|"tib"|"pb"|"pib"
|
||||
typealias DataSizeUnit =
|
||||
"b" | "kb" | "kib" | "mb" | "mib" | "gb" | "gib" | "tb" | "tib" | "pb" | "pib"
|
||||
|
||||
/// A quantity of binary data, represented as a [value] (e.g. `30.5`) and [unit] (e.g. `mb`).
|
||||
external class DataSize extends Any {
|
||||
@@ -1894,7 +1926,7 @@ class Listing<out Element> extends Object {
|
||||
/// Returns the element at [index].
|
||||
///
|
||||
/// Returns [default] applied to [index] if [index] is outside the bounds of this listing.
|
||||
///
|
||||
///
|
||||
/// This is equivalent to `getOrNull(index) ?? default.apply(index)`.
|
||||
@Since { version = "0.29.0" }
|
||||
external function getOrDefault(index: Int): Element
|
||||
@@ -1989,13 +2021,13 @@ class Listing<out Element> extends Object {
|
||||
external function distinctBy(selector: (Element) -> Any): Listing<Element>
|
||||
|
||||
/// Tells if [predicate] holds for every element of this listing.
|
||||
///
|
||||
///
|
||||
/// Returns [true] for an empty listing.
|
||||
@Since { version = "0.27.0" }
|
||||
external function every(predicate: (Element) -> Boolean): Boolean
|
||||
|
||||
/// Tells if [predicate] holds for at least one element of this listing.
|
||||
///
|
||||
///
|
||||
/// Returns [false] for an empty listing.
|
||||
@Since { version = "0.27.0" }
|
||||
external function any(predicate: (Element) -> Boolean): Boolean
|
||||
@@ -2018,7 +2050,10 @@ class Listing<out Element> extends Object {
|
||||
/// Folds this listing in iteration order using [operator], starting with [initial].
|
||||
///
|
||||
/// The first parameter of [operator] is the zero-based index of the current element.
|
||||
external function foldIndexed<Result>(initial: Result, operator: (Int, Result, Element) -> Result): Result
|
||||
external function foldIndexed<Result>(
|
||||
initial: Result,
|
||||
operator: (Int, Result, Element) -> Result,
|
||||
): Result
|
||||
|
||||
/// Converts the elements of this listing to strings and concatenates them inserting [separator] between elements.
|
||||
external function join(separator: String): String
|
||||
@@ -2052,9 +2087,9 @@ class Mapping<out Key, out Value> extends Object {
|
||||
|
||||
/// Tells if this mapping contains [key].
|
||||
external function containsKey(key: Any): Boolean
|
||||
|
||||
|
||||
/// Tells if this mapping contains an entry with the given [value].
|
||||
@Since { version = "0.27.0" }
|
||||
@Since { version = "0.27.0" }
|
||||
external function containsValue(value: Any): Boolean
|
||||
|
||||
/// Returns the value associated with [key] or [null] if this mapping does not contain [key].
|
||||
@@ -2066,20 +2101,20 @@ class Mapping<out Key, out Value> extends Object {
|
||||
/// not contain [key].
|
||||
///
|
||||
/// This is equivalent to `getOrNull(key) ?? default.apply(key)`.
|
||||
@Since { version = "0.29.0" }
|
||||
@Since { version = "0.29.0" }
|
||||
external function getOrDefault(key: Any): Value
|
||||
|
||||
/// Folds the entries of this mapping in iteration order using [operator], starting with [initial].
|
||||
external function fold<Result>(initial: Result, operator: (Result, Key, Value) -> Result): Result
|
||||
|
||||
|
||||
/// Tells if [predicate] holds for every entry of this mapping.
|
||||
///
|
||||
///
|
||||
/// Returns [true] for an empty mapping.
|
||||
@Since { version = "0.27.0" }
|
||||
external function every(predicate: (Key, Value) -> Boolean): Boolean
|
||||
|
||||
|
||||
/// Tells if [predicate] holds for at least one entry of this mapping.
|
||||
///
|
||||
///
|
||||
/// Returns [false] for an empty mapping.
|
||||
@Since { version = "0.27.0" }
|
||||
external function any(predicate: (Key, Value) -> Boolean): Boolean
|
||||
@@ -2119,13 +2154,15 @@ external class Function3<in Param1, in Param2, in Param3, out Result> extends Fu
|
||||
}
|
||||
|
||||
/// A function literal with four parameters.
|
||||
external class Function4<in Param1, in Param2, in Param3, in Param4, out Result> extends Function<Result> {
|
||||
external class Function4<in Param1, in Param2, in Param3, in Param4, out Result>
|
||||
extends Function<Result> {
|
||||
@AlsoKnownAs { names { "call"; "invoke" } }
|
||||
external function apply(p1: Param1, p2: Param2, p3: Param3, p4: Param4): Result
|
||||
}
|
||||
|
||||
/// A function literal with five parameters.
|
||||
external class Function5<in Param1, in Param2, in Param3, in Param4, in Param5, out Result> extends Function<Result> {
|
||||
external class Function5<in Param1, in Param2, in Param3, in Param4, in Param5, out Result>
|
||||
extends Function<Result> {
|
||||
@AlsoKnownAs { names { "call"; "invoke" } }
|
||||
external function apply(p1: Param1, p2: Param2, p3: Param3, p4: Param4, p5: Param5): Result
|
||||
}
|
||||
@@ -2157,7 +2194,7 @@ external const function Undefined(): nothing
|
||||
const function TODO(): nothing = throw("TODO")
|
||||
|
||||
/// Creates a null value that turns into [defaultValue] when amended.
|
||||
external const function Null(defaultValue: Object|Function<Object>): Null
|
||||
external const function Null(defaultValue: Object | Function<Object>): Null
|
||||
|
||||
/// Constructs a [Pair].
|
||||
external const function Pair<First, Second>(first: First, second: Second): Pair<First, Second>
|
||||
@@ -2312,7 +2349,9 @@ abstract external class Collection<out Element> extends Any {
|
||||
/// Same as [split()] but returns [null] if [index] is outside range `0`..[length].
|
||||
abstract function splitOrNull(index: Int): Pair<Collection<Element>, Collection<Element>>?
|
||||
|
||||
abstract function partition(predicate: (Element) -> Boolean): Pair<Collection<Element>, Collection<Element>>
|
||||
abstract function partition(
|
||||
predicate: (Element) -> Boolean,
|
||||
): Pair<Collection<Element>, Collection<Element>>
|
||||
|
||||
/// The zero-based index of the first occurrence of [element] in this collection.
|
||||
///
|
||||
@@ -2384,11 +2423,11 @@ abstract external class Collection<out Element> extends Any {
|
||||
/// List(4, 6, 8).findIndex((n) -> n.isEven) == 0
|
||||
/// import("pkl:test").catch(() -> List(5, 7, 9).findLast((n) -> n.isEven))
|
||||
/// ```
|
||||
@AlsoKnownAs { names { "indexWhere" }}
|
||||
@AlsoKnownAs { names { "indexWhere" } }
|
||||
abstract function findIndex(predicate: (Element) -> Boolean): Int
|
||||
|
||||
/// Same as [findIndex()] but returns [null] if [predicate] does not hold for any element in this collection.
|
||||
@AlsoKnownAs { names { "indexWhere" }}
|
||||
@AlsoKnownAs { names { "indexWhere" } }
|
||||
abstract function findIndexOrNull(predicate: (Element) -> Boolean): Int?
|
||||
|
||||
/// The index of the last element for which [predicate] returns [true].
|
||||
@@ -2401,11 +2440,11 @@ abstract external class Collection<out Element> extends Any {
|
||||
/// List(4, 6, 8).findLastIndex((n) -> n.isEven) == 2
|
||||
/// import("pkl:test").catch(() -> List(5, 7, 9).findLastIndex((n) -> n.isEven))
|
||||
/// ```
|
||||
@AlsoKnownAs { names { "lastIndexWhere" }}
|
||||
@AlsoKnownAs { names { "lastIndexWhere" } }
|
||||
abstract function findLastIndex(predicate: (Element) -> Boolean): Int
|
||||
|
||||
/// Same as [findLastIndex()] but returns [null] if [predicate] does not hold for any element in this collection.
|
||||
@AlsoKnownAs { names { "lastIndexWhere" }}
|
||||
@AlsoKnownAs { names { "lastIndexWhere" } }
|
||||
abstract function findLastIndexOrNull(predicate: (Element) -> Boolean): Int?
|
||||
|
||||
/// The number of elements for which [predicate] returns [true].
|
||||
@@ -2510,7 +2549,9 @@ abstract external class Collection<out Element> extends Any {
|
||||
/// List(1, 2, 3).mapNonNull((n) -> if (n.isOdd) null else n + 2) == List(4)
|
||||
/// ```
|
||||
@AlsoKnownAs { names { "filterMap" } }
|
||||
abstract function mapNonNull<Result>(transform: (Element) -> Result): Collection<Result(this != null)>
|
||||
abstract function mapNonNull<Result>(
|
||||
transform: (Element) -> Result,
|
||||
): Collection<Result(this != null)>
|
||||
|
||||
/// Transforms this collection by applying [transform] to each element and removing resulting [null] elements.
|
||||
///
|
||||
@@ -2522,7 +2563,9 @@ abstract external class Collection<out Element> extends Any {
|
||||
/// List(1, 2, 3, 4, null).mapNonNullIndexed((i, n) -> if (n?.isOdd ?? true) null else n * i) == List(2, 12)
|
||||
/// ```
|
||||
@Since { version = "0.29.0" }
|
||||
abstract function mapNonNullIndexed<Result>(transform: (Int, Element) -> Result): Collection<Result(this != null)>
|
||||
abstract function mapNonNullIndexed<Result>(
|
||||
transform: (Int, Element) -> Result,
|
||||
): Collection<Result(this != null)>
|
||||
|
||||
/// Applies a collection-generating [transform] to each element in this collection
|
||||
/// and concatenates the resulting collections.
|
||||
@@ -2536,7 +2579,9 @@ abstract external class Collection<out Element> extends Any {
|
||||
/// [transform] takes two arguments: the index of the element, and the element itself.
|
||||
///
|
||||
/// Throws if [transform] produces a non-collection value.
|
||||
abstract function flatMapIndexed<Result>(transform: (Int, Element) -> Collection<Result>): Collection<Result>
|
||||
abstract function flatMapIndexed<Result>(
|
||||
transform: (Int, Element) -> Collection<Result>,
|
||||
): Collection<Result>
|
||||
|
||||
/// Concatenates the elements in this collection, each of which must itself be a collection.
|
||||
///
|
||||
@@ -2547,7 +2592,7 @@ abstract external class Collection<out Element> extends Any {
|
||||
/// Adds [element] to this collection.
|
||||
///
|
||||
/// For [List], [element] is appended.
|
||||
abstract function add<Other>(element: Other): Collection<Element|Other>
|
||||
abstract function add<Other>(element: Other): Collection<Element | Other>
|
||||
|
||||
/// Returns the first [n] elements in this collection.
|
||||
@AlsoKnownAs { names { "limit" } }
|
||||
@@ -2588,15 +2633,18 @@ abstract external class Collection<out Element> extends Any {
|
||||
/// Folds this collection in iteration order using [operator], starting with [initial].
|
||||
///
|
||||
/// The first parameter of [operator] is the zero-based index of the current element.
|
||||
abstract function foldIndexed<Result>(initial: Result, operator: (Int, Result, Element) -> Result): Result
|
||||
abstract function foldIndexed<Result>(
|
||||
initial: Result,
|
||||
operator: (Int, Result, Element) -> Result,
|
||||
): Result
|
||||
|
||||
/// Folds this collection in iteration order using [operator], starting with the first element.
|
||||
///
|
||||
/// Throws if this collection is empty.
|
||||
abstract function reduce<Result>(operator: (Element|Result, Element) -> Result): Result
|
||||
abstract function reduce<Result>(operator: (Element | Result, Element) -> Result): Result
|
||||
|
||||
/// Same as [reduce()] but returns [null] if this collection is empty.
|
||||
abstract function reduceOrNull<Result>(operator: (Element|Result, Element) -> Result): Result?
|
||||
abstract function reduceOrNull<Result>(operator: (Element | Result, Element) -> Result): Result?
|
||||
|
||||
/// Groups the elements in this collection according to keys returned by [selector].
|
||||
abstract function groupBy<Key>(selector: (Element) -> Key): Map<Key, Collection<Element>>
|
||||
@@ -2659,10 +2707,12 @@ abstract external class Collection<out Element> extends Any {
|
||||
/// [comparator] should return [true] if its first argument is less than its second argument, and [false] otherwise.
|
||||
///
|
||||
/// Throws if this collection is empty.
|
||||
abstract function maxWith(comparator: (Element, Element) -> Boolean|/*Deprecated*/Int): Element
|
||||
abstract function maxWith(comparator: (Element, Element) -> Boolean | /*Deprecated*/ Int): Element
|
||||
|
||||
/// Same as [maxWith()] but returns [null] if this collection is empty.
|
||||
abstract function maxWithOrNull(comparator: (Element, Element) -> Boolean|/*Deprecated*/Int): Element?
|
||||
abstract function maxWithOrNull(
|
||||
comparator: (Element, Element) -> Boolean | /*Deprecated*/ Int,
|
||||
): Element?
|
||||
|
||||
/// Sorts this collection of [Comparable] elements in ascending order.
|
||||
///
|
||||
@@ -2687,7 +2737,9 @@ abstract external class Collection<out Element> extends Any {
|
||||
/// ```
|
||||
/// List(1, 2, 3).sortWith((a, b) -> a > b)) == List(3, 2, 1)
|
||||
/// ```
|
||||
abstract function sortWith(comparator: (Element, Element) -> Boolean|/*Deprecated*/Int): Collection<Element>
|
||||
abstract function sortWith(
|
||||
comparator: (Element, Element) -> Boolean | /*Deprecated*/ Int,
|
||||
): Collection<Element>
|
||||
|
||||
/// Reverses the order of elements in this collection.
|
||||
abstract function reverse(): Collection<Element>
|
||||
@@ -2725,7 +2777,10 @@ abstract external class Collection<out Element> extends Any {
|
||||
abstract function toSet(): Set<Element>
|
||||
|
||||
/// Converts this collection to a map by extracting a key and value from each element using the given functions.
|
||||
abstract function toMap<Key, Value>(keyExtractor: (Element) -> Key, valueExtractor: (Element) -> Value): Map<Key, Value>
|
||||
abstract function toMap<Key, Value>(
|
||||
keyExtractor: (Element) -> Key,
|
||||
valueExtractor: (Element) -> Value,
|
||||
): Map<Key, Value>
|
||||
|
||||
/// Converts this collection to a [Listing].
|
||||
abstract function toListing(): Listing<Element>
|
||||
@@ -2959,8 +3014,12 @@ external class List<out Element> extends Collection<Element> {
|
||||
external function mapIndexed<Result>(transform: (Int, Element) -> Result): List<Result>
|
||||
|
||||
@Since { version = "0.29.0" }
|
||||
external function mapNonNullIndexed<Result>(transform: (Int, Element) -> Result): List<Result(this != null)>
|
||||
external function flatMapIndexed<Result>(transform: (Int, Element) -> Collection<Result>): List<Result>
|
||||
external function mapNonNullIndexed<Result>(
|
||||
transform: (Int, Element) -> Result,
|
||||
): List<Result(this != null)>
|
||||
external function flatMapIndexed<Result>(
|
||||
transform: (Int, Element) -> Collection<Result>,
|
||||
): List<Result>
|
||||
|
||||
external function filterIsInstance<Type>(clazz: Class<Type>): List<Type>
|
||||
|
||||
@@ -3013,27 +3072,35 @@ external class List<out Element> extends Collection<Element> {
|
||||
external function every(predicate: (Element) -> Boolean): Boolean
|
||||
external function any(predicate: (Element) -> Boolean): Boolean
|
||||
|
||||
external function add<Other>(element: Other): List<Element|Other>
|
||||
external function add<Other>(element: Other): List<Element | Other>
|
||||
|
||||
/// Replaces the element at [index] with [replacement].
|
||||
///
|
||||
/// Throws if [index] is outside the bounds of this list.
|
||||
external function replace<Other>(index: Int, replacement: Other): List<Element|Other>
|
||||
external function replace<Other>(index: Int, replacement: Other): List<Element | Other>
|
||||
|
||||
/// Replaces the element at [index] with [replacement].
|
||||
///
|
||||
/// Returns [null] if [index] is outside the bounds of this list.
|
||||
external function replaceOrNull<Other>(index: Int, replacement: Other): List<Element|Other>?
|
||||
external function replaceOrNull<Other>(index: Int, replacement: Other): List<Element | Other>?
|
||||
|
||||
/// Replaces the elements between indices [range] and [exclusiveEnd] with [replacement].
|
||||
///
|
||||
/// Throws if [range] or [exclusiveEnd] is outside the bounds of this list.
|
||||
external function replaceRange<Other>(start: Int, exclusiveEnd: Int, replacement: Collection<Other>): List<Element|Other>
|
||||
external function replaceRange<Other>(
|
||||
start: Int,
|
||||
exclusiveEnd: Int,
|
||||
replacement: Collection<Other>,
|
||||
): List<Element | Other>
|
||||
|
||||
/// Replaces the elements between indices [range] and [exclusiveEnd] with [replacement].
|
||||
///
|
||||
/// Returns [null] if [range] or [exclusiveEnd] is outside the bounds of this list.
|
||||
external function replaceRangeOrNull<Other>(start: Int, exclusiveEnd: Int, replacement: Collection<Other>): List<Element|Other>?
|
||||
external function replaceRangeOrNull<Other>(
|
||||
start: Int,
|
||||
exclusiveEnd: Int,
|
||||
replacement: Collection<Other>,
|
||||
): List<Element | Other>?
|
||||
|
||||
external function find(predicate: (Element) -> Boolean): Element
|
||||
external function findOrNull(predicate: (Element) -> Boolean): Element?
|
||||
@@ -3067,10 +3134,13 @@ external class List<out Element> extends Collection<Element> {
|
||||
|
||||
external function fold<Result>(initial: Result, operator: (Result, Element) -> Result): Result
|
||||
external function foldBack<Result>(initial: Result, operator: (Element, Result) -> Result): Result
|
||||
external function foldIndexed<Result>(initial: Result, operator: (Int, Result, Element) -> Result): Result
|
||||
external function foldIndexed<Result>(
|
||||
initial: Result,
|
||||
operator: (Int, Result, Element) -> Result,
|
||||
): Result
|
||||
|
||||
external function reduce<Result>(operator: (Element|Result, Element) -> Result): Result
|
||||
external function reduceOrNull<Result>(operator: (Element|Result, Element) -> Result): Result?
|
||||
external function reduce<Result>(operator: (Element | Result, Element) -> Result): Result
|
||||
external function reduceOrNull<Result>(operator: (Element | Result, Element) -> Result): Result?
|
||||
|
||||
external function groupBy<Key>(selector: (Element) -> Key): Map<Key, List<Element>>
|
||||
|
||||
@@ -3108,7 +3178,10 @@ external class List<out Element> extends Collection<Element> {
|
||||
|
||||
external function toSet(): Set<Element>
|
||||
|
||||
external function toMap<Key, Value>(keyExtractor: (Element) -> Key, valueExtractor: (Element) -> Value): Map<Key, Value>
|
||||
external function toMap<Key, Value>(
|
||||
keyExtractor: (Element) -> Key,
|
||||
valueExtractor: (Element) -> Value,
|
||||
): Map<Key, Value>
|
||||
|
||||
external function toListing(): Listing<Element>
|
||||
|
||||
@@ -3176,8 +3249,12 @@ external class Set<out Element> extends Collection<Element> {
|
||||
external function mapIndexed<Result>(transform: (Int, Element) -> Result): Set<Result>
|
||||
|
||||
@Since { version = "0.29.0" }
|
||||
external function mapNonNullIndexed<Result>(transform: (Int, Element) -> Result): Set<Result(this != null)>
|
||||
external function flatMapIndexed<Result>(transform: (Int, Element) -> Collection<Result>): Set<Result>
|
||||
external function mapNonNullIndexed<Result>(
|
||||
transform: (Int, Element) -> Result,
|
||||
): Set<Result(this != null)>
|
||||
external function flatMapIndexed<Result>(
|
||||
transform: (Int, Element) -> Collection<Result>,
|
||||
): Set<Result>
|
||||
|
||||
external function filterIsInstance<Type>(clazz: Class<Type>): Set<Type>
|
||||
|
||||
@@ -3186,7 +3263,7 @@ external class Set<out Element> extends Collection<Element> {
|
||||
external function every(predicate: (Element) -> Boolean): Boolean
|
||||
external function any(predicate: (Element) -> Boolean): Boolean
|
||||
|
||||
external function add<Other>(element: Other): Set<Element|Other>
|
||||
external function add<Other>(element: Other): Set<Element | Other>
|
||||
|
||||
external function find(predicate: (Element) -> Boolean): Element
|
||||
external function findOrNull(predicate: (Element) -> Boolean): Element?
|
||||
@@ -3208,10 +3285,13 @@ external class Set<out Element> extends Collection<Element> {
|
||||
|
||||
external function fold<Result>(initial: Result, operator: (Result, Element) -> Result): Result
|
||||
external function foldBack<Result>(initial: Result, operator: (Element, Result) -> Result): Result
|
||||
external function foldIndexed<Result>(initial: Result, operator: (Int, Result, Element) -> Result): Result
|
||||
external function foldIndexed<Result>(
|
||||
initial: Result,
|
||||
operator: (Int, Result, Element) -> Result,
|
||||
): Result
|
||||
|
||||
external function reduce<Result>(operator: (Element|Result, Element) -> Result): Result
|
||||
external function reduceOrNull<Result>(operator: (Element|Result, Element) -> Result): Result?
|
||||
external function reduce<Result>(operator: (Element | Result, Element) -> Result): Result
|
||||
external function reduceOrNull<Result>(operator: (Element | Result, Element) -> Result): Result?
|
||||
|
||||
external function groupBy<Key>(selector: (Element) -> Key): Map<Key, Set<Element>>
|
||||
|
||||
@@ -3223,8 +3303,10 @@ external class Set<out Element> extends Collection<Element> {
|
||||
external function minBy(selector: (Element) -> Int): Element
|
||||
external function minByOrNull(selector: (Element) -> Int): Element?
|
||||
|
||||
external function minWith(comparator: (Element, Element) -> Boolean|/*Deprecated*/Int): Element
|
||||
external function minWithOrNull(comparator: (Element, Element) -> Boolean|/*Deprecated*/Int): Element?
|
||||
external function minWith(comparator: (Element, Element) -> Boolean | /*Deprecated*/ Int): Element
|
||||
external function minWithOrNull(
|
||||
comparator: (Element, Element) -> Boolean | /*Deprecated*/ Int,
|
||||
): Element?
|
||||
|
||||
external max: Element
|
||||
external maxOrNull: Element?
|
||||
@@ -3232,12 +3314,16 @@ external class Set<out Element> extends Collection<Element> {
|
||||
external function maxBy(selector: (Element) -> Int): Element
|
||||
external function maxByOrNull(selector: (Element) -> Int): Element?
|
||||
|
||||
external function maxWith(comparator: (Element, Element) -> Boolean|/*Deprecated*/Int): Element
|
||||
external function maxWithOrNull(comparator: (Element, Element) -> Boolean|/*Deprecated*/Int): Element?
|
||||
external function maxWith(comparator: (Element, Element) -> Boolean | /*Deprecated*/ Int): Element
|
||||
external function maxWithOrNull(
|
||||
comparator: (Element, Element) -> Boolean | /*Deprecated*/ Int,
|
||||
): Element?
|
||||
|
||||
external function sort(): List<Element>
|
||||
external function sortBy(selector: (Element) -> Comparable): List<Element>
|
||||
external function sortWith(comparator: (Element, Element) -> Boolean|/*Deprecated*/Int): List<Element>
|
||||
external function sortWith(
|
||||
comparator: (Element, Element) -> Boolean | /*Deprecated*/ Int,
|
||||
): List<Element>
|
||||
|
||||
external function reverse(): List<Element>
|
||||
|
||||
@@ -3249,7 +3335,10 @@ external class Set<out Element> extends Collection<Element> {
|
||||
|
||||
external function toSet(): Set<Element>
|
||||
|
||||
external function toMap<Key, Value>(keyExtractor: (Element) -> Key, valueExtractor: (Element) -> Value): Map<Key, Value>
|
||||
external function toMap<Key, Value>(
|
||||
keyExtractor: (Element) -> Key,
|
||||
valueExtractor: (Element) -> Value,
|
||||
): Map<Key, Value>
|
||||
|
||||
external function toListing(): Listing<Element>
|
||||
|
||||
@@ -3257,7 +3346,7 @@ external class Set<out Element> extends Collection<Element> {
|
||||
|
||||
/// The intersection of this set and [other].
|
||||
external function intersect(other: Set): Set<Element>
|
||||
|
||||
|
||||
/// The difference of this set and [other].
|
||||
external function difference(other: Set): Set<Element>
|
||||
}
|
||||
@@ -3271,7 +3360,7 @@ external class Set<out Element> extends Collection<Element> {
|
||||
/// Map("name", "Pigeon", "age", 42).keys == Set("name", "age")
|
||||
/// Map("name", "Pigeon", "age", 42).values == Set("Pigeon", 42)
|
||||
/// ```
|
||||
external const function Map<Key, Value>(keysAndValues: VarArgs<Key|Value>): Map<Key, Value>
|
||||
external const function Map<Key, Value>(keysAndValues: VarArgs<Key | Value>): Map<Key, Value>
|
||||
|
||||
/// A mapping from keys to values.
|
||||
///
|
||||
@@ -3313,7 +3402,10 @@ external class Map<out Key, out Value> extends Any {
|
||||
external function containsValue(value: Any): Boolean
|
||||
|
||||
/// Adds or updates [key] to [value].
|
||||
external function put<NewKey, NewValue>(key: NewKey, value: NewValue): Map<NewKey|Key, NewValue|Value>
|
||||
external function put<NewKey, NewValue>(
|
||||
key: NewKey,
|
||||
value: NewValue,
|
||||
): Map<NewKey | Key, NewValue | Value>
|
||||
|
||||
/// Removes the map entry with the given key.
|
||||
///
|
||||
@@ -3327,7 +3419,9 @@ external class Map<out Key, out Value> extends Any {
|
||||
external function fold<Result>(initial: Result, operator: (Result, Key, Value) -> Result): Result
|
||||
|
||||
/// Transforms the entries of this map using [transform].
|
||||
external function map<NewKey, NewValue>(transform: (Key, Value) -> Pair<NewKey, NewValue>): Map<NewKey, NewValue>
|
||||
external function map<NewKey, NewValue>(
|
||||
transform: (Key, Value) -> Pair<NewKey, NewValue>,
|
||||
): Map<NewKey, NewValue>
|
||||
|
||||
/// Transforms the keys of this map using [transform].
|
||||
external function mapKeys<NewKey>(transform: (Key, Value) -> NewKey): Map<NewKey, Value>
|
||||
@@ -3336,7 +3430,9 @@ external class Map<out Key, out Value> extends Any {
|
||||
external function mapValues<NewValue>(transform: (Key, Value) -> NewValue): Map<Key, NewValue>
|
||||
|
||||
/// Applies a map-generating [transform] to each map entry and concatenates the resulting maps.
|
||||
external function flatMap<NewKey, NewValue>(transform: (Key, Value) -> Map<NewKey, NewValue>): Map<NewKey, NewValue>
|
||||
external function flatMap<NewKey, NewValue>(
|
||||
transform: (Key, Value) -> Map<NewKey, NewValue>,
|
||||
): Map<NewKey, NewValue>
|
||||
|
||||
/// Tells if [predicate] holds for every entry of this map.
|
||||
///
|
||||
|
||||
@@ -45,15 +45,15 @@ class Parser {
|
||||
/// Value converters to apply to parsed values.
|
||||
///
|
||||
/// For further information see [PcfRenderer.converters].
|
||||
converters: Mapping<Class|String(!isEmpty), (unknown) -> unknown>
|
||||
converters: Mapping<Class | String(!isEmpty), (unknown) -> unknown>
|
||||
|
||||
/// Parses [source] as a JSON document.
|
||||
///
|
||||
/// Throws if an error occurs during parsing.
|
||||
///
|
||||
/// If [source] is a [Resource], the resource URI is included in parse error messages.
|
||||
external function parse(source: Resource|String): Value
|
||||
external function parse(source: Resource | String): Value
|
||||
}
|
||||
|
||||
/// Pkl representation of a JSON value.
|
||||
typealias Value = Null|Boolean|Number|String|Listing|Dynamic|Mapping
|
||||
typealias Value = Null | Boolean | Number | String | Listing | Dynamic | Mapping
|
||||
|
||||
@@ -78,7 +78,7 @@ class Renderer extends ValueRenderer {
|
||||
/// If non-empty, renders object fields and array elements on separate lines,
|
||||
/// and strings containing newlines as `|||` multiline text blocks,
|
||||
/// with the given leading line [indent].
|
||||
indent: String|/*Deprecated*/Null = " "
|
||||
indent: String | /*Deprecated*/ Null = " "
|
||||
|
||||
/// Whether to omit Jsonnet object fields whose value is `null`.
|
||||
omitNullProperties: Boolean = true
|
||||
|
||||
@@ -79,7 +79,6 @@ external minPositiveFloat: Float
|
||||
/// [1]: https://en.wikipedia.org/wiki/E_(mathematical_constant)
|
||||
external e: Float
|
||||
|
||||
|
||||
/// The number [π][1].
|
||||
///
|
||||
/// [1]: https://en.wikipedia.org/wiki/Pi
|
||||
|
||||
@@ -66,7 +66,7 @@ class VirtualMachine {
|
||||
/// The operating system of a platform.
|
||||
class OperatingSystem {
|
||||
/// The name of this operating system.
|
||||
name: "macOS"|"Linux"|"Windows"|String
|
||||
name: "macOS" | "Linux" | "Windows" | String
|
||||
|
||||
/// The version of this operating system.
|
||||
version: String
|
||||
|
||||
@@ -216,7 +216,7 @@ external class Module extends Declaration {
|
||||
/// A class or type alias declaration.
|
||||
abstract external class TypeDeclaration extends Declaration {
|
||||
/// The class or type alias reflected upon.
|
||||
abstract hidden reflectee: base.Class|base.TypeAlias
|
||||
abstract hidden reflectee: base.Class | base.TypeAlias
|
||||
|
||||
/// The module enclosing this type declaration.
|
||||
///
|
||||
@@ -298,7 +298,7 @@ external class Property extends Declaration {
|
||||
allModifiers: Set<Modifier>
|
||||
|
||||
/// The annotations of this module, appended with any from the containing class's superclasses.
|
||||
///
|
||||
///
|
||||
/// Annotations are ordered starting with the current class and walking up the class hierarchy.
|
||||
@Since { version = "0.30.0" }
|
||||
allAnnotations: List<Annotation>
|
||||
@@ -341,13 +341,13 @@ external class TypeParameter {
|
||||
}
|
||||
|
||||
/// A modifier of a [Declaration].
|
||||
typealias Modifier = "abstract"|"external"|"hidden"|"open"|"fixed"|"const"
|
||||
typealias Modifier = "abstract" | "external" | "hidden" | "open" | "fixed" | "const"
|
||||
|
||||
/// The variance of a [TypeParameter].
|
||||
///
|
||||
/// An "in" type parameter is contravariant.
|
||||
/// An "out" type parameter is covariant.
|
||||
typealias Variance = "in"|"out"
|
||||
typealias Variance = "in" | "out"
|
||||
|
||||
/// A type as it occurs, say, in a type annotation.
|
||||
abstract external class Type {
|
||||
|
||||
@@ -47,7 +47,8 @@ function Version(version: String): Version =
|
||||
/// ```
|
||||
function parseOrNull(version: String): Version? =
|
||||
let (groups = versionRegex.matchEntire(version)?.groups)
|
||||
if (groups == null) null
|
||||
if (groups == null)
|
||||
null
|
||||
else
|
||||
new Version {
|
||||
major = groups[1].value.toInt()
|
||||
@@ -99,9 +100,15 @@ class Version {
|
||||
/// - `"1.0.0-0.3.7"`
|
||||
/// - `"1.0.0-x.7.z.92"`
|
||||
/// - `"1.0.0-x-y-z.–"`
|
||||
preRelease: String(matches(Regex(#"(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*"#)))?
|
||||
preRelease: String(
|
||||
matches(
|
||||
Regex(
|
||||
#"(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*"#,
|
||||
),
|
||||
),
|
||||
)?
|
||||
|
||||
hidden fixed preReleaseIdentifiers: List<Int|String> =
|
||||
hidden fixed preReleaseIdentifiers: List<Int | String> =
|
||||
if (preRelease == null) List() else preRelease.split(".").map((it) -> it.toIntOrNull() ?? it)
|
||||
|
||||
/// Build metadata MAY be denoted by appending a plus sign and a series of dot separated identifiers immediately following the patch or pre-release version.
|
||||
@@ -119,8 +126,7 @@ class Version {
|
||||
/// Note: Unlike `==`, [equals()] and comparison methods such as [isLessThan()] ignore [build].
|
||||
build: String(matches(Regex(#"[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*"#)))?
|
||||
|
||||
hidden fixed buildIdentifiers: List<String> =
|
||||
if (build == null) List() else build.split(".")
|
||||
hidden fixed buildIdentifiers: List<String> = if (build == null) List() else build.split(".")
|
||||
|
||||
/// Tells whether this version is equal to [other] according to semantic versioning rules.
|
||||
///
|
||||
@@ -160,23 +166,19 @@ class Version {
|
||||
major < other.major
|
||||
|| major == other.major && minor < other.minor
|
||||
|| major == other.major && minor == other.minor && patch < other.patch
|
||||
||
|
||||
major == other.major
|
||||
&& minor == other.minor
|
||||
&& patch == other.patch
|
||||
&& isPreReleaseLessThan(other)
|
||||
|| major == other.major
|
||||
&& minor == other.minor
|
||||
&& patch == other.patch
|
||||
&& isPreReleaseLessThan(other)
|
||||
|
||||
/// Tells whether this version is less than or equal to [other] according to semantic versioning rules.
|
||||
function isLessThanOrEquals(other: Version): Boolean =
|
||||
isLessThan(other) || equals(other)
|
||||
function isLessThanOrEquals(other: Version): Boolean = isLessThan(other) || equals(other)
|
||||
|
||||
/// Tells whether this version is greater than [other] according to semantic versioning rules.
|
||||
function isGreaterThan(other: Version): Boolean =
|
||||
other.isLessThan(this)
|
||||
function isGreaterThan(other: Version): Boolean = other.isLessThan(this)
|
||||
|
||||
/// Tells whether this version is greater than or equal to [other] according to semantic versioning rules.
|
||||
function isGreaterThanOrEquals(other: Version): Boolean =
|
||||
other.isLessThanOrEquals(this)
|
||||
function isGreaterThanOrEquals(other: Version): Boolean = other.isLessThanOrEquals(this)
|
||||
|
||||
/// A normal version number MUST take the form X.Y.Z where X, Y, and Z are non-negative integers, and MUST NOT contain leading zeroes.
|
||||
function isNormal(): Boolean = preRelease == null && build == null
|
||||
@@ -187,24 +189,39 @@ class Version {
|
||||
/// Strips [preRelease] and [build] from this version.
|
||||
function toNormal(): Version = (this) { preRelease = null; build = null }
|
||||
|
||||
function toString() = "\(major).\(minor).\(patch)\(if (preRelease != null) "-\(preRelease)" else "")\(if (build != null) "+\(build)" else "")"
|
||||
function toString() =
|
||||
"\(major).\(minor).\(patch)\(if (preRelease != null) "-\(preRelease)" else "")\(if (build != null) "+\(build)" else "")"
|
||||
|
||||
local function isPreReleaseLessThan(other: Version): Boolean =
|
||||
if (preRelease == null) false
|
||||
else if (other.preRelease == null) true
|
||||
else if (preRelease == other.preRelease) false
|
||||
if (preRelease == null)
|
||||
false
|
||||
else if (other.preRelease == null)
|
||||
true
|
||||
else if (preRelease == other.preRelease)
|
||||
false
|
||||
else
|
||||
let (result = preReleaseIdentifiers
|
||||
.zip(other.preReleaseIdentifiers)
|
||||
.fold(null, (result, next) ->
|
||||
if (result != null) result
|
||||
else
|
||||
if (next.first == next.second) null
|
||||
else if (next.first.getClass() == next.second.getClass()) next.first < next.second
|
||||
else next.first is Int
|
||||
)
|
||||
) if (result != null) result else preReleaseIdentifiers.length < other.preReleaseIdentifiers.length
|
||||
let (result =
|
||||
preReleaseIdentifiers
|
||||
.zip(other.preReleaseIdentifiers)
|
||||
.fold(null, (result, next) ->
|
||||
if (result != null)
|
||||
result
|
||||
else if (next.first == next.second)
|
||||
null
|
||||
else if (next.first.getClass() == next.second.getClass())
|
||||
next.first < next.second
|
||||
else
|
||||
next.first is Int
|
||||
)
|
||||
)
|
||||
if (result != null)
|
||||
result
|
||||
else
|
||||
preReleaseIdentifiers.length < other.preReleaseIdentifiers.length
|
||||
}
|
||||
|
||||
// https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
|
||||
local versionRegex = Regex(#"(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?"#)
|
||||
local versionRegex =
|
||||
Regex(
|
||||
#"(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?"#,
|
||||
)
|
||||
|
||||
@@ -28,10 +28,7 @@ function escapeWithSingleQuotes(str: String): String =
|
||||
else if (acc.last.last != "'" && ch != "'")
|
||||
acc.replace(acc.lastIndex, acc.last.add(ch))
|
||||
else
|
||||
acc.add(List(ch)))
|
||||
let (grouped = str.chars.fold(List(), processChar))
|
||||
grouped
|
||||
.map((chSeq) ->
|
||||
if (chSeq == List("'")) #"\'"#
|
||||
else "'\(chSeq.join(""))'")
|
||||
.join("")
|
||||
acc.add(List(ch))
|
||||
)
|
||||
let (grouped = str.chars.fold(List(), processChar))
|
||||
grouped.map((chSeq) -> if (chSeq == List("'")) #"\'"# else "'\(chSeq.join(""))'").join("")
|
||||
|
||||
@@ -39,13 +39,13 @@ class Renderer extends ValueRenderer {
|
||||
indent: String = " "
|
||||
|
||||
/// The XML version to use.
|
||||
xmlVersion: *"1.0"|"1.1"
|
||||
xmlVersion: *"1.0" | "1.1"
|
||||
|
||||
/// The name of the XML document's root element.
|
||||
rootElementName: String(!isEmpty) = "root"
|
||||
|
||||
/// The attributes of the XML document's root element.
|
||||
rootElementAttributes: Mapping<String(!isEmpty), String|Boolean|Int|Float>
|
||||
rootElementAttributes: Mapping<String(!isEmpty), String | Boolean | Int | Float>
|
||||
|
||||
external function renderDocument(value: Any): String
|
||||
|
||||
@@ -83,12 +83,12 @@ function Element(_name: String(!isEmpty)): Dynamic = new {
|
||||
}
|
||||
|
||||
/// Creates an [Inline] directive for [_value].
|
||||
function Inline(_value: Object|Collection|Map): Inline = new { value = _value }
|
||||
function Inline(_value: Object | Collection | Map): Inline = new { value = _value }
|
||||
|
||||
/// Inlines the members of [value] into the enclosing XML element,
|
||||
/// without rendering an XML element for [value] itself.
|
||||
class Inline {
|
||||
value: Object|Collection|Map
|
||||
value: Object | Collection | Map
|
||||
}
|
||||
|
||||
/// Creates an XML [Comment] with the given [_text].
|
||||
|
||||
@@ -50,7 +50,7 @@ class Parser {
|
||||
/// - `"compat"` - YAML 1.1 _or_ 1.2 (default)
|
||||
/// - `"1.1"` - YAML 1.1
|
||||
/// - `"1.2"` - YAML 1.2 (Core schema)
|
||||
mode: "compat"|"1.1"|"1.2" = "compat"
|
||||
mode: "compat" | "1.1" | "1.2" = "compat"
|
||||
|
||||
/// Determines what the parser produces when parsing YAML `!!map` types.
|
||||
///
|
||||
@@ -64,7 +64,7 @@ class Parser {
|
||||
/// Value converters to apply to parsed values.
|
||||
///
|
||||
/// For further information see [PcfRenderer.converters].
|
||||
converters: Mapping<Class|String(!isEmpty), (unknown) -> unknown>
|
||||
converters: Mapping<Class | String(!isEmpty), (unknown) -> unknown>
|
||||
|
||||
/// The maximum number of aliases for collection nodes.
|
||||
///
|
||||
@@ -77,15 +77,15 @@ class Parser {
|
||||
/// Throws if an error occurs during parsing, or if [source] contains multiple YAML documents.
|
||||
///
|
||||
/// If [source] is a [Resource], the resource URI is included in parse error messages.
|
||||
external function parse(source: Resource|String): Value
|
||||
external function parse(source: Resource | String): Value
|
||||
|
||||
/// Parses all YAML documents contained in [source].
|
||||
///
|
||||
/// Throws if an error occurs during parsing.
|
||||
///
|
||||
/// If [source] is a [Resource], the resource URI is included in parse error messages.
|
||||
external function parseAll(source: Resource|String): List<Value>
|
||||
external function parseAll(source: Resource | String): List<Value>
|
||||
}
|
||||
|
||||
/// Pkl representation of a YAML value.
|
||||
typealias Value = Null|Boolean|Number|String|Listing|Dynamic|Mapping
|
||||
typealias Value = Null | Boolean | Number | String | Listing | Dynamic | Mapping
|
||||
|
||||
Reference in New Issue
Block a user