Skip to content
Snippets Groups Projects
Commit 9b01ae19 authored by Jeanine Adkisson's avatar Jeanine Adkisson
Browse files

Merge pull request #276 from radex/master

Swift 2 changes
parents 508eae45 6b1e2e3d
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -14,21 +14,17 @@ module Rouge
id = /#{id_head}#{id_rest}*/
 
keywords = Set.new %w(
break case continue default do else fallthrough if in for return switch where while
break case continue default do else fallthrough if in for return switch where while try catch throw guard defer repeat
 
as dynamicType is new super self Self Type __COLUMN__ __FILE__ __FUNCTION__ __LINE__
 
associativity didSet get infix inout left mutating none nonmutating operator override postfix precedence prefix right set unowned weak willSet
associativity didSet get infix inout left mutating none nonmutating operator override postfix precedence prefix right set unowned weak willSet throws rethrows
)
 
declarations = Set.new %w(
class deinit enum extension final func import init internal lazy let optional private protocol public required static struct subscript typealias var dynamic
)
 
attributes = Set.new %w(
autoclosure IBAction IBDesignable IBInspectable IBOutlet noreturn NSCopying NSManaged objc UIApplicationMain NSApplicationMain objc_block noescape
)
constants = Set.new %w(
true false nil
)
Loading
Loading
@@ -70,21 +66,7 @@ module Rouge
rule /0b[01]+(?:_[01]+)*/, Num::Bin
rule %r{[\d]+(?:_\d+)*}, Num::Integer
 
rule /@availability[(][^)]+[)]/, Keyword::Declaration
rule /(@objc[(])([^)]+)([)])/ do
groups Keyword::Declaration, Name::Class, Keyword::Declaration
end
rule /@autoclosure\(escaping\)/, Keyword::Declaration
rule /@(#{id})/ do |m|
if attributes.include? m[1]
token Keyword
else
token Error
end
end
rule /@#{id}(\([^)]+\))?/, Keyword::Declaration
 
rule /(private|internal)(\([ ]*)(\w+)([ ]*\))/ do |m|
if m[3] == 'set'
Loading
Loading
@@ -101,6 +83,8 @@ module Rouge
groups Keyword::Declaration, Error, Keyword::Declaration
end
end
rule /#available\([^)]+\)/, Keyword::Declaration
 
rule /(let|var)\b(\s*)(#{id})/ do
groups Keyword, Text, Name::Variable
Loading
Loading
@@ -115,6 +99,7 @@ module Rouge
end
rule /as[?!]?/, Keyword
rule /try[!]?/, Keyword
 
rule /(#?(?!default)(?![[:upper:]])#{id})(\s*)(:)/ do
groups Name::Variable, Text, Punctuation
Loading
Loading
import Foundation
@testable import MyModule
 
func sayHello(person:String) -> String {
return "Hello, \(capitalize(word:person)). \"How're are you doin\'?\""
Loading
Loading
@@ -23,6 +24,12 @@ func halfOpenRangeLength(start:Int, end:Int) -> Int {
 
halfOpenRangeLength(3, 8)
 
if let var = option {
if more && complex, let optional = binding, example = here where option.foo == example.foo {
// things
}
}
func count(string:String) -> (vowels:Int, consonants:Int, others:Int) {
var vowels = 0, consonants = 0, emoji = 0, whitespace = 0, others = 0
 
Loading
Loading
@@ -189,6 +196,44 @@ let maybeFunction: (() -> ())? = nil
maybeFunction?()
maybeFunction!()
 
// Swift 2 exceptions
func throwingFunction() throws -> String {
throw ErrorType.Error
}
do {
try throwingFunction()
} catch {
println(error)
}
try! throwingFunction()
func rethrowingFunction(f: T throws -> U) rethrows -> U {}
// other swift 2 stuff
guard let x = optionalValue else {
print("Fail")
throw NSError(domain: "", code: 0, userInfo: nil)
}
defer { callback() }
if case let x? = optionalValue {print("Unwrapped: \(x)")}
repeat {
// loop…
} while condition
if #available(iOS 8.0, OSX 10.10, *) {
// Use Handoff APIs when available.
let activity = NSUserActivity(activityType:"com.example.ShoppingList.view")
} else {
// Fall back when Handoff APIs not available.
}
//MARK: Classes
public class Person : NSObject {
let firstName: String
Loading
Loading
@@ -233,8 +278,16 @@ public class Person : NSObject {
 
//MARK: Protocols
@objc protocol Random {
typealias T: SomeConstraint
func random() -> Self
optional func seed(seed: Int)
required func foo()
}
extension SomeProtocol where T: OtherProtocol {
func blah() {
// default implementation
}
}
 
extension SomeClass {
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment