Replace eval by a jsep evaluator

This is an experiment to replace the evals with an evaluator of an AST produced by (jsep)[http://jsep.from.so/]

jsep produces an AST that is compatible with Esprima but it weighs only 600 lines of code and 1kb once minified.

The original issue was filed here: https://github.com/sutoiku/formula.js/issues/27
You guys were asking if we had some ideas regarding this and most importantly, I am a lot more at ease developing on the top of your branch than the original one at Sutoiku.
So I am making a PR here.

It works well enough for the test suite but it is very brittle: errors in the expression will put some noise in the console and the expression's node that did not work will return undefined and move-on.

Let me know if you find this promising enough.
Oh! Thanks for spotting this. Dont know how the tests could pass without
that.
Hugues

On Tue, Sep 9, 2014 at 3:04 PM, Sjoerd de Jong <notifications@github.com>
wrote:

> In lib/expr_eval.js:
>
> > +    if (!logop) {
> > +      return console.error('Unknown logical operator ' + node.operator);
> > +    }
> > +    return logop(do_eval(node.left), do_eval(node.right));
> > +  } else if (node.type === 'Literal') {
> > +    return node.value;
> > +  } else if (node.type === 'Identifier') {
> > +    return variables ? variables[node.name] : undefined;
> > +  } else {
> > +    console.error('Unsupported expr node', node);
> > +  }
> > +}
> > +
> > +module.exports = function evalExpr(expr, variables) {
> > +  var ast = jsep(expr);
> > +  return do_eval(ast);
>
> I guess this line needs the variables variable too?
>
> return do_eval(ast, variables);
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/CrowdProcess/formula.js/pull/2/files#r17284958>.
>