Module matcher

Source
Description

User-extensible search-pattern interface.

Matcher abstracts "things that can answer whether, and where, an element matches inside a haystack". It's the foundation for pluggable .find / .contains / .split on Str and any Seq-like type. This module supplies the trait, four built-in impls (Str, Codepoint, (Vec Codepoint), (Vec U8)), and a blanket impl for quotations.

Matcher carries both elem and haystack as primary parameters today; the CodepointMatcher / ByteMatcher constraint aliases recover the single-parameter shape. Byte-index ranges use (Range AnyInt) and the byte matcher's haystack and element are (Vec AnyInt) / AnyInt — both sharpen to the narrower AnyUInt and U8 shapes once the corresponding checker plumbing lands.

Abstractions

Traits

ByteMatcher

Convenience constraint alias: "any matcher whose haystack is a

CodepointMatcher

Convenience constraint alias: "any matcher whose haystack is Str

Matcher

Search-pattern interface.

Trait Implementations

impl Matcher Str Codepoint for Codepoint

A Codepoint is a matcher that matches its UTF-8-encoded single character inside a Str. .find-in encodes the codepoint to a one-char Str and delegates to str-find.

.find-all-in ( Codepoint Str (Vec (Range (Int ..))) )

.find-in ( Codepoint Str (Option (Range (Int ..))) )

impl Matcher Vec(?620312) ?620312 for [?620312 -> Bool]

Blanket impl: any quotation [elem -> Bool] is itself a matcher against a (Vec elem) haystack. Interprets "match at position i" as "quot applied to element i returns true".

Spec canonical shape is [ (Seq elem _) AnyUInt -> (Option AnyUInt) ] — a next-match driver that receives the remaining-haystack view and a starting offset and returns the end offset of the match. That shape lets matchers scan arbitrarily forward. Today the checker cannot dispatch blanket impls whose Self is a quotation type of that full shape, and structural-search-over-Seq-existentials is not expressible either, so this impl lands in a simpler predicate flavour: [elem -> Bool] walking a (Vec elem) haystack one element at a time. The driver-style blanket impl will land once those checker features arrive.

.find-all-in ( [elem Bool ] (Vec elem) (Vec (Range (Int ..))) )

.find-in ( [elem Bool ] (Vec elem) (Option (Range (Int ..))) )

impl Matcher Str Codepoint for Str

Str is a matcher that matches itself byte-identically inside another Str. .find-in delegates to the host str-find intrinsic and shapes the byte offset into Some (RangeBoth start end) or None. .find-all-in walks the input with successive slices.

.find-all-in ( Str Str (Vec (Range (Int ..))) )

.find-in ( Str Str (Option (Range (Int ..))) )

impl Matcher Vec(Int(..)) Int(..) for Vec(Int(..))

.find-all-in ( (Vec (Int ..)) (Vec (Int ..)) (Vec (Range (Int ..))) )

.find-in ( (Vec (Int ..)) (Vec (Int ..)) (Option (Range (Int ..))) )

impl Matcher Str Codepoint for Vec(Codepoint)

A (Vec Codepoint) is a matcher that matches any codepoint in the set. Walks the haystack by byte offset via str-next-char.

.find-all-in ( (Vec Codepoint) Str (Vec (Range (Int ..))) )

.find-in ( (Vec Codepoint) Str (Option (Range (Int ..))) )