From 71f98a60ba0fa34592e11c1478f65881b86ed339 Mon Sep 17 00:00:00 2001 From: Andrew Lord Date: Sat, 22 Sep 2018 01:45:05 +0100 Subject: [PATCH] Recognize destructuring --- lib/rouge/lexers/kotlin.rb | 11 +++++++++++ spec/visual/samples/kotlin | 2 ++ 2 files changed, 13 insertions(+) diff --git a/lib/rouge/lexers/kotlin.rb b/lib/rouge/lexers/kotlin.rb index 4e6021cc14..ad32d8e639 100644 --- a/lib/rouge/lexers/kotlin.rb +++ b/lib/rouge/lexers/kotlin.rb @@ -61,6 +61,10 @@ class Kotlin < RegexLexer groups Keyword, Text push :package end + rule %r'\b(val|var)(\s+)(\()' do + groups Keyword::Declaration, Text, Punctuation + push :destructure + end rule %r'\b(val|var)(\s+)' do groups Keyword::Declaration, Text push :property @@ -97,6 +101,13 @@ class Kotlin < RegexLexer state :property do rule id, Name::Property, :pop! end + + state :destructure do + rule %r'(,)', Punctuation + rule %r'(\))', Punctuation, :pop! + rule %r'(\s+)', Text + rule id, Name::Property + end end end end diff --git a/spec/visual/samples/kotlin b/spec/visual/samples/kotlin index 8bce715e2f..6d161097de 100644 --- a/spec/visual/samples/kotlin +++ b/spec/visual/samples/kotlin @@ -152,4 +152,6 @@ fun String.genericExtensionFunction() { fun anAnnotatedFunction() = { } +val (a, b) = pair + // comment at EOF (#797)