0001 // The MIT License 0002 // 0003 // Copyright (c) 2015 Gwendal Roué 0004 // 0005 // Permission is hereby granted, free of charge, to any person obtaining a copy 0006 // of this software and associated documentation files (the "Software"), to deal 0007 // in the Software without restriction, including without limitation the rights 0008 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 0009 // copies of the Software, and to permit persons to whom the Software is 0010 // furnished to do so, subject to the following conditions: 0011 // 0012 // The above copyright notice and this permission notice shall be included in 0013 // all copies or substantial portions of the Software. 0014 // 0015 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 0016 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 0017 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 0018 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 0019 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 0020 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 0021 // THE SOFTWARE. 0022 0023 0024 /** 0025 The abstract syntax tree of a template 0026 */ 0027 final class TemplateAST{ 0028 0029 // A template AST can be "defined" or "undefined". 0030 // 0031 // Undefined template ASTs are used when parsing templates which embed a 0032 // partial tag which refers to themselves. The compiler would emit a 0033 // PartialNode which contains a reference to an undefined (yet) template 0034 // AST. At the end of the compilation the undefined template AST would 0035 // become defined. 0036 // 0037 // See TemplateRepository.templateAST(named:relativeToTemplateID:error:). 0038 enum TemplateASTType
TemplateCompiler.swift:34 func templateAST() throws -> TemplateAST {TemplateCompiler.swift:39 return TemplateAST(nodes: compilationState.currentScope.templateASTNodes, contentType: compilationState.contentType)TemplateCompiler.swift:216 let templateAST = TemplateAST(nodes: templateASTNodes, contentType: compilationState.contentType)TemplateCompiler.swift:246 let templateAST = TemplateAST(nodes: templateASTNodes, contentType: compilationState.contentType)TemplateCompiler.swift:284 let templateAST = TemplateAST(nodes: templateASTNodes, contentType: compilationState.contentType)TemplateCompiler.swift:304 let templateAST = TemplateAST(nodes: templateASTNodes, contentType: compilationState.contentType)TemplateGenerator.swift:24 extension TemplateAST : CustomDebugStringConvertible {TemplateGenerator.swift:47 func stringFromTemplateAST(templateAST: TemplateAST) -> String {TemplateGenerator.swift:53 private func renderTemplateAST(templateAST: TemplateAST) {RenderingEngine.swift:25 init(templateAST: TemplateAST, context: Context) {RenderingEngine.swift:40 private let templateAST: TemplateASTRenderingEngine.swift:44 private func renderTemplateAST(templateAST: TemplateAST, inContext context: Context) throws {RenderingEngine.swift:216 var usedParentTemplateASTs: [TemplateAST] = []RenderingEngine.swift:248 private func resolveBlock(block: TemplateASTNode.Block, inChildTemplateAST childTemplateAST: TemplateAST) -> (TemplateASTNode.Block, Bool)Template.swift:205 let templateAST: TemplateASTTemplate.swift:207 init(repository: TemplateRepository, templateAST: TemplateAST, baseContext: Context) {Template.swift:279 templateAST: TemplateAST(nodes: [partialOverrideNode], contentType: self.templateAST.contentType),TemplateRepository.swift:237 func templateAST(named name: String, relativeToTemplateID baseTemplateID: TemplateID? = nil) throws -> TemplateAST {TemplateRepository.swift:259 let templateAST = TemplateAST()TemplateRepository.swift:274 func templateAST(string string: String, templateID: TemplateID? = nil) throws -> TemplateAST {TemplateRepository.swift:304 private var templateASTCache: [TemplateID: TemplateAST]SectionTag.swift:29 let innerTemplateAST: TemplateASTSectionTag.swift:31 init(innerTemplateAST: TemplateAST, openingToken: TemplateToken, innerTemplateString: String) {TemplateAST.swift:87 func updateFromTemplateAST(templateAST: TemplateAST) {TemplateASTNode.swift:36 let innerTemplateAST: TemplateASTTemplateASTNode.swift:42 let childTemplateAST: TemplateASTTemplateASTNode.swift:47 let templateAST: TemplateASTTemplateASTNode.swift:66 static func block(innerTemplateAST innerTemplateAST: TemplateAST, name: String) -> TemplateASTNode {TemplateASTNode.swift:70 static func partialOverride(childTemplateAST childTemplateAST: TemplateAST, parentTemplateAST: TemplateAST, parentPartialName: String? = nil) -> TemplateASTNode {TemplateASTNode.swift:70 static func partialOverride(childTemplateAST childTemplateAST: TemplateAST, parentTemplateAST: TemplateAST, parentPartialName: String? = nil) -> TemplateASTNode {TemplateASTNode.swift:74 static func partial(templateAST templateAST: TemplateAST, name: String?) -> TemplateASTNode {TemplateASTNode.swift:78 static func section(templateAST templateAST: TemplateAST, expression: Expression, inverted: Bool, openingToken: TemplateToken, innerTemplateString: String) -> TemplateASTNode {{ 0039 case Undefined
TemplateAST.swift:42 var type: TemplateASTTypeTemplateAST.swift:44 private init(type: TemplateASTType) {TemplateAST.swift:53 self.init(type: TemplateASTType.Undefined)TemplateAST.swift:60 self.init(type: TemplateASTType.Defined(nodes: nodes, contentType: contentType))0040 case Defined
TemplateCompiler.swift:275 case .Undefined:TemplateAST.swift:53 self.init(type: TemplateASTType.Undefined)TemplateAST.swift:68 case .Undefined:TemplateAST.swift:80 case .Undefined:(nodes: [TemplateASTNode], contentType: ContentType) 0041 } 0042 var type
TemplateCompiler.swift:277 case .Defined(nodes: _, contentType: let partialContentType):TemplateAST.swift:60 self.init(type: TemplateASTType.Defined(nodes: nodes, contentType: contentType))TemplateAST.swift:70 case .Defined(let nodes, _):TemplateAST.swift:82 case .Defined(_, let contentType):: TemplateASTType 0043 0044 private init
TemplateCompiler.swift:274 switch parentTemplateAST.type {TemplateAST.swift:45 self.type = typeTemplateAST.swift:67 switch type {TemplateAST.swift:79 switch type {TemplateAST.swift:88 self.type = templateAST.typeTemplateAST.swift:88 self.type = templateAST.type(type: TemplateASTType) { 0045 self.type = type 0046 } 0047 0048 0049 /** 0050 Returns an undefined TemplateAST. 0051 */ 0052 convenience init
TemplateAST.swift:53 self.init(type: TemplateASTType.Undefined)TemplateAST.swift:60 self.init(type: TemplateASTType.Defined(nodes: nodes, contentType: contentType))() { 0053 self.init(type: TemplateASTType.Undefined) 0054 } 0055 0056 /** 0057 Returns a defined TemplateAST. 0058 */ 0059 convenience init
TemplateRepository.swift:259 let templateAST = TemplateAST()(nodes: [TemplateASTNode], contentType: ContentType) { 0060 self.init(type: TemplateASTType.Defined(nodes: nodes, contentType: contentType)) 0061 } 0062 0063 /** 0064 Returns nil if the template AST is undefined. 0065 */ 0066 var nodes
TemplateCompiler.swift:39 return TemplateAST(nodes: compilationState.currentScope.templateASTNodes, contentType: compilationState.contentType)TemplateCompiler.swift:216 let templateAST = TemplateAST(nodes: templateASTNodes, contentType: compilationState.contentType)TemplateCompiler.swift:246 let templateAST = TemplateAST(nodes: templateASTNodes, contentType: compilationState.contentType)TemplateCompiler.swift:284 let templateAST = TemplateAST(nodes: templateASTNodes, contentType: compilationState.contentType)TemplateCompiler.swift:304 let templateAST = TemplateAST(nodes: templateASTNodes, contentType: compilationState.contentType)Template.swift:279 templateAST: TemplateAST(nodes: [partialOverrideNode], contentType: self.templateAST.contentType),: [TemplateASTNode]! { 0067 switch type { 0068 case .Undefined: 0069 return nil 0070 case .Defined(let nodes, _): 0071 return nodes 0072 } 0073 } 0074 0075 /** 0076 Returns nil if the template AST is undefined. 0077 */ 0078 var contentType
TemplateGenerator.swift:54 for node in templateAST.nodes {RenderingEngine.swift:61 for node in templateAST.nodes {RenderingEngine.swift:254 return childTemplateAST.nodes.reduce((block, false)) { (step, node) in: ContentType! { 0079 switch type { 0080 case .Undefined: 0081 return nil 0082 case .Defined(_, let contentType): 0083 return contentType 0084 } 0085 } 0086 0087 func updateFromTemplateAST
RenderingEngine.swift:34 return Rendering(buffer, templateAST.contentType)RenderingEngine.swift:56 let targetContentType = self.templateAST.contentType!RenderingEngine.swift:57 if templateAST.contentType == targetContentTypeRenderingEngine.swift:190 switch (templateAST.contentType!, rendering.contentType, escapesHTML) {Template.swift:92 return templateAST.contentTypeTemplate.swift:279 templateAST: TemplateAST(nodes: [partialOverrideNode], contentType: self.templateAST.contentType),(templateAST: TemplateAST) { 0088 self.type = templateAST.type 0089 } 0090 } 0091
TemplateRepository.swift:265 templateAST.updateFromTemplateAST(compiledAST)