serializeParsedExprAST

API / @publicodes/tools / index / serializeParsedExprAST

function serializeParsedExprAST(parsedExpr, needsParens): undefined | string

Defined in: commons.ts:178

Serialize a parsed expression into its string representation.

Parameters

ParameterTypeDefault valueDescription
parsedExprExprASTundefinedThe parsed expression in a JSON format.
needsParensbooleanfalseWhether the expression needs to be wrapped in parentheses.

Returns

undefined | string

The string representation of the parsed expression.

Note

Could be clever and remove unnecessary parentheses, for example: (A + B) + C -> A + B + C

Example

serializeParsedExprAST(
  { '+': [{ variable: "A" }, { constant: { type: "number", nodeValue: "10" } }] },
  true
)
// "(A + 10)"