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() ) );
240 rule->m_LayerSource = FromUTF8();
253 msg.Printf(
_(
"Unrecognized item '%s'.| Expected %s." ), FromUTF8(),
254 wxT(
"constraint, condition, or disallow" ) );
275 if( token == T_mechanical_clearance )
278 token = T_physical_clearance;
280 else if( token == T_mechanical_hole_clearance )
282 reportDeprecation( wxT(
"mechanical_hole_clearance" ), wxT(
"physical_hole_clearance" ) );
283 token = T_physical_hole_clearance;
285 else if( token == T_hole )
290 else if( (
int) token ==
DSN_RIGHT || token == T_EOF )
292 msg.Printf(
_(
"Missing constraint type.| Expected %s." ),
293 wxT(
"assertion, clearance, hole_clearance, edge_clearance, "
294 "physical_clearance, physical_hole_clearance, courtyard_clearance, "
295 "silk_clearance, hole_size, hole_to_hole, track_width, annular_width, "
296 "via_diameter, disallow, zone_connection, thermal_relief_gap, "
297 "thermal_spoke_width, min_resolved_spokes, length, skew, via_count, "
298 "diff_pair_gap or diff_pair_uncoupled" ) );
332 msg.Printf(
_(
"Unrecognized item '%s'.| Expected %s." ), FromUTF8(),
333 wxT(
"assertion, clearance, hole_clearance, edge_clearance, "
334 "physical_clearance, physical_hole_clearance, courtyard_clearance, "
335 "silk_clearance, hole_size, hole_to_hole, track_width, annular_width, "
336 "disallow, zone_connection, thermal_relief_gap, thermal_spoke_width, "
337 "min_resolved_spokes, length, skew, via_count, via_diameter, "
338 "diff_pair_gap or diff_pair_uncoupled" ) );
344 msg.Printf(
_(
"Rule already has a '%s' constraint." ), FromUTF8() );
353 for( token = NextTok(); token != T_RIGHT; token = NextTok() )
356 token = GetCurStrAsToken();
376 msg.Printf(
_(
"Unrecognized item '%s'.| Expected %s." ), FromUTF8(),
377 wxT(
"track, via, micro_via, buried_via, pad, zone, text, graphic, "
378 "hole, or footprint." ) );
395 token = GetCurStrAsToken();
400 case T_thermal_reliefs: c.
m_ZoneConnection = ZONE_CONNECTION::THERMAL;
break;
408 msg.Printf(
_(
"Unrecognized item '%s'.| Expected %s." ), FromUTF8(),
409 "solid, thermal_reliefs or none." );
431 value = (int) strtol( CurText(),
nullptr, 10 );
453 if( IsSymbol( token ) )
460 msg.Printf(
_(
"Unrecognized item '%s'.| Expected quoted expression." ), FromUTF8() );
466 reportError( wxString::Format(
_(
"Unrecognized item '%s'." ), FromUTF8() ) );
474 for( token = NextTok(); token != T_RIGHT && token != T_EOF; token = NextTok() )
476 if( token != T_LEFT )
497 reportError( wxString::Format(
_(
"Unrecognized item '%s'." ), FromUTF8() ) );
518 reportError( wxString::Format(
_(
"Unrecognized item '%s'." ), FromUTF8() ) );
538 reportError( wxString::Format(
_(
"Unrecognized item '%s'." ), FromUTF8() ) );
549 msg.Printf(
_(
"Unrecognized item '%s'.| Expected %s." ),
551 wxT(
"min, max, or opt" ) );
566 auto errorHandler = [&](
const wxString& aMessage,
int aOffset )
569 wxString first = aMessage.BeforeFirst(
'|', &rest );
573 wxString msg = wxString::Format(
_(
"ERROR: <a href='%d:%d'>%s</a>%s" ),
574 CurLineNumber(), CurOffset() + aOffset, first, rest );
580 wxString msg = wxString::Format(
_(
"ERROR: %s%s" ), first, rest );
583 CurOffset() + aOffset );
592 aResult = evaluator.
Result();
599 int token = NextTok();
606 else if( token == T_outer )
610 else if( token == T_inner )
616 wxString layerName = FromUTF8();
619 for(
unsigned ii = 0; ii < layerMap.GetCount(); ++ii )
621 wxPGChoiceEntry& entry = layerMap[ii];
623 if( entry.GetText().Matches( layerName ) )
629 reportError( wxString::Format(
_(
"Unrecognized layer '%s'." ), layerName ) );
636 reportError( wxString::Format(
_(
"Unrecognized item '%s'." ), FromUTF8() ) );
651 if( (
int) token ==
DSN_RIGHT || token == T_EOF )
665 msg.Printf(
_(
"Unrecognized item '%s'.| Expected %s." ),
667 wxT(
"ignore, warning, error, or exclusion" ) );
DRC_RULE_CONDITION * m_Test
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 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_MAX_UNCOUPLED_CONSTRAINT
@ DIFF_PAIR_GAP_CONSTRAINT
@ SILK_CLEARANCE_CONSTRAINT
@ EDGE_CLEARANCE_CONSTRAINT
@ MIN_RESOLVED_SPOKES_CONSTRAINT
@ TEXT_THICKNESS_CONSTRAINT
@ PHYSICAL_HOLE_CLEARANCE_CONSTRAINT
@ THERMAL_SPOKE_WIDTH_CONSTRAINT
@ CONNECTION_WIDTH_CONSTRAINT
@ THERMAL_RELIEF_GAP_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)