From 97ab3cf31dd2f9e3635abd57fb15c965cf0973ef Mon Sep 17 00:00:00 2001 From: Ilya Puchka Date: Sun, 8 Oct 2017 00:38:49 +0200 Subject: [PATCH] xcode backward compatibility fixes - moved back to single line string literal - fixed calculating string lenght --- Sources/Errors.swift | 20 +++++++++++++------- Sources/Lexer.swift | 2 +- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Sources/Errors.swift b/Sources/Errors.swift index 8ab3c49..8fb988e 100644 --- a/Sources/Errors.swift +++ b/Sources/Errors.swift @@ -66,13 +66,10 @@ open class SimpleErrorReporter: ErrorReporter { let tokenContent = context.template.templateString.substring(with: lexeme.range) let lexer = Lexer(templateString: context.template.templateString) let line = lexer.lexemeLine(lexeme) - let highlight = "\(String(Array(repeating: " ", count: line.offset)))^\(String(Array(repeating: "~", count: max(tokenContent.count - 1, 0))))" - let description = """ - \(templateName)\(line.number):\(line.offset): error: \(error.description) - \(line.content) - \(highlight) - """ - return TemplateSyntaxError(description) + let highlight = "\(String(Array(repeating: " ", count: line.offset)))^\(String(Array(repeating: "~", count: max(tokenContent.length - 1, 0))))" + let description = "\(templateName)\(line.number):\(line.offset): error: \(error.description)\n\(line.content)\n\(highlight)" + let error = TemplateSyntaxError(description) + return error } } @@ -86,4 +83,13 @@ extension String { var range: Range { return startIndex..=3.2) + return count + #else + return characters.count + #endif + } + } diff --git a/Sources/Lexer.swift b/Sources/Lexer.swift index 68ec385..51d8372 100644 --- a/Sources/Lexer.swift +++ b/Sources/Lexer.swift @@ -107,7 +107,7 @@ class Scanner { let result = content.substring(to: index) if returnUntil { - range = range.lowerBound..