Skip to main content

Module pattern

Module pattern 

Source
Expand description

A port of fzf’s query language — src/pattern.go from fzf 0.74.3.

fzf’s default search mode is EXTENDED: a query is a space-separated list of terms that must all match (AND), | between terms makes an OR set, and a term can carry a sigil that changes how it matches:

fuzzy      'exact      ^prefix      suffix$      ^equal$      'boundary'
!inverse   !'inverse-fuzzy          !^inverse-prefix          !inverse-suffix$

Everything here is a PORT, not an approximation — parseTerms, the term type flips, extendedMatch’s OR/AND/inverse walk and the sortable / cacheable flags all follow the Go source, so arb --fzf answers a query the way fzf answers it. -x/--extended and +x/--no-extended select the mode; extended is the default, as in fzf.

A Pattern is built ONCE per query and scored against every line. That is deliberate: the pattern’s Vec<char> and case decision are per-QUERY work, and doing them per line (as arb did before this module existed) cost more than the match itself on a query that rejects most of the corpus.

Structs§

Bounds
Where a pattern matched a line, folded across every term set — fzf’s buildResult inputs (result.go:32). min_begin/min_end/max_end are character indices; a term that located nothing (a satisfied !term) contributes an empty offset and is skipped.
Pattern
A parsed query, ready to score any number of lines.
Term
One term of a query: the text to look for, how to look for it, and whether finding it DISQUALIFIES the line (!).

Enums§

Criterion
One ranking criterion — fzf’s criterion (options.go:268). Score is always first; the rest are the --tiebreak list, applied in order, with the item’s input index as the final, implicit tiebreak.
TermType
How one term matches — fzf’s termType (pattern.go:22).

Functions§

compare_points
fzf’s compareRanks (result_x86.go): the four slots read as one integer, most significant first, then the item’s input index breaks a full tie.
parse_tiebreak
fzf’s parseTiebreak (options.go:1349). index adds no criterion — it IS the implicit final one — but it must come last, and no name may repeat. None for a spec fzf would reject, which keeps the caller’s default.
points
fzf’s buildResultFromBounds (result.go:54): pack the criteria into four u16 slots, best-first, so ordering is one integer comparison per pair.
scan_direction
fzf’s core.go:215: the --tiebreak criteria decide how the matchers scan. Returns (forward, with_pos).
scheme_criteria
The criteria a --scheme implies when --tiebreak is not given — fzf’s parseScheme (options.go:1336).