moonrockz/diagrams/railroad-trace
Types
Attempt
pub struct Attempt {
id : String
status : AttemptStatus
steps : ReadOnlyArray[Step]
failure : FailurePoint?
continuous : Bool
label : String?
} derive(Eq, @moonbitlang/core/debug.Debug)One finite attempt of an external engine. Repeated or backtracked steps stay separate, even when they reuse a term or connector.
Attempt::equal
fn Attempt::equal(Attempt, Attempt) -> BoolAttempt::new
fn Attempt::new(id : String, status : AttemptStatus, steps : ArrayView[Step], failure? : FailurePoint, continuous? : Bool, label? : String) -> AttemptAttempt::not_equal
fn Attempt::not_equal(x : Attempt, y : Attempt) -> BoolAttempt::to_repr
fn Attempt::to_repr(Attempt) -> @moonbitlang/core/debug.ReprAttemptStatus
pub(all) enum AttemptStatus {
Matched
NotMatched
} derive(Eq, @moonbitlang/core/debug.Debug)AttemptStatus::equal
fn AttemptStatus::equal(AttemptStatus, AttemptStatus) -> BoolAttemptStatus::not_equal
fn AttemptStatus::not_equal(x : AttemptStatus, y : AttemptStatus) -> BoolAttemptStatus::to_repr
fn AttemptStatus::to_repr(AttemptStatus) -> @moonbitlang/core/debug.ReprConnector
pub struct Connector {
id : String
owner : String
role : ConnectorRole
from : String
to : String
rule : String
constraint : Bool
} derive(Eq, @moonbitlang/core/debug.Debug)One drawn connector between two points, in its semantic direction.
Connector::equal
fn Connector::equal(Connector, Connector) -> BoolConnector::not_equal
fn Connector::not_equal(x : Connector, y : Connector) -> BoolConnector::to_repr
fn Connector::to_repr(Connector) -> @moonbitlang/core/debug.ReprConnectorRole
pub(all) enum ConnectorRole {
Start
End
Gap
Split(Int)
Join(Int)
Enter
Leave
Bypass
Return
Empty
} derive(Eq, @moonbitlang/core/debug.Debug)The structural role of a drawn connector.
ConnectorRole::equal
fn ConnectorRole::equal(ConnectorRole, ConnectorRole) -> BoolConnectorRole::name
fn ConnectorRole::name(self : ConnectorRole) -> StringConnectorRole::not_equal
fn ConnectorRole::not_equal(x : ConnectorRole, y : ConnectorRole) -> BoolConnectorRole::to_repr
fn ConnectorRole::to_repr(ConnectorRole) -> @moonbitlang/core/debug.ReprFailurePoint
pub struct FailurePoint {
target : FailureTarget
position : Int?
message : String?
} derive(Eq, @moonbitlang/core/debug.Debug)FailurePoint::equal
fn FailurePoint::equal(FailurePoint, FailurePoint) -> BoolFailurePoint::new
fn FailurePoint::new(target : FailureTarget, position? : Int, message? : String) -> FailurePointFailurePoint::not_equal
fn FailurePoint::not_equal(x : FailurePoint, y : FailurePoint) -> BoolFailurePoint::to_repr
fn FailurePoint::to_repr(FailurePoint) -> @moonbitlang/core/debug.ReprFailureTarget
pub(all) enum FailureTarget {
Terminal(String)
Assertion(String)
Entry(String)
Exit(String)
} derive(Eq, @moonbitlang/core/debug.Debug)The place where an attempt failed.
FailureTarget::equal
fn FailureTarget::equal(FailureTarget, FailureTarget) -> BoolFailureTarget::not_equal
fn FailureTarget::not_equal(x : FailureTarget, y : FailureTarget) -> BoolFailureTarget::to_repr
fn FailureTarget::to_repr(FailureTarget) -> @moonbitlang/core/debug.ReprInputSpan
pub struct InputSpan {
start : Int
end : Int
} derive(Eq, @moonbitlang/core/debug.Debug)A half-open UTF-16 span of the input.
InputSpan::equal
fn InputSpan::equal(InputSpan, InputSpan) -> BoolInputSpan::new
fn InputSpan::new(start : Int, end : Int) -> InputSpanInputSpan::not_equal
fn InputSpan::not_equal(x : InputSpan, y : InputSpan) -> BoolInputSpan::to_repr
fn InputSpan::to_repr(InputSpan) -> @moonbitlang/core/debug.ReprStep
pub(all) enum Step {
Visit(String, InputSpan?)
Traverse(String, Bool)
} derive(Eq, @moonbitlang/core/debug.Debug)One oriented trace step. A visit passes through a term from its entry to its exit. A traversal follows a drawn connector, forward or reversed.
Step::equal
fn Step::equal(Step, Step) -> BoolStep::not_equal
fn Step::not_equal(x : Step, y : Step) -> BoolStep::to_repr
fn Step::to_repr(Step) -> @moonbitlang/core/debug.ReprSubject
pub(all) enum Subject {
Regex(@moonrockz/diagrams/regex.Regex)
Ebnf(@moonrockz/diagrams/ebnf.Grammar, String)
} derive(Eq, @moonbitlang/core/debug.Debug)The typed subject of a trace request. An EBNF subject names its start rule by rule identity.
Subject::equal
fn Subject::equal(Subject, Subject) -> BoolSubject::fingerprint
fn Subject::fingerprint(self : Subject) -> StringThe fingerprint of the structure of a subject. A trace for an edited or different model has a different fingerprint, even with equal identities.
Subject::identity
fn Subject::identity(self : Subject, view_id? : String) -> SubjectIdentitySubject::kind
fn Subject::kind(self : Subject) -> SubjectKindSubject::model_id
fn Subject::model_id(self : Subject) -> StringSubject::not_equal
fn Subject::not_equal(x : Subject, y : Subject) -> BoolSubject::to_repr
fn Subject::to_repr(Subject) -> @moonbitlang/core/debug.ReprSubjectIdentity
pub struct SubjectIdentity {
kind : SubjectKind
model_id : String
view_id : String
fingerprint : String
start_rule : String?
} derive(Eq, @moonbitlang/core/debug.Debug)The provenance of a trace: subject kind, model and view identity and the structural fingerprint of the model.
SubjectIdentity::equal
fn SubjectIdentity::equal(SubjectIdentity, SubjectIdentity) -> BoolSubjectIdentity::not_equal
fn SubjectIdentity::not_equal(x : SubjectIdentity, y : SubjectIdentity) -> BoolSubjectIdentity::to_repr
fn SubjectIdentity::to_repr(SubjectIdentity) -> @moonbitlang/core/debug.ReprSubjectKind
pub(all) enum SubjectKind {
Regex
Ebnf
} derive(Eq, @moonbitlang/core/debug.Debug)The two railroad subject kinds.
SubjectKind::equal
fn SubjectKind::equal(SubjectKind, SubjectKind) -> BoolSubjectKind::not_equal
fn SubjectKind::not_equal(x : SubjectKind, y : SubjectKind) -> BoolSubjectKind::to_repr
fn SubjectKind::to_repr(SubjectKind) -> @moonbitlang/core/debug.ReprTerm
pub struct Term {
id : String
kind : TermKind
label : String
rule : String
constraint : Bool
entry : String
exit : String
} derive(Eq, @moonbitlang/core/debug.Debug)One visible term occurrence. Equal labels in different positions have different identities.
Term::equal
fn Term::equal(Term, Term) -> BoolTerm::not_equal
fn Term::not_equal(x : Term, y : Term) -> BoolTerm::to_repr
fn Term::to_repr(Term) -> @moonbitlang/core/debug.ReprTermKind
pub(all) enum TermKind {
Consumed
Reference(@moonrockz/diagrams/ebnf.Resolution)
Anchor
Assertion
Empty
} derive(Eq, @moonbitlang/core/debug.Debug)The role of one visible term. Terms are visit targets.
TermKind::equal
fn TermKind::equal(TermKind, TermKind) -> BoolTermKind::not_equal
fn TermKind::not_equal(x : TermKind, y : TermKind) -> BoolTermKind::to_repr
fn TermKind::to_repr(TermKind) -> @moonbitlang/core/debug.ReprTopology
pub struct Topology {
kind : SubjectKind
model_id : String
fingerprint : String
tracks : ReadOnlyArray[Track]
terms : ReadOnlyArray[Term]
connectors : ReadOnlyArray[Connector]
walk : ReadOnlyArray[Step]
// private fields
}The semantic railroad topology of a model: visible terms, points and drawn connectors. External engines map their events to these identities before any SVG or animation exists.
Topology::connector
fn Topology::connector(self : Topology, id : String) -> Connector?Topology::connector_between
fn Topology::connector_between(self : Topology, from : String, to : String) -> Connector?The connector between two points, if one is drawn.
Topology::connector_of
fn Topology::connector_of(self : Topology, owner : String, role : ConnectorRole) -> Connector?The connector with role that owner draws, if any.
Topology::connectors_from
fn Topology::connectors_from(self : Topology, point : String) -> Array[Connector]The connectors that leave point, in drawing order.
Topology::ebnf
fn Topology::ebnf(grammar : @moonrockz/diagrams/ebnf.Grammar, limits? : @moonrockz/diagrams/ebnf.Limits) -> TopologyResultBuild the topology of a grammar. Each rule is one track. References are terms; no connector joins two rules.
Topology::entry
fn Topology::entry(self : Topology, id : String) -> String?The entry point of a node, rule or model identity.
Topology::exit
fn Topology::exit(self : Topology, id : String) -> String?The exit point of a node, rule or model identity.
Topology::has_point
fn Topology::has_point(self : Topology, point : String) -> BoolTopology::regex
fn Topology::regex(model : @moonrockz/diagrams/regex.Regex, limits? : @moonrockz/diagrams/regex.Limits) -> TopologyResultBuild the topology of a regex model. The pattern is one track whose identity is the model identity.
Topology::term
fn Topology::term(self : Topology, id : String) -> Term?TopologyResult
pub struct TopologyResult {
topology : Topology?
diagnostics : ReadOnlyArray[@moonrockz/diagrams.Diagnostic]
}Trace
pub struct Trace {
subject : SubjectIdentity
input : String
provider : String
attempts : ReadOnlyArray[Attempt]
} derive(Eq, @moonbitlang/core/debug.Debug)Immutable evidence that an external engine supplied. It is separate from the diagram and is never computed by this library.
Trace::equal
fn Trace::equal(Trace, Trace) -> BoolTrace::new
fn Trace::new(request : TraceRequest, provider : String, attempts : ArrayView[Attempt]) -> TraceMake a trace bound to the subject of request.
Trace::not_equal
fn Trace::not_equal(x : Trace, y : Trace) -> BoolTrace::to_repr
fn Trace::to_repr(Trace) -> @moonbitlang/core/debug.ReprTraceLimits
pub struct TraceLimits {
input : Int
attempts : Int
steps : Int
depth : Int
work : Int
} derive(Eq, @moonbitlang/core/debug.Debug)Explicit trace bounds. Providers honor them cooperatively; validation enforces them for every supplied trace.
TraceLimits::equal
fn TraceLimits::equal(TraceLimits, TraceLimits) -> BoolTraceLimits::new
fn TraceLimits::new(input? : Int, attempts? : Int, steps? : Int, depth? : Int, work? : Int) -> TraceLimitsTraceLimits::not_equal
fn TraceLimits::not_equal(x : TraceLimits, y : TraceLimits) -> BoolTraceLimits::to_repr
fn TraceLimits::to_repr(TraceLimits) -> @moonbitlang/core/debug.ReprTraceLimits::valid
fn TraceLimits::valid(self : TraceLimits) -> BoolTraceRequest
pub struct TraceRequest {
subject : Subject
view_id : String
input : String
limits : TraceLimits
} derive(Eq, @moonbitlang/core/debug.Debug)One immutable request to an external matching or parsing engine.
TraceRequest::ebnf
fn TraceRequest::ebnf(grammar : @moonrockz/diagrams/ebnf.Grammar, start_rule : String, input : String, view_id? : String, limits? : TraceLimits) -> TraceRequestTraceRequest::equal
fn TraceRequest::equal(TraceRequest, TraceRequest) -> BoolTraceRequest::identity
fn TraceRequest::identity(self : TraceRequest) -> SubjectIdentityThe provenance that a trace for this request must carry.
TraceRequest::not_equal
fn TraceRequest::not_equal(x : TraceRequest, y : TraceRequest) -> BoolTraceRequest::regex
fn TraceRequest::regex(model : @moonrockz/diagrams/regex.Regex, input : String, view_id? : String, limits? : TraceLimits) -> TraceRequestTraceRequest::to_repr
fn TraceRequest::to_repr(TraceRequest) -> @moonbitlang/core/debug.ReprTraceRequest::topology
fn TraceRequest::topology(self : TraceRequest) -> TopologyResultThe semantic topology of the requested subject, for mapping engine events.
TraceRequest::validate
fn TraceRequest::validate(self : TraceRequest) -> ReadOnlyArray[@moonrockz/diagrams.Diagnostic]Check a request before a provider receives it.
TraceResult
pub(all) enum TraceResult {
Matched(Trace)
NotMatched(Trace)
Unsupported(String)
Exhausted(String)
ProviderError(String)
} derive(Eq, @moonbitlang/core/debug.Debug)The outcome of a provider. Unsupported, exhausted and error results are not evidence of a non-match.
TraceResult::equal
fn TraceResult::equal(TraceResult, TraceResult) -> BoolTraceResult::not_equal
fn TraceResult::not_equal(x : TraceResult, y : TraceResult) -> BoolTraceResult::to_repr
fn TraceResult::to_repr(TraceResult) -> @moonbitlang/core/debug.ReprTraceRun
pub struct TraceRun {
result : TraceResult?
validated : ValidatedTrace?
diagnostics : ReadOnlyArray[@moonrockz/diagrams.Diagnostic]
}The result of an explicit provider run.
TraceRun::refused
fn TraceRun::refused(diagnostics : ArrayView[@moonrockz/diagrams.Diagnostic]) -> TraceRunA run that did not reach a provider, with the reasons.
TraceValidation
pub struct TraceValidation {
validated : ValidatedTrace?
diagnostics : ReadOnlyArray[@moonrockz/diagrams.Diagnostic]
}Track
pub struct Track {
id : String
name : String
start : String
end : String
} derive(Eq, @moonbitlang/core/debug.Debug)One rule, or the single pattern of a regex, with its boundary points.
Track::equal
fn Track::equal(Track, Track) -> BoolTrack::not_equal
fn Track::not_equal(x : Track, y : Track) -> BoolTrack::to_repr
fn Track::to_repr(Track) -> @moonbitlang/core/debug.ReprValidatedTrace
pub struct ValidatedTrace {
trace : Trace
topology : Topology
}A trace that passed structural validation against one subject, with the topology it refers to. Validation never re-runs or verifies matching.
Traits
RailroadTraceProvider
pub(open) trait RailroadTraceProvider {
fn trace(Self, TraceRequest) -> TraceResult
}A publicly implementable hook for an external regex matcher or grammar
parser. This library bundles no implementation. A provider that supports
one subject kind returns Unsupported for the other.
Values
connector_id
fn connector_id(owner : String, role : ConnectorRole) -> StringThe stable identity of the connector that owner draws with role.
diagnostic_codes
let diagnostic_codes : ReadOnlyArray[String]The stable diagnostic codes of trace validation and the provider driver.
point_id
fn point_id(owner : String, side : String) -> StringThe stable identity of a point. Identities are length-prefixed, so a
node identity that contains : cannot collide with another point.
run
fn[P : RailroadTraceProvider] run(provider : P, request : TraceRequest) -> TraceRunInvoke provider once for request and validate its result. This is the
only library entry point that calls a provider.
validate_result
fn validate_result(result : TraceResult, subject : Subject, view_id? : String, limits? : TraceLimits) -> TraceValidationValidate a provider result. A matched result needs a matched attempt; a non-match result has none.
validate_trace
fn validate_trace(trace : Trace, subject : Subject, view_id? : String, limits? : TraceLimits) -> TraceValidationValidate supplied evidence: subject kind, model/view identity, structural fingerprint, targets, roles, declared continuity, spans and bounds. It reports invalid evidence without guessing targets from labels.