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: Highlight constructor and function calls #1321

Merged
merged 3 commits into from
Sep 9, 2019
Merged
Show file tree
Hide file tree
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
24 changes: 9 additions & 15 deletions lib/rouge/lexers/kotlin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,9 @@ class Kotlin < RegexLexer

id = %r'(#{name_backtick})'

upper = %r'[\p{Lu}]'

state :root do
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 Text, Punctuation, Text, Name::Class
end
rule %r'\b(companion)(\s+)(object)\b' do
groups Keyword, Text, Keyword
end
Expand All @@ -48,13 +43,6 @@ 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 Down Expand Up @@ -85,7 +73,13 @@ class Kotlin < RegexLexer
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 %r/@#{id}/, Name::Decorator
rule %r/(@#{upper}#{name_backtick})/, Name::Decorator
rule %r'(#{upper}#{name_backtick})(<)' do
groups Name::Class, Punctuation
push :generic_parameters
end
rule %r'(#{upper}#{name_backtick})', Name::Class
rule %r'(#{name_backtick})(?=\s*[({])', Name::Function
lordcodes marked this conversation as resolved.
Show resolved Hide resolved
rule id, Name
end

Expand Down
9 changes: 9 additions & 0 deletions spec/visual/samples/kotlin
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,15 @@ fun main(args: Array<String>) {
""", 10)
}

data class Point(x: Float, y: Float)

class ExampleChild(x: Int): Parent(x) {
fun something(): Thing<MyType> {
val thisThing = OtherThing(x)
return Thing<MyType>()
}
}

// UTILITIES

fun runGameOfLife(fieldText: String, steps: Int) {
Expand Down