lib/rouge/lexers/swift.rb in rouge-4.1.2 vs lib/rouge/lexers/swift.rb in rouge-4.1.3

- old
+ new

@@ -13,32 +13,33 @@ id_head = /_|(?!\p{Mc})\p{Alpha}|[^\u0000-\uFFFF]/ id_rest = /[\p{Alnum}_]|[^\u0000-\uFFFF]/ id = /#{id_head}#{id_rest}*/ keywords = Set.new %w( - await break case continue default do else fallthrough if in for return switch where while try catch throw guard defer repeat + 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 __COLUMN__ __FILE__ __FUNCTION__ __LINE__ + as dynamicType is new super self Self Type - associativity async didSet get infix inout isolated mutating none nonmutating operator override postfix precedence prefix set unowned weak willSet throws rethrows precedencegroup - - #available #colorLiteral #column #else #elseif #endif #error #file #fileLiteral #function #if #imageLiteral #line #selector #sourceLocation #warning + 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 class deinit enum convenience extension final func import init internal lazy let nonisolated optional private protocol public required static struct subscript typealias var dynamic indirect associatedtype open fileprivate some + 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( true false nil ) - start { push :bol } + start do + push :bol + @re_delim = "" # multi-line regex delimiter + end # beginning of line state :bol do - rule %r/#.*/, Comment::Preproc + rule %r/#(?![#"\/]).*/, Comment::Preproc mixin :inline_whitespace rule(//) { pop! } end @@ -67,12 +68,15 @@ state :root do mixin :whitespace 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 rule %r([-/=+*%<>!&|^.~]+), Operator rule %r/@?"/, Str, :dq rule %r/'(\\.|.)'/, Str::Char rule %r/(\d+(?:_\d+)*\*|(?:\d+(?:_\d+)*)*\.\d+(?:_\d)*)(e[+-]?\d+(?:_\d)*)?/i, Num::Float rule %r/\d+e[+-]?[0-9]+/i, Num::Float @@ -80,10 +84,11 @@ rule %r/0x[0-9A-Fa-f]+(?:_[0-9A-Fa-f]+)*((\.[0-9A-F]+(?:_[0-9A-F]+)*)?p[+-]?\d+)?/, Num::Hex rule %r/0b[01]+(?:_[01]+)*/, Num::Bin 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' token Keyword::Declaration else @@ -97,18 +102,10 @@ else groups Keyword::Declaration, Error, Keyword::Declaration end end - rule %r/#available\([^)]+\)/, Keyword::Declaration - - rule %r/(#(?:selector|keyPath)\()([^)]+?(?:[(].*?[)])?)(\))/ do - groups Keyword::Declaration, Name::Function, Keyword::Declaration - end - - rule %r/#(line|file|column|function|dsohandle)/, Keyword::Declaration - rule %r/(let|var)\b(\s*)(#{id})/ do groups Keyword, Text, Name::Variable end rule %r/(let|var)\b(\s*)([(])/ do @@ -146,10 +143,16 @@ end rule %r/(`)(#{id})(`)/ do groups Punctuation, Name::Variable, Punctuation end + + rule %r{(#+)/\n} do |m| + @re_delim = m[1] + token Str::Regex + push :re_multi + end end state :tuple do rule %r/(#{id})/, Name::Variable rule %r/(`)(#{id})(`)/ do @@ -178,9 +181,22 @@ state :interp_inner do rule %r/[(]/, Punctuation, :push rule %r/[)]/, Punctuation, :pop! mixin :root + end + + state :re_multi do + rule %r{^\s*/#+} do |m| + token Str::Regex + if m[0].end_with?("/#{@re_delim}") + @re_delim = "" + pop! + end + end + + rule %r/#.*/, Comment::Single + rule %r/./m, Str::Regex end end end end