Skip to content

Commit

Permalink
Add some keyword and key-path syntax to Swift lexer (#1332)
Browse files Browse the repository at this point in the history
This commit adds support for the `some` keyword and `\.Type.variable`
key-path syntax to the Swift lexer.
  • Loading branch information
AlanQuatermain authored and pyrmont committed Jan 5, 2020
1 parent e22ce33 commit 3ed2f30
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/rouge/lexers/swift.rb
Expand Up @@ -25,7 +25,7 @@ class Swift < RegexLexer
)

declarations = Set.new %w(
class deinit enum convenience extension final func import init internal lazy let optional private protocol public required static struct subscript typealias var dynamic indirect associatedtype open fileprivate
class deinit enum convenience extension final func import init internal lazy let optional private protocol public required static struct subscript typealias var dynamic indirect associatedtype open fileprivate some
)

constants = Set.new %w(
Expand Down Expand Up @@ -67,6 +67,7 @@ class deinit enum convenience extension final func import init internal lazy let

state :root do
mixin :whitespace

rule %r/\$(([1-9]\d*)?\d)/, Name::Variable

rule %r{[()\[\]{}:;,?\\]}, Punctuation
Expand Down
20 changes: 20 additions & 0 deletions spec/visual/samples/swift
Expand Up @@ -416,6 +416,7 @@ var `var` = 3

// keypath
let keypath = \Person.firstName
var keyPath: KeyPath<String, Bool> = \.isEmpty

// tuple destructuring
let (t1, t2) = (1, 2)
Expand All @@ -432,4 +433,23 @@ funcWithLambdaArg { x in x + 5 }
funcWithLambdaArg { $0 + 5 }
funcWithLambdaArg({ x in x + 5 })

func newView() -> some View {
ViewRegistry.find(\.MyView.name)
}

@frozen
public enum Types {
case a, b, c
case d
}

func test(t: Types?) -> Bool {
switch t {
case .a?: return true
case .b?: return true
case .c: return true
default: return false
}
}

foo() // end-of-file comment

0 comments on commit 3ed2f30

Please sign in to comment.