Skip to content

Commit

Permalink
Revert "Implements extends functionality in the dsl"
Browse files Browse the repository at this point in the history
This reverts commit 1259c3d.
  • Loading branch information
markbjerke committed Dec 17, 2015
1 parent 1259c3d commit f672179
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 133 deletions.
16 changes: 3 additions & 13 deletions lib/compile/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ var createFunction = function (body, defined, scope, scopeNames, definedNames) {

var createDefined = (function () {

var _createDefined = function (options, defined, scope) {
var action = options.properties
,proto, base;
//
var _createDefined = function (action, defined, scope) {
if (isString(action)) {
var declares = [];
extd(defined).keys().forEach(function (i) {
Expand Down Expand Up @@ -60,14 +57,7 @@ var createDefined = (function () {
}
}
};
if (options.extend) {
base = defined[options.extend];
proto = Object.create(base.prototype);
ret.prototype = proto;
}
else {
proto = ret.prototype;
}
var proto = ret.prototype;
for (var i in action) {
proto[i] = action[i];
}
Expand All @@ -76,7 +66,7 @@ var createDefined = (function () {
};

return function (options, defined, scope) {
return _createDefined(options, defined, scope);
return _createDefined(options.properties, defined, scope);
};
})();

Expand Down
40 changes: 9 additions & 31 deletions lib/compile/transpile.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,48 +7,26 @@ var extd = require("../extended"),
constraintMatcher = require("../constraintMatcher"),
parser = require("../parser");

function definedToJs(options, extend) {
function definedToJs(options) {
/*jshint evil:true*/
options = isString(options) ? new Function("return " + options + ";")() : options;
var ret = ["(function(flow){"], value;
var ret = ["(function(){"], value;

if (options.hasOwnProperty("constructor") && "function" === typeof options.constructor) {
ret.push("var Defined = " + options.constructor.toString() + ";");
} else {
ret.push("var Defined = function(opts){ for(var i in opts){if(opts.hasOwnProperty(i)){this[i] = opts[i];}}};");
}
if (extend) {
ret.push("var proto = Object.create(flow.getDefined('" + extend + "').prototype); proto.constructor = Defined; Defined.prototype = proto;");
}
else {
ret.push("var proto = Defined.prototype;");
}

ret.push("var proto = Defined.prototype;");
for (var key in options) {
var str;
if (options.hasOwnProperty(key) && key !== 'constructor') {
if (options.hasOwnProperty(key)) {
value = options[key];
str = ("proto." + key + " = ");
if (extd.isFunction(value)) {
str += value.toString();
}
else {
if (value instanceof Array) {
str += JSON.stringify(value);
}
else {
str += extd.format("%j", value);
}
str += ";"
}
ret.push(str);
ret.push("proto." + key + " = " + (extd.isFunction(value) ? value.toString() : extd.format("%j", value)) + ";");
}
}
ret.push("return Defined;");
ret.push("}(this))");
var sJoin = ret.join("");
debugger;
return sJoin;
ret.push("}())");
return ret.join("");

}

Expand Down Expand Up @@ -170,7 +148,7 @@ exports.transpile = function (flowObj, options) {
ret.push(extd(flowObj.define || []).map(function (defined) {
var name = defined.name;
defined[name] = {};
return ["var", name, "= defined." + name, "= this.addDefined('" + name + "',", definedToJs(defined.properties, defined.extend) + ");"].join(" ");
return ["var", name, "= defined." + name, "= this.addDefined('" + name + "',", definedToJs(defined.properties) + ");"].join(" ");
}).value().join("\n"));
ret.push(extd(flowObj.scope || []).map(function (s) {
var name = s.name;
Expand Down
7 changes: 1 addition & 6 deletions lib/parser/nools/tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,17 +240,12 @@ var topLevelTokens = {
var name = src.match(/^([a-zA-Z_$][0-9a-zA-Z_$]*)/);
if (name) {
src = src.replace(name[0], "").replace(/^\s*|\s*$/g, "");
var extend = src.match(/^extends\s+([a-zA-Z_$][0-9a-zA-Z_$]*)/);
if (extend) {
src = src.replace(extend[0], "").replace(/^\s*|\s*$/g, "");
extend = extend[1];
}
if (utils.findNextToken(src) === "{") {
name = name[1];
var body = utils.getTokensBetween(src, "{", "}", true).join("");
src = src.replace(body, "");
//should
context.define.push({ name: name, extend: extend, properties: "(" + body + ")" });
context.define.push({name: name, properties: "(" + body + ")"});
return src;
} else {
throw new Error("unexpected token : expected : '{' found : '" + utils.findNextToken(src) + "'");
Expand Down
14 changes: 1 addition & 13 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,19 +146,6 @@ To use the flow
var flow = nools.compile(__dirname + "/helloworld.nools"),
Message = flow.getDefined("message");
```
# Type Declaration 'extends'
Defined types in the DSL no support 'extends' keyword for inheritance.

Any type present in the flow can be extended. Base types must be defined before extended types.

```
define EncodedMessage extends Message {
encoding: 'sha1'
,constructor: function(message, encoding) {
Message.call(this, message); // call superclass manually
this.encoding = encoding
}
}

### Flow Events

Expand Down Expand Up @@ -355,6 +342,7 @@ session.getFacts(Number); //[1, 2];
session.getFacts(String); //["A", "B"];
```


<a name="firing"></a>
## Firing the rules

Expand Down
24 changes: 0 additions & 24 deletions test/flow.dsl.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -593,28 +593,4 @@ it.describe("Flow dsl", function (it) {
});
});
});
/*
it.describe("extended Fact types", function (it) {
var Person, Student, LongTermStudent, Count, session1Fired = {}, session1;
var flow = nools.compile(resolve(__dirname, "./rules/extends.nools"), {
name: 'extendsTest'
});
Person = flow.getDefined('Person');
Student = flow.getDefined('Student');
LongTermStudent = flow.getDefined('LongTermStudent');
//
session1 = flow.getSession(new Person('Bob'), new Student('Sue', 'harvard'), new LongTermStudent('Jim', 'princeton', 1)).on('fire', function (name) {
session1Fired[name] = session1Fired[name] || { cnt: 0 };
session1Fired[name].cnt++;
});
//
it.should(" fire rule(s) correctly according to type. each rule matching a single type ", function (next) {
return session1.match().then(function () {
assert(session1Fired['PersonTest'].cnt === 3);
assert(session1Fired['StudentTest'].cnt === 2);
assert(session1Fired['LongTermStudentTest'].cnt === 1);
})
});
});
*/
});
46 changes: 0 additions & 46 deletions test/rules/extends.nools

This file was deleted.

0 comments on commit f672179

Please sign in to comment.