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 final class TemplateCompiler: TemplateTokenConsumer { 0024 private var state
TemplateRepository.swift:276 let compiler = TemplateCompiler(: CompilerState 0025 private let repository
TemplateCompiler.swift:29 self.state = .Compiling(CompilationState(contentType: contentType))TemplateCompiler.swift:35 switch(state) {TemplateCompiler.swift:58 state = .Error(error)TemplateCompiler.swift:62 switch(state) {TemplateCompiler.swift:321 state = .Error(error): TemplateRepository 0026 private let templateID
TemplateCompiler.swift:30 self.repository = repositoryTemplateCompiler.swift:273 let parentTemplateAST = try repository.templateAST(named: parentPartialName, relativeToTemplateID:templateID)TemplateCompiler.swift:313 let partialTemplateAST = try repository.templateAST(named: partialName, relativeToTemplateID: templateID): TemplateID? 0027 0028 init
TemplateCompiler.swift:31 self.templateID = templateIDTemplateCompiler.swift:273 let parentTemplateAST = try repository.templateAST(named: parentPartialName, relativeToTemplateID:templateID)TemplateCompiler.swift:313 let partialTemplateAST = try repository.templateAST(named: partialName, relativeToTemplateID: templateID)(contentType: ContentType, repository: TemplateRepository, templateID: TemplateID?) { 0029 self.state = .Compiling(CompilationState(contentType: contentType)) 0030 self.repository = repository 0031 self.templateID = templateID 0032 } 0033 0034 func templateAST
TemplateRepository.swift:276 let compiler = TemplateCompiler(() throws -> TemplateAST { 0035 switch(state) { 0036 case .Compiling(let compilationState): 0037 switch compilationState.currentScope.type { 0038 case .Root: 0039 return TemplateAST(nodes: compilationState.currentScope.templateASTNodes, contentType: compilationState.contentType) 0040 case .Section(openingToken: let openingToken, expression: _): 0041 throw MustacheError(kind: .ParseError, message: "Unclosed Mustache tag", templateID: openingToken.templateID, lineNumber: openingToken.lineNumber) 0042 case .InvertedSection(openingToken: let openingToken, expression: _): 0043 throw MustacheError(kind: .ParseError, message: "Unclosed Mustache tag", templateID: openingToken.templateID, lineNumber: openingToken.lineNumber) 0044 case .PartialOverride(openingToken: let openingToken, parentPartialName: _): 0045 throw MustacheError(kind: .ParseError, message: "Unclosed Mustache tag", templateID: openingToken.templateID, lineNumber: openingToken.lineNumber) 0046 case .Block(openingToken: let openingToken, blockName: _): 0047 throw MustacheError(kind: .ParseError, message: "Unclosed Mustache tag", templateID: openingToken.templateID, lineNumber: openingToken.lineNumber) 0048 } 0049 case .Error(let compilationError): 0050 throw compilationError 0051 } 0052 } 0053 0054 0055 // MARK: - TemplateTokenConsumer 0056 0057 func parser(parser: TemplateParser, didFailWithError error: ErrorType) { 0058 state = .Error(error) 0059 } 0060 0061 func parser(parser: TemplateParser, shouldContinueAfterParsingToken token: TemplateToken) -> Bool { 0062 switch(state) { 0063 case .Error: 0064 return false 0065 case .Compiling(let compilationState): 0066 do { 0067 switch(token.type) { 0068 0069 case .SetDelimiters: 0070 // noop 0071 break 0072 0073 case .Comment: 0074 // noop 0075 break 0076 0077 case .Pragma(content: let content): 0078 let pragma = content.stringByTrimmingCharactersInSet(CharacterSet.whitespaceAndNewline) 0079 if pragma == "CONTENT_TYPE : TEXT" { 0080 switch compilationState.compilerContentType { 0081 case .Unlocked: 0082 compilationState.compilerContentType = .Unlocked(.Text) 0083 case .Locked(_): 0084 throw MustacheError(kind: .ParseError, message:"CONTENT_TYPE:TEXT pragma tag must prepend any Mustache variable, section, or partial tag.", templateID: token.templateID, lineNumber: token.lineNumber) 0085 } 0086 } else if pragma == "CONTENT_TYPE : HTML" { 0087 switch compilationState.compilerContentType { 0088 case .Unlocked: 0089 compilationState.compilerContentType = .Unlocked(.HTML) 0090 case .Locked(_): 0091 throw MustacheError(kind: .ParseError, message:"CONTENT_TYPE:HTML pragma tag must prepend any Mustache variable, section, or partial tag.", templateID: token.templateID, lineNumber: token.lineNumber) 0092 } 0093 } else { 0094 throw MustacheError(kind: .ParseError, message:"Syntax should be \"CONTENT_TYPE : TEXT\" or \"CONTENT_TYPE : HTML\"", templateID: token.templateID, lineNumber: token.lineNumber) 0095 } 0096 0097 case .Text(text: let text): 0098 switch compilationState.currentScope.type { 0099 case .PartialOverride: 0100 // Text inside a partial override tag is not rendered. 0101 // 0102 // We could throw an error, like we do for illegal tags 0103 // inside a partial override tag. 0104 // 0105 // But Hogan.js has an explicit test for "successfully" 0106 // ignored text. So let's not throw. 0107 // 0108 // Ignore text inside a partial override tag: 0109 break 0110 default: 0111 compilationState.currentScope.appendNode(TemplateASTNode.text(text: text)) 0112 } 0113 0114 case .EscapedVariable(content: let content, tagDelimiterPair: _): 0115 switch compilationState.currentScope.type { 0116 case .PartialOverride: 0117 throw MustacheError(kind: .ParseError, message:"Illegal tag inside a partial override tag.", templateID: token.templateID, lineNumber: token.lineNumber) 0118 default: 0119 var empty = false 0120 do { 0121 let expression = try ExpressionParser().parse(content, empty: &empty) 0122 compilationState.currentScope.appendNode(TemplateASTNode.variable(expression: expression, contentType: compilationState.contentType, escapesHTML: true, token: token)) 0123 compilationState.compilerContentType = .Locked(compilationState.contentType) 0124 } catch let error as MustacheError { 0125 throw error.errorWith(templateID: token.templateID, lineNumber: token.lineNumber) 0126 } catch { 0127 throw MustacheError(kind: .ParseError, templateID: token.templateID, lineNumber: token.lineNumber, underlyingError: error) 0128 } 0129 } 0130 0131 case .UnescapedVariable(content: let content, tagDelimiterPair: _): 0132 switch compilationState.currentScope.type { 0133 case .PartialOverride: 0134 throw MustacheError(kind: .ParseError, message: "Illegal tag inside a partial override tag: \(token.templateSubstring)", templateID: token.templateID, lineNumber: token.lineNumber) 0135 default: 0136 var empty = false 0137 do { 0138 let expression = try ExpressionParser().parse(content, empty: &empty) 0139 compilationState.currentScope.appendNode(TemplateASTNode.variable(expression: expression, contentType: compilationState.contentType, escapesHTML: false, token: token)) 0140 compilationState.compilerContentType = .Locked(compilationState.contentType) 0141 } catch let error as MustacheError { 0142 throw error.errorWith(templateID: token.templateID, lineNumber: token.lineNumber) 0143 } catch { 0144 throw MustacheError(kind: .ParseError, templateID: token.templateID, lineNumber: token.lineNumber, underlyingError: error) 0145 } 0146 } 0147 0148 case .Section(content: let content, tagDelimiterPair: _): 0149 switch compilationState.currentScope.type { 0150 case .PartialOverride: 0151 throw MustacheError(kind: .ParseError, message: "Illegal tag inside a partial override tag: \(token.templateSubstring)", templateID: token.templateID, lineNumber: token.lineNumber) 0152 default: 0153 var empty = false 0154 do { 0155 let expression = try ExpressionParser().parse(content, empty: &empty) 0156 compilationState.pushScope(Scope(type: .Section(openingToken: token, expression: expression))) 0157 compilationState.compilerContentType = .Locked(compilationState.contentType) 0158 } catch let error as MustacheError { 0159 throw error.errorWith(templateID: token.templateID, lineNumber: token.lineNumber) 0160 } catch { 0161 throw MustacheError(kind: .ParseError, templateID: token.templateID, lineNumber: token.lineNumber, underlyingError: error) 0162 } 0163 } 0164 0165 case .InvertedSection(content: let content, tagDelimiterPair: _): 0166 switch compilationState.currentScope.type { 0167 case .PartialOverride: 0168 throw MustacheError(kind: .ParseError, message: "Illegal tag inside a partial override tag: \(token.templateSubstring)", templateID: token.templateID, lineNumber: token.lineNumber) 0169 default: 0170 var empty = false 0171 do { 0172 let expression = try ExpressionParser().parse(content, empty: &empty) 0173 compilationState.pushScope(Scope(type: .InvertedSection(openingToken: token, expression: expression))) 0174 compilationState.compilerContentType = .Locked(compilationState.contentType) 0175 } catch let error as MustacheError { 0176 throw error.errorWith(templateID: token.templateID, lineNumber: token.lineNumber) 0177 } catch { 0178 throw MustacheError(kind: .ParseError, templateID: token.templateID, lineNumber: token.lineNumber, underlyingError: error) 0179 } 0180 } 0181 0182 case .Block(content: let content): 0183 var empty: Bool = false 0184 let blockName = try blockNameFromString(content, inToken: token, empty: &empty) 0185 compilationState.pushScope(Scope(type: .Block(openingToken: token, blockName: blockName))) 0186 compilationState.compilerContentType = .Locked(compilationState.contentType) 0187 0188 case .PartialOverride(content: let content): 0189 var empty: Bool = false 0190 let parentPartialName = try partialNameFromString(content, inToken: token, empty: &empty) 0191 compilationState.pushScope(Scope(type: .PartialOverride(openingToken: token, parentPartialName: parentPartialName))) 0192 compilationState.compilerContentType = .Locked(compilationState.contentType) 0193 0194 case .Close(content: let content): 0195 switch compilationState.currentScope.type { 0196 case .Root: 0197 throw MustacheError(kind: .ParseError, message: "Unmatched closing tag", templateID: token.templateID, lineNumber: token.lineNumber) 0198 0199 case .Section(openingToken: let openingToken, expression: let closedExpression): 0200 var empty: Bool = false 0201 var expression: Expression? 0202 do { 0203 expression = try ExpressionParser().parse(content, empty: &empty) 0204 } catch let error as MustacheError { 0205 if empty == false { 0206 throw error.errorWith(templateID: token.templateID, lineNumber: token.lineNumber) 0207 } 0208 } catch { 0209 throw MustacheError(kind: .ParseError, templateID: token.templateID, lineNumber: token.lineNumber, underlyingError: error) 0210 } 0211 if expression != nil && expression != closedExpression { 0212 throw MustacheError(kind: .ParseError, message: "Unmatched closing tag", templateID: token.templateID, lineNumber: token.lineNumber) 0213 } 0214 0215 let templateASTNodes = compilationState.currentScope.templateASTNodes 0216 let templateAST = TemplateAST(nodes: templateASTNodes, contentType: compilationState.contentType) 0217 0218 // // TODO: uncomment and make it compile 0219 // if token.templateString !== openingToken.templateString { 0220 // fatalError("Not implemented") 0221 // } 0222 let templateString = token.templateString 0223 let innerContentRange = openingToken.range.endIndex..<token.range.startIndex 0224 let sectionTag = TemplateASTNode.section(templateAST: templateAST, expression: closedExpression, inverted: false, openingToken: openingToken, innerTemplateString: templateString[innerContentRange]) 0225 0226 compilationState.popCurrentScope() 0227 compilationState.currentScope.appendNode(sectionTag) 0228 0229 case .InvertedSection(openingToken: let openingToken, expression: let closedExpression): 0230 var empty: Bool = false 0231 var expression: Expression? 0232 do { 0233 expression = try ExpressionParser().parse(content, empty: &empty) 0234 } catch let error as MustacheError { 0235 if empty == false { 0236 throw error.errorWith(templateID: token.templateID, lineNumber: token.lineNumber) 0237 } 0238 } catch { 0239 throw MustacheError(kind: .ParseError, templateID: token.templateID, lineNumber: token.lineNumber, underlyingError: error) 0240 } 0241 if expression != nil && expression != closedExpression { 0242 throw MustacheError(kind: .ParseError, message: "Unmatched closing tag", templateID: token.templateID, lineNumber: token.lineNumber) 0243 } 0244 0245 let templateASTNodes = compilationState.currentScope.templateASTNodes 0246 let templateAST = TemplateAST(nodes: templateASTNodes, contentType: compilationState.contentType) 0247 0248 // // TODO: uncomment and make it compile 0249 // if token.templateString !== openingToken.templateString { 0250 // fatalError("Not implemented") 0251 // } 0252 let templateString = token.templateString 0253 let innerContentRange = openingToken.range.endIndex..<token.range.startIndex 0254 let sectionTag = TemplateASTNode.section(templateAST: templateAST, expression: closedExpression, inverted: true, openingToken: openingToken, innerTemplateString: templateString[innerContentRange]) 0255 0256 compilationState.popCurrentScope() 0257 compilationState.currentScope.appendNode(sectionTag) 0258 0259 case .PartialOverride(openingToken: _, parentPartialName: let parentPartialName): 0260 var empty: Bool = false 0261 var partialName: String? 0262 do { 0263 partialName = try partialNameFromString(content, inToken: token, empty: &empty) 0264 } catch { 0265 if empty == false { 0266 throw error 0267 } 0268 } 0269 if partialName != nil && partialName != parentPartialName { 0270 throw MustacheError(kind: .ParseError, message: "Unmatched closing tag", templateID: token.templateID, lineNumber: token.lineNumber) 0271 } 0272 0273 let parentTemplateAST = try repository.templateAST(named: parentPartialName, relativeToTemplateID:templateID) 0274 switch parentTemplateAST.type { 0275 case .Undefined: 0276 break 0277 case .Defined(nodes: _, contentType: let partialContentType): 0278 if partialContentType != compilationState.contentType { 0279 throw MustacheError(kind: .ParseError, message: "Content type mismatch", templateID: token.templateID, lineNumber: token.lineNumber) 0280 } 0281 } 0282 0283 let templateASTNodes = compilationState.currentScope.templateASTNodes 0284 let templateAST = TemplateAST(nodes: templateASTNodes, contentType: compilationState.contentType) 0285 let partialOverrideNode = TemplateASTNode.partialOverride(childTemplateAST: templateAST, parentTemplateAST: parentTemplateAST, parentPartialName: parentPartialName) 0286 compilationState.popCurrentScope() 0287 compilationState.currentScope.appendNode(partialOverrideNode) 0288 0289 case .Block(openingToken: _, blockName: let closedBlockName): 0290 var empty: Bool = false 0291 var blockName: String? 0292 do { 0293 blockName = try blockNameFromString(content, inToken: token, empty: &empty) 0294 } catch { 0295 if empty == false { 0296 throw error 0297 } 0298 } 0299 if blockName != nil && blockName != closedBlockName { 0300 throw MustacheError(kind: .ParseError, message: "Unmatched closing tag", templateID: token.templateID, lineNumber: token.lineNumber) 0301 } 0302 0303 let templateASTNodes = compilationState.currentScope.templateASTNodes 0304 let templateAST = TemplateAST(nodes: templateASTNodes, contentType: compilationState.contentType) 0305 let blockNode = TemplateASTNode.block(innerTemplateAST: templateAST, name: closedBlockName) 0306 compilationState.popCurrentScope() 0307 compilationState.currentScope.appendNode(blockNode) 0308 } 0309 0310 case .Partial(content: let content): 0311 var empty: Bool = false 0312 let partialName = try partialNameFromString(content, inToken: token, empty: &empty) 0313 let partialTemplateAST = try repository.templateAST(named: partialName, relativeToTemplateID: templateID) 0314 let partialNode = TemplateASTNode.partial(templateAST: partialTemplateAST, name: partialName) 0315 compilationState.currentScope.appendNode(partialNode) 0316 compilationState.compilerContentType = .Locked(compilationState.contentType) 0317 } 0318 0319 return true 0320 } catch { 0321 state = .Error(error) 0322 return false 0323 } 0324 } 0325 } 0326 0327 0328 // MARK: - Private 0329 0330 private class CompilationState
TemplateRepository.swift:290 return try compiler.templateAST(){ 0331 var currentScope
TemplateCompiler.swift:29 self.state = .Compiling(CompilationState(contentType: contentType))TemplateCompiler.swift:366 case Compiling(CompilationState): Scope { 0332 return scopeStack[scopeStack.endIndex - 1] 0333 } 0334 var contentType
TemplateCompiler.swift:37 switch compilationState.currentScope.type {TemplateCompiler.swift:39 return TemplateAST(nodes: compilationState.currentScope.templateASTNodes, contentType: compilationState.contentType)TemplateCompiler.swift:98 switch compilationState.currentScope.type {TemplateCompiler.swift:111 compilationState.currentScope.appendNode(TemplateASTNode.text(text: text))TemplateCompiler.swift:115 switch compilationState.currentScope.type {TemplateCompiler.swift:122 compilationState.currentScope.appendNode(TemplateASTNode.variable(expression: expression, contentType: compilationState.contentType, escapesHTML: true, token: token))TemplateCompiler.swift:132 switch compilationState.currentScope.type {TemplateCompiler.swift:139 compilationState.currentScope.appendNode(TemplateASTNode.variable(expression: expression, contentType: compilationState.contentType, escapesHTML: false, token: token))TemplateCompiler.swift:149 switch compilationState.currentScope.type {TemplateCompiler.swift:166 switch compilationState.currentScope.type {TemplateCompiler.swift:195 switch compilationState.currentScope.type {TemplateCompiler.swift:215 let templateASTNodes = compilationState.currentScope.templateASTNodesTemplateCompiler.swift:227 compilationState.currentScope.appendNode(sectionTag)TemplateCompiler.swift:245 let templateASTNodes = compilationState.currentScope.templateASTNodesTemplateCompiler.swift:257 compilationState.currentScope.appendNode(sectionTag)TemplateCompiler.swift:283 let templateASTNodes = compilationState.currentScope.templateASTNodesTemplateCompiler.swift:287 compilationState.currentScope.appendNode(partialOverrideNode)TemplateCompiler.swift:303 let templateASTNodes = compilationState.currentScope.templateASTNodesTemplateCompiler.swift:307 compilationState.currentScope.appendNode(blockNode)TemplateCompiler.swift:315 compilationState.currentScope.appendNode(partialNode): ContentType { 0335 switch compilerContentType { 0336 case .Unlocked(let contentType): 0337 return contentType 0338 case .Locked(let contentType): 0339 return contentType 0340 } 0341 } 0342 0343 init
TemplateCompiler.swift:39 return TemplateAST(nodes: compilationState.currentScope.templateASTNodes, contentType: compilationState.contentType)TemplateCompiler.swift:122 compilationState.currentScope.appendNode(TemplateASTNode.variable(expression: expression, contentType: compilationState.contentType, escapesHTML: true, token: token))TemplateCompiler.swift:123 compilationState.compilerContentType = .Locked(compilationState.contentType)TemplateCompiler.swift:139 compilationState.currentScope.appendNode(TemplateASTNode.variable(expression: expression, contentType: compilationState.contentType, escapesHTML: false, token: token))TemplateCompiler.swift:140 compilationState.compilerContentType = .Locked(compilationState.contentType)TemplateCompiler.swift:157 compilationState.compilerContentType = .Locked(compilationState.contentType)TemplateCompiler.swift:174 compilationState.compilerContentType = .Locked(compilationState.contentType)TemplateCompiler.swift:186 compilationState.compilerContentType = .Locked(compilationState.contentType)TemplateCompiler.swift:192 compilationState.compilerContentType = .Locked(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:278 if partialContentType != compilationState.contentType {TemplateCompiler.swift:284 let templateAST = TemplateAST(nodes: templateASTNodes, contentType: compilationState.contentType)TemplateCompiler.swift:304 let templateAST = TemplateAST(nodes: templateASTNodes, contentType: compilationState.contentType)TemplateCompiler.swift:316 compilationState.compilerContentType = .Locked(compilationState.contentType)(contentType: ContentType) { 0344 self.compilerContentType = .Unlocked(contentType) 0345 self.scopeStack = [Scope(type: .Root)] 0346 } 0347 0348 func popCurrentScope
TemplateCompiler.swift:29 self.state = .Compiling(CompilationState(contentType: contentType))() { 0349 scopeStack.removeLast() 0350 } 0351 0352 func pushScope
TemplateCompiler.swift:226 compilationState.popCurrentScope()TemplateCompiler.swift:256 compilationState.popCurrentScope()TemplateCompiler.swift:286 compilationState.popCurrentScope()TemplateCompiler.swift:306 compilationState.popCurrentScope()(scope: Scope) { 0353 scopeStack.append(scope) 0354 } 0355 0356 enum CompilerContentType
TemplateCompiler.swift:156 compilationState.pushScope(Scope(type: .Section(openingToken: token, expression: expression)))TemplateCompiler.swift:173 compilationState.pushScope(Scope(type: .InvertedSection(openingToken: token, expression: expression)))TemplateCompiler.swift:185 compilationState.pushScope(Scope(type: .Block(openingToken: token, blockName: blockName)))TemplateCompiler.swift:191 compilationState.pushScope(Scope(type: .PartialOverride(openingToken: token, parentPartialName: parentPartialName))){ 0357 case Unlocked
TemplateCompiler.swift:361 var compilerContentType: CompilerContentType(ContentType) 0358 case Locked
TemplateCompiler.swift:81 case .Unlocked:TemplateCompiler.swift:82 compilationState.compilerContentType = .Unlocked(.Text)TemplateCompiler.swift:88 case .Unlocked:TemplateCompiler.swift:89 compilationState.compilerContentType = .Unlocked(.HTML)TemplateCompiler.swift:336 case .Unlocked(let contentType):TemplateCompiler.swift:344 self.compilerContentType = .Unlocked(contentType)(ContentType) 0359 } 0360 0361 var compilerContentType
TemplateCompiler.swift:83 case .Locked(_):TemplateCompiler.swift:90 case .Locked(_):TemplateCompiler.swift:123 compilationState.compilerContentType = .Locked(compilationState.contentType)TemplateCompiler.swift:140 compilationState.compilerContentType = .Locked(compilationState.contentType)TemplateCompiler.swift:157 compilationState.compilerContentType = .Locked(compilationState.contentType)TemplateCompiler.swift:174 compilationState.compilerContentType = .Locked(compilationState.contentType)TemplateCompiler.swift:186 compilationState.compilerContentType = .Locked(compilationState.contentType)TemplateCompiler.swift:192 compilationState.compilerContentType = .Locked(compilationState.contentType)TemplateCompiler.swift:316 compilationState.compilerContentType = .Locked(compilationState.contentType)TemplateCompiler.swift:338 case .Locked(let contentType):: CompilerContentType 0362 private var scopeStack
TemplateCompiler.swift:80 switch compilationState.compilerContentType {TemplateCompiler.swift:82 compilationState.compilerContentType = .Unlocked(.Text)TemplateCompiler.swift:87 switch compilationState.compilerContentType {TemplateCompiler.swift:89 compilationState.compilerContentType = .Unlocked(.HTML)TemplateCompiler.swift:123 compilationState.compilerContentType = .Locked(compilationState.contentType)TemplateCompiler.swift:140 compilationState.compilerContentType = .Locked(compilationState.contentType)TemplateCompiler.swift:157 compilationState.compilerContentType = .Locked(compilationState.contentType)TemplateCompiler.swift:174 compilationState.compilerContentType = .Locked(compilationState.contentType)TemplateCompiler.swift:186 compilationState.compilerContentType = .Locked(compilationState.contentType)TemplateCompiler.swift:192 compilationState.compilerContentType = .Locked(compilationState.contentType)TemplateCompiler.swift:316 compilationState.compilerContentType = .Locked(compilationState.contentType)TemplateCompiler.swift:335 switch compilerContentType {TemplateCompiler.swift:344 self.compilerContentType = .Unlocked(contentType): [Scope] 0363 } 0364 0365 private enum CompilerState
TemplateCompiler.swift:332 return scopeStack[scopeStack.endIndex - 1]TemplateCompiler.swift:332 return scopeStack[scopeStack.endIndex - 1]TemplateCompiler.swift:345 self.scopeStack = [Scope(type: .Root)]TemplateCompiler.swift:349 scopeStack.removeLast()TemplateCompiler.swift:353 scopeStack.append(scope){ 0366 case Compiling
TemplateCompiler.swift:24 private var state: CompilerState(CompilationState) 0367 case Error
TemplateCompiler.swift:29 self.state = .Compiling(CompilationState(contentType: contentType))TemplateCompiler.swift:36 case .Compiling(let compilationState):TemplateCompiler.swift:65 case .Compiling(let compilationState):(ErrorType) 0368 } 0369 0370 private class Scope
TemplateCompiler.swift:49 case .Error(let compilationError):TemplateCompiler.swift:58 state = .Error(error)TemplateCompiler.swift:63 case .Error:TemplateCompiler.swift:321 state = .Error(error){ 0371 let type
TemplateCompiler.swift:156 compilationState.pushScope(Scope(type: .Section(openingToken: token, expression: expression)))TemplateCompiler.swift:173 compilationState.pushScope(Scope(type: .InvertedSection(openingToken: token, expression: expression)))TemplateCompiler.swift:185 compilationState.pushScope(Scope(type: .Block(openingToken: token, blockName: blockName)))TemplateCompiler.swift:191 compilationState.pushScope(Scope(type: .PartialOverride(openingToken: token, parentPartialName: parentPartialName)))TemplateCompiler.swift:331 var currentScope: Scope {TemplateCompiler.swift:345 self.scopeStack = [Scope(type: .Root)]TemplateCompiler.swift:352 func pushScope(scope: Scope) {TemplateCompiler.swift:362 private var scopeStack: [Scope]: ScopeType 0372 var templateASTNodes
TemplateCompiler.swift:37 switch compilationState.currentScope.type {TemplateCompiler.swift:98 switch compilationState.currentScope.type {TemplateCompiler.swift:115 switch compilationState.currentScope.type {TemplateCompiler.swift:132 switch compilationState.currentScope.type {TemplateCompiler.swift:149 switch compilationState.currentScope.type {TemplateCompiler.swift:166 switch compilationState.currentScope.type {TemplateCompiler.swift:195 switch compilationState.currentScope.type {TemplateCompiler.swift:375 self.type = type: [TemplateASTNode] 0373 0374 init
TemplateCompiler.swift:39 return TemplateAST(nodes: compilationState.currentScope.templateASTNodes, contentType: compilationState.contentType)TemplateCompiler.swift:215 let templateASTNodes = compilationState.currentScope.templateASTNodesTemplateCompiler.swift:245 let templateASTNodes = compilationState.currentScope.templateASTNodesTemplateCompiler.swift:283 let templateASTNodes = compilationState.currentScope.templateASTNodesTemplateCompiler.swift:303 let templateASTNodes = compilationState.currentScope.templateASTNodesTemplateCompiler.swift:376 self.templateASTNodes = []TemplateCompiler.swift:380 templateASTNodes.append(node)(type: ScopeType) { 0375 self.type = type 0376 self.templateASTNodes = [] 0377 } 0378 0379 func appendNode
TemplateCompiler.swift:156 compilationState.pushScope(Scope(type: .Section(openingToken: token, expression: expression)))TemplateCompiler.swift:173 compilationState.pushScope(Scope(type: .InvertedSection(openingToken: token, expression: expression)))TemplateCompiler.swift:185 compilationState.pushScope(Scope(type: .Block(openingToken: token, blockName: blockName)))TemplateCompiler.swift:191 compilationState.pushScope(Scope(type: .PartialOverride(openingToken: token, parentPartialName: parentPartialName)))TemplateCompiler.swift:345 self.scopeStack = [Scope(type: .Root)](node: TemplateASTNode) { 0380 templateASTNodes.append(node) 0381 } 0382 0383 enum ScopeType
TemplateCompiler.swift:111 compilationState.currentScope.appendNode(TemplateASTNode.text(text: text))TemplateCompiler.swift:122 compilationState.currentScope.appendNode(TemplateASTNode.variable(expression: expression, contentType: compilationState.contentType, escapesHTML: true, token: token))TemplateCompiler.swift:139 compilationState.currentScope.appendNode(TemplateASTNode.variable(expression: expression, contentType: compilationState.contentType, escapesHTML: false, token: token))TemplateCompiler.swift:227 compilationState.currentScope.appendNode(sectionTag)TemplateCompiler.swift:257 compilationState.currentScope.appendNode(sectionTag)TemplateCompiler.swift:287 compilationState.currentScope.appendNode(partialOverrideNode)TemplateCompiler.swift:307 compilationState.currentScope.appendNode(blockNode)TemplateCompiler.swift:315 compilationState.currentScope.appendNode(partialNode){ 0384 case Root
TemplateCompiler.swift:371 let type: ScopeTypeTemplateCompiler.swift:374 init(type: ScopeType) {0385 case Section
TemplateCompiler.swift:38 case .Root:TemplateCompiler.swift:196 case .Root:TemplateCompiler.swift:345 self.scopeStack = [Scope(type: .Root)](openingToken: TemplateToken, expression: Expression) 0386 case InvertedSection
TemplateCompiler.swift:40 case .Section(openingToken: let openingToken, expression: _):TemplateCompiler.swift:156 compilationState.pushScope(Scope(type: .Section(openingToken: token, expression: expression)))TemplateCompiler.swift:199 case .Section(openingToken: let openingToken, expression: let closedExpression):(openingToken: TemplateToken, expression: Expression) 0387 case PartialOverride
TemplateCompiler.swift:42 case .InvertedSection(openingToken: let openingToken, expression: _):TemplateCompiler.swift:173 compilationState.pushScope(Scope(type: .InvertedSection(openingToken: token, expression: expression)))TemplateCompiler.swift:229 case .InvertedSection(openingToken: let openingToken, expression: let closedExpression):(openingToken: TemplateToken, parentPartialName: String) 0388 case Block
TemplateCompiler.swift:44 case .PartialOverride(openingToken: let openingToken, parentPartialName: _):TemplateCompiler.swift:99 case .PartialOverride:TemplateCompiler.swift:116 case .PartialOverride:TemplateCompiler.swift:133 case .PartialOverride:TemplateCompiler.swift:150 case .PartialOverride:TemplateCompiler.swift:167 case .PartialOverride:TemplateCompiler.swift:191 compilationState.pushScope(Scope(type: .PartialOverride(openingToken: token, parentPartialName: parentPartialName)))TemplateCompiler.swift:259 case .PartialOverride(openingToken: _, parentPartialName: let parentPartialName):(openingToken: TemplateToken, blockName: String) 0389 } 0390 } 0391 0392 private func blockNameFromString
TemplateCompiler.swift:46 case .Block(openingToken: let openingToken, blockName: _):TemplateCompiler.swift:185 compilationState.pushScope(Scope(type: .Block(openingToken: token, blockName: blockName)))TemplateCompiler.swift:289 case .Block(openingToken: _, blockName: let closedBlockName):(string: String, inToken token: TemplateToken, inout empty: Bool) throws -> String { 0393 let whiteSpace = CharacterSet.whitespaceAndNewline 0394 let blockName = string.stringByTrimmingCharactersInSet(whiteSpace) 0395 if blockName.characters.count == 0 { 0396 empty = true 0397 throw MustacheError(kind: .ParseError, message: "Missing block name", templateID: token.templateID, lineNumber: token.lineNumber) 0398 } else if blockName.containsCharacterFromSet(whiteSpace) { 0399 empty = false 0400 throw MustacheError(kind: .ParseError, message: "Invalid block name", templateID: token.templateID, lineNumber: token.lineNumber) 0401 } 0402 return blockName 0403 } 0404 0405 private func partialNameFromString
TemplateCompiler.swift:184 let blockName = try blockNameFromString(content, inToken: token, empty: &empty)TemplateCompiler.swift:293 blockName = try blockNameFromString(content, inToken: token, empty: &empty)(string: String, inToken token: TemplateToken, inout empty: Bool) throws -> String { 0406 let whiteSpace = CharacterSet.whitespaceAndNewline 0407 let partialName = string.stringByTrimmingCharactersInSet(whiteSpace) 0408 if partialName.characters.count == 0 { 0409 empty = true 0410 throw MustacheError(kind: .ParseError, message: "Missing template name", templateID: token.templateID, lineNumber: token.lineNumber) 0411 } else if partialName.containsCharacterFromSet(whiteSpace) { 0412 empty = false 0413 throw MustacheError(kind: .ParseError, message: "Invalid template name", templateID: token.templateID, lineNumber: token.lineNumber) 0414 } 0415 return partialName 0416 } 0417 } 0418 0419 0420 0421 extension String { 0422 func stringByTrimmingCharactersInSet
TemplateCompiler.swift:190 let parentPartialName = try partialNameFromString(content, inToken: token, empty: &empty)TemplateCompiler.swift:263 partialName = try partialNameFromString(content, inToken: token, empty: &empty)TemplateCompiler.swift:312 let partialName = try partialNameFromString(content, inToken: token, empty: &empty)(characterSet: Set<Character>) -> String { 0423 let string = stringByTrimmingFromStartCharactersInSet(characterSet) 0424 return string.stringByTrimmingFromEndCharactersInSet(characterSet) 0425 } 0426 0427 private func stringByTrimmingFromStartCharactersInSet
TemplateCompiler.swift:78 let pragma = content.stringByTrimmingCharactersInSet(CharacterSet.whitespaceAndNewline)TemplateCompiler.swift:394 let blockName = string.stringByTrimmingCharactersInSet(whiteSpace)TemplateCompiler.swift:407 let partialName = string.stringByTrimmingCharactersInSet(whiteSpace)(characterSet: Set<Character>) -> String { 0428 var trimStartIndex: Int = characters.count 0429 for (index, character) in characters.enumerate() { 0430 if !characterSet.contains(character) { 0431 trimStartIndex = index 0432 break 0433 } 0434 } 0435 return self[startIndex.advancedBy(trimStartIndex) ..< endIndex] 0436 } 0437 0438 private func stringByTrimmingFromEndCharactersInSet
TemplateCompiler.swift:423 let string = stringByTrimmingFromStartCharactersInSet(characterSet)(characterSet: Set<Character>) -> String { 0439 var trimEndIndex: Int = characters.count 0440 for (index, character) in characters.reverse().enumerate() { 0441 if !characterSet.contains(character) { 0442 trimEndIndex = index 0443 break 0444 } 0445 } 0446 return self[startIndex ..< startIndex.advancedBy(characters.count - trimEndIndex)] 0447 } 0448 } 0449 0450 extension String { 0451 func containsCharacterFromSet
TemplateCompiler.swift:424 return string.stringByTrimmingFromEndCharactersInSet(characterSet)(characterSet: Set<Character>) -> Bool { 0452 for character in characters { 0453 if characterSet.contains(character) { 0454 return false 0455 } 0456 } 0457 return true 0458 } 0459 }
TemplateCompiler.swift:398 } else if blockName.containsCharacterFromSet(whiteSpace) {TemplateCompiler.swift:411 } else if partialName.containsCharacterFromSet(whiteSpace) {