-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathExprEvaluatorImpl.js
55 lines (45 loc) · 1.53 KB
/
ExprEvaluatorImpl.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* jshint evil: true */
var Class = require('../ext/Class');
var NodeValue = require('./expr/NodeValue');
var NodeValueUtils = require('./NodeValueUtils');
var ExprEvaluator = require('./ExprEvaluator');
var ExprEvaluatorImpl = Class.create(ExprEvaluator, {
eval: function(expr, binding) {
var result;
var e;
if (expr.isVar()) {
e = expr.getExprVar();
result = this.evalExprVar(e, binding);
} else if (expr.isFunction()) {
e = expr.getFunction();
result = this.evalExprFunction(e, binding);
} else if (expr.isConstant()) {
e = expr.getConstant();
// FIXME: this.evalConstant not defined
result = this.evalConstant(e, binding);
} else {
throw new Error('Unsupported expr type');
}
return result;
},
evalExprVar: function(expr, binding) {
// console.log('Expr' + JSON.stringify(expr));
var v = expr.asVar();
var node = binding.get(v);
var result;
if (node == null) {
// console.log('No Binding for variable "' + v + '" in ' + expr + ' with binding ' + binding);
// throw 'Bailing out';
return NodeValue.nvNothing;
// return null;
} else {
result = NodeValueUtils.makeNode(node);
}
return result;
},
evalExprFunction: function() { // expr, binding) {
},
evalNodeValue: function() { // expr, binding) {
},
});
module.exports = ExprEvaluatorImpl;