semantic-math / math-rules

Manipulate math-ast ASTs based on algebraic rules
MIT License
4 stars 1 forks source link

Return the path of updated nodes in input and output ASTs #40

Open kevinbarabash opened 7 years ago

kevinbarabash commented 7 years ago

A path is an array of object keys/array index.

kevinbarabash commented 7 years ago

Given the following AST:

{
  type: 'Apply',
  op: 'add',
  args: [
     { type: 'number', value: '1' },
     { type: 'identifier', value: 'a', subscript: { type: 'number', value: '0' },
     { type: 'Apply', op: 'mul', args: [ 5, 10, 20, 35, 50 ] },
 ],
}

The path ['args', '1', 'subscript'] corresponds to { type: 'number', value: '0' }.

The path ['args', '2', 'args', ['1', '2', '3']] corresponds to nodes 10, 20, 35. (full node form omitted to save space.

There should be some sort of function to get the node at path. Calling it on an AST will return the node (or nodes) for the path in the given AST. If no nodes are found for the given path then it should return null.

kevinbarabash commented 7 years ago

applyRule should be updated to return a struct containing the following data: