From c99692df8a1634c297d942222afa6dbaf2c52062 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Sat, 20 Dec 2025 13:00:42 -0800 Subject: [PATCH] Fix overly greedy digits This fixes several rules that were using greedy repetition operators. The problem with `(DIGIT|_)* DIGIT` is that the first repetition consumes all of the digits. I actually don't know exactly why the original rules were written in this particular way. I'm guessing they were intending to express that there must be at least one digit. However, just having `_`* should be sufficient. --- src/tokens.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/tokens.md b/src/tokens.md index f34fcb92d6..ddb958304c 100644 --- a/src/tokens.md +++ b/src/tokens.md @@ -445,11 +445,11 @@ INTEGER_LITERAL -> DEC_LITERAL -> DEC_DIGIT (DEC_DIGIT|`_`)* -BIN_LITERAL -> `0b` (BIN_DIGIT|`_`)* BIN_DIGIT (BIN_DIGIT|`_`)* +BIN_LITERAL -> `0b` `_`* BIN_DIGIT (BIN_DIGIT|`_`)* -OCT_LITERAL -> `0o` (OCT_DIGIT|`_`)* OCT_DIGIT (OCT_DIGIT|`_`)* +OCT_LITERAL -> `0o` `_`* OCT_DIGIT (OCT_DIGIT|`_`)* -HEX_LITERAL -> `0x` (HEX_DIGIT|`_`)* HEX_DIGIT (HEX_DIGIT|`_`)* +HEX_LITERAL -> `0x` `_`* HEX_DIGIT (HEX_DIGIT|`_`)* BIN_DIGIT -> [`0`-`1`] @@ -561,7 +561,7 @@ FLOAT_LITERAL -> | DEC_LITERAL (`.` DEC_LITERAL)? FLOAT_EXPONENT SUFFIX? FLOAT_EXPONENT -> - (`e`|`E`) (`+`|`-`)? (DEC_DIGIT|`_`)* DEC_DIGIT (DEC_DIGIT|`_`)* + (`e`|`E`) (`+`|`-`)? `_`* DEC_DIGIT (DEC_DIGIT|`_`)* ``` r[lex.token.literal.float.form]