Fix Spice subcircuit parsing

When parsing a subcircuit, the parser was incorrectly identifying
parameters of models inside it as belonging to the subcircuit.
This commit is contained in:
Mikolaj Wielgus 2022-08-30 11:58:20 +02:00
parent 767be75cac
commit 2bcfe5e42c
2 changed files with 6 additions and 10 deletions

View File

@ -37,7 +37,7 @@ namespace SIM_MODEL_SUBCKT_SPICE_PARSER
template <> struct spiceUnitSelector<dotSubckt> : std::true_type {}; template <> struct spiceUnitSelector<dotSubckt> : std::true_type {};
template <> struct spiceUnitSelector<modelName> : std::true_type {}; template <> struct spiceUnitSelector<modelName> : std::true_type {};
template <> struct spiceUnitSelector<dotSubcktPinName> : std::true_type {}; template <> struct spiceUnitSelector<dotSubcktPinName> : std::true_type {};
template <> struct spiceUnitSelector<paramValuePairs> : std::true_type {}; template <> struct spiceUnitSelector<dotSubcktParams> : std::true_type {};
template <> struct spiceUnitSelector<param> : std::true_type {}; template <> struct spiceUnitSelector<param> : std::true_type {};
template <> struct spiceUnitSelector<number<SIM_VALUE::TYPE_INT, NOTATION::SPICE>> template <> struct spiceUnitSelector<number<SIM_VALUE::TYPE_INT, NOTATION::SPICE>>
: std::true_type {}; : std::true_type {};
@ -72,8 +72,6 @@ void SIM_MODEL_SUBCKT::ReadSpiceCode( const wxString& aSpiceCode )
{ {
if( node->is_type<SIM_MODEL_SUBCKT_SPICE_PARSER::dotSubckt>() ) if( node->is_type<SIM_MODEL_SUBCKT_SPICE_PARSER::dotSubckt>() )
{ {
bool hadParamValuePairs = false;
for( const auto& subnode : node->children ) for( const auto& subnode : node->children )
{ {
if( subnode->is_type<SIM_MODEL_SUBCKT_SPICE_PARSER::modelName>() ) if( subnode->is_type<SIM_MODEL_SUBCKT_SPICE_PARSER::modelName>() )
@ -83,8 +81,7 @@ void SIM_MODEL_SUBCKT::ReadSpiceCode( const wxString& aSpiceCode )
{ {
AddPin( { subnode->string(), wxString::FromCDouble( GetPinCount() + 1 ) } ); AddPin( { subnode->string(), wxString::FromCDouble( GetPinCount() + 1 ) } );
} }
else if( !hadParamValuePairs else if( subnode->is_type<SIM_MODEL_SUBCKT_SPICE_PARSER::dotSubcktParams>() )
&& subnode->is_type<SIM_MODEL_SUBCKT_SPICE_PARSER::paramValuePairs>() )
{ {
for( const auto& subsubnode : subnode->children ) for( const auto& subsubnode : subnode->children )
{ {
@ -102,8 +99,6 @@ void SIM_MODEL_SUBCKT::ReadSpiceCode( const wxString& aSpiceCode )
wxFAIL_MSG( "Unhandled parse tree subsubnode" ); wxFAIL_MSG( "Unhandled parse tree subsubnode" );
} }
} }
hadParamValuePairs = true;
} }
else if( subnode->is_type< else if( subnode->is_type<
SIM_MODEL_SUBCKT_SPICE_PARSER::number<SIM_VALUE::TYPE_INT, SIM_MODEL_SUBCKT_SPICE_PARSER::number<SIM_VALUE::TYPE_INT,

View File

@ -159,6 +159,9 @@ namespace SPICE_GRAMMAR
struct dotSubcktPinSequence : seq<opt<dotSubcktPinName, struct dotSubcktPinSequence : seq<opt<dotSubcktPinName,
star<sep, star<sep,
dotSubcktPinName>>> {}; dotSubcktPinName>>> {};
struct dotSubcktParams : seq<TAO_PEGTL_ISTRING( "params:" ),
sep,
paramValuePairs> {};
struct dotSubcktEnd : seq<TAO_PEGTL_ISTRING( ".ends" ), struct dotSubcktEnd : seq<TAO_PEGTL_ISTRING( ".ends" ),
until<newline>> {}; until<newline>> {};
struct spiceUnit; struct spiceUnit;
@ -169,9 +172,7 @@ namespace SPICE_GRAMMAR
sep, sep,
dotSubcktPinSequence, dotSubcktPinSequence,
opt<sep, opt<sep,
TAO_PEGTL_ISTRING( "params:" ), dotSubcktParams>,
sep,
paramValuePairs>,
opt<sep>, opt<sep>,
newline, newline,
until<dotSubcktEnd, spiceUnit>> {}; until<dotSubcktEnd, spiceUnit>> {};