35#include <pegtl/contrib/parse_tree.hpp>
61static SIM_MODEL::TYPE
getFallbackType(
const wxString& aToken,
const wxString& aLine )
63 for( SIM_MODEL::TYPE candidate : SIM_MODEL::TYPE_ITERATOR() )
67 if( candidate_type.IsEmpty() )
76 if( candidate_type.StartsWith( wxS(
"VDMOS" ) ) && aToken == wxS(
"VDMOS" ) )
78 if( candidate_type.EndsWith( wxS(
"PCHAN" ) ) )
80 if( aLine.Upper().Contains( wxS(
"PCHAN" ) ) )
85 if( !aLine.Upper().Contains( wxS(
"PCHAN" ) ) )
89 else if( aToken.StartsWith( candidate_type ) )
95 return SIM_MODEL::TYPE::NONE;
103 wxArrayString lines = wxSplit(
SafeReadFile( aFilePath, wxS(
"r" ) ),
'\n' );
105 for(
const wxString& line : lines )
107 wxStringTokenizer tokenizer( line, wxS(
" ()\t\r\n" ), wxTOKEN_STRTOK );
108 wxString
token = tokenizer.GetNextToken().Lower();
110 if(
token == wxS(
".model" ) )
112 wxString
name = tokenizer.GetNextToken();
113 wxString typeToken = tokenizer.GetNextToken().Upper();
116 m_library.
m_models.push_back( std::make_unique<SIM_MODEL_SPICE_FALLBACK>( type ) );
119 else if(
token == wxS(
".inc" ) )
121 wxString lib = tokenizer.GetNextToken();
141 tao::pegtl::string_input<> in(
SafeReadFile( aFilePath, wxS(
"r" ) ).ToStdString(),
142 aFilePath.ToStdString() );
148 for(
const auto& node : root->children )
152 std::string model = node->string();
153 std::string
modelName = node->children.at( 0 )->string();
167 wxString lib = node->children.at( 0 )->string();
187 wxFAIL_MSG(
"Unhandled parse tree node" );
195 catch(
const tao::pegtl::parse_error& e )
211 if( !
m_forceFullParse && aFilePath.Contains( wxS(
"/LTspiceXVII/lib/cmp/standard" ) ) )
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
A pure virtual class used to derive REPORTER objects from.
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
std::function< wxString(const wxString &, const wxString &)> * m_pathResolver
std::vector< std::string > m_modelNames
std::vector< std::unique_ptr< SIM_MODEL > > m_models
static std::unique_ptr< SIM_MODEL_SPICE > Create(const SIM_LIBRARY_SPICE &aLibrary, const std::string &aSpiceCode)
static SPICE_INFO SpiceInfo(TYPE aType)
void parseFile(const wxString &aFilePath, REPORTER &aReporter)
virtual void ReadFile(const wxString &aFilePath, REPORTER *aReporter)
SIM_LIBRARY_SPICE & m_library
void readFallbacks(const wxString &aFilePath, REPORTER &aReporter)
This file is part of the common library.
must_if< error >::control< Rule > control
wxString SafeReadFile(const wxString &aFilePath, const wxString &aReadType)
Nominally opens a file and reads it into a string.
static SIM_MODEL::TYPE getFallbackType(const wxString &aToken, const wxString &aLine)