substituteInParsedExpr

API / @publicodes/tools / index / substituteInParsedExpr

function substituteInParsedExpr(
   parsedExpr, 
   variableName, 
   constValue): ExprAST

Defined in: commons.ts:229

Replace all occurences [variableName] node with the corresponding [constValue] node.

Parameters

ParameterTypeDescription
parsedExprExprASTThe parsed expression in a JSON format.
variableNamestringThe name of the variable to replace.
constValuestringThe value to replace the variable with.

Returns

ExprAST

The parsed expression with all occurences of [VariableNode] with the corresponding [ConstantNode].

Example

substituteIn(
 { variable: "A" },
 "A",
 "10",
 "ruleA"
 )
 // { constant: { type: "number", nodeValue: "10" } }