classify

package
v0.11.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 10 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package classify holds the format-neutral ingestion passes that stamp derived facts onto the IR, so check reads a data fact instead of re-parsing vendor strings on every model build. The first was the component-classification pass (WS3-071), which derives a device class from ref-des prefix and part-type tokens. The package also owns the net-role vocabulary, the value parser and the MPN stamp. It imports the generated ir and config protos and the model read-surface contract, and check and formats both depend on it.

Index

Constants

View Source
const (
	ClassResistor             = model.ClassResistor
	ClassCapacitor            = model.ClassCapacitor
	ClassInductor             = model.ClassInductor
	ClassFerrite              = model.ClassFerrite
	ClassThermistor           = model.ClassThermistor
	ClassDiode                = model.ClassDiode
	ClassLED                  = model.ClassLED
	ClassTVS                  = model.ClassTVS
	ClassZener                = model.ClassZener
	ClassFuse                 = model.ClassFuse
	ClassNetTie               = model.ClassNetTie
	ClassConnector            = model.ClassConnector
	ClassTestConnector        = model.ClassTestConnector
	ClassTestPoint            = model.ClassTestPoint
	ClassClock                = model.ClassClock
	ClassOscillator           = model.ClassOscillator
	ClassCrystal              = model.ClassCrystal
	ClassCeramicResonator     = model.ClassCeramicResonator
	ClassIC                   = model.ClassIC
	ClassTransistor           = model.ClassTransistor
	ClassIdealDiodeController = model.ClassIdealDiodeController
	ClassCurrentLimitSwitch   = model.ClassCurrentLimitSwitch
	ClassUnknown              = model.ClassUnknown
)
View Source
const AttrDeclaredRole = "declared_role"

AttrDeclaredRole is the ir.Net.attributes key for a role that the SOURCE FILE stated outright. The reader that understood the format has already translated the role into the NetRole vocabulary above. StampNetRoles unions it with what the naming lexicon infers.

A role can be KNOWN rather than guessed. IPC-2581 declares it on LogicalNet/@netClass as a closed enum, so a net called "N$17" can be authoritatively GROUND with nothing in the name to go on.

The READER translates, per C9, so this package never learns a format's enum, and a second format that declares roles writes this same key. An UNMAPPABLE source term is not written (the reader keeps it verbatim in its own attribute), so this key holds a valid NetRole token or is absent. It is an attribute rather than a typed field because C9 admits a typed field only once a second format populates it.

View Source
const UnitOhm = "\u03a9" // Ω

UnitOhm is the canonical ohm symbol, GREEK CAPITAL LETTER OMEGA (U+03A9), and every reader's spelling normalizes to it. Designs also contain the visually IDENTICAL OHM SIGN (U+2126) and a bare "R". A consumer comparing unit strings would treat the three as different units.

Variables

View Source
var MPNAliases = []string{"MPN", "Manufacturer_PN", "Manufacturer PN", "mpn", "Part Number", "PartNumber"}

MPNAliases lists the built-in attribute keys for a manufacturer part number, in preference order. It is the default of the lexicon's attribute.mpn, and a project adds its own keys there.

It is exported because a reader needs the same spellings to find the fact in its own grammar (EDIF scans cell `property` nodes by name). This pass decides which field the fact goes into. A reader reads no configuration, so a project's own keys never reach that scan.

These are read-only. Nothing writes a canonical MPN attribute. The answer goes in the typed ir.Component.mpn field, and the pass derives it FROM these raw keys. KiCad's "Part Number" field is here since public boards (HackRF One, Cynthion) put their part numbers in it (agni 1285), and "PartNumber" since Altium boards (the foxBMS ones) spell some parts that way (agni 1349).

Functions

func AddClassTag added in v0.2.2

func AddClassTag(c *ir.Component, class string, src ir.ClassSource)

AddClassTag adds one class to a component's device_classes set, attributed to src. A class already present is not duplicated. When src is stronger, the tag's recorded source is UPGRADED, and the upgrade changes provenance and never membership. The empty and unknown classes are not facts and are dropped. It is the component twin of AddNetRole, with the same additive-only contract.

func AddNetRole added in v0.2.0

func AddNetRole(n *ir.Net, role ir.Role, src ir.RoleSource)

AddNetRole merges one role fact into a net's set, keeping the STRONGER evidence when that role is already present. Every evidence tier merges through it, both the ingestion pass (names and format declarations) and the params tier (a datasheet's pin functions). A declared ground whose name also spells "GND" keeps its declared source, and running a pass twice merges rather than duplicating.

func AddNetRoleWhy added in v0.4.0

func AddNetRoleWhy(n *ir.Net, role ir.Role, src ir.RoleSource, why string)

AddNetRoleWhy is AddNetRole with a reason for the role. The reason goes with the stronger evidence, so a role upgraded to a stronger source takes that source's reason.

func AllNetRoles added in v0.2.2

func AllNetRoles() []ir.Role

AllNetRoles is every role the engine stamps, in declaration order and without the zero value. It reads the GENERATED enum, so a role added to the proto is projected, parseable and configurable with no second list to update.

func BuiltinLexicon added in v0.4.0

func BuiltinLexicon() *configpb.NamingLexicon

BuiltinLexicon returns the engine's built-in vocabularies in the conventions schema, the class tables included, so a reader sees every default a convention can add to or replace. It is a fresh value each call.

func BySpecificity added in v0.2.2

func BySpecificity(classes []string) []string

BySpecificity orders a device_classes set most-specific first, dropping the unknown marker and the empty string. A ranked class comes before an unranked one, and two unranked classes keep the order the evidence tiers wrote. The convention tier stamps first, so a datasheet class missing from the table sorts behind the keyword-derived one rather than displacing it.

When only the ingestion pass has written the set, it is already in this order, because ClassesOf writes the specific class and then its family. So this reorders nothing until a second evidence tier contributes.

func ClassNames added in v0.2.2

func ClassNames(c *ir.Component) []string

ClassNames returns a component's device-class names, dropping each tag's evidence. It is for a consumer that asks only what a component IS; a consumer weighing how well it is known reads the tags.

func ClassesOf

func ClassesOf(cl ComponentClass) []string

ClassesOf expands a single derived class into its device_classes SET, the specific class plus its family tag. A consumer then tests membership (tvs in classes, any diode-family in classes) rather than equality. ClassUnknown yields the empty set, since "unknown" is the absence of a class fact, not a tag to record.

func ConventionRoles added in v0.2.0

func ConventionRoles(roles ...ir.Role) []*ir.NetRole

ConventionRoles builds a role set as a naming convention would stamp it, for an IR assembled by hand rather than by the ingestion pass (a test fixture, an overlay composing a design in memory). It names CONVENTION explicitly rather than leaving the source unspecified, so a hand-built net states the same thing the pass would have stated about the same name.

func DiffPairEntry added in v0.4.0

func DiffPairEntry(p *configpb.DiffSuffix) string

DiffPairEntry spells a suffix pair as a LexiconEntry's value. ParseDiffPairEntry reads it back.

func EffectiveLexicon added in v0.4.0

func EffectiveLexicon(over *configpb.NamingLexicon) *configpb.NamingLexicon

EffectiveLexicon merges the convention lexicon over with the built-ins and writes the result as one convention lexicon. Every list is written out whole with `replace: true`, so a convention holding it reads a design exactly as the merge does. The rail-inference switch is always stated.

func FirstPart

func FirstPart(index map[string]*ir.PartType, c *ir.Component) *ir.PartType

FirstPart walks a component's sections in order and returns the first PartType one of them resolves to in an index from PartIndex. It returns nil when no section resolves (a component with no known part type). The class derivation reads this part type for its name/kind and designator prefix.

func HasClassTags added in v0.2.2

func HasClassTags(d *ir.Design) bool

HasClassTags reports whether any component in the design has a device-class tag. A consumer uses it to tell a classified design from a hand-authored IR that never went through the classify pass. It is a DESIGN-level question because a single component with no tags is an ordinary unclassified part, and only the absence across the whole design says the pass never ran.

func NetRoles added in v0.2.2

func NetRoles(n *ir.Net) []ir.Role

NetRoles returns a net's roles, dropping the evidence. It is the typed counterpart of RoleTokens, for a caller comparing against the vocabulary rather than rendering it.

func ParseDiffPairEntry added in v0.4.0

func ParseDiffPairEntry(s string) *configpb.DiffSuffix

ParseDiffPairEntry reads a value DiffPairEntry wrote.

func ParsePinPairEntry added in v0.6.1

func ParsePinPairEntry(s string) *configpb.PinPair

ParsePinPairEntry reads a value PinPairEntry wrote.

func ParseQuantity

func ParseQuantity(text string) (value float64, unit string, ok bool)

ParseQuantity reads a component's value text into a number in its SI BASE unit, the unit symbol, and whether a number was found at all (WS3-118). It is the format-neutral half of the value pass, so every reader hands it whatever its dialect wrote and it applies the one grammar that is specified.

IEC 60062 defines the RKM code, where the multiplier letter stands in for the decimal point (4R7 is 4.7 Ω, 4k7 is 4700 Ω, 0R05 is 0.05 Ω, 1M5 is 1.5 MΩ). With SI prefixes that covers nearly every spelling found in designs.

quantity := mantissa prefix? unit?        // 10k, 1.5kΩ, 100nF
          | digits prefix digits          // RKM: 4k7, 0R05

The unit of a BARE number is NOT decided here, because no specification defines it; ValueVocab owns that convention. ParseQuantity returns such a number with an EMPTY unit, which is a real state and not a failure.

THE PARSE IS EXACT DECIMAL AND SCALES ONCE. A component value is printed in decimal, so the text is exact and the parse is string manipulation into (digits, decimal exponent), which scale() converts in a single operation. Reading the mantissa as a float first and scaling after rounds twice, and the two routes give DIFFERENT doubles for 1573 of the 7920 two-and-three-significant-figure values across the SI prefixes designs use. The divergence is concentrated at small magnitudes, in picofarads, where crystal load caps live and where a shipped rule already reads capacitance.

It also means two spellings of one value produce the IDENTICAL double, so a diff can compare component values across revisions by equality rather than by tolerance.

ok is false when no number could be read at all ("DNP", "", "DO NOT FIT"). The caller must keep that distinct from a value of zero, which is a legal resistance.

func ParseRole added in v0.2.2

func ParseRole(token string) (ir.Role, bool)

ParseRole maps a token back to its role, reporting whether the vocabulary has one. A reader translating a format's netclass, or a config naming a role, gets false for an unknown token rather than a value that silently matches nothing (agni 677 is the same failure for classes).

func PartIndex

func PartIndex(d *ir.Design) map[string]*ir.PartType

PartIndex indexes a design's part types by (library, part) name so a component section resolves to its PartType. It holds a qualified "library/part" key and a loose "/part" key, and the loose key matches when a section omits the library ref. It also holds a fallback alias on the part's native id (see below). Stamp and check.NewModel both use it, so both resolve parts identically.

func PinPairEntry added in v0.6.1

func PinPairEntry(p *configpb.PinPair) string

PinPairEntry spells a through pair as a LexiconEntry's value, "A{n}=B{n}". ParsePinPairEntry reads it back.

func RoleLeaf added in v0.4.0

func RoleLeaf(name string) string

RoleLeaf returns the part of a net name that the net vocabularies match. That part is the last segment of a hierarchical name, so /Power/VCC matches as VCC.

func RoleToken added in v0.2.2

func RoleToken(r ir.Role) string

RoleToken renders a role as the lowercase token the query language and the config lexicon use, so ROLE_GATE_DRIVE becomes "gate_drive". It is DERIVED from the generated enum name rather than read from a table, so the tokens cannot drift from the vocabulary and another language can apply the same transform to its own generated enum.

ROLE_UNSPECIFIED renders empty, so a zero value never reaches a fact row looking like a real role.

func RoleTokens added in v0.2.0

func RoleTokens(n *ir.Net) []string

RoleTokens returns a net's role tokens, dropping the evidence. It is for the many callers that ask WHICH roles rather than how each was established. A caller that needs the source reads the NetRole values, or asks check.NetRoleSource.

func SetActiveClassVocab

func SetActiveClassVocab(v *ClassVocab)

SetActiveClassVocab replaces the process-level classification lexicon (agni serve installs its server default this way, through naming.ApplyLexicon). Same contract as SetActiveRoleVocab, so nil restores the defaults, and it must run before ingestion because Stamp reads the active vocab.

func SetActiveRoleVocab

func SetActiveRoleVocab(v *RoleVocab)

SetActiveRoleVocab replaces the process-level lexicon (agni serve installs its server default this way). Passing nil restores the defaults. It must run before ingestion (ReadDesign), since StampNetRoles stamps net.role with the active vocab.

func Stamp

func Stamp(d *ir.Design)

Stamp runs the classification pass over a read design, filling each component's device_classes SET once at ingestion (WS3-071). It recomputes and overwrites the set, so a re-stamp is safe. formats.DeriveDesign sets its place in the pass order. It is the process-level form of (*Lexicon).Stamp (WS3-106).

func StampClassesFromSpecs added in v0.2.2

func StampClassesFromSpecs(d *ir.Design, deviceClassFor func(mpn string) string)

StampClassesFromSpecs is the DATASHEET evidence tier of the device-class stamp. For every component whose MPN joins a seeded spec carrying a device_class, it adds that class and its family tag to ir.Component.device_classes, attributed to CLASS_SOURCE_DATASHEET.

It is its own pass and runs after Stamp and StampMPN. Stamp REPLACES the class set, and StampMPN fills the MPN this pass joins on. The pass also needs a params corpus, so a read without one skips it (C9's evidence-tier variant; agni issue 280 named the case, 710 closed it). The ordering is in docsite/content/architecture/ingestion-and-ir.md#derived-fields-and-the-tiers-that-fill-them.

Only this tier can subtype a clock source (tokenClasses says why the keyword path refuses) or reach ideal_diode_controller, since no netlist labels a FET plus a bias network as one.

ADDITIVE AND IDEMPOTENT. It never removes or downgrades a convention-tier class, and a second run changes nothing. Both matter because two callers run it. The Loader runs it when the read has a corpus, and check.Model runs it when the model is given a corpus the read did not have.

deviceClassFor answers the vendor's device_class string for an MPN, or "" for a part with no spec or no class on it. It is a function rather than the param provider so classify does not import the datasheet layer.

func StampMPN added in v0.2.0

func StampMPN(d *ir.Design)

StampMPN is the process-level form of (*Lexicon).StampMPN.

func StampNetRoles

func StampNetRoles(d *ir.Design)

StampNetRoles fills each net's roles SET once at ingestion (WS3-072), so the core reads a normalized net.role fact instead of re-running name matching per net per rule. It recomputes and overwrites. A net matching no vocabulary gets an empty set. Consumers read that as "no role", the same way an empty device_classes reads as "unknown". This is the process-level form of (*Lexicon).StampNetRoles.

func StampPowerInPins

func StampPowerInPins(d *ir.Design)

StampPowerInPins FILLS the POWER_IN electrical type on under-typed supply pins (WS3-072 PR2), once at ingestion. KiCad and gEDA already mark a VCC/VIN pin POWER_IN, so it is a no-op there, and an INPUT pin in those formats is left INPUT (formatTypesPowerIn). EDIF's port grammar has only INPUT/OUTPUT/INOUT, so a VDD pin reads as plain INPUT. This pass promotes such a pin when its direction is under-specified AND its name is a supply name. Every power-pin rule then checks PinDir == POWER_IN whatever the format.

This is the FILL variant of the C9 DERIVED-NORMALIZATION carve-out. It narrows an EXISTING reader-set field only where the reader was under-specified, so a confident OUTPUT/POWER_OUT is never overwritten. When the pass did not run, the reader's INPUT stands and the power-pin rules do not fire. That outcome meets carve-out condition (c). It mutates the shared part-type pins, so a promotion applies to every instance of the part. It is idempotent.

This is the process-level form; a read carrying its own conventions calls (*Lexicon).StampPowerInPins instead (WS3-106).

func StampValues

func StampValues(d *ir.Design)

StampValues is the process-level form of (*Lexicon).StampValues, whose doc states the contract.

func Tags added in v0.2.2

func Tags(names ...string) []*ir.ComponentClassTag

Tags builds CONVENTION-tier tags from class names verbatim, for a caller writing a device_classes set by hand, such as a test IR or a host that classifies a component itself. TagsOf is the derived form, which expands one class into its family; this is the literal one, and it adds no family tag.

func TagsOf added in v0.2.2

TagsOf expands a single derived class into device_classes TAGS attributed to one source. It returns the specific class plus its family tag, which is the ClassesOf set with its evidence attached.

Types

type ClassVocab

type ClassVocab struct {
	// contains filtered or unexported fields
}

ClassVocab is the component-classification lexicon. It holds per-class regex patterns, and each is matched against a part's text TOKENS to hint its ComponentClass. It also holds the ref-des prefix table, which gives a part its base class. A project extends it through config, as it does the RoleVocab naming lexicon (WS3-069). It can add an ESD-array MPN family, a house part-name convention or a TH prefix for its thermistors, or it can tighten a fickle token (WS3-070, agni issue 677).

Patterns match a single token, case-insensitively. The built-in defaults are exact-anchored ("^tvs$") so classification is whole-token, never a substring, as tokenClasses promises. A project may use looser patterns ("^pesd") to catch a part-number family.

func ActiveClassVocab

func ActiveClassVocab() *ClassVocab

ActiveClassVocab returns the classification lexicon currently in effect.

func BuildClassVocab

func BuildClassVocab(overrides map[ComponentClass]*configpb.ClassVocab) (*ClassVocab, error)

BuildClassVocab applies per-class overrides onto DefaultClassVocab, compiling and VALIDATING each pattern and prefix (config is operator input, so a bad one is a returned error). An empty override leaves that class at its default. Replace drops the built-in patterns and families for that class and leaves its prefixes alone. A prefix is added to the built-in table and wins over it. The caller has already refused a class name the engine does not know (ParseComponentClass).

func DefaultClassVocab

func DefaultClassVocab() *ClassVocab

DefaultClassVocab returns the built-in classification lexicon. It inverts the tokenClasses map into class -> exact-anchored token patterns, so the defaults reproduce the whole-token behavior exactly.

func (*ClassVocab) ClassForPrefix added in v0.2.2

func (v *ClassVocab) ClassForPrefix(prefix string) ComponentClass

ClassForPrefix maps a ref-des letter prefix ("R", "TP") to the base class it marks by convention. It returns ClassUnknown when neither the built-in table nor the project names it. The prefix is expected uppercased, as refDesPrefix returns it.

func (*ClassVocab) FamilyClass added in v0.4.0

func (v *ClassVocab) FamilyClass(tokens []string) ComponentClass

FamilyClass returns the class whose part-number family matches one of the tokens, or "" when none does. Classes are tried in name order, so the answer does not depend on map order.

func (*ClassVocab) HintsFor

func (v *ClassVocab) HintsFor(tokens []string) map[ComponentClass]bool

HintsFor returns the set of classes whose patterns match any of the tokens (the classification hint set).

type ComponentClass

type ComponentClass = model.ComponentClass

The component-class vocabulary, re-exported from model so the classifier reads bare Class* names. A type alias is the same type, so classify.ComponentClass and model.ComponentClass interchange.

const ClassEfuse ComponentClass = "efuse"

ClassEfuse is the eFuse tag that comes from a datasheet's device_class. A project's config extends the component class vocabulary, and ClassEfuse is not in that vocabulary, because a project has no keyword that could recognise an eFuse. It exists here so an eFuse also gets ClassCurrentLimitSwitch.

func Classify

func Classify(c *ir.Component, pt *ir.PartType) ComponentClass

Classify derives the component.class fact. The ref-des prefix convention gives the base class, and part-type data then overrides or refines it. The part's designator_prefix comes first, then whole-token hints in its name/kind and in the component's attribute values. A token hint may refine a base class only within the same device family (diode -> led/tvs, inductor -> ferrite), so a resistor named "PULLUP_LED_EN" is still a resistor. With no base class the token decides outright. Stamp and check.Model share this pure, single-class derivation.

func MostSpecific

func MostSpecific(classes []string) ComponentClass

MostSpecific picks the most-specific class from a device_classes set using the classifier's specificity order. A refined subtype like tvs beats its diode family tag. So a Model exposing a single component.class gives the same answer as the set widens with family tags (WS3-071). An empty set is ClassUnknown, and a class outside the token-hint priority (ClassIC) still resolves.

It is the head of BySpecificity rather than its own walk. The model wants one answer and the drawing wants the list, and sharing the ranking means the two cannot rank a set differently (agni issue 710).

func NormalizeDeviceClass

func NormalizeDeviceClass(s string) ComponentClass

NormalizeDeviceClass maps a datasheet device_class string to a canonical ComponentClass (WS10-015). It alnum-lowercases the input and looks it up in the alias table, then falls back to the canonical class-name set (so "efuse", "ldo", "crystal" pass through as themselves). Failing both, it casts the raw string, for an unknown-but-meaningful value. The additive enrichment relies on that identity pass-through. An empty string yields ClassUnknown. The datasheet enrichment runs this before ClassesOf, so a vendor spelling gets the same family tag the keyword path would.

func ParseComponentClass

func ParseComponentClass(name string) (ComponentClass, bool)

ParseComponentClass maps a class NAME (its string value, e.g. "tvs" or "test_point") to the class, reporting whether it is a known, overridable class. A config loader validates names with it, so an unknown class name in a lexicon block is a teaching error, not a silently ignored key.

type Lexicon

type Lexicon struct {
	Role  *RoleVocab
	Class *ClassVocab
	// Value carries the bare-number unit conventions (WS3-118).
	Value *ValueVocab
}

Lexicon is the naming vocabulary for one READ. It holds the role vocabulary (rail, ground, feedback, switching, control, gate-drive and supply-pin names), the classification vocabulary (device-class token hints) and the value vocabulary. The loader holds it as a VALUE rather than a process global, so two designs read in one process can be stamped with different project conventions (WS3-106).

The stamps below turn a vocabulary into DATA (ir.Net.roles, ir.Component.device_classes, POWER_IN pin directions). Rules then read the data and no longer consult the vocabulary (WS3-072's left-shift). The package-level Stamp, StampNetRoles, StampValues and StampPowerInPins are the process-level forms of the methods here, and they read the globals through ActiveLexicon.

A nil *Lexicon means the process defaults.

func ActiveLexicon

func ActiveLexicon() *Lexicon

ActiveLexicon captures the process-level vocabularies as a value, for callers that install a convention globally (`agni serve`, through naming.ApplyLexicon). The globals are read ONCE here, at read time, rather than by every downstream name match.

func DefaultLexicon

func DefaultLexicon() *Lexicon

DefaultLexicon returns the engine's built-in vocabularies. A read with no project convention uses this value.

func (*Lexicon) ClassVocab

func (l *Lexicon) ClassVocab() *ClassVocab

ClassVocab returns the classification vocabulary in effect (the process default when unset).

func (*Lexicon) Classify

func (l *Lexicon) Classify(c *ir.Component, pt *ir.PartType) ComponentClass

Classify is the per-read form. It runs the same derivation against THIS lexicon's vocabularies rather than the process globals (WS3-106).

func (*Lexicon) RoleVocab

func (l *Lexicon) RoleVocab() *RoleVocab

RoleVocab returns the role vocabulary in effect (the process default when unset), for consumers that must match a bare NAME after the read, such as the spec-language name FFIs and pin-role derivation, which have no net to read a stamped role from.

func (*Lexicon) Stamp

func (l *Lexicon) Stamp(d *ir.Design)

Stamp runs the classification pass with this lexicon, filling each component's device_classes SET. See the package-level Stamp for the pass's contract.

It REPLACES the set. Replacing keeps a re-stamp idempotent, and it also drops any datasheet tag from an earlier StampClassesFromSpecs. So StampClassesFromSpecs must run after it. See docsite/content/architecture/ingestion-and-ir.md#derived-fields-and-the-tiers-that-fill-them.

func (*Lexicon) StampMPN added in v0.4.0

func (l *Lexicon) StampMPN(d *ir.Design)

StampMPN fills ir.Component.mpn once at ingestion, for every format. It is a DERIVED-NORMALIZATION pass under C9. No reader populates the field. A design built without the pass leaves it empty, and consumers read that as "no part number stated".

It is a shared pass rather than reader work (agni issue 519). If one reader promoted the number privately, every other format would have an empty component.mpn and a silently disabled parameter tier. See docsite/content/build/format-reader.md#getting-the-part-number-wrong-fails-quietly.

It tries three sources, most specific first, and stops at the first that answers.

  1. THE COMPONENT'S OWN ATTRIBUTES, under any alias. The usual case, since a part number is stated per placement and a library symbol is coarser than an orderable product.
  2. ITS PART TYPE's typed mpn, for the sources that model the type AS an orderable part.
  3. ITS PART TYPE's attributes, under any alias, for a reader that has not been converted to the typed field.

It resolves the part through PartIndex/FirstPart. Stamp and check.NewModel resolve it the same way, so a component's class and its part number cannot disagree about which part type it has.

It is idempotent, since it skips a component that already has an MPN. The keys come from the read's lexicon (attribute.mpn), so the pass runs in DeriveDesign rather than with the parse.

func (*Lexicon) StampNetRoles

func (l *Lexicon) StampNetRoles(d *ir.Design)

StampNetRoles fills each net's roles SET from this lexicon. See the package-level StampNetRoles.

func (*Lexicon) StampPowerInPins

func (l *Lexicon) StampPowerInPins(d *ir.Design)

StampPowerInPins promotes under-typed supply pins to POWER_IN using this lexicon's supply-pin names. See the package-level StampPowerInPins.

func (*Lexicon) StampValues

func (l *Lexicon) StampValues(d *ir.Design)

StampValues fills each component's value Quantity from its value attribute, under whatever key its format used (WS3-118). A rule then reads a NUMBER rather than re-parsing text per format. It is idempotent, recomputing and overwriting.

A component with no value attribute gets NO Quantity (nil). If its value text cannot be parsed, it gets a Quantity with the input and no number. Only that second case is a gap worth reporting.

func (*Lexicon) ValueVocab

func (l *Lexicon) ValueVocab() *ValueVocab

ValueVocab returns the bare-number unit vocabulary in effect (the built-in default when unset).

type LexiconEntry added in v0.4.0

type LexiconEntry struct {
	// Vocabulary names the entry's list by its path in the conventions YAML ("net.rail",
	// "pin.supply", "class.tvs").
	Vocabulary string
	// Kind is "pattern", "exclude", "prefix", "exclude_prefix", "family", "pair", "unit", "key" or
	// "switch". A "key" entry is one attribute key or do-not-populate value under "attribute.<list>".
	// A pair's Value is its two suffixes, or two pin-name templates, joined by "=" (see DiffPairEntry
	// and PinPairEntry). A unit's Value is the unit
	// of a bare number on the class, under the vocabulary "value_unit.<class>".
	Kind  string
	Value string
	// FromConvention is set on an entry the convention added, and clear on a built-in one.
	FromConvention bool
	// Replaced is set on a built-in entry that the convention's `replace: true` took out.
	Replaced bool
}

LexiconEntry is one pattern, exclusion, ref-des prefix, part-number family or switch of an effective lexicon. It records whether the entry came from the built-ins or from the convention laid over them (agni issue 1266).

func EffectiveEntries added in v0.4.0

func EffectiveEntries(over *configpb.NamingLexicon) []LexiconEntry

EffectiveEntries lays the convention lexicon over on the built-ins and lists the result entry by entry. It applies the same merge as BuildRoleVocab and BuildClassVocab. A list's convention entries add to its built-in ones. `replace: true` takes the built-in ones out, and they are listed with Replaced. A class's ref-des prefixes are the exception, since a replace keeps them. When the convention lists or excludes a built-in prefix under any class, the built-in entry is Replaced, since the convention's wins. A nil over lists the built-ins alone.

The order is net, pin, then class by name, each list's built-in entries before the convention's.

type RoleVocab

type RoleVocab struct {
	// These are the EFFECTIVE patterns the vocabulary was built from. A caller can read back what a
	// project installed rather than only asking yes/no questions. The message is embedded by POINTER
	// because a protobuf-go message holds a DoNotCopy. A value embedding would make every RoleVocab
	// copy a vet copylocks error.
	*configpb.NamingLexicon
	// contains filtered or unexported fields
}

RoleVocab is the naming lexicon. Its regex sets decide a net's electrical ROLE by name (rail, ground, feedback), for the cases where a directionless netlist has only the name as evidence. A project whose house naming differs extends or replaces each vocabulary via config (WS3-069). check re-exports the names (WS3-072).

Matching is on the hierarchy LEAF ("/psu/12V" -> "12V", the WS3-006 convention) and case-insensitive. The zero value is not usable; build one with DefaultRoleVocab or BuildRoleVocab.

The net vocabularies classify NET names; supplyPin classifies a component's PIN names (which supply a part CONSUMES, for the WS3-072 POWER_IN stamp). supplyPin is stricter than rail. A supply PIN is named VDD/VIN, never "3V3", and a bare "+" is a polarized-part terminal, so the net-name forms (^+, digit-then-V) and the supply OUTPUT name VOUT are absent from it.

func ActiveRoleVocab

func ActiveRoleVocab() *RoleVocab

ActiveRoleVocab returns the process-level lexicon currently in effect (the defaults unless a project config replaced it), so a caller can inspect what was installed.

func BuildRoleVocab

func BuildRoleVocab(over *configpb.NamingLexicon) (*RoleVocab, error)

BuildRoleVocab merges a project's overrides onto the built-in lexicon and compiles the result, VALIDATING every pattern, since config is operator input and a bad regex should be a returned error rather than a panic. A nil override yields the built-ins. Patterns are RE2, matched case-insensitively on the hierarchy leaf (write ^/$ for whole-leaf anchoring).

func DefaultRoleVocab

func DefaultRoleVocab() *RoleVocab

DefaultRoleVocab is the built-in lexicon, compiled. A project's config merges onto (or replaces) these; see BuildRoleVocab.

func (*RoleVocab) DiffNegative added in v0.4.0

func (v *RoleVocab) DiffNegative(name string) (string, bool)

DiffNegative returns the complementary net name for a differential pair's positive member, and ok=false when the name is not one. The longest matching positive suffix wins, and each letter of the complement's suffix takes the case of the letter it replaces, so usb_p reads usb_n and USB_dP reads USB_dN. A negative suffix longer than the positive takes the last letter's case for the rest.

func (*RoleVocab) InfersRails added in v0.4.0

func (v *RoleVocab) InfersRails() bool

func (*RoleVocab) IsAnode added in v0.4.0

func (v *RoleVocab) IsAnode(name string) bool

IsAnode and IsCathode classify a diode-family pin name, whole, and the caller applies the class gate.

func (*RoleVocab) IsCathode added in v0.4.0

func (v *RoleVocab) IsCathode(name string) bool

func (*RoleVocab) IsControl added in v0.2.2

func (v *RoleVocab) IsControl(name string) bool

func (*RoleVocab) IsDrain

func (v *RoleVocab) IsDrain(name string) bool

func (*RoleVocab) IsExposedPad added in v0.4.0

func (v *RoleVocab) IsExposedPad(name string) bool

func (*RoleVocab) IsFeedback

func (v *RoleVocab) IsFeedback(name string) bool

func (*RoleVocab) IsFeedbackPin added in v0.4.0

func (v *RoleVocab) IsFeedbackPin(name string) bool

IsFeedbackPin and IsSwitchingPin classify a part's PIN name as a regulator's feedback or switch pin.

func (*RoleVocab) IsGate

func (v *RoleVocab) IsGate(name string) bool

IsGate / IsSource / IsDrain classify a TRANSISTOR's pin name. The caller must apply the class gate, because these vocabularies are short and collide on any other part (see the type doc).

func (*RoleVocab) IsGateDrive added in v0.2.2

func (v *RoleVocab) IsGateDrive(name string) bool

func (*RoleVocab) IsGround

func (v *RoleVocab) IsGround(name string) bool

func (*RoleVocab) IsI2C added in v0.4.0

func (v *RoleVocab) IsI2C(name string) bool

IsI2C classifies a NET name as an I2C bus line, and IsExposedPad a PIN name as a package's exposed pad. InfersRails reports whether a supply-fed net may be read as a rail by a later name token.

func (*RoleVocab) IsNoConnect added in v0.4.0

func (v *RoleVocab) IsNoConnect(name string) bool

IsNoConnect reports whether a net's name says its designer left it unconnected on purpose.

func (*RoleVocab) IsRail

func (v *RoleVocab) IsRail(name string) bool

IsRail through IsGateDrive classify a NET name against the vocabulary. IsSupplyPin classifies a component's PIN name as a power-supply input, a stricter vocabulary (see the type doc).

func (*RoleVocab) IsSource

func (v *RoleVocab) IsSource(name string) bool

func (*RoleVocab) IsSupplyPin

func (v *RoleVocab) IsSupplyPin(name string) bool

func (*RoleVocab) IsSwitching added in v0.2.2

func (v *RoleVocab) IsSwitching(name string) bool

func (*RoleVocab) IsSwitchingPin added in v0.4.0

func (v *RoleVocab) IsSwitchingPin(name string) bool

func (*RoleVocab) IsUnfitted added in v0.4.0

func (v *RoleVocab) IsUnfitted(c *ir.Component) bool

IsUnfitted reports whether a component has a do-not-populate flag. The flag is an attribute.dnp key whose value is one of attribute.dnp_values. Every key is tried, so KiCad's own dnp flag set to "no" does not hide a house DNP field saying the part is not fitted. A section's attributes count too.

func (*RoleVocab) NominalVoltage added in v0.4.0

func (v *RoleVocab) NominalVoltage(name string) (volts float64, ok bool)

NominalVoltage reads a rail's nominal voltage off its net name (3V3 -> 3.3). A directionless netlist has no other voltage evidence. Each token is matched whole against the voltage vocabulary. ok is false when no token reads or two disagree ("12V_TO_5V"), and every voltage rule relies on that refusal.

func (*RoleVocab) ThroughPartners added in v0.6.1

func (v *RoleVocab) ThroughPartners(name string) []string

ThroughPartners returns the pin names that carry a pin's signal across its part, from the through pairs, in the order the pairs are listed. A name on neither side of any pair answers none. The caller looks the names up among the part's own pins, since a pair only holds where the part has both.

func (*RoleVocab) ValueText added in v0.4.0

func (v *RoleVocab) ValueText(c *ir.Component) string

ValueText returns the text of the component's attribute.value field, or "" when it has none.

type ValueVocab

type ValueVocab struct {
	// contains filtered or unexported fields
}

ValueVocab is the CONVENTION half of reading a component's value, kept out of the parser (WS3-118).

ParseQuantity implements the specified part of the notation, IEC 60062's RKM code and the SI prefixes. No specification says what unit a BARE number is in, because that depends on the component's class and on house habit. A bare "100" on a resistor is 100 Ω by universal convention; on a capacitor it could be farads, microfarads or picofarads depending on the era and the tool that wrote it. So it is a naming convention, declared under the lexicon's value_unit like the rail and ground patterns in RoleVocab.

The DEFAULT covers resistors only. Guessing a bare capacitor or inductor unit would put a number three or six orders of magnitude out into a field that reads as authoritative. An unset class yields an empty unit. Quantity exists to represent this "number known, unit not" state.

func BuildValueVocab

func BuildValueVocab(bareUnits map[string]string) (*ValueVocab, error)

BuildValueVocab returns a vocabulary from a convention's value_unit block. The block maps a device-class name to the unit of a bare number on that class. The unit is an SI base unit ("F", "ohm", "henry") or one with a multiplier prefix ("pF", "uH", "kohm"), and the prefix scales the bare number. An empty or nil config yields the defaults. Naming a class replaces that class's default, and every class the config leaves out keeps its default. A class the engine does not ship, or a unit it cannot read, is an error, since config is operator input and a skipped line reads as applied.

func DefaultValueVocab

func DefaultValueVocab() *ValueVocab

DefaultValueVocab returns the built-in bare-number conventions. A resistor's bare value is ohms and nothing else is assumed; the ValueVocab doc says why the default is this narrow.

func (*ValueVocab) UnitFor

func (v *ValueVocab) UnitFor(class ComponentClass, prefixed bool) string

UnitFor returns the unit for a value on this component class when the notation stated none. prefixed says whether the value had a multiplier ("10u" yes, "100" no), and it selects between the dimension and bareUnit cases. Empty is a real answer, not a failure.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL