moonrockz/diagrams/ebnf

Types

Grammar

pub struct Grammar {
  id : String
  items : ReadOnlyArray[Item]
  nodes : ReadOnlyArray[Node]
  title : String?
  accessibility_title : String?
  accessibility_description : String?
} derive(Eq, @moonbitlang/core/debug.Debug)

One immutable grammar diagram. It describes a grammar; it does not parse input.

Source

Grammar::equal

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

Source

Grammar::new

fn Grammar::new(id : String, items : ArrayView[Item], nodes : ArrayView[Node], title? : String, accessibility_title? : String, accessibility_description? : String) -> Grammar

Source

Grammar::not_equal

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

Source

Grammar::rules

fn Grammar::rules(self : Grammar) -> Array[Rule]

The rules of the grammar in source order.

Source

Grammar::to_repr

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

Source

Index

pub struct Index {
  grammar : Grammar
  order : ReadOnlyArray[String]
  // private fields
}

A validated grammar with constant-time lookups. Each expression node has exactly one owner. References are symbolic and never expand definitions.

Source

Index::build

fn Index::build(grammar : Grammar, limits? : Limits) -> IndexResult

Validate identities, ownership, references, counts and limits without recursion. Unresolved and ambiguous names are warnings.

Source

Index::depth

fn Index::depth(self : Index, id : String) -> Int?

Source

Index::node

fn Index::node(self : Index, id : String) -> Node?

Source

Index::owner

fn Index::owner(self : Index, id : String) -> String?

The identity of the rule that owns an expression node.

Source

Index::parent

fn Index::parent(self : Index, id : String) -> String?

The parent node of an expression node. The body root has no parent.

Source

Index::resolution

fn Index::resolution(self : Index, id : String) -> Resolution?

The resolution of a reference node, or None for another node kind.

Source

Index::rule

fn Index::rule(self : Index, id : String) -> Rule?

Source

IndexResult

pub struct IndexResult {
  index : Index?
  diagnostics : ReadOnlyArray[@moonrockz/diagrams.Diagnostic]
}

Source

Item

pub(all) enum Item {
  Rule(Rule)
  Note(String, String)
} derive(Eq, @moonbitlang/core/debug.Debug)

One ordered grammar statement: a rule or a free-standing note.

Source

Item::equal

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

Source

Item::not_equal

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

Source

Item::to_repr

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

Source

Kind

pub(all) enum Kind {
  Terminal(String, Quote)
  Reference(String, String?)
  Special(String)
  Empty
  Sequence(ReadOnlyArray[String])
  Choice(ReadOnlyArray[String])
  Optional(String)
  ZeroOrMore(String)
  OneOrMore(String)
  Count(String, String)
  Exclusion(String, String)
} derive(Eq, @moonbitlang/core/debug.Debug)

The meaning of one grammar expression node. Composite kinds name their children by node identity, so a grammar is a flat, bounded arena.

Source

Kind::equal

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

Source

Kind::not_equal

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

Source

Kind::to_repr

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

Source

Limits

pub struct Limits {
  nodes : Int
  depth : Int
  work : Int
} derive(Eq, @moonbitlang/core/debug.Debug)

Explicit bounds for grammar validation and indexing.

Source

Limits::equal

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

Source

Limits::new

fn Limits::new(nodes? : Int, depth? : Int, work? : Int) -> Limits

Source

Limits::not_equal

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

Source

Limits::to_repr

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

Source

Node

pub struct Node {
  id : String
  kind : Kind
  notes_above : ReadOnlyArray[String]
  notes_below : ReadOnlyArray[String]
  source : @moonrockz/diagrams.Span?
} derive(Eq, @moonbitlang/core/debug.Debug)

Source

Node::children

fn Node::children(self : Node) -> ReadOnlyArray[String]

The children of node in drawing order. An exclusion lists its left term first and its excluded term second.

Source

Node::equal

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

Source

Node::is_leaf

fn Node::is_leaf(self : Node) -> Bool

Terminals, references, special sequences and empty terms are leaves.

Source

Node::label

fn Node::label(self : Node) -> String

Source

Node::new

fn Node::new(id : String, kind : Kind, notes_above? : ArrayView[String], notes_below? : ArrayView[String], source? : @moonrockz/diagrams.Span) -> Node

Source

Node::not_equal

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

Source

Node::to_repr

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

Source

Quote

pub(all) enum Quote {
  Double
  Single
} derive(Eq, @moonbitlang/core/debug.Debug)

The quote character of a terminal string.

Source

Quote::equal

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

Source

Quote::not_equal

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

Source

Quote::to_repr

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

Source

Resolution

pub(all) enum Resolution {
  Resolved(String)
  Unresolved
  Ambiguous(ReadOnlyArray[String])
} derive(Eq, @moonbitlang/core/debug.Debug)

How a reference resolved. Unresolved and ambiguous names stay renderable.

Source

Resolution::equal

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

Source

Resolution::not_equal

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

Source

Resolution::to_repr

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

Source

Rule

pub struct Rule {
  id : String
  name : String
  body : String?
  note_above : String?
  note_below : String?
  source : @moonrockz/diagrams.Span?
} derive(Eq, @moonbitlang/core/debug.Debug)

One named rule. A rule without a body is an empty definition.

Source

Rule::equal

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

Source

Rule::new

fn Rule::new(id : String, name : String, body? : String, note_above? : String, note_below? : String, source? : @moonrockz/diagrams.Span) -> Rule

Source

Rule::not_equal

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

Source

Rule::to_repr

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

Source

Values

diagnostic_codes

let diagnostic_codes : ReadOnlyArray[String]

The stable diagnostic codes of grammar validation.

Source

validate

fn validate(grammar : Grammar, limits? : Limits) -> ReadOnlyArray[@moonrockz/diagrams.Diagnostic]

Validate a constructed grammar. Errors prevent rendering; warnings for unresolved or ambiguous names do not.

Source