Class Reg<V, N, F, L>
Type Parameters
- V = RegVal
- N extends boolean = boolean
- F extends Bound = AnyBound
- L extends Bound = AnyBound
Methods
as
bind
- bind<S extends Record<string, HandleKind>>(
source: Cell<string>,
opts: { schema: S },
): { [K in string | number | symbol]: HandleOf<S[K]> }Bind named captures (
.as) to editable handles oversource: a string capture →Writable<Str>, astarcapture →Arr<string>.Pass
opts.schema({ name: "str" | "arr" }) for known keys and per-handle types without casts.Type Parameters
- S extends Record<string, HandleKind>
Returns { [K in string | number | symbol]: HandleOf<S[K]> }
map
match
Parse
sfully (must consume to the end);nullif it doesn't match. Single-pass and linear.Parameters
- s: string
Returns V | null
optic
This grammar as a first-class, composable
Optic<string, V>:getparses (falling back to the default value off-language),putreprints and round-trip-guards (an off-language source or a non-round-tripping value leaves the source untouched). Drops straight intocompose(...)andcell.through(...), so it chains withatKey/isoand string lenses likecaseFold.Returns Optic<string, V>
optional
or
plus
spans
Source spans of each named capture, keyed by name — the
get/putcorrespondence made visible. Empty ifsdoesn't fully match.Parameters
- s: string
Returns Record<string, Span>
star
- star<
Vs = never,
Ns extends boolean = boolean,
Fs extends Bound = Bound,
Ls extends Bound = Bound,
>(
this: Reg<V, N, F, L>,
sep?: Reg<Vs, Ns, Fs, Ls>,
opts?: { key?: (item: string) => string },
): Reg<StarVal<V>, true, F, L>Iterate zero-or-more, optionally separated by
sep; binds to anArr. A separated star is a split (≥1 piece, likeStr.split). Passopts.keyfor resourceful alignment across reorders.Type Parameters
- Vs = never
- Ns extends boolean = boolean
- Fs extends Bound = Bound
- Ls extends Bound = Bound
Parameters
Returns Reg<StarVal<V>, true, F, L>
test
Does
sfully match? Linear.Parameters
- s: string
Returns boolean
then
- then<T extends readonly AnyReg[]>(
this: Reg<V, N, F, L>,
...next: T extends readonly [H, AnyReg]
? Overlaps<L, FirstOf<H>> extends true ? readonly AdjErr[] : T
: T,
): Reg<
SeqVal<[Reg<V, N, F, L>, ...T[]]>,
SeqNull<[Reg<V, N, F, L>, ...T[]]>,
SeqFirst<[Reg<V, N, F, L>, ...T[]]>,
SeqLast<[Reg<V, N, F, L>, ...T[]]>,
>seq(this, ...next). A provably-overlapping boundary betweenthisand the next part is a type error — soa.then(b).then(c)statically checks every link. Interior boundaries of a multi-arg call, and thecopy/ofescapes, are checked at construction (throws).Type Parameters
- T extends readonly AnyReg[]
Parameters
Returns Reg<
SeqVal<[Reg<V, N, F, L>, ...T[]]>,
SeqNull<[Reg<V, N, F, L>, ...T[]]>,
SeqFirst<[Reg<V, N, F, L>, ...T[]]>,
SeqLast<[Reg<V, N, F, L>, ...T[]]>,
>
view
Staticalt
Staticcopy
The escape hatch: capture the text matched by an arbitrary regular
re. Non-regular constructs (anchors, lookaround, backreferences) throw. The boundary is opaque to the type system (AnyBound), so adjacency can't be checked at compile time — the construction-time check still applies.Parameters
- re: RegExp
Returns Reg<string, boolean, AnyBound, AnyBound>
Staticdigits
One or more digits,
\d+, as a string.Returns Reg<string, false, DigitBound, DigitBound>
Staticint
One or more digits, decoded as a
number(a quotient lens — leading zeros are not preserved).Returns Reg<number, false, DigitBound, DigitBound>
Staticletters
One or more ASCII letters,
[A-Za-z]+.Returns Reg<string, false, LetterBound, LetterBound>
Staticlit
Staticof
Staticopt
Staticseq
- seq<T extends readonly AnyReg[]>(
...parts: T,
): Reg<SeqVal<T>, SeqNull<T>, SeqFirst<T>, SeqLast<T>>Unambiguous concatenation; every boundary is checked here and throws on ambiguity. (For compile-time adjacency checking, prefer the fluent
a.then(b).then(c), which validates each link.)Type Parameters
- T extends readonly AnyReg[]
Parameters
- ...parts: T
Returns Reg<SeqVal<T>, SeqNull<T>, SeqFirst<T>, SeqLast<T>>
Staticuntil
Staticword
One or more word characters,
\w+(letters, digits, underscore).Returns Reg<string, false, WordBound, WordBound>
An immutable bidirectional string-lens description. Build with the typed leaf builders and combinators, then
bind/viewonto aCell<string>.The four type parameters are phantom:
Vis the parsed value,Nwhether it accepts "", andF/Lthe character classes its match can begin/end with.F/L/Ndrive the compile-time ambiguity checks; they have no runtime presence.