From 555105feb89c86c1634e9fa45a3a447517600c68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Thu, 16 Nov 2017 08:34:13 +0100 Subject: [PATCH] Parser/compiler - Display errors on the console --- demo.cc | 32 -------------------------------- opmgr.cc | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 32 deletions(-) diff --git a/demo.cc b/demo.cc index cb6dc82..e808411 100644 --- a/demo.cc +++ b/demo.cc @@ -65,38 +65,6 @@ void T_Demo::handleWheel( { } -namespace { - -/*============================================================================*/ - - -void PrintStreamError( - char const* const prefix , - T_String const& name , - ebcl::X_StreamError const& error ) -{ - T_StringBuilder sb; - sb << prefix << " '" << name << "': " << error.what( ); - if ( error.code( ) == ebcl::E_StreamError::SYSTEM_ERROR ) { - sb << " (error code " << error.systemError( ) << ")"; - } - sb << '\n' << '\0'; - fprintf( stderr , "%s" , sb.data( ) ); -} - -void WriteSRDError( - T_StringBuilder& sb , - ebcl::T_SRDError const& error ) -{ - sb << error.location( ) << " - " << error.error( ) << "\n"; -} - - -/*============================================================================*/ - -} // namespace - - bool T_Demo::runInit( ops::T_OpProgram& p ) diff --git a/opmgr.cc b/opmgr.cc index 9f3fab6..36326d8 100644 --- a/opmgr.cc +++ b/opmgr.cc @@ -8,6 +8,35 @@ #include +/*============================================================================*/ + +namespace { + +void WriteSRDError( + T_StringBuilder& sb , + ebcl::T_SRDError const& error ) +{ + sb << error.location( ) << " - " << error.error( ) << "\n"; +} + +void DumpSRDErrors( + T_String const& header , + T_Array< ebcl::T_SRDError > const& errors ) +{ + T_StringBuilder sb; + sb << "=============================================================\n" + << header << '\n' + << "-------------------------------------------------------------\n"; + for ( auto& error : errors ) { + WriteSRDError( sb , error ); + } + sb << "=============================================================\n" << '\0'; + printf( "%s" , sb.data( ) ); +} + +} // namespace + + /*= T_ScriptManager ============================================================*/ T_ScriptManager::T_ScriptManager( ) noexcept @@ -38,6 +67,7 @@ void T_ScriptManager::loadScript( ) noexcept } errors_.addNew( std::move( sb ) , T_SRDLocation{ inputName , 1 , 1 } ); + DumpSRDErrors( "Script not found" , errors_ ); return; } @@ -56,6 +86,7 @@ void T_ScriptManager::loadScript( ) noexcept } errors_.addNew( std::move( sb ) , T_SRDLocation{ inputName , 1 , 1 } ); + DumpSRDErrors( "Script not loaded" , errors_ ); return; } catch ( X_SRDErrors const& e ) { @@ -65,12 +96,14 @@ void T_ScriptManager::loadScript( ) noexcept for ( auto i = 0u ; i < nErrors ; i ++ ) { errors_.add( e.errors[ i ] ); } + DumpSRDErrors( "Script not loaded" , errors_ ); return; } // Parse the fuck if ( !parser_.parse( srdOut.list( ) ) ) { errors_.addAll( parser_.errors( ) ); + DumpSRDErrors( "Parse errors" , errors_ ); return; } output_ = compiler_.compile( *parser_.result( ) );