Std. Regex. Syntax. Parser
(Cure Standard Library v0.37.2)
View Source
Compile-time parser for regex literal patterns. It validates the complete literal and returns a structured syntax-tree error when parsing stops early.
Examples
use Std.Regex.Syntax.Model
use Std.Regex.Syntax.Parser
fn parsed_literal_ok() -> Bool = match parse_literal(['a', '+'])
LiteralParsed(_, []) -> true
_ -> false
Summary
Functions
Appends two lists of LiteralPattern nodes.
Returns true when a bounded quantifier count does not exceed literal_quantifier_limit().
Returns true when char is a valid continuation character (A-Z, a-z, 0-9, or _) for a capture name.
Returns true when name is a non-empty valid ASCII identifier for a named capture group.
Returns true when char is a valid starting character (A-Z, a-z, or _) for a capture name.
Returns true when every trailing character in a capture group name is valid.
Completes an open-ended {n,} quantifier, applying any trailing lazy (?) or possessive (+) modifier.
Completes a ranged {n,m} quantifier after validating bounds and range order.
Completes an exact {n} quantifier, applying any trailing lazy (?) or possessive (+) modifier.
Constructs a located parse error spanning a malformed bounded quantifier {...}.
Maps a supported inline option character (i, m, s, u, U) to its LiteralModifier.
Returns the predecessor of a positive Nat, or None() for Z().
Parses a complete regex literal character list, including optional leading newline control verbs.
Parses a |-separated alternation expression bounded by structural recursion fuel.
Parses remaining | alternation branches left-associatively after an initial branch.
Parses a single regex atom: wildcard, anchor, group, character class, escape, or literal character.
Parses an atomic group (?>...) into LiteralAtomic.
Parses the body of a {n}, {n,}, or {n,m} bounded quantifier following {.
Parses the upper bound and closing } of a {n,m} bounded quantifier.
Parses the |-separated arms of a branch-reset group (?|...) into LiteralBranchReset.
Parses a capturing group (...) into LiteralCapture.
Finalizes a parse result, rejecting trailing input and converting suffix errors into located spans.
Parses the yes and optional |no branches of a conditional pattern up to ).
Parses the condition header inside (?(cond)yes|no), dispatching numeric, <name>, or bare-name references.
Parses a bare named capture reference (?(name)...) in a conditional header.
Parses an angle-bracketed named capture reference (?( <name> )...) in a conditional header.
Parses a 1-based numeric capture reference inside a conditional header (?(n)...).
Parses a base-10 non-negative integer count for quantifiers and numeric capture references.
Parses a backslash escape sequence into a character class shorthand, anchor, Unicode property, or literal character.
Dispatches parenthesized group forms after (, including captures, lookarounds, conditionals, and inline options.
Parses a scoped inline option group (?flags-flags:...) into LiteralScopedOptions.
Parses a positive or negative lookahead or lookbehind group into LiteralLookahead or LiteralLookbehind.
Starts parsing an angle-bracketed named capture group (?<name>...) given its first character.
Reads the name up to > for (?<name>...) or (?P<name>...) and delegates to the capture body parser.
Parses the body of a named capture group up to its closing ) and wraps it in LiteralNamedCapture.
Reads the name up to ' for (?'name'...) and delegates to the capture body parser.
Parses a non-capturing group (?:...) and returns its inner pattern directly.
Parses an atom followed by an optional greedy, lazy, possessive, or bounded quantifier.
Parses a concatenation sequence until end-of-input or a stop delimiter (| or )).
Parses remaining sequence items left-associatively after the first parsed element.
Parses a \N{...} Unicode character name escape after \N.
Reads the braced name in \N{NAME} and resolves it via Std.Char.from_unicode_name.
Parses a regex literal and wraps a successful AST with the given newline policy.
Reverses a list of LiteralPattern nodes.
Functions
fn append_literal_patterns(left: List(LiteralPattern), right: List(LiteralPattern)) -> List(LiteralPattern)
Appends two lists of LiteralPattern nodes.
fn bounded_count_allowed(value: Nat) -> Bool
Returns true when a bounded quantifier count does not exceed literal_quantifier_limit().
fn capture_name_continue(char: Char) -> Bool
Returns true when char is a valid continuation character (A-Z, a-z, 0-9, or _) for a capture name.
fn capture_name_is_valid(name: List(Char)) -> Bool
Returns true when name is a non-empty valid ASCII identifier for a named capture group.
fn capture_name_start(char: Char) -> Bool
Returns true when char is a valid starting character (A-Z, a-z, or _) for a capture name.
fn capture_name_tail_is_valid(name: List(Char)) -> Bool
Returns true when every trailing character in a capture group name is valid.
fn finish_literal_at_least_bounded(atom: LiteralPattern, count: Nat, rest: List(Char), origin: List(Char)) -> LiteralParse
Completes an open-ended {n,} quantifier, applying any trailing lazy (?) or possessive (+) modifier.
fn finish_literal_between_bounded(atom: LiteralPattern, minimum: Nat, maximum: Nat, rest: List(Char), origin: List(Char)) -> LiteralParse
Completes a ranged {n,m} quantifier after validating bounds and range order.
fn finish_literal_exact_bounded(atom: LiteralPattern, count: Nat, rest: List(Char), origin: List(Char)) -> LiteralParse
Completes an exact {n} quantifier, applying any trailing lazy (?) or possessive (+) modifier.
fn literal_bounded_failure(reason: Atom, origin: List(Char)) -> LiteralParse
Constructs a located parse error spanning a malformed bounded quantifier {...}.
fn literal_inline_modifier(char: Char) -> Option(LiteralModifier)
Maps a supported inline option character (i, m, s, u, U) to its LiteralModifier.
fn literal_nat_predecessor(value: Nat) -> Option(Nat)
Returns the predecessor of a positive Nat, or None() for Z().
fn parse_literal(input: List(Char)) -> LiteralParse
Parses a complete regex literal character list, including optional leading newline control verbs.
fn parse_literal_alternate_fuel(input: List(Char), fuel: Nat) -> LiteralParse
Parses a |-separated alternation expression bounded by structural recursion fuel.
fn parse_literal_alternate_tail_fuel(left: LiteralPattern, input: List(Char), fuel: Nat) -> LiteralParse
Parses remaining | alternation branches left-associatively after an initial branch.
fn parse_literal_atom_fuel(input: List(Char), fuel: Nat) -> LiteralParse
Parses a single regex atom: wildcard, anchor, group, character class, escape, or literal character.
fn parse_literal_atomic_fuel(input: List(Char), fuel: Nat, origin: List(Char)) -> LiteralParse
Parses an atomic group (?>...) into LiteralAtomic.
fn parse_literal_bounded(atom: LiteralPattern, input: List(Char), origin: List(Char)) -> LiteralParse
Parses the body of a {n}, {n,}, or {n,m} bounded quantifier following {.
fn parse_literal_bounded_maximum(atom: LiteralPattern, minimum: Nat, input: List(Char), origin: List(Char)) -> LiteralParse
Parses the upper bound and closing } of a {n,m} bounded quantifier.
fn parse_literal_branch_reset_fuel(input: List(Char), fuel: Nat, origin: List(Char), reversed: List(LiteralPattern)) -> LiteralParse
Parses the |-separated arms of a branch-reset group (?|...) into LiteralBranchReset.
fn parse_literal_capture_fuel(input: List(Char), fuel: Nat, origin: List(Char)) -> LiteralParse
Parses a capturing group (...) into LiteralCapture.
fn parse_literal_complete(result: LiteralParse, original: List(Char)) -> LiteralParse
Finalizes a parse result, rejecting trailing input and converting suffix errors into located spans.
fn parse_literal_conditional_body(input: List(Char), fuel: Nat, origin: List(Char), reference: LiteralCaptureReference) -> LiteralParse
Parses the yes and optional |no branches of a conditional pattern up to ).
fn parse_literal_conditional_header(input: List(Char), fuel: Nat, origin: List(Char), reversed: List(Char)) -> LiteralParse
Parses the condition header inside (?(cond)yes|no), dispatching numeric, <name>, or bare-name references.
fn parse_literal_conditional_name_header(input: List(Char), fuel: Nat, origin: List(Char), reversed: List(Char)) -> LiteralParse
Parses a bare named capture reference (?(name)...) in a conditional header.
fn parse_literal_conditional_named_header(input: List(Char), fuel: Nat, origin: List(Char), reversed: List(Char)) -> LiteralParse
Parses an angle-bracketed named capture reference (?( <name> )...) in a conditional header.
fn parse_literal_conditional_numeric_header(input: List(Char), fuel: Nat, origin: List(Char)) -> LiteralParse
Parses a 1-based numeric capture reference inside a conditional header (?(n)...).
fn parse_literal_count(input: List(Char), value: Nat, seen: Bool) -> LiteralCountParse
Parses a base-10 non-negative integer count for quantifiers and numeric capture references.
fn parse_literal_escape(input: List(Char), origin: List(Char)) -> LiteralParse
Parses a backslash escape sequence into a character class shorthand, anchor, Unicode property, or literal character.
fn parse_literal_group_fuel(input: List(Char), fuel: Nat, origin: List(Char)) -> LiteralParse
Dispatches parenthesized group forms after (, including captures, lookarounds, conditionals, and inline options.
fn parse_literal_inline_options(input: List(Char), fuel: Nat, origin: List(Char), enabled: List(LiteralModifier), disabled: List(LiteralModifier), removing: Bool) -> LiteralParse
Parses a scoped inline option group (?flags-flags:...) into LiteralScopedOptions.
fn parse_literal_lookaround_fuel(input: List(Char), fuel: Nat, origin: List(Char), lookahead: Bool, polarity: LiteralAssertionPolarity) -> LiteralParse
Parses a positive or negative lookahead or lookbehind group into LiteralLookahead or LiteralLookbehind.
fn parse_literal_named_capture_angle(first: Char, input: List(Char), fuel: Nat, origin: List(Char), reversed: List(Char)) -> LiteralParse
Starts parsing an angle-bracketed named capture group (?<name>...) given its first character.
fn parse_literal_named_capture_angle_tail(input: List(Char), fuel: Nat, origin: List(Char), reversed: List(Char)) -> LiteralParse
Reads the name up to > for (?<name>...) or (?P<name>...) and delegates to the capture body parser.
fn parse_literal_named_capture_body(input: List(Char), fuel: Nat, origin: List(Char), name: String) -> LiteralParse
Parses the body of a named capture group up to its closing ) and wraps it in LiteralNamedCapture.
fn parse_literal_named_capture_quote(input: List(Char), fuel: Nat, origin: List(Char), reversed: List(Char)) -> LiteralParse
Reads the name up to ' for (?'name'...) and delegates to the capture body parser.
fn parse_literal_non_capture_fuel(input: List(Char), fuel: Nat, origin: List(Char)) -> LiteralParse
Parses a non-capturing group (?:...) and returns its inner pattern directly.
fn parse_literal_repetition_fuel(input: List(Char), fuel: Nat) -> LiteralParse
Parses an atom followed by an optional greedy, lazy, possessive, or bounded quantifier.
fn parse_literal_sequence_fuel(input: List(Char), fuel: Nat) -> LiteralParse
Parses a concatenation sequence until end-of-input or a stop delimiter (| or )).
fn parse_literal_sequence_tail_fuel(left: LiteralPattern, input: List(Char), fuel: Nat) -> LiteralParse
Parses remaining sequence items left-associatively after the first parsed element.
fn parse_literal_unicode_name(input: List(Char), origin: List(Char), reversed: List(Char)) -> LiteralParse
Parses a \N{...} Unicode character name escape after \N.
fn parse_literal_unicode_name_body(input: List(Char), origin: List(Char), reversed: List(Char)) -> LiteralParse
Reads the braced name in \N{NAME} and resolves it via Std.Char.from_unicode_name.
fn parse_literal_with_policy(policy: LiteralNewlinePolicy, input: List(Char)) -> LiteralParse
Parses a regex literal and wraps a successful AST with the given newline policy.
fn reverse_literal_patterns(values: List(LiteralPattern)) -> List(LiteralPattern)
Reverses a list of LiteralPattern nodes.