`parserFactory` can be used to generate TDOP/Pratt parsers. The reason for using this style of parsing is that it's much easier to change the precedence and add new operators that it would be other parser types.
npm install @math-blocks/parserparserFactory can be used to generate TDOP/Pratt parsers. The reason for using
this style of parsing is that it's much easier to change the precedence and add
new operators that it would be other parser types.
``typescript`
function parserFactory
getPrefixParselet: (token: T) => PrefixParselet
getInfixParselet: (token: T) => InfixParselet
getOpPrecedence: (arg0: O) => number,
EOL: T,
): {parse: (arg0: Array
The three generic properties are:
- T: token object type produced by a lexerN
- : node object type that the parser will produceO
- : operator type (usually an enum of union of strings)
getPrefixParselet and getInfixParselet are functions that return the parselettoken
that should be used for the given . Parselets are objects that containparse
a method and possible additional data. Infix parselets also keep track
of the current operator.
In the future, support for post-fix operators such as ! and '` will be added.
- @math-blocks/editor-parser/src/editor-parser.ts
- @math-blocks/testing/src/text-parser.ts