Added break and continue nodes

This commit is contained in:
Ilya Puchka
2017-12-23 18:54:04 +01:00
committed by David Jennes
parent 248d664d4a
commit a7448b74cf
5 changed files with 246 additions and 26 deletions

View File

@@ -11,15 +11,24 @@ public protocol NodeType {
/// Render the collection of nodes in the given context
public func renderNodes(_ nodes: [NodeType], _ context: Context) throws -> String {
try nodes
.map { node in
do {
return try node.render(context)
} catch {
throw error.withToken(node.token)
}
var result = ""
for node in nodes {
do {
result += try node.render(context)
} catch {
throw error.withToken(node.token)
}
.joined()
let shouldBreak = context[LoopTerminationNode.breakContextKey] != nil
let shouldContinue = context[LoopTerminationNode.continueContextKey] != nil
if shouldBreak || shouldContinue {
break
}
}
return result
}
/// Simple node, used for triggering a closure during rendering