[ruby/prism] Match error messages for invalid instance/class variables
https://github.com/ruby/prism/commit/82fd0599ed
This commit is contained in:
parent
67bd5b33f9
commit
d898f00fe1
@ -47,6 +47,7 @@ errors:
|
|||||||
- CLASS_SUPERCLASS
|
- CLASS_SUPERCLASS
|
||||||
- CLASS_TERM
|
- CLASS_TERM
|
||||||
- CLASS_UNEXPECTED_END
|
- CLASS_UNEXPECTED_END
|
||||||
|
- CLASS_VARIABLE_BARE
|
||||||
- CONDITIONAL_ELSIF_PREDICATE
|
- CONDITIONAL_ELSIF_PREDICATE
|
||||||
- CONDITIONAL_IF_PREDICATE
|
- CONDITIONAL_IF_PREDICATE
|
||||||
- CONDITIONAL_PREDICATE_TERM
|
- CONDITIONAL_PREDICATE_TERM
|
||||||
@ -119,6 +120,7 @@ errors:
|
|||||||
- INCOMPLETE_VARIABLE_CLASS_3_3_0
|
- INCOMPLETE_VARIABLE_CLASS_3_3_0
|
||||||
- INCOMPLETE_VARIABLE_INSTANCE
|
- INCOMPLETE_VARIABLE_INSTANCE
|
||||||
- INCOMPLETE_VARIABLE_INSTANCE_3_3_0
|
- INCOMPLETE_VARIABLE_INSTANCE_3_3_0
|
||||||
|
- INSTANCE_VARIABLE_BARE
|
||||||
- INVALID_CHARACTER
|
- INVALID_CHARACTER
|
||||||
- INVALID_ENCODING_MAGIC_COMMENT
|
- INVALID_ENCODING_MAGIC_COMMENT
|
||||||
- INVALID_FLOAT_EXPONENT
|
- INVALID_FLOAT_EXPONENT
|
||||||
|
@ -9022,7 +9022,7 @@ lex_at_variable(pm_parser_t *parser) {
|
|||||||
while (parser->current.end < parser->end && (width = char_is_identifier(parser, parser->current.end)) > 0) {
|
while (parser->current.end < parser->end && (width = char_is_identifier(parser, parser->current.end)) > 0) {
|
||||||
parser->current.end += width;
|
parser->current.end += width;
|
||||||
}
|
}
|
||||||
} else {
|
} else if (parser->current.end < parser->end && pm_char_is_decimal_digit(*parser->current.end)) {
|
||||||
pm_diagnostic_id_t diag_id = (type == PM_TOKEN_CLASS_VARIABLE) ? PM_ERR_INCOMPLETE_VARIABLE_CLASS : PM_ERR_INCOMPLETE_VARIABLE_INSTANCE;
|
pm_diagnostic_id_t diag_id = (type == PM_TOKEN_CLASS_VARIABLE) ? PM_ERR_INCOMPLETE_VARIABLE_CLASS : PM_ERR_INCOMPLETE_VARIABLE_INSTANCE;
|
||||||
if (parser->version == PM_OPTIONS_VERSION_CRUBY_3_3_0) {
|
if (parser->version == PM_OPTIONS_VERSION_CRUBY_3_3_0) {
|
||||||
diag_id = (type == PM_TOKEN_CLASS_VARIABLE) ? PM_ERR_INCOMPLETE_VARIABLE_CLASS_3_3_0 : PM_ERR_INCOMPLETE_VARIABLE_INSTANCE_3_3_0;
|
diag_id = (type == PM_TOKEN_CLASS_VARIABLE) ? PM_ERR_INCOMPLETE_VARIABLE_CLASS_3_3_0 : PM_ERR_INCOMPLETE_VARIABLE_INSTANCE_3_3_0;
|
||||||
@ -9030,6 +9030,9 @@ lex_at_variable(pm_parser_t *parser) {
|
|||||||
|
|
||||||
size_t width = parser->encoding->char_width(parser->current.end, parser->end - parser->current.end);
|
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);
|
PM_PARSER_ERR_TOKEN_FORMAT(parser, parser->current, diag_id, (int) ((parser->current.end + width) - parser->current.start), (const char *) parser->current.start);
|
||||||
|
} else {
|
||||||
|
pm_diagnostic_id_t diag_id = (type == PM_TOKEN_CLASS_VARIABLE) ? PM_ERR_CLASS_VARIABLE_BARE : PM_ERR_INSTANCE_VARIABLE_BARE;
|
||||||
|
pm_parser_err_token(parser, &parser->current, diag_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we're lexing an embedded variable, then we need to pop back into the
|
// If we're lexing an embedded variable, then we need to pop back into the
|
||||||
|
@ -132,6 +132,7 @@ static const pm_diagnostic_data_t diagnostic_messages[PM_DIAGNOSTIC_ID_MAX] = {
|
|||||||
[PM_ERR_CLASS_SUPERCLASS] = { "expected a superclass after `<`", PM_ERROR_LEVEL_SYNTAX },
|
[PM_ERR_CLASS_SUPERCLASS] = { "expected a superclass after `<`", PM_ERROR_LEVEL_SYNTAX },
|
||||||
[PM_ERR_CLASS_TERM] = { "expected an `end` to close the `class` statement", PM_ERROR_LEVEL_SYNTAX },
|
[PM_ERR_CLASS_TERM] = { "expected an `end` to close the `class` statement", PM_ERROR_LEVEL_SYNTAX },
|
||||||
[PM_ERR_CLASS_UNEXPECTED_END] = { "unexpected `end`, expecting ';' or '\\n'", PM_ERROR_LEVEL_SYNTAX },
|
[PM_ERR_CLASS_UNEXPECTED_END] = { "unexpected `end`, expecting ';' or '\\n'", PM_ERROR_LEVEL_SYNTAX },
|
||||||
|
[PM_ERR_CLASS_VARIABLE_BARE] = { "'@@' without identifiers is not allowed as a class variable name", PM_ERROR_LEVEL_SYNTAX },
|
||||||
[PM_ERR_CONDITIONAL_ELSIF_PREDICATE] = { "expected a predicate expression for the `elsif` statement", PM_ERROR_LEVEL_SYNTAX },
|
[PM_ERR_CONDITIONAL_ELSIF_PREDICATE] = { "expected a predicate expression for the `elsif` statement", PM_ERROR_LEVEL_SYNTAX },
|
||||||
[PM_ERR_CONDITIONAL_IF_PREDICATE] = { "expected a predicate expression for the `if` statement", PM_ERROR_LEVEL_SYNTAX },
|
[PM_ERR_CONDITIONAL_IF_PREDICATE] = { "expected a predicate expression for the `if` statement", PM_ERROR_LEVEL_SYNTAX },
|
||||||
[PM_ERR_CONDITIONAL_PREDICATE_TERM] = { "expected `then` or `;` or '\\n'", PM_ERROR_LEVEL_SYNTAX },
|
[PM_ERR_CONDITIONAL_PREDICATE_TERM] = { "expected `then` or `;` or '\\n'", PM_ERROR_LEVEL_SYNTAX },
|
||||||
@ -203,6 +204,7 @@ static const pm_diagnostic_data_t diagnostic_messages[PM_DIAGNOSTIC_ID_MAX] = {
|
|||||||
[PM_ERR_INCOMPLETE_VARIABLE_CLASS] = { "'%.*s' is not allowed as a class variable name", PM_ERROR_LEVEL_SYNTAX },
|
[PM_ERR_INCOMPLETE_VARIABLE_CLASS] = { "'%.*s' is not allowed as a class variable name", PM_ERROR_LEVEL_SYNTAX },
|
||||||
[PM_ERR_INCOMPLETE_VARIABLE_INSTANCE_3_3_0] = { "`%.*s' is not allowed as an instance variable name", PM_ERROR_LEVEL_SYNTAX },
|
[PM_ERR_INCOMPLETE_VARIABLE_INSTANCE_3_3_0] = { "`%.*s' is not allowed as an instance variable name", PM_ERROR_LEVEL_SYNTAX },
|
||||||
[PM_ERR_INCOMPLETE_VARIABLE_INSTANCE] = { "'%.*s' is not allowed as an instance variable name", PM_ERROR_LEVEL_SYNTAX },
|
[PM_ERR_INCOMPLETE_VARIABLE_INSTANCE] = { "'%.*s' is not allowed as an instance variable name", PM_ERROR_LEVEL_SYNTAX },
|
||||||
|
[PM_ERR_INSTANCE_VARIABLE_BARE] = { "'@' without identifiers is not allowed as an instance variable name", PM_ERROR_LEVEL_SYNTAX },
|
||||||
[PM_ERR_INVALID_FLOAT_EXPONENT] = { "invalid exponent", PM_ERROR_LEVEL_SYNTAX },
|
[PM_ERR_INVALID_FLOAT_EXPONENT] = { "invalid exponent", PM_ERROR_LEVEL_SYNTAX },
|
||||||
[PM_ERR_INVALID_NUMBER_BINARY] = { "invalid binary number", 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_DECIMAL] = { "invalid decimal number", PM_ERROR_LEVEL_SYNTAX },
|
||||||
|
Loading…
x
Reference in New Issue
Block a user