From 5c53bb9e9feaf3e0579e6fbbf2650f116e3a214d Mon Sep 17 00:00:00 2001 From: Robert Bendun Date: Sun, 21 Aug 2022 20:39:35 +0200 Subject: [PATCH] Nicer undefiend operator message --- src/errors.cc | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/errors.cc b/src/errors.cc index 35ae955..966e6af 100644 --- a/src/errors.cc +++ b/src/errors.cc @@ -317,6 +317,27 @@ std::ostream& operator<<(std::ostream& os, Error const& err) os << '\n'; print_error_line(loc); + + static constexpr auto Operators = std::array { + "and", "or", + "==", "!=", "<", ">", "<=", ">=", + "+", "+=", "-", "-=", "*", "*=", "/", "/=", + "&", "&=", "." + }; + + os << pretty::begin_comment; + os << "Operators that look familiar to one above:\n"; + os << " "; + + for (auto op : Operators) { + for (auto c : err.op) { + if (std::string_view(op).find(c) != std::string_view::npos) { + os << op << ' '; + break; + } + } + } + os << '\n' << pretty::end; }, [&](errors::Unexpected_Keyword const&) { unimplemented(); }, }, err.details);