зеркало из https://github.com/github/ruby.git
[ruby/yarp] Check whether the conditional predicate is closed
https://github.com/ruby/yarp/commit/5022b51db2
This commit is contained in:
Родитель
639971a080
Коммит
0a630fa461
|
@ -1302,6 +1302,14 @@ module YARP
|
||||||
assert_error_messages "%sXfooX", error_messages
|
assert_error_messages "%sXfooX", error_messages
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_conditional_predicate_closed
|
||||||
|
source = "if 0 0; end\nunless 0 0; end"
|
||||||
|
assert_errors expression(source), source, [
|
||||||
|
["Expected `then` or `;` or '\n" + "'", 5..6],
|
||||||
|
["Expected `then` or `;` or '\n" + "'", 21..22],
|
||||||
|
]
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def assert_errors(expected, source, errors, compare_ripper: RUBY_ENGINE == "ruby")
|
def assert_errors(expected, source, errors, compare_ripper: RUBY_ENGINE == "ruby")
|
||||||
|
|
|
@ -93,6 +93,7 @@ static const char* const diagnostic_messages[YP_DIAGNOSTIC_ID_LEN] = {
|
||||||
[YP_ERR_CLASS_TERM] = "Expected an `end` to close the `class` statement",
|
[YP_ERR_CLASS_TERM] = "Expected an `end` to close the `class` statement",
|
||||||
[YP_ERR_CONDITIONAL_ELSIF_PREDICATE] = "Expected a predicate expression for the `elsif` statement",
|
[YP_ERR_CONDITIONAL_ELSIF_PREDICATE] = "Expected a predicate expression for the `elsif` statement",
|
||||||
[YP_ERR_CONDITIONAL_IF_PREDICATE] = "Expected a predicate expression for the `if` statement",
|
[YP_ERR_CONDITIONAL_IF_PREDICATE] = "Expected a predicate expression for the `if` statement",
|
||||||
|
[YP_ERR_CONDITIONAL_PREDICATE_TERM] = "Expected `then` or `;` or '\n'",
|
||||||
[YP_ERR_CONDITIONAL_TERM] = "Expected an `end` to close the conditional clause",
|
[YP_ERR_CONDITIONAL_TERM] = "Expected an `end` to close the conditional clause",
|
||||||
[YP_ERR_CONDITIONAL_TERM_ELSE] = "Expected an `end` to close the `else` clause",
|
[YP_ERR_CONDITIONAL_TERM_ELSE] = "Expected an `end` to close the `else` clause",
|
||||||
[YP_ERR_CONDITIONAL_UNLESS_PREDICATE] = "Expected a predicate expression for the `unless` statement",
|
[YP_ERR_CONDITIONAL_UNLESS_PREDICATE] = "Expected a predicate expression for the `unless` statement",
|
||||||
|
|
|
@ -58,6 +58,7 @@ typedef enum {
|
||||||
YP_ERR_CLASS_TERM,
|
YP_ERR_CLASS_TERM,
|
||||||
YP_ERR_CONDITIONAL_ELSIF_PREDICATE,
|
YP_ERR_CONDITIONAL_ELSIF_PREDICATE,
|
||||||
YP_ERR_CONDITIONAL_IF_PREDICATE,
|
YP_ERR_CONDITIONAL_IF_PREDICATE,
|
||||||
|
YP_ERR_CONDITIONAL_PREDICATE_TERM,
|
||||||
YP_ERR_CONDITIONAL_TERM,
|
YP_ERR_CONDITIONAL_TERM,
|
||||||
YP_ERR_CONDITIONAL_TERM_ELSE,
|
YP_ERR_CONDITIONAL_TERM_ELSE,
|
||||||
YP_ERR_CONDITIONAL_UNLESS_PREDICATE,
|
YP_ERR_CONDITIONAL_UNLESS_PREDICATE,
|
||||||
|
|
|
@ -9814,8 +9814,11 @@ parse_conditional(yp_parser_t *parser, yp_context_t context) {
|
||||||
yp_node_t *predicate = parse_expression(parser, YP_BINDING_POWER_MODIFIER, error_id);
|
yp_node_t *predicate = parse_expression(parser, YP_BINDING_POWER_MODIFIER, error_id);
|
||||||
|
|
||||||
// Predicates are closed by a term, a "then", or a term and then a "then".
|
// Predicates are closed by a term, a "then", or a term and then a "then".
|
||||||
accept2(parser, YP_TOKEN_NEWLINE, YP_TOKEN_SEMICOLON);
|
bool predicate_closed = accept2(parser, YP_TOKEN_NEWLINE, YP_TOKEN_SEMICOLON);
|
||||||
accept1(parser, YP_TOKEN_KEYWORD_THEN);
|
predicate_closed |= accept1(parser, YP_TOKEN_KEYWORD_THEN);
|
||||||
|
if (!predicate_closed) {
|
||||||
|
yp_diagnostic_list_append(&parser->error_list, parser->current.start, parser->current.end, YP_ERR_CONDITIONAL_PREDICATE_TERM);
|
||||||
|
}
|
||||||
|
|
||||||
context_pop(parser);
|
context_pop(parser);
|
||||||
yp_statements_node_t *statements = NULL;
|
yp_statements_node_t *statements = NULL;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче