Skip to content

Commit

Permalink
[Swift] Support tuple destructuring
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-zheng committed Dec 12, 2017
1 parent 8935d0b commit cb28457
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lib/rouge/lexers/swift.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ class deinit enum extension final func import init internal lazy let optional pr
groups Keyword, Text, Name::Variable
end

rule /(let|var)\b(\s*)([(])/ do
groups Keyword, Text, Punctuation
push :tuple
end

rule /(?!\b(if|while|for|private|internal|unowned|switch|case)\b)\b#{id}(?=(\?|!)?\s*[(])/ do |m|
if m[0] =~ /^[[:upper:]]/
token Keyword::Type
Expand Down Expand Up @@ -137,10 +142,18 @@ class deinit enum extension final func import init internal lazy let optional pr
end

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

state :tuple do
rule /(#{id})/, Name::Variable
rule /,/, Punctuation
rule /[(]/, Punctuation, :push
rule /[)]/, Punctuation, :pop!
mixin :inline_whitespace
end

state :dq do
rule /\\[\\0tnr'"]/, Str::Escape
rule /\\[(]/, Str::Escape, :interp
Expand Down

0 comments on commit cb28457

Please sign in to comment.