Skip to content

Commit

Permalink
Improve support for Gradle plugin names in Kotlin lexer (#1323)
Browse files Browse the repository at this point in the history
The contents of Gradle's Kotlin DSL is essentially Kotlin code and
Rouge's Kotlin lexer is used for lexing these files. However, since
Gradle plugins can include dashes, these were not being lexed correctly.

This commit permits dashes in identifiers. This will mean syntactically
incorrect Kotlin is not highlighted with errors but for the sake of
simplicity this is considered an appropriate trade-off.
  • Loading branch information
lordcodes authored and pyrmont committed Sep 10, 2019
1 parent 9890431 commit c227b37
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rouge/lexers/kotlin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Kotlin < RegexLexer
while yield
)

name_chars = %r'[\p{Lu}\p{Ll}\p{Lt}\p{Lm}\p{Nl}\p{Nd}\p{Pc}\p{Cf}\p{Mn}\p{Mc}]*'
name_chars = %r'[-_\p{Lu}\p{Ll}\p{Lt}\p{Lm}\p{Nl}\p{Nd}\p{Pc}\p{Cf}\p{Mn}\p{Mc}]*'

class_name = %r'`?[\p{Lu}]#{name_chars}`?'
name = %r'`?[_\p{Lu}\p{Ll}\p{Lt}\p{Lm}\p{Nl}]#{name_chars}`?'
Expand Down
2 changes: 2 additions & 0 deletions spec/visual/samples/kotlin
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ fun next(field: Field): Field {
}
}

`maven-publish-plugin`

/** A few colony examples here */
fun main(args: Array<String>) {
// Simplistic demo
Expand Down

0 comments on commit c227b37

Please sign in to comment.