in the project I am working right now we use mathjs to be able to write complex expressions that we then want to validate and evaluate.
My issue is with the validate part. We want to validate different things so far:
- The expression is valid (well formed)
- Functions being used are valid (they exist)
- Function parameters are the right ones in number and type
Number 1 and 2 are solved already. I am asking help with number 3.
One thing I tried was to evaluate each function node in the expression. Something similar to:
mathInstance.parser().evaluate(node.toString());
and if it throws an exception then something is invalid, but it has two issues:
I might not have the context to evaluate the expression (the app has two steps, in step one the user enters the expression, in the step two we get the values to put into the expression)
the evaluate function does not seem to throw an error when the argument type is invalid, it seems to throw only when the arguments quantity is incorrect
Is there a way to validate the arguments are correct in number and type?
Thanks in advance.