fixed iterating over template lines on linux
This commit is contained in:
@@ -87,7 +87,7 @@ class ForNode : NodeType {
|
|||||||
var values: [Any]
|
var values: [Any]
|
||||||
|
|
||||||
if let dictionary = resolved as? [String: Any], !dictionary.isEmpty {
|
if let dictionary = resolved as? [String: Any], !dictionary.isEmpty {
|
||||||
values = dictionary.map { ($0.key, $0.value) }
|
values = dictionary.map { ($0.key, $0.value) } as [(String, Any)]
|
||||||
} else if let array = resolved as? [Any] {
|
} else if let array = resolved as? [Any] {
|
||||||
values = array
|
values = array
|
||||||
} else if let range = resolved as? CountableClosedRange<Int> {
|
} else if let range = resolved as? CountableClosedRange<Int> {
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import Foundation
|
||||||
|
|
||||||
struct Lexer {
|
struct Lexer {
|
||||||
let templateString: String
|
let templateString: String
|
||||||
|
|
||||||
@@ -58,16 +60,17 @@ struct Lexer {
|
|||||||
var lineNumber: Int = 0
|
var lineNumber: Int = 0
|
||||||
var offset = 0
|
var offset = 0
|
||||||
var lineContent = ""
|
var lineContent = ""
|
||||||
|
|
||||||
templateString.enumerateLines { (line, stop) in
|
for line in templateString.components(separatedBy: CharacterSet.newlines) {
|
||||||
lineNumber += 1
|
lineNumber += 1
|
||||||
lineContent = line
|
lineContent = line
|
||||||
if let rangeOfLine = self.templateString.range(of: line), rangeOfLine.contains(lexeme.range.lowerBound) {
|
if let rangeOfLine = templateString.range(of: line), rangeOfLine.contains(lexeme.range.lowerBound) {
|
||||||
offset = self.templateString.distance(from: rangeOfLine.lowerBound, to:
|
offset = templateString.distance(from: rangeOfLine.lowerBound, to:
|
||||||
lexeme.range.lowerBound)
|
lexeme.range.lowerBound)
|
||||||
stop = true
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (lineContent, lineNumber, offset)
|
return (lineContent, lineNumber, offset)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,6 @@ func testEnvironment() {
|
|||||||
error.lexeme = Token.block(value: token, at: template.templateString.range(of: token)!)
|
error.lexeme = Token.block(value: token, at: template.templateString.range(of: token)!)
|
||||||
let context = ErrorReporterContext(template: template)
|
let context = ErrorReporterContext(template: template)
|
||||||
error = environment.errorReporter.contextAwareError(error, context: context) as! TemplateSyntaxError
|
error = environment.errorReporter.contextAwareError(error, context: context) as! TemplateSyntaxError
|
||||||
print(error)
|
|
||||||
return error
|
return error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user