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

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

3781f49ea2c76d6ecf0c6cda46096d49?s=47 omochimetaru
November 21, 2017

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

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

3781f49ea2c76d6ecf0c6cda46096d49?s=128

omochimetaru

November 21, 2017
Tweet

Transcript

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

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

    - startIndex, endIndex, subscript, _SliceBuffer ContiguousArray - startIndex, endIndex, subscript, _ContiguousArrayBuffer
  3. gyb Generate Your Boilerplate

  4. gyb Generate Your Boilerplate ࣮ߦ: %{ <python code> }% ࣮ߦ:

    % <python code> (ߦ຤) ࣜల։: ${ <python code> }
  5. Arrays.swift.gyb apple/swift @ github

  6. %{ arrayTypes = [ ('ContiguousArray', 'a `ContiguousArray` instance'), ('ArraySlice', 'an

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

    var _buffer: _Buffer } public struct ArraySlice<Element> { internal typealias _Buffer = _SliceBuffer<Element> internal var _buffer: _Buffer } public struct Array<Element> { internal typealias _Buffer = _ArrayBuffer<Element> internal var _buffer: _Buffer }
  8. gyb ͷྑ͘ͳ͍ͱ͜Ζ

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

  10. gysb Generate Your Swifty Boilerplate

  11. gysb Generate Your Swifty Boilerplate https://github.com/omochi/gysb ࣮ߦ: %{ <swift code>

    }% ࣮ߦ: % <swift code> (ߦ຤) ࣜల։: ${ <swift code> }
  12. Demo ࣮ࡍͷσϞͷͱ͖͸ɺ ҎԼͷιʔεΛ୊ࡐʹɺ --source-dirs, --parse, --compile Ϟʔυͷಈ࡞Λ঺հ͠ ͨɻ https://github.com/omochi/ReactiveEmitter/blob/master/ Sources/ReactiveEmitter/Operator/Combine.swift.gysb

  13. gysb ͷ։ൃ gysb ͷಈ࡞ݪཧͦΕࣗମϝλϓϩάϥϛϯά͔ͩΒ Swift ͷϝλϓϩάϥϛϯά͢ΔͨΊʹ Swift ͷϝλϓϩάϥϛϯάΛߦ͏ Swift ϓϩάϥϜΛ࡞ͬͨ

    ! (͋ͱ Kotlin ΍ C++ ΋ੜ੒Ͱ͖ΔΑ)
  14. (એ఻) Discord Offline Discord αʔό ios-developers-japan ΛϦΞϧͰ 12/4 ϝϧΧϦ ύωϧσΟεΧογϣϯܗࣜ

    https://connpass.com/event/71774/
  15. Sourceryͱͷҧ͍ Sourcery ͸ ܕ৘ใऔಘ + ςϯϓϨʔτ(ෳ਺ݴޠ) gysb ͸ ςϯϓϨʔτ Sourcery

    ͷ swift ςϯϓϨʔτ͸ϥΠϒϥϦඇରԠ gysb ͸ gysb.json Ͱ SwiftPM ʹରԠ