From 2eee11e4767705505864b7badcb3a5884af1ea31 Mon Sep 17 00:00:00 2001 From: Robert Bendun Date: Mon, 30 May 2022 00:02:50 +0200 Subject: [PATCH] Removed unused errors --- src/errors.cc | 6 ------ src/musique.hh | 27 ++++++--------------------- src/parser.cc | 11 +---------- 3 files changed, 7 insertions(+), 37 deletions(-) diff --git a/src/errors.cc b/src/errors.cc index 67426cc..fe31493 100644 --- a/src/errors.cc +++ b/src/errors.cc @@ -106,11 +106,8 @@ void assert(bool condition, std::string message, Location loc) std::ostream& operator<<(std::ostream& os, Error const& err) { std::string_view short_description = visit(Overloaded { - [](errors::Expected_Keyword const&) { return "Expected keyword"; }, [](errors::Failed_Numeric_Parsing const&) { return "Failed to parse a number"; }, - [](errors::Music_Literal_Used_As_Identifier const&) { return "Music literal in place of identifier"; }, [](errors::Not_Callable const&) { return "Value not callable"; }, - [](errors::Undefined_Identifier const&) { return "Undefined identifier"; }, [](errors::Undefined_Operator const&) { return "Undefined operator"; }, [](errors::Unexpected_Empty_Source const&) { return "Unexpected end of file"; }, [](errors::Unexpected_Keyword const&) { return "Unexpected keyword"; }, @@ -158,10 +155,7 @@ std::ostream& operator<<(std::ostream& os, Error const& err) } }, - [&os](errors::Expected_Keyword const&) { unimplemented(); }, - [&os](errors::Music_Literal_Used_As_Identifier const&) { unimplemented(); }, [&os](errors::Not_Callable const&) { unimplemented(); }, - [&os](errors::Undefined_Identifier const&) { unimplemented(); }, [&os](errors::Undefined_Operator const&) { unimplemented(); }, [&os](errors::Unexpected_Keyword const&) { unimplemented(); }, [&os](errors::Unexpected_Empty_Source const&) { unimplemented(); } diff --git a/src/musique.hh b/src/musique.hh index b7b1c44..6dc030e 100644 --- a/src/musique.hh +++ b/src/musique.hh @@ -59,16 +59,6 @@ namespace errors std::errc reason; }; - struct Undefined_Identifier - { - }; - - struct Expected_Keyword - { - std::string_view keyword; - std::string_view received_type = {}; - }; - struct Expected_Expression_Separator_Before { std::string_view what; @@ -89,17 +79,15 @@ namespace errors std::string_view type; }; - struct Music_Literal_Used_As_Identifier - { - std::string_view source; - - /// Why only identifier can be used? - std::string_view identifier_context; - }; - /// Collection of messages that are considered internal and should not be printed to the end user. namespace internal { + struct Expected_Keyword + { + std::string_view keyword; + std::string_view received_type = {}; + }; + struct Unexpected_Token { /// Type of the token @@ -115,11 +103,8 @@ namespace errors using Details = std::variant< Expected_Expression_Separator_Before, - Expected_Keyword, Failed_Numeric_Parsing, - Music_Literal_Used_As_Identifier, Not_Callable, - Undefined_Identifier, Undefined_Operator, Unexpected_Empty_Source, Unexpected_Keyword, diff --git a/src/parser.cc b/src/parser.cc index 971eb2b..6d24beb 100644 --- a/src/parser.cc +++ b/src/parser.cc @@ -68,16 +68,7 @@ Result Parser::parse_expression() Result Parser::parse_variable_declaration() { - if (!expect(Token::Type::Keyword, "var")) { - Error error; - errors::Expected_Keyword kw { .keyword = "var" }; - if (token_id >= tokens.size()) { - kw.received_type = type_name(peek()->type); - error.location = peek()->location; - } - error.details = std::move(kw); - return error; - } + assert(expect(Token::Type::Keyword, "var"), "Parser::parse_variable_declaration must be called only on expressions that starts with 'var'"); auto var = consume(); auto lvalue = Try(parse_many(*this, &Parser::parse_identifier, std::nullopt, At_Least::One));