mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-09-14 10:13:19 +02:00
ADDED: expression support in min/max/opt values.
This commit is contained in:
parent
a382fd3064
commit
38f4a21b96
@ -73,7 +73,7 @@ void DRC_RULES_PARSER::reportError( const wxString& aMessage )
|
||||
}
|
||||
|
||||
|
||||
void DRC_RULES_PARSER::reportDeprecation( const wxString& oldToken, const wxString newToken )
|
||||
void DRC_RULES_PARSER::reportDeprecation( const wxString& oldToken, const wxString& newToken )
|
||||
{
|
||||
if( m_reporter )
|
||||
{
|
||||
@ -105,6 +105,29 @@ void DRC_RULES_PARSER::parseUnknown()
|
||||
}
|
||||
|
||||
|
||||
wxString DRC_RULES_PARSER::parseExpression()
|
||||
{
|
||||
wxString expr;
|
||||
int depth = 1;
|
||||
|
||||
for( T token = NextTok(); token != T_EOF; token = NextTok() )
|
||||
{
|
||||
if( token == T_LEFT )
|
||||
depth++;
|
||||
|
||||
if( token == T_RIGHT )
|
||||
{
|
||||
if( --depth == 0 )
|
||||
break;
|
||||
}
|
||||
|
||||
expr += FromUTF8();
|
||||
}
|
||||
|
||||
return expr;
|
||||
}
|
||||
|
||||
|
||||
void DRC_RULES_PARSER::Parse( std::vector<std::shared_ptr<DRC_RULE>>& aRules, REPORTER* aReporter )
|
||||
{
|
||||
bool haveVersion = false;
|
||||
@ -696,76 +719,64 @@ void DRC_RULES_PARSER::parseConstraint( DRC_RULE* aRule )
|
||||
break;
|
||||
|
||||
case T_min:
|
||||
token = NextTok();
|
||||
{
|
||||
wxString expr = parseExpression();
|
||||
|
||||
if( (int) token == DSN_RIGHT )
|
||||
if( expr.IsEmpty() )
|
||||
{
|
||||
reportError( _( "Missing min value." ) );
|
||||
break;
|
||||
}
|
||||
|
||||
parseValueWithUnits( FromUTF8(), value, units, unitless );
|
||||
parseValueWithUnits( expr, value, units, unitless );
|
||||
validateAndSetValueWithUnits( value, units,
|
||||
[&c]( const int aValue )
|
||||
{
|
||||
c.m_Value.SetMin( aValue );
|
||||
} );
|
||||
|
||||
if( (int) NextTok() != DSN_RIGHT )
|
||||
{
|
||||
reportError( wxString::Format( _( "Unrecognized item '%s'." ), FromUTF8() ) );
|
||||
parseUnknown();
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case T_max:
|
||||
token = NextTok();
|
||||
{
|
||||
wxString expr = parseExpression();
|
||||
|
||||
if( (int) token == DSN_RIGHT )
|
||||
if( expr.IsEmpty() )
|
||||
{
|
||||
reportError( _( "Missing max value." ) );
|
||||
break;
|
||||
}
|
||||
|
||||
parseValueWithUnits( FromUTF8(), value, units, unitless );
|
||||
parseValueWithUnits( expr, value, units, unitless );
|
||||
validateAndSetValueWithUnits( value, units,
|
||||
[&c]( const int aValue )
|
||||
{
|
||||
c.m_Value.SetMax( aValue );
|
||||
} );
|
||||
|
||||
if( (int) NextTok() != DSN_RIGHT )
|
||||
{
|
||||
reportError( wxString::Format( _( "Unrecognized item '%s'." ), FromUTF8() ) );
|
||||
parseUnknown();
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case T_opt:
|
||||
token = NextTok();
|
||||
{
|
||||
wxString expr = parseExpression();
|
||||
|
||||
if( (int) token == DSN_RIGHT )
|
||||
if( expr.IsEmpty() )
|
||||
{
|
||||
reportError( _( "Missing opt value." ) );
|
||||
break;
|
||||
}
|
||||
|
||||
parseValueWithUnits( FromUTF8(), value, units, unitless );
|
||||
parseValueWithUnits( expr, value, units, unitless );
|
||||
validateAndSetValueWithUnits( value, units,
|
||||
[&c]( const int aValue )
|
||||
{
|
||||
c.m_Value.SetOpt( aValue );
|
||||
} );
|
||||
|
||||
if( (int) NextTok() != DSN_RIGHT )
|
||||
{
|
||||
reportError( wxString::Format( _( "Unrecognized item '%s'." ), FromUTF8() ) );
|
||||
parseUnknown();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case T_EOF:
|
||||
reportError( _( "Incomplete statement." ) );
|
||||
|
@ -59,9 +59,10 @@ private:
|
||||
LSET parseLayer( wxString* aSource );
|
||||
SEVERITY parseSeverity();
|
||||
void parseUnknown();
|
||||
wxString parseExpression();
|
||||
|
||||
void reportError( const wxString& aMessage );
|
||||
void reportDeprecation( const wxString& oldToken, const wxString newToken );
|
||||
void reportDeprecation( const wxString& oldToken, const wxString& newToken );
|
||||
|
||||
private:
|
||||
int m_requiredVersion;
|
||||
|
Loading…
x
Reference in New Issue
Block a user