Skip to content

Commit

Permalink
Swift 5.9 updates
Browse files Browse the repository at this point in the history
  • Loading branch information
johnfairh committed Jun 23, 2023
1 parent 53c67f8 commit f442349
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
14 changes: 4 additions & 10 deletions lib/rouge/lexers/swift.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ class Swift < RegexLexer
id = /#{id_head}#{id_rest}*/

keywords = Set.new %w(
autoreleasepool await break case catch continue default defer do else fallthrough guard if in for repeat return switch throw try where while
autoreleasepool await break case catch consume continue default defer discard do each else fallthrough guard if in for repeat return switch throw try where while

as dynamicType is new super self Self Type

associativity async didSet get infix inout isolated left mutating none nonmutating operator override postfix precedence precedencegroup prefix rethrows right set throws unowned weak willSet
)

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

constants = Set.new %w(
Expand Down Expand Up @@ -71,6 +71,7 @@ class Swift < RegexLexer

rule %r/\$(([1-9]\d*)?\d)/, Name::Variable
rule %r/\$#{id}/, Name
rule %r/~Copyable\b/, Keyword::Type

rule %r{[()\[\]{}:;,?\\]}, Punctuation
rule %r{(#*)/(?!\s).*(?<![\s\\])/\1}, Str::Regex
Expand All @@ -85,6 +86,7 @@ class Swift < RegexLexer
rule %r{[\d]+(?:_\d+)*}, Num::Integer

rule %r/@#{id}/, Keyword::Declaration
rule %r/##{id}/, Keyword

rule %r/(private|internal)(\([ ]*)(\w+)([ ]*\))/ do |m|
if m[3] == 'set'
Expand All @@ -102,14 +104,6 @@ class Swift < RegexLexer
end
end

rule %r/#(?:un)?available\([^)]+\)/, Keyword::Declaration

rule %r/(#(?:selector|keyPath)\()([^)]+?(?:[(].*?[)])?)(\))/ do
groups Keyword::Declaration, Name::Function, Keyword::Declaration
end

rule %r/#(line|file|fileID|filePath|column|function|dsohandle)/, Keyword::Declaration

rule %r/(let|var)\b(\s*)(#{id})/ do
groups Keyword, Text, Name::Variable
end
Expand Down
22 changes: 21 additions & 1 deletion spec/visual/samples/swift
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ typealias StringDictionary<T> = Dictionary<String, T>
@available(*, unavailable, renamed: "MyRenamedProtocol")
@discardableResult func f() -> T {}

#sourceLocation(file: "foo", line: 42)
_ = #sourceLocation(file: "foo", line: 42)

@available(swift, obsoleted: 5.0.0, renamed: "foo2(file:line:)")
func foo(_ file: StaticString = #file, line: UInt = #line) { }
Expand Down Expand Up @@ -498,4 +498,24 @@ let res = [
/##
]

package struct FileDescriptor: ~Copyable {
private var fd: Int32

consuming func close() throws {
discard self
}
}

func makePairs<each First, each Second>(
firsts first: repeat each First,
seconds second: repeat each Second
) -> (repeat Pair<each First, each Second>) {
return (repeat Pair(each first, each second))
}

@freestanding(expression)
public macro stringify<T>(_ value: T) -> (T, String) = #externalMacro(module: "m", type: "t")

let p = #stringify(x + y)

foo() // end-of-file comment

0 comments on commit f442349

Please sign in to comment.