Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error messages for unterminated ( and { #3271

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/prism.c
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,13 @@ pm_parser_err_token(pm_parser_t *parser, const pm_token_t *token, pm_diagnostic_
* given token and a format string.
*/
#define PM_PARSER_ERR_TOKEN_FORMAT(parser, token, diag_id, ...) \
PM_PARSER_ERR_FORMAT(parser, (token).start, (token).end, diag_id, __VA_ARGS__)
do { \
pm_token_t errtok = (token); \
if (errtok.type == PM_TOKEN_EOF && errtok.start > parser->start && (*(errtok.start - 1) == '\n')) { \
errtok.start = errtok.start - 1; \
} \
PM_PARSER_ERR_FORMAT(parser, (token).start, (token).end, diag_id, __VA_ARGS__); \
} while(0)

/**
* Append an error to the list of errors on the parser using the location of the
Expand Down
4 changes: 4 additions & 0 deletions test/prism/errors/unterminated_block.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
foo {
^ unexpected end-of-input, assuming it is closing the parent top level context
^ expected a block beginning with `{` to end with `}`

3 changes: 3 additions & 0 deletions test/prism/errors/unterminated_method_parameters.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
foo(
^ unexpected end-of-input; expected a `)` to close the arguments

Loading