Feat: Add support for Swift 4.0

This commit is contained in:
andy
2018-10-01 11:58:20 +01:00
parent 01afae9b79
commit 66a9bc563a
7 changed files with 61 additions and 10 deletions

View File

@@ -22,11 +22,17 @@ struct Lexer {
init(templateName: String? = nil, templateString: String) {
self.templateName = templateName
self.templateString = templateString
self.lines = templateString.components(separatedBy: .newlines).enumerated().compactMap {
guard !$0.element.isEmpty else { return nil }
return (content: $0.element, number: UInt($0.offset + 1), templateString.range(of: $0.element)!)
}
#if swift(>=4.1)
self.lines = templateString.components(separatedBy: .newlines).enumerated().compactMap {
guard !$0.element.isEmpty else { return nil }
return (content: $0.element, number: UInt($0.offset + 1), templateString.range(of: $0.element)!)
}
#else
self.lines = templateString.components(separatedBy: .newlines).enumerated().flatMap {
guard !$0.element.isEmpty else { return nil }
return (content: $0.element, number: UInt($0.offset + 1), templateString.range(of: $0.element)!)
}
#endif
}
/// Create a token that will be passed on to the parser, with the given