Skip to content

Commit

Permalink
[Swift] Fix tuple destructuring and backticks around identifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-zheng committed Dec 12, 2017
1 parent cb28457 commit 691aa70
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lib/rouge/lexers/swift.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,15 @@ class deinit enum extension final func import init internal lazy let optional pr
end

rule /(`)(#{id})(`)/ do
groups Punctuation, Name, Punctuation
groups Punctuation, Name::Variable, Punctuation
end
end

state :tuple do
rule /(#{id})/, Name::Variable
rule /(`)(#{id})(`)/ do
groups Punctuation, Name::Variable, Punctuation
end
rule /,/, Punctuation
rule /[(]/, Punctuation, :push
rule /[)]/, Punctuation, :pop!
Expand Down
8 changes: 7 additions & 1 deletion spec/visual/samples/swift
Original file line number Diff line number Diff line change
Expand Up @@ -395,4 +395,10 @@ var `var` = 3
// keypath
let keypath = \Person.firstName

foo() // end-of-file comment
// tuple destructuring
let (t1, t2) = (1, 2)
var ((`func`, foo), `protocol`) = ((3, 4), 5)
var ( t3 , /* comment */
( t4 , t5 ) ) = ("a", ("b", "c"))

foo() // end-of-file comment

0 comments on commit 691aa70

Please sign in to comment.