@@ -458,7 +458,7 @@ class Lexer(input: Iterator<Char>) : Iterator<Spanned<Token>> {
458458 fun readE (): String {
459459 val e = iter.next().toString()
460460 val sign = accept(" +-" )?.toString() ? : " "
461- val exp = acceptMany(" 0123456789 " )
461+ val exp = acceptMany(" 0123456789_ " ).replace( " _ " , " " )
462462 if (exp.isEmpty()) {
463463 val span = Span .new(startPos, iter.position())
464464 lexError(" Invalid number format: expected number after `e`." , span)
@@ -481,7 +481,7 @@ class Lexer(input: Iterator<Char>) : Iterator<Spanned<Token>> {
481481 // binary numbers
482482 ' b' , ' B' -> {
483483 iter.next()
484- val bin = acceptMany(" 01 " )
484+ val bin = acceptMany(" 01_ " ).replace( " _ " , " " )
485485 if (bin.isEmpty()) lexError(" Binary number cannot be empty" )
486486 val l = accept(" L" )
487487 if (l != null ) LongT (bin.toSafeLong(2 ) * n, " ${pref} 0$c$bin " )
@@ -490,7 +490,7 @@ class Lexer(input: Iterator<Char>) : Iterator<Spanned<Token>> {
490490 // hex numbers
491491 ' x' , ' X' -> {
492492 iter.next()
493- val hex = acceptMany(" 0123456789abcdefABCDEF " )
493+ val hex = acceptMany(" 0123456789abcdefABCDEF_ " ).replace( " _ " , " " )
494494 if (hex.isEmpty()) lexError(" Hexadecimal number cannot be empty" )
495495 val l = accept(" L" )
496496 if (l != null ) LongT (hex.toSafeLong(16 ) * n, " ${pref} 0$c$hex " )
@@ -508,14 +508,14 @@ class Lexer(input: Iterator<Char>) : Iterator<Spanned<Token>> {
508508 }
509509 }
510510 } else {
511- val num = init + acceptMany(" 0123456789 " )
511+ val num = init + acceptMany(" 0123456789_ " ).replace( " _ " , " " )
512512
513513 val next = if (iter.hasNext()) iter.peek() else ' '
514514 when {
515515 next == ' .' -> {
516516 // Double
517517 iter.next()
518- val end = acceptMany(" 0123456789 " )
518+ val end = acceptMany(" 0123456789_ " ).replace( " _ " , " " )
519519 if (end.isEmpty()) lexError(" Invalid number format: number cannot end in `.`" )
520520 val number = if (iter.hasNext() && iter.peek().lowercaseChar() == ' e' ) {
521521 " $num .$end${readE()} "
0 commit comments