Skip to content

Commit

Permalink
[pkl.experimental.syntax] Do not generate spaces at EOL for long type…
Browse files Browse the repository at this point in the history
…aliases
  • Loading branch information
The Pkl Team (automation) authored and holzensp committed Jul 1, 2024
1 parent 3528213 commit 7b16701
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 14 deletions.
2 changes: 1 addition & 1 deletion packages/k8s.contrib.crd/PklProject
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ dependencies {
}

package {
version = "1.0.7"
version = "1.0.8"
}
4 changes: 2 additions & 2 deletions packages/k8s.contrib.crd/PklProject.deps.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
},
"package://pkg.pkl-lang.org/pkl-pantry/org.json_schema.contrib@1": {
"type": "local",
"uri": "projectpackage://pkg.pkl-lang.org/pkl-pantry/[email protected].8",
"uri": "projectpackage://pkg.pkl-lang.org/pkl-pantry/[email protected].9",
"path": "../org.json_schema.contrib"
},
"package://pkg.pkl-lang.org/pkl-pantry/pkl.experimental.syntax@1": {
"type": "local",
"uri": "projectpackage://pkg.pkl-lang.org/pkl-pantry/[email protected].2",
"uri": "projectpackage://pkg.pkl-lang.org/pkl-pantry/[email protected].3",
"path": "../pkl.experimental.syntax"
},
"package://pkg.pkl-lang.org/pkl-pantry/pkl.experimental.uri@1": {
Expand Down
2 changes: 1 addition & 1 deletion packages/org.json_schema.contrib/PklProject
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ dependencies {
}

package {
version = "1.0.8"
version = "1.0.9"
}
2 changes: 1 addition & 1 deletion packages/org.json_schema.contrib/PklProject.deps.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"resolvedDependencies": {
"package://pkg.pkl-lang.org/pkl-pantry/pkl.experimental.syntax@1": {
"type": "local",
"uri": "projectpackage://pkg.pkl-lang.org/pkl-pantry/[email protected].2",
"uri": "projectpackage://pkg.pkl-lang.org/pkl-pantry/[email protected].3",
"path": "../pkl.experimental.syntax"
},
"package://pkg.pkl-lang.org/pkl-pantry/pkl.experimental.uri@1": {
Expand Down
2 changes: 1 addition & 1 deletion packages/pkl.experimental.syntax/PklProject
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
amends "../basePklProject.pkl"

package {
version = "1.0.2"
version = "1.0.3"
apiTests = import*("tests/*.pkl").keys.toListing()
}
13 changes: 11 additions & 2 deletions packages/pkl.experimental.syntax/TypeAliasNode.pkl
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,21 @@ annotations: Listing<AnnotationNode>?

modifiers: Listing<"external"|"local">(isDistinct)?

local function renderAlias(currentIndent: String) = new Listing {
local function renderAlias(currentIndent: String) =
let (typeRendered = type.render(currentIndent))
new Listing {
renderHeader(currentIndent)
when (!typeRendered.startsWith("\n")) { // if the type is rendered starting on the next line, do not add a space
" "
}
typeRendered
}.join("")

function renderHeader(currentIndent: String) = new Listing {
...?modifiers
"typealias"
name.render(currentIndent)
"="
type.render(currentIndent)
}.join(" ")

function render(currentIndent: String) = List(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
examples {
["binary operators - basic"] {
"\"foo\" + \"bar\""
#""foo" + "bar""#
}
["binary operators - precedence: no parentheses when child precedence is higher"] {
"5 * 5 + 5 * 5"
Expand Down Expand Up @@ -39,10 +39,10 @@ examples {
"super.someProperty(true)"
}
["super subscript"] {
"super[\"test\"]"
#"super["test"]"#
}
["subscript"] {
"test[\"key\"]"
#"test["key"]"#
"""
(if (test)
testTrue
Expand All @@ -51,9 +51,9 @@ examples {
"""
}
["read"] {
"read(\"env:HOME\")"
"read*(\"env:HOME\")"
"read?(\"env:HOME\")"
#"read("env:HOME")"#
#"read*("env:HOME")"#
#"read?("env:HOME")"#
}
["trace"] {
"trace(test)"
Expand Down
31 changes: 31 additions & 0 deletions packages/pkl.experimental.syntax/tests/ModuleNode.pkl
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,35 @@ examples {
}
}.output.text
}
["typealiases"] {
new ModuleNode {
typealiases {
new {
name { value = "Short" }
type = new TypeNode.UnionTypeNode {
members {
new TypeNode.StringLiteralTypeNode { value = "A" }
new TypeNode.StringLiteralTypeNode { value = "B" }
}
}
}
new {
name { value = "Long" }
type = new TypeNode.UnionTypeNode {
members {
new TypeNode.StringLiteralTypeNode { value = "Apple" }
new TypeNode.StringLiteralTypeNode { value = "Blackberry" }
new TypeNode.StringLiteralTypeNode { value = "Cherry" }
new TypeNode.StringLiteralTypeNode { value = "Durian" }
new TypeNode.StringLiteralTypeNode { value = "Elderberry" }
new TypeNode.StringLiteralTypeNode { value = "Fig" }
new TypeNode.StringLiteralTypeNode { value = "Guava" }
new TypeNode.StringLiteralTypeNode { value = "Huckleberry" }
new TypeNode.StringLiteralTypeNode { value = "I_can't_think_of_a_fruit_that_starts_with_I" }
}
}
}
}
}.output.text
}
}
17 changes: 17 additions & 0 deletions packages/pkl.experimental.syntax/tests/ModuleNode.pkl-expected.pcf
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,23 @@ examples {
value = inputIntegerValue + 5
}

"""
}
["typealiases"] {
"""
typealias Short = "A"|"B"

typealias Long =
"Apple"
|"Blackberry"
|"Cherry"
|"Durian"
|"Elderberry"
|"Fig"
|"Guava"
|"Huckleberry"
|"I_can't_think_of_a_fruit_that_starts_with_I"

"""
}
}

0 comments on commit 7b16701

Please sign in to comment.