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. Please use '%s' instead." ),
89 for(
size_t pos = curText.find(
"${" ); pos != std::string::npos;
90 pos = curText.find(
"${", pos + 2 ) )
92 size_t end = curText.find(
'}', pos + 2 );
94 if(
end != std::string::npos )
96 wxString token = wxString::FromUTF8( curText.substr( pos + 2,
end - ( pos + 2 ) ) );
104 reportError(
_(
"Unresolved text variable" ), (
int) pos );
116 for(
T token = NextTok(); token != T_EOF; token = NextTok() )
118 if( token == T_LEFT )
121 if( token == T_RIGHT )
134 if( curText.starts_with(
"${" ) )
135 msg.Printf(
_(
"Unresolved text variable." ) );
137 msg.Printf(
_(
"Unrecognized item '%s'.| Expected %s." ), FromUTF8(), expectedTokens );
149 for(
T token = NextTok(); token != T_EOF; token = NextTok() )
151 if( token == T_LEFT )
154 if( token == T_RIGHT )
160 if( !expr.IsEmpty() )
161 expr += CurSeparator();
173 bool haveVersion =
false;
177 for(
T token = NextTok(); token != T_EOF; token = NextTok() )
182 if( token != T_LEFT )
187 if( !haveVersion && token != T_version )
227 expected( wxT(
"rule or version" ) );
239 std::vector<std::shared_ptr<COMPONENT_CLASS_ASSIGNMENT_RULE>>& aRules,
REPORTER* aReporter )
241 bool haveVersion =
false;
245 for(
T token = NextTok(); token != T_EOF; token = NextTok() )
247 if( token != T_LEFT )
252 if( !haveVersion && token != T_version )
283 case T_assign_component_class:
292 expected( wxT(
"assign_component_class or version" ) );
305 std::shared_ptr<DRC_RULE> rule = std::make_shared<DRC_RULE>();
306 int conditionLine = 0;
307 int conditionOffset = 0;
308 std::string conditionSource;
312 if( !IsSymbol( token ) )
316 rule->m_Name = FromUTF8();
318 for( token = NextTok(); token != T_RIGHT && token != T_EOF; token = NextTok() )
323 if( token != T_LEFT )
341 else if( IsSymbol( token ) )
345 conditionLine = CurLineNumber();
346 conditionOffset = CurOffset();
347 conditionSource = CurLine();
349 if( !rule->m_Condition->Compile(
m_reporter, CurLineNumber(), CurOffset() ) )
350 reportError( wxString::Format(
_(
"Could not parse expression '%s'." ), FromUTF8() ) );
366 rule->m_LayerCondition =
parseLayer( &rule->m_LayerSource );
378 expected( wxT(
"constraint, condition, or disallow" ) );
385 if( rule->m_Condition && rule->m_Condition->RequiresPairItems() )
390 if( !rule->m_Condition->ReferencesItemB()
401 _(
"Item 'B' is not available for a single-item constraint in rule '%s'." ), rule->m_Name ),
402 conditionLine, conditionOffset, conditionSource.c_str() );
414 std::shared_ptr<DRC_RULE_CONDITION> condition;
418 if( !IsSymbol( token ) )
422 wxString componentClass = FromUTF8();
424 for( token = NextTok(); token != T_RIGHT && token != T_EOF; token = NextTok() )
426 if( token != T_LEFT )
440 else if( IsSymbol( token ) )
443 condition = std::make_shared<DRC_RULE_CONDITION>( FromUTF8() );
445 if( !condition->Compile(
m_reporter, CurLineNumber(), CurOffset() ) )
446 reportError( wxString::Format(
_(
"Could not parse expression '%s'." ), FromUTF8() ) );
470 return std::make_shared<COMPONENT_CLASS_ASSIGNMENT_RULE>( componentClass, std::move( condition ) );
481 bool allowsTimeDomain =
false;
483 auto validateAndSetValueWithUnits =
484 [
this, &allowsTimeDomain, &
unitsType, &c](
int aValue,
const EDA_UNITS aUnits,
auto aSetter )
489 reportError(
_(
"Time based units not allowed for constraint type." ) );
494 reportError(
_(
"Mixed units for constraint values." ) );
500 if( allowsTimeDomain )
520 if( token == T_mechanical_clearance )
523 token = T_physical_clearance;
525 else if( token == T_mechanical_hole_clearance )
527 reportDeprecation( wxT(
"mechanical_hole_clearance" ), wxT(
"physical_hole_clearance" ) );
528 token = T_physical_hole_clearance;
530 else if( token == T_hole )
535 else if( (
int) token ==
DSN_RIGHT || token == T_EOF )
537 msg.Printf(
_(
"Missing constraint type.| Expected %s." ),
538 wxT(
"assertion, clearance, hole_clearance, edge_clearance, physical_clearance, "
539 "physical_hole_clearance, courtyard_clearance, silk_clearance, hole_size, "
540 "hole_to_hole, track_width, track_angle, track_segment_length, annular_width, "
541 "disallow, zone_connection, thermal_relief_gap, thermal_spoke_width, "
542 "min_resolved_spokes, microvia_stack_depth, hole_aspect_ratio, solder_mask_expansion, "
543 "solder_paste_abs_margin, "
544 "solder_paste_rel_margin, length, net_chain_length, skew, via_count, "
545 "via_dangling, via_diameter, diff_pair_gap or diff_pair_uncoupled" ) );
595 expected( wxT(
"assertion, clearance, hole_clearance, edge_clearance, physical_clearance, "
596 "physical_hole_clearance, courtyard_clearance, silk_clearance, hole_size, "
597 "hole_to_hole, track_width, track_angle, track_segment_length, annular_width, "
598 "disallow, zone_connection, thermal_relief_gap, thermal_spoke_width, "
599 "min_resolved_spokes, microvia_stack_depth, hole_aspect_ratio, solder_mask_expansion, "
600 "solder_mask_sliver, "
601 "solder_paste_abs_margin, solder_paste_rel_margin, length, line_width, net_chain_length, "
602 "skew, via_count, via_dangling, via_diameter, diff_pair_gap, "
603 "diff_pair_uncoupled or bridged_mask" ) );
609 msg.Printf(
_(
"Rule already has a '%s' constraint." ), FromUTF8() );
615 bool unitless = ratio
633 for( token = NextTok(); token != T_RIGHT; token = NextTok() )
636 token = GetCurStrAsToken();
661 expected( wxT(
"track, via, through_via, blind_via, micro_via, buried_via, pad, zone, text, "
662 "graphic, hole, or footprint." ) );
676 for( token = NextTok(); token != T_RIGHT; token = NextTok() )
678 if( token == T_LEFT )
684 NeedSYMBOLorNUMBER();
690 NeedSYMBOLorNUMBER();
701 while( NextTok() != T_RIGHT )
715 token = GetCurStrAsToken();
728 expected( wxT(
"solid, thermal_reliefs or none." ) );
749 value = (int) strtol( CurText(),
nullptr, 10 );
770 if( IsSymbol( token ) )
776 reportError(
_(
"Item 'B' is not available in assertion expressions." ) );
790 for( token = NextTok(); token != T_RIGHT && token != T_EOF; token = NextTok() )
792 if( token != T_LEFT )
799 case T_within_diff_pairs:
803 reportError(
_(
"within_diff_pairs option invalid for constraint type." ) );
812 size_t offset = CurOffset() + GetTokenString( token ).length();
822 validateAndSetValueWithUnits( value, units,
823 [&c](
const int aValue )
833 size_t offset = CurOffset() + GetTokenString( token ).length();
843 validateAndSetValueWithUnits( value, units,
844 [&c](
const int aValue )
854 size_t offset = CurOffset() + GetTokenString( token ).length();
864 validateAndSetValueWithUnits( value, units,
865 [&c](
const int aValue )
878 expected( wxT(
"min, max, opt, or within_diff_pairs" ) );
887 bool aUnitless,
bool aRatio,
bool aImpliedDegrees )
893 [&](
const wxString&
message,
int offset )
896 wxString first =
message.BeforeFirst(
'|', &rest );
900 wxString msg = wxString::Format(
_(
"ERROR: <a href='%d:%d'>%s</a>%s" ),
910 wxString msg = wxString::Format(
_(
"ERROR: %s%s" ), first, rest );
913 CurOffset() + aOffset );
925 aUnits = evaluator.
Units();
933 int token = NextTok();
940 else if( token == T_outer )
942 *aSource = GetTokenString( token );
945 else if( token == T_inner )
947 *aSource = GetTokenString( token );
952 wxString layerName = FromUTF8();
955 for(
unsigned ii = 0; ii < layerMap.GetCount(); ++ii )
957 wxPGChoiceEntry& entry = layerMap[ii];
959 if( entry.GetText().Matches( layerName ) )
961 *aSource = layerName;
969 reportError( wxString::Format(
_(
"Unrecognized layer '%s'." ), layerName ) );
988 if( (
int) token ==
DSN_RIGHT || token == T_EOF )
1002 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()
void parseValueWithUnits(int aOffset, const wxString &aExpr, int &aResult, EDA_UNITS &aUnits, bool aUnitless=false, bool aRatio=false, bool aImpliedDegrees=false)
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 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.
@ 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
@ HOLE_ASPECT_RATIO_CONSTRAINT
@ NET_CHAIN_RETURN_PATH_CONSTRAINT
@ PHYSICAL_HOLE_CLEARANCE_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
bool IsComponentClassSelector(const wxString &aToken)
${Class:X} inside a DRC rule is a component-class selector consumed by testFootprintSelector(),...
#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