fixed indetnations

This commit is contained in:
Ilya Puchka
2018-08-13 20:00:27 +01:00
parent 4f1a5b3e3d
commit b9702afbd4
6 changed files with 42 additions and 44 deletions

View File

@@ -31,8 +31,8 @@ class ForNode : NodeType {
let resolvable = try parser.compileResolvable(components[3], containedIn: token)
let `where` = hasToken("where", at: 4)
? try parseExpression(components: Array(components.suffix(from: 5)), tokenParser: parser, token: token)
: nil
? try parseExpression(components: Array(components.suffix(from: 5)), tokenParser: parser, token: token)
: nil
let forNodes = try parser.parse(until(["endfor", "empty"]))
@@ -145,7 +145,7 @@ class ForNode : NodeType {
try renderNodes(nodes, context)
}
}
}.joined(separator: "")
}.joined(separator: "")
}
return try context.push {

View File

@@ -189,8 +189,7 @@ extension String {
lineNumber += 1
lineContent = line
if let rangeOfLine = self.range(of: line), rangeOfLine.contains(range.lowerBound) {
offset = distance(from: rangeOfLine.lowerBound, to:
range.lowerBound)
offset = distance(from: rangeOfLine.lowerBound, to: range.lowerBound)
break
}
}

View File

@@ -11,13 +11,13 @@ public protocol NodeType {
/// Render the collection of nodes in the given context
public func renderNodes(_ nodes:[NodeType], _ context:Context) throws -> String {
return try nodes.map({
return try nodes.map {
do {
return try $0.render(context)
} catch {
throw error.withToken($0.token)
}
}).joined(separator: "")
}.joined(separator: "")
}
public class SimpleNode : NodeType {

View File

@@ -120,19 +120,18 @@ public class TokenParser {
do {
return try FilterExpression(token: filterToken, parser: self)
} catch {
if var error = error as? TemplateSyntaxError, error.token == nil {
// find offset of filter in the containing token so that only filter is highligted, not the whole token
if let filterTokenRange = containingToken.contents.range(of: filterToken) {
var rangeLine = containingToken.sourceMap.line
rangeLine.offset += containingToken.contents.distance(from: containingToken.contents.startIndex, to: filterTokenRange.lowerBound)
error.token = .variable(value: filterToken, at: SourceMap(filename: containingToken.sourceMap.filename, line: rangeLine))
} else {
error.token = containingToken
}
throw error
} else {
guard var syntaxError = error as? TemplateSyntaxError, syntaxError.token == nil else {
throw error
}
// find offset of filter in the containing token so that only filter is highligted, not the whole token
if let filterTokenRange = containingToken.contents.range(of: filterToken) {
var rangeLine = containingToken.sourceMap.line
rangeLine.offset += containingToken.contents.distance(from: containingToken.contents.startIndex, to: filterTokenRange.lowerBound)
syntaxError.token = .variable(value: filterToken, at: SourceMap(filename: containingToken.sourceMap.filename, line: rangeLine))
} else {
syntaxError.token = containingToken
}
throw syntaxError
}
}