Sim: Fix inference of RLC models with garbage suffixes
Garbage suffix is e.g. the "F" in "100uF".
This commit is contained in:
parent
f0c58ccdc1
commit
5096f5d8a9
|
@ -62,6 +62,14 @@ namespace SIM_MODEL_GRAMMAR
|
||||||
quotedStringContent,
|
quotedStringContent,
|
||||||
one<'"'>> {};
|
one<'"'>> {};
|
||||||
|
|
||||||
|
struct fieldFloatValue : seq<star<space>,
|
||||||
|
number<SIM_VALUE::TYPE_FLOAT, NOTATION::SI>,
|
||||||
|
star<not_at<space>, any>, // Garbage suffix.
|
||||||
|
star<space>> {};
|
||||||
|
|
||||||
|
struct fieldFloatValueGrammar : must<fieldFloatValue,
|
||||||
|
tao::pegtl::eof> {};
|
||||||
|
|
||||||
struct param : plus<alnum> {};
|
struct param : plus<alnum> {};
|
||||||
|
|
||||||
struct fieldParamValuePair : seq<param,
|
struct fieldParamValuePair : seq<param,
|
||||||
|
|
|
@ -23,10 +23,22 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sim/sim_model_ideal.h>
|
#include <sim/sim_model_ideal.h>
|
||||||
|
#include <tao/pegtl.hpp>
|
||||||
|
#include <tao/pegtl/contrib/parse_tree.hpp>
|
||||||
|
|
||||||
using PARAM = SIM_MODEL::PARAM;
|
using PARAM = SIM_MODEL::PARAM;
|
||||||
|
|
||||||
|
|
||||||
|
namespace SIM_MODEL_PARSER
|
||||||
|
{
|
||||||
|
using namespace SIM_MODEL_GRAMMAR;
|
||||||
|
|
||||||
|
template <typename Rule> struct fieldFloatValueSelector : std::false_type {};
|
||||||
|
template <> struct fieldFloatValueSelector<number<SIM_VALUE::TYPE_FLOAT, NOTATION::SI>>
|
||||||
|
: std::true_type {};
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
SIM_MODEL_IDEAL::SIM_MODEL_IDEAL( TYPE aType )
|
SIM_MODEL_IDEAL::SIM_MODEL_IDEAL( TYPE aType )
|
||||||
: SIM_MODEL( aType ),
|
: SIM_MODEL( aType ),
|
||||||
m_isInferred( false )
|
m_isInferred( false )
|
||||||
|
@ -111,9 +123,24 @@ void SIM_MODEL_IDEAL::inferredReadDataFields( unsigned aSymbolPinCount, const st
|
||||||
if( InferTypeFromRefAndValue( GetFieldValue( aFields, REFERENCE_FIELD ),
|
if( InferTypeFromRefAndValue( GetFieldValue( aFields, REFERENCE_FIELD ),
|
||||||
GetFieldValue( aFields, VALUE_FIELD ) ) == GetType() )
|
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'" ),
|
THROW_IO_ERROR( wxString::Format( _( "Failed to infer model from Value '%s'" ),
|
||||||
GetFieldValue( aFields, VALUE_FIELD ) ) );
|
GetFieldValue( aFields, VALUE_FIELD ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
m_isInferred = true;
|
m_isInferred = true;
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -68,8 +68,6 @@ void SIM_MODEL_SUBCKT::ReadSpiceCode( const std::string& aSpiceCode )
|
||||||
THROW_IO_ERROR( e.what() );
|
THROW_IO_ERROR( e.what() );
|
||||||
}
|
}
|
||||||
|
|
||||||
wxASSERT( root );
|
|
||||||
|
|
||||||
for( const auto& node : root->children )
|
for( const auto& node : root->children )
|
||||||
{
|
{
|
||||||
if( node->is_type<SIM_MODEL_SUBCKT_SPICE_PARSER::dotSubckt>() )
|
if( node->is_type<SIM_MODEL_SUBCKT_SPICE_PARSER::dotSubckt>() )
|
||||||
|
|
|
@ -193,7 +193,7 @@ namespace SIM_VALUE_GRAMMAR
|
||||||
struct garbageSuffix;
|
struct garbageSuffix;
|
||||||
|
|
||||||
template <> struct garbageSuffix<NOTATION::SI> : seq<> {};
|
template <> struct garbageSuffix<NOTATION::SI> : seq<> {};
|
||||||
template <> struct garbageSuffix<NOTATION::SPICE> : star<alnum> {};
|
template <> struct garbageSuffix<NOTATION::SPICE> : star<alpha> {};
|
||||||
|
|
||||||
|
|
||||||
template <SIM_VALUE::TYPE ValueType, NOTATION Notation>
|
template <SIM_VALUE::TYPE ValueType, NOTATION Notation>
|
||||||
|
|
Loading…
Reference in New Issue