#include "externals.hh" #include "globals.hh" #include "opcomp.hh" #include "ops.hh" #include #include #include /*= T_ScriptManager ============================================================*/ T_ScriptManager::T_ScriptManager( ) noexcept : watcher_( Globals::Watcher( ) , [this](){ loadScript( ); } ) , parser_( ) , compiler_( ) { watcher_.watch( T_String::Pooled( "demo.srd" ) ); loadScript( ); } void T_ScriptManager::loadScript( ) noexcept { output_.clear( ); errors_.clear( ); using namespace ebcl; const T_String inputName( T_String::Pooled( "demo.srd" ) ); T_File input( inputName , E_FileMode::READ_ONLY ); try { input.open( ); } catch ( X_StreamError const& e ) { T_StringBuilder sb; sb << "could not open: " << e.what( ); if ( e.code( ) == ebcl::E_StreamError::SYSTEM_ERROR ) { sb << " (error code " << e.systemError( ) << ")"; } errors_.addNew( std::move( sb ) , T_SRDLocation{ inputName , 1 , 1 } ); return; } // Load SRD data T_SRDMemoryTarget srdOut; srdOut.clearComments( true ).clearFlushToken( true ); try { T_SRDTextReader srdReader{ srdOut }; T_FileInputStream fis{ input }; srdReader.read( inputName , fis ); } catch ( X_StreamError const& e ) { T_StringBuilder sb; sb << "could not load: " << e.what( ); if ( e.code( ) == ebcl::E_StreamError::SYSTEM_ERROR ) { sb << " (error code " << e.systemError( ) << ")"; } errors_.addNew( std::move( sb ) , T_SRDLocation{ inputName , 1 , 1 } ); return; } catch ( X_SRDErrors const& e ) { T_StringBuilder sb; const auto nErrors( e.errors.size( ) ); errors_.ensureCapacity( nErrors ); for ( auto i = 0u ; i < nErrors ; i ++ ) { errors_.add( e.errors[ i ] ); } return; } // Parse the fuck if ( !parser_.parse( srdOut.list( ) ) ) { errors_.addAll( parser_.errors( ) ); return; } output_ = compiler_.compile( *parser_.result( ) ); // FIXME - errors from compiler }