moonrockz/notebooks/dib

Types

Cell

type Cell derive(Eq, @moonbitlang/core/debug.Debug)

An immutable source cell with a kernel name. Sources normalize line endings and trim only empty boundary lines. Notebook construction resolves kernel aliases; a standalone cell may still contain an alias.

Source

Cell::Cell

fn Cell::Cell(source : String, kernel~ : KernelName) -> Cell

Normalize LF, CRLF and CR to LF and remove empty boundary lines. Retain whitespace-only and internal blank lines. Registry membership is checked by Notebook construction; selector conflicts are checked on writing.

Source

Cell::directives

fn Cell::directives(self : Cell) -> ReadOnlyArray[Directive]

Return column-zero #! lines in source order as immutable directive views. Indented lines are excluded. Kernel selectors consumed during parsing are cell properties and do not appear in parsed cell source.

Source

Cell::equal

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

Source

Cell::kernel

fn Cell::kernel(self : Cell) -> KernelName

Return the cell's kernel name. Notebook construction canonicalizes registered aliases; a standalone Cell retains the supplied name.

Source

Cell::kind

fn Cell::kind(self : Cell) -> @moonrockz/notebooks.CellKind

Classify markdown and md cells as Markdown and other kernels as Code.

Source

Cell::metadata

fn Cell::metadata(_self : Cell) -> @moonrockz/notebooks.Metadata?

DIB has no stored MIME bundles, so capability inspection uses the shared default of None. It also has no cell-local metadata container.

Source

Cell::mime_capability

fn Cell::mime_capability(_self : Cell) -> &@moonrockz/notebooks.MimeTyped?

DIB has no stored MIME bundles, so capability inspection uses the shared default of None. It also has no cell-local metadata container.

Source

Cell::not_equal

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

Source

Cell::source

fn Cell::source(self : Cell) -> String

Return normalized cell source without its kernel selector.

Source

Cell::to_repr

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

Source

impl CellView for Cell

CellView::kind

fn kind(self : Cell) -> @moonrockz/notebooks.CellKind

Source

CellView::source

fn source(self : Cell) -> String?

Source

Directive

type Directive derive(Eq, @moonbitlang/core/debug.Debug)

An immutable column-zero #! line retained in cell source, with a name, unparsed arguments, exact normalized line text and one-based source line. This view does not execute commands or interpret quoted arguments.

Source

Directive::arguments

fn Directive::arguments(self : Directive) -> String

Return the remaining command text with leading whitespace removed. Arguments remain uninterpreted; quoting is not parsed.

Source

Directive::equal

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

Source

Directive::line

fn Directive::line(self : Directive) -> Int

Return the one-based line relative to normalized cell source, not the line number in the original DIB document.

Source

Directive::name

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

Return the command token after #!, stopping at the first space or tab.

Source

Directive::not_equal

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

Source

Directive::text

fn Directive::text(self : Directive) -> String

Return the complete #! source line, without a newline terminator.

Source

Directive::to_repr

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

Source

KernelInfo

type KernelInfo derive(Eq, @moonbitlang/core/debug.Debug)

An immutable registration describing a canonical kernel name, its aliases and an optional language label. Names alone do not execute or install a kernel.

Source

KernelInfo::KernelInfo

fn KernelInfo::KernelInfo(name : KernelName, aliases? : ReadOnlyArray[KernelName], language? : String?) -> KernelInfo

Describe a kernel using validated names. Defaults to no aliases and no language label. Registry construction checks name and alias collisions.

Source

KernelInfo::aliases

fn KernelInfo::aliases(self : KernelInfo) -> ReadOnlyArray[KernelName]

Return immutable case-sensitive aliases for this kernel.

Source

KernelInfo::equal

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

Source

KernelInfo::language

fn KernelInfo::language(self : KernelInfo) -> String?

Return the optional language label supplied by the registration.

Source

KernelInfo::name

fn KernelInfo::name(self : KernelInfo) -> KernelName

Return this registration's canonical name.

Source

KernelInfo::not_equal

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

Source

KernelInfo::to_repr

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

Source

KernelName

type KernelName derive(Eq, @moonbitlang/core/debug.Debug)

A validated kernel name or alias. Names are case-sensitive and nonblank; they cannot start with #, contain line breaks or name a metadata header.

Source

KernelName::KernelName

fn KernelName::KernelName(value : String) -> KernelName raise FormatError

Validate a case-sensitive kernel name or alias. Raise InvalidKernelName for blank names, leading #, line breaks or reserved metadata selectors. This validates spelling, not membership in a kernel registry.

test "doc: resolve a kernel alias" {
  let registry = @dib.KernelRegistry::standard()
  let name = @dib.KernelName("csharp")
  @expect.expect(registry.resolve("c#")).to_equal(Some(name))
}

Source

KernelName::equal

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

Source

KernelName::not_equal

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

Source

KernelName::to_repr

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

Source

KernelName::to_string

fn KernelName::to_string(self : KernelName) -> String

Return the name or alias exactly as supplied.

Source

KernelRegistry

type KernelRegistry derive(Eq, @moonbitlang/core/debug.Debug)

An immutable execution environment used to distinguish cell selectors from source directives. Lookups map canonical names and aliases to canonical KernelName values. Parsing also supplies the Markdown pseudo-kernel.

Source

KernelRegistry::KernelRegistry

fn KernelRegistry::KernelRegistry(kernels : ReadOnlyArray[KernelInfo], default_kernel~ : KernelName) -> KernelRegistry raise FormatError

Build a registry and resolve its required default name or alias. Raise DuplicateKernelName for any repeated name/alias, including within one registration, or UnknownKernel if the default cannot be resolved.

Source

KernelRegistry::default_kernel

fn KernelRegistry::default_kernel(self : KernelRegistry) -> KernelName

Return the default kernel's canonical name.

Source

KernelRegistry::equal

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

Source

KernelRegistry::kernels

fn KernelRegistry::kernels(self : KernelRegistry) -> ReadOnlyArray[KernelInfo]

Return immutable registrations in their stored order.

Source

KernelRegistry::not_equal

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

Source

KernelRegistry::resolve

fn KernelRegistry::resolve(self : KernelRegistry, name : String) -> KernelName?

Resolve an exact, case-sensitive name or alias to its canonical name. Return None for an unregistered name.

Source

KernelRegistry::standard

fn KernelRegistry::standard() -> KernelRegistry

Return the standard execution-kernel registrations with C# as default. Includes C#, F#, PowerShell, JavaScript, HTML, SQL, KQL, HTTP, value and Mermaid. Parsing and Notebook construction also add Markdown as needed.

Source

KernelRegistry::to_repr

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

Source

MetadataOutput

pub(all) enum MetadataOutput {
  Auto
  Json
  Ion
} derive(Eq, @moonbitlang/core/debug.Debug)

DIB output keeps JSON when it preserves the metadata, otherwise uses Ion. Explicit Json requests reject metadata that cannot round-trip through JSON.

Source

MetadataOutput::equal

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

Source

MetadataOutput::not_equal

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

Source

MetadataOutput::to_repr

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

Source

Node

pub(all) enum Node {
  Notebook(Notebook)
  Cell(Cell)
  Directive(Directive)
} derive(Eq, @moonbitlang/core/debug.Debug)

A concrete DIB traversal node. Notebook children are cells in source order; cell children are retained directives in source order. Directives are leaves. Metadata and kernel registrations use their own accessors.

Source

Node::at

fn Node::at(self : Node, path : @moonrockz/notebooks.NodePath) -> Node?

Resolve a shared child-index path relative to this node, returning None for any invalid index. Cell child indices refer to retained directives.

Source

Node::children

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

Return immutable cells or directives in source order. Directive leaves have no children. Kernel selectors are properties of cells, not children.

Source

Node::cursor

fn Node::cursor(self : Node) -> @moonrockz/notebooks.Cursor[Node]

Establish a new navigation root at this node. Use an existing cursor to retain its original paths and ancestors.

Source

Node::equal

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

Source

Node::kind

fn Node::kind(self : Node) -> @moonrockz/notebooks.NodeKind

Classify this concrete node for shared traversal. Directive kinds retain the command name, while concrete nodes retain the complete directive.

Source

Node::metadata

fn Node::metadata(self : Node) -> @moonrockz/notebooks.Metadata?

Return this node's own metadata. Some(empty) retains an empty container; None means this node has none. Ancestor metadata is never inherited.

Source

Node::not_equal

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

Source

Node::source

fn Node::source(self : Node) -> String?

Return normalized cell source or a directive's source line. Return None for a notebook node.

Source

Node::to_repr

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

Source

impl Node for Node

Node::children

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

Source

Node::kind

fn kind(self : Node) -> @moonrockz/notebooks.NodeKind

Source

Node::metadata

fn metadata(self : Node) -> @moonrockz/notebooks.Metadata?

Source

Node::source

fn source(self : Node) -> String?

Source

Notebook

type Notebook derive(Eq, @moonbitlang/core/debug.Debug)

An immutable DIB source notebook with ordered cells, metadata and the kernel registry needed to interpret its selectors. DIB stores no outputs.

Source

Notebook::Notebook

fn Notebook::Notebook(cells : ReadOnlyArray[Cell], metadata? : @moonrockz/notebooks.Metadata, registry? : KernelRegistry) -> Notebook raise FormatError

Build a notebook with empty metadata and the standard registry by default. Interpret metadata registrations and canonicalize each cell's kernel alias. Raise FormatError for invalid registration metadata, duplicate kernel names or unregistered cell kernels. Empty cells remain until serialization.

Source

Notebook::cell

fn Notebook::cell(self : Notebook, index : Int) -> Cell?

Look up a zero-based cell index. Return None for negative or out-of-range indices.

Source

Notebook::cells

fn Notebook::cells(self : Notebook) -> ReadOnlyArray[Cell]

Return immutable cells in source order, including constructed empty cells.

Source

Notebook::cells_for_kernel

fn Notebook::cells_for_kernel(self : Notebook, name : String) -> ReadOnlyArray[Cell]

Resolve a canonical name or alias, then select matching cells in source order. Return an empty immutable array for an unknown name. Markdown is a selectable pseudo-kernel.

Source

Notebook::cursor

fn Notebook::cursor(self : Notebook) -> @moonrockz/notebooks.Cursor[Node]

Start a typed DIB cursor at this notebook with depth zero and path $.

Source

Notebook::equal

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

Source

Notebook::fold

fn[A] Notebook::fold(self : Notebook, init : A, f : (A, @moonrockz/notebooks.Cursor[Node]) -> A) -> A

Thread an accumulator through this notebook tree in pre-order, supplying typed DIB cursors. Use walk for pruning or early termination.

Source

Notebook::metadata

fn Notebook::metadata(self : Notebook) -> @moonrockz/notebooks.Metadata

Return immutable document metadata, retaining custom namespaces.

Source

Notebook::not_equal

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

Source

Notebook::registry

fn Notebook::registry(self : Notebook) -> KernelRegistry

Return the effective registry, including metadata declarations and Markdown. Retain it when rereading custom environment-dependent selectors.

Source

Notebook::root

fn Notebook::root(self : Notebook) -> Node

Wrap this notebook as the concrete root accepted by shared traversal.

Source

Notebook::to_repr

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

Source

Notebook::to_string

fn Notebook::to_string(self : Notebook, metadata_output? : MetadataOutput) -> String raise FormatError

Serialize normalized DIB source using canonical kernel selectors. Omit empty cells and retain document metadata. Auto output uses JSON when it preserves the metadata, otherwise Ion. Explicit Json rejects data loss. Emit a header when needed to preserve later metadata directives as source. Raise UnrepresentableSource if embedded registered selectors would split a cell. Custom kernels supplied only by the environment require the same registry on subsequent reads; the writer does not inject those registrations.

Source

Errors

FormatError

pub(all) suberror FormatError {
  InvalidMetadata(line~ : Int, message~ : String)
  InvalidKernelName(String)
  DuplicateKernelName(String)
  UnknownKernel(String)
  UnrepresentableSource(cell~ : Int, line~ : Int)
} derive(Eq, @moonbitlang/core/debug.Debug)

A DIB metadata, kernel registration or serialization failure. UnrepresentableSource identifies a zero-based cell index and a one-based line within its normalized source. Metadata line numbers are one-based.

Source

FormatError::equal

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

Source

FormatError::not_equal

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

Source

FormatError::to_repr

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

Source

Type aliases

Control

using @moonrockz/notebooks { type Control }

Shared navigation types. Explicit cursor annotations use Cursor[Node].

Source

Cursor

using @moonrockz/notebooks { type Cursor }

Shared navigation types. Explicit cursor annotations use Cursor[Node].

Source

Metadata

using @moonrockz/notebooks { type Metadata }

Shared navigation types. Explicit cursor annotations use Cursor[Node].

Source

NodePath

using @moonrockz/notebooks { type NodePath }

Shared navigation types. Explicit cursor annotations use Cursor[Node].

Source

Values

parse

fn parse(source : String, registry? : KernelRegistry) -> Notebook raise FormatError

Read a DIB source notebook without executing it. Registered, exact column-zero selectors start cells; other directives remain source. Read the first exact metadata section and apply its registrations. #!meta and #!meta json read JSON; #!meta yaml, #!meta toml and #!meta ion are extensions. Normalize line endings, trim empty boundary lines and omit empty sections; an empty document yields one empty cell. Accept a leading BOM. Raise FormatError for invalid metadata or conflicting kernel registrations.

Source

walk

fn walk(root : Node, enter : (Node) -> @moonrockz/notebooks.Control, leave? : (Node) -> Unit) -> Unit

Walk concrete DIB nodes in depth-first pre-order with the shared engine. Use walk_cursor when callbacks need path or ancestor context.

Source

walk_cursor

fn walk_cursor(root : Node, enter : (@moonrockz/notebooks.Cursor[Node]) -> @moonrockz/notebooks.Control, leave? : (@moonrockz/notebooks.Cursor[Node]) -> Unit) -> Unit

Use the shared engine to walk typed DIB positions from a new root. SkipChildren still receives leave; Stop cancels pending leave calls.

Source