export interface ValueParserResult {
value: number,
error: string
}
interface subParseResult {
result: (string | number) [],
error: string
}
class ValueParser {
parse(eq: string, values: {[key: string] : number}, level?: number) : ValueParserResult {
const result: ValueParserResult = { value: 0, error: "" }
const numberRe: RegExp = /([^|\\(||/|/\\-|-|\\*|\\*\\-|+|\\^])+([0-9.]*)([$|(|)|/|/-|-|*|*-|+|])+/g;
const eqParse = eq.split(" ").join('');
eqParse.replace(numberRe, (matched) => {
return " ," + matched;
})
console.log(eqParse)
return result;
}
}
const vp = new ValueParser();
const values = {x: 18, y:-3, z: 7}
const eq = "3452/132*67*(x+y/z)"
vp.parse(eq, values)
This snippet formats the eqParse
data by adding a space and comma before each value instead of capturing surrounding strings.