Sim: Allow principal value in Value field to be followed by regular params
This commit is contained in:
parent
585fac19c6
commit
9819fa43dd
|
@ -56,24 +56,18 @@ namespace SIM_MODEL_PARSER
|
||||||
using namespace SIM_MODEL_GRAMMAR;
|
using namespace SIM_MODEL_GRAMMAR;
|
||||||
|
|
||||||
template <typename Rule> struct fieldParamValuePairsSelector : std::false_type {};
|
template <typename Rule> struct fieldParamValuePairsSelector : std::false_type {};
|
||||||
|
|
||||||
|
|
||||||
template <typename Rule> struct pinSequenceSelector : std::false_type {};
|
|
||||||
template <> struct pinSequenceSelector<pinNumber> : std::true_type {};
|
|
||||||
|
|
||||||
|
|
||||||
template <typename Rule> struct fieldFloatValueSelector : std::false_type {};
|
|
||||||
template <> struct fieldFloatValueSelector<number<SIM_VALUE::TYPE_FLOAT, NOTATION::SI>>
|
|
||||||
: std::true_type {};
|
|
||||||
template <> struct fieldParamValuePairsSelector<param> : std::true_type {};
|
template <> struct fieldParamValuePairsSelector<param> : std::true_type {};
|
||||||
template <> struct fieldParamValuePairsSelector<quotedStringContent> : std::true_type {};
|
template <> struct fieldParamValuePairsSelector<quotedStringContent> : std::true_type {};
|
||||||
template <> struct fieldParamValuePairsSelector<unquotedString> : std::true_type {};
|
template <> struct fieldParamValuePairsSelector<unquotedString> : std::true_type {};
|
||||||
|
|
||||||
|
|
||||||
|
template <typename Rule> struct pinSequenceSelector : std::false_type {};
|
||||||
|
template <> struct pinSequenceSelector<pinNumber> : std::true_type {};
|
||||||
|
|
||||||
template <typename Rule> struct fieldInferValueSelector : std::false_type {};
|
template <typename Rule> struct fieldInferValueSelector : std::false_type {};
|
||||||
template <> struct fieldInferValueSelector<fieldFloatValue> : std::true_type {};
|
template <> struct fieldInferValueSelector<fieldInferValueType> : std::true_type {};
|
||||||
|
template <> struct fieldInferValueSelector<fieldInferValuePrincipalValue> : std::true_type {};
|
||||||
template <> struct fieldInferValueSelector<number<SIM_VALUE::TYPE_FLOAT, NOTATION::SI>> : std::true_type {};
|
template <> struct fieldInferValueSelector<number<SIM_VALUE::TYPE_FLOAT, NOTATION::SI>> : std::true_type {};
|
||||||
template <> struct fieldInferValueSelector<fieldInferValuePrefix> : std::true_type {};
|
|
||||||
template <> struct fieldInferValueSelector<fieldParamValuePairs> : std::true_type {};
|
template <> struct fieldInferValueSelector<fieldParamValuePairs> : std::true_type {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -454,7 +448,7 @@ DEVICE_TYPE SIM_MODEL::InferDeviceTypeFromRef( const std::string& aRef )
|
||||||
|
|
||||||
TYPE SIM_MODEL::InferTypeFromRefAndValue( const std::string& aRef, const std::string& aValue )
|
TYPE SIM_MODEL::InferTypeFromRefAndValue( const std::string& aRef, const std::string& aValue )
|
||||||
{
|
{
|
||||||
std::string prefix;
|
std::string typeString;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -466,8 +460,8 @@ TYPE SIM_MODEL::InferTypeFromRefAndValue( const std::string& aRef, const std::st
|
||||||
|
|
||||||
for( const auto& node : root->children )
|
for( const auto& node : root->children )
|
||||||
{
|
{
|
||||||
if( node->is_type<SIM_MODEL_PARSER::fieldInferValuePrefix>() )
|
if( node->is_type<SIM_MODEL_PARSER::fieldInferValueType>() )
|
||||||
prefix = node->string();
|
typeString = node->string();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch( const tao::pegtl::parse_error& )
|
catch( const tao::pegtl::parse_error& )
|
||||||
|
@ -478,7 +472,7 @@ TYPE SIM_MODEL::InferTypeFromRefAndValue( const std::string& aRef, const std::st
|
||||||
|
|
||||||
for( TYPE type : TYPE_ITERATOR() )
|
for( TYPE type : TYPE_ITERATOR() )
|
||||||
{
|
{
|
||||||
if( TypeInfo( type ).deviceType == deviceType && TypeInfo( type ).fieldValue == prefix )
|
if( TypeInfo( type ).deviceType == deviceType && TypeInfo( type ).fieldValue == typeString )
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -812,8 +806,9 @@ void SIM_MODEL::SetParamValue( const std::string& aParamName, const SIM_VALUE& a
|
||||||
|
|
||||||
if( it == params.end() )
|
if( it == params.end() )
|
||||||
{
|
{
|
||||||
THROW_IO_ERROR( wxString::Format( _( "Could not find a simulation model parameter named '%s'" ),
|
THROW_IO_ERROR( wxString::Format( _( "Could not find a parameter named '%s' in simulation model of type '%s'" ),
|
||||||
aParamName ) );
|
aParamName,
|
||||||
|
GetTypeInfo().fieldValue ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
SetParamValue( static_cast<int>( it - params.begin() ), aValue );
|
SetParamValue( static_cast<int>( it - params.begin() ), aValue );
|
||||||
|
@ -827,8 +822,9 @@ void SIM_MODEL::SetParamValue( const std::string& aParamName, const std::string&
|
||||||
|
|
||||||
if( !param )
|
if( !param )
|
||||||
{
|
{
|
||||||
THROW_IO_ERROR( wxString::Format( _( "Could not find a simulation model parameter named '%s'" ),
|
THROW_IO_ERROR( wxString::Format( _( "Could not find a parameter named '%s' in simulation model of type '%s'" ),
|
||||||
aParamName ) );
|
aParamName,
|
||||||
|
GetTypeInfo().fieldValue ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
const SIM_VALUE& value = *FindParam( aParamName )->value;
|
const SIM_VALUE& value = *FindParam( aParamName )->value;
|
||||||
|
@ -1059,7 +1055,7 @@ void SIM_MODEL::ParseParamsField( const std::string& aParamsField )
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Using parse tree instead of actions because we don't care about performance that much,
|
// Using parse tree instead of actions because we don't care about performance that much,
|
||||||
// and having a tree greatly simplifies some things.
|
// and having a tree greatly simplifies things.
|
||||||
root = tao::pegtl::parse_tree::parse<
|
root = tao::pegtl::parse_tree::parse<
|
||||||
SIM_MODEL_PARSER::fieldParamValuePairsGrammar,
|
SIM_MODEL_PARSER::fieldParamValuePairsGrammar,
|
||||||
SIM_MODEL_PARSER::fieldParamValuePairsSelector,
|
SIM_MODEL_PARSER::fieldParamValuePairsSelector,
|
||||||
|
@ -1172,7 +1168,7 @@ void SIM_MODEL::doReadDataFields( unsigned aSymbolPinCount, const std::vector<T>
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void SIM_MODEL::InferredReadDataFields( unsigned aSymbolPinCount, const std::vector<T>* aFields,
|
void SIM_MODEL::InferredReadDataFields( unsigned aSymbolPinCount, const std::vector<T>* aFields,
|
||||||
bool aAllowOnlyFirstValue )
|
bool aAllowPrincipalValueWithoutName )
|
||||||
{
|
{
|
||||||
// TODO: Make a subclass SIM_MODEL_NONE.
|
// TODO: Make a subclass SIM_MODEL_NONE.
|
||||||
if( GetType() == SIM_MODEL::TYPE::NONE )
|
if( GetType() == SIM_MODEL::TYPE::NONE )
|
||||||
|
@ -1197,11 +1193,9 @@ void SIM_MODEL::InferredReadDataFields( unsigned aSymbolPinCount, const std::vec
|
||||||
|
|
||||||
for( const auto& node : root->children )
|
for( const auto& node : root->children )
|
||||||
{
|
{
|
||||||
if( node->is_type<SIM_MODEL_PARSER::fieldParamValuePairs>() )
|
if( node->is_type<SIM_MODEL_PARSER::fieldInferValuePrincipalValue>() )
|
||||||
ParseParamsField( node->string() );
|
|
||||||
else if( node->is_type<SIM_MODEL_PARSER::fieldFloatValue>() )
|
|
||||||
{
|
{
|
||||||
if( aAllowOnlyFirstValue )
|
if( aAllowPrincipalValueWithoutName )
|
||||||
{
|
{
|
||||||
for( const auto& subnode : node->children )
|
for( const auto& subnode : node->children )
|
||||||
{
|
{
|
||||||
|
@ -1212,15 +1206,24 @@ void SIM_MODEL::InferredReadDataFields( unsigned aSymbolPinCount, const std::vec
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
THROW_IO_ERROR(
|
||||||
|
wxString::Format( _( "Model of type '%s' cannot have a principal value (which is '%s') in Value field" ),
|
||||||
|
GetTypeInfo().fieldValue,
|
||||||
|
node->string() ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if( node->is_type<SIM_MODEL_PARSER::fieldParamValuePairs>() )
|
||||||
|
ParseParamsField( node->string() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch( const tao::pegtl::parse_error& e )
|
catch( const tao::pegtl::parse_error& e )
|
||||||
{
|
{
|
||||||
THROW_IO_ERROR( e.what() );
|
THROW_IO_ERROR( e.what() );
|
||||||
}
|
}
|
||||||
|
|
||||||
m_isInferred = true;
|
SetIsInferred( true );
|
||||||
}
|
}
|
||||||
|
|
||||||
template void SIM_MODEL::InferredReadDataFields( unsigned aSymbolPinCount,
|
template void SIM_MODEL::InferredReadDataFields( unsigned aSymbolPinCount,
|
||||||
|
|
|
@ -55,22 +55,13 @@ namespace SIM_MODEL_GRAMMAR
|
||||||
tao::pegtl::eof> {};
|
tao::pegtl::eof> {};
|
||||||
|
|
||||||
|
|
||||||
struct pinNumber : plus<not_at<sep>,
|
struct pinNumber : plus<not_at<sep>, any> {};
|
||||||
any> {};
|
|
||||||
struct pinSequence : list<pinNumber, sep> {};
|
struct pinSequence : list<pinNumber, sep> {};
|
||||||
struct pinSequenceGrammar : must<opt<sep>,
|
struct pinSequenceGrammar : must<opt<sep>,
|
||||||
opt<pinSequence>,
|
opt<pinSequence>,
|
||||||
opt<sep>,
|
opt<sep>,
|
||||||
tao::pegtl::eof> {};
|
tao::pegtl::eof> {};
|
||||||
|
|
||||||
|
|
||||||
struct fieldFloatValue : seq<number<SIM_VALUE::TYPE_FLOAT, NOTATION::SI>,
|
|
||||||
star<not_at<sep>, not_at<one<'='>>, any>> {}; // Garbage suffix.
|
|
||||||
|
|
||||||
struct fieldFloatValueGrammar : must<fieldFloatValue,
|
|
||||||
tao::pegtl::eof> {};
|
|
||||||
|
|
||||||
|
|
||||||
struct param : plus<alnum> {};
|
struct param : plus<alnum> {};
|
||||||
|
|
||||||
struct unquotedString : plus<not_at<sep>, any> {};
|
struct unquotedString : plus<not_at<sep>, any> {};
|
||||||
|
@ -91,24 +82,31 @@ namespace SIM_MODEL_GRAMMAR
|
||||||
opt<sep>,
|
opt<sep>,
|
||||||
tao::pegtl::eof> {};
|
tao::pegtl::eof> {};
|
||||||
|
|
||||||
struct fieldInferValuePrefix : plus<alpha> {};
|
struct fieldInferValueType : plus<upper> {};
|
||||||
struct fieldInferValue : seq<opt<fieldInferValuePrefix,
|
struct fieldInferValuePrincipalValue : seq<// HACK: Because `number` matches empty string,
|
||||||
sep>,
|
// ensure it is not empty.
|
||||||
fieldParamValuePairs> {};
|
at<sor<tao::pegtl::digit,
|
||||||
|
one<'.'>>>,
|
||||||
|
// END HACK.
|
||||||
|
number<SIM_VALUE::TYPE_FLOAT, NOTATION::SI>,
|
||||||
|
star<not_at<sep>, not_at<one<'='>>, any>> {};
|
||||||
|
struct fieldInferValue : sor<seq<fieldInferValueType,
|
||||||
|
opt<sep,
|
||||||
|
fieldParamValuePairs>>,
|
||||||
|
seq<opt<fieldInferValuePrincipalValue>,
|
||||||
|
opt<sep>,
|
||||||
|
opt<fieldParamValuePairs>>> {};
|
||||||
struct fieldInferValueGrammar : must<opt<sep>,
|
struct fieldInferValueGrammar : must<opt<sep>,
|
||||||
sor<seq<fieldFloatValue,
|
fieldInferValue,
|
||||||
opt<sep>,
|
opt<sep>,
|
||||||
tao::pegtl::eof>,
|
tao::pegtl::eof> {};
|
||||||
seq<fieldInferValue,
|
|
||||||
opt<sep>,
|
|
||||||
tao::pegtl::eof>>> {};
|
|
||||||
|
|
||||||
|
|
||||||
template <typename> inline constexpr const char* errorMessage = nullptr;
|
template <typename> inline constexpr const char* errorMessage = nullptr;
|
||||||
template <> inline constexpr auto errorMessage<opt<sep>> = "";
|
template <> inline constexpr auto errorMessage<opt<sep>> = "";
|
||||||
template <> inline constexpr auto errorMessage<opt<pinSequence>> = "";
|
template <> inline constexpr auto errorMessage<opt<pinSequence>> = "";
|
||||||
template <> inline constexpr auto errorMessage<fieldFloatValue> =
|
template <> inline constexpr auto errorMessage<opt<sor<fieldInferValueType,
|
||||||
"expected number";
|
fieldInferValuePrincipalValue>>> = "";
|
||||||
template <> inline constexpr auto errorMessage<one<'='>> =
|
template <> inline constexpr auto errorMessage<one<'='>> =
|
||||||
"expected '='";
|
"expected '='";
|
||||||
template <> inline constexpr auto errorMessage<sor<quotedString,
|
template <> inline constexpr auto errorMessage<sor<quotedString,
|
||||||
|
@ -117,13 +115,8 @@ namespace SIM_MODEL_GRAMMAR
|
||||||
template <> inline constexpr auto errorMessage<fieldParamValuePairs> =
|
template <> inline constexpr auto errorMessage<fieldParamValuePairs> =
|
||||||
"expected parameter=value pairs";
|
"expected parameter=value pairs";
|
||||||
template <> inline constexpr auto errorMessage<opt<fieldParamValuePairs>> = "";
|
template <> inline constexpr auto errorMessage<opt<fieldParamValuePairs>> = "";
|
||||||
template <> inline constexpr auto errorMessage<sor<seq<fieldFloatValue,
|
template <> inline constexpr auto errorMessage<fieldInferValue> =
|
||||||
opt<sep>,
|
"expected parameter=value pairs, together possibly preceded by a type or principal value";
|
||||||
tao::pegtl::eof>,
|
|
||||||
seq<fieldInferValue,
|
|
||||||
opt<sep>,
|
|
||||||
tao::pegtl::eof>>> =
|
|
||||||
"expected parameter=value pairs, together optionally preceded by type, or a single number";
|
|
||||||
template <> inline constexpr auto errorMessage<tao::pegtl::eof> =
|
template <> inline constexpr auto errorMessage<tao::pegtl::eof> =
|
||||||
"expected end of string";
|
"expected end of string";
|
||||||
|
|
||||||
|
@ -629,7 +622,7 @@ protected:
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void InferredReadDataFields( unsigned aSymbolPinCount, const std::vector<T>* aFields,
|
void InferredReadDataFields( unsigned aSymbolPinCount, const std::vector<T>* aFields,
|
||||||
bool aAllowOnlyFirstValue = false );
|
bool aAllowPrincipalValueWithoutName = false );
|
||||||
std::vector<PARAM> m_params;
|
std::vector<PARAM> m_params;
|
||||||
const SIM_MODEL* m_baseModel;
|
const SIM_MODEL* m_baseModel;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue