From dfd565def1d2034aa3644527e8cf260d0812c918 Mon Sep 17 00:00:00 2001 From: Jan Koutny Date: Sat, 25 Apr 2020 23:20:46 +0100 Subject: [PATCH] Improve parsing of numbers in Kotlin lexer - Adds support for underscore separator. - Add support for binary literals. - Removes invalid support for lowercase "l" suffix. - Adds support for unsigned literals. --- lib/rouge/lexers/kotlin.rb | 2 +- spec/visual/samples/kotlin | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/rouge/lexers/kotlin.rb b/lib/rouge/lexers/kotlin.rb index d60d6efd24..a06b36ff93 100644 --- a/lib/rouge/lexers/kotlin.rb +++ b/lib/rouge/lexers/kotlin.rb @@ -73,7 +73,7 @@ class Kotlin < RegexLexer 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"(([0-9]|_)+(\.([0-9]|_)*)?[eE][+-]?([0-9]|_)*)[fF]?|((0[xX][0-9a-fA-F_]*[0-9a-fA-F])|(0[bB][01_]*[01])|([0-9]([0-9]|_)*)[uU]?L?)", Num rule %r'(@#{class_name})', Name::Decorator rule %r'(#{class_name})(<)' do groups Name::Class, Punctuation diff --git a/spec/visual/samples/kotlin b/spec/visual/samples/kotlin index 1ece9ae72d..4b72b9a6d4 100644 --- a/spec/visual/samples/kotlin +++ b/spec/visual/samples/kotlin @@ -182,4 +182,12 @@ loop@ for (i in 1..100) { } } +val oneMillion = 1_000_000 +val creditCardNumber = 1234_5678_9012_3456L +val socialSecurityNumber = 999_99_9999L +val hexBytes = 0xFF_EC_DE_5E +val bytes = 0b11010010_01101001_10010100_10010010 +val exponents = listOf(1e10, -1E10F, 1.5e10, 1e-10) +val unsigned = 420U + // comment at EOF (#797)