diff --git a/alib2cli/src/parser/Parser.cpp b/alib2cli/src/parser/Parser.cpp index f66de7d4e9b6baeed2ea9d051d994a24da6d1f5a..b1ef6a61d8934755eee13fa36f62a7c26f06398d 100644 --- a/alib2cli/src/parser/Parser.cpp +++ b/alib2cli/src/parser/Parser.cpp @@ -48,7 +48,7 @@ std::unique_ptr < TypeOption > Parser::type_option ( ) { match ( cli::Lexer::TokenType::INTEGER, cli::Lexer::TokenType::IDENTIFIER ); return std::make_unique < TypeOption > ( std::move ( value ) ); } else { - throw exception::CommonException ( "Mismatched colon sign while expanding type_option rule." ); + throw exception::CommonException ( "Mismatched colon sign while expanding type_option rule. Token is " + Lexer::tokenTypeToString ( m_current.m_type ) + "." ); } } @@ -185,7 +185,7 @@ std::shared_ptr < Statement > Parser::common ( ) { match ( cli::Lexer::TokenType::RIGHT_BRACE ); return res; } else { - throw exception::CommonException ( "Mismatched set while expanding common rule." ); + throw exception::CommonException ( "Mismatched set while expanding common rule. Token is " + Lexer::tokenTypeToString ( m_current.m_type ) + "." ); } } @@ -206,7 +206,7 @@ std::shared_ptr < Statement > Parser::param ( ) { std::shared_ptr < Statement > castedParam = param ( ); return std::make_shared < CastStatement > ( std::move ( type ), castedParam, move ); } else { - throw exception::CommonException ( "Mismatched set while expanding param rule." ); + throw exception::CommonException ( "Mismatched set while expanding param rule. Token is " + Lexer::tokenTypeToString ( m_current.m_type ) + "." ); } } @@ -238,7 +238,7 @@ std::shared_ptr < Statement > Parser::statement ( ) { return std::make_shared < CastStatement > ( std::move ( type ), castedStatement, move ); } else { // TODO builtin statement type to get string type - throw exception::CommonException ( "Mismatched set while expanding param statement." ); + throw exception::CommonException ( "Mismatched set while expanding param statement. Token is " + Lexer::tokenTypeToString ( m_current.m_type ) + "." ); } } @@ -305,7 +305,7 @@ std::pair < bool, bool > Parser::introspect_cast_from_to ( ) { match_nonreserved_kw ( "to" ); to = true; } else { - throw exception::CommonException ( "Mismatched set while expanding param introspect_cast_from_to." ); + throw exception::CommonException ( "Mismatched set while expanding param introspect_cast_from_to. Token is " + Lexer::tokenTypeToString ( m_current.m_type ) + "." ); } } return std::make_pair ( from, to ); @@ -344,7 +344,7 @@ std::unique_ptr < Command > Parser::introspect_command ( ) { std::unique_ptr < cli::Arg > param = optional_arg ( ); return std::make_unique < BindingsIntrospectionCommand > ( std::move ( param ) ); } else { - throw exception::CommonException ( "Mismatched set while expanding param introspect_command." ); + throw exception::CommonException ( "Mismatched set while expanding param introspect_command. Token is " + Lexer::tokenTypeToString ( m_current.m_type ) + "." ); } } @@ -406,7 +406,7 @@ std::unique_ptr < Command > Parser::parse ( ) { } else if ( check ( cli::Lexer::TokenType::EOT ) ) { return std::make_unique < QuitCommand > ( nullptr ); } else { - throw exception::CommonException ( "Mismatched set while expanding parse rule." ); + throw exception::CommonException ( "Mismatched set while expanding parse rule. Token is " + Lexer::tokenTypeToString ( m_current.m_type ) + "." ); } } diff --git a/alib2cli/src/parser/Parser.h b/alib2cli/src/parser/Parser.h index 92e1631ea75ee863ff15c190a212f529939b3129..aae76ffdbfa1b908e2aed4ad51d25d7d38e234ca 100644 --- a/alib2cli/src/parser/Parser.h +++ b/alib2cli/src/parser/Parser.h @@ -45,21 +45,21 @@ public: template < class Token, class ... Tokens > bool match ( Token token, Tokens ... tokens ) { if ( ! check ( token, tokens ... ) ) - throw exception::CommonException ( std::string ( "Mismatched token while matching a token " ) + Lexer::tokenTypeToString ( token ) + "." ); + throw exception::CommonException ( std::string ( "Mismatched token while matching a token " ) + ( Lexer::tokenTypeToString ( token ) + ... + ( ", " + Lexer::tokenTypeToString ( tokens ) ) ) + ". Actual was " + Lexer::tokenTypeToString ( m_current.m_type ) + "." ); m_current = m_lexer.nextToken ( false ); return true; } bool match_nonreserved_kw ( const std::string & kw ) { if ( ! check_nonreserved_kw ( kw ) ) - throw exception::CommonException ( "Mismatched token while matching a token." ); + throw exception::CommonException ( "Mismatched token while matching a non reseved keyword: " + kw + "." ); m_current = m_lexer.nextToken ( false ); return true; } std::string matchIdentifier ( ) { if ( ! check ( Lexer::TokenType::IDENTIFIER ) ) - throw exception::CommonException ( "Mismatched token while matching a token." ); + throw exception::CommonException ( "Mismatched token while matching an identifier." ); std::string res = m_current.m_value; m_current = m_lexer.nextToken ( false ); return res; @@ -67,7 +67,7 @@ public: std::string matchString ( ) { if ( ! check ( Lexer::TokenType::STRING ) ) - throw exception::CommonException ( "Mismatched token while matching a token." ); + throw exception::CommonException ( "Mismatched token while matching a string." ); std::string res = m_current.m_value; m_current = m_lexer.nextToken ( false ); return res; @@ -75,7 +75,7 @@ public: int matchInteger ( ) { if ( ! check ( Lexer::TokenType::INTEGER ) ) - throw exception::CommonException ( "Mismatched token while matching a token." ); + throw exception::CommonException ( "Mismatched token while matching an integer." ); int res = ext::from_string < int > ( m_current.m_value ); m_current = m_lexer.nextToken ( false ); return res;