Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP Xcode 8 #222

Closed
wants to merge 5 commits into from
Closed

WIP Xcode 8 #222

wants to merge 5 commits into from

Conversation

jpsim
Copy link
Owner

@jpsim jpsim commented Jun 14, 2016

SUUUUPER early wip version of Xcode 8 + Swift 3 support.

Also need to apply the following YamlSwift patch:

diff --git a/Yaml.xcodeproj/project.pbxproj b/Yaml.xcodeproj/project.pbxproj
index 6b1446b..6b0e6ce 100644
--- a/Yaml.xcodeproj/project.pbxproj
+++ b/Yaml.xcodeproj/project.pbxproj
@@ -352,6 +352,7 @@
                    };
                    8E1D76201B258FEE0022C013 = {
                        CreatedOnToolsVersion = 6.3.2;
+                       LastSwiftMigration = 0800;
                    };
                    8E1D762B1B258FEE0022C013 = {
                        CreatedOnToolsVersion = 6.3.2;
@@ -754,6 +755,7 @@
                SDKROOT = macosx;
                SKIP_INSTALL = YES;
                SWIFT_OPTIMIZATION_LEVEL = "-Onone";
+               SWIFT_VERSION = 3.0;
                VERSIONING_SYSTEM = "apple-generic";
                VERSION_INFO_PREFIX = "";
            };
@@ -802,6 +804,7 @@
                MTL_ENABLE_DEBUG_INFO = NO;
                SDKROOT = macosx;
                SKIP_INSTALL = YES;
+               SWIFT_VERSION = 3.0;
                VERSIONING_SYSTEM = "apple-generic";
                VERSION_INFO_PREFIX = "";
            };
diff --git a/Yaml/Operators.swift b/Yaml/Operators.swift
index 36cbf22..b16a1c9 100644
--- a/Yaml/Operators.swift
+++ b/Yaml/Operators.swift
@@ -3,6 +3,6 @@ func |> <T, U> (x: T, f: (T) -> U) -> U {
   return f(x)
 }

-func count(string: String) -> String.IndexDistance {
+func count(_ string: String) -> String.IndexDistance {
     return string.characters.count
-}
\ No newline at end of file
+}
diff --git a/Yaml/Regex.swift b/Yaml/Regex.swift
index 95009c5..0e0b06b 100644
--- a/Yaml/Regex.swift
+++ b/Yaml/Regex.swift
@@ -1,36 +1,36 @@
 import Foundation

-func matchRange (_ string: String, regex: NSRegularExpression) -> NSRange {
+func matchRange (_ string: String, regex: RegularExpression) -> NSRange {
   let sr = NSMakeRange(0, string.utf16.count)
   return regex.rangeOfFirstMatch(in: string, options: [], range: sr)
 }

-func matches (_ string: String, regex: NSRegularExpression) -> Bool {
+func matches (_ string: String, regex: RegularExpression) -> Bool {
   return matchRange(string, regex: regex).location != NSNotFound
 }

-func regex (_ pattern: String, options: String = "") -> NSRegularExpression! {
+func regex (_ pattern: String, options: String = "") -> RegularExpression! {
   if matches(options, regex: invalidOptionsPattern) {
     return nil
   }

-  let opts = options.characters.reduce(NSRegularExpressionOptions()) { (acc, opt) -> NSRegularExpressionOptions in
-    return NSRegularExpressionOptions(rawValue:acc.rawValue | (regexOptions[opt] ?? NSRegularExpressionOptions()).rawValue)
+  let opts = options.characters.reduce(RegularExpression.Options()) { (acc, opt) -> RegularExpression.Options in
+    return RegularExpression.Options(rawValue:acc.rawValue | (regexOptions[opt] ?? RegularExpression.Options()).rawValue)
   }
-  return try? NSRegularExpression(pattern: pattern, options: opts)
+  return try? RegularExpression(pattern: pattern, options: opts)
 }

 let invalidOptionsPattern =
-        try! NSRegularExpression(pattern: "[^ixsm]", options: [])
+        try! RegularExpression(pattern: "[^ixsm]", options: [])

-let regexOptions: [Character: NSRegularExpressionOptions] = [
+let regexOptions: [Character: RegularExpression.Options] = [
   "i": .caseInsensitive,
   "x": .allowCommentsAndWhitespace,
   "s": .dotMatchesLineSeparators,
   "m": .anchorsMatchLines
 ]

-func replace (_ regex: NSRegularExpression, template: String) -> (String)
+func replace (_ regex: RegularExpression, template: String) -> (String)
     -> String {
       return { string in
         let s = NSMutableString(string: string)
@@ -45,7 +45,7 @@ func replace (_ regex: NSRegularExpression, template: String) -> (String)
       }
 }

-func replace (_ regex: NSRegularExpression, block: ([String]) -> String)
+func replace (_ regex: RegularExpression, block: ([String]) -> String)
     -> (String) -> String {
       return { string in
         let s = NSMutableString(string: string)
@@ -74,7 +74,7 @@ func replace (_ regex: NSRegularExpression, block: ([String]) -> String)
       }
 }

-func splitLead (_ regex: NSRegularExpression) -> (String)
+func splitLead (_ regex: RegularExpression) -> (String)
     -> (String, String) {
       return { string in
         let r = matchRange(string, regex: regex)
@@ -88,7 +88,7 @@ func splitLead (_ regex: NSRegularExpression) -> (String)
       }
 }

-func splitTrail (_ regex: NSRegularExpression) -> (String)
+func splitTrail (_ regex: RegularExpression) -> (String)
     -> (String, String) {
       return { string in
         let r = matchRange(string, regex: regex)
diff --git a/Yaml/Result.swift b/Yaml/Result.swift
index ed8140f..56b21e6 100644
--- a/Yaml/Result.swift
+++ b/Yaml/Result.swift
@@ -16,14 +16,14 @@ public enum Result<T> {
     }
   }

-  public func map <U> (f: (T) -> U) -> Result<U> {
+  public func map <U> (_ f: (T) -> U) -> Result<U> {
     switch self {
     case .Error(let e): return .Error(e)
     case .Value(let v): return .Value(f(v))
     }
   }

-  public func flatMap <U> (f: (T) -> Result<U>) -> Result<U> {
+  public func flatMap <U> (_ f: (T) -> Result<U>) -> Result<U> {
     switch self {
     case .Error(let e): return .Error(e)
     case .Value(let v): return f(v)
@@ -42,17 +42,17 @@ func <*> <T, U> (f: Result<(T) -> U>, x: Result<T>) -> Result<U> {

 infix operator <^> { associativity left }
 func <^> <T, U> (f: (T) -> U, x: Result<T>) -> Result<U> {
-  return x.map(f: f)
+  return x.map(f)
 }

 infix operator >>- { associativity left }
 func >>- <T, U> (x: Result<T>, f: (T) -> U) -> Result<U> {
-  return x.map(f: f)
+  return x.map(f)
 }

 infix operator >>=- { associativity left }
 func >>=- <T, U> (x: Result<T>, f: (T) -> Result<U>) -> Result<U> {
-  return x.flatMap(f: f)
+  return x.flatMap(f)
 }

 infix operator >>| { associativity left }
diff --git a/Yaml/Tokenizer.swift b/Yaml/Tokenizer.swift
index a6f7b7f..9fc6a01 100644
--- a/Yaml/Tokenizer.swift
+++ b/Yaml/Tokenizer.swift
@@ -46,7 +46,7 @@ enum TokenType: Swift.String {
   case End = "end"
 }

-typealias TokenPattern = (type: TokenType, pattern: NSRegularExpression)
+typealias TokenPattern = (type: TokenType, pattern: RegularExpression)
 typealias TokenMatch = (type: TokenType, match: String)

 let bBreak = "(?:\\r\\n|\\r|\\n)"
diff --git a/Yaml/Yaml.swift b/Yaml/Yaml.swift
index 40e3c43..26c76cd 100644
--- a/Yaml/Yaml.swift
+++ b/Yaml/Yaml.swift
@@ -1,5 +1,5 @@
 public enum Yaml {
-  case Null
+  case null
   case Bool(Swift.Bool)
   case Int(Swift.Int)
   case Double(Swift.Double)
@@ -10,7 +10,7 @@ public enum Yaml {

 extension Yaml: NilLiteralConvertible {
   public init(nilLiteral: ()) {
-    self = .Null
+    self = .null
   }
 }

@@ -65,7 +65,7 @@ extension Yaml: DictionaryLiteralConvertible {
 extension Yaml: CustomStringConvertible {
   public var description: Swift.String {
     switch self {
-    case .Null:
+    case .null:
       return "Null"
     case .Bool(let b):
       return "Bool(\(b))"
@@ -132,10 +132,10 @@ extension Yaml {
         if array.indices.contains(index) {
           return array[index]
         } else {
-          return .Null
+          return .null
         }
       default:
-        return .Null
+        return .null
       }
     }
     set {
@@ -143,13 +143,13 @@ extension Yaml {
       switch self {
       case .Array(let array):
         let emptyCount = max(0, index + 1 - array.count)
-        let empty = [Yaml](repeating: .Null, count: emptyCount)
+        let empty = [Yaml](repeating: .null, count: emptyCount)
         var new = array
         new.append(contentsOf: empty)
         new[index] = newValue
         self = .Array(new)
       default:
-        var array = [Yaml](repeating: .Null, count: index + 1)
+        var array = [Yaml](repeating: .null, count: index + 1)
         array[index] = newValue
         self = .Array(array)
       }
@@ -160,9 +160,9 @@ extension Yaml {
     get {
       switch self {
       case .Dictionary(let dictionary):
-        return dictionary[key] ?? .Null
+        return dictionary[key] ?? .null
       default:
-        return .Null
+        return .null
       }
     }
     set {
@@ -257,7 +257,7 @@ extension Yaml {

 public func == (lhs: Yaml, rhs: Yaml) -> Bool {
   switch (lhs, rhs) {
-  case (.Null, .Null):
+  case (.null, .null):
     return true
   case (.Bool(let lv), .Bool(let rv)):
     return lv == rv

jpsim added 5 commits June 6, 2016 14:44
* master:
  move file system check out of String.isSwiftFile
  fix '.swift' directories considered Swift files
  Remove "key.offset" and "key.length" from results of `dictWithCommentMarkNamesCursorInfo()`
  use guard in File.parseDeclaration(...)
  simplify File.parseDeclaration(...)
  fix bug where parsed declaration would include body
@jpsim
Copy link
Owner Author

jpsim commented Sep 19, 2016

Continued in #223. master already has Swift 2.3 support, thanks to #246.

@jpsim jpsim closed this Sep 19, 2016
@jpsim jpsim deleted the xcode-8 branch September 19, 2016 21:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant