From b5ccb8dc322b914484924caf4463d601a64382f7 Mon Sep 17 00:00:00 2001 From: Victor Kropp Date: Fri, 8 Feb 2019 23:50:23 +0100 Subject: [PATCH] Improve numbers parsing in Kotlin --- lexers/k/kotlin.go | 2 +- lexers/testdata/kotlin.actual | 1 + lexers/testdata/kotlin.expected | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lexers/k/kotlin.go b/lexers/k/kotlin.go index bf6fd31..56b7966 100644 --- a/lexers/k/kotlin.go +++ b/lexers/k/kotlin.go @@ -30,7 +30,7 @@ var Kotlin = internal.Register(MustNewLexer( {`"""[^"]*"""`, LiteralString, nil}, {`"(\\\\|\\"|[^"\n])*["\n]`, LiteralString, nil}, {`'\\.'|'[^\\]'`, LiteralStringChar, nil}, - {`[0-9](\.[0-9]*)?([eE][+-][0-9]+)?[flFL]?|0[xX][0-9a-fA-F]+[Ll]?`, LiteralNumber, nil}, + {`0[xX][0-9a-fA-F]+[Uu]?[Ll]?|[0-9]+(\.[0-9]*)?([eE][+-][0-9]+)?[fF]?[Uu]?[Ll]?`, LiteralNumber, nil}, {`(companion)(\s+)(object)`, ByGroups(Keyword, Text, Keyword), nil}, {`(class|interface|object)(\s+)`, ByGroups(Keyword, Text), Push("class")}, {`(package|import)(\s+)`, ByGroups(Keyword, Text), Push("package")}, diff --git a/lexers/testdata/kotlin.actual b/lexers/testdata/kotlin.actual index 12904de..7dbd8ea 100644 --- a/lexers/testdata/kotlin.actual +++ b/lexers/testdata/kotlin.actual @@ -10,6 +10,7 @@ fun main(args: Array) { StringBuilder().apply { append(multiline) } + val unsigned = 0x00UL + 123u + 76.54 } /* */ diff --git a/lexers/testdata/kotlin.expected b/lexers/testdata/kotlin.expected index 09efbdf..cd7574b 100644 --- a/lexers/testdata/kotlin.expected +++ b/lexers/testdata/kotlin.expected @@ -53,6 +53,22 @@ {"type":"Punctuation","value":")"}, {"type":"Text","value":"\n "}, {"type":"Punctuation","value":"}"}, + {"type":"Text","value":"\n "}, + {"type":"Keyword","value":"val"}, + {"type":"Text","value":" "}, + {"type":"NameProperty","value":"unsigned"}, + {"type":"Text","value":" "}, + {"type":"Punctuation","value":"="}, + {"type":"Text","value":" "}, + {"type":"LiteralNumber","value":"0x00UL"}, + {"type":"Text","value":" "}, + {"type":"Punctuation","value":"+"}, + {"type":"Text","value":" "}, + {"type":"LiteralNumber","value":"123u"}, + {"type":"Text","value":" "}, + {"type":"Punctuation","value":"+"}, + {"type":"Text","value":" "}, + {"type":"LiteralNumber","value":"76.54"}, {"type":"Text","value":"\n"}, {"type":"Punctuation","value":"}"}, {"type":"Text","value":"\n"},