Skip to content

Commit

Permalink
[ruby/prism] Update error message for invalid % at EOF
Browse files Browse the repository at this point in the history
  • Loading branch information
kddnewton authored and matzbot committed May 16, 2024
1 parent 7a4b9d1 commit 910bb49
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions prism/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ errors:
- INVALID_NUMBER_UNDERSCORE_INNER
- INVALID_NUMBER_UNDERSCORE_TRAILING
- INVALID_PERCENT
- INVALID_PERCENT_EOF
- INVALID_PRINTABLE_CHARACTER
- INVALID_RETRY_AFTER_ELSE
- INVALID_RETRY_AFTER_ENSURE
Expand Down
2 changes: 1 addition & 1 deletion prism/prism.c
Original file line number Diff line number Diff line change
Expand Up @@ -11356,7 +11356,7 @@ parser_lex(pm_parser_t *parser) {
// operator because we don't want to move into the string
// lex mode unnecessarily.
if ((lex_state_beg_p(parser) || lex_state_arg_p(parser)) && (parser->current.end >= parser->end)) {
pm_parser_err_current(parser, PM_ERR_INVALID_PERCENT);
pm_parser_err_current(parser, PM_ERR_INVALID_PERCENT_EOF);
LEX(PM_TOKEN_PERCENT);
}

Expand Down
1 change: 1 addition & 0 deletions prism/templates/src/diagnostic.c.erb
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ static const pm_diagnostic_data_t diagnostic_messages[PM_DIAGNOSTIC_ID_MAX] = {
[PM_ERR_INVALID_MULTIBYTE_ESCAPE] = { "invalid multibyte escape: /%.*s/", PM_ERROR_LEVEL_SYNTAX },
[PM_ERR_INVALID_PRINTABLE_CHARACTER] = { "invalid character `%c`", PM_ERROR_LEVEL_SYNTAX },
[PM_ERR_INVALID_PERCENT] = { "unknown type of %string", PM_ERROR_LEVEL_SYNTAX },
[PM_ERR_INVALID_PERCENT_EOF] = { "unterminated quoted string meets end of file", PM_ERROR_LEVEL_SYNTAX },
[PM_ERR_INVALID_RETRY_AFTER_ELSE] = { "Invalid retry after else", PM_ERROR_LEVEL_SYNTAX },
[PM_ERR_INVALID_RETRY_AFTER_ENSURE] = { "Invalid retry after ensure", PM_ERROR_LEVEL_SYNTAX },
[PM_ERR_INVALID_RETRY_WITHOUT_RESCUE] = { "Invalid retry without rescue", PM_ERROR_LEVEL_SYNTAX },
Expand Down
2 changes: 1 addition & 1 deletion test/prism/errors_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def test_missing_terminator_in_parentheses

def test_unterminated_argument_expression
assert_errors expression('a %'), 'a %', [
["unknown type of %string", 2..3],
["unterminated quoted string meets end of file", 2..3],
["unexpected end-of-input; expected an expression after the operator", 3..3],
["unexpected end-of-input, assuming it is closing the parent top level context", 3..3]
]
Expand Down

0 comments on commit 910bb49

Please sign in to comment.