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.
Grammar::equal
fn Grammar::equal(Grammar, Grammar) -> BoolGrammar::new
fn Grammar::new(id : String, items : ArrayView[Item], nodes : ArrayView[Node], title? : String, accessibility_title? : String, accessibility_description? : String) -> GrammarGrammar::not_equal
fn Grammar::not_equal(x : Grammar, y : Grammar) -> BoolGrammar::rules
fn Grammar::rules(self : Grammar) -> Array[Rule]The rules of the grammar in source order.
Grammar::to_repr
fn Grammar::to_repr(Grammar) -> @moonbitlang/core/debug.ReprIndex
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.
Index::build
fn Index::build(grammar : Grammar, limits? : Limits) -> IndexResultValidate identities, ownership, references, counts and limits without recursion. Unresolved and ambiguous names are warnings.
Index::depth
fn Index::depth(self : Index, id : String) -> Int?Index::node
fn Index::node(self : Index, id : String) -> Node?Index::owner
fn Index::owner(self : Index, id : String) -> String?The identity of the rule that owns an expression node.
Index::parent
fn Index::parent(self : Index, id : String) -> String?The parent node of an expression node. The body root has no parent.
Index::resolution
fn Index::resolution(self : Index, id : String) -> Resolution?The resolution of a reference node, or None for another node kind.
Index::rule
fn Index::rule(self : Index, id : String) -> Rule?IndexResult
pub struct IndexResult {
index : Index?
diagnostics : ReadOnlyArray[@moonrockz/diagrams.Diagnostic]
}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.
Item::equal
fn Item::equal(Item, Item) -> BoolItem::not_equal
fn Item::not_equal(x : Item, y : Item) -> BoolItem::to_repr
fn Item::to_repr(Item) -> @moonbitlang/core/debug.ReprKind
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.
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 grammar 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.ReprNode
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)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.
Node::equal
fn Node::equal(Node, Node) -> BoolNode::is_leaf
fn Node::is_leaf(self : Node) -> BoolTerminals, references, special sequences and empty terms are leaves.
Node::label
fn Node::label(self : Node) -> StringNode::new
fn Node::new(id : String, kind : Kind, notes_above? : ArrayView[String], notes_below? : ArrayView[String], 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.ReprQuote
pub(all) enum Quote {
Double
Single
} derive(Eq, @moonbitlang/core/debug.Debug)The quote character of a terminal string.
Quote::equal
fn Quote::equal(Quote, Quote) -> BoolQuote::not_equal
fn Quote::not_equal(x : Quote, y : Quote) -> BoolQuote::to_repr
fn Quote::to_repr(Quote) -> @moonbitlang/core/debug.ReprResolution
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.
Resolution::equal
fn Resolution::equal(Resolution, Resolution) -> BoolResolution::not_equal
fn Resolution::not_equal(x : Resolution, y : Resolution) -> BoolResolution::to_repr
fn Resolution::to_repr(Resolution) -> @moonbitlang/core/debug.ReprRule
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.
Rule::equal
fn Rule::equal(Rule, Rule) -> BoolRule::new
fn Rule::new(id : String, name : String, body? : String, note_above? : String, note_below? : String, source? : @moonrockz/diagrams.Span) -> RuleRule::not_equal
fn Rule::not_equal(x : Rule, y : Rule) -> BoolRule::to_repr
fn Rule::to_repr(Rule) -> @moonbitlang/core/debug.ReprValues
diagnostic_codes
let diagnostic_codes : ReadOnlyArray[String]The stable diagnostic codes of grammar validation.
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.