29#include <drc_rules_lexer.h>
33using namespace DRCRULE_T;
37 DRC_RULES_LEXER( aSource.ToStdString(), aSourceDescr ),
38 m_requiredVersion( 0 ),
46 DRC_RULES_LEXER( aFile, aFilename ),
47 m_requiredVersion( 0 ),
57 wxString first = aMessage.BeforeFirst(
'|', &rest );
61 wxString msg = wxString::Format(
_(
"ERROR: <a href='%d:%d'>%s</a>%s" ), CurLineNumber(),
62 CurOffset(), first, rest );
68 wxString msg = wxString::Format(
_(
"ERROR: %s%s" ), first, rest );
79 wxString msg = wxString::Format(
_(
"The '%s' keyword has been deprecated. "
80 "Please use '%s' instead." ),
93 for( T token = NextTok(); token != T_EOF; token = NextTok() )
98 if( token == T_RIGHT )
109 bool haveVersion =
false;
114 for( T token = NextTok(); token != T_EOF; token = NextTok() )
116 if( token != T_LEFT )
121 if( !haveVersion && token != T_version )
147 msg.Printf(
_(
"Unrecognized item '%s'.| Expected version number." ),
154 msg.Printf(
_(
"Unrecognized item '%s'." ),
171 msg.Printf(
_(
"Unrecognized item '%s'.| Expected %s." ), FromUTF8(),
172 wxT(
"rule or version" ) );
187 std::shared_ptr<DRC_RULE> rule = std::make_shared<DRC_RULE>();
192 if( !IsSymbol( token ) )
195 rule->m_Name = FromUTF8();
197 for( token = NextTok(); token != T_RIGHT && token != T_EOF; token = NextTok() )
199 if( token != T_LEFT )
219 if( IsSymbol( token ) )
222 rule->m_Condition->Compile(
m_reporter, CurLineNumber(), CurOffset() );
226 msg.Printf(
_(
"Unrecognized item '%s'.| Expected quoted expression." ),
233 reportError( wxString::Format(
_(
"Unrecognized item '%s'." ), FromUTF8() ) );
242 rule->m_LayerSource = FromUTF8();
255 msg.Printf(
_(
"Unrecognized item '%s'.| Expected %s." ), FromUTF8(),
256 wxT(
"constraint, condition, or disallow" ) );
277 if( token == T_mechanical_clearance )
280 token = T_physical_clearance;
282 else if( token == T_mechanical_hole_clearance )
284 reportDeprecation( wxT(
"mechanical_hole_clearance" ), wxT(
"physical_hole_clearance" ) );
285 token = T_physical_hole_clearance;
287 else if( token == T_hole )
292 else if( (
int) token ==
DSN_RIGHT || token == T_EOF )
294 msg.Printf(
_(
"Missing constraint type.| Expected %s." ),
295 wxT(
"assertion, clearance, hole_clearance, edge_clearance, "
296 "physical_clearance, physical_hole_clearance, courtyard_clearance, "
297 "silk_clearance, hole_size, hole_to_hole, track_width, annular_width, "
298 "via_diameter, disallow, zone_connection, thermal_relief_gap, "
299 "thermal_spoke_width, min_resolved_spokes, length, skew, via_count, "
300 "diff_pair_gap or diff_pair_uncoupled" ) );
337 msg.Printf(
_(
"Unrecognized item '%s'.| Expected %s." ), FromUTF8(),
338 wxT(
"assertion, clearance, hole_clearance, edge_clearance, "
339 "physical_clearance, physical_hole_clearance, courtyard_clearance, "
340 "silk_clearance, hole_size, hole_to_hole, track_width, track_angle, track_segment_length, annular_width, "
341 "disallow, zone_connection, thermal_relief_gap, thermal_spoke_width, "
342 "min_resolved_spokes, length, skew, via_count, via_diameter, "
343 "diff_pair_gap or diff_pair_uncoupled" ) );
349 msg.Printf(
_(
"Rule already has a '%s' constraint." ), FromUTF8() );
359 for( token = NextTok(); token != T_RIGHT; token = NextTok() )
362 token = GetCurStrAsToken();
382 msg.Printf(
_(
"Unrecognized item '%s'.| Expected %s." ), FromUTF8(),
383 wxT(
"track, via, micro_via, buried_via, pad, zone, text, graphic, "
384 "hole, or footprint." ) );
401 token = GetCurStrAsToken();
406 case T_thermal_reliefs: c.
m_ZoneConnection = ZONE_CONNECTION::THERMAL;
break;
414 msg.Printf(
_(
"Unrecognized item '%s'.| Expected %s." ), FromUTF8(),
415 "solid, thermal_reliefs or none." );
437 value = (int) strtol( CurText(),
nullptr, 10 );
459 if( IsSymbol( token ) )
466 msg.Printf(
_(
"Unrecognized item '%s'.| Expected quoted expression." ), FromUTF8() );
472 reportError( wxString::Format(
_(
"Unrecognized item '%s'." ), FromUTF8() ) );
480 for( token = NextTok(); token != T_RIGHT && token != T_EOF; token = NextTok() )
482 if( token != T_LEFT )
489 case T_within_diff_pairs:
492 reportError(
_(
"within_diff_pairs option invalid for constraint type." ) );
500 reportError( wxString::Format(
_(
"Unrecognized item '%s'." ), FromUTF8() ) );
519 reportError( wxString::Format(
_(
"Unrecognized item '%s'." ), FromUTF8() ) );
540 reportError( wxString::Format(
_(
"Unrecognized item '%s'." ), FromUTF8() ) );
560 reportError( wxString::Format(
_(
"Unrecognized item '%s'." ), FromUTF8() ) );
571 msg.Printf(
_(
"Unrecognized item '%s'.| Expected %s." ),
573 wxT(
"min, max, or opt" ) );
588 auto errorHandler = [&](
const wxString& aMessage,
int aOffset )
591 wxString first = aMessage.BeforeFirst(
'|', &rest );
595 wxString msg = wxString::Format(
_(
"ERROR: <a href='%d:%d'>%s</a>%s" ),
596 CurLineNumber(), CurOffset() + aOffset, first, rest );
602 wxString msg = wxString::Format(
_(
"ERROR: %s%s" ), first, rest );
605 CurOffset() + aOffset );
614 aResult = evaluator.
Result();
621 int token = NextTok();
628 else if( token == T_outer )
632 else if( token == T_inner )
638 wxString layerName = FromUTF8();
641 for(
unsigned ii = 0; ii < layerMap.GetCount(); ++ii )
643 wxPGChoiceEntry& entry = layerMap[ii];
645 if( entry.GetText().Matches( layerName ) )
651 reportError( wxString::Format(
_(
"Unrecognized layer '%s'." ), layerName ) );
658 reportError( wxString::Format(
_(
"Unrecognized item '%s'." ), FromUTF8() ) );
673 if( (
int) token ==
DSN_RIGHT || token == T_EOF )
687 msg.Printf(
_(
"Unrecognized item '%s'.| Expected %s." ),
689 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 parseValueWithUnits(const wxString &aExpr, int &aResult, bool aUnitless=false)
void Parse(std::vector< std::shared_ptr< DRC_RULE > > &aRules, REPORTER *aReporter)
std::shared_ptr< DRC_RULE > parseDRC_RULE()
void parseConstraint(DRC_RULE *aRule)
void reportError(const wxString &aMessage)
DRC_RULES_PARSER(const wxString &aSource, const wxString &aSourceDescr)
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 ExternalCuMask()
Return a mask holding the Front and Bottom layers.
static LSET AllLayersMask()
static LSET InternalCuMask()
Return a complete set of internal copper layers which is all Cu layers except F_Cu and B_Cu.
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
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)=0
Report a string with a given severity.
@ 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
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
PCB_LAYER_ID ToLAYER_ID(int aLayer)