Start walk for math expression trees

This commit is contained in:
Garrett Mills 2022-04-08 23:34:33 -05:00
parent 0b1c8f4655
commit df3b1314ed
2 changed files with 47 additions and 65 deletions

47
src/support/parse.ts Normal file
View File

@ -0,0 +1,47 @@
import math from 'mathjs'
export abstract class MathNodeWalk<TReturn> {
abstract walkAccessorNode(node: math.AccessorNode): TReturn
abstract walkArrayNode(node: math.ArrayNode): TReturn
abstract walkAssignmentNode(node: math.AssignmentNode): TReturn
abstract walkBlockNode(node: math.BlockNode): TReturn
abstract walkConditionalNode(node: math.ConditionalNode): TReturn
abstract walkConstantNode(node: math.ConstantNode): TReturn
abstract walkFunctionAssignmentNode(node: math.FunctionAssignmentNode): TReturn
abstract walkFunctionNode(node: math.FunctionNode): TReturn
abstract walkIndexNode(node: math.IndexNode): TReturn
abstract walkObjectNode(node: math.ObjectNode): TReturn
abstract walkOperatorNode(node: math.OperatorNode): TReturn
abstract walkParenthesisNode(node: math.ParenthesisNode): TReturn
abstract walkRangeNode(node: math.RangeNode): TReturn
abstract walkRelationalNode(node: math.RelationalNode): TReturn
abstract walkSymbolNode(node: math.SymbolNode): TReturn
}
export class MathStatement {
constructor(
public readonly raw: string,
) {}
// parse(): MathNode {
// return parse(this.raw)
// }
}
export class MathExpression extends MathStatement {}

View File

@ -1,65 +0,0 @@
import {
parse,
MathNode,
AccessorNode,
ArrayNode,
AssignmentNode,
BlockNode,
ConditionalNode,
ConstantNode,
FunctionAssignmentNode,
FunctionNode,
IndexNode,
ObjectNode,
OperatorNode,
ParenthesisNode,
RangeNode,
RelationalNode,
SymbolNode,
} from 'mathjs'
export abstract class MathNodeWalk<TReturn> {
abstract walkAccessorNode(node: AccessorNode): TReturn
abstract walkArrayNode(node: ArrayNode): TReturn
abstract walkAssignmentNode(node: AssignmentNode): TReturn
abstract walkBlockNode(node: BlockNode): TReturn
abstract walkConditionalNode(node: ConditionalNode): TReturn
abstract walkConstantNode(node: ConstantNode): TReturn
abstract walkFunctionAssignmentNode(node: FunctionAssignmentNode): TReturn
abstract walkFunctionNode(node: FunctionNode): TReturn
abstract walkIndexNode(node: IndexNode): TReturn
abstract walkObjectNode(node: ObjectNode): TReturn
abstract walkOperatorNode(node: OperatorNode): TReturn
abstract walkParenthesisNode(node: ParenthesisNode): TReturn
abstract walkRangeNode(node: RangeNode): TReturn
abstract walkRelationalNode(node: RelationalNode): TReturn
abstract walkSymbolNode(node: SymbolNode): TReturn
}
export class MathStatement {
constructor(
public readonly raw: string,
) {}
parse(): MathNode {
return parse(this.raw)
}
}
export class MathExpression extends MathStatement {}