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

メタプログラミング向けのテンプレートエンジン gysb を作った

omochimetaru
November 21, 2017

メタプログラミング向けのテンプレートエンジン gysb を作った

2017/11/21 関西モバイルアプリ研究会 in 関東
https://kanmoba.connpass.com/event/70685/

omochimetaru

November 21, 2017
Tweet

More Decks by omochimetaru

Other Decks in Programming

Transcript

  1. ϝλϓϩάϥϛϯά޲͚
    ͷςϯϓϨʔτΤϯδϯ
    gysb Λ࡞ͬͨ
    omochimetaru @

    View full-size slide

  2. Array ͱ ஥ؒͨͪ
    Array
    - startIndex, endIndex, subscript, _ArrayBuffer
    ArraySlice
    - startIndex, endIndex, subscript, _SliceBuffer
    ContiguousArray
    - startIndex, endIndex, subscript, _ContiguousArrayBuffer

    View full-size slide

  3. gyb
    Generate Your Boilerplate

    View full-size slide

  4. gyb
    Generate Your Boilerplate
    ࣮ߦ: %{ }%
    ࣮ߦ: % (ߦ຤)
    ࣜల։: ${ }

    View full-size slide

  5. Arrays.swift.gyb
    apple/swift @ github

    View full-size slide

  6. %{
    arrayTypes = [
    ('ContiguousArray', 'a `ContiguousArray` instance'),
    ('ArraySlice', 'an `ArraySlice` instance'),
    ('Array', 'an array'),
    ]
    }%
    % for (Self, a_Self) in arrayTypes:
    public struct ${Self} {
    %if Self == 'Array':
    internal typealias _Buffer = _ArrayBuffer
    %elif Self == 'ArraySlice':
    internal typealias _Buffer = _SliceBuffer
    %else:
    internal typealias _Buffer = _${Self.strip('_')}Buffer
    %end
    internal var _buffer: _Buffer
    }
    %end

    View full-size slide

  7. public struct ContiguousArray {
    internal typealias _Buffer = _ContiguousBuffer
    internal var _buffer: _Buffer
    }
    public struct ArraySlice {
    internal typealias _Buffer = _SliceBuffer
    internal var _buffer: _Buffer
    }
    public struct Array {
    internal typealias _Buffer = _ArrayBuffer
    internal var _buffer: _Buffer
    }

    View full-size slide

  8. gyb ͷྑ͘ͳ͍ͱ͜Ζ

    View full-size slide

  9. gyb ͷྑ͘ͳ͍ͱ͜Ζ
    python Λॻ͘ͱ͜Ζ

    View full-size slide

  10. gysb
    Generate Your Swifty Boilerplate

    View full-size slide

  11. gysb
    Generate Your Swifty Boilerplate
    https://github.com/omochi/gysb
    ࣮ߦ: %{ }%
    ࣮ߦ: % (ߦ຤)
    ࣜల։: ${ }

    View full-size slide

  12. Demo
    ࣮ࡍͷσϞͷͱ͖͸ɺ
    ҎԼͷιʔεΛ୊ࡐʹɺ
    --source-dirs, --parse, --compile Ϟʔυͷಈ࡞Λ঺հ͠
    ͨɻ
    https://github.com/omochi/ReactiveEmitter/blob/master/
    Sources/ReactiveEmitter/Operator/Combine.swift.gysb

    View full-size slide

  13. gysb ͷ։ൃ
    gysb ͷಈ࡞ݪཧͦΕࣗମϝλϓϩάϥϛϯά͔ͩΒ
    Swift ͷϝλϓϩάϥϛϯά͢ΔͨΊʹ
    Swift ͷϝλϓϩάϥϛϯάΛߦ͏
    Swift ϓϩάϥϜΛ࡞ͬͨ !
    (͋ͱ Kotlin ΍ C++ ΋ੜ੒Ͱ͖ΔΑ)

    View full-size slide

  14. (એ఻) Discord Offline
    Discord αʔό ios-developers-japan ΛϦΞϧͰ
    12/4 ϝϧΧϦ
    ύωϧσΟεΧογϣϯܗࣜ
    https://connpass.com/event/71774/

    View full-size slide

  15. Sourceryͱͷҧ͍
    Sourcery ͸ ܕ৘ใऔಘ + ςϯϓϨʔτ(ෳ਺ݴޠ)
    gysb ͸ ςϯϓϨʔτ
    Sourcery ͷ swift ςϯϓϨʔτ͸ϥΠϒϥϦඇରԠ
    gysb ͸ gysb.json Ͱ SwiftPM ʹରԠ

    View full-size slide