25#include <drc_rules_lexer.h>
32using namespace DRCRULE_T;
36 DRC_RULES_LEXER( aSource.
ToStdString(), aSourceDescr ),
46 reportErrorAt( aMessage, CurLineNumber(), CurOffset() + aOffset, CurLine() );
53 wxString first = aMessage.BeforeFirst(
'|', &rest );
57 wxString msg = wxString::Format(
_(
"ERROR: <a href='%d:%d'>%s</a>%s" ),
67 wxString msg = wxString::Format(
_(
"ERROR: %s%s" ), first, rest );
78 wxString msg = wxString::Format(
_(
"The '%s' keyword has been deprecated. "
79 "Please use '%s' instead." ),
90 for(
size_t pos = curText.find(
"${" ); pos != std::string::npos;
91 pos = curText.find(
"${", pos + 2 ) )
93 size_t end = curText.find(
'}', pos + 2 );
95 if(
end != std::string::npos )
97 wxString token = wxString::FromUTF8( curText.substr( pos + 2,
end - ( pos + 2 ) ) );
105 reportError(
_(
"Unresolved text variable" ), (
int) pos );
117 for(
T token = NextTok(); token != T_EOF; token = NextTok() )
119 if( token == T_LEFT )
122 if( token == T_RIGHT )
135 if( curText.starts_with(
"${" ) )
136 msg.Printf(
_(
"Unresolved text variable." ) );
138 msg.Printf(
_(
"Unrecognized item '%s'.| Expected %s." ), FromUTF8(), expectedTokens );
150 for(
T token = NextTok(); token != T_EOF; token = NextTok() )
152 if( token == T_LEFT )
155 if( token == T_RIGHT )
161 if( !expr.IsEmpty() )
162 expr += CurSeparator();
174 bool haveVersion =
false;
179 for(
T token = NextTok(); token != T_EOF; token = NextTok() )
184 if( token != T_LEFT )
189 if( !haveVersion && token != T_version )
229 expected( wxT(
"rule or version" ) );
241 std::vector<std::shared_ptr<COMPONENT_CLASS_ASSIGNMENT_RULE>>& aRules,
REPORTER* aReporter )
243 bool haveVersion =
false;
248 for(
T token = NextTok(); token != T_EOF; token = NextTok() )
250 if( token != T_LEFT )
255 if( !haveVersion && token != T_version )
286 case T_assign_component_class:
295 expected( wxT(
"assign_component_class or version" ) );
308 std::shared_ptr<DRC_RULE> rule = std::make_shared<DRC_RULE>();
309 int conditionLine = 0;
310 int conditionOffset = 0;
311 std::string conditionSource;
316 if( !IsSymbol( token ) )
320 rule->m_Name = FromUTF8();
322 for( token = NextTok(); token != T_RIGHT && token != T_EOF; token = NextTok() )
327 if( token != T_LEFT )
345 else if( IsSymbol( token ) )
349 conditionLine = CurLineNumber();
350 conditionOffset = CurOffset();
351 conditionSource = CurLine();
353 if( !rule->m_Condition->Compile(
m_reporter, CurLineNumber(), CurOffset() ) )
354 reportError( wxString::Format(
_(
"Could not parse expression '%s'." ), FromUTF8() ) );
370 rule->m_LayerCondition =
parseLayer( &rule->m_LayerSource );
382 expected( wxT(
"constraint, condition, or disallow" ) );
389 if( rule->m_Condition && rule->m_Condition->RequiresPairItems() )
394 if( !rule->m_Condition->ReferencesItemB()
405 _(
"Item 'B' is not available for a single-item constraint in rule '%s'." ), rule->m_Name ),
406 conditionLine, conditionOffset, conditionSource.c_str() );
418 std::shared_ptr<DRC_RULE_CONDITION> condition;
423 if( !IsSymbol( token ) )
427 wxString componentClass = FromUTF8();
429 for( token = NextTok(); token != T_RIGHT && token != T_EOF; token = NextTok() )
431 if( token != T_LEFT )
445 else if( IsSymbol( token ) )
448 condition = std::make_shared<DRC_RULE_CONDITION>( FromUTF8() );
450 if( !condition->Compile(
m_reporter, CurLineNumber(), CurOffset() ) )
451 reportError( wxString::Format(
_(
"Could not parse expression '%s'." ), FromUTF8() ) );
475 return std::make_shared<COMPONENT_CLASS_ASSIGNMENT_RULE>( componentClass, std::move( condition ) );
486 bool allowsTimeDomain =
false;
488 auto validateAndSetValueWithUnits =
489 [
this, &allowsTimeDomain, &
unitsType, &c](
int aValue,
const EDA_UNITS aUnits,
auto aSetter )
494 reportError(
_(
"Time based units not allowed for constraint type." ) );
499 reportError(
_(
"Mixed units for constraint values." ) );
505 if( allowsTimeDomain )
525 if( token == T_mechanical_clearance )
528 token = T_physical_clearance;
530 else if( token == T_mechanical_hole_clearance )
532 reportDeprecation( wxT(
"mechanical_hole_clearance" ), wxT(
"physical_hole_clearance" ) );
533 token = T_physical_hole_clearance;
535 else if( token == T_hole )
540 else if( (
int) token ==
DSN_RIGHT || token == T_EOF )
542 msg.Printf(
_(
"Missing constraint type.| Expected %s." ),
543 wxT(
"assertion, clearance, hole_clearance, edge_clearance, physical_clearance, "
544 "physical_hole_clearance, courtyard_clearance, silk_clearance, hole_size, "
545 "hole_to_hole, track_width, track_angle, track_segment_length, annular_width, "
546 "disallow, zone_connection, thermal_relief_gap, thermal_spoke_width, "
547 "min_resolved_spokes, microvia_stack_depth, microvia_aspect_ratio, solder_mask_expansion, "
548 "solder_paste_abs_margin, "
549 "solder_paste_rel_margin, length, net_chain_length, skew, via_count, "
550 "via_dangling, via_diameter, diff_pair_gap or diff_pair_uncoupled" ) );
599 expected( wxT(
"assertion, clearance, hole_clearance, edge_clearance, physical_clearance, "
600 "physical_hole_clearance, courtyard_clearance, silk_clearance, hole_size, "
601 "hole_to_hole, track_width, track_angle, track_segment_length, annular_width, "
602 "disallow, zone_connection, thermal_relief_gap, thermal_spoke_width, "
603 "min_resolved_spokes, microvia_stack_depth, microvia_aspect_ratio, solder_mask_expansion, "
604 "solder_mask_sliver, "
605 "solder_paste_abs_margin, solder_paste_rel_margin, length, net_chain_length, "
606 "skew, via_count, via_dangling, via_diameter, diff_pair_gap, "
607 "diff_pair_uncoupled or bridged_mask" ) );
613 msg.Printf(
_(
"Rule already has a '%s' constraint." ), FromUTF8() );
629 for( token = NextTok(); token != T_RIGHT; token = NextTok() )
632 token = GetCurStrAsToken();
657 expected( wxT(
"track, via, through_via, blind_via, micro_via, buried_via, pad, zone, text, "
658 "graphic, hole, or footprint." ) );
672 for( token = NextTok(); token != T_RIGHT; token = NextTok() )
674 if( token == T_LEFT )
680 NeedSYMBOLorNUMBER();
686 NeedSYMBOLorNUMBER();
697 while( NextTok() != T_RIGHT )
711 token = GetCurStrAsToken();
724 expected( wxT(
"solid, thermal_reliefs or none." ) );
745 value = (int) strtol( CurText(),
nullptr, 10 );
766 if( IsSymbol( token ) )
772 reportError(
_(
"Item 'B' is not available in assertion expressions." ) );
786 for( token = NextTok(); token != T_RIGHT && token != T_EOF; token = NextTok() )
788 if( token != T_LEFT )
795 case T_within_diff_pairs:
799 reportError(
_(
"within_diff_pairs option invalid for constraint type." ) );
808 size_t offset = CurOffset() + GetTokenString( token ).length();
818 validateAndSetValueWithUnits( value, units,
819 [&c](
const int aValue )
829 size_t offset = CurOffset() + GetTokenString( token ).length();
839 validateAndSetValueWithUnits( value, units,
840 [&c](
const int aValue )
850 size_t offset = CurOffset() + GetTokenString( token ).length();
860 validateAndSetValueWithUnits( value, units,
861 [&c](
const int aValue )
874 expected( wxT(
"min, max, opt, or within_diff_pairs" ) );
883 bool aUnitless,
bool aRatio )
889 [&](
const wxString& message,
int offset )
892 wxString first = message.BeforeFirst(
'|', &rest );
896 wxString msg = wxString::Format(
_(
"ERROR: <a href='%d:%d'>%s</a>%s" ),
906 wxString msg = wxString::Format(
_(
"ERROR: %s%s" ), first, rest );
909 CurOffset() + aOffset );
921 aUnits = evaluator.
Units();
929 int token = NextTok();
936 else if( token == T_outer )
938 *aSource = GetTokenString( token );
941 else if( token == T_inner )
943 *aSource = GetTokenString( token );
948 wxString layerName = FromUTF8();
951 for(
unsigned ii = 0; ii < layerMap.GetCount(); ++ii )
953 wxPGChoiceEntry& entry = layerMap[ii];
955 if( entry.GetText().Matches( layerName ) )
957 *aSource = layerName;
965 reportError( wxString::Format(
_(
"Unrecognized layer '%s'." ), layerName ) );
985 if( (
int) token ==
DSN_RIGHT || token == T_EOF )
999 expected( wxT(
"ignore, warning, error, or exclusion" ) );
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
BASE_SET & set(size_t pos)
DRC_RULE_CONDITION * m_Test
void SetOption(OPTIONS option)
ZONE_CONNECTION m_ZoneConnection
wxString m_ReferenceLayer
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 reportError(const wxString &aMessage, int aOffset=0)
void parseValueWithUnits(int aOffset, const wxString &aExpr, int &aResult, EDA_UNITS &aUnits, bool aUnitless=false, bool aRatio=false)
void ParseComponentClassAssignmentRules(std::vector< std::shared_ptr< COMPONENT_CLASS_ASSIGNMENT_RULE > > &aRules, REPORTER *aReporter)
void expected(const wxString &expectedTokens)
bool checkUnresolvedTextVariable()
std::shared_ptr< DRC_RULE > parseDRC_RULE()
LSET parseLayer(wxString *aSource)
void parseConstraint(DRC_RULE *aRule)
void reportErrorAt(const wxString &aMessage, int aLine, int aOffset, const char *aSourceLine)
DRC_RULES_PARSER(const wxString &aSource, const wxString &aSourceDescr)
bool Compile(REPORTER *aReporter, int aSourceLine=0, int aSourceOffset=0)
bool RequiresPairItems() const
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 & AllCuMask()
return AllCuMask( MAX_CU_LAYERS );
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.
double ResultAsDouble() const
Unrounded result, for constraints whose value is a ratio rather than a count or a length.
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.
static EDA_DATA_TYPE GetTypeFromUnits(const EDA_UNITS aUnits)
Gets the inferred type from the given units.
bool IsComponentClassSelector(const wxString &aToken)
${Class:X} inside a DRC rule is a component-class selector consumed by testFootprintSelector(),...
@ DRC_DISALLOW_BURIED_VIAS
@ DRC_DISALLOW_BLIND_VIAS
@ DRC_DISALLOW_THROUGH_VIAS
@ DRC_DISALLOW_FOOTPRINTS
@ DRC_DISALLOW_MICRO_VIAS
@ ANNULAR_WIDTH_CONSTRAINT
@ BRIDGED_MASK_CONSTRAINT
@ COURTYARD_CLEARANCE_CONSTRAINT
@ VIA_DIAMETER_CONSTRAINT
@ ZONE_CONNECTION_CONSTRAINT
@ DIFF_PAIR_GAP_CONSTRAINT
@ NET_CHAIN_LENGTH_CONSTRAINT
@ VIA_DANGLING_CONSTRAINT
@ SOLDER_MASK_SLIVER_CONSTRAINT
@ NET_CHAIN_STUB_LENGTH_CONSTRAINT
@ SILK_CLEARANCE_CONSTRAINT
@ EDGE_CLEARANCE_CONSTRAINT
@ MIN_RESOLVED_SPOKES_CONSTRAINT
@ TRACK_SEGMENT_LENGTH_CONSTRAINT
@ TEXT_THICKNESS_CONSTRAINT
@ NET_CHAIN_RETURN_PATH_CONSTRAINT
@ PHYSICAL_HOLE_CLEARANCE_CONSTRAINT
@ MICROVIA_ASPECT_RATIO_CONSTRAINT
@ THERMAL_SPOKE_WIDTH_CONSTRAINT
@ CONNECTION_WIDTH_CONSTRAINT
@ THERMAL_RELIEF_GAP_CONSTRAINT
@ MAX_UNCOUPLED_CONSTRAINT
@ MICROVIA_STACK_DEPTH_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
static std::string ToStdString(const wxString &aStr)
EDA_DATA_TYPE
The type of unit.
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
PCB_LAYER_ID ToLAYER_ID(int aLayer)
VECTOR3I expected(15, 30, 45)
@ THERMAL
Use thermal relief for pads.
@ NONE
Pads are not covered.
@ FULL
pads are covered by copper