Skip to content

Commit 011b69b

Browse files
committed
Fix Kotlin number literals
1 parent 2e93787 commit 011b69b

File tree

2 files changed

+161
-21
lines changed

2 files changed

+161
-21
lines changed

src/basic-languages/kotlin/kotlin.test.ts

Lines changed: 155 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,13 @@ testTokenization('kotlin', [
277277
}
278278
],
279279

280+
[
281+
{
282+
line: '.123',
283+
tokens: [{ startIndex: 0, type: 'number.float.kt' }]
284+
}
285+
],
286+
280287
[
281288
{
282289
line: '0x',
@@ -301,24 +308,62 @@ testTokenization('kotlin', [
301308
}
302309
],
303310

311+
[
312+
{
313+
line: '0Xff_81_00L',
314+
tokens: [{ startIndex: 0, type: 'number.hex.kt' }]
315+
}
316+
],
317+
318+
[
319+
{
320+
line: '0x123u',
321+
tokens: [{ startIndex: 0, type: 'number.hex.kt' }]
322+
}
323+
],
324+
325+
[
326+
{
327+
line: '0x123U',
328+
tokens: [{ startIndex: 0, type: 'number.hex.kt' }]
329+
}
330+
],
331+
332+
[
333+
{
334+
line: '0x123uL',
335+
tokens: [{ startIndex: 0, type: 'number.hex.kt' }]
336+
}
337+
],
338+
339+
[
340+
{
341+
line: '0x123UL',
342+
tokens: [{ startIndex: 0, type: 'number.hex.kt' }]
343+
}
344+
],
345+
304346
[
305347
{
306348
line: '023L',
307-
tokens: [{ startIndex: 0, type: 'number.octal.kt' }]
349+
tokens: [{ startIndex: 0, type: 'number.kt' }]
308350
}
309351
],
310352

311353
[
312354
{
313355
line: '0123l',
314-
tokens: [{ startIndex: 0, type: 'number.octal.kt' }]
356+
tokens: [
357+
{ startIndex: 0, type: 'number.kt' },
358+
{ startIndex: 4, type: 'identifier.kt' }
359+
]
315360
}
316361
],
317362

318363
[
319364
{
320365
line: '05_2',
321-
tokens: [{ startIndex: 0, type: 'number.octal.kt' }]
366+
tokens: [{ startIndex: 0, type: 'number.kt' }]
322367
}
323368
],
324369

@@ -336,6 +381,41 @@ testTokenization('kotlin', [
336381
}
337382
],
338383

384+
[
385+
{
386+
line: '0b0101L',
387+
tokens: [{ startIndex: 0, type: 'number.binary.kt' }]
388+
}
389+
],
390+
391+
[
392+
{
393+
line: '0B0101u',
394+
tokens: [{ startIndex: 0, type: 'number.binary.kt' }]
395+
}
396+
],
397+
398+
[
399+
{
400+
line: '0B1__0U',
401+
tokens: [{ startIndex: 0, type: 'number.binary.kt' }]
402+
}
403+
],
404+
405+
[
406+
{
407+
line: '0B0101uL',
408+
tokens: [{ startIndex: 0, type: 'number.binary.kt' }]
409+
}
410+
],
411+
412+
[
413+
{
414+
line: '0B1__0UL',
415+
tokens: [{ startIndex: 0, type: 'number.binary.kt' }]
416+
}
417+
],
418+
339419
[
340420
{
341421
line: '10e3',
@@ -401,57 +481,88 @@ testTokenization('kotlin', [
401481

402482
[
403483
{
404-
line: '23.5D',
484+
line: '.001f',
405485
tokens: [{ startIndex: 0, type: 'number.float.kt' }]
406486
}
407487
],
408488

489+
[
490+
{
491+
line: '23.5D',
492+
tokens: [
493+
{ startIndex: 0, type: 'number.float.kt' },
494+
{ startIndex: 4, type: 'type.identifier.kt' }
495+
]
496+
}
497+
],
498+
409499
[
410500
{
411501
line: '23.5d',
412-
tokens: [{ startIndex: 0, type: 'number.float.kt' }]
502+
tokens: [
503+
{ startIndex: 0, type: 'number.float.kt' },
504+
{ startIndex: 4, type: 'identifier.kt' }
505+
]
413506
}
414507
],
415508

416509
[
417510
{
418511
line: '1.72E3D',
419-
tokens: [{ startIndex: 0, type: 'number.float.kt' }]
512+
tokens: [
513+
{ startIndex: 0, type: 'number.float.kt' },
514+
{ startIndex: 6, type: 'type.identifier.kt' }
515+
]
420516
}
421517
],
422518

423519
[
424520
{
425521
line: '1.72E3d',
426-
tokens: [{ startIndex: 0, type: 'number.float.kt' }]
522+
tokens: [
523+
{ startIndex: 0, type: 'number.float.kt' },
524+
{ startIndex: 6, type: 'identifier.kt' }
525+
]
427526
}
428527
],
429528

430529
[
431530
{
432531
line: '1.72E-3d',
433-
tokens: [{ startIndex: 0, type: 'number.float.kt' }]
532+
tokens: [
533+
{ startIndex: 0, type: 'number.float.kt' },
534+
{ startIndex: 7, type: 'identifier.kt' }
535+
]
434536
}
435537
],
436538

437539
[
438540
{
439541
line: '1.72e3D',
440-
tokens: [{ startIndex: 0, type: 'number.float.kt' }]
542+
tokens: [
543+
{ startIndex: 0, type: 'number.float.kt' },
544+
{ startIndex: 6, type: 'type.identifier.kt' }
545+
]
441546
}
442547
],
443548

444549
[
445550
{
446551
line: '1.72e3d',
447-
tokens: [{ startIndex: 0, type: 'number.float.kt' }]
552+
tokens: [
553+
{ startIndex: 0, type: 'number.float.kt' },
554+
{ startIndex: 6, type: 'identifier.kt' }
555+
]
448556
}
449557
],
450558

451559
[
452560
{
453561
line: '1.72e-3d',
454-
tokens: [{ startIndex: 0, type: 'number.float.kt' }]
562+
tokens: [
563+
{ startIndex: 0, type: 'number.float.kt' },
564+
{ startIndex: 7, type: 'identifier.kt' }
565+
]
455566
}
456567
],
457568

@@ -465,6 +576,37 @@ testTokenization('kotlin', [
465576
[
466577
{
467578
line: '23l',
579+
tokens: [
580+
{ startIndex: 0, type: 'number.kt' },
581+
{ startIndex: 2, type: 'identifier.kt' }
582+
]
583+
}
584+
],
585+
586+
[
587+
{
588+
line: '23u',
589+
tokens: [{ startIndex: 0, type: 'number.kt' }]
590+
}
591+
],
592+
593+
[
594+
{
595+
line: '23U',
596+
tokens: [{ startIndex: 0, type: 'number.kt' }]
597+
}
598+
],
599+
600+
[
601+
{
602+
line: '23uL',
603+
tokens: [{ startIndex: 0, type: 'number.kt' }]
604+
}
605+
],
606+
607+
[
608+
{
609+
line: '23UL',
468610
tokens: [{ startIndex: 0, type: 'number.kt' }]
469611
}
470612
],
@@ -496,8 +638,7 @@ testTokenization('kotlin', [
496638
tokens: [
497639
{ startIndex: 0, type: 'number.kt' },
498640
{ startIndex: 1, type: 'identifier.kt' },
499-
{ startIndex: 2, type: 'delimiter.kt' },
500-
{ startIndex: 3, type: 'number.float.kt' }
641+
{ startIndex: 2, type: 'number.float.kt' }
501642
]
502643
}
503644
],
@@ -567,7 +708,7 @@ testTokenization('kotlin', [
567708
{
568709
line: '052_',
569710
tokens: [
570-
{ startIndex: 0, type: 'number.octal.kt' },
711+
{ startIndex: 0, type: 'number.kt' },
571712
{ startIndex: 3, type: 'identifier.kt' }
572713
]
573714
}

src/basic-languages/kotlin/kotlin.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -211,13 +211,12 @@ export const language = <languages.IMonarchLanguage>{
211211
[/@\s*[a-zA-Z_\$][\w\$]*/, 'annotation'],
212212

213213
// numbers
214-
[/(@digits)[eE]([\-+]?(@digits))?[fFdD]?/, 'number.float'],
215-
[/(@digits)\.(@digits)([eE][\-+]?(@digits))?[fFdD]?/, 'number.float'],
216-
[/0[xX](@hexdigits)[Ll]?/, 'number.hex'],
217-
[/0(@octaldigits)[Ll]?/, 'number.octal'],
218-
[/0[bB](@binarydigits)[Ll]?/, 'number.binary'],
219-
[/(@digits)[fFdD]/, 'number.float'],
220-
[/(@digits)[lL]?/, 'number'],
214+
[/(@digits)[eE]([\-+]?(@digits))?[fF]?/, 'number.float'],
215+
[/(@digits)?\.(@digits)([eE][\-+]?(@digits))?[fF]?/, 'number.float'],
216+
[/0[xX](@hexdigits)[uU]?L?/, 'number.hex'],
217+
[/0[bB](@binarydigits)[uU]?L?/, 'number.binary'],
218+
[/(@digits)[fF]/, 'number.float'],
219+
[/(@digits)[uU]?L?/, 'number'],
221220

222221
// delimiter: after number because of .\d floats
223222
[/[;,.]/, 'delimiter'],

0 commit comments

Comments
 (0)