Scripts - Also watch included files

This commit is contained in:
Emmanuel BENOîT 2017-12-28 13:02:48 +01:00
parent 915d797a77
commit e8b3188be9
3 changed files with 20 additions and 3 deletions

View file

@ -14,6 +14,7 @@ struct T_OpsParserOutput
{
opast::T_RootNode root;
T_KeyValueTable< T_String , opast::E_DataType > types;
ebcl::T_Set< T_FSPath > files{ ebcl::UseTag< ebcl::ArrayBacked< 16 > >( ) };
};
// The actual parser

View file

@ -88,10 +88,11 @@ void T_ScriptManager::loadScript( ) noexcept
// Load SRD data
T_SRDMemoryTarget srdOut;
srdOut.clearComments( true ).clearFlushToken( true );
const auto fn{ path_.makeRelative( Common::Project( ).basePath( ) ) };
try {
T_SRDTextReader srdReader{ srdOut };
T_FileInputStream fis{ input };
srdReader.read( path_.toString( ) , fis );
srdReader.read( fn.toString( ) , fis );
} catch ( X_StreamError const& e ) {
T_StringBuilder sb;
sb << "could not load: " << e.what( );
@ -115,11 +116,24 @@ void T_ScriptManager::loadScript( ) noexcept
}
// Parse the fuck
if ( !parser_.parse( path_ , srdOut.list( ) ) ) {
const bool parsed{ parser_.parse( path_ , srdOut.list( ) ) };
auto pOut{ parser_.result( ) };
const auto nf{ pOut->files.size( ) };
if ( nf ) {
watcher_.clear( );
for ( auto i = 0u ; i < nf ; i ++ ) {
watcher_.watch( pOut->files[ i ] );
}
}
if ( !parsed ) {
errors_.addAll( parser_.errors( ) );
DumpSRDErrors( "Parse errors" , errors_ );
return;
}
output_ = compiler_.compile( *parser_.result( ) );
output_ = compiler_.compile( *pOut );
// FIXME - errors from compiler
printf( "Script loaded & compiled\n" );
}

View file

@ -342,6 +342,7 @@ void T_ParserImpl_::main(
assert( file.isAbsolute( ) );
curFile = file.canonical( );
baseDir = file.parent( );
output->files.add( file );
parseTopLevel( input )
&& checkRequiredBlocks( input )
&& checkCalls( )
@ -1082,6 +1083,7 @@ void T_ParserImpl_::handleInclude(
// Parse included file
inclStack.add( curFile );
curFile = inclPath;
output->files.add( inclPath );
parseTLList( srdOut.list( ) );
curFile = inclStack.last( );
inclStack.removeLast( );