-
Notifications
You must be signed in to change notification settings - Fork 729
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
Added Kotlin lexer #354
Added Kotlin lexer #354
Conversation
Based on Pygments parser, and version converted by @hastebrot. Fixes rouge-ruby#295
Any idea how I get the function generics highlighted as fun foo(arg: String) {
println(arg)
}
fun <T> bar(arg: List<T>) {
println(arg)
}
fun <S, T> baz(arg: Pair<S, T>) {
println(arg)
} |
Here is a lazy incomplete solution for a function state/rule: rule %r'(fun)(\s+)' do
groups Keyword, Text
push :function
end
# ...
state :function do
rule %r'(<)(.+)(>)(\s+)' do
groups Operator, Name, Operator, Text
end
rule /#{id}/, Name::Function, :pop!
end This needs to be improved in order to correctly highlight |
Changes: state :root do
rule %r'(fun)' do token Keyword; push :function end
# ...
end
state :function do
rule /</, Punctuation, :function_type_params
rule /\s+/, Text
rule /#{id}(\.)/ do groups Name::Class, Operator end
rule /#{id}/, Name::Function, :pop!
end
state :function_type_params do
rule />/, Punctuation, :pop!
mixin :root
end Samples: val foo: String = "foo"
val bar: List<String> = listOf("bar")
val baz: Pair<Int, String> = 42 to "baz"
fun foo(arg: String) {}
fun <T> bar(arg: List<T>) {}
fun <S, T> baz(arg: Pair<S, T>) {}
fun<T>Quux.foo() {}
fun <T : Any> Quux.bar() {}
inline fun <reified T : Any> Quux.baz() {} |
module Rouge | ||
module Lexers | ||
class Kotlin < RegexLexer | ||
title "Java" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Kotlin"
not "Java"
.
Hello! What needs to be done for this to be merged? |
Yep, specially since Pygments has supported Kotlin for a while, and Rouge aims to be a drop-in replacement with Pygments. Having language parity with Pygments is even more important since GitHub pages will only support Rouge starting May 1st. |
👍 Pushing for this PR as well. Would love too see Kotlin support in Rouge. |
Here is list of remaining issues (tested with http://try.kotlinlang.org/#/Examples/Longer%20examples/Life/Life.kt):
Update: This was also mentioned in the related issue: #295 |
Hi! As I'm sure you know, writing lexers takes a lot of time and work, and having language parity with Pygments is currently a rather unrealistic goal. But I do hope to merge the Kotlin lexer soon! Since #476 includes this work, I'm closing this PR in favor of that one. |
upgraded to wily to remove error from version trusty
Based on Pygments parser, and version converted by @hastebrot.
Fixes #295