Skip to content

Commit

Permalink
Improve numbers parsing in Kotlin
Browse files Browse the repository at this point in the history
  • Loading branch information
kropp authored and alecthomas committed Feb 8, 2019
1 parent f4dea84 commit b5ccb8d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lexers/k/kotlin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")},
Expand Down
1 change: 1 addition & 0 deletions lexers/testdata/kotlin.actual
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ fun main(args: Array<String>) {
StringBuilder().apply {
append(multiline)
}
val unsigned = 0x00UL + 123u + 76.54
}
/*
*/
Expand Down
16 changes: 16 additions & 0 deletions lexers/testdata/kotlin.expected
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down

0 comments on commit b5ccb8d

Please sign in to comment.