diff options
author | Haldun Bayhantopcu <haldun@github.com> | 2023-09-27 20:24:19 +0200 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2023-09-28 13:31:22 +0000 |
commit | 7799fe90da49958af0d33d18c82f12012610f32a (patch) | |
tree | 8c98f0749b042432eadbfa62275444cfc80e673a /prism | |
parent | 0084bac47a49d787a86c4cfd4d238c24736eb659 (diff) | |
download | ruby-7799fe90da49958af0d33d18c82f12012610f32a.tar.gz |
[ruby/prism] Check for a semicolon or a newline after the inheritance operator
https://github.com/ruby/prism/commit/0326ba6775
Diffstat (limited to 'prism')
-rw-r--r-- | prism/diagnostic.c | 1 | ||||
-rw-r--r-- | prism/diagnostic.h | 1 | ||||
-rw-r--r-- | prism/prism.c | 6 |
3 files changed, 7 insertions, 1 deletions
diff --git a/prism/diagnostic.c b/prism/diagnostic.c index b8b92f97e0..7eafd8b088 100644 --- a/prism/diagnostic.c +++ b/prism/diagnostic.c @@ -92,6 +92,7 @@ static const char* const diagnostic_messages[PM_DIAGNOSTIC_ID_LEN] = { [PM_ERR_CLASS_NAME] = "Expected a constant name after `class`", [PM_ERR_CLASS_SUPERCLASS] = "Expected a superclass after `<`", [PM_ERR_CLASS_TERM] = "Expected an `end` to close the `class` statement", + [PM_ERR_CLASS_UNEXPECTED_END] = "Unexpected `end`, expecting ';' or '\n'", [PM_ERR_CONDITIONAL_ELSIF_PREDICATE] = "Expected a predicate expression for the `elsif` statement", [PM_ERR_CONDITIONAL_IF_PREDICATE] = "Expected a predicate expression for the `if` statement", [PM_ERR_CONDITIONAL_PREDICATE_TERM] = "Expected `then` or `;` or '\n'", diff --git a/prism/diagnostic.h b/prism/diagnostic.h index 33bf381d61..062ba07d42 100644 --- a/prism/diagnostic.h +++ b/prism/diagnostic.h @@ -57,6 +57,7 @@ typedef enum { PM_ERR_CLASS_NAME, PM_ERR_CLASS_SUPERCLASS, PM_ERR_CLASS_TERM, + PM_ERR_CLASS_UNEXPECTED_END, PM_ERR_CONDITIONAL_ELSIF_PREDICATE, PM_ERR_CONDITIONAL_IF_PREDICATE, PM_ERR_CONDITIONAL_PREDICATE_TERM, diff --git a/prism/prism.c b/prism/prism.c index f1438b8132..5fee40351c 100644 --- a/prism/prism.c +++ b/prism/prism.c @@ -12304,7 +12304,11 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power) { } pm_parser_scope_push(parser, true); - accept2(parser, PM_TOKEN_NEWLINE, PM_TOKEN_SEMICOLON); + if (inheritance_operator.type != PM_TOKEN_NOT_PROVIDED) { + expect2(parser, PM_TOKEN_NEWLINE, PM_TOKEN_SEMICOLON, PM_ERR_CLASS_UNEXPECTED_END); + } else { + accept2(parser, PM_TOKEN_NEWLINE, PM_TOKEN_SEMICOLON); + } pm_node_t *statements = NULL; if (!match3(parser, PM_TOKEN_KEYWORD_RESCUE, PM_TOKEN_KEYWORD_ENSURE, PM_TOKEN_KEYWORD_END)) { |