29#include <drc_rules_lexer.h>
34using namespace DRCRULE_T;
38 DRC_RULES_LEXER( aSource.ToStdString(), aSourceDescr ),
39 m_requiredVersion( 0 ),
49 wxString first = aMessage.BeforeFirst(
'|', &rest );
53 wxString msg = wxString::Format(
_(
"ERROR: <a href='%d:%d'>%s</a>%s" ),
63 wxString msg = wxString::Format(
_(
"ERROR: %s%s" ), first, rest );
74 wxString msg = wxString::Format(
_(
"The '%s' keyword has been deprecated. "
75 "Please use '%s' instead." ),
88 for(
T token = NextTok(); token != T_EOF; token = NextTok() )
93 if( token == T_RIGHT )
107 for(
T token = NextTok(); token != T_EOF; token = NextTok() )
109 if( token == T_LEFT )
112 if( token == T_RIGHT )
118 if( !expr.IsEmpty() )
119 expr += CurSeparator();
130 bool haveVersion =
false;
135 for(
T token = NextTok(); token != T_EOF; token = NextTok() )
137 if( token != T_LEFT )
142 if( !haveVersion && token != T_version )
168 msg.Printf(
_(
"Unrecognized item '%s'.| Expected version number." ), FromUTF8() );
174 msg.Printf(
_(
"Unrecognized item '%s'." ), FromUTF8() );
190 msg.Printf(
_(
"Unrecognized item '%s'.| Expected %s." ), FromUTF8(),
191 wxT(
"rule or version" ) );
205 std::vector<std::shared_ptr<COMPONENT_CLASS_ASSIGNMENT_RULE>>& aRules,
REPORTER* aReporter )
207 bool haveVersion =
false;
212 for(
T token = NextTok(); token != T_EOF; token = NextTok() )
214 if( token != T_LEFT )
219 if( !haveVersion && token != T_version )
245 msg.Printf(
_(
"Unrecognized item '%s'.| Expected version number." ), FromUTF8() );
251 msg.Printf(
_(
"Unrecognized item '%s'." ), FromUTF8() );
258 case T_assign_component_class:
262 case T_EOF:
reportError(
_(
"Incomplete statement." ) );
break;
265 msg.Printf(
_(
"Unrecognized item '%s'.| Expected %s." ), FromUTF8(),
266 wxT(
"assign_component_class or version" ) );
281 std::shared_ptr<DRC_RULE> rule = std::make_shared<DRC_RULE>();
286 if( !IsSymbol( token ) )
289 rule->m_Name = FromUTF8();
291 for( token = NextTok(); token != T_RIGHT && token != T_EOF; token = NextTok() )
293 if( token != T_LEFT )
313 if( IsSymbol( token ) )
316 rule->m_Condition->Compile(
m_reporter, CurLineNumber(), CurOffset() );
320 msg.Printf(
_(
"Unrecognized item '%s'.| Expected quoted expression." ), FromUTF8() );
326 reportError( wxString::Format(
_(
"Unrecognized item '%s'." ), FromUTF8() ) );
336 rule->m_LayerCondition =
parseLayer( &rule->m_LayerSource );
348 msg.Printf(
_(
"Unrecognized item '%s'.| Expected %s." ), FromUTF8(),
349 wxT(
"constraint, condition, or disallow" ) );
364 std::shared_ptr<DRC_RULE_CONDITION> condition;
369 if( !IsSymbol( token ) )
372 wxString componentClass = FromUTF8();
374 for( token = NextTok(); token != T_RIGHT && token != T_EOF; token = NextTok() )
376 if( token != T_LEFT )
392 if( IsSymbol( token ) )
394 condition = std::make_shared<DRC_RULE_CONDITION>( FromUTF8() );
396 if( !condition->Compile(
m_reporter, CurLineNumber(), CurOffset() ) )
397 reportError( wxString::Format(
_(
"Could not parse expression '%s'." ), FromUTF8() ) );
401 msg.Printf(
_(
"Unrecognized item '%s'.| Expected quoted expression." ), FromUTF8() );
407 reportError( wxString::Format(
_(
"Unrecognized item '%s'." ), FromUTF8() ) );
418 msg.Printf(
_(
"Unrecognized item '%s'.| Expected %s." ), FromUTF8(), wxT(
"condition" ) );
427 return std::make_shared<COMPONENT_CLASS_ASSIGNMENT_RULE>( componentClass,
428 std::move( condition ) );
440 bool allowsTimeDomain =
false;
442 auto validateAndSetValueWithUnits =
443 [
this, &allowsTimeDomain, &
unitsType, &c](
int aValue,
const EDA_UNITS aUnits,
auto aSetter )
447 if( !allowsTimeDomain && unitsTypeTmp == EDA_DATA_TYPE::TIME )
448 reportError(
_(
"Time based units not allowed for constraint type." ) );
453 reportError(
_(
"Mixed units for constraint values." ) );
459 if( allowsTimeDomain )
476 if( token == T_mechanical_clearance )
479 token = T_physical_clearance;
481 else if( token == T_mechanical_hole_clearance )
483 reportDeprecation( wxT(
"mechanical_hole_clearance" ), wxT(
"physical_hole_clearance" ) );
484 token = T_physical_hole_clearance;
486 else if( token == T_hole )
491 else if( (
int) token ==
DSN_RIGHT || token == T_EOF )
493 msg.Printf(
_(
"Missing constraint type.| Expected %s." ),
494 wxT(
"assertion, clearance, hole_clearance, edge_clearance, physical_clearance, "
495 "physical_hole_clearance, courtyard_clearance, silk_clearance, hole_size, "
496 "hole_to_hole, track_width, track_angle, track_segment_length, annular_width, "
497 "disallow, zone_connection, thermal_relief_gap, thermal_spoke_width, "
498 "min_resolved_spokes, solder_mask_expansion, solder_paste_abs_margin, "
499 "solder_paste_rel_margin, length, skew, via_count, via_diameter, "
500 "diff_pair_gap or diff_pair_uncoupled" ) );
540 msg.Printf(
_(
"Unrecognized item '%s'.| Expected %s." ), FromUTF8(),
541 wxT(
"assertion, clearance, hole_clearance, edge_clearance, physical_clearance, "
542 "physical_hole_clearance, courtyard_clearance, silk_clearance, hole_size, "
543 "hole_to_hole, track_width, track_angle, track_segment_length, annular_width, "
544 "disallow, zone_connection, thermal_relief_gap, thermal_spoke_width, "
545 "min_resolved_spokes, solder_mask_expansion, solder_paste_abs_margin, "
546 "solder_paste_rel_margin, length, skew, via_count, via_diameter, "
547 "diff_pair_gap or diff_pair_uncoupled" ) );
553 msg.Printf(
_(
"Rule already has a '%s' constraint." ), FromUTF8() );
565 for( token = NextTok(); token != T_RIGHT; token = NextTok() )
568 token = GetCurStrAsToken();
588 msg.Printf(
_(
"Unrecognized item '%s'.| Expected %s." ), FromUTF8(),
589 wxT(
"track, via, micro_via, buried_via, pad, zone, text, graphic, "
590 "hole, or footprint." ) );
607 token = GetCurStrAsToken();
612 case T_thermal_reliefs: c.
m_ZoneConnection = ZONE_CONNECTION::THERMAL;
break;
620 msg.Printf(
_(
"Unrecognized item '%s'.| Expected %s." ), FromUTF8(),
621 "solid, thermal_reliefs or none." );
643 value = (int) strtol( CurText(),
nullptr, 10 );
665 if( IsSymbol( token ) )
672 msg.Printf(
_(
"Unrecognized item '%s'.| Expected quoted expression." ), FromUTF8() );
678 reportError( wxString::Format(
_(
"Unrecognized item '%s'." ), FromUTF8() ) );
686 for( token = NextTok(); token != T_RIGHT && token != T_EOF; token = NextTok() )
688 if( token != T_LEFT )
695 case T_within_diff_pairs:
698 reportError(
_(
"within_diff_pairs option invalid for constraint type." ) );
706 reportError( wxString::Format(
_(
"Unrecognized item '%s'." ), FromUTF8() ) );
714 size_t offset = CurOffset() + GetTokenString( token ).length();
724 validateAndSetValueWithUnits( value, units,
725 [&c](
const int aValue )
735 size_t offset = CurOffset() + GetTokenString( token ).length();
745 validateAndSetValueWithUnits( value, units,
746 [&c](
const int aValue )
756 size_t offset = CurOffset() + GetTokenString( token ).length();
766 validateAndSetValueWithUnits( value, units,
767 [&c](
const int aValue )
780 msg.Printf(
_(
"Unrecognized item '%s'.| Expected %s." ), FromUTF8(),
781 wxT(
"min, max, or opt" ) );
798 aUnits = EDA_UNITS::UNSCALED;
801 [&](
const wxString& message,
int offset )
804 wxString first = message.BeforeFirst(
'|', &rest );
808 wxString msg = wxString::Format(
_(
"ERROR: <a href='%d:%d'>%s</a>%s" ),
818 wxString msg = wxString::Format(
_(
"ERROR: %s%s" ), first, rest );
821 CurOffset() + aOffset );
831 aResult = evaluator.
Result();
832 aUnits = evaluator.
Units();
840 int token = NextTok();
847 else if( token == T_outer )
849 *aSource = GetTokenString( token );
852 else if( token == T_inner )
854 *aSource = GetTokenString( token );
859 wxString layerName = FromUTF8();
862 for(
unsigned ii = 0; ii < layerMap.GetCount(); ++ii )
864 wxPGChoiceEntry& entry = layerMap[ii];
866 if( entry.GetText().Matches( layerName ) )
868 *aSource = layerName;
875 reportError( wxString::Format(
_(
"Unrecognized layer '%s'." ), layerName ) );
882 reportError( wxString::Format(
_(
"Unrecognized item '%s'." ), FromUTF8() ) );
897 if( (
int) token ==
DSN_RIGHT || token == T_EOF )
911 msg.Printf(
_(
"Unrecognized item '%s'.| Expected %s." ), FromUTF8(),
912 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)
wxString parseExpression()
std::shared_ptr< COMPONENT_CLASS_ASSIGNMENT_RULE > parseComponentClassAssignment()
void reportDeprecation(const wxString &oldToken, const wxString &newToken)
void Parse(std::vector< std::shared_ptr< DRC_RULE > > &aRules, REPORTER *aReporter)
void parseValueWithUnits(int aOffset, const wxString &aExpr, int &aResult, EDA_UNITS &aUnits, bool aUnitless=false)
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)
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 const LSET & ExternalCuMask()
Return a mask holding the Front and Bottom layers.
static const LSET & AllLayersMask()
static LSET AllCuMask()
return AllCuMask( MAX_CU_LAYERS );
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
@ SOLDER_PASTE_ABS_MARGIN_CONSTRAINT
@ SOLDER_MASK_EXPANSION_CONSTRAINT
@ PHYSICAL_CLEARANCE_CONSTRAINT
@ SOLDER_PASTE_REL_MARGIN_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)