Renaming internal ExprEval Expression class to ExprEvalExpression
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
45dff33bb5
commit
8c8964e75e
5 changed files with 19 additions and 14 deletions
|
@ -146,7 +146,7 @@ function substitute(tokens, variable, expr) {
|
||||||
/**
|
/**
|
||||||
* Evaluates the given instructions for a given Expression with given values.
|
* Evaluates the given instructions for a given Expression with given values.
|
||||||
* @param {Instruction[]} tokens
|
* @param {Instruction[]} tokens
|
||||||
* @param {Expression} expr
|
* @param {ExprEvalExpression} expr
|
||||||
* @param {Record.<string, number>} values
|
* @param {Record.<string, number>} values
|
||||||
* @return {number}
|
* @return {number}
|
||||||
*/
|
*/
|
||||||
|
@ -442,7 +442,7 @@ function getSymbols(tokens, symbols, options) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Expression {
|
export class ExprEvalExpression {
|
||||||
/**
|
/**
|
||||||
* @param {Instruction[]} tokens
|
* @param {Instruction[]} tokens
|
||||||
* @param {Parser} parser
|
* @param {Parser} parser
|
||||||
|
@ -458,26 +458,26 @@ export class Expression {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simplifies the expression.
|
* Simplifies the expression.
|
||||||
* @param {Object<string, number|Expression>|undefined} values
|
* @param {Object<string, number|ExprEvalExpression>|undefined} values
|
||||||
* @returns {Expression}
|
* @returns {ExprEvalExpression}
|
||||||
*/
|
*/
|
||||||
simplify(values) {
|
simplify(values) {
|
||||||
values = values || {}
|
values = values || {}
|
||||||
return new Expression(simplify(this.tokens, this.unaryOps, this.binaryOps, this.ternaryOps, values), this.parser)
|
return new ExprEvalExpression(simplify(this.tokens, this.unaryOps, this.binaryOps, this.ternaryOps, values), this.parser)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new expression where the variable is substituted by the given expression.
|
* Creates a new expression where the variable is substituted by the given expression.
|
||||||
* @param {string} variable
|
* @param {string} variable
|
||||||
* @param {string|Expression} expr
|
* @param {string|ExprEvalExpression} expr
|
||||||
* @returns {Expression}
|
* @returns {ExprEvalExpression}
|
||||||
*/
|
*/
|
||||||
substitute(variable, expr) {
|
substitute(variable, expr) {
|
||||||
if(!(expr instanceof Expression)) {
|
if(!(expr instanceof ExprEvalExpression)) {
|
||||||
expr = this.parser.parse(String(expr))
|
expr = this.parser.parse(String(expr))
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Expression(substitute(this.tokens, variable, expr), this.parser)
|
return new ExprEvalExpression(substitute(this.tokens, variable, expr), this.parser)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -527,7 +527,7 @@ export class Expression {
|
||||||
/**
|
/**
|
||||||
* Converts the expression to a JS function.
|
* Converts the expression to a JS function.
|
||||||
* @param {string} param - Parsed variables for the function.
|
* @param {string} param - Parsed variables for the function.
|
||||||
* @param {Object.<string, (Expression|string)>} variables - Default variables to provide.
|
* @param {Object.<string, (ExprEvalExpression|string)>} variables - Default variables to provide.
|
||||||
* @returns {function(...any)}
|
* @returns {function(...any)}
|
||||||
*/
|
*/
|
||||||
toJSFunction(param, variables) {
|
toJSFunction(param, variables) {
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
import * as Polyfill from "./polyfill.mjs"
|
import * as Polyfill from "./polyfill.mjs"
|
||||||
import { ParserState } from "./parserstate.mjs"
|
import { ParserState } from "./parserstate.mjs"
|
||||||
import { TEOF, TokenStream } from "./tokens.mjs"
|
import { TEOF, TokenStream } from "./tokens.mjs"
|
||||||
import { Expression } from "./expression.mjs"
|
import { ExprEvalExpression } from "./expression.mjs"
|
||||||
|
|
||||||
const optionNameMap = {
|
const optionNameMap = {
|
||||||
"+": "add",
|
"+": "add",
|
||||||
|
@ -156,7 +156,7 @@ export class Parser {
|
||||||
parserState.parseExpression(instr)
|
parserState.parseExpression(instr)
|
||||||
parserState.expect(TEOF, QT_TRANSLATE_NOOP("error", "EOF"))
|
parserState.expect(TEOF, QT_TRANSLATE_NOOP("error", "EOF"))
|
||||||
|
|
||||||
return new Expression(instr, this)
|
return new ExprEvalExpression(instr, this)
|
||||||
}
|
}
|
||||||
|
|
||||||
evaluate(expr, variables) {
|
evaluate(expr, variables) {
|
||||||
|
|
|
@ -42,6 +42,10 @@ export class Expression {
|
||||||
this.latexMarkup = Latex.expression(this.calc.tokens)
|
this.latexMarkup = Latex.expression(this.calc.tokens)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
variables() {
|
||||||
|
return this.calc.variables()
|
||||||
|
}
|
||||||
|
|
||||||
isConstant() {
|
isConstant() {
|
||||||
let vars = this.calc.variables()
|
let vars = this.calc.variables()
|
||||||
return !vars.includes("x") && !vars.includes("n")
|
return !vars.includes("x") && !vars.includes("n")
|
||||||
|
|
|
@ -79,6 +79,7 @@ export class ExprParserAPI extends Module {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} expression - Expression to parse
|
* @param {string} expression - Expression to parse
|
||||||
|
* @returns {ExprEvalExpression}
|
||||||
*/
|
*/
|
||||||
parse(expression) {
|
parse(expression) {
|
||||||
return this._parser.parse(expression)
|
return this._parser.parse(expression)
|
||||||
|
|
|
@ -107,7 +107,7 @@ export class ExpressionSetting extends Setting {
|
||||||
* @param {Expression} value
|
* @param {Expression} value
|
||||||
*/
|
*/
|
||||||
set(value) {
|
set(value) {
|
||||||
let vars = value.calc.variables()
|
let vars = value.variables()
|
||||||
if(vars.length === this.variables.length && vars.every(x => this.variables.includes(x)))
|
if(vars.length === this.variables.length && vars.every(x => this.variables.includes(x)))
|
||||||
Helper.setSetting(this.nameInConfig, value)
|
Helper.setSetting(this.nameInConfig, value)
|
||||||
else {
|
else {
|
||||||
|
|
Loading…
Reference in a new issue