parseExpression

API / publicodes / parseExpression

function parseExpression(rawNode, dottedName): ExprAST

Experimental

Parse a publicodes expression into an JSON object representing the AST.

The parsing is done with the nearley parser

Parameters

ParameterTypeDescription
rawNodestringThe expression to parse
dottedNamestringThe dottedName of the rule being parsed

Returns

ExprAST

The parsing result as a JSON object

Throws

A SyntaxError if the expression is invalid

Throws

A PublicodesInternalError if the parser is unable to parse the expression

Example

parseExpression('20.3 * nombre', 'foo . bar')
// returns { "*": [ { constant: { type: "number", nodeValue: 20.3 } }, { variable:"nombre" } ] }

Defined in

packages/core/src/parseExpression.ts:60