Skip to content

Commit

Permalink
Removed match result in favor of a context
Browse files Browse the repository at this point in the history
  • Loading branch information
doug-martin committed Feb 14, 2013
1 parent 2432c3f commit 2558f1b
Show file tree
Hide file tree
Showing 8 changed files with 275 additions and 232 deletions.
2 changes: 1 addition & 1 deletion lib/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@
throw new Error("Name must be present in JSON or options");
}
var flow = new Container(name);
var defined = merge({Array: Array, String: String, Number: Number, Boolean: Boolean, RegExp: RegExp}, options.define || {});
var defined = merge({Array: Array, String: String, Number: Number, Boolean: Boolean, RegExp: RegExp, Object: Object}, options.define || {});
if (typeof Buffer !== "undefined") {
defined.Buffer = Buffer;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/constraintMatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,14 +312,14 @@ var toJs = exports.toJs = function (rule, scope) {
var js = lang.parse(rule);
scope = scope || {};
var vars = lang.getIdentifiers(rule);
return ["(function(){ return function jsMatcher(hash){", map(vars,function (v) {
return ["(function(){ return function jsMatcher(fact, hash){", map(vars,function (v) {
var ret = ["var ", v, " = "];
if (definedFuncs.hasOwnProperty(v)) {
ret.push("definedFuncs['", v, "']");
} else if (scope.hasOwnProperty(v)) {
ret.push("scope['", v, "']");
} else {
ret.push("hash['", v, "']");
ret.push("'", v , "' in fact ? fact['", v, "'] : hash['", v, "']");
}
ret.push(";");
return ret.join("");
Expand Down
32 changes: 30 additions & 2 deletions lib/matchResult.js → lib/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var extd = require("./extended"),
union = extd.union,
map = extd.map;

declare({
var Match = declare({
instance: {
constructor: function (assertable) {
assertable = assertable || {};
Expand All @@ -23,7 +23,7 @@ declare({
this.factHash = merge(this.factHash, assertable.factHash);
this.recency = union(this.recency, assertable.recency);
} else {
var fact = assertable.fact;
var fact = assertable;
if (fact) {
this.facts.push(fact);
this.recency.push(fact.recency);
Expand Down Expand Up @@ -52,6 +52,34 @@ declare({
}

}
});

declare({
instance: {
match: null,
factHash: null,
fact: null,
hashCode: null,
paths: null,

constructor: function (fact, paths, mr) {
this.fact = fact;
this.paths = paths || null;
var match = this.match = mr || new Match(fact);
this.factHash = match.factHash;
this.hashCode = match.hashCode;
},

"set": function (key, value) {
this.factHash[key] = value;
return this;
},

isMatch: function (isMatch) {
this.match.isMatch = isMatch;
return this;
}
}
}).as(module);


0 comments on commit 2558f1b

Please sign in to comment.