mirror of
https://github.com/ruby/ruby.git
synced 2025-08-24 05:25:34 +02:00
[ruby/prism] CRuby error message for trailing underscore in number
4e34f236d3
This commit is contained in:
parent
d5d2c6ea33
commit
fc8fb581cf
4 changed files with 13 additions and 10 deletions
|
@ -143,7 +143,8 @@ errors:
|
|||
- INVALID_NUMBER_DECIMAL
|
||||
- INVALID_NUMBER_HEXADECIMAL
|
||||
- INVALID_NUMBER_OCTAL
|
||||
- INVALID_NUMBER_UNDERSCORE
|
||||
- INVALID_NUMBER_UNDERSCORE_INNER
|
||||
- INVALID_NUMBER_UNDERSCORE_TRAILING
|
||||
- INVALID_PERCENT
|
||||
- INVALID_PRINTABLE_CHARACTER
|
||||
- INVALID_RETRY_AFTER_ELSE
|
||||
|
|
|
@ -8558,10 +8558,11 @@ context_human(pm_context_t context) {
|
|||
/* Specific token lexers */
|
||||
/******************************************************************************/
|
||||
|
||||
static void
|
||||
pm_strspn_number_validate(pm_parser_t *parser, const uint8_t *invalid) {
|
||||
static inline void
|
||||
pm_strspn_number_validate(pm_parser_t *parser, const uint8_t *string, size_t length, const uint8_t *invalid) {
|
||||
if (invalid != NULL) {
|
||||
pm_parser_err(parser, invalid, invalid + 1, PM_ERR_INVALID_NUMBER_UNDERSCORE);
|
||||
pm_diagnostic_id_t diag_id = (invalid == (string + length - 1)) ? PM_ERR_INVALID_NUMBER_UNDERSCORE_TRAILING : PM_ERR_INVALID_NUMBER_UNDERSCORE_INNER;
|
||||
pm_parser_err(parser, invalid, invalid + 1, diag_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8569,7 +8570,7 @@ static size_t
|
|||
pm_strspn_binary_number_validate(pm_parser_t *parser, const uint8_t *string) {
|
||||
const uint8_t *invalid = NULL;
|
||||
size_t length = pm_strspn_binary_number(string, parser->end - string, &invalid);
|
||||
pm_strspn_number_validate(parser, invalid);
|
||||
pm_strspn_number_validate(parser, string, length, invalid);
|
||||
return length;
|
||||
}
|
||||
|
||||
|
@ -8577,7 +8578,7 @@ static size_t
|
|||
pm_strspn_octal_number_validate(pm_parser_t *parser, const uint8_t *string) {
|
||||
const uint8_t *invalid = NULL;
|
||||
size_t length = pm_strspn_octal_number(string, parser->end - string, &invalid);
|
||||
pm_strspn_number_validate(parser, invalid);
|
||||
pm_strspn_number_validate(parser, string, length, invalid);
|
||||
return length;
|
||||
}
|
||||
|
||||
|
@ -8585,7 +8586,7 @@ static size_t
|
|||
pm_strspn_decimal_number_validate(pm_parser_t *parser, const uint8_t *string) {
|
||||
const uint8_t *invalid = NULL;
|
||||
size_t length = pm_strspn_decimal_number(string, parser->end - string, &invalid);
|
||||
pm_strspn_number_validate(parser, invalid);
|
||||
pm_strspn_number_validate(parser, string, length, invalid);
|
||||
return length;
|
||||
}
|
||||
|
||||
|
@ -8593,7 +8594,7 @@ static size_t
|
|||
pm_strspn_hexadecimal_number_validate(pm_parser_t *parser, const uint8_t *string) {
|
||||
const uint8_t *invalid = NULL;
|
||||
size_t length = pm_strspn_hexadecimal_number(string, parser->end - string, &invalid);
|
||||
pm_strspn_number_validate(parser, invalid);
|
||||
pm_strspn_number_validate(parser, string, length, invalid);
|
||||
return length;
|
||||
}
|
||||
|
||||
|
|
|
@ -222,7 +222,8 @@ static const pm_diagnostic_data_t diagnostic_messages[PM_DIAGNOSTIC_ID_MAX] = {
|
|||
[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_NUMBER_UNDERSCORE_INNER] = { "invalid underscore placement in number", PM_ERROR_LEVEL_SYNTAX },
|
||||
[PM_ERR_INVALID_NUMBER_UNDERSCORE_TRAILING] = { "trailing '_' 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 },
|
||||
[PM_ERR_INVALID_MULTIBYTE_CHARACTER] = { "invalid multibyte character 0x%X", PM_ERROR_LEVEL_SYNTAX },
|
||||
|
|
|
@ -1381,7 +1381,6 @@ module Prism
|
|||
|
||||
def test_invalid_number_underscores
|
||||
error_messages = ["invalid underscore placement in number"]
|
||||
|
||||
assert_error_messages "1__1", error_messages
|
||||
assert_error_messages "0b1__1", error_messages
|
||||
assert_error_messages "0o1__1", error_messages
|
||||
|
@ -1389,6 +1388,7 @@ module Prism
|
|||
assert_error_messages "0d1__1", error_messages
|
||||
assert_error_messages "0x1__1", error_messages
|
||||
|
||||
error_messages = ["trailing '_' in number"]
|
||||
assert_error_messages "1_1_", error_messages
|
||||
assert_error_messages "0b1_1_", error_messages
|
||||
assert_error_messages "0o1_1_", error_messages
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue