Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kotlin: Recognizing function parameters and return type #999

Merged
merged 3 commits into from
Oct 1, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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