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
Parameter | Type | Default value | Description |
---|---|---|---|
parsedExpr | ExprAST | undefined | The parsed expression in a JSON format. |
needsParens | boolean | false | Whether 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)"