Class Reg<V, N, F, L>

    An immutable bidirectional string-lens description. Build with the typed leaf builders and combinators, then bind/view onto a Cell<string>.

    The four type parameters are phantom: V is the parsed value, N whether it accepts "", and F/L the character classes its match can begin/end with. F/L/N drive the compile-time ambiguity checks; they have no runtime presence.

    Type Parameters

    • V = RegVal
    • N extends boolean = boolean
    • F extends Bound = AnyBound
    • L extends Bound = AnyBound
    Index

    Methods

    • Bind named captures (.as) to editable handles over source: a string capture → Writable<Str>, a star capture → Arr<string>.

      Pass opts.schema ({ name: "str" | "arr" }) for known keys and per-handle types without casts.

      Type Parameters

      Parameters

      • source: Cell<string>
      • opts: { schema: S }

      Returns { [K in string | number | symbol]: HandleOf<S[K]> }

    • Bind named captures (.as) to editable handles over source: a string capture → Writable<Str>, a star capture → Arr<string>.

      Pass opts.schema ({ name: "str" | "arr" }) for known keys and per-handle types without casts.

      Parameters

      Returns Record<string, Handle>

    • Parse s fully (must consume to the end); null if it doesn't match. Single-pass and linear.

      Parameters

      • s: string

      Returns V | null

    • This grammar as a first-class, composable Optic<string, V>: get parses (falling back to the default value off-language), put reprints and round-trip-guards (an off-language source or a non-round-tripping value leaves the source untouched). Drops straight into compose(...) and cell.through(...), so it chains with atKey/iso and string lenses like caseFold.

      Returns Optic<string, V>

    • Iterate one-or-more (forbids the empty list when unseparated).

      Type Parameters

      • Vs = never
      • Ns extends boolean = boolean
      • Fs extends Bound = Bound
      • Ls extends Bound = Bound

      Parameters

      • this: Reg<V, N, F, L>
      • Optionalsep: Reg<Vs, Ns, Fs, Ls>
      • opts: { key?: (item: string) => string } = {}

      Returns Reg<StarVal<V>, N, F, L>

    • Source spans of each named capture, keyed by name — the get/put correspondence made visible. Empty if s doesn't fully match.

      Parameters

      • s: string

      Returns Record<string, Span>

    • Iterate zero-or-more, optionally separated by sep; binds to an Arr. A separated star is a split (≥1 piece, like Str.split). Pass opts.key for resourceful alignment across reorders.

      Type Parameters

      • Vs = never
      • Ns extends boolean = boolean
      • Fs extends Bound = Bound
      • Ls extends Bound = Bound

      Parameters

      • this: Reg<V, N, F, L>
      • Optionalsep: Reg<Vs, Ns, Fs, Ls>
      • opts: { key?: (item: string) => string } = {}

      Returns Reg<StarVal<V>, true, F, L>

    • seq(this, ...next). A provably-overlapping boundary between this and the next part is a type error — so a.then(b).then(c) statically checks every link. Interior boundaries of a multi-arg call, and the copy/of escapes, are checked at construction (throws).

      Type Parameters

      • T extends readonly AnyReg[]

      Parameters

      • this: Reg<V, N, F, L>
      • ...next: T extends readonly [H, AnyReg]
            ? Overlaps<L, FirstOf<H>> extends true ? readonly AdjErr[] : T
            : T

      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[]]>,
      >

    • Ordered union; branches must be first-disjoint (checked).

      Type Parameters

      • T extends readonly AnyReg[]

      Parameters

      • ...branches: T

      Returns Reg<AltOf<T>, AltNull<T>, AltFirst<T>, AltLast<T>>

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

    • One or more digits, \d+, as a string.

      Returns Reg<string, false, DigitBound, DigitBound>

    • One or more digits, decoded as a number (a quotient lens — leading zeros are not preserved).

      Returns Reg<number, false, DigitBound, DigitBound>

    • One or more ASCII letters, [A-Za-z]+.

      Returns Reg<string, false, LetterBound, LetterBound>

    • A fixed delimiter: matched and printed, never surfaced as a value.

      Type Parameters

      • T extends string

      Parameters

      • text: T

      Returns Reg<
          Silent,
          T extends "" ? true : false,
          LitBound<FirstChar<T>>,
          LitBound<LastChar<T>>,
      >

    • Typed escape hatch: re recognizes, codec decodes/encodes.

      Type Parameters

      • T

      Parameters

      Returns Reg<T, boolean, AnyBound, AnyBound>

    • Optional (part or nothing). part must be non-nullable. The value is the inner value when present and null when absent; an optional with no value of its own (e.g. lit(...).optional()) records presence as true.

      Type Parameters

      • V2
      • F2 extends Bound
      • L2 extends Bound

      Parameters

      Returns Reg<OptVal<V2>, true, F2, L2>

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

    • Text up to (but not including) the delimiter c — i.e. [^c]*. Nullable (an empty field is allowed); the natural companion of star(lit(c)).

      Type Parameters

      • C extends string

      Parameters

      Returns Reg<string, true, UntilBound<C>, UntilBound<C>>

    • One or more word characters, \w+ (letters, digits, underscore).

      Returns Reg<string, false, WordBound, WordBound>