Skip to content
Snippets Groups Projects
Commit 539a789d authored by radex's avatar radex
Browse files

Swift: add new Swift 2 keywords

parent f9db92aa
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -14,11 +14,11 @@ 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(
Loading
Loading
@@ -97,6 +97,7 @@ module Rouge
end
rule /as[?!]?/, Keyword
rule /try[!]?/, Keyword
 
rule /(#?(?!default)(?![[:upper:]])#{id})(\s*)(:)/ do
groups Name::Variable, Text, Punctuation
Loading
Loading
Loading
Loading
@@ -196,6 +196,37 @@ 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
//MARK: Classes
public class Person : NSObject {
let firstName: String
Loading
Loading
@@ -240,8 +271,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