Merge pull request #4973 from flofriday/fix-kotlin-number-literals

Fix Kotlin number literals
This commit is contained in:
Henning Dieterichs 2025-10-15 12:21:30 +02:00 committed by GitHub
commit 3a25d8ef40
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 161 additions and 21 deletions

View file

@ -277,6 +277,13 @@ testTokenization('kotlin', [
}
],
[
{
line: '.123',
tokens: [{ startIndex: 0, type: 'number.float.kt' }]
}
],
[
{
line: '0x',
@ -301,24 +308,62 @@ testTokenization('kotlin', [
}
],
[
{
line: '0Xff_81_00L',
tokens: [{ startIndex: 0, type: 'number.hex.kt' }]
}
],
[
{
line: '0x123u',
tokens: [{ startIndex: 0, type: 'number.hex.kt' }]
}
],
[
{
line: '0x123U',
tokens: [{ startIndex: 0, type: 'number.hex.kt' }]
}
],
[
{
line: '0x123uL',
tokens: [{ startIndex: 0, type: 'number.hex.kt' }]
}
],
[
{
line: '0x123UL',
tokens: [{ startIndex: 0, type: 'number.hex.kt' }]
}
],
[
{
line: '023L',
tokens: [{ startIndex: 0, type: 'number.octal.kt' }]
tokens: [{ startIndex: 0, type: 'number.kt' }]
}
],
[
{
line: '0123l',
tokens: [{ startIndex: 0, type: 'number.octal.kt' }]
tokens: [
{ startIndex: 0, type: 'number.kt' },
{ startIndex: 4, type: 'identifier.kt' }
]
}
],
[
{
line: '05_2',
tokens: [{ startIndex: 0, type: 'number.octal.kt' }]
tokens: [{ startIndex: 0, type: 'number.kt' }]
}
],
@ -336,6 +381,41 @@ testTokenization('kotlin', [
}
],
[
{
line: '0b0101L',
tokens: [{ startIndex: 0, type: 'number.binary.kt' }]
}
],
[
{
line: '0B0101u',
tokens: [{ startIndex: 0, type: 'number.binary.kt' }]
}
],
[
{
line: '0B1__0U',
tokens: [{ startIndex: 0, type: 'number.binary.kt' }]
}
],
[
{
line: '0B0101uL',
tokens: [{ startIndex: 0, type: 'number.binary.kt' }]
}
],
[
{
line: '0B1__0UL',
tokens: [{ startIndex: 0, type: 'number.binary.kt' }]
}
],
[
{
line: '10e3',
@ -401,57 +481,88 @@ testTokenization('kotlin', [
[
{
line: '23.5D',
line: '.001f',
tokens: [{ startIndex: 0, type: 'number.float.kt' }]
}
],
[
{
line: '23.5D',
tokens: [
{ startIndex: 0, type: 'number.float.kt' },
{ startIndex: 4, type: 'type.identifier.kt' }
]
}
],
[
{
line: '23.5d',
tokens: [{ startIndex: 0, type: 'number.float.kt' }]
tokens: [
{ startIndex: 0, type: 'number.float.kt' },
{ startIndex: 4, type: 'identifier.kt' }
]
}
],
[
{
line: '1.72E3D',
tokens: [{ startIndex: 0, type: 'number.float.kt' }]
tokens: [
{ startIndex: 0, type: 'number.float.kt' },
{ startIndex: 6, type: 'type.identifier.kt' }
]
}
],
[
{
line: '1.72E3d',
tokens: [{ startIndex: 0, type: 'number.float.kt' }]
tokens: [
{ startIndex: 0, type: 'number.float.kt' },
{ startIndex: 6, type: 'identifier.kt' }
]
}
],
[
{
line: '1.72E-3d',
tokens: [{ startIndex: 0, type: 'number.float.kt' }]
tokens: [
{ startIndex: 0, type: 'number.float.kt' },
{ startIndex: 7, type: 'identifier.kt' }
]
}
],
[
{
line: '1.72e3D',
tokens: [{ startIndex: 0, type: 'number.float.kt' }]
tokens: [
{ startIndex: 0, type: 'number.float.kt' },
{ startIndex: 6, type: 'type.identifier.kt' }
]
}
],
[
{
line: '1.72e3d',
tokens: [{ startIndex: 0, type: 'number.float.kt' }]
tokens: [
{ startIndex: 0, type: 'number.float.kt' },
{ startIndex: 6, type: 'identifier.kt' }
]
}
],
[
{
line: '1.72e-3d',
tokens: [{ startIndex: 0, type: 'number.float.kt' }]
tokens: [
{ startIndex: 0, type: 'number.float.kt' },
{ startIndex: 7, type: 'identifier.kt' }
]
}
],
@ -465,6 +576,37 @@ testTokenization('kotlin', [
[
{
line: '23l',
tokens: [
{ startIndex: 0, type: 'number.kt' },
{ startIndex: 2, type: 'identifier.kt' }
]
}
],
[
{
line: '23u',
tokens: [{ startIndex: 0, type: 'number.kt' }]
}
],
[
{
line: '23U',
tokens: [{ startIndex: 0, type: 'number.kt' }]
}
],
[
{
line: '23uL',
tokens: [{ startIndex: 0, type: 'number.kt' }]
}
],
[
{
line: '23UL',
tokens: [{ startIndex: 0, type: 'number.kt' }]
}
],
@ -496,8 +638,7 @@ testTokenization('kotlin', [
tokens: [
{ startIndex: 0, type: 'number.kt' },
{ startIndex: 1, type: 'identifier.kt' },
{ startIndex: 2, type: 'delimiter.kt' },
{ startIndex: 3, type: 'number.float.kt' }
{ startIndex: 2, type: 'number.float.kt' }
]
}
],
@ -567,7 +708,7 @@ testTokenization('kotlin', [
{
line: '052_',
tokens: [
{ startIndex: 0, type: 'number.octal.kt' },
{ startIndex: 0, type: 'number.kt' },
{ startIndex: 3, type: 'identifier.kt' }
]
}

View file

@ -211,13 +211,12 @@ export const language = <languages.IMonarchLanguage>{
[/@\s*[a-zA-Z_\$][\w\$]*/, 'annotation'],
// numbers
[/(@digits)[eE]([\-+]?(@digits))?[fFdD]?/, 'number.float'],
[/(@digits)\.(@digits)([eE][\-+]?(@digits))?[fFdD]?/, 'number.float'],
[/0[xX](@hexdigits)[Ll]?/, 'number.hex'],
[/0(@octaldigits)[Ll]?/, 'number.octal'],
[/0[bB](@binarydigits)[Ll]?/, 'number.binary'],
[/(@digits)[fFdD]/, 'number.float'],
[/(@digits)[lL]?/, 'number'],
[/(@digits)[eE]([\-+]?(@digits))?[fF]?/, 'number.float'],
[/(@digits)?\.(@digits)([eE][\-+]?(@digits))?[fF]?/, 'number.float'],
[/0[xX](@hexdigits)[uU]?L?/, 'number.hex'],
[/0[bB](@binarydigits)[uU]?L?/, 'number.binary'],
[/(@digits)[fF]/, 'number.float'],
[/(@digits)[uU]?L?/, 'number'],
// delimiter: after number because of .\d floats
[/[;,.]/, 'delimiter'],