storing full sourcemap in token, refactored error reporting

This commit is contained in:
Ilya Puchka
2017-12-27 02:31:47 +01:00
parent cb124319ec
commit ac2fd56e8e
15 changed files with 149 additions and 188 deletions

View File

@@ -107,9 +107,11 @@ public class TokenParser {
return try FilterExpression(token: filterToken, parser: self)
} catch {
if var error = error as? TemplateSyntaxError, error.token == nil {
// find range of filter in the containing token so that only filter is highligted, not the whole token
if let filterTokenRange = environment.template?.templateString.range(of: filterToken, range: containingToken.range) {
error.token = Token.variable(value: filterToken, at: filterTokenRange)
// find offset of filter in the containing token so that only filter is highligted, not the whole token
if let filterTokenRange = containingToken.contents.range(of: filterToken) {
var rangeLine = containingToken.sourceMap.line
rangeLine.offset += containingToken.contents.distance(from: containingToken.contents.startIndex, to: filterTokenRange.lowerBound)
error.token = .variable(value: filterToken, at: SourceMap(filename: containingToken.sourceMap.filename, line: rangeLine))
} else {
error.token = containingToken
}