lib/rouge/lexers/kotlin.rb in rouge-2.2.1 vs lib/rouge/lexers/kotlin.rb in rouge-3.0.0
- old
+ new
@@ -1,12 +1,14 @@
# -*- coding: utf-8 -*- #
module Rouge
module Lexers
class Kotlin < RegexLexer
+ # https://kotlinlang.org/docs/reference/grammar.html
+
title "Kotlin"
- desc "Kotlin <http://kotlinlang.org>"
+ desc "Kotlin Programming Language (http://kotlinlang.org)"
tag 'kotlin'
filenames '*.kt'
mimetypes 'text/x-kotlin'
@@ -39,30 +41,27 @@
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 %r'(companion)(\s+)(object)' do
+ rule %r'\b(companion)(\s+)(object)\b' do
groups Keyword, Text, Keyword
end
- rule %r'(class|data\s+class|interface|object)(\s+)' do
+ rule %r'\b(class|data\s+class|interface|object)(\s+)' do
groups Keyword::Declaration, Text
push :class
end
- rule %r'(package|import)(\s+)' do
+ rule %r'\b(package|import)(\s+)' do
groups Keyword, Text
push :package
end
- rule %r'(val|var)(\s+)' do
+ rule %r'\b(val|var)(\s+)' do
groups Keyword::Declaration, Text
push :property
end
- rule %r'(fun)(\s+)' do
- groups Keyword, Text
- push :function
- end
- rule /(?:#{keywords.join('|')})\b/, Keyword
+ rule %r/\bfun\b/, Keyword
+ rule /\b(?:#{keywords.join('|')})\b/, Keyword
rule id, Name
end
state :package do
rule /\S+/, Name::Namespace, :pop!
@@ -72,13 +71,9 @@
rule id, Name::Class, :pop!
end
state :property do
rule id, Name::Property, :pop!
- end
-
- state :function do
- rule id, Name::Function, :pop!
end
end
end
end