From 5eb570e000c432335cf3582885eb88177df7a0f2 Mon Sep 17 00:00:00 2001 From: Wenbin Lin Date: Thu, 26 Dec 2024 14:49:10 -0800 Subject: [PATCH] Revert D67603915: Make parser::report_expected accept format string Differential Revision: D67603915 Original commit changeset: 51c410893390 Original Phabricator Diff: D67603915 fbshipit-source-id: 88d0b20c747925a81291cbbfbb3989ca0bd45daf --- thrift/compiler/whisker/parser.cc | 69 +++++++++++++++++-------------- 1 file changed, 39 insertions(+), 30 deletions(-) diff --git a/thrift/compiler/whisker/parser.cc b/thrift/compiler/whisker/parser.cc index be2b14aec64..93dd0656ce8 100644 --- a/thrift/compiler/whisker/parser.cc +++ b/thrift/compiler/whisker/parser.cc @@ -536,15 +536,12 @@ class parser { throw parse_error(); } - template [[noreturn]] void report_expected( - const parser_scan_window& scan, - fmt::format_string msg, - T&&... args) { + const parser_scan_window& scan, std::string_view expected) { report_fatal_error( scan, "expected {} but found {}", - fmt::format(msg, std::forward(args)...), + expected, to_string(scan.peek().kind)); } @@ -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(); @@ -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{ @@ -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(); @@ -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); @@ -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 { @@ -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(); @@ -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 { @@ -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 { @@ -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(); @@ -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())); } }; @@ -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) { @@ -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(); @@ -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())); } }; @@ -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 {