Skip to content

Commit

Permalink
Revert D67603915: Make parser::report_expected accept format string
Browse files Browse the repository at this point in the history
Differential Revision:
D67603915

Original commit changeset: 51c410893390

Original Phabricator Diff: D67603915

fbshipit-source-id: 88d0b20c747925a81291cbbfbb3989ca0bd45daf
  • Loading branch information
Wenbin Lin authored and facebook-github-bot committed Dec 26, 2024
1 parent 908e0ad commit 5eb570e
Showing 1 changed file with 39 additions and 30 deletions.
69 changes: 39 additions & 30 deletions thrift/compiler/whisker/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -536,15 +536,12 @@ class parser {
throw parse_error();
}

template <typename... T>
[[noreturn]] void report_expected(
const parser_scan_window& scan,
fmt::format_string<T...> msg,
T&&... args) {
const parser_scan_window& scan, std::string_view expected) {
report_fatal_error(
scan,
"expected {} but found {}",
fmt::format(msg, std::forward<T>(args)...),
expected,
to_string(scan.peek().kind));
}

Expand Down Expand Up @@ -800,7 +797,7 @@ class parser {
report_expected(scan, "comment text");
}
if (scan.peek().kind != tok::close) {
report_expected(scan, "{} to close comment", tok::close);
report_expected(scan, fmt::format("{} to close comment", tok::close));
}
scan.advance();

Expand Down Expand Up @@ -896,7 +893,8 @@ class parser {
}
ast::expression lookup = std::move(expression).consume_and_advance(&scan);
if (!try_consume_token(&scan, tok::close)) {
report_expected(scan, "{} to close interpolation", tok::close);
report_expected(
scan, fmt::format("{} to close interpolation", tok::close));
}
return {
ast::interpolation{
Expand Down Expand Up @@ -967,7 +965,8 @@ class parser {
ast::variable_lookup open =
std::move(lookup_at_open).consume_and_advance(&scan);
if (!try_consume_token(&scan, tok::close)) {
report_expected(scan, "{} to open section-block", tok::close);
report_expected(
scan, fmt::format("{} to open section-block", tok::close));
}
scan = scan.make_fresh();

Expand All @@ -976,24 +975,27 @@ class parser {
if (!try_consume_token(&scan, tok::open)) {
report_expected(
scan,
"{} to close section-block '{}'",
tok::open,
open.chain_string());
fmt::format(
"{} to close section-block '{}'",
tok::open,
open.chain_string()));
}
if (!try_consume_token(&scan, tok::slash)) {
report_expected(
scan,
"{} to close section-block '{}'",
tok::slash,
open.chain_string());
fmt::format(
"{} to close section-block '{}'",
tok::slash,
open.chain_string()));
}

parse_result lookup_at_close = parse_variable_lookup(scan.make_fresh());
if (!lookup_at_close.has_value()) {
report_expected(
scan,
"variable-lookup to close section-block '{}'",
open.chain_string());
fmt::format(
"variable-lookup to close section-block '{}'",
open.chain_string()));
}
ast::variable_lookup close =
std::move(lookup_at_close).consume_and_advance(&scan);
Expand Down Expand Up @@ -1175,7 +1177,8 @@ class parser {

if (!try_consume_token(&scan, tok::r_paren)) {
report_expected(
scan, "{} to close function '{}'", tok::r_paren, func.name());
scan,
fmt::format("{} to close function '{}'", tok::r_paren, func.name()));
}

return {
Expand Down Expand Up @@ -1207,7 +1210,7 @@ class parser {
scan.advance();

if (!try_consume_token(&scan, tok::eq)) {
report_expected(scan, "{} in let-statement", tok::eq);
report_expected(scan, fmt::format("{} in let-statement", tok::eq));
}

scan = scan.make_fresh();
Expand All @@ -1218,7 +1221,8 @@ class parser {
ast::expression value = std::move(expression).consume_and_advance(&scan);

if (!try_consume_token(&scan, tok::close)) {
report_expected(scan, "{} to close let-statement", tok::close);
report_expected(
scan, fmt::format("{} to close let-statement", tok::close));
}

return {
Expand Down Expand Up @@ -1259,7 +1263,8 @@ class parser {
}

if (!try_consume_token(&scan, tok::close)) {
report_expected(scan, "{} to close pragma-statement", tok::close);
report_expected(
scan, fmt::format("{} to close pragma-statement", tok::close));
}

return {
Expand Down Expand Up @@ -1295,11 +1300,11 @@ class parser {

parse_result condition = parse_expression(scan);
if (!condition.has_value()) {
report_expected(scan, "expression to open if-block");
report_expected(scan, fmt::format("expression to open if-block"));
}
ast::expression open = std::move(condition).consume_and_advance(&scan);
if (!try_consume_token(&scan, tok::close)) {
report_expected(scan, "{} to open if-block", tok::close);
report_expected(scan, fmt::format("{} to open if-block", tok::close));
}
scan = scan.make_fresh();

Expand Down Expand Up @@ -1331,7 +1336,8 @@ class parser {
const auto expect_on_close = [&](tok kind) {
if (!try_consume_token(&scan, kind)) {
report_expected(
scan, "{} to close if-block '{}'", kind, open.to_string());
scan,
fmt::format("{} to close if-block '{}'", kind, open.to_string()));
}
};

Expand All @@ -1341,7 +1347,8 @@ class parser {
condition = parse_expression(scan.make_fresh());
if (!condition.has_value()) {
report_expected(
scan, "expression to close if-block '{}'", open.to_string());
scan,
fmt::format("expression to close if-block '{}'", open.to_string()));
}
ast::expression close = {std::move(condition).consume_and_advance(&scan)};
if (close != open) {
Expand Down Expand Up @@ -1381,11 +1388,11 @@ class parser {

parse_result value = parse_expression(scan);
if (!value.has_value()) {
report_expected(scan, "expression to open with-block");
report_expected(scan, fmt::format("expression to open with-block"));
}
ast::expression expr = std::move(value).consume_and_advance(&scan);
if (!try_consume_token(&scan, tok::close)) {
report_expected(scan, "{} to open with-block", tok::close);
report_expected(scan, fmt::format("{} to open with-block", tok::close));
}
scan = scan.make_fresh();

Expand All @@ -1394,7 +1401,8 @@ class parser {
const auto expect_on_close = [&](tok kind) {
if (!try_consume_token(&scan, kind)) {
report_expected(
scan, "{} to close with-block '{}'", kind, expr.to_string());
scan,
fmt::format("{} to close with-block '{}'", kind, expr.to_string()));
}
};

Expand Down Expand Up @@ -1436,9 +1444,10 @@ class parser {
if (!try_consume_token(&scan, tok::close)) {
report_expected(
scan,
"{} to close partial-apply '{}'",
tok::close,
lookup.as_string());
fmt::format(
"{} to close partial-apply '{}'",
tok::close,
lookup.as_string()));
}

return {
Expand Down

0 comments on commit 5eb570e

Please sign in to comment.