Expand description
The one digit-separator rule for numeric literals (§4.3).
1_000_000 is one literal, and the _s in it are punctuation the value
does not contain. Two places have to agree about that: the lexer, which
decides how far a numeric literal runs, and lowering, which turns its text
into an i64 or an f64. If the lexer refuses a separator the decoder
strips, the literal is broken up before the decoder ever sees it and the
strip is unreachable.
Both halves live here so neither can drift: separator_run_len is what
the lexer consumes, strip_digit_separators is what the decoder removes,
and the rule is stated once.
The rule: a separator is one or more _ with a digit on each side. So
1_0, 1_000_000 and 1__0 are literals; _1 is an identifier (the lexer
never reaches here — dispatch routes on the first byte) and 1_ is the
literal 1 followed by the _ token. Nothing here decides where digits may
appear; the caller owns that, which is why a separator is legal in a fraction
and an exponent too (1_0.5_5e1_0).
Functions§
- parse_
int_ literal - The
i64anIntLittoken’s text names, orNonewhen it names a value outsideInt(§4.3). - separator_
run_ len - The length in bytes of the digit-separator run at
at, or0if there is none. - strip_
digit_ separators swith every digit separator removed, ready forstr::parse.