0001 // 0002 // Syntax.swift 0003 // SourceKitten 0004 // 0005 // Created by JP Simard on 2015-01-07. 0006 // Copyright (c) 2015 SourceKitten. All rights reserved. 0007 // 0008 0009 import Commandant 0010 import Foundation 0011 import Result 0012 import SourceKittenFramework 0013 0014 struct SyntaxCommand: CommandType { 0015 let verb = "syntax" 0016 let function = "Print Swift syntax information as JSON" 0017 0018 func run(options: SyntaxOptions) -> Result<(), SourceKittenError> { 0019 if !options.file.isEmpty { 0020 if let file = File(path: options.file) { 0021 print(SyntaxMap(file: file)) 0022 return .Success() 0023 } 0024 return .Failure(.ReadFailed(path: options.file)) 0025 } 0026 print(SyntaxMap(file: File(contents: options.text))) 0027 return .Success() 0028 } 0029 } 0030 0031 struct SyntaxOptions
main.swift:19 registry.register(SyntaxCommand()): OptionsType { 0032 let file: String 0033 let text: String 0034 0035 static func create(file: String) -> (text: String) -> SyntaxOptions { 0036 return { text in 0037 self.init(file: file, text: text) 0038 } 0039 } 0040 0041 static func evaluate(m: CommandMode) -> Result<SyntaxOptions, CommandantError<SourceKittenError>> { 0042 return create 0043 <*> m <| Option(key: "file", defaultValue: "", usage: "relative or absolute path of Swift file to parse") 0044 <*> m <| Option(key: "text", defaultValue: "", usage: "Swift code text to parse") 0045 } 0046 } 0047
SyntaxCommand.swift:35 static func create(file: String) -> (text: String) -> SyntaxOptions {