Upgrade to Pro — share decks privately, control downloads, hide ads and more …

SwiftSyntaxBuilder = SwiftSyntax × Function Bui...

Akio Yasui
September 26, 2019

SwiftSyntaxBuilder = SwiftSyntax × Function Builders

Akio Yasui

September 26, 2019
Tweet

More Decks by Akio Yasui

Other Decks in Programming

Transcript

  1. ࣗݾ঺հ ҆Ҫ ӯஉ / Akio Yasui @akkyie 2019 ೥ 4

    ݄ AbemaTV ৽ଔೖࣾ . 2 — SwiftSyntaxBuilder = SwiftSyntax × Function Builders @ CA.swift #10
  2. എܠ • SwiftUI ͕ WWDC 19 Ͱൃද͞Εͨ • એݴతʹϏϡʔ͕ఆٛͰ͖Δ struct

    LandmarkList: View { var landmarks: [Landmark] var body: some View { List(landmarks) { landmark in HStack { Image(landmark.thumbnail) Text(landmark.name) } } // ... 3 — SwiftSyntaxBuilder = SwiftSyntax × Function Builders @ CA.swift #10
  3. എܠ ! SwiftUI ͷΑ͏ʹ Swift ͷίʔυΛهड़Ͱ͖ͨΒ໘ന͍ͷͰ͸…ʁ // هड़ྫ // ੜ੒͞ΕΔ

    Import("SwiftSyntax") import SwiftSyntax Struct("ExampleStruct") { struct ExampleStruct { Let("syntax", of: "Syntax") let syntax: Syntax } } 4 — SwiftSyntaxBuilder = SwiftSyntax × Function Builders @ CA.swift #10
  4. ࠓճ͓࿩͢͠Δ͜ͱ • SwiftSyntax Ͱ Swift ίʔυΛੜ੒͢Δ • Function Builders Ͱએݴతͳه๏Λ࣮ݱ͢Δ

    • Function Builders ͷϋϚΓͲ͜Ζ • SwiftSyntaxBuilder ͰͰ͖Δ͜ͱ 9 — SwiftSyntaxBuilder = SwiftSyntax × Function Builders @ CA.swift #10
  5. SwiftSyntax ͱ͸ • Swift ίϯύΠϥͷҰ෦Ͱ͋Δ lib/Syntax ͷ Swift όΠϯσΟϯά •

    ߏจ (syntax) ʹ͍ͭͯͷߏ଄Λఆٛ͢Δ • ҙຯ࿦ (semantics) ʹ͍ͭͯ͸ؔ஌͠ͳ͍ • lib/Syntax ΍ SwiftSyntax Λ௨ͯ͡ߏจղੳΛߦ͏͜ͱͰɺ • ίϯύΠϥ͕ੜ੒͢Δ AST ͱ ਖ਼֬ʹಉ͡৘ใ ͕ಘΒΕΔ • ߏจతͳਖ਼͠͞Λอͪͭͭ AST Λฤू͢Δ͜ͱ͕Ͱ͖Δ → apple/swift-format ͷΑ͏ͳ Linter/Formatter ͕࡞ΕΔ 11 — SwiftSyntaxBuilder = SwiftSyntax × Function Builders @ CA.swift #10
  6. SwiftSyntax ͱ͸ ίϯύΠϥ͕ੜ੒͢Δ AST Λ֬ೝ͢Δʹ͸ $ swift -frontend -emit-syntax test.swift

    \ | python -m json.tool 12 — SwiftSyntaxBuilder = SwiftSyntax × Function Builders @ CA.swift #10
  7. SwiftSyntax ͰͰ͖Δ͜ͱ SyntaxRewriter Λ࣮૷͢Δ͜ͱͰ AST ͷ֤ϊʔυΛฤूͰ͖Δ let sourceFile: SourceFileSyntax =

    try SyntaxParser.parse(source: "let number = 1000") class AddOneToIntegerLiterals: SyntaxRewriter { override func visit(_ token: TokenSyntax) -> Syntax { guard case .integerLiteral(let text) = token.tokenKind else { return token } let integerText = String(text.filter { ("0"..."9").contains($0) }) let int = Int(integerText)! return token.withKind(.integerLiteral("\(int + 1)")) } } let incremented = AddOneToIntegerLiterals().visit(sourceFile) print(incremented) // => "let number = 1001" 13 — SwiftSyntaxBuilder = SwiftSyntax × Function Builders @ CA.swift #10
  8. SwiftSyntax ͰͰ͖Δ͜ͱ ๚Εͨ AST ͷϊʔυʢ͜͜Ͱ͸ TokenSyntaxʣͷ kind ͷΈมߋ let sourceFile:

    SourceFileSyntax = try SyntaxParser.parse(source: "let number = 1000") class AddOneToIntegerLiterals: SyntaxRewriter { override func visit(_ token: TokenSyntax) -> Syntax { guard case .integerLiteral(let text) = token.tokenKind else { return token } let integerText = String(text.filter { ("0"..."9").contains($0) }) let int = Int(integerText)! return token.withKind(.integerLiteral("\(int + 1)")) } } let incremented = AddOneToIntegerLiterals().visit(sourceFile) print(incremented) // => "let number = 1001" 14 — SwiftSyntaxBuilder = SwiftSyntax × Function Builders @ CA.swift #10
  9. SwiftSyntax ͰͰ͖Δ͜ͱ let sourceFile: SourceFileSyntax = try SyntaxParser.parse(source: "...") SourceFileSyntax

    ͸ Syntax ϓϩτίϧʹ४ڌ͢Δ struct • ܕ΍ม਺ͷఆٛʢDeclarationʣ͸ DeclSyntax • ࣜʢExpressionʣ͸ ExprSyntaxɺจʢStatementʣ͸ StmtSyntax → AST ͷਖ਼͕͠͞ܕͰอޢ͞ΕΔ • ྫ: ࣜʢExprSyntaxʣΛจʢStmtSyntaxʣʹ͸ஔ͖׵͑ΒΕͳ͍ 15 — SwiftSyntaxBuilder = SwiftSyntax × Function Builders @ CA.swift #10
  10. SwiftSyntax ͰͰ͖Δ͜ͱ • AST Λฤू͢Δ͜ͱ͕Ͱ͖Δ → θϩ͔Βੜ੒͢Δ ͜ͱ΋Ͱ͖Δ • ͨͩ͠

    AST ͷߏ଄Λਖ਼֬ʹҰͭҰͭ૊ΈཱͯΔඞཁ͕͋Δ • ݁ՌͱͳΔίʔυʹରͯ͠৑௕ʹͳΓ͕ͪ • ͨͱ͑͹ɺԼͷίʔυΛੜ੒͢ΔͨΊʹ… struct Foo { let bar: String } 16 — SwiftSyntaxBuilder = SwiftSyntax × Function Builders @ CA.swift #10
  11. SwiftSyntax ʹΑΔ AST ͷఆٛ • ͜Ε͚ͩͷهड़͕ඞཁ • লུ͍ͯ͠Δ͕ɺ࣮ࡍ͸͞Βʹ Triviaʢۭന΍ׅހͳͲʣͷࢦఆ͕ඞཁ StructDeclSyntax

    { builder in builder.useStructKeyword(SyntaxFactory.makeStructKeyword()) // struct Ωʔϫʔυ builder.useIdentifier(SyntaxFactory.makeIdentifier("Foo")) // ߏ଄ମͷ໊લΛࢦఆ builder.useMembers(MemberDeclBlockSyntax { builder in // ߏ଄ମͷϝϯόʔΛఆٛ builder.addMember(MemberDeclListItemSyntax { builder in builder.useDecl(VariableDeclSyntax { builder in // ม਺ఆٛΛ௥Ճ builder.useLetOrVarKeyword(SyntaxFactory.makeLetKeyword()) // let Ωʔϫʔυ builder.addBinding(PatternBindingSyntax { builder in // ύλʔϯʹର͢Δม਺ଋറ builder.usePattern( SyntaxFactory.makeIdentifierPattern( // ࣝผࢠύλʔϯ identifier: SyntaxFactory.makeIdentifier("bar"))) // ࣝผࢠΛࢦఆ builder.useTypeAnnotation(TypeAnnotationSyntax { builder in // ܕΞϊςʔγϣϯΛ௥Ճ builder.useColon(SyntaxFactory.makeColonToken()) // ίϩϯ builder.useType(SyntaxFactory.makeTypeIdentifier("String")) // String ܕ // ... 17 — SwiftSyntaxBuilder = SwiftSyntax × Function Builders @ CA.swift #10
  12. ཧ૝ • ΑΓએݴతʹॻ͖͍ͨ Struct("Foo") { Let("bar", "String") } // ↓

    struct Foo { let bar: String } → SwiftUI ͷه๏Λ࣮ݱ͍ͯ͠Δ Function Builders Λ༻͍ͯ࡞Εͦ͏ 18 — SwiftSyntaxBuilder = SwiftSyntax × Function Builders @ CA.swift #10
  13. Function Builders ͱ͸ • Swift 5.1 Ͱࢼݧతʹ௥Ճ͞Εͨݴޠػೳ • ؔ਺΍ΫϩʔδϟͷதͰ ෳ਺ͷ஋Λฦ͢Α͏ͳ

    ॻ͖ํ͕Ͱ͖Δ func join(/* ... */) { /* ... */ } join { "foo" "bar" } // => "foo, bar" 20 — SwiftSyntaxBuilder = SwiftSyntax × Function Builders @ CA.swift #10
  14. Function Builders ͷఆٛྫ Function Builders Ͱ join ؔ਺Λఆٛͯ͠ΈΔ @_functionBuilder struct

    StringBuilder { static func buildBlock(_ strings: String...) -> String { return strings } } func join(@StringBuilder builder: () -> String) -> [String] { return builder().joined(separator: ", ") } join { "foo" "bar" } // => "foo, bar" 21 — SwiftSyntaxBuilder = SwiftSyntax × Function Builders @ CA.swift #10
  15. Function Builders ͷఆٛྫ ͜ͷଐੑΛ͚ͭΔ͜ͱͰ StringBuilder Λଐੑͱͯ͠࢖͑ΔΑ͏ʹͳΔ @_functionBuilder struct StringBuilder {

    static func buildBlock(_ strings: String...) -> String { return strings } } func join(@StringBuilder builder: () -> String) -> [String] { return builder().joined(separator: ", ") } join { "foo" "bar" } // => "foo, bar" 22 — SwiftSyntaxBuilder = SwiftSyntax × Function Builders @ CA.swift #10
  16. Function Builders ͷఆٛྫ ؔ਺ͷҾ਺ͱͳΔΫϩʔδϟʹ StringBuilder Λଐੑͱͯ͠෇༩͢Δͱɺ @_functionBuilder struct StringBuilder {

    static func buildBlock(_ strings: String...) -> String { return strings } } func join(@StringBuilder builder: () -> String) -> [String] { return builder().joined(separator: ", ") } join { "foo" "bar" } // => "foo, bar" 23 — SwiftSyntaxBuilder = SwiftSyntax × Function Builders @ CA.swift #10
  17. Function Builders ͷఆٛྫ ΫϩʔδϟͷதͰෳ਺ݸͷ஋Λฦ͢Α͏ͳॻ͖ํ͕Ͱ͖ΔΑ͏ʹͳΔ @_functionBuilder struct StringBuilder { static func

    buildBlock(_ strings: String...) -> String { return strings } } func join(@StringBuilder builder: () -> String) -> [String] { return builder().joined(separator: ", ") } join { "foo" "bar" } // => "foo, bar" 24 — SwiftSyntaxBuilder = SwiftSyntax × Function Builders @ CA.swift #10
  18. Function Builders ͷॲཧͷྲྀΕ Function Builder Λ "ల։" ͢ΔͱɺҎԼͷΑ͏ͳॲཧʹ૬౰͢Δ struct StringBuilder

    { static func buildBlock(_ strings: String...) -> [String] { ... } } func join(builder: () -> [String]) -> String { ... } join { let v1 = "foo" let v2 = "bar" let v = buildBlock(v1, v2) return v } // => "foo, bar" 25 — SwiftSyntaxBuilder = SwiftSyntax × Function Builders @ CA.swift #10
  19. Function Builders ͷॲཧͷྲྀΕ Ϋϩʔδϟ಺ͷ஋͕ buildBlock ؔ਺ʹ౉͞Εͯ [String] ʹͳΓɺ struct StringBuilder

    { static func buildBlock(_ strings: String...) -> [String] { ... } } func join(builder: () -> [String]) -> String { ... } join { let v1 = "foo" let v2 = "bar" let v = buildBlock(v1, v2) return v } // => "foo, bar" 26 — SwiftSyntaxBuilder = SwiftSyntax × Function Builders @ CA.swift #10
  20. Function Builders ͷॲཧͷྲྀΕ buildBlock ͷ݁Ռ͕ join ؔ਺ͷΫϩʔδϟͷ݁ՌͱͳΔ struct StringBuilder {

    static func buildBlock(_ strings: String...) -> [String] { ... } } func join(builder: () -> [String]) -> String { ... } join { let v1 = "foo" let v2 = "bar" let v = buildBlock(v1, v2) return v } // => "foo, bar" 27 — SwiftSyntaxBuilder = SwiftSyntax × Function Builders @ CA.swift #10
  21. Function Builders ͷॲཧͷྲྀΕ • ड͚औΔܕ͕ҟͳΔΦʔόʔϩʔυΛ༻ҙ͢Δ͜ͱ΋Մೳ extension StringBuilder { static func

    buildBlock(_ numbers: Int...) -> [String] { return numbers.map { String($0) } } } join { 123 456 } // => "123, 456" 28 — SwiftSyntaxBuilder = SwiftSyntax × Function Builders @ CA.swift #10
  22. SwiftSyntaxBuilder ͱ͸ SwiftSyntax ͷ Syntax Λ SwiftUI ϥΠΫʹੜ੒Ͱ͖Δ import SwiftSyntax

    import SwiftSyntaxBuilder let sourceFile = SourceFile { Import("SwiftSyntax") Struct("ExampleStruct") { Let("syntax", of: "Syntax") } } let syntax: Syntax = sourceFile.buildSyntax(format: format, leadingTrivia: .zero) 30 — SwiftSyntaxBuilder = SwiftSyntax × Function Builders @ CA.swift #10
  23. SwiftSyntaxBuilder ͷ࣮૷ • Syntax ΍ DeclSyntax Λੜ੒Ͱ͖Δ struct ͱͯ͠ίϯϙʔωϯτԽ struct

    SourceFile: SyntaxBuildable { init(@SyntaxListBuilder makeBuilder: () -> SyntaxListBuildable) { func buildSyntax(format: Format, leadingTrivia: Trivia) -> Syntax } struct Struct: DeclBuildable { init(_ name: String, @DeclListBuilder buildMemberList: () -> DeclListBuildable) func buildDecl(format: Format, leadingTrivia: Trivia) -> DeclSyntax } struct Import: DeclBuildable { init(_ moduleName: String) func buildDecl(format: Format, leadingTrivia: Trivia) -> DeclSyntax } 31 — SwiftSyntaxBuilder = SwiftSyntax × Function Builders @ CA.swift #10
  24. SwiftSyntaxBuilder ͷ࣮૷ Θ͔Γ΍͍͢୯ҐͰίϯϙʔωϯτԽ͢Δ͜ͱͰɺSwiftSyntax ͷ API Λ௚઀࢖͏͜ͱʹΑΔ৑௕ੑΛӅṭ struct Import: DeclBuildable {

    let moduleName: String // ... func buildDecl(format: Format, leadingTrivia: Trivia) -> DeclSyntax { let importToken = Tokens.import.withLeadingTrivia(leadingTrivia) let moduleNameToken = SyntaxFactory.makeIdentifier(moduleName) return ImportDeclSyntax { $0.useImportTok(importToken) $0.addPathComponent(AccessPathComponentSyntax { $0.useName(moduleNameToken) }) } } } 32 — SwiftSyntaxBuilder = SwiftSyntax × Function Builders @ CA.swift #10
  25. SwiftSyntaxBuilder ͷ࣮૷ • ·ͩݶΒΕͨίϯϙʔωϯτ͔࣮͠૷͞Ε͍ͯͳ͍ • SourceFile • Import • Struct

    • Let / Var • ίϝϯτ΍վߦͷૠೖͳͲ΋ະ࣮૷ • ͨͩ͠ɺੜ੒ͨ͠ Syntax Λͦͷ·· apple/swift-format ͳͲʹ౉ͤΔ • ϑΥʔϚοτͷৄࡉͳࢦఆʹ͸ରԠ͢Δඞཁ͕ͳ͍ͱߟ͑ΒΕΔ 33 — SwiftSyntaxBuilder = SwiftSyntax × Function Builders @ CA.swift #10
  26. Function Builders ͷ஫ҙ఺ • buildBlock ͱಉ༷ʹ buildIf ΍ buildDo ͳͲΛ࣮૷͢Δ͜ͱͰ

    if จ΍ do จʹରԠ͢Δ͜ͱ΋Ͱ͖Δ // if จ static func buildIf(_ string: Component?) -> Component // do จ static func buildDo(_ string: Component?) -> Component // if-else จ static func buildEither(first string: Component) -> Component static func buildEither(second string: Component) -> Component 35 — SwiftSyntaxBuilder = SwiftSyntax × Function Builders @ CA.swift #10
  27. Function Builders ͷ஫ҙ఺ • ҎԼͷΑ͏ͳ࣮૷͕Ͱ͖ͦ͏͕ͩ… @_functionBuilder extension StringBuilder { static

    func buildIf(_ strings: [String]?) -> [String] { return strings ?? [] } } join { "foo" "bar" if condition { "hoge" "fuga" } } 36 — SwiftSyntaxBuilder = SwiftSyntax × Function Builders @ CA.swift #10
  28. Function Builders ͷ஫ҙ఺ "ల։" ͞ΕͨॲཧͷΠϝʔδ extension StringBuilder { static func

    buildIf(_ strings: [String]?) -> [String] { ... } } join { let _v1 = "foo" let _v2 = "bar" var _vif: [String]? = nil if condition { _vif = StringBuilder.buildBlock("hoge", "fuga") } let _v3 = StringBuilder.buildIf(_vif) let result = StringBuilder.buildBlock(_v1, _v2, _v3) } 37 — SwiftSyntaxBuilder = SwiftSyntax × Function Builders @ CA.swift #10
  29. Function Builders ͷ஫ҙ఺ ܕ͕߹Θͳ͍ͨΊɺ͜ͷఆٛͰ͸࢖͑ͳ͍ extension StringBuilder { static func buildIf(_

    strings: [String]?) -> [String] { ... } } join { let _v1 = "foo" // => String let _v2 = "bar" // => String var _vif: [String]? = nil if condition { _vif = StringBuilder.buildBlock("hoge", "fuga") } let _v3 = StringBuilder.buildIf(_vif) // => [String] let result = StringBuilder.buildBlock(_v1, _v2, _v3) } /* String, String, [String] */ 38 — SwiftSyntaxBuilder = SwiftSyntax × Function Builders @ CA.swift #10
  30. Function Builders ͷ஫ҙ఺ • buildBlock ΍ buildIf ͷ݁Ռ΋·ͨ buildBlock ͷҾ਺ͷͻͱͭͱͯ͠౉ͤͳ͚͹ͳΒͳ͍

    • ͭ·ΓɺbuildBlock ͕ड͚औΔͻͱͭͻͱͭͷ஋ͷܕͱ buildBlock ͷ݁Ռͷܕ͕Ұக͍ͯ͠Δඞཁ͕͋Δ static func buildBlock(_ strings: Component...) -> Component { ... } ↑ ↑ ┌──┴───────────┬────┘ ↓ ↓ static func buildIf(_ strings: Component?) -> Component { ... } 39 — SwiftSyntaxBuilder = SwiftSyntax × Function Builders @ CA.swift #10
  31. Function Builders ͷ஫ҙ఺ • join ؔ਺ͷྫͰ͸ɺ String ͱ [String] Λಉ͡ܕͱͯ͠ѻ͍͍ͨ

    • [String] Λϥοϓ͢Δ StringList ܕΛ࡞Δ public struct StringList { let strings: [String] } • String ͸҉໧తʹ StringList ʹม׵Ͱ͖ΔΑ͏ʹ͓ͯ͘͠ extension StringList: ExpressibleByStringLiteral { public init(stringLiteral value: String) { self.strings = [value] } } // => "asdf" Λ StringList(strings: ["asdf"]) ͱͯ͠ѻ͑Δ 40 — SwiftSyntaxBuilder = SwiftSyntax × Function Builders @ CA.swift #10
  32. Function Builders ͷ஫ҙ఺ • buildBlock ͷ݁Ռ͕·ͨ buildBlock ͷҰҾ਺ʹͳΕΔ extension StringListBuilder

    { static func buildIf(_ strings: StringList?) -> StringList { strings ?? StringList(strings: []) } } join { "foo" // => StringList "bar" // => StringList if condition { "hoge" // => StringList──┐ "fuga" // => StringList──┴─buildBlock─→ StringList } } 41 — SwiftSyntaxBuilder = SwiftSyntax × Function Builders @ CA.swift #10
  33. Function Builders ͷ஫ҙ఺ • SwiftSyntaxBuilder Ͱ΋ X ϓϩτίϧʹରͯ͠ XList ϓϩτίϧΛఆٛ

    • ୯Ұͷ஋΋Ϧετͱͯ͠ৼΔ෣͑ΔΑ͏ʹ͍ͯ͠Δ protocol DeclListBuildable { func buildDeclList(format: Format, leadingTrivia: Trivia) -> [DeclSyntax] } protocol DeclBuildable DeclListBuildable { func buildDecl(format: Format, leadingTrivia: Trivia) -> DeclSyntax } extension DeclBuildable { func buildDeclList(format: Format, leadingTrivia: Trivia) -> [DeclSyntax] { [buildDecl(format: format, leadingTrivia: leadingTrivia)] } } 42 — SwiftSyntaxBuilder = SwiftSyntax × Function Builders @ CA.swift #10
  34. SwiftUI ͷ৔߹ SwiftUI ͰϏϡʔͷఆٛʹ༻͍ΒΕΔ ViewBuilder Ͱ͸ • buildBlock ͷҾ਺͸ View

    ϓϩτίϧͷ஋ • buildBlock ͷ݁Ռ͸ TupleView ͱ͍͏ View ϓϩτίϧͷ஋ ͱҰக͍ͯ͠Δ @_functionBuilder struct ViewBuilder { static func buildBlock<C0, C1>(_ c0: C0, _ c1: C1) -> TupleView<(C0, C1)> where C0 : View, C1 : View } 44 — SwiftSyntaxBuilder = SwiftSyntax × Function Builders @ CA.swift #10
  35. SwiftUI ͷ৔߹ buildBlock ɾ TupleView ͸ 10 Ҿ਺ͷ৔߹·Ͱ༻ҙ͞Ε͍ͯΔ static func

    buildBlock<C0, C1>(_ c0: C0, _ c1: C1) -> TupleView<(C0, C1)> where C0 : View, C1 : View static func buildBlock<C0, C1, C2>(_ c0: C0, _ c1: C1, _ c2: C2) -> TupleView<(C0, C1, C2)> where C0 : View, C1 : View, C2 : View // ... static func buildBlock<C0, C1, C2, C3, C4, C5, C6, C7, C8>(_ c0: C0, _ c1: C1, (ུ) , _ c8: C8) -> TupleView<(C0, C1, C2, C3, C4, C5, C6, C7, C8)> where C0 : View, C1 : View, C2 : View, C3 : View, C4 : View, C5 : View, C6 : View, C7 : View, C8 : View static func buildBlock<C0, C1, C2, C3, C4, C5, C6, C7, C8, C9>(_ c0: C0, _ c1: C1, (ུ) , _ c9: C9) -> TupleView<(C0, C1, C2, C3, C4, C5, C6, C7, C8, C9)> where C0 : View, C1 : View, C2 : View, C3 : View, C4 : View, C5 : View, C6 : View, C7 : View, C8 : View, C9 : View 45 — SwiftSyntaxBuilder = SwiftSyntax × Function Builders @ CA.swift #10
  36. SwiftSyntaxBuilder Λࢼ͢ • SwiftSyntaxBuilder ͸طʹ apple/swift-syntax ͷ master ʹೖ͍ͬͯΔ •

    ઌ೔෇༩͞Εͨλά 0.50100.0 ʹ͸ؚ·Εͯ ͍ͳ͍ • SwiftPM Ͱ master Λࢦఆͯ͠΋ɺ gyb Ͱੜ੒͞ΕΔίʔυؚ͕·Ε͍ͯͳ͍ • ͍·ͷͱ͜Ζࣗ෼Ͱੜ੒ͨ͠΋ͷΛ࢖͏ඞཁ͕͋Δ • apple/swift-syntax ͷ README ʹ͕ͨͬͯ͠ Swift ίϯύΠϥશମΛνΣοΫΞ΢τ • swift-syntax/build-script.py Λ࣮ߦ let package = Package( name: "tryswiftsyntax", dependencies: [.package(path: "~/swift-source/swift-syntax")], targets: [.target(name: "tryswiftsyntax", dependencies: ["SwiftSyntax"])] ) 48 — SwiftSyntaxBuilder = SwiftSyntax × Function Builders @ CA.swift #10
  37. ·ͱΊ • SwiftSyntax ͱ Function Builders Λ૊Έ߹Θͤͨ SwiftSyntaxBuilder Λ࡞ͬͨ •

    SwiftSyntax ͸ AST Λऔಘɾฤूɾੜ੒͢Δ͜ͱ͕Ͱ͖Δ • Function Builders Ͱ એݴతͳهड़ํ๏Λ࣮ݱͰ͖Δ → SwiftSyntaxBuilder Ͱએݴతͳ AST ੜ੒͕ߦ͑Δ • ࣮༻తͳ Function Builder Λ࣮૷͢Δʹ͸޻෉͕ඞཁ • SwiftSyntaxBuilder ͸·ͩੜ·Εͨͯ • Ұॹʹ࣮૷͠·͠ΐ͏ ! 50 — SwiftSyntaxBuilder = SwiftSyntax × Function Builders @ CA.swift #10
  38. ࢀߟจݙɾؔ࿈ࢿྉ • apple/swift https://github.com/apple/swift • lib/Syntax https://github.com/apple/swift/tree/master/lib/Syntax • apple/swift-syntax https://github.com/apple/swift-syntax

    • SwiftSyntaxBuilder https://github.com/apple/swift-syntax/pull/139 • apple/swift-format https://github.com/apple/swift-format • Function Builders draft proposal https://github.com/apple/swift-evolution/pull/1046 • SwiftUI Tutorials https://developer.apple.com/tutorials/swiftui/ • StringListBuilder ࣮૷ྫ https://github.com/akkyie/functionbuilderexample • AST Exploler https://swift-ast-explorer.kishikawakatsumi.com • SwiftSyntax - NSHipster https://nshipster.com/swiftsyntax/ 51 — SwiftSyntaxBuilder = SwiftSyntax × Function Builders @ CA.swift #10