classify

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: Apache-2.0 Imports: 8 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
	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
	ClassUnknown              = model.ClassUnknown
)
View Source
const AttrDeclaredRole = "declared_role"

AttrDeclaredRole is the ir.Net.attributes key carrying a role the SOURCE FILE stated outright, already translated into the NetRole vocabulary above by the reader that understood the format. 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 every reader's spelling normalizes to, GREEK CAPITAL LETTER OMEGA (U+03A9). Designs also carry the visually IDENTICAL OHM SIGN (U+2126) and a bare "R", which a consumer comparing unit strings would treat as three different units.

Variables

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

MPNAliases are the attribute keys a source spells a manufacturer part number with, in preference order. Sources disagree on separator and case, and this list covers that variance.

Exported because a reader needs the same spellings to find the fact in its own grammar (EDIF scans cell `property` nodes by name), while deciding where the fact lands is this pass's job.

These are read-only. Nothing writes a canonical MPN attribute; the answer is the typed ir.Component.mpn field, and these are the raw keys it is derived FROM.

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; its recorded source is UPGRADED when src is stronger, which is a note about provenance and never a change to 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: the ingestion pass (names and format declarations) and the params tier (a datasheet's pin functions). A declared ground whose name also spells "GND" stays declared, and running a pass twice merges rather than duplicating.

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 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 class the specificity table ranks comes before one it does not, and two unranked classes keep the order the evidence tiers wrote them in. The convention tier stamps first, so a datasheet class the table does not know stays behind the keyword-derived one rather than displacing it.

The set the ingestion pass alone produces is already in this order (ClassesOf writes the specific class 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 the evidence each tag carries. 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, so a consumer does 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 carry.

func ConventionRoles added in v0.2.0

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

ConventionRoles builds the role set a naming convention would stamp, 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 FirstPart

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

FirstPart resolves the first PartType any of a component's sections references, using an index from PartIndex; nil when no section resolves (a component with no known part type). It is the part-type signal the class derivation reads (name/kind, designator prefix).

func HasClassTags added in v0.2.2

func HasClassTags(d *ir.Design) bool

HasClassTags reports whether any component in the design carries a device-class tag, which is how a consumer tells a design the classify pass has seen from a hand-authored IR that never went through it. 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 the roles a net carries, dropping the evidence. The typed counterpart of RoleTokens, for a caller comparing against the vocabulary rather than rendering it.

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 a design carries:

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 land on 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 carries both the qualified "library/part" key and a loose "/part" key that matches when a section omits the library ref, PLUS a fallback alias on the part's native id (see below). It is shared by Stamp and check.NewModel so both resolve parts identically.

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 just the role tokens a net carries, dropping the evidence. 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, and Loader.ReadDesign is where its place in the pass order lives. 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, run after Stamp and StampMPN, because Stamp REPLACES the class set and the join key is the MPN that StampMPN fills. It also needs a params corpus, which a read without one never has (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 when the read carries a corpus and check.Model when the model is given one 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 fills ir.Component.mpn once at ingestion, for every format. It is a DERIVED-NORMALIZATION pass under C9: no reader populates the field, and a design built without the pass leaves it empty, which consumers read as "no part number stated".

It is a shared pass rather than reader work (agni issue 519), because a reader promoting the number privately leaves every other format with an empty component.mpn and a silently disabled parameter tier. See docsite/content/build/format-reader.md#the-part-number-is-the-one-to-get-wrong-quietly.

Three sources, most specific first, and it 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, the same resolution Stamp and check.NewModel use, so a component's class and its part number cannot disagree about which part type it has.

Idempotent, since a component that already has one is skipped.

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, which consumers read 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 supply pins a reader left under-typed (WS3-072 PR2), once at ingestion. KiCad and gEDA already mark a VCC/VIN pin POWER_IN, so it is a no-op there. EDIF's port grammar carries only INPUT/OUTPUT/INOUT, so a VDD pin reads as plain INPUT, and this promotes it where the direction is under-specified AND the pin 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, which meets carve-out condition (c). It mutates the shared part-type pins, so a promotion holds for every instance of the part. 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, which carries 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: 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: the specific class plus its family tag, the ClassesOf set with its evidence attached.

Types

type ClassVocab

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

ClassVocab is the component-classification lexicon, holding per-class regex patterns matched against a part's text TOKENS to hint its ComponentClass and the ref-des prefix table that gives a part its base class. Like the RoleVocab naming lexicon (WS3-069), a project extends it through config (an ESD-array MPN family, a house part-name convention, a TH prefix for its thermistors) or tightens 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, and Replace drops the built-in patterns 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 is the built-in classification lexicon, the tokenClasses map inverted to 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 is the base class a ref-des letter prefix ("R", "TP") conventionally marks, or ClassUnknown when neither the built-in table nor the project names it. The prefix is expected uppercased, as refDesPrefix returns it.

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.

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 (the part's designator_prefix, then whole-token hints in its name/kind and the component's Value attribute) overrides or refines it. 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" stays a resistor; with no base class the token decides outright. It is the pure, single-class derivation Stamp and check.Model share.

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 stays stable 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, so a consumer wanting one answer (the model) and one wanting the list (the drawing) 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), then to the raw string cast for an unknown-but-meaningful value (identity, the pass-through the additive enrichment relies on). An empty string yields ClassUnknown. This is what the datasheet enrichment runs before ClassesOf, so a vendor spelling reaches 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. It is the validation a config loader uses 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 one READ is performed with: 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. It is a VALUE carried by the loader, not 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), after which rules read the data and the vocabulary is spent (WS3-072's left-shift). The package-level Stamp, StampNetRoles, StampValues and StampPowerInPins are the process-level forms of the methods here, reading 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, the value a read with no project convention uses.

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, 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, which keeps a re-stamp idempotent and also drops any datasheet tag an earlier StampClassesFromSpecs added, so StampClassesFromSpecs must run after it. See docsite/content/architecture/ingestion-and-ir.md#derived-fields-and-the-tiers-that-fill-them.

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 whatever attribute its format spelled the value in (WS3-118), so a rule 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). One whose value text could not be parsed gets a Quantity carrying the input with the number absent, and 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 RoleVocab

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

RoleVocab is the naming lexicon, the regex sets that decide a net's electrical ROLE by name (rail, ground, feedback), for the cases where a directionless netlist carries the name as the only 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) 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) IsFeedback

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

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) 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

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 part of the notation that is specified: IEC 60062's RKM code and the SI prefixes. No specification says what unit a BARE number carries, 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 through --conventions 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, the "number known, unit not" state Quantity exists to represent.

func BuildValueVocab

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

BuildValueVocab returns a vocabulary from declared conventions, a map of device-class name to the SI BASE unit a bare number on that class means ("ohm"/"farad"/"henry" are accepted alongside the symbols). An empty or nil config yields the defaults. A class the config names replaces the default for that class; classes it does not name keep theirs.

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 a value on this component class is measured in when the notation stated none. prefixed says whether the value carried a multiplier ("10u" yes, "100" no), which 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