lib/rouge/lexers/swift.rb in rouge-3.0.0 vs lib/rouge/lexers/swift.rb in rouge-3.1.0

- old
+ new

@@ -64,11 +64,11 @@ state :root do mixin :whitespace rule /\$(([1-9]\d*)?\d)/, Name::Variable - rule %r{[()\[\]{}:;,?]}, Punctuation + rule %r{[()\[\]{}:;,?\\]}, Punctuation rule %r([-/=+*%<>!&|^.~]+), Operator rule /@?"/, Str, :dq rule /'(\\.|.)'/, Str::Char rule /(\d+\*|\d*\.\d+)(e[+-]?[0-9]+)?/i, Num::Float rule /\d+e[+-]?[0-9]+/i, Num::Float @@ -105,12 +105,17 @@ rule /(let|var)\b(\s*)(#{id})/ do groups Keyword, Text, Name::Variable end - rule /(?!\b(if|while|for|private|internal|unowned|switch|case)\b)\b#{id}(?=(\?|!)?\s*[(])/ do |m| - if m[0] =~ /^[[:upper:]]/ + 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[1] == '(' && m[0] =~ /^[[:upper:]]/ token Keyword::Type else token Name::Function end end @@ -133,9 +138,24 @@ token Keyword::Type else token Name end end + + rule /(`)(#{id})(`)/ do + 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! + mixin :inline_whitespace end state :dq do rule /\\[\\0tnr'"]/, Str::Escape rule /\\[(]/, Str::Escape, :interp