diff --git a/Sources/Errors.swift b/Sources/Errors.swift index 91e617b..a6191f9 100644 --- a/Sources/Errors.swift +++ b/Sources/Errors.swift @@ -37,8 +37,6 @@ public struct TemplateSyntaxError : Error, Equatable, CustomStringConvertible { public init(_ description: String) { self.init(reason: description) } - - } extension Error { diff --git a/Sources/Inheritence.swift b/Sources/Inheritence.swift index f72f7ae..e512bfb 100644 --- a/Sources/Inheritence.swift +++ b/Sources/Inheritence.swift @@ -63,7 +63,9 @@ class ExtendsNode : NodeType { guard (parsedNodes.any { $0 is ExtendsNode }) == nil else { throw TemplateSyntaxError("'extends' cannot appear more than once in the same template") } + let blockNodes = parsedNodes.compactMap { $0 as? BlockNode } + let nodes = blockNodes.reduce([String: BlockNode]()) { (accumulator, node) -> [String: BlockNode] in var dict = accumulator dict[node.name] = node diff --git a/Sources/Lexer.swift b/Sources/Lexer.swift index a64b05c..f6fc426 100644 --- a/Sources/Lexer.swift +++ b/Sources/Lexer.swift @@ -22,6 +22,7 @@ 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)!) diff --git a/Sources/Variable.swift b/Sources/Variable.swift index 797cd8a..eb30060 100644 --- a/Sources/Variable.swift +++ b/Sources/Variable.swift @@ -116,13 +116,12 @@ public struct Variable : Equatable, Resolvable { return normalize(current) } - } private func resolveCollection(_ collection: T, bit: String) -> Any? { if let index = Int(bit) { if index >= 0 && index < collection.count { - return collection[collection.index(collection.startIndex, offsetBy: index)] + return collection[collection.index(collection.startIndex, offsetBy: index)] } else { return nil }