ident

package
v0.3.13 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: Apache-2.0 Imports: 6 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 ident compares identifiers that name the same thing in two documents that spell it differently: a pin map against a netlist, a selected function against a vendor's pin table.

That comparison is where false warnings come from (agni issue 517). We reproduced a shipped in-house checker against a large production board, and EVERY warning that run produced was a string-comparison artifact rather than a design defect. The pin was legal in all of them and the two strings naming it disagreed.

ONE canonical form, defined once, applied to BOTH sides. That tool carried two normalizers with opposite conventions (one stripped leading zeros, PTA00 to PTA0; the other padded to two digits, PTE7 to PTE07) on the same field, and it worked only because each ran on its own side of a comparison. Everything here goes through Canonical, and a caller comparing raw strings brings that bug back.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Alternatives

func Alternatives(s string) []string

Alternatives splits a cell that may name several functions into the ones it names, always keeping the WHOLE cell as the first alternative.

Keeping the whole string makes this safe on a name that legitimately contains a separator. `R/W` is an ordinary pin name (read/write), and a splitter returning only the halves would compare `R` against a table and lose the name that was actually written. The caller reports WHICH reading matched.

Both sides of a comparison are split by this same function, which fixes the largest class of false warning we measured. That tool looked for a separator only in the AVAILABLE function name, so a map cell reading `GPIO[34] / WKPU[8]` could not match a table listing `GPIO[34]` and `WKPU[8]` on separate rows, though both halves are legal on that pin.

func Canonical

func Canonical(s string) string

Canonical is the one canonical form of an identifier, and the only spelling anything in this package compares.

The stage order matters. NFKC first, so a fullwidth digit lifted out of a PDF becomes the ASCII one and a non-breaking space becomes an ordinary space that the whitespace stage can then remove. Format characters next, since they survive NFKC untouched. Upper case after that, because vendor tables mix camel-case and upper-case spellings of one peripheral freely. Whitespace removed rather than collapsed, because a multi-valued cell is split by Alternatives BEFORE this runs, so no separator depends on the whitespace surviving. The index last, once the digits are ASCII.

func CompareNatural added in v0.3.10

func CompareNatural(x, y string) int

CompareNatural compares two names with their digit runs read as numbers, so R2 < R10 and U10.3 < U10.12. Text runs compare case-insensitively, and the plain strings break a tie, so R01 and R1 still order the same way every time.

It is the order a reader expects a list of ref-des, pins or nets in, and it lives here rather than in service so core/check can order evidence the way Tabulate orders a name column (agni issue 1165). The query panel sorts with its own copy, held to this one by testdata/natural_twin.json.

func PinName added in v0.3.4

func PinName(s string) string

PinName is the key a pin's FUNCTIONAL name is compared on, Canonical with underscores removed.

Pin names are compared more loosely than net names because the two sides split a subscript differently: a datasheet prints `V CCA` and a symbol library writes `VCC_A`. A net name is the design's own identifier and keeps its underscores, which is also why this is not folded into Canonical, whose fuzzy pass splits on them.

The underscore goes AFTER the index rewrite, so `IO0_1` keys as `IO01` and never meets a distinct `IO1` on the same part. Dropping it first would let the index rewrite strip the bank digit's zero.

A subscript written as markup folds the same way (agni issue 1160): KiCad's `VCC_{A}` and a datasheet's `VCC(A)` both key as `VCCA`, since a symbol library and a pin table print one supply pin those two ways. The parenthesized form folds only for one to three letters or digits, which is how a pin table prints a domain, so a longer note such as `PB3(SWO_TRACE)` is left as written. KiCad's overbar `~{RESET}` is NOT folded, since it marks an active-low pin, a different pin from `RESET`.

func PinNumber added in v0.3.4

func PinNumber(s string) string

PinNumber is the key a pin's package designator is compared on. It is Canonical without the index rewrite, so `01` and `A01` keep their zeros, since a pinout that writes one never writes the other, while a zero-width or full-width character pasted out of a PDF still settles.

Types

type Match

type Match string

Match is how closely two identifiers agree. The three positive answers are kept apart because a reviewer does something different about each, and a bool would make a checker either noisy or silently permissive.

const (
	// Exact means the two strings are byte-identical. Nothing was done to reach this.
	Exact Match = "exact"
	// Normalized means equal once both sides were canonicalized. It is a real match, and Note says
	// what differed ("these differ only by a character you cannot see") so the author can fix the map.
	Normalized Match = "normalized"
	// Fuzzy means equal only after factoring out tokens one side carries and the other does not. It
	// must be REPORTED rather than passed silently, because the tool inferred the match. Vendor tables
	// are inconsistent with themselves (see tokenSubsequence), so an author cannot be asked to guess
	// which spelling a checker prefers.
	Fuzzy Match = "fuzzy"
	// None means no reading of either string makes them agree.
	None Match = "none"
)

type Result

type Result struct {
	// Match is how closely the two agree.
	Match Match
	// Note says what had to be done to reach a Normalized or Fuzzy match, phrased for the person
	// reading the finding. Empty for Exact and None.
	Note string
	// A and B are the alternatives that actually matched, which is not always the strings passed in.
	// Either side may be a multi-valued cell, and naming the half that matched lets a reviewer confirm
	// the answer without re-deriving it.
	A, B string
}

Result is one comparison and why it came out that way.

func Compare

func Compare(a, b string) Result

Compare reports whether two identifiers name the same thing, and what had to be done to say so.

It tries the readings in order of how much they assume: byte equality, then canonical equality, then a token-subsequence match. The first that succeeds wins, so a pair that agrees exactly is never reported as having needed normalizing.

Every alternative on the left is tried against every alternative on the right, and the result names the pair that matched.

Jump to

Keyboard shortcuts

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