Making your own tools using SwiftSyntax - Yusuke Kita === {%hackmd FGRWt1UuTFKk0wSbGgg-SA %} > 請從這裡開始 ## YouTube {%youtube NuUJbMx92TE %} ## Slide {%slideshare kitasuke/making-your-own-tool-using-swiftsyntax %} ### What's SwiftSyntax for? SwiftSyntax功能如format, search constant (A parsing tool) * Code Modifier * Code Analyzer SwiftSyntax把swift code轉成(emit)樹狀 ``` swift -frontend emit-syntax ``` * Swift AST Explorer ## Recap SwiftSyntax is a parsing tool emits syntax tree allows to inspect and transform source code ## Install 可以透過 SPM 安裝,建議指定特定 Tag,例如: * `swift-5.0.3-RELEASE` ``` swift .package(url: "https://github.com/apple/swift-syntax.git", .exact("<#Specify Release tag#>")), ``` ## interfaces syntaxParser SourceFileSyntax Syntax TonkenSyntax ### Resource * [Slide](https://github.com/kitasuke/talks/blob/master/2019-iplayground/swiftsyntax-tool.md) * [SE-0250: Swift Code Style Guidelines and Formatter](https://forums.swift.org/t/se-0250-swift-code-style-guidelines-and-formatter/21795) * [swift-format](https://github.com/apple/swift-format) * [SwiftConst](https://github.com/kitasuke/SwiftConst) * [SourceKit](https://github.com/apple/swift/tree/master/tools/SourceKit) * [sourcekit-lsp](https://github.com/apple/sourcekit-lsp) * [swift-ast-explorer](https://github.com/kishikawakatsumi/swift-ast-explorer) * [swift-ast-explorer demo](https://swift-ast-explorer.kishikawakatsumi.com) * [PDF](https://github.com/kitasuke/talks/blob/master/2019-iplayground/swiftsyntax-tool.pdf) * [Integrating libSyntax into the compiler pipeline](https://www.slideshare.net/kitasuke/integrating-libsyntax-into-the-compiler-pipeline) ###### tags:`iPlayground2019`