Open DragonOsman opened 3 years ago
It looks like you're using the parse and evaluate functions correctly, but you're getting a syntax error in the evaluated string (storedValue
). Take a look at its value right before you try to parse it, and feel free to add it as a comment. That should point to the problem.
I'm only getting this stuff in the console:
Uncaught Error: unexpected TEOF: EOF
at ParserState.push../node_modules/expr-eval/dist/index.mjs.ParserState.parseAtom (index.mjs:1070)
at ParserState.push../node_modules/expr-eval/dist/index.mjs.ParserState.parseMemberExpression (index.mjs:1299)
at ParserState.push../node_modules/expr-eval/dist/index.mjs.ParserState.parseFunctionCall (index.mjs:1271)
at ParserState.push../node_modules/expr-eval/dist/index.mjs.ParserState.parsePostfixExpression (index.mjs:1254)
at ParserState.push../node_modules/expr-eval/dist/index.mjs.ParserState.parseExponential (index.mjs:1246)
at ParserState.push../node_modules/expr-eval/dist/index.mjs.ParserState.parseFactor (index.mjs:1241)
at ParserState.push../node_modules/expr-eval/dist/index.mjs.ParserState.parseTerm (index.mjs:1209)
at ParserState.push../node_modules/expr-eval/dist/index.mjs.ParserState.parseAddSub (index.mjs:1201)
at ParserState.push../node_modules/expr-eval/dist/index.mjs.ParserState.parseComparison (index.mjs:1187)
at ParserState.push../node_modules/expr-eval/dist/index.mjs.ParserState.parseAndExpression (index.mjs:1175)
at ParserState.push../node_modules/expr-eval/dist/index.mjs.ParserState.parseOrExpression (index.mjs:1165)
at ParserState.push../node_modules/expr-eval/dist/index.mjs.ParserState.parseConditionalExpression (index.mjs:1151)
at ParserState.push../node_modules/expr-eval/dist/index.mjs.ParserState.parseVariableAssignmentExpression (index.mjs:1120)
at ParserState.push../node_modules/expr-eval/dist/index.mjs.ParserState.parseExpression (index.mjs:1079)
at Parser.push../node_modules/expr-eval/dist/index.mjs.Parser.parse (index.mjs:1765)
at handleEqualsClick (App.js:216)
at HTMLButtonElement.clickHandler (App.js:261)
Even when I click on the equals sign and then open up the console, I don't see anything that should've been logged from handleEqualsClick
.
And the Uncaught Error: unexpected TEOF: EOF
error is from like 1070 in index.mjs as well.
@silentmatt I changed the equals click handler to this:
const parser = new exprEval.Parser();
const handleEqualsClick = event => {
setEqualsClicked(true);
const stored = `${storedValue}${currentValue}`;
setStoredValue(stored);
console.log(storedValue);
let calculatedValue;
try {
calculatedValue = parser.parse(storedValue).evaluate();
} catch (err) {
console.log(`Error occurred: ${err}`);
}
setCurrentValue(`${calculatedValue}`);
setStoredValue(`${stored}${event.target.textContent}`);
};
and made sure to remove spaces from the string constructed as the value for storedValue
. But for some reason, the value logged to the console in handleEqualsClick
is just ${number}${operator}
. The number that should be right after that isn't logged with the rest of that. Is that what's going into the parse
function? Or is it just not able to log the whole thing before the error is thrown?
And for some reason calculatedValue
is undefined
.
What am I doing wrong here?
I'm getting this error message:
when I try to use the
parse().evaluate()
function. What am I doing wrong? Full source code is on GitHub here. Thanks in advance for replies and help.