moonrockz/diagrams/regex
Types
AnchorKind
pub(all) enum AnchorKind {
LineStart
LineEnd
InputStart
InputEndBeforeNewline
InputEnd
PreviousMatchEnd
WordBoundary
NonWordBoundary
} derive(Eq, @moonbitlang/core/debug.Debug)A zero-width position test that consumes no input.
AnchorKind::equal
fn AnchorKind::equal(AnchorKind, AnchorKind) -> BoolAnchorKind::not_equal
fn AnchorKind::not_equal(x : AnchorKind, y : AnchorKind) -> BoolAnchorKind::to_repr
fn AnchorKind::to_repr(AnchorKind) -> @moonbitlang/core/debug.ReprBounds
pub struct Bounds {
min : Int
max : Int?
reluctant : Bool
spelling : String
} derive(Eq, @moonbitlang/core/debug.Debug)Symbolic repetition bounds. A repeat is never expanded into copies.
Bounds::equal
fn Bounds::equal(Bounds, Bounds) -> BoolBounds::new
fn Bounds::new(min : Int, max? : Int, reluctant? : Bool, spelling? : String) -> BoundsMake bounds. The spelling defaults to the canonical regex quantifier.
Bounds::not_equal
fn Bounds::not_equal(x : Bounds, y : Bounds) -> BoolBounds::to_repr
fn Bounds::to_repr(Bounds) -> @moonbitlang/core/debug.ReprClassKind
pub(all) enum ClassKind {
Any
Shorthand(Char)
Property(String)
CodePoint(String)
Posix(String)
} derive(Eq, @moonbitlang/core/debug.Debug)A predefined character class. The spelling is kept for display.
ClassKind::equal
fn ClassKind::equal(ClassKind, ClassKind) -> BoolClassKind::not_equal
fn ClassKind::not_equal(x : ClassKind, y : ClassKind) -> BoolClassKind::to_repr
fn ClassKind::to_repr(ClassKind) -> @moonbitlang/core/debug.ReprGroupKind
pub(all) enum GroupKind {
Capturing
NonCapturing
Named(String)
} derive(Eq, @moonbitlang/core/debug.Debug)GroupKind::equal
fn GroupKind::equal(GroupKind, GroupKind) -> BoolGroupKind::not_equal
fn GroupKind::not_equal(x : GroupKind, y : GroupKind) -> BoolGroupKind::to_repr
fn GroupKind::to_repr(GroupKind) -> @moonbitlang/core/debug.ReprIndex
pub struct Index {
regex : Regex
order : ReadOnlyArray[String]
// private fields
}A validated view of a regex model with constant-time lookups. Every node except the root has exactly one parent, so the arena is a finite tree.
Index::build
fn Index::build(regex : Regex, limits? : Limits) -> IndexResultValidate identities, ownership, bounds and explicit limits without recursion.
Index::depth
fn Index::depth(self : Index, id : String) -> Int?Index::node
fn Index::node(self : Index, id : String) -> Node?Index::parent
fn Index::parent(self : Index, id : String) -> String?IndexResult
pub struct IndexResult {
index : Index?
diagnostics : ReadOnlyArray[@moonrockz/diagrams.Diagnostic]
}Kind
pub(all) enum Kind {
Literal(String)
Class(ClassKind)
Set(Bool, ReadOnlyArray[SetItem])
Anchor(AnchorKind)
Backreference(String)
Sequence(ReadOnlyArray[String])
Choice(ReadOnlyArray[String])
Group(GroupKind, String)
Repeat(Bounds, String)
Assertion(Look, Bool, String)
} derive(Eq, @moonbitlang/core/debug.Debug)The meaning of one expression node. Composite kinds name their children by node identity, so a model is a flat, bounded arena.
Kind::equal
fn Kind::equal(Kind, Kind) -> BoolKind::not_equal
fn Kind::not_equal(x : Kind, y : Kind) -> BoolKind::to_repr
fn Kind::to_repr(Kind) -> @moonbitlang/core/debug.ReprLimits
pub struct Limits {
nodes : Int
depth : Int
work : Int
} derive(Eq, @moonbitlang/core/debug.Debug)Explicit bounds for model validation and indexing.
Limits::equal
fn Limits::equal(Limits, Limits) -> BoolLimits::new
fn Limits::new(nodes? : Int, depth? : Int, work? : Int) -> LimitsLimits::not_equal
fn Limits::not_equal(x : Limits, y : Limits) -> BoolLimits::to_repr
fn Limits::to_repr(Limits) -> @moonbitlang/core/debug.ReprLook
pub(all) enum Look {
Ahead
Behind
} derive(Eq, @moonbitlang/core/debug.Debug)The direction of a lookaround assertion.
Look::equal
fn Look::equal(Look, Look) -> BoolLook::not_equal
fn Look::not_equal(x : Look, y : Look) -> BoolLook::to_repr
fn Look::to_repr(Look) -> @moonbitlang/core/debug.ReprNode
pub struct Node {
id : String
kind : Kind
source : @moonrockz/diagrams.Span?
} derive(Eq, @moonbitlang/core/debug.Debug)Node::children
fn Node::children(self : Node) -> ReadOnlyArray[String]The children of node in drawing order.
Node::equal
fn Node::equal(Node, Node) -> BoolNode::is_leaf
fn Node::is_leaf(self : Node) -> BoolLiteral text, classes, sets and anchors are leaves of the railroad.
Node::label
fn Node::label(self : Node) -> StringThe visible label of a leaf, or the name of a composite construct.
Node::new
fn Node::new(id : String, kind : Kind, source? : @moonrockz/diagrams.Span) -> NodeNode::not_equal
fn Node::not_equal(x : Node, y : Node) -> BoolNode::to_repr
fn Node::to_repr(Node) -> @moonbitlang/core/debug.ReprRegex
pub struct Regex {
id : String
root : String
nodes : ReadOnlyArray[Node]
title : String?
accessibility_title : String?
accessibility_description : String?
pattern : String?
} derive(Eq, @moonbitlang/core/debug.Debug)One immutable regular-expression diagram. It describes the structure of a pattern; it does not match input.
Regex::equal
fn Regex::equal(Regex, Regex) -> BoolRegex::new
fn Regex::new(id : String, root : String, nodes : ArrayView[Node], title? : String, accessibility_title? : String, accessibility_description? : String, pattern? : String) -> RegexMake a regex model. pattern is the optional source spelling for display.
Regex::node
fn Regex::node(self : Regex, id : String) -> Node?Find a node by identity. The search is linear; use Index for repeated lookups.
Regex::not_equal
fn Regex::not_equal(x : Regex, y : Regex) -> BoolRegex::to_repr
fn Regex::to_repr(Regex) -> @moonbitlang/core/debug.ReprSetItem
pub(all) enum SetItem {
Char(String)
Range(String, String)
Escape(String)
} derive(Eq, @moonbitlang/core/debug.Debug)One item of a bracketed character set.
SetItem::equal
fn SetItem::equal(SetItem, SetItem) -> BoolSetItem::not_equal
fn SetItem::not_equal(x : SetItem, y : SetItem) -> BoolSetItem::to_repr
fn SetItem::to_repr(SetItem) -> @moonbitlang/core/debug.ReprValues
diagnostic_codes
let diagnostic_codes : ReadOnlyArray[String]The stable diagnostic codes of model validation.
validate
fn validate(regex : Regex, limits? : Limits) -> ReadOnlyArray[@moonrockz/diagrams.Diagnostic]Validate a constructed model. An empty result means the model is valid.