わいわいOperator

011714704c4a925e542d426d4cdaa4e3?s=47 giginet
September 12, 2018

 わいわいOperator

011714704c4a925e542d426d4cdaa4e3?s=128

giginet

September 12, 2018
Tweet

Transcript

  1. Θ͍Θ͍Operator Θ͍Θ͍swiftc #5 @giginet

  2. iOSDCͷLT !

  3. • Protocol Extension͔ΒᤈࢠΛੜ΍͢Έ͍ͨͳωλΛ΍ͬͨ

  4. ͜Εpostfix operatorͰͰ͖ͳ͍ͷʁ !

  5. import Foundation import Peafowl postfix operator ᤈ extension Int {

    postfix static func ᤈ(lhs: Int) -> Tile { return Tile(.character(lhs))! } } 1ᤈ
  6. None
  7. ແཧͦ͏

  8. ύʔαʔΛಡΉ • https://github.com/apple/swift/blob/master/include/swift/AST/ Identifier.h#L94

  9. /// isOperatorStartCodePoint - Return true if the specified code point

    is a /// valid start of an operator. static bool isOperatorStartCodePoint(uint32_t C) { // ASCII operator chars. static const char OpChars[] = "/=-+*%<>!&|^~.?"; if (C < 0x80) return memchr(OpChars, C, sizeof(OpChars) - 1) != 0; // Unicode math, symbol, arrow, dingbat, and line/box drawing chars. return (C >= 0x00A1 && C <= 0x00A7) || C == 0x00A9 || C == 0x00AB || C == 0x00AC || C == 0x00AE || C == 0x00B0 || C == 0x00B1 || C == 0x00B6 || C == 0x00BB || C == 0x00BF || C == 0x00D7 || C == 0x00F7 || C == 0x2016 || C == 0x2017 || (C >= 0x2020 && C <= 0x2027) || (C >= 0x2030 && C <= 0x203E) || (C >= 0x2041 && C <= 0x2053) || (C >= 0x2055 && C <= 0x205E) || (C >= 0x2190 && C <= 0x23FF) || (C >= 0x2500 && C <= 0x2775) || (C >= 0x2794 && C <= 0x2BFF) || (C >= 0x2E00 && C <= 0x2E7F) || (C >= 0x3001 && C <= 0x3003) || (C >= 0x3008 && C <= 0x3030); }
  10. None
  11. ·ͱΊ • operatorͰ࢖͑Δจࣈίʔυ͸ܾ·ͬͯΔ • ϙϯυ͸operatorʹͰ͖Δ͕ɺϢʔϩ͸operatorʹͰ͖ͳ͍ • ଞʹ͋Δ͔΋

  12. ΦϚέ • ࣮͸੃ṛ͸શͯUnicodeʹׂΓ౰ͯΒΕ͍ͯΔ • ͜Ε͸ΦϖϨʔλʔʹͰ͖ͳ͍ʁ

  13. ແཧͩͬͨ

  14. ΦϚέ2 • ੃ṛΛ൑ఆ͢ΔCharacterSetͰ͢ import Foundation public let MahjongTileCharacterSet = {

    () -> CharacterSet in let start = Character("").unicodeScalars.first! let end = Character("").unicodeScalars.first! let range: ClosedRange<Unicode.Scalar> = start...end return CharacterSet(charactersIn: range) }()