|
|
|
@ -47,47 +47,68 @@ namespace SIM_LIBRARY_SPICE_PARSER |
|
|
|
template <> struct librarySelector<modelUnit> : std::true_type {}; |
|
|
|
template <> struct librarySelector<modelName> : std::true_type {}; |
|
|
|
|
|
|
|
template <> struct librarySelector<dotInclude> : std::true_type {}; |
|
|
|
template <> struct librarySelector<dotIncludePathWithoutQuotes> : std::true_type {}; |
|
|
|
template <> struct librarySelector<dotIncludePathWithoutApostrophes> : std::true_type {}; |
|
|
|
template <> struct librarySelector<dotIncludePath> : std::true_type {}; |
|
|
|
|
|
|
|
// For debugging.
|
|
|
|
template <> struct librarySelector<unknownLine> : std::true_type {}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
void SPICE_LIBRARY_PARSER::ReadFile( const std::string& aFilePath ) |
|
|
|
void SPICE_LIBRARY_PARSER::readElement( const std::string &aFilePath ) |
|
|
|
{ |
|
|
|
try |
|
|
|
{ |
|
|
|
tao::pegtl::file_input in( aFilePath ); |
|
|
|
auto root = tao::pegtl::parse_tree::parse<SIM_LIBRARY_SPICE_PARSER::libraryGrammar, |
|
|
|
SIM_LIBRARY_SPICE_PARSER::librarySelector, |
|
|
|
tao::pegtl::nothing, |
|
|
|
SIM_LIBRARY_SPICE_PARSER::control>( in ); |
|
|
|
tao::pegtl::file_input in( aFilePath ); |
|
|
|
std::unique_ptr<tao::pegtl::parse_tree::node> root = |
|
|
|
tao::pegtl::parse_tree::parse<SIM_LIBRARY_SPICE_PARSER::libraryGrammar, |
|
|
|
SIM_LIBRARY_SPICE_PARSER::librarySelector, |
|
|
|
tao::pegtl::nothing, |
|
|
|
SIM_LIBRARY_SPICE_PARSER::control>( in ); |
|
|
|
|
|
|
|
m_library.m_models.clear(); |
|
|
|
m_library.m_modelNames.clear(); |
|
|
|
|
|
|
|
for( const auto& node : root->children ) |
|
|
|
for( const auto& node : root->children ) |
|
|
|
{ |
|
|
|
if( node->is_type<SIM_LIBRARY_SPICE_PARSER::modelUnit>() ) |
|
|
|
{ |
|
|
|
if( node->is_type<SIM_LIBRARY_SPICE_PARSER::modelUnit>() ) |
|
|
|
try |
|
|
|
{ |
|
|
|
try |
|
|
|
{ |
|
|
|
m_library.m_models.push_back( SIM_MODEL_SPICE::Create( m_library, node->string() ) ); |
|
|
|
m_library.m_modelNames.emplace_back( node->children.at( 0 )->string() ); |
|
|
|
} |
|
|
|
catch( const IO_ERROR& e ) |
|
|
|
{ |
|
|
|
DisplayErrorMessage( nullptr, e.What() ); |
|
|
|
} |
|
|
|
m_library.m_models.push_back( SIM_MODEL_SPICE::Create( m_library, node->string() ) ); |
|
|
|
m_library.m_modelNames.emplace_back( node->children.at( 0 )->string() ); |
|
|
|
} |
|
|
|
else if( node->is_type<SIM_LIBRARY_SPICE_PARSER::unknownLine>() ) |
|
|
|
catch( const IO_ERROR& e ) |
|
|
|
{ |
|
|
|
// Do nothing.
|
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
wxFAIL_MSG( "Unhandled parse tree node" ); |
|
|
|
DisplayErrorMessage( nullptr, e.What() ); |
|
|
|
} |
|
|
|
} |
|
|
|
else if( node->is_type<SIM_LIBRARY_SPICE_PARSER::dotInclude>() ) |
|
|
|
{ |
|
|
|
std::string lib = node->children.at( 0 )->string(); |
|
|
|
|
|
|
|
if( m_library.m_pathResolver ) |
|
|
|
lib = ( *m_library.m_pathResolver )( lib, aFilePath ); |
|
|
|
|
|
|
|
readElement( lib ); |
|
|
|
} |
|
|
|
else if( node->is_type<SIM_LIBRARY_SPICE_PARSER::unknownLine>() ) |
|
|
|
{ |
|
|
|
// Do nothing.
|
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
wxFAIL_MSG( "Unhandled parse tree node" ); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void SPICE_LIBRARY_PARSER::ReadFile( const std::string& aFilePath ) |
|
|
|
{ |
|
|
|
m_library.m_models.clear(); |
|
|
|
m_library.m_modelNames.clear(); |
|
|
|
|
|
|
|
try |
|
|
|
{ |
|
|
|
readElement( aFilePath ); |
|
|
|
} |
|
|
|
catch( const std::filesystem::filesystem_error& e ) |
|
|
|
{ |
|
|
|
|