diff --git a/Sources/Errors.swift b/Sources/Errors.swift index 55b976a..07ee702 100644 --- a/Sources/Errors.swift +++ b/Sources/Errors.swift @@ -67,7 +67,7 @@ open class SimpleErrorReporter: ErrorReporter { func describe(token: Token) -> String { let templateName = token.sourceMap.filename ?? "" let location = token.sourceMap.location - let highlight = "\(String(Array(repeating: " ", count: location.lineOffset)))^\(String(Array(repeating: "~", count: max(token.contents.characters.count - 1, 0))))" + let highlight = "\(String(Array(repeating: " ", count: location.lineOffset)))^\(String(Array(repeating: "~", count: max(token.contents.count - 1, 0))))" return "\(templateName)\(location.lineNumber):\(location.lineOffset): error: \(templateError.reason)\n" + "\(location.content)\n" diff --git a/Sources/Lexer.swift b/Sources/Lexer.swift index fdbc880..26d6a1a 100644 --- a/Sources/Lexer.swift +++ b/Sources/Lexer.swift @@ -11,7 +11,7 @@ struct Lexer { self.templateName = templateName self.templateString = templateString - self.lines = templateString.components(separatedBy: .newlines).enumerated().flatMap { + 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)!) } @@ -19,7 +19,7 @@ struct Lexer { func createToken(string: String, at range: Range) -> Token { func strip() -> String { - guard string.characters.count > 4 else { return "" } + guard string.count > 4 else { return "" } let start = string.index(string.startIndex, offsetBy: 2) let end = string.index(string.endIndex, offsetBy: -2) let trimmed = String(string[start..