This module parses and outputs an Abstract Syntax Tree representing the formula using the MASTON format.
To use it, use the MathAtom.toAST()
method.
Methods
asLatex(ast: object): stringinner
ast
:
object
Abstract Syntax Tree object (in canonical form)
A LaTeX representation of the AST
asMachineNumber(node: object): numberprivateinner
node
:
object
Abstract Syntax Tree node
A JavaScript number, the value of the AST or NaN
asSymbol(expr: object): stringinner
expr
:
object
Abstract Syntax Tree object
A string, the symbol, or undefined
escapeText(s: string): stringinner
Return a string escaped as necessary to comply with the JSON format
s
:
string
formatMantissa(m: string, config: [string]:any)inner
Return a formatted mantissa: 1234567 -> 123 456 7... 1233333 -> 12(3)
m
:
string
config
:
[string]:any
getCanonicalName(latex,: string): stringinner
latex,
:
string
for example '\times'
the canonical name for the input, for example '*'
getLatexForSymbol(name: string): stringinner
name
:
string
symbol name, e.g. "alpha"
getLatexTemplateForFunction(name: string): stringinner
name
:
string
function canonical name
getPrecedence(canonicalName,: string): numberinner
Given a canonical name, return its precedence
canonicalName,
:
string
for example "and"
isAtom(expr: object, type: string, value: string)inner
Return true if the current atom is of the specified type and value.
expr
:
object
type
:
string
value
:
string
negate(node: object)inner
Return the negative of the expression. Usually { fn:'negate', arg } but for numbers, the negated number
node
:
object
numberAsLatex(num: string | number): stringinner
num
:
string
|
number
A number, represented as a string (e.g. "-12.45" particularly useful for arbitrary precision numbers) or a number (-12.45)
A LaTeX representation of the AST
opPrec(atom: object): numberinner
Return the operator precedence of the atom or -1 if not an operator
atom
:
object
parse(atoms: Atoms[]): objectinner
atoms
:
Atoms[]
parseDelim()inner
Delimiters can be expressed:
- as a matching pair of regular characters: '(a)'
- a as 'leftright' expression: '\left(a\right)'
- as a matching pair of 'sizeddelim': '\Bigl(a\Bigr)
Note that the '\delim' command is only used for delimiters in the middle of a \left\right pair and not to represent pair-matched delimiters.
This function handles all three cases
parseDigraph()inner
Some symbols are made up of two consecutive characters. Handle them here. Return undefined if not a digraph. TODO: other digraphs: := ++ ** =: °C U+2103 °F U+2109
parseExpression(expr: object): objectprivateinner
Given an atom or an array of atoms, return their AST representation as an object.
expr
:
object
An expressions, including expr.atoms, expr.index, expr.minPrec the minimum precedence that this parser should parse before returning; expr.lhs (optional); expr.ast, the resulting AST.
the expr object, updated
parsePostfix()inner
Parse postfix operators, such as "!" (factorial)
parseSentence(expr: object): objectinner
Parse a sequence of text zone and math zones:
expr
:
object
parseSupsub(expr: object)inner
Parse for a possible sup/sub attached directly to the current atom or to a following 'msubsup' atom. After the call, the index points to the next atom to process.
expr
:
object
wrapFence(fence: string): stringinner
fence
:
string
The fence to wrap around the arguments
- A string wrapped in the fence
wrapFn(functionName: string, …params: object)inner
functionName
:
string
params
:
object
repeatable