Skip to content

Commit

Permalink
Fix type highlighting (including nested generics) in Kotlin lexer (#1322
Browse files Browse the repository at this point in the history
)

The Kotlin lexer does not highlight a property's type nor does it
properly highlight nested generics, e.g. `Array<Array<Boolean>>`. This
commit fixes both issues.
  • Loading branch information
lordcodes authored and pyrmont committed Sep 7, 2019
1 parent 7b87678 commit cdb3592
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/rouge/lexers/kotlin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ class Kotlin < RegexLexer
id = %r'(#{name_backtick})'

state :root do
rule %r'(\))(\s*)(:)(\s+)(#{name_backtick})(<)' do
groups Punctuation, Text, Punctuation, Text, Name::Class, Punctuation
rule %r'(\s*)(:)(\s+)(#{name_backtick})(<)' do
groups Text, Punctuation, Text, Name::Class, Punctuation
push :generic_parameters
end
rule %r'(\))(\s*)(:)(\s+)(#{name_backtick})' do
groups Punctuation, Text, Punctuation, Text, Name::Class
rule %r'(\s*)(:)(\s+)(#{name_backtick})' do
groups Text, Punctuation, Text, Name::Class
end
rule %r'\b(companion)(\s+)(object)\b' do
groups Keyword, Text, Keyword
Expand Down Expand Up @@ -108,6 +108,7 @@ class Kotlin < RegexLexer

state :generic_parameters do
rule id, Name::Class
rule %r'(<)', Punctuation, :generic_parameters
rule %r'(,)', Punctuation
rule %r'(\s+)', Text
rule %r'(>)', Punctuation, :pop!
Expand Down

0 comments on commit cdb3592

Please sign in to comment.