Skip to content

Commit

Permalink
Improve parsing of numbers in Kotlin lexer
Browse files Browse the repository at this point in the history
- Adds support for underscore separator.
- Add support for binary literals.
- Removes invalid support for lowercase "l" suffix.
- Adds support for unsigned literals.
  • Loading branch information
goodhoko committed Apr 25, 2020
1 parent 2e9c3cd commit dfd565d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rouge/lexers/kotlin.rb
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions spec/visual/samples/kotlin
Expand Up @@ -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)

0 comments on commit dfd565d

Please sign in to comment.