replaced Token with Lexeme protocol on TemplateSyntaxError
This commit is contained in:
@@ -1,32 +1,5 @@
|
||||
import Foundation
|
||||
|
||||
|
||||
public struct TemplateSyntaxError : Error, Equatable, CustomStringConvertible {
|
||||
public let description:String
|
||||
public var token: Token?
|
||||
|
||||
public init(_ description:String) {
|
||||
self.description = description
|
||||
}
|
||||
|
||||
public func contextAwareError(templateName: String?, templateContent: String) -> TemplateSyntaxError? {
|
||||
guard let token = token, token.range != .unknown else { return nil }
|
||||
let templateName = templateName.map({ "\($0):" }) ?? ""
|
||||
let (line, lineNumber, offset) = templateContent.lineAndPosition(at: token.range)
|
||||
let tokenContent = templateContent.substring(with: token.range)
|
||||
let highlight = "\(String(Array(repeating: " ", count: offset)))^\(String(Array(repeating: "~", count: max(tokenContent.count - 1, 0))))"
|
||||
let description = "\(templateName)\(lineNumber):\(offset): error: " + self.description + "\n\(line)\n\(highlight)\n"
|
||||
return TemplateSyntaxError(description)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public func ==(lhs:TemplateSyntaxError, rhs:TemplateSyntaxError) -> Bool {
|
||||
return lhs.description == rhs.description
|
||||
}
|
||||
|
||||
|
||||
public protocol NodeType {
|
||||
/// Render the node in the given context
|
||||
func render(_ context:Context) throws -> String
|
||||
|
||||
Reference in New Issue
Block a user