[ruby/prism] Fix up error messages for empty global variable
https://github.com/ruby/prism/commit/fa7559d40b
This commit is contained in:
parent
d898f00fe1
commit
d6c1cc5532
@ -109,6 +109,7 @@ errors:
|
||||
- FOR_IN
|
||||
- FOR_INDEX
|
||||
- FOR_TERM
|
||||
- GLOBAL_VARIABLE_BARE
|
||||
- HASH_EXPRESSION_AFTER_LABEL
|
||||
- HASH_KEY
|
||||
- HASH_ROCKET
|
||||
|
@ -7994,8 +7994,7 @@ lex_numeric(pm_parser_t *parser) {
|
||||
static pm_token_type_t
|
||||
lex_global_variable(pm_parser_t *parser) {
|
||||
if (parser->current.end >= parser->end) {
|
||||
pm_diagnostic_id_t diag_id = parser->version == PM_OPTIONS_VERSION_CRUBY_3_3_0 ? PM_ERR_INVALID_VARIABLE_GLOBAL_3_3_0 : PM_ERR_INVALID_VARIABLE_GLOBAL;
|
||||
PM_PARSER_ERR_TOKEN_FORMAT_CONTENT(parser, parser->current, diag_id);
|
||||
pm_parser_err_token(parser, &parser->current, PM_ERR_GLOBAL_VARIABLE_BARE);
|
||||
return PM_TOKEN_GLOBAL_VARIABLE;
|
||||
}
|
||||
|
||||
@ -8066,10 +8065,11 @@ lex_global_variable(pm_parser_t *parser) {
|
||||
parser->current.end += width;
|
||||
} while (parser->current.end < parser->end && (width = char_is_identifier(parser, parser->current.end)) > 0);
|
||||
} else {
|
||||
// If we get here, then we have a $ followed by something that isn't
|
||||
// recognized as a global variable.
|
||||
// If we get here, then we have a $ followed by something that
|
||||
// isn't recognized as a global variable.
|
||||
pm_diagnostic_id_t diag_id = parser->version == PM_OPTIONS_VERSION_CRUBY_3_3_0 ? PM_ERR_INVALID_VARIABLE_GLOBAL_3_3_0 : PM_ERR_INVALID_VARIABLE_GLOBAL;
|
||||
PM_PARSER_ERR_TOKEN_FORMAT_CONTENT(parser, parser->current, diag_id);
|
||||
size_t width = parser->encoding->char_width(parser->current.end, parser->end - parser->current.end);
|
||||
PM_PARSER_ERR_TOKEN_FORMAT(parser, parser->current, diag_id, (int) ((parser->current.end + width) - parser->current.start), (const char *) parser->current.start);
|
||||
}
|
||||
|
||||
return PM_TOKEN_GLOBAL_VARIABLE;
|
||||
|
@ -193,6 +193,7 @@ static const pm_diagnostic_data_t diagnostic_messages[PM_DIAGNOSTIC_ID_MAX] = {
|
||||
[PM_ERR_FOR_INDEX] = { "expected an index after `for`", PM_ERROR_LEVEL_SYNTAX },
|
||||
[PM_ERR_FOR_IN] = { "expected an `in` after the index in a `for` statement", PM_ERROR_LEVEL_SYNTAX },
|
||||
[PM_ERR_FOR_TERM] = { "expected an `end` to close the `for` loop", PM_ERROR_LEVEL_SYNTAX },
|
||||
[PM_ERR_GLOBAL_VARIABLE_BARE] = { "'$' without identifiers is not allowed as a global variable name", PM_ERROR_LEVEL_SYNTAX },
|
||||
[PM_ERR_HASH_EXPRESSION_AFTER_LABEL] = { "expected an expression after the label in a hash", PM_ERROR_LEVEL_SYNTAX },
|
||||
[PM_ERR_HASH_KEY] = { "unexpected %s, expecting '}' or a key in the hash literal", PM_ERROR_LEVEL_SYNTAX },
|
||||
[PM_ERR_HASH_ROCKET] = { "expected a `=>` between the hash key and value", PM_ERROR_LEVEL_SYNTAX },
|
||||
|
Loading…
x
Reference in New Issue
Block a user