Std. Regex. Core
(Cure Standard Library v0.37.2)
View Source
Shared indexed Regex vocabulary and definitionally relevant shape operations.
Examples
use Std.Regex.Core
Simplify(PairC(UnitC, CharC)) # => CharC
Simplify(ListC(UnitC)) # => NatC
simplify_value(OptionC(UnitC), Some(())) # => true
Summary
Types
Ordinary boundaries remain the small ten-field context used by the existing Thompson proof. Lookaround evaluators carry their suffix and bounded history separately, so adding assertions does not perturb the ordinary proof indices.
Cure does not otherwise expose a general-purpose Either in the current prelude. Keep the branch witness local to the typed regex result universe; alternatives preserve which branch accepted.
A suffix-indexed intrinsic grammar. Encodes(shape, input, rest) proves
that one value of shape consumes a prefix of input and leaves rest.
This is the context-threaded formulation from the thesis: concatenation and
repetition compose by sharing a middle suffix, with no append theorem or
runtime boundary witness.
The runtime remainder returned by one extraction is also its result index.
Recursive callers therefore receive the exact boundary required by the next
erased Encodes witness without recovering runtime data from that witness.
Evidence is a postfix program result stored in reverse order, so emitting is constant-time. Pair/branch/list markers precede their operands in the final list, which lets the total extractor consume it in one pass.
State identifiers are naturals below state_count. Thompson construction
allocates disjoint contiguous ranges and preserves that invariant by
shifting the right machine by the left machine's count. Accepted is an
accepting edge (the paper's Nothing), not an allocated state. The runtime
transition relation is ordered and epsilon-free.
Atomic markers are semantic no-ops in the evidence VM. The ordered search
consumes them as lexical commit boundaries; keeping them in the same
routine stream makes replay and proof paths share one trace.
Minimal regular-language algebra. Every constructor fixes its result shape definitionally, so Thompson construction and evidence extraction cannot disagree later about what a successful path produces.
A transition row fixes the source state once, outside the input loop. The
spine is indexed by both its remaining rows and the machine's total state
count, so lookup by Bounded(n) has no malformed-table fallback.
Functions
Count the number of elements in a List(Unit) as a Nat.
Wrap a decoded left-branch value into Sem(ChoiceC(left, right)).
Wrap a decoded right-branch value into Sem(ChoiceC(left, right)).
Reverse a List(Char) in the evidence VM without depending on external
list helpers.
Tail-recursive accumulator helper for evidence_reverse_chars.
Extract a complete Sem(shape) value from a fully consumed Evidence
stream proved by Encodes(shape, input, Nil()).
Total proof-directed extraction (thesis §5.3 / Fig. 5.8). input is an
explicit runtime argument, exactly like the paper's ev; only encoding
is erased. The evidence marker is inspected first and its index leaves one
possible proof constructor. There is no malformed-evidence branch and no
Option after an accepting run has produced the certificate.
Extract a reversed list of repeated Sem(shape) items from input using
the erased EncodesMany proof witness, returning the remaining evidence.
Project a MachineState(n) to its underlying ThreadState(n), discarding
attached evidence instructions and boundary constraints.
Push a matched char onto every open CaptureFrame in frames.
One canonical resource bound shared by syntax admission, runtime child evaluation, and proof-facing assertion entry points. Keeping this in the core module prevents compile-time and runtime limits from drifting.
Reverse a list of decoded Sem(shape) values into forward match order.
Tail-recursive accumulator helper for reverse_sem_values.
Genuine large elimination: each value-level shape computes to its Cure result type. No runtime tag, Dynamic value, cast, or postulate is involved.
Recursively normalize a ShapeCode by eliminating redundant UnitC
structure across pairs, choices, options, and lists.
Simplify a ChoiceC(left, right) shape, collapsing two UnitC branches
into BoolC.
Simplify a choice shape whose left branch is UnitC, collapsing
ChoiceC(UnitC, UnitC) to BoolC.
Simplify a ListC(inner) shape, collapsing ListC(UnitC) to NatC.
Simplify an OptionC(inner) shape, collapsing OptionC(UnitC) to BoolC.
Simplify a PairC(left, right) shape by eliding UnitC on either side.
Simplify a pair shape whose left component is non-unit, dropping a trailing
UnitC on the right.
Normalize structural extraction shapes into ergonomic public results. Every companion value function is total at the corresponding computed type; no equality cast connects the raw and simplified interpretations.
Reduction witness checking that Sem(CharC) reduces definitionally to Char.
Reduction witness checking that nested Sem(PairC(CharC, ListC(UnitC)))
reduces definitionally to Tuple(Char, List(Unit)).
Phase-1 reduction witnesses. These bodies only check if Sem computes at constructor applications rather than behaving as an opaque type function.
Companion value transformer for SimplifyChoiceUnit, mapping
Choice(Unit, Unit) to Bool (true for left, false for right).
Companion value transformer for SimplifyChoice.
Apply simplify_value elementwise across a list of Sem(inner) values.
Companion value transformer for SimplifyList, collapsing List(Unit) to
its length as a Nat.
Companion value transformer for SimplifyOption, mapping Option(Unit) to
Bool.
Companion value transformer for SimplifyPairPresent, dropping a trailing
Unit or pairing left_value with right_value.
Companion value transformer for SimplifyPairUnit, returning right_value
directly after dropping a leading Unit.
Companion value transformer for SimplifyPair, combining simplified left
and right pair components.
Recursively simplify a value of type Sem(shape) into Sem(Simplify(shape)).
Types
enum Boundary
Boundary
Ordinary boundaries remain the small ten-field context used by the existing Thompson proof. Lookaround evaluators carry their suffix and bounded history separately, so adding assertions does not perturb the ordinary proof indices.
enum BoundaryConstraint
BoundaryConstraint
enum CaptureCondition
CaptureParticipated
CaptureAbsent
enum CaptureFrame
CaptureFrame
enum Choice
ChoseLeft
ChoseRight
Cure does not otherwise expose a general-purpose Either in the current prelude. Keep the branch witness local to the typed regex result universe; alternatives preserve which branch accepted.
type Encodes indices (shape: ShapeCode, input: List(Evidence), rest: List(Evidence))
EncodesUnit : Encodes(UnitC, Cons(UnitEvidence(), rest), rest)
EncodesCharacter : (char: Char) -> Encodes(CharC, Cons(CharacterEvidence(char), rest), rest)
EncodesString : (value: String) -> Encodes(StringC, Cons(StringEvidence(value), rest), rest)
EncodesPair : (@erased right : Encodes(right_shape, pair_evidence, left_evidence)) -> (@erased left : Encodes(left_shape, left_evidence, rest)) -> Encodes(PairC(left_shape, right_shape), Cons(PairEvidence(), pair_evidence), rest)
EncodesLeft : (@erased branch : Encodes(left, branch_evidence, rest)) -> Encodes(ChoiceC(left, right), Cons(LeftEvidence(), branch_evidence), rest)
EncodesRight : (@erased branch : Encodes(right, branch_evidence, rest)) -> Encodes(ChoiceC(left, right), Cons(RightEvidence(), branch_evidence), rest)
EncodesList : (@erased items : EncodesMany(inner, items_evidence, rest)) -> Encodes(ListC(inner), Cons(EndListEvidence(), items_evidence), rest)
A suffix-indexed intrinsic grammar. Encodes(shape, input, rest) proves
that one value of shape consumes a prefix of input and leaves rest.
This is the context-threaded formulation from the thesis: concatenation and
repetition compose by sharing a middle suffix, with no append theorem or
runtime boundary witness.
type EncodesMany indices (shape: ShapeCode, input: List(Evidence), rest: List(Evidence))
EncodesManyEmpty : EncodesMany(shape, Cons(BeginListEvidence(), rest), rest)
EncodesManyItem : (@erased item : Encodes(shape, item_evidence, prior_evidence)) -> (@erased prior : EncodesMany(shape, prior_evidence, rest)) -> EncodesMany(shape, item_evidence, rest)
type EncodingExtraction indices (shape: ShapeCode, input: List(Evidence), rest: List(Evidence))
EncodingExtracted : (remaining: List(Evidence)) -> (value: Sem(shape)) -> EncodingExtraction(shape, input, remaining)
The runtime remainder returned by one extraction is also its result index.
Recursive callers therefore receive the exact boundary required by the next
erased Encodes witness without recovering runtime data from that witness.
enum Evidence
CharacterEvidence
UnitEvidence
PairEvidence
LeftEvidence
RightEvidence
BeginListEvidence
EndListEvidence
StringEvidence
Evidence is a postfix program result stored in reverse order, so emitting is constant-time. Pair/branch/list markers precede their operands in the final list, which lets the total extractor consume it in one pass.
enum EvidenceExecution
EvidenceExecution
enum EvidenceInstruction
EmitChar
EmitUnit
EmitPair
EmitLeft
EmitRight
BeginList
EndList
BeginCapture
EndCapture
BeginCaptureSlot
EndCaptureSlot
BeginAtomic
EndAtomic
State identifiers are naturals below state_count. Thompson construction
allocates disjoint contiguous ranges and preserves that invariant by
shifting the right machine by the left machine's count. Accepted is an
accepting edge (the paper's Nothing), not an allocated state. The runtime
transition relation is ordered and epsilon-free.
Atomic markers are semantic no-ops in the evidence VM. The ordered search
consumes them as lexical commit boundaries; keeping them in the same
routine stream makes replay and proof paths share one trace.
enum EvidencePrefix
EvidencePrefix
type EvidenceThread indices (n: Nat)
EvidenceThread : ThreadState(n) -> List(Evidence) -> List(CaptureFrame) -> EvidenceThread(n)
enum InitialPosition
InitialPosition
enum LookaroundCondition
LookaheadCondition
LookbehindCondition
type LookaroundMachine
type MachineState indices (n: Nat)
Active : Bounded(n) -> List(EvidenceInstruction) -> List(BoundaryConstraint) -> MachineState(n)
Accepted : List(EvidenceInstruction) -> List(BoundaryConstraint) -> MachineState(n)
type ManyEncodingExtraction indices (shape: ShapeCode, input: List(Evidence), rest: List(Evidence))
ManyEncodingExtracted : (remaining: List(Evidence)) -> (values: List(Sem(shape))) -> ManyEncodingExtraction(shape, input, remaining)
enum NewlinePolicy
LFNewline
CRNewline
CRLFNewline
AnyCRLFNewline
AnyUnicodeNewline
type Pattern indices (shape: ShapeCode)
PatternPredicate : Function(Char, Bool) -> Pattern(CharC)
PatternEmpty : Pattern(UnitC)
PatternConcat : Pattern(left) -> Pattern(right) -> Pattern(PairC(left, right))
PatternGroup : Pattern(inner) -> Pattern(StringC)
PatternAlternate : Pattern(left) -> Pattern(right) -> Pattern(ChoiceC(left, right))
PatternAlternateMode : Pattern(left) -> Pattern(right) -> Bool -> Pattern(ChoiceC(left, right))
PatternRepeat : Pattern(inner) -> Pattern(ListC(inner))
PatternRepeatMode : Pattern(inner) -> Bool -> Pattern(ListC(inner))
PatternBoundary : BoundaryConstraint -> Pattern(UnitC)
Minimal regular-language algebra. Every constructor fixes its result shape definitionally, so Thompson construction and evidence extraction cannot disagree later about what a successful path produces.
type PatternMachine indices (n: Nat)
MkPatternMachine : List(MachineState(n)) -> Function(Bounded(n), Char, List(MachineState(n))) -> PatternMachine(n)
enum ShapeCode
UnitC
CharC
StringC
BoolC
NatC
IntC
PairC
ChoiceC
OptionC
ListC
type ThreadState indices (n: Nat)
ThreadActive : Bounded(n) -> ThreadState(n)
ThreadAccepted : ThreadState(n)
type TransitionRows indices (n: Nat)
TransitionRows : TransitionRowsFrom(n, n) -> TransitionRows(n)
type TransitionRowsFrom indices (remaining: Nat, total: Nat)
NoTransitionRows : TransitionRowsFrom(Z(), total)
MoreTransitionRows : Function(Char, List(MachineState(total))) -> TransitionRowsFrom(remaining, total) -> TransitionRowsFrom(S(remaining), total)
A transition row fixes the source state once, outside the input loop. The
spine is indexed by both its remaining rows and the machine's total state
count, so lookup by Bounded(n) has no malformed-table fallback.
Functions
fn count_units(values: List(Unit)) -> Nat
Count the number of elements in a List(Unit) as a Nat.
fn decoded_left_value(left: ShapeCode, right: ShapeCode, value: Sem(left)) -> Sem(ChoiceC(left, right))
Wrap a decoded left-branch value into Sem(ChoiceC(left, right)).
fn decoded_right_value(left: ShapeCode, right: ShapeCode, value: Sem(right)) -> Sem(ChoiceC(left, right))
Wrap a decoded right-branch value into Sem(ChoiceC(left, right)).
fn evidence_reverse_chars(input: List(Char)) -> List(Char)
Reverse a List(Char) in the evidence VM without depending on external
list helpers.
fn evidence_reverse_chars_into(input: List(Char), output: List(Char)) -> List(Char)
Tail-recursive accumulator helper for evidence_reverse_chars.
fn extract_encoding(shape: ShapeCode, input: List(Evidence), encoding: Encodes(shape, input, Nil())) -> Sem(shape)
Extract a complete Sem(shape) value from a fully consumed Evidence
stream proved by Encodes(shape, input, Nil()).
fn extract_encoding_result(shape: ShapeCode, input: List(Evidence), rest: List(Evidence), encoding: Encodes(shape, input, rest)) -> EncodingExtraction(shape, input, rest)
Total proof-directed extraction (thesis §5.3 / Fig. 5.8). input is an
explicit runtime argument, exactly like the paper's ev; only encoding
is erased. The evidence marker is inspected first and its index leaves one
possible proof constructor. There is no malformed-evidence branch and no
Option after an accepting run has produced the certificate.
fn extract_many_encoding_result(shape: ShapeCode, input: List(Evidence), rest: List(Evidence), encoding: EncodesMany(shape, input, rest)) -> ManyEncodingExtraction(shape, input, rest)
Extract a reversed list of repeated Sem(shape) items from input using
the erased EncodesMany proof witness, returning the remaining evidence.
fn machine_state_thread(n: Nat, state: MachineState(n)) -> ThreadState(n)
Project a MachineState(n) to its underlying ThreadState(n), discarding
attached evidence instructions and boundary constraints.
fn record_capture_char(frames: List(CaptureFrame), char: Char) -> List(CaptureFrame)
Push a matched char onto every open CaptureFrame in frames.
fn regex_assertion_depth_limit() -> Nat
One canonical resource bound shared by syntax admission, runtime child evaluation, and proof-facing assertion entry points. Keeping this in the core module prevents compile-time and runtime limits from drifting.
fn reverse_sem_values(shape: ShapeCode, values: List(Sem(shape))) -> List(Sem(shape))
Reverse a list of decoded Sem(shape) values into forward match order.
fn reverse_sem_values_into(shape: ShapeCode, values: List(Sem(shape)), output: List(Sem(shape))) -> List(Sem(shape))
Tail-recursive accumulator helper for reverse_sem_values.
fn Sem(shape: ShapeCode) -> Type
Genuine large elimination: each value-level shape computes to its Cure result type. No runtime tag, Dynamic value, cast, or postulate is involved.
fn Simplify(shape: ShapeCode) -> ShapeCode
Recursively normalize a ShapeCode by eliminating redundant UnitC
structure across pairs, choices, options, and lists.
fn SimplifyChoice(left: ShapeCode, right: ShapeCode) -> ShapeCode
Simplify a ChoiceC(left, right) shape, collapsing two UnitC branches
into BoolC.
fn SimplifyChoiceUnit(right: ShapeCode) -> ShapeCode
Simplify a choice shape whose left branch is UnitC, collapsing
ChoiceC(UnitC, UnitC) to BoolC.
fn SimplifyList(inner: ShapeCode) -> ShapeCode
Simplify a ListC(inner) shape, collapsing ListC(UnitC) to NatC.
fn SimplifyOption(inner: ShapeCode) -> ShapeCode
Simplify an OptionC(inner) shape, collapsing OptionC(UnitC) to BoolC.
fn SimplifyPair(left: ShapeCode, right: ShapeCode) -> ShapeCode
Simplify a PairC(left, right) shape by eliding UnitC on either side.
fn SimplifyPairPresent(left: ShapeCode, right: ShapeCode) -> ShapeCode
Simplify a pair shape whose left component is non-unit, dropping a trailing
UnitC on the right.
fn SimplifyPairUnit(right: ShapeCode) -> ShapeCode
Normalize structural extraction shapes into ergonomic public results. Every companion value function is total at the corresponding computed type; no equality cast connects the raw and simplified interpretations.
fn sem_char_witness(value: Char) -> Sem(CharC)
Reduction witness checking that Sem(CharC) reduces definitionally to Char.
fn sem_nested_witness(value: Char) -> Sem(PairC(CharC, ListC(UnitC)))
Reduction witness checking that nested Sem(PairC(CharC, ListC(UnitC)))
reduces definitionally to Tuple(Char, List(Unit)).
fn sem_unit_witness() -> Sem(UnitC)
Phase-1 reduction witnesses. These bodies only check if Sem computes at constructor applications rather than behaving as an opaque type function.
fn simplify_choice_unit_value(right: ShapeCode, value: Choice(Unit, Sem(right))) -> Sem(SimplifyChoiceUnit(right))
Companion value transformer for SimplifyChoiceUnit, mapping
Choice(Unit, Unit) to Bool (true for left, false for right).
fn simplify_choice_value(left: ShapeCode, right: ShapeCode, value: Choice(Sem(left), Sem(right))) -> Sem(SimplifyChoice(left, right))
Companion value transformer for SimplifyChoice.
fn simplify_list(inner: ShapeCode, values: List(Sem(inner))) -> List(Sem(Simplify(inner)))
Apply simplify_value elementwise across a list of Sem(inner) values.
fn simplify_list_values(inner: ShapeCode, values: List(Sem(inner))) -> Sem(SimplifyList(inner))
Companion value transformer for SimplifyList, collapsing List(Unit) to
its length as a Nat.
fn simplify_option_value(inner: ShapeCode, value: Option(Sem(inner))) -> Sem(SimplifyOption(inner))
Companion value transformer for SimplifyOption, mapping Option(Unit) to
Bool.
fn simplify_pair_present_value(left: ShapeCode, right: ShapeCode, left_value: Sem(left), right_value: Sem(right)) -> Sem(SimplifyPairPresent(left, right))
Companion value transformer for SimplifyPairPresent, dropping a trailing
Unit or pairing left_value with right_value.
fn simplify_pair_unit_value(right: ShapeCode, right_value: Sem(right)) -> Sem(SimplifyPairUnit(right))
Companion value transformer for SimplifyPairUnit, returning right_value
directly after dropping a leading Unit.
fn simplify_pair_value(left: ShapeCode, right: ShapeCode, left_value: Sem(left), right_value: Sem(right)) -> Sem(SimplifyPair(left, right))
Companion value transformer for SimplifyPair, combining simplified left
and right pair components.
fn simplify_value(shape: ShapeCode, value: Sem(shape)) -> Sem(Simplify(shape))
Recursively simplify a value of type Sem(shape) into Sem(Simplify(shape)).