From c17f33aa4240e38cefdb2af04a078409c2645a5a Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Wed, 13 Mar 2024 12:50:27 -0400 Subject: [PATCH] [ruby/prism] Only use e suffix for floats if followed by +, -, or digit https://github.com/ruby/prism/commit/164de502c9 --- prism/prism.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/prism/prism.c b/prism/prism.c index 930530e837..a4f9c5dafa 100644 --- a/prism/prism.c +++ b/prism/prism.c @@ -7595,26 +7595,33 @@ lex_optional_float_suffix(pm_parser_t *parser, bool* seen_e) { parser->current.end += pm_strspn_decimal_number_validate(parser, parser->current.end); type = PM_TOKEN_FLOAT; } else { - // If we had a . and then something else, then it's not a float suffix on - // a number it's a method call or something else. + // If we had a . and then something else, then it's not a float + // suffix on a number it's a method call or something else. return type; } } // Here we're going to attempt to parse the optional exponent portion of a // float. If it's not there, it's okay and we'll just continue on. - if (match(parser, 'e') || match(parser, 'E')) { - (void) (match(parser, '+') || match(parser, '-')); - *seen_e = true; + if ((peek(parser) == 'e') || (peek(parser) == 'E')) { + if ((peek_offset(parser, 1) == '+') || (peek_offset(parser, 1) == '-')) { + parser->current.end += 2; - if (pm_char_is_decimal_digit(peek(parser))) { + if (pm_char_is_decimal_digit(peek(parser))) { + parser->current.end++; + parser->current.end += pm_strspn_decimal_number_validate(parser, parser->current.end); + } else { + pm_parser_err_current(parser, PM_ERR_INVALID_FLOAT_EXPONENT); + } + } else if (pm_char_is_decimal_digit(peek_offset(parser, 1))) { parser->current.end++; parser->current.end += pm_strspn_decimal_number_validate(parser, parser->current.end); - type = PM_TOKEN_FLOAT; } else { - pm_parser_err_current(parser, PM_ERR_INVALID_FLOAT_EXPONENT); - type = PM_TOKEN_FLOAT; + return type; } + + *seen_e = true; + type = PM_TOKEN_FLOAT; } return type;