diff --git a/eeschema/sim/sim_model.h b/eeschema/sim/sim_model.h index 24e6753a01..b481ace6e0 100644 --- a/eeschema/sim/sim_model.h +++ b/eeschema/sim/sim_model.h @@ -62,6 +62,14 @@ namespace SIM_MODEL_GRAMMAR quotedStringContent, one<'"'>> {}; + struct fieldFloatValue : seq, + number, + star, any>, // Garbage suffix. + star> {}; + + struct fieldFloatValueGrammar : must {}; + struct param : plus {}; struct fieldParamValuePair : seq +#include +#include using PARAM = SIM_MODEL::PARAM; +namespace SIM_MODEL_PARSER +{ + using namespace SIM_MODEL_GRAMMAR; + + template struct fieldFloatValueSelector : std::false_type {}; + template <> struct fieldFloatValueSelector> + : std::true_type {}; +}; + + SIM_MODEL_IDEAL::SIM_MODEL_IDEAL( TYPE aType ) : SIM_MODEL( aType ), m_isInferred( false ) @@ -111,9 +123,24 @@ void SIM_MODEL_IDEAL::inferredReadDataFields( unsigned aSymbolPinCount, const st if( InferTypeFromRefAndValue( GetFieldValue( aFields, REFERENCE_FIELD ), GetFieldValue( aFields, VALUE_FIELD ) ) == GetType() ) { - if( !SetParamValue( 0, GetFieldValue( aFields, VALUE_FIELD ) ) ) + try + { + wxString value = GetFieldValue( aFields, VALUE_FIELD ); + + tao::pegtl::string_input<> in( value.ToStdString(), "Value" ); + auto root = tao::pegtl::parse_tree::parse< + SIM_MODEL_PARSER::fieldFloatValueGrammar, + SIM_MODEL_PARSER::fieldFloatValueSelector> + ( in ); + + // The grammar and selector must guarantee having at least one child. + SetParamValue( 0, root->children[0]->string() ); + } + catch( const tao::pegtl::parse_error& e ) + { THROW_IO_ERROR( wxString::Format( _( "Failed to infer model from Value '%s'" ), GetFieldValue( aFields, VALUE_FIELD ) ) ); + } m_isInferred = true; return; diff --git a/eeschema/sim/sim_model_subckt.cpp b/eeschema/sim/sim_model_subckt.cpp index c6ab9560ba..232f57da62 100644 --- a/eeschema/sim/sim_model_subckt.cpp +++ b/eeschema/sim/sim_model_subckt.cpp @@ -68,8 +68,6 @@ void SIM_MODEL_SUBCKT::ReadSpiceCode( const std::string& aSpiceCode ) THROW_IO_ERROR( e.what() ); } - wxASSERT( root ); - for( const auto& node : root->children ) { if( node->is_type() ) diff --git a/eeschema/sim/sim_value.h b/eeschema/sim/sim_value.h index 1ca97ae9c9..b6a7c498c5 100644 --- a/eeschema/sim/sim_value.h +++ b/eeschema/sim/sim_value.h @@ -193,7 +193,7 @@ namespace SIM_VALUE_GRAMMAR struct garbageSuffix; template <> struct garbageSuffix : seq<> {}; - template <> struct garbageSuffix : star {}; + template <> struct garbageSuffix : star {}; template