Skip to content

Commit 7c0b020

Browse files
committed
Add functionality from TypeScript implementation
1 parent 9d79438 commit 7c0b020

13 files changed

+2937
-619
lines changed

Package.resolved

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"pins" : [
3+
{
4+
"identity" : "swift-collections",
5+
"kind" : "remoteSourceControl",
6+
"location" : "https://github.com/apple/swift-collections.git",
7+
"state" : {
8+
"revision" : "671108c96644956dddcd89dd59c203dcdb36cec7",
9+
"version" : "1.1.4"
10+
}
11+
}
12+
],
13+
"version" : 2
14+
}

Package.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,25 @@ let package = Package(
1313
targets: ["Jinja"]
1414
)
1515
],
16+
dependencies: [
17+
.package(url: "https://github.com/apple/swift-collections.git", from: "1.1.4")
18+
],
1619
targets: [
1720
// Targets are the basic building blocks of a package, defining a module or a test suite.
1821
// Targets can depend on other targets in this package and products from dependencies.
1922
.target(
2023
name: "Jinja",
24+
dependencies: [
25+
.product(name: "OrderedCollections", package: "swift-collections")
26+
],
2127
path: "Sources",
2228
swiftSettings: [.enableUpcomingFeature("BareSlashRegexLiterals")]
2329
),
2430
.testTarget(
2531
name: "JinjaTests",
26-
dependencies: ["Jinja"],
32+
dependencies: [
33+
"Jinja"
34+
],
2735
path: "Tests",
2836
swiftSettings: [.enableUpcomingFeature("BareSlashRegexLiterals")]
2937
),

Sources/Ast.swift

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77

88
import Foundation
9+
import OrderedCollections
910

1011
protocol Statement {}
1112

@@ -41,15 +42,15 @@ struct TupleLiteral: Literal {
4142
}
4243

4344
struct ObjectLiteral: Literal {
44-
var value: [(Expression, Expression)]
45+
var value: OrderedDictionary<String, Expression>
4546
}
4647

4748
struct Set: Statement {
4849
var assignee: Expression
4950
var value: Expression
5051
}
5152

52-
struct If: Statement {
53+
struct If: Statement, Expression {
5354
var test: Expression
5455
var body: [Statement]
5556
var alternate: [Statement]
@@ -59,14 +60,14 @@ struct Identifier: Expression {
5960
var value: String
6061
}
6162

62-
protocol Loopvar {}
63-
extension Identifier: Loopvar {}
64-
extension TupleLiteral: Loopvar {}
63+
typealias Loopvar = Expression
6564

6665
struct For: Statement {
6766
var loopvar: Loopvar
6867
var iterable: Expression
6968
var body: [Statement]
69+
var defaultBlock: [Statement]
70+
var ifCondition: Expression?
7071
}
7172

7273
struct MemberExpression: Expression {
@@ -124,3 +125,23 @@ struct KeywordArgumentExpression: Expression {
124125
struct NullLiteral: Literal {
125126
var value: Any? = nil
126127
}
128+
129+
struct SelectExpression: Expression {
130+
var iterable: Expression
131+
var test: Expression
132+
}
133+
134+
struct Macro: Statement {
135+
var name: Identifier
136+
var args: [Expression]
137+
var body: [Statement]
138+
}
139+
140+
struct KeywordArgumentsValue: RuntimeValue {
141+
var value: [String: any RuntimeValue]
142+
var builtins: [String: any RuntimeValue] = [:]
143+
144+
func bool() -> Bool {
145+
!value.isEmpty
146+
}
147+
}

0 commit comments

Comments
 (0)