Start MathPage class

This commit is contained in:
Garrett Mills 2022-04-09 01:20:39 -05:00
parent 189439227f
commit 8f42f771d8
2 changed files with 34 additions and 0 deletions

33
src/support/page.ts Normal file
View File

@ -0,0 +1,33 @@
import {MathStatement} from './parse'
import * as math from 'mathjs'
export class MathPage {
protected statements: Record<string, MathStatement> = {}
constructor(
public readonly id: string,
) {}
addStatement(statement: MathStatement): this {
this.statements[statement.id] = statement
return this
}
symbols(): math.SymbolNode[] {
return Object.values(this.statements)
.map(x => x.symbols())
.reduce((carry, current) => current.concat(carry), [])
}
defines(): math.SymbolNode[] {
return Object.values(this.statements)
.map(x => x.defines())
.reduce((carry, current) => current.concat(carry), [])
}
uses(): math.SymbolNode[] {
return Object.values(this.statements)
.map(x => x.uses())
.reduce((carry, current) => current.concat(carry), [])
}
}

View File

@ -253,6 +253,7 @@ export class LValSymbolWalk extends SymbolWalk {
export class MathStatement { export class MathStatement {
constructor( constructor(
public readonly id: string,
public readonly raw: string, public readonly raw: string,
) {} ) {}