Skip to main content

Module model

Module model 

Expand description

Structured model for the math editor.

A formula is a Row — an ordered list of Node atoms. Atoms are either leaves (a single character: a digit, an operator, a letter of an identifier) or structures that own one or more child rows (a fraction owns a numerator row and a denominator row; a power owns an exponent row; a radical owns a radicand row and an optional index row). This is a real tree, not a flat string — which is what makes a true 2D caret, structural backspace, and stacked rendering possible.

The model serializes to a compact linear expression and parses that form back into a tree. Applications may feed the serialization to an evaluator, persist it, or use the tree directly for read-only mathematical content.

Structs§

MathExpr
The whole editable document for one field.
Path
A caret location: a chain of (node index in the current row, which child slot) descents, terminated by an offset insertion gap in the deepest row. An empty steps with offset = k means “gap k in the root row”.

Enums§

Node
One element of a Row.
Slot
Which child row of a structure a path step descends into.

Constants§

FUNCS
Names rendered upright as function calls when reading a linear string.

Functions§

child_row
child_row_mut
node_slots
Slots a node exposes, in caret Up/Down navigation order (top → bottom).
parse
Parse a flat ASCII expression into a structured tree. Best-effort and total: anything it cannot classify is kept as literal Char atoms so the field never loses content (the engine reports semantic errors at plot time). Recognizes name(...) calls, (...) groups, ^ powers, sqrt(...)/root(i,x) radicals, and a/b fractions where a and b are simple immediate operands.
to_linear
Serialize the whole expression to a flat ASCII string. Round-trips with parse.

Type Aliases§

Row
An ordered list of atoms. The editable unit.