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.

Source

Attempt::equal

fn Attempt::equal(Attempt, Attempt) -> Bool

Source

Attempt::new

fn Attempt::new(id : String, status : AttemptStatus, steps : ArrayView[Step], failure? : FailurePoint, continuous? : Bool, label? : String) -> Attempt

Source

Attempt::not_equal

fn Attempt::not_equal(x : Attempt, y : Attempt) -> Bool

Source

Attempt::to_repr

fn Attempt::to_repr(Attempt) -> @moonbitlang/core/debug.Repr

Source

AttemptStatus

pub(all) enum AttemptStatus {
  Matched
  NotMatched
} derive(Eq, @moonbitlang/core/debug.Debug)

Source

AttemptStatus::equal

fn AttemptStatus::equal(AttemptStatus, AttemptStatus) -> Bool

Source

AttemptStatus::not_equal

fn AttemptStatus::not_equal(x : AttemptStatus, y : AttemptStatus) -> Bool

Source

AttemptStatus::to_repr

fn AttemptStatus::to_repr(AttemptStatus) -> @moonbitlang/core/debug.Repr

Source

Connector

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.

Source

Connector::equal

fn Connector::equal(Connector, Connector) -> Bool

Source

Connector::not_equal

fn Connector::not_equal(x : Connector, y : Connector) -> Bool

Source

Connector::to_repr

fn Connector::to_repr(Connector) -> @moonbitlang/core/debug.Repr

Source

ConnectorRole

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.

Source

ConnectorRole::equal

fn ConnectorRole::equal(ConnectorRole, ConnectorRole) -> Bool

Source

ConnectorRole::name

fn ConnectorRole::name(self : ConnectorRole) -> String

Source

ConnectorRole::not_equal

fn ConnectorRole::not_equal(x : ConnectorRole, y : ConnectorRole) -> Bool

Source

ConnectorRole::to_repr

fn ConnectorRole::to_repr(ConnectorRole) -> @moonbitlang/core/debug.Repr

Source

FailurePoint

pub struct FailurePoint {
  target : FailureTarget
  position : Int?
  message : String?
} derive(Eq, @moonbitlang/core/debug.Debug)

Source

FailurePoint::equal

fn FailurePoint::equal(FailurePoint, FailurePoint) -> Bool

Source

FailurePoint::new

fn FailurePoint::new(target : FailureTarget, position? : Int, message? : String) -> FailurePoint

Source

FailurePoint::not_equal

fn FailurePoint::not_equal(x : FailurePoint, y : FailurePoint) -> Bool

Source

FailurePoint::to_repr

fn FailurePoint::to_repr(FailurePoint) -> @moonbitlang/core/debug.Repr

Source

FailureTarget

pub(all) enum FailureTarget {
  Terminal(String)
  Assertion(String)
  Entry(String)
  Exit(String)
} derive(Eq, @moonbitlang/core/debug.Debug)

The place where an attempt failed.

Source

FailureTarget::equal

fn FailureTarget::equal(FailureTarget, FailureTarget) -> Bool

Source

FailureTarget::not_equal

fn FailureTarget::not_equal(x : FailureTarget, y : FailureTarget) -> Bool

Source

FailureTarget::to_repr

fn FailureTarget::to_repr(FailureTarget) -> @moonbitlang/core/debug.Repr

Source

InputSpan

pub struct InputSpan {
  start : Int
  end : Int
} derive(Eq, @moonbitlang/core/debug.Debug)

A half-open UTF-16 span of the input.

Source

InputSpan::equal

fn InputSpan::equal(InputSpan, InputSpan) -> Bool

Source

InputSpan::new

fn InputSpan::new(start : Int, end : Int) -> InputSpan

Source

InputSpan::not_equal

fn InputSpan::not_equal(x : InputSpan, y : InputSpan) -> Bool

Source

InputSpan::to_repr

fn InputSpan::to_repr(InputSpan) -> @moonbitlang/core/debug.Repr

Source

Step

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.

Source

Step::equal

fn Step::equal(Step, Step) -> Bool

Source

Step::not_equal

fn Step::not_equal(x : Step, y : Step) -> Bool

Source

Step::to_repr

fn Step::to_repr(Step) -> @moonbitlang/core/debug.Repr

Source

Subject

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.

Source

Subject::equal

fn Subject::equal(Subject, Subject) -> Bool

Source

Subject::fingerprint

fn Subject::fingerprint(self : Subject) -> String

The fingerprint of the structure of a subject. A trace for an edited or different model has a different fingerprint, even with equal identities.

Source

Subject::identity

fn Subject::identity(self : Subject, view_id? : String) -> SubjectIdentity

Source

Subject::kind

fn Subject::kind(self : Subject) -> SubjectKind

Source

Subject::model_id

fn Subject::model_id(self : Subject) -> String

Source

Subject::not_equal

fn Subject::not_equal(x : Subject, y : Subject) -> Bool

Source

Subject::to_repr

fn Subject::to_repr(Subject) -> @moonbitlang/core/debug.Repr

Source

SubjectIdentity

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.

Source

SubjectIdentity::equal

fn SubjectIdentity::equal(SubjectIdentity, SubjectIdentity) -> Bool

Source

SubjectIdentity::not_equal

fn SubjectIdentity::not_equal(x : SubjectIdentity, y : SubjectIdentity) -> Bool

Source

SubjectIdentity::to_repr

fn SubjectIdentity::to_repr(SubjectIdentity) -> @moonbitlang/core/debug.Repr

Source

SubjectKind

pub(all) enum SubjectKind {
  Regex
  Ebnf
} derive(Eq, @moonbitlang/core/debug.Debug)

The two railroad subject kinds.

Source

SubjectKind::equal

fn SubjectKind::equal(SubjectKind, SubjectKind) -> Bool

Source

SubjectKind::not_equal

fn SubjectKind::not_equal(x : SubjectKind, y : SubjectKind) -> Bool

Source

SubjectKind::to_repr

fn SubjectKind::to_repr(SubjectKind) -> @moonbitlang/core/debug.Repr

Source

Term

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.

Source

Term::equal

fn Term::equal(Term, Term) -> Bool

Source

Term::not_equal

fn Term::not_equal(x : Term, y : Term) -> Bool

Source

Term::to_repr

fn Term::to_repr(Term) -> @moonbitlang/core/debug.Repr

Source

TermKind

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.

Source

TermKind::equal

fn TermKind::equal(TermKind, TermKind) -> Bool

Source

TermKind::not_equal

fn TermKind::not_equal(x : TermKind, y : TermKind) -> Bool

Source

TermKind::to_repr

fn TermKind::to_repr(TermKind) -> @moonbitlang/core/debug.Repr

Source

Topology

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.

Source

Topology::connector

fn Topology::connector(self : Topology, id : String) -> Connector?

Source

Topology::connector_between

fn Topology::connector_between(self : Topology, from : String, to : String) -> Connector?

The connector between two points, if one is drawn.

Source

Topology::connector_of

fn Topology::connector_of(self : Topology, owner : String, role : ConnectorRole) -> Connector?

The connector with role that owner draws, if any.

Source

Topology::connectors_from

fn Topology::connectors_from(self : Topology, point : String) -> Array[Connector]

The connectors that leave point, in drawing order.

Source

Topology::ebnf

fn Topology::ebnf(grammar : @moonrockz/diagrams/ebnf.Grammar, limits? : @moonrockz/diagrams/ebnf.Limits) -> TopologyResult

Build the topology of a grammar. Each rule is one track. References are terms; no connector joins two rules.

Source

Topology::entry

fn Topology::entry(self : Topology, id : String) -> String?

The entry point of a node, rule or model identity.

Source

Topology::exit

fn Topology::exit(self : Topology, id : String) -> String?

The exit point of a node, rule or model identity.

Source

Topology::has_point

fn Topology::has_point(self : Topology, point : String) -> Bool

Source

Topology::regex

fn Topology::regex(model : @moonrockz/diagrams/regex.Regex, limits? : @moonrockz/diagrams/regex.Limits) -> TopologyResult

Build the topology of a regex model. The pattern is one track whose identity is the model identity.

Source

Topology::term

fn Topology::term(self : Topology, id : String) -> Term?

Source

TopologyResult

pub struct TopologyResult {
  topology : Topology?
  diagnostics : ReadOnlyArray[@moonrockz/diagrams.Diagnostic]
}

Source

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.

Source

Trace::equal

fn Trace::equal(Trace, Trace) -> Bool

Source

Trace::new

fn Trace::new(request : TraceRequest, provider : String, attempts : ArrayView[Attempt]) -> Trace

Make a trace bound to the subject of request.

Source

Trace::not_equal

fn Trace::not_equal(x : Trace, y : Trace) -> Bool

Source

Trace::to_repr

fn Trace::to_repr(Trace) -> @moonbitlang/core/debug.Repr

Source

TraceLimits

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.

Source

TraceLimits::equal

fn TraceLimits::equal(TraceLimits, TraceLimits) -> Bool

Source

TraceLimits::new

fn TraceLimits::new(input? : Int, attempts? : Int, steps? : Int, depth? : Int, work? : Int) -> TraceLimits

Source

TraceLimits::not_equal

fn TraceLimits::not_equal(x : TraceLimits, y : TraceLimits) -> Bool

Source

TraceLimits::to_repr

fn TraceLimits::to_repr(TraceLimits) -> @moonbitlang/core/debug.Repr

Source

TraceLimits::valid

fn TraceLimits::valid(self : TraceLimits) -> Bool

Source

TraceRequest

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.

Source

TraceRequest::ebnf

fn TraceRequest::ebnf(grammar : @moonrockz/diagrams/ebnf.Grammar, start_rule : String, input : String, view_id? : String, limits? : TraceLimits) -> TraceRequest

Source

TraceRequest::equal

fn TraceRequest::equal(TraceRequest, TraceRequest) -> Bool

Source

TraceRequest::identity

fn TraceRequest::identity(self : TraceRequest) -> SubjectIdentity

The provenance that a trace for this request must carry.

Source

TraceRequest::not_equal

fn TraceRequest::not_equal(x : TraceRequest, y : TraceRequest) -> Bool

Source

TraceRequest::regex

fn TraceRequest::regex(model : @moonrockz/diagrams/regex.Regex, input : String, view_id? : String, limits? : TraceLimits) -> TraceRequest

Source

TraceRequest::to_repr

fn TraceRequest::to_repr(TraceRequest) -> @moonbitlang/core/debug.Repr

Source

TraceRequest::topology

fn TraceRequest::topology(self : TraceRequest) -> TopologyResult

The semantic topology of the requested subject, for mapping engine events.

Source

TraceRequest::validate

fn TraceRequest::validate(self : TraceRequest) -> ReadOnlyArray[@moonrockz/diagrams.Diagnostic]

Check a request before a provider receives it.

Source

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.

Source

TraceResult::equal

fn TraceResult::equal(TraceResult, TraceResult) -> Bool

Source

TraceResult::not_equal

fn TraceResult::not_equal(x : TraceResult, y : TraceResult) -> Bool

Source

TraceResult::to_repr

fn TraceResult::to_repr(TraceResult) -> @moonbitlang/core/debug.Repr

Source

TraceRun

pub struct TraceRun {
  result : TraceResult?
  validated : ValidatedTrace?
  diagnostics : ReadOnlyArray[@moonrockz/diagrams.Diagnostic]
}

The result of an explicit provider run.

Source

TraceRun::refused

fn TraceRun::refused(diagnostics : ArrayView[@moonrockz/diagrams.Diagnostic]) -> TraceRun

A run that did not reach a provider, with the reasons.

Source

TraceValidation

pub struct TraceValidation {
  validated : ValidatedTrace?
  diagnostics : ReadOnlyArray[@moonrockz/diagrams.Diagnostic]
}

Source

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.

Source

Track::equal

fn Track::equal(Track, Track) -> Bool

Source

Track::not_equal

fn Track::not_equal(x : Track, y : Track) -> Bool

Source

Track::to_repr

fn Track::to_repr(Track) -> @moonbitlang/core/debug.Repr

Source

ValidatedTrace

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.

Source

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.

Source

Values

connector_id

fn connector_id(owner : String, role : ConnectorRole) -> String

The stable identity of the connector that owner draws with role.

Source

diagnostic_codes

let diagnostic_codes : ReadOnlyArray[String]

The stable diagnostic codes of trace validation and the provider driver.

Source

point_id

fn point_id(owner : String, side : String) -> String

The stable identity of a point. Identities are length-prefixed, so a node identity that contains : cannot collide with another point.

Source

run

fn[P : RailroadTraceProvider] run(provider : P, request : TraceRequest) -> TraceRun

Invoke provider once for request and validate its result. This is the only library entry point that calls a provider.

Source

validate_result

fn validate_result(result : TraceResult, subject : Subject, view_id? : String, limits? : TraceLimits) -> TraceValidation

Validate a provider result. A matched result needs a matched attempt; a non-match result has none.

Source

validate_trace

fn validate_trace(trace : Trace, subject : Subject, view_id? : String, limits? : TraceLimits) -> TraceValidation

Validate 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.

Source