Skip to content

Commit

Permalink
Merge pull request #999 from lordcodes/kotlin-function-signature
Browse files Browse the repository at this point in the history
Kotlin: Recognizing function parameters and return type
  • Loading branch information
dblessing committed Oct 1, 2018
2 parents d4a2bb6 + aebe68f commit 6aee3b7
Showing 1 changed file with 30 additions and 16 deletions.
46 changes: 30 additions & 16 deletions lib/rouge/lexers/kotlin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,13 @@ class Kotlin < RegexLexer
id = %r'(#{name_backtick})'

state :root do
rule %r'^\s*\[.*?\]', Name::Attribute
rule %r'[^\S\n]+', Text
rule %r'\\\n', Text # line continuation
rule %r'//.*?$', Comment::Single
rule %r'/[*].*?[*]/'m, Comment::Multiline
rule %r'\n', Text
rule %r'::|!!|\?[:.]', Operator
rule %r"(\.\.)", Operator
rule %r'[~!%^&*()+=|\[\]:;,.<>/?-]', Punctuation
rule %r'[{}]', Punctuation
rule %r'@"(""|[^"])*"'m, Str
rule %r'""".*?"""'m, Str
rule %r'"(\\\\|\\"|[^"\n])*["\n]'m, Str
rule %r"'\\.'|'[^\\]'", Str::Char
rule %r"[0-9](\.[0-9]+)?([eE][+-][0-9]+)?[flFL]?|0[xX][0-9a-fA-F]+[Ll]?", Num
rule /@#{id}/, Name::Decorator
rule %r'(\))(\s*)(:)(\s+)(#{name_backtick})(<)' do
groups Punctuation, Text, Punctuation, Text, Name::Class, Punctuation
push :generic_parameters
end
rule %r'(\))(\s*)(:)(\s+)(#{name_backtick})' do
groups Punctuation, Text, Punctuation, Text, Name::Class
end
rule %r'\b(companion)(\s+)(object)\b' do
groups Keyword, Text, Keyword
end
Expand All @@ -57,6 +48,13 @@ class Kotlin < RegexLexer
groups Keyword, Text
push :function
end
rule %r'(#{name_backtick})(:)(\s+)(#{name_backtick})(<)' do
groups Name::Variable, Punctuation, Text, Name::Class, Punctuation
push :generic_parameters
end
rule %r'(#{name_backtick})(:)(\s+)(#{name_backtick})' do
groups Name::Variable, Punctuation, Text, Name::Class
end
rule %r'\b(package|import)(\s+)' do
groups Keyword, Text
push :package
Expand All @@ -67,6 +65,22 @@ class Kotlin < RegexLexer
end
rule %r/\bfun\b/, Keyword
rule /\b(?:#{keywords.join('|')})\b/, Keyword
rule %r'^\s*\[.*?\]', Name::Attribute
rule %r'[^\S\n]+', Text
rule %r'\\\n', Text # line continuation
rule %r'//.*?$', Comment::Single
rule %r'/[*].*?[*]/'m, Comment::Multiline
rule %r'\n', Text
rule %r'::|!!|\?[:.]', Operator
rule %r"(\.\.)", Operator
rule %r'[~!%^&*()+=|\[\]:;,.<>/?-]', Punctuation
rule %r'[{}]', Punctuation
rule %r'@"(""|[^"])*"'m, Str
rule %r'""".*?"""'m, Str
rule %r'"(\\\\|\\"|[^"\n])*["\n]'m, Str
rule %r"'\\.'|'[^\\]'", Str::Char
rule %r"[0-9](\.[0-9]+)?([eE][+-][0-9]+)?[flFL]?|0[xX][0-9a-fA-F]+[Ll]?", Num
rule /@#{id}/, Name::Decorator
rule id, Name
end

Expand Down

0 comments on commit 6aee3b7

Please sign in to comment.