Skip to content

Commit

Permalink
Improve parser error messages for empty arguments and captures in par…
Browse files Browse the repository at this point in the history
…tial block

Summary: self-explanatory. Based on createdbysk's feedback :)

Reviewed By: rmakheja

Differential Revision: D68966636

fbshipit-source-id: 56244d0f2fa5f658c84a427d13861581d723f96c
  • Loading branch information
praihan authored and facebook-github-bot committed Jan 31, 2025
1 parent 4ac9dc1 commit 536d373
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
12 changes: 8 additions & 4 deletions third-party/thrift/src/thrift/compiler/whisker/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1615,8 +1615,10 @@ class parser {
if (try_consume_token(&scan, tok::pipe)) {
const token* first_argument = try_consume_token(&scan, tok::identifier);
if (first_argument == nullptr) {
report_fatal_expected(
scan, "at least one argument in partial-block '{}'", id.name);
report_fatal_error(
scan,
"expected at least one argument in partial-block '{}' but found none",
id.name);
}
arguments.insert(make_identifier(*first_argument));
while (const token* argument =
Expand Down Expand Up @@ -1656,8 +1658,10 @@ class parser {

const token* first_capture = try_consume_token(&scan, tok::identifier);
if (first_capture == nullptr) {
report_fatal_expected(
scan, "at least one capture in partial-block '{}'", id.name);
report_fatal_error(
scan,
"expected at least one capture in partial-block '{}' but found none",
id.name);
}
insert_capture(make_identifier(*first_capture));
while (const token* capture = try_consume_token(&scan, tok::identifier)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,7 @@ TEST_F(ParserTest, partial_block_empty_arguments) {
diagnostics,
testing::ElementsAre(diagnostic(
diagnostic_level::error,
"expected at least one argument in partial-block 'foo' but found `|`",
"expected at least one argument in partial-block 'foo' but found none",
path_to_file(1),
1)));
}
Expand All @@ -1110,7 +1110,7 @@ TEST_F(ParserTest, partial_block_empty_captures) {
diagnostics,
testing::ElementsAre(diagnostic(
diagnostic_level::error,
"expected at least one capture in partial-block 'foo' but found `|`",
"expected at least one capture in partial-block 'foo' but found none",
path_to_file(1),
1)));
}
Expand Down

0 comments on commit 536d373

Please sign in to comment.