Start walk for math expression trees
This commit is contained in:
parent
0b1c8f4655
commit
df3b1314ed
47
src/support/parse.ts
Normal file
47
src/support/parse.ts
Normal 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 {}
|
@ -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 {}
|
Loading…
Reference in New Issue
Block a user