29#include <drc_rules_lexer.h>
34using namespace DRCRULE_T;
38 DRC_RULES_LEXER( aSource.ToStdString(), aSourceDescr ),
39 m_requiredVersion( 0 ),
47 DRC_RULES_LEXER( aFile, aFilename ),
48 m_requiredVersion( 0 ),
58 wxString first = aMessage.BeforeFirst(
'|', &rest );
62 wxString msg = wxString::Format(
_(
"ERROR: <a href='%d:%d'>%s</a>%s" ), CurLineNumber(),
63 CurOffset(), first, rest );
69 wxString msg = wxString::Format(
_(
"ERROR: %s%s" ), first, rest );
80 wxString msg = wxString::Format(
_(
"The '%s' keyword has been deprecated. "
81 "Please use '%s' instead." ),
94 for(
T token = NextTok(); token != T_EOF; token = NextTok() )
99 if( token == T_RIGHT )
110 bool haveVersion =
false;
115 for(
T token = NextTok(); token != T_EOF; token = NextTok() )
117 if( token != T_LEFT )
122 if( !haveVersion && token != T_version )
148 msg.Printf(
_(
"Unrecognized item '%s'.| Expected version number." ),
155 msg.Printf(
_(
"Unrecognized item '%s'." ),
172 msg.Printf(
_(
"Unrecognized item '%s'.| Expected %s." ), FromUTF8(),
173 wxT(
"rule or version" ) );
187 std::vector<std::shared_ptr<COMPONENT_CLASS_ASSIGNMENT_RULE>>& aRules,
REPORTER* aReporter )
189 bool haveVersion =
false;
194 for(
T token = NextTok(); token != T_EOF; token = NextTok() )
196 if( token != T_LEFT )
201 if( !haveVersion && token != T_version )
227 msg.Printf(
_(
"Unrecognized item '%s'.| Expected version number." ), FromUTF8() );
233 msg.Printf(
_(
"Unrecognized item '%s'." ), FromUTF8() );
240 case T_assign_component_class:
244 case T_EOF:
reportError(
_(
"Incomplete statement." ) );
break;
247 msg.Printf(
_(
"Unrecognized item '%s'.| Expected %s." ), FromUTF8(),
248 wxT(
"assign_component_class or version" ) );
263 std::shared_ptr<DRC_RULE> rule = std::make_shared<DRC_RULE>();
268 if( !IsSymbol( token ) )
271 rule->m_Name = FromUTF8();
273 for( token = NextTok(); token != T_RIGHT && token != T_EOF; token = NextTok() )
275 if( token != T_LEFT )
295 if( IsSymbol( token ) )
298 rule->m_Condition->Compile(
m_reporter, CurLineNumber(), CurOffset() );
302 msg.Printf(
_(
"Unrecognized item '%s'.| Expected quoted expression." ),
309 reportError( wxString::Format(
_(
"Unrecognized item '%s'." ), FromUTF8() ) );
319 rule->m_LayerCondition =
parseLayer( &rule->m_LayerSource );
331 msg.Printf(
_(
"Unrecognized item '%s'.| Expected %s." ), FromUTF8(),
332 wxT(
"constraint, condition, or disallow" ) );
347 std::shared_ptr<DRC_RULE_CONDITION> condition;
352 if( !IsSymbol( token ) )
355 wxString componentClass = FromUTF8();
357 for( token = NextTok(); token != T_RIGHT && token != T_EOF; token = NextTok() )
359 if( token != T_LEFT )
375 if( IsSymbol( token ) )
377 condition = std::make_shared<DRC_RULE_CONDITION>( FromUTF8() );
379 if( !condition->Compile(
m_reporter, CurLineNumber(), CurOffset() ) )
381 reportError( wxString::Format(
_(
"Could not parse expression '%s'." ),
387 msg.Printf(
_(
"Unrecognized item '%s'.| Expected quoted expression." ),
394 reportError( wxString::Format(
_(
"Unrecognized item '%s'." ), FromUTF8() ) );
400 case T_EOF:
reportError(
_(
"Incomplete statement." ) );
return nullptr;
403 msg.Printf(
_(
"Unrecognized item '%s'.| Expected %s." ), FromUTF8(),
404 wxT(
"condition" ) );
413 return std::make_shared<COMPONENT_CLASS_ASSIGNMENT_RULE>( componentClass,
414 std::move( condition ) );
426 bool allowsTimeDomain =
false;
428 auto validateAndSetValueWithUnits =
429 [
this, &allowsTimeDomain, &
unitsType, &c](
int aValue,
const EDA_UNITS aUnits,
auto aSetter )
433 if( !allowsTimeDomain && unitsTypeTmp == EDA_DATA_TYPE::TIME )
434 reportError(
_(
"Time based units not allowed for constraint type." ) );
438 reportError(
_(
"Mixed units for constraint values." ) );
444 if( allowsTimeDomain )
461 if( token == T_mechanical_clearance )
464 token = T_physical_clearance;
466 else if( token == T_mechanical_hole_clearance )
468 reportDeprecation( wxT(
"mechanical_hole_clearance" ), wxT(
"physical_hole_clearance" ) );
469 token = T_physical_hole_clearance;
471 else if( token == T_hole )
476 else if( (
int) token ==
DSN_RIGHT || token == T_EOF )
478 msg.Printf(
_(
"Missing constraint type.| Expected %s." ),
479 wxT(
"assertion, clearance, hole_clearance, edge_clearance, "
480 "physical_clearance, physical_hole_clearance, courtyard_clearance, "
481 "silk_clearance, hole_size, hole_to_hole, track_width, annular_width, "
482 "via_diameter, disallow, zone_connection, thermal_relief_gap, "
483 "thermal_spoke_width, min_resolved_spokes, length, skew, via_count, "
484 "diff_pair_gap or diff_pair_uncoupled" ) );
521 msg.Printf(
_(
"Unrecognized item '%s'.| Expected %s." ), FromUTF8(),
522 wxT(
"assertion, clearance, hole_clearance, edge_clearance, "
523 "physical_clearance, physical_hole_clearance, courtyard_clearance, "
524 "silk_clearance, hole_size, hole_to_hole, track_width, track_angle, track_segment_length, annular_width, "
525 "disallow, zone_connection, thermal_relief_gap, thermal_spoke_width, "
526 "min_resolved_spokes, length, skew, via_count, via_diameter, "
527 "diff_pair_gap or diff_pair_uncoupled" ) );
533 msg.Printf(
_(
"Rule already has a '%s' constraint." ), FromUTF8() );
545 for( token = NextTok(); token != T_RIGHT; token = NextTok() )
548 token = GetCurStrAsToken();
568 msg.Printf(
_(
"Unrecognized item '%s'.| Expected %s." ), FromUTF8(),
569 wxT(
"track, via, micro_via, buried_via, pad, zone, text, graphic, "
570 "hole, or footprint." ) );
587 token = GetCurStrAsToken();
592 case T_thermal_reliefs: c.
m_ZoneConnection = ZONE_CONNECTION::THERMAL;
break;
600 msg.Printf(
_(
"Unrecognized item '%s'.| Expected %s." ), FromUTF8(),
601 "solid, thermal_reliefs or none." );
623 value = (int) strtol( CurText(),
nullptr, 10 );
645 if( IsSymbol( token ) )
652 msg.Printf(
_(
"Unrecognized item '%s'.| Expected quoted expression." ), FromUTF8() );
658 reportError( wxString::Format(
_(
"Unrecognized item '%s'." ), FromUTF8() ) );
666 for( token = NextTok(); token != T_RIGHT && token != T_EOF; token = NextTok() )
668 if( token != T_LEFT )
675 case T_within_diff_pairs:
678 reportError(
_(
"within_diff_pairs option invalid for constraint type." ) );
686 reportError( wxString::Format(
_(
"Unrecognized item '%s'." ), FromUTF8() ) );
701 validateAndSetValueWithUnits( value, units,
702 [&c](
const int aValue )
709 reportError( wxString::Format(
_(
"Unrecognized item '%s'." ), FromUTF8() ) );
725 validateAndSetValueWithUnits( value, units,
726 [&c](
const int aValue )
733 reportError( wxString::Format(
_(
"Unrecognized item '%s'." ), FromUTF8() ) );
749 validateAndSetValueWithUnits( value, units,
750 [&c](
const int aValue )
757 reportError( wxString::Format(
_(
"Unrecognized item '%s'." ), FromUTF8() ) );
768 msg.Printf(
_(
"Unrecognized item '%s'.| Expected %s." ),
770 wxT(
"min, max, or opt" ) );
786 aUnits = EDA_UNITS::UNSCALED;
788 auto errorHandler = [&](
const wxString& aMessage,
int aOffset )
791 wxString first = aMessage.BeforeFirst(
'|', &rest );
795 wxString msg = wxString::Format(
_(
"ERROR: <a href='%d:%d'>%s</a>%s" ),
796 CurLineNumber(), CurOffset() + aOffset, first, rest );
802 wxString msg = wxString::Format(
_(
"ERROR: %s%s" ), first, rest );
805 CurOffset() + aOffset );
815 aResult = evaluator.
Result();
816 aUnits = evaluator.
Units();
824 int token = NextTok();
831 else if( token == T_outer )
833 *aSource = GetTokenString( token );
836 else if( token == T_inner )
838 *aSource = GetTokenString( token );
843 wxString layerName = FromUTF8();
846 for(
unsigned ii = 0; ii < layerMap.GetCount(); ++ii )
848 wxPGChoiceEntry& entry = layerMap[ii];
850 if( entry.GetText().Matches( layerName ) )
852 *aSource = layerName;
859 reportError( wxString::Format(
_(
"Unrecognized layer '%s'." ), layerName ) );
866 reportError( wxString::Format(
_(
"Unrecognized item '%s'." ), FromUTF8() ) );
881 if( (
int) token ==
DSN_RIGHT || token == T_EOF )
895 msg.Printf(
_(
"Unrecognized item '%s'.| Expected %s." ),
897 wxT(
"ignore, warning, error, or exclusion" ) );
BASE_SET & set(size_t pos)
DRC_RULE_CONDITION * m_Test
void SetOption(OPTIONS option)
ZONE_CONNECTION m_ZoneConnection
void ClearOption(OPTIONS option)
std::shared_ptr< COMPONENT_CLASS_ASSIGNMENT_RULE > parseComponentClassAssignment()
void Parse(std::vector< std::shared_ptr< DRC_RULE > > &aRules, REPORTER *aReporter)
void ParseComponentClassAssignmentRules(std::vector< std::shared_ptr< COMPONENT_CLASS_ASSIGNMENT_RULE > > &aRules, REPORTER *aReporter)
std::shared_ptr< DRC_RULE > parseDRC_RULE()
LSET parseLayer(wxString *aSource)
void parseConstraint(DRC_RULE *aRule)
void reportError(const wxString &aMessage)
DRC_RULES_PARSER(const wxString &aSource, const wxString &aSourceDescr)
void parseValueWithUnits(const wxString &aExpr, int &aResult, EDA_UNITS &aUnits, bool aUnitless=false)
void reportDeprecation(const wxString &oldToken, const wxString newToken)
bool Compile(REPORTER *aReporter, int aSourceLine=0, int aSourceOffset=0)
void AddConstraint(DRC_CONSTRAINT &aConstraint)
std::optional< DRC_CONSTRAINT > FindConstraint(DRC_CONSTRAINT_T aType)
static ENUM_MAP< T > & Instance()
LSET is a set of PCB_LAYER_IDs.
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
static const LSET & ExternalCuMask()
Return a mask holding the Front and Bottom layers.
static const LSET & AllLayersMask()
static const LSET & InternalCuMask()
Return a complete set of internal copper layers which is all Cu layers except F_Cu and B_Cu.
bool Evaluate(const wxString &aExpr)
void SetErrorCallback(std::function< void(const wxString &aMessage, int aOffset)> aCallback)
A pure virtual class used to derive REPORTER objects from.
virtual bool HasMessage() const =0
Returns true if the reporter client is non-empty.
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Report a string with a given severity.
static EDA_DATA_TYPE GetTypeFromUnits(const EDA_UNITS aUnits)
Gets the inferred type from the given units.
@ DRC_DISALLOW_FOOTPRINTS
@ DRC_DISALLOW_MICRO_VIAS
@ ANNULAR_WIDTH_CONSTRAINT
@ COURTYARD_CLEARANCE_CONSTRAINT
@ VIA_DIAMETER_CONSTRAINT
@ ZONE_CONNECTION_CONSTRAINT
@ DIFF_PAIR_GAP_CONSTRAINT
@ SILK_CLEARANCE_CONSTRAINT
@ EDGE_CLEARANCE_CONSTRAINT
@ MIN_RESOLVED_SPOKES_CONSTRAINT
@ TRACK_SEGMENT_LENGTH_CONSTRAINT
@ TEXT_THICKNESS_CONSTRAINT
@ PHYSICAL_HOLE_CLEARANCE_CONSTRAINT
@ THERMAL_SPOKE_WIDTH_CONSTRAINT
@ CONNECTION_WIDTH_CONSTRAINT
@ THERMAL_RELIEF_GAP_CONSTRAINT
@ MAX_UNCOUPLED_CONSTRAINT
@ HOLE_CLEARANCE_CONSTRAINT
@ PHYSICAL_CLEARANCE_CONSTRAINT
@ HOLE_TO_HOLE_CONSTRAINT
#define DRC_RULE_FILE_VERSION
EDA_DATA_TYPE
The type of unit.
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
PCB_LAYER_ID ToLAYER_ID(int aLayer)