lib/rouge/lexers/swift.rb in rouge-1.10.1 vs lib/rouge/lexers/swift.rb in rouge-1.11.0

- old
+ new

@@ -16,15 +16,15 @@ keywords = Set.new %w( break case continue default do else fallthrough if in for return switch where while try catch throw guard defer repeat as dynamicType is new super self Self Type __COLUMN__ __FILE__ __FUNCTION__ __LINE__ - associativity didSet get infix inout left mutating none nonmutating operator override postfix precedence prefix right set unowned weak willSet throws rethrows + associativity didSet get infix inout left mutating none nonmutating operator override postfix precedence prefix right set unowned weak willSet throws rethrows associatedtype ) declarations = Set.new %w( - class deinit enum extension final func import init internal lazy let optional private protocol public required static struct subscript typealias var dynamic + class deinit enum extension final func import init internal lazy let optional private protocol public required static struct subscript typealias var dynamic indirect associatedtype ) constants = Set.new %w( true false nil ) @@ -40,19 +40,30 @@ rule(//) { pop! } end state :inline_whitespace do rule /\s+/m, Text - rule %r((?<re>\/\*(?:(?>[^\/\*\*\/]+)|\g<re>)*\*\/))m, Comment::Multiline + mixin :has_comments end state :whitespace do rule /\n+/m, Text, :bol rule %r(\/\/.*?$), Comment::Single, :bol mixin :inline_whitespace end + state :has_comments do + rule %r(/[*]), Comment::Multiline, :nested_comment + end + + state :nested_comment do + mixin :has_comments + rule %r([*]/), Comment::Multiline, :pop! + rule %r([^*/]+)m, Comment::Multiline + rule /./, Comment::Multiline + end + state :root do mixin :whitespace rule /\$(([1-9]\d*)?\d)/, Name::Variable rule %r{[()\[\]{}:;,?]}, Punctuation @@ -83,10 +94,14 @@ groups Keyword::Declaration, Error, Keyword::Declaration end end rule /#available\([^)]+\)/, Keyword::Declaration + + rule /(#selector\()([^)]+?(?:[(].*?[)])?)(\))/ do + groups Keyword::Declaration, Name::Function, Keyword::Declaration + end rule /(let|var)\b(\s*)(#{id})/ do groups Keyword, Text, Name::Variable end @@ -96,11 +111,11 @@ else token Name::Function end end - rule /as[?!]?/, Keyword - rule /try[!]?/, Keyword + rule /as[?!]?(?=\s)/, Keyword + rule /try[!]?(?=\s)/, Keyword rule /(#?(?!default)(?![[:upper:]])#{id})(\s*)(:)/ do groups Name::Variable, Text, Punctuation end