Skip to content

Commit

Permalink
Match CRuby error messages for invalid numerics
Browse files Browse the repository at this point in the history
  • Loading branch information
kddnewton committed Apr 26, 2024
1 parent c0ccde1 commit be21a1b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/prism.c
Original file line number Diff line number Diff line change
Expand Up @@ -8507,6 +8507,7 @@ lex_numeric_prefix(pm_parser_t *parser, bool* seen_e) {
if (pm_char_is_decimal_digit(peek(parser))) {
parser->current.end += pm_strspn_decimal_number_validate(parser, parser->current.end);
} else {
match(parser, '_');
pm_parser_err_current(parser, PM_ERR_INVALID_NUMBER_DECIMAL);
}

Expand All @@ -8519,6 +8520,7 @@ lex_numeric_prefix(pm_parser_t *parser, bool* seen_e) {
if (pm_char_is_binary_digit(peek(parser))) {
parser->current.end += pm_strspn_binary_number_validate(parser, parser->current.end);
} else {
match(parser, '_');
pm_parser_err_current(parser, PM_ERR_INVALID_NUMBER_BINARY);
}

Expand All @@ -8532,6 +8534,7 @@ lex_numeric_prefix(pm_parser_t *parser, bool* seen_e) {
if (pm_char_is_octal_digit(peek(parser))) {
parser->current.end += pm_strspn_octal_number_validate(parser, parser->current.end);
} else {
match(parser, '_');
pm_parser_err_current(parser, PM_ERR_INVALID_NUMBER_OCTAL);
}

Expand Down Expand Up @@ -8559,6 +8562,7 @@ lex_numeric_prefix(pm_parser_t *parser, bool* seen_e) {
if (pm_char_is_hexadecimal_digit(peek(parser))) {
parser->current.end += pm_strspn_hexadecimal_number_validate(parser, parser->current.end);
} else {
match(parser, '_');
pm_parser_err_current(parser, PM_ERR_INVALID_NUMBER_HEXADECIMAL);
}

Expand Down
8 changes: 4 additions & 4 deletions templates/src/diagnostic.c.erb
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,10 @@ static const pm_diagnostic_data_t diagnostic_messages[PM_DIAGNOSTIC_ID_MAX] = {
[PM_ERR_INVALID_FLOAT_EXPONENT] = { "invalid exponent", PM_ERROR_LEVEL_SYNTAX },
[PM_ERR_INVALID_LOCAL_VARIABLE_READ] = { "identifier %.*s is not valid to get", PM_ERROR_LEVEL_SYNTAX },
[PM_ERR_INVALID_LOCAL_VARIABLE_WRITE] = { "identifier %.*s is not valid to set", PM_ERROR_LEVEL_SYNTAX },
[PM_ERR_INVALID_NUMBER_BINARY] = { "invalid binary number", PM_ERROR_LEVEL_SYNTAX },
[PM_ERR_INVALID_NUMBER_DECIMAL] = { "invalid decimal number", PM_ERROR_LEVEL_SYNTAX },
[PM_ERR_INVALID_NUMBER_HEXADECIMAL] = { "invalid hexadecimal number", PM_ERROR_LEVEL_SYNTAX },
[PM_ERR_INVALID_NUMBER_OCTAL] = { "invalid octal number", PM_ERROR_LEVEL_SYNTAX },
[PM_ERR_INVALID_NUMBER_BINARY] = { "invalid binary number; numeric literal without digits", PM_ERROR_LEVEL_SYNTAX },
[PM_ERR_INVALID_NUMBER_DECIMAL] = { "invalid decimal number; numeric literal without digits", PM_ERROR_LEVEL_SYNTAX },
[PM_ERR_INVALID_NUMBER_HEXADECIMAL] = { "invalid hexadecimal number; numeric literal without digits", PM_ERROR_LEVEL_SYNTAX },
[PM_ERR_INVALID_NUMBER_OCTAL] = { "invalid octal number; numeric literal without digits", PM_ERROR_LEVEL_SYNTAX },
[PM_ERR_INVALID_NUMBER_UNDERSCORE] = { "invalid underscore placement in number", PM_ERROR_LEVEL_SYNTAX },
[PM_ERR_INVALID_CHARACTER] = { "invalid character 0x%X", PM_ERROR_LEVEL_SYNTAX },
[PM_ERR_INVALID_MULTIBYTE_CHAR] = { "invalid multibyte char (%s)", PM_ERROR_LEVEL_SYNTAX },
Expand Down

0 comments on commit be21a1b

Please sign in to comment.