From 11f79aa366cac166f222538e21b20f10f28eb8ef Mon Sep 17 00:00:00 2001 From: Doug Martin Date: Wed, 20 Nov 2013 17:30:34 -0600 Subject: [PATCH] v0.2.2 * Performance Upgrades * Added BetaNode indexing * Abstracted out JoinNode to extend BetaNode (Prevents the checking of constraints if there are not any constraints to check) * Refactored BetaNetwork * Created a new Memory Class to encapusulate left and right memory for BetaNodes * Added new `exists` logic operator to check for existence of fact (opposite of `not`) --- docs-md/examples.md | 2 + docs/History.html | 11 + docs/examples.html | 2 + docs/examples/browser/assets/conways.css | 106 +- docs/examples/browser/diagnose.html | 126 +- docs/examples/browser/fibonacci.html | 6 +- docs/examples/browser/manners.html | 81 +- .../browser/rules/sendMoreMoney.nools | 16 + docs/examples/browser/sendMoreMoney.html | 106 + docs/examples/browser/src/common.js | 2 +- docs/examples/browser/src/sudoku.js | 58 +- docs/examples/browser/sudoku.html | 58 +- docs/examples/browser/waltzDb.html | 78 +- docs/index.html | 32 +- docs/nools.js | 17 +- examples/browser/assets/conways.css | 106 +- examples/browser/diagnose.html | 126 +- examples/browser/fibonacci.html | 6 +- examples/browser/manners.html | 81 +- examples/browser/rules/sendMoreMoney.nools | 16 + examples/browser/sendMoreMoney.html | 106 + examples/browser/src/common.js | 2 +- examples/browser/src/sudoku.js | 58 +- examples/browser/sudoku.html | 58 +- examples/browser/waltzDb.html | 78 +- history.md | 9 + lib/agenda.js | 1 - lib/conflict.js | 3 +- lib/constraint.js | 65 +- lib/constraintMatcher.js | 102 +- lib/context.js | 14 +- lib/extended.js | 98 +- lib/linkedList.js | 27 + lib/nodes/adapterNode.js | 35 + lib/nodes/betaNode.js | 234 + lib/nodes/equalityNode.js | 20 +- lib/nodes/existsFromNode.js | 99 + lib/nodes/existsNode.js | 173 + lib/nodes/fromNode.js | 13 +- lib/nodes/fromNotNode.js | 18 +- lib/nodes/index.js | 34 +- lib/nodes/joinNode.js | 259 +- lib/nodes/joinReferenceNode.js | 115 +- lib/nodes/leftAdapterNode.js | 2 +- lib/nodes/misc/leftMemory.js | 12 + lib/nodes/misc/memory.js | 219 + lib/nodes/misc/rightMemory.js | 12 + lib/nodes/node.js | 12 +- lib/nodes/notNode.js | 217 +- lib/nodes/rightAdapterNode.js | 2 +- lib/nodes/terminalNode.js | 8 +- lib/nodes/typeNode.js | 3 +- lib/parser/nools/tokens.js | 14 +- lib/pattern.js | 4 +- lib/rule.js | 30 +- nools.js | 14909 +++++++++------- nools.min.js | 17 +- package.json | 4 +- readme.md | 45 + test/browserling.js | 2 +- test/constraintMatcher.test.js | 73 +- test/flow.dsl.test.js | 4 +- test/flow.test.js | 1667 -- test/flow/agendaGroups.test.js | 158 + test/flow/async.test.js | 45 + test/flow/events.test.js | 77 + test/flow/exists.test.js | 291 + test/flow/from.test.js | 565 + test/flow/index.js | 14 + test/flow/leftMemory.test.js | 131 + test/flow/matchUntil.halt.js | 65 + test/flow/not.test.js | 185 + test/flow/or.test.js | 176 + test/flow/rightMemory.test.js | 130 + test/flow/rule.test.js | 49 + test/flow/salience.test.js | 59 + test/flow/scope.test.js | 49 + test/flow/simple.test.js | 29 + test/nools.test.js | 67 + test/noolsParser.test.js | 20 + test/rules.test.js | 35 +- 81 files changed, 13336 insertions(+), 8722 deletions(-) create mode 100644 docs/examples/browser/rules/sendMoreMoney.nools create mode 100644 docs/examples/browser/sendMoreMoney.html create mode 100644 examples/browser/rules/sendMoreMoney.nools create mode 100644 examples/browser/sendMoreMoney.html create mode 100644 lib/nodes/adapterNode.js create mode 100644 lib/nodes/betaNode.js create mode 100644 lib/nodes/existsFromNode.js create mode 100644 lib/nodes/existsNode.js create mode 100644 lib/nodes/misc/leftMemory.js create mode 100644 lib/nodes/misc/memory.js create mode 100644 lib/nodes/misc/rightMemory.js create mode 100644 test/flow/agendaGroups.test.js create mode 100644 test/flow/async.test.js create mode 100644 test/flow/events.test.js create mode 100644 test/flow/exists.test.js create mode 100644 test/flow/from.test.js create mode 100644 test/flow/index.js create mode 100644 test/flow/leftMemory.test.js create mode 100644 test/flow/matchUntil.halt.js create mode 100644 test/flow/not.test.js create mode 100644 test/flow/or.test.js create mode 100644 test/flow/rightMemory.test.js create mode 100644 test/flow/rule.test.js create mode 100644 test/flow/salience.test.js create mode 100644 test/flow/scope.test.js create mode 100644 test/flow/simple.test.js create mode 100644 test/nools.test.js diff --git a/docs-md/examples.md b/docs-md/examples.md index f600335..2210d5e 100644 --- a/docs-md/examples.md +++ b/docs-md/examples.md @@ -5,4 +5,6 @@ * [Sudoku](./examples/browser/sudoku.html) * [Fibonacci](./examples/browser/fibonacci.html) * [Miss Manners](./examples/browser/manners.html) + * [Waltz DB](./examples/browser/waltzDb.html) + * [Send More Money](./examples/browser/sendMoreMoney.html) * [Diagnosis](./examples/browser/diagnose.html) diff --git a/docs/History.html b/docs/History.html index b615e93..ff035bb 100644 --- a/docs/History.html +++ b/docs/History.html @@ -178,6 +178,17 @@ +

0.2.2

+

0.2.1

diff --git a/docs/examples/browser/assets/conways.css b/docs/examples/browser/assets/conways.css index b4eced4..5a08222 100644 --- a/docs/examples/browser/assets/conways.css +++ b/docs/examples/browser/assets/conways.css @@ -16,45 +16,91 @@ body { height: 100%; } -#fibonacci div.inline { +.fibonacci div.inline { height: 100%; margin: 10px; } -#fibonacci #results_container { +.fibonacci .results_container { word-wrap: break-word; max-width: 100%; line-height: 50px; } -#diagnose { - width: 500px; - padding: 10px; - border: 1px solid rgba(0, 0, 0, 0.1); - -webkit-box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.1); - -moz-box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.1); - box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.1); +.diagnose { + width: 100%; } -#manners { - width: 50%; +.diagnose .diagnose-container{ + width: 49%; + vertical-align: top; padding: 10px; - border: 1px solid rgba(0, 0, 0, 0.1); - -webkit-box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.1); - -moz-box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.1); - box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.1); +} +.waltz-db, +.manners { + width: 100%; } -#manners #results_container { +.waltz-db .editor-container, +.manners .editor-container, +.diagnose .editor-container, +.send-more-money .editor-container { + width: 49%; + height: 100%; + display: inline-block; +} + +.waltz-db .results_container, +.manners .results_container { + width: 49%; + vertical-align: top; + display: inline-block; + height: 100%; overflow: auto; - height: 400px; - width: 95%; background: #dfdfdf; color: #09C; font-family: Tahoma, Geneva, sans-serif; + padding-left: 10px; +} + +.editor-container { + width: 100%; + height: 400px; + position: relative; + border: 1px solid lightgray; +} + +.editor-container .editor { + width: 100%; + height: 100%; + position: relative; +} + +.send-more-money { + width: 100%; +} + +.send-more-money .equation-container { + vertical-align: top; + width: 49%; +} + +.send-more-money .equation { + font-size: 6em; + text-align: right; + width: 400px; +} + +.send-more-money .equation > div > span { + width: 30px; + display: inline-block; + height: 50px; padding: 10px; - border-radius: 10px; +} + +.send-more-money .equation > div:last-child { + border-top: solid black 1px; } .container > header { @@ -108,6 +154,12 @@ input[type="submit"], input[type="button"] { margin: 10px; } +input[type="submit"]:disabled, +input[type="button"]:disabled { + background-color: lightgray; + cursor: not-allowed; +} + #grid { overflow: hidden; @@ -136,6 +188,7 @@ input[type="submit"], input[type="button"] { box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.2); position: absolute; bottom: 5px; + right: 5px; } .row { @@ -152,6 +205,10 @@ input[type="submit"], input[type="button"] { box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.2); } +.sudoku { + width: 100%; +} + .sudoku .col { width: 50px; height: 50px; @@ -164,11 +221,20 @@ input[type="submit"], input[type="button"] { background-color: rgba(255, 0, 0, 0.43); } -.sudoku #grid{ +.sudoku #grid { width: 465px; height: 470px; } +.sudoku .grid-container { + vertical-align: top; + width: 49%; +} + +.sudoku .editor-container { + width: 49%; +} + .col.live { background-color: black; } diff --git a/docs/examples/browser/diagnose.html b/docs/examples/browser/diagnose.html index 4d70368..699138c 100644 --- a/docs/examples/browser/diagnose.html +++ b/docs/examples/browser/diagnose.html @@ -11,56 +11,58 @@ -
-

Diagnose Me

- - -
-
- - - - - -
- - -
-
- - -
-
- - -
-
- - -
- -
-
-

Diagnoses

- -
+
+
+

Diagnose Me

+
+ +
+
+
+ +
+
+
+ + + + + +
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+
+

Diagnoses

+ +
+
-
-
-
- - - + + - diff --git a/docs/examples/browser/fibonacci.html b/docs/examples/browser/fibonacci.html index d53f1ec..76b25bd 100644 --- a/docs/examples/browser/fibonacci.html +++ b/docs/examples/browser/fibonacci.html @@ -9,7 +9,7 @@ -
+

Fibonacci

@@ -20,7 +20,7 @@

Fibonacci

=
-
+
@@ -90,7 +90,7 @@

Fibonacci

} - var resultsContainer = $("#results_container"), valInput = $("#val"); + var resultsContainer = $(".results_container"), valInput = $("#val"); $("#fibonacci_form").on('submit', function () { var num = parseInt(valInput.val(), 10); resultsContainer.text("Calculating..."); diff --git a/docs/examples/browser/manners.html b/docs/examples/browser/manners.html index 9c36d5b..de6a8e1 100644 --- a/docs/examples/browser/manners.html +++ b/docs/examples/browser/manners.html @@ -4,43 +4,42 @@ - Manners Benchmark -
-

Manners Benchmark

+
+
+

Manners Benchmark

-
+ + + +
+
- - - +
+
+
-
-
- - +
+
-
-
-
- - + + @@ -52,7 +51,7 @@

Manners Benchmark

}).then(function (res) { var session, dataset, - resultsContainer = $("#results_container"), + resultsContainer = $(".results_container"), statsListener = stats(), flowStr = res, flow = nools.compile(res, {name: "manners"}), @@ -83,6 +82,7 @@

Manners Benchmark

session .on("pathDone", function (obj) { resultsContainer.append(createSeat(obj.seating)); + resultsContainer.scrollTop(resultsContainer.prop("scrollHeight")); }) .match().then(function () { console.log("done"); @@ -114,30 +114,19 @@

Manners Benchmark

return false; }); - $("#editor-dialog").dialog({ - autoOpen: false, - modal: true, - width: window.innerWidth * 0.9, - height: window.innerHeight * 0.9, - open: function () { - (editor = ace.edit("editor").getSession()).setValue(flowStr); - }, - buttons: { - "Save": function () { - $(this).dialog("close"); - nools.deleteFlow("manners"); - stop(); - flow = nools.compile((flowStr = editor.getValue()), {name: "manners"}); - }, - Cancel: function () { - $(this).dialog("close"); - } - } - }); + var height = $(document).height() - $("#manners .header").height() - 100; + $(".editor-container").height(height); + resultsContainer.height(height); + + var editor = ace.edit("editor"); + //editor.setTheme("ace/theme/monokai"); + var editorSession = editor.getSession(); + editorSession.setMode("ace/mode/javascript"); + editorSession.setValue(res); + editor.setReadOnly(true); }); - }) - ; + }); diff --git a/docs/examples/browser/rules/sendMoreMoney.nools b/docs/examples/browser/rules/sendMoreMoney.nools new file mode 100644 index 0000000..c7d5bd1 --- /dev/null +++ b/docs/examples/browser/rules/sendMoreMoney.nools @@ -0,0 +1,16 @@ +rule SendMoreMoney { + when { + s : Number s != 0; + e : Number e != s; + n : Number n != s && n != e; + d : Number d != s && d != e && d != n; + m : Number m != 0 && m != s && m != e && m != n && m != d; + o : Number o != s && o != e && o != n && o != d && o != m; + r : Number r != s && r != e && r != n && r != d && r != m && r != o; + y : Number y != s && y != e && y != n && y != d && y != m && y != o && y != r + && (s*1000 + e*100 + n*10 + d + m*1000 + o*100 + r*10 + e) == (m*10000 + o*1000 + n*100 + e*10 + y); + } + then { + emit("solved", {s : s, e : e, n : n, d : d, m : m, o: o, r : r, y : y}); + } +} \ No newline at end of file diff --git a/docs/examples/browser/sendMoreMoney.html b/docs/examples/browser/sendMoreMoney.html new file mode 100644 index 0000000..fb90c1c --- /dev/null +++ b/docs/examples/browser/sendMoreMoney.html @@ -0,0 +1,106 @@ + + + + + + + + + Send More Money Benchmark + + + + +
+
+

Send More Money

+ Warning: This can take a while! +
+ +
+
+
+
+
+
+ + + S + E + N + D +
+
+ + + + M + O + R + E +
+
+ + M + O + N + E + Y +
+
+ +
+
+ + + + + + + + + diff --git a/docs/examples/browser/src/common.js b/docs/examples/browser/src/common.js index 146ff3f..9ab0d04 100644 --- a/docs/examples/browser/src/common.js +++ b/docs/examples/browser/src/common.js @@ -64,7 +64,7 @@ } setInterval(function () { - runningTimeSpan.text("running Time:" + Math.round(transCum / 1000 / 60) + "min"); + runningTimeSpan.text("running time:" + Math.round(transCum / 1000 / 60) + "min"); firesSpan.text('rules fired: : ' + fires); retractionsSpan.text('facts retracted: ' + retractions); modifiesSpan.text('facts modified: ' + modified); diff --git a/docs/examples/browser/src/sudoku.js b/docs/examples/browser/src/sudoku.js index 31da919..1e4741f 100644 --- a/docs/examples/browser/src/sudoku.js +++ b/docs/examples/browser/src/sudoku.js @@ -6,6 +6,13 @@ var allNine = [1, 2, 3, 4, 5, 6, 7, 8, 9]; + if (typeof console === 'undefined') { + console = { + log: function () { + } + }; + } + var SetOfNine = declare({ instance: { @@ -102,7 +109,7 @@ }, valueAsString: function () { - return this.value === null ? " ": this.value; + return this.value === null ? " " : this.value; }, posAsString: function () { @@ -206,35 +213,39 @@ }, step: function () { - this.session.modify(this.counter, function () { - this.count = 1; - }); - if (!this.stepping) { - this.session.assert(new Stepping()); - } - return this.session.matchUntilHalt(function (err) { - if (err) { - console.log(err); + if (!this.invalid) { + this.session.modify(this.counter, function () { + this.count = 1; + }); + if (!this.stepping) { + this.session.assert(new Stepping()); } - }); + return this.session.matchUntilHalt(function (err) { + if (err) { + console.log(err); + } + }); + } }, solve: function () { - this.session.modify(this.counter, function () { - this.count = Infinity; - }); - if (this.stepping) { - this.session.retract(this.stepping); - } - return this.session.match(function (err) { - if (err) { - console.log(err); + if (!this.invalid) { + this.session.modify(this.counter, function () { + this.count = Infinity; + }); + if (this.stepping) { + this.session.retract(this.stepping); } - }); + return this.session.match(function (err) { + if (err) { + console.log(err); + } + }); + } }, setCellValue: function setCellValue(cell) { - cell.el.text(cell.value ? cell.value: ""); + cell.el.text(cell.value ? cell.value : ""); return cell; }, @@ -296,7 +307,6 @@ if (value) { session.assert(new Setting(iRow, iCol, value)); initial++; - //console.log(initial); } } } @@ -340,11 +350,13 @@ }, setInvalidCellValue: function setCellValue(cell) { + this.invalid = true; cell.el.addClass("error"); return cell; }, validate: function () { + this.invalid = false; this.session.assert("validate"); return this.session.focus("validate") .on("invalid", this.setInvalidCellValue) diff --git a/docs/examples/browser/sudoku.html b/docs/examples/browser/sudoku.html index 81afdba..2729f44 100644 --- a/docs/examples/browser/sudoku.html +++ b/docs/examples/browser/sudoku.html @@ -11,28 +11,32 @@
-
-

Sudoku

+
+

Sudoku

-
- + + -
-
-
-
+
+ +
+
+
+ +
+
+
+ -
-
- - + + @@ -44,7 +48,6 @@

Sudoku

- - - + + + @@ -50,10 +49,11 @@

WaltzDB Benchmark

}).then(function (res) { var session, dataset, - resultsContainer = $("#results_container"), + resultsContainer = $(".results_container"), statsListener = stats(), flowStr = res, - flow = nools.compile(res, {name: "waltzDb"}); + flow = nools.compile(res, {name: "waltzDb"}) + .conflictResolution(["salience", "factRecency", "activationRecency"]); function stop() { if (session) { @@ -81,7 +81,7 @@

WaltzDB Benchmark

session .on("log", function (data) { resultsContainer.append(data + "
"); - resultsContainer.scrollTop(resultsContainer.scrollHeight); + resultsContainer.scrollTop(resultsContainer.prop("scrollHeight")); }) .match().then(function () { console.profileEnd(); @@ -114,26 +114,16 @@

WaltzDB Benchmark

return false; }); - $("#editor-dialog").dialog({ - autoOpen: false, - modal: true, - width: window.innerWidth * 0.9, - height: window.innerHeight * 0.9, - open: function () { - (editor = ace.edit("editor").getSession()).setValue(flowStr); - }, - buttons: { - "Save": function () { - $(this).dialog("close"); - nools.deleteFlow("manners"); - stop(); - flow = nools.compile((flowStr = editor.getValue()), {name: "manners"}); - }, - Cancel: function () { - $(this).dialog("close"); - } - } - }); + var height = $(document).height() - $("#manners .header").height() - 100; + $(".editor-container").height(height); + resultsContainer.height(height); + + var editor = ace.edit("editor"); + //editor.setTheme("ace/theme/monokai"); + var editorSession = editor.getSession(); + editorSession.setMode("ace/mode/javascript"); + editorSession.setValue(res); + editor.setReadOnly(true); }); }); diff --git a/docs/index.html b/docs/index.html index 9bad862..572e6c4 100644 --- a/docs/index.html +++ b/docs/index.html @@ -218,6 +218,7 @@

Usage

  • Not
  • Or
  • From
  • +
  • Exists
  • Actions
  • @@ -231,7 +232,17 @@

    Usage

    Resources

    @@ -1199,6 +1210,25 @@

    From Constraint

    assert(n1); } } +

    +

    Exists Constraint

    +

    exists is the logical inversion of a not constraint. It checks for the existence of a fact in memory.

    +

    NOTE If there are multiple facts that satisfy the constraint the rule will ONLY be fired once.

    +
    
    + [
    +     ["exists", Number, "n1", "n1 > 1"]
    + ]
    +

    Or using the DSL.

    +
    
    + when {
    +     exists(n1: Number n1 > 1);
    + }
    +

    Assuming the above constraint. The following facts would cause the rule to fire once since there is a number that is greater than 1.

    +
     session.assert(1);
    + session.assert(2);
    + session.assert(3);
    + session.assert(4);
    + session.assert(5);

    Action

    The action is a function that should be fired when all patterns in the rule match. The action is called in the scope diff --git a/docs/nools.js b/docs/nools.js index 744d562..f4a6d0d 100644 --- a/docs/nools.js +++ b/docs/nools.js @@ -1,10 +1,11 @@ -/*! nools - v0.2.1 - 2013-11-08 +/*! nools - v0.2.2 - 2013-11-20 * http://c2fo.github.com/nools * Copyright (c) 2013 Doug Martin (http://c2fo.com); Licensed */ -!function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);throw new Error("Cannot find module '"+g+"'")}var j=c[g]={exports:{}};b[g][0].call(j.exports,function(a){var c=b[g][1][a];return e(c?c:a)},j,j.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;gc&&g>c&&c++;);var h=d[c]-e[c];return h||(h=f-g),h}function g(a,b){return a.recency-b.recency}var h=a("./extended").map,i={salience:d,bucketCounter:e,factRecency:f,activationRecency:g};c.strategies=i,c.strategy=function(a){a=h(a,function(a){return i[a]});var b=a.length;return function(c,d){var e=-1,f=0,g=c===d||c.name===d.name&&c.hashCode===d.hashCode;if(!g){for(;++e0?1:-1}return f}}},{"./extended":12}],8:[function(a,b,c){"use strict";var d,e=a("./extended"),f=e.deepEqual,g=e.merge,h=e.instanceOf,i=e.filter,j=e.declare,k=0,l=j({instance:{constructor:function(b,c){d||(d=a("./constraintMatcher")),this.id=k++,this.type=b,this.constraint=c,e.bindAll(this,["assert"])},assert:function(){throw new Error("not implemented")},equal:function(a){return h(a,this._static)&&this.get("alias")===a.get("alias")&&e.deepEqual(this.constraint,a.constraint)},getters:{variables:function(){return[this.get("alias")]}}}});l.extend({instance:{constructor:function(a){this._super(["object",a])},assert:function(a){return a instanceof this.constraint||a.constructor===this.constraint},equal:function(a){return h(a,this._static)&&this.constraint===a.constraint}}}).as(c,"ObjectConstraint"),l.extend({instance:{constructor:function(a,b){this._super(["equality",a]),b=b||{},this.pattern=b.pattern,this._matcher=d.getMatcher(a,b.scope||{})},assert:function(a){return this._matcher(a)}}}).as(c,"EqualityConstraint"),l.extend({instance:{constructor:function(){this._super(["equality",[!0]])},equal:function(a){return h(a,this._static)&&this.get("alias")===a.get("alias")},assert:function(){return!0}}}).as(c,"TrueConstraint"),l.extend({instance:{constructor:function(a,b){this.cache={},this._super(["reference",a]),b=b||{},this.values=[],this.pattern=b.pattern,this._options=b,this._matcher=d.getMatcher(a,b.scope||{})},assert:function(a){try{return this._matcher(a)}catch(b){throw new Error("Error with evaluating pattern "+this.pattern+" "+b.message)}},merge:function(a){var b=this;return a instanceof this._static&&(b=new this._static([this.constraint,a.constraint,"and"],g({},this._options,this._options)),b._alias=this._alias||a._alias,b.vars=this.vars.concat(a.vars)),b},equal:function(a){return h(a,this._static)&&e.deepEqual(this.constraint,a.constraint)},getters:{variables:function(){return this.vars},alias:function(){return this._alias}},setters:{alias:function(a){this._alias=a,this.vars=i(d.getIdentifiers(this.constraint),function(b){return b!==a})}}}}).as(c,"ReferenceConstraint"),l.extend({instance:{constructor:function(a){this._super(["hash",a])},equal:function(a){return e.instanceOf(a,this._static)&&this.get("alias")===a.get("alias")&&e.deepEqual(this.constraint,a.constraint)},assert:function(){return!0},getters:{variables:function(){return this.constraint}}}}).as(c,"HashConstraint"),l.extend({instance:{constructor:function(a,b){this.type="from",this.constraints=d.getSourceMatcher(a,(b||{}).scope||{}),e.bindAll(this,["assert"])},equal:function(a){return h(a,this._static)&&this.get("alias")===a.get("alias")&&f(this.constraints,a.constraints)},assert:function(a,b){return this.constraints(a,b)},getters:{variables:function(){return this.constraint}}}}).as(c,"FromConstraint")},{"./constraintMatcher":9,"./extended":12}],9:[function(a,b,c){"use strict";var d=a("./extended"),e=d.isArray,f=d.forEach,g=d.some,h=d.map,i=d.indexOf,j=d.isNumber,k=d.removeDuplicates,l=a("./constraint"),m={indexOf:d.indexOf,now:function(){return new Date},Date:function(a,b,c,d,e,f,g){var h=new Date;return j(a)&&h.setYear(a),j(b)&&h.setMonth(b),j(c)&&h.setDate(c),j(d)&&h.setHours(d),j(e)&&h.setMinutes(e),j(f)&&h.setSeconds(f),j(g)&&h.setMilliseconds(g),h},lengthOf:function(a,b){return a.length===b},isTrue:function(a){return a===!0},isFalse:function(a){return a===!1},isNotNull:function(a){return null!==a},dateCmp:function(a,b){return d.compare(a,b)}};f(["years","days","months","hours","minutes","seconds"],function(a){m[a+"FromNow"]=d[a+"FromNow"],m[a+"Ago"]=d[a+"Ago"]}),f(["isArray","isNumber","isHash","isObject","isDate","isBoolean","isString","isRegExp","isNull","isEmpty","isUndefined","isDefined","isUndefinedOrNull","isPromiseLike","isFunction","deepEqual"],function(a){var b=d[a];m[a]=function(){return b.apply(d,arguments)}});var n={equal:function(a,b){var c=!1;return a===b?c=!0:a[2]===b[2]&&(c=-1!==i(["string","number","boolean","regexp","identifier","null"],a[2])?a[0]===b[0]:"unary"===a[2]||"logicalNot"===a[2]?this.equal(a[0],b[0]):this.equal(a[0],b[0])&&this.equal(a[1],b[1])),c},getIdentifiers:function(a){var b=[],c=a[2];if("identifier"===c)return[a[0]];if("function"===c)b=b.concat(this.getIdentifiers(a[0])).concat(this.getIdentifiers(a[1]));else if("string"!==c&&"number"!==c&&"boolean"!==c&&"regexp"!==c&&"unary"!==c&&"unary"!==c)if("prop"===c){if(b=b.concat(this.getIdentifiers(a[0])),a[1])for(var d=a[1];e(d);){if("function"===d[2]){b=b.concat(this.getIdentifiers(d[1]));break}d=d[1]}}else a[0]&&(b=b.concat(this.getIdentifiers(a[0]))),a[1]&&(b=b.concat(this.getIdentifiers(a[1])));return k(b)},toConstraints:function(a,b){var c=[],d=b.alias,e=b.scope||{},f=a[2];return"and"===f?c=c.concat(this.toConstraints(a[0],b)).concat(this.toConstraints(a[1],b)):("composite"===f||"or"===f||"lt"===f||"gt"===f||"lte"===f||"gte"===f||"like"===f||"notLike"===f||"eq"===f||"neq"===f||"in"===f||"notIn"===f||"prop"===f||"propLookup"===f||"function"===f||"logicalNot"===f)&&(g(this.getIdentifiers(a),function(a){return!(a===d||a in m||a in e)})?c.push(new l.ReferenceConstraint(a,b)):c.push(new l.EqualityConstraint(a,b))),c},parse:function(a){return this[a[2]](a[0],a[1])},composite:function(a){return this.parse(a)},and:function(a,b){return["(",this.parse(a),"&&",this.parse(b),")"].join(" ")},or:function(a,b){return["(",this.parse(a),"||",this.parse(b),")"].join(" ")},prop:function(a,b){return"function"===b[2]?[this.parse(a),this.parse(b)].join("."):[this.parse(a),"['",this.parse(b),"']"].join("")},propLookup:function(a,b){return"function"===b[2]?[this.parse(a),this.parse(b)].join("."):[this.parse(a),"[",this.parse(b),"]"].join("")},unary:function(a){return-1*this.parse(a)},plus:function(a,b){return[this.parse(a),"+",this.parse(b)].join(" ")},minus:function(a,b){return[this.parse(a),"-",this.parse(b)].join(" ")},mult:function(a,b){return[this.parse(a),"*",this.parse(b)].join(" ")},div:function(a,b){return[this.parse(a),"/",this.parse(b)].join(" ")},mod:function(a,b){return[this.parse(a),"%",this.parse(b)].join(" ")},lt:function(a,b){return[this.parse(a),"<",this.parse(b)].join(" ")},gt:function(a,b){return[this.parse(a),">",this.parse(b)].join(" ")},lte:function(a,b){return[this.parse(a),"<=",this.parse(b)].join(" ")},gte:function(a,b){return[this.parse(a),">=",this.parse(b)].join(" ")},like:function(a,b){return[this.parse(b),".test(",this.parse(a),")"].join("")},notLike:function(a,b){return["!",this.parse(b),".test(",this.parse(a),")"].join("")},eq:function(a,b){return[this.parse(a),"===",this.parse(b)].join(" ")},neq:function(a,b){return[this.parse(a),"!==",this.parse(b)].join(" ")},"in":function(a,b){return["(indexOf(",this.parse(b),",",this.parse(a),")) != -1"].join("")},notIn:function(a,b){return["(indexOf(",this.parse(b),",",this.parse(a),")) == -1"].join("")},arguments:function(a,b){var c=[];return a&&c.push(this.parse(a)),b&&c.push(this.parse(b)),c.join(",")},array:function(a){var b=[];return a?(b=this.parse(a),e(b)?b:["[",b,"]"].join("")):["[",b.join(","),"]"].join("")},"function":function(a,b){var c=this.parse(b);return[this.parse(a),"(",c,")"].join("")},string:function(a){return"'"+a+"'"},number:function(a){return a},"boolean":function(a){return a},regexp:function(a){return a},identifier:function(a){return a},"null":function(){return"null"},logicalNot:function(a){return["!(",this.parse(a),")"].join("")}},o=c.toJs=function(a,b,c){var d=n.parse(a);b=b||{};var e=n.getIdentifiers(a),f="var indexOf = definedFuncs.indexOf;"+h(e,function(a){var c=["var ",a," = "];return m.hasOwnProperty(a)?c.push("definedFuncs['",a,"']"):b.hasOwnProperty(a)?c.push("scope['",a,"']"):c.push("'",a,"' in fact ? fact['",a,"'] : hash['",a,"']"),c.push(";"),c.join("")}).join("")+" return "+(c?c(d):d),g=new Function("fact, hash, definedFuncs, scope",f);return function(a,c){return g(a,c,m,b)}};c.getMatcher=function(a,b){return o(a,b,function(a){return"!!("+a+")"})},c.getSourceMatcher=function(a,b){return o(a,b,function(a){return a})},c.toConstraints=function(a,b){return n.toConstraints(a,b)},c.equal=function(a,b){return n.equal(a,b)},c.getIdentifiers=function(a){return n.getIdentifiers(a)}},{"./constraint":8,"./extended":12}],10:[function(a,b){"use strict";var c=a("./extended"),d=c.isBoolean,e=c.declare,f=c.merge,g=c.union,h=Array.prototype.slice,i=e({instance:{constructor:function(a){this.isMatch=!0,a instanceof this._static?(this.isMatch=a.isMatch,this.facts=h.call(a.facts),this.factIds=h.call(a.factIds),this.hashCode=this.factIds.join(":"),this.factHash=f({},a.factHash),this.recency=h.call(a.recency)):a?(this.facts=[a],this.factIds=[a.id],this.recency=[a.recency],this.hashCode=a.id+"",this.factHash=a.factHash||{}):(this.facts=[],this.factIds=[],this.factHash={},this.hashCode="")},merge:function(a){var b=new this._static;return b.isMatch=a.isMatch,b.facts=this.facts.concat(a.facts),b.factIds=this.factIds.concat(a.factIds),b.hashCode=b.factIds.join(":"),b.factHash=f({},this.factHash,a.factHash),b.recency=g(this.recency,a.recency),b}}}),j=e({instance:{match:null,factHash:null,fact:null,hashCode:null,paths:null,constructor:function(a,b,c){this.fact=a,this.paths=b||null;var d=this.match=c||new i(a);this.factHash=d.factHash,this.hashCode=d.hashCode,this.factIds=d.factIds},set:function(a,b){return this.factHash[a]=b,this},isMatch:function(a){return d(a)?(this.match.isMatch=a,this):this.match.isMatch},mergeMatch:function(a){var b=this.match=this.match.merge(a);return this.factHash=b.factHash,this.hashCode=b.hashCode,this.factIds=b.factIds,this},clone:function(a,b,c){return new j(a||this.fact,b||this.path,c||this.match)}}}).as(b)},{"./extended":12}],11:[function(a,b){var c=a("./extended"),d=c.Promise,e=a("./nextTick"),f=c.isPromiseLike;d.extend({instance:{looping:!1,constructor:function(a,b){this._super([]),this.flow=a,this.agenda=a.agenda,this.rootNode=a.rootNode,this.matchUntilHalt=!!b,c.bindAll(this,["onAlter","callNext"])},halt:function(){this.__halted=!0,this.looping||this.callback()},onAlter:function(){this.flowAltered=!0,this.looping||!this.matchUntilHalt||this.__halted||this.callNext()},setup:function(){var a=this.flow;this.rootNode.resetCounter(),a.on("assert",this.onAlter),a.on("modify",this.onAlter),a.on("retract",this.onAlter)},tearDown:function(){var a=this.flow;a.removeListener("assert",this.onAlter),a.removeListener("modify",this.onAlter),a.removeListener("retract",this.onAlter)},__handleAsyncNext:function(a){var b=this,c=b.agenda;return a.addCallback(function(){b.looping=!1,c.isEmpty()?(!b.matchUntilHalt||b.__halted)&&b.callback():(b.flowAltered&&(b.rootNode.incrementCounter(),b.flowAltered=!1),b.__halted?b.callback():b.callNext()),b=null}).addErrback(this.errback)},__handleSyncNext:function(a){return this.looping=!1,this.agenda.isEmpty()||this.flowAltered&&(this.rootNode.incrementCounter(),this.flowAltered=!1),a&&!this.__halted?e(this.callNext):(!this.matchUntilHalt||this.__halted)&&this.callback(),a},callback:function(){this.tearDown(),this._super(arguments)},callNext:function(){this.looping=!0;var a=this.agenda.fireNext();return f(a)?this.__handleAsyncNext(a):this.__handleSyncNext(a)},execute:function(){return this.setup(),this.callNext(),this}}}).as(b)},{"./extended":12,"./nextTick":17}],12:[function(a,b){b.exports=a("extended")().register(a("array-extended")).register(a("date-extended")).register(a("object-extended")).register(a("string-extended")).register(a("promise-extended")).register(a("function-extended")).register(a("is-extended")).register("HashTable",a("ht")).register("declare",a("declare.js")).register(a("leafy")).register("LinkedList",a("./linkedList"))},{"./linkedList":16,"array-extended":42,"date-extended":43,"declare.js":45,extended:46,"function-extended":49,ht:55,"is-extended":56,leafy:57,"object-extended":58,"promise-extended":59,"string-extended":60}],13:[function(a,b){"use strict";var c=a("./extended"),d=c.bind,e=c.declare,f=a("./nodes"),g=a("events").EventEmitter,h=a("./workingMemory"),i=h.WorkingMemory,j=a("./executionStrategy"),k=a("./agenda");b.exports=e(g,{instance:{name:null,executionStrategy:null,constructor:function(a,b){this.env=null,this.name=a,this.__rules={},this.conflictResolutionStrategy=b,this.workingMemory=new i,this.agenda=new k(this,b),this.agenda.on("fire",d(this,"emit","fire")),this.agenda.on("focused",d(this,"emit","focused")),this.rootNode=new f.RootNode(this.workingMemory,this.agenda),c.bindAll(this,"halt","assert","retract","modify","focus","emit")},focus:function(a){return this.agenda.setFocus(a),this},halt:function(){var a=this.executionStrategy;return a.matchUntilHalt&&a.halt(),this},dispose:function(){this.workingMemory.dispose(),this.agenda.dispose(),this.rootNode.dispose()},assert:function(a){return this.rootNode.assertFact(this.workingMemory.assertFact(a)),this.emit("assert",a),a},retract:function(a){return this.rootNode.retractFact(this.workingMemory.retractFact(a)),this.emit("retract",a),a},modify:function(a,b){return"function"==typeof b&&b.call(a,a),this.rootNode.modifyFact(this.workingMemory.modifyFact(a)),this.emit("modify",a),a},print:function(){this.rootNode.print()},containsRule:function(a){return this.rootNode.containsRule(a)},rule:function(a){this.rootNode.assertRule(a)},matchUntilHalt:function(a){return(this.executionStrategy=new j(this,!0)).execute().classic(a).promise()},match:function(a){return(this.executionStrategy=new j(this)).execute().classic(a).promise()}}})},{"./agenda":3,"./executionStrategy":11,"./extended":12,"./nodes":23,"./workingMemory":40,events:50}],14:[function(a,b){"use strict";var c=a("./extended"),d=c.instanceOf,e=c.forEach,f=c.declare,g=a("./pattern").InitialFact,h=a("./conflict"),i=h.strategy(["salience","activationRecency"]),j=a("./rule"),k=a("./flow"),l={},m=f({instance:{constructor:function(a,b){if(this.name=a,this.cb=b,this.__rules=[],this.__defined={},this.conflictResolutionStrategy=i,b&&b.call(this,this),l.hasOwnProperty(a))throw new Error("Flow with "+a+" already defined");l[a]=this},conflictResolution:function(a){return this.conflictResolutionStrategy=h.strategy(a),this},getDefined:function(a){var b=this.__defined[a.toLowerCase()];if(!b)throw new Error(a+" flow class is not defined");return b},addDefined:function(a,b){return this.__defined[a.toLowerCase()]=b,b},rule:function(){return this.__rules=this.__rules.concat(j.createRule.apply(j,arguments)),this},getSession:function(){var a=new k(this.name,this.conflictResolutionStrategy);e(this.__rules,function(b){a.rule(b)}),a.assert(new g);for(var b=0,c=arguments.length;c>b;b++)a.assert(arguments[b]);return a},containsRule:function(a){return c.some(this.__rules,function(b){return b.name===a})}},"static":{getFlow:function(a){return l[a]},hasFlow:function(a){return c.has(l,a)},deleteFlow:function(a){return d(a,m)&&(a=a.name),delete l[a],m},deleteFlows:function(){for(var a in l)a in l&&delete l[a];return m},create:function(a,b){return new m(a,b)}}}).as(b)},{"./conflict":7,"./extended":12,"./flow":13,"./pattern":38,"./rule":39}],15:[function(a,b,c){"use strict";function d(a){return/\.nools$/.test(a)}function e(a){var b;return b=d(a)?i.parse(g.readFileSync(a,"utf8"),a):i.parse(a)}var f=a("./extended"),g=a("fs"),h=a("path"),i=a("./compile"),j=a("./flowContainer");c.Flow=j,c.getFlow=j.getFlow,c.hasFlow=j.hasFlow,c.deleteFlow=function(a){return j.deleteFlow(a),this},c.deleteFlows=function(){return j.deleteFlows(),this},c.flow=j.create,c.compile=function(a,b,c){if(f.isFunction(b)?(c=b,b={}):(b=b||{},c=null),f.isString(a)&&(b.name=b.name||(d(a)?h.basename(a,h.extname(a)):null),a=e(a)),!b.name)throw new Error("Name required when compiling nools source");return i.compile(a,b,c,j)},c.transpile=function(a,b){return b=b||{},f.isString(a)&&(b.name=b.name||(d(a)?h.basename(a,h.extname(a)):null),a=e(a)),i.transpile(a,b)},c.parse=e},{"./compile":5,"./extended":12,"./flowContainer":14,fs:51,path:52}],16:[function(a,b){var c=a("declare.js");c({instance:{constructor:function(){this.head=null,this.tail=null,this.length=null},push:function(a){var b=this.tail,c=this.head,d={data:a,prev:b,next:null};return b&&(this.tail.next=d),this.tail=d,c||(this.head=d),this.length++,d},remove:function(a){a.prev?a.prev.next=a.next:this.head=a.next,a.next?a.next.prev=a.prev:this.tail=a.prev,this.length--},forEach:function(a){for(var b={next:this.head};b=b.next;)a(b.data)},clear:function(){this.head=this.tail=null,this.length=0}}}).as(b)},{"declare.js":45}],17:[function(a,b){var c,d=a("__browserify_process"),e=a("./extended");if("function"==typeof setImmediate)c="undefined"!=typeof window?e.bind(window,setImmediate):setImmediate;else if("undefined"!=typeof d)c=d.nextTick;else if("undefined"!=typeof MessageChannel){var f=new MessageChannel,g={},h=g;f.port1.onmessage=function(){g=g.next;var a=g.task;delete g.task,a()},c=function(a){h=h.next={task:a},f.port2.postMessage(0)}}else c=function(a){setTimeout(a,0)};b.exports=c},{"./extended":12,__browserify_process:54}],18:[function(a,b){var c=a("./alphaNode");c.extend({instance:{constructor:function(){this._super(arguments),this.alias=this.constraint.get("alias")},toString:function(){return"AliasNode"+this.__count},assert:function(a){return this.__propagate("assert",a.set(this.alias,a.fact.object))},modify:function(a){return this.__propagate("modify",a.set(this.alias,a.fact.object))},retract:function(a){return this.__propagate("retract",a.set(this.alias,a.fact.object))},equal:function(a){return a instanceof this._static&&this.alias===a.alias}}}).as(b)},{"./alphaNode":19}],19:[function(a,b){"use strict";var c=a("./node");c.extend({instance:{constructor:function(a){this._super([]),this.constraint=a,this.constraintAssert=this.constraint.assert},toString:function(){return"AlphaNode "+this.__count},equal:function(a){return this.constraint.equal(a.constraint)}}}).as(b)},{"./node":27}],20:[function(a,b){function c(a){for(var b=[],c=a.paths,d=-1,e=c.length;++dd;d++)this.__checkMatch(a,c[d],!0);else j(c)&&this.__checkMatch(a,c,!0)},__checkMatch:function(a,b,c){var d;return(d=this.__createMatch(a,b)).isMatch()&&c&&this.__propagate("assert",d.clone()),d},__createMatch:function(a,b){if(this.type(b)){var c,d=this.workingMemory.getFactHandle(b,!0),e=new i(d).set(this.alias,b),f=d.id,g=e.factHash,h=a.factHash;for(var j in h)g[j]=h[j];for(var k=this.__equalityConstraints,l=this.__variables,m=-1,o=k.length;++mc;c++)b=this.__checkMatch(a,l[c],!1),b.isMatch()&&(e=b.fact.id,e in k?this.__propagate("modify",b.clone()):this.__propagate("assert",b.clone()));else j(l)&&(b=this.__checkMatch(a,l,!1),b.isMatch()&&(e=b.fact.id,e in k?this.__propagate("modify",b.clone()):this.__propagate("assert",b.clone())));for(c in k)c in i||(this.removeFromFromMemory(k[c]),this.__propagate("retract",k[c].clone()))}else this.assertLeft(a);f=a.fact,e=f.id;var n=this.fromMemory[e];if(this.fromMemory[e]={},n){var o,p,q,r,s=f.object;for(c in n)p=n[c],o=p[0],q=p[1],r=q.isMatch(),o.hashCode!==a.hashCode&&(b=this.__createMatch(o,s,!1),r&&this.__propagate("retract",q.clone()),b.isMatch()&&this.__propagate(r?"modify":"assert",b.clone()))}},assertLeft:function(a){this.__addToLeftMemory(a),a.fromMatches={},this.__createMatches(a)},assertRight:function(){throw new Error("Shouldnt have gotten here")},toString:function(){return"FromNode"+this.__count}}}).as(b)},{"../constraint":8,"../context":10,"../extended":12,"./joinNode":24}],22:[function(a,b){var c=a("./joinNode"),d=a("../extended"),e=a("../constraint"),f=e.EqualityConstraint,g=e.HashConstraint,h=e.ReferenceConstraint,i=a("../context"),j=d.isDefined,k=d.forEach,l=d.isArray;c.extend({instance:{constructor:function(a,b){this._super(arguments),this.workingMemory=b,this.pattern=a,this.type=a.get("constraints")[0].assert,this.alias=a.get("alias"),this.from=a.from.assert,this.fromMemory={};var c=this.__equalityConstraints=[],d=[];k(this.constraints=this.pattern.get("constraints").slice(1),function(a){a instanceof f||a instanceof h?c.push(a.assert):a instanceof g&&(d=d.concat(a.get("variables")))}),this.__variables=d},retractLeft:function(a){var b=this.removeFromLeftMemory(a);b&&(b=b.data,b.blocked||this.__propagate("retract",b.clone()))},__modify:function(a,b){var c=b.blocked,d=a.factHash,e=this.from(d);if(l(e)){for(var f=0,g=e.length;g>f;f++)if(this.__isMatch(a,e[f],!0)){a.blocked=!0;break}}else j(e)&&(a.blocked=this.__isMatch(a,e,!0));var h=a.blocked;h?c||this.__propagate("retract",b.clone()):c?this.__propagate("assert",a.clone()):this.__propagate("modify",a.clone())},modifyLeft:function(a){var b=this.removeFromLeftMemory(a);if(!b)throw new Error;this.__addToLeftMemory(a),this.__modify(a,b.data);var c=this.fromMemory[a.fact.id];if(this.fromMemory[a.fact.id]={},c)for(var d in c)if(d!==a.hashCode){var e=c[d];b=this.removeFromLeftMemory(e),b&&(e=e.clone(),e.blocked=!1,this.__addToLeftMemory(e),this.__modify(e,b.data))}},__findMatches:function(a){var b=a.factHash,c=this.from(b),d=!1;if(l(c)){for(var e=0,f=c.length;f>e;e++)if(this.__isMatch(a,c[e],!0))return a.blocked=!0,void 0;this.__propagate("assert",a.clone())}else j(c)&&!(a.blocked=this.__isMatch(a,c,!0))&&this.__propagate("assert",a.clone());return d},__isMatch:function(a,b,c){var d=!1;if(this.type(b)){var e=this.workingMemory.getFactHandle(b),f=new i(e,null).mergeMatch(a.match).set(this.alias,b);if(c){var g=this.fromMemory[e.id];g||(g=this.fromMemory[e.id]={}),g[a.hashCode]=a}for(var h=f.factHash,j=this.__equalityConstraints,k=0,l=j.length;l>k;k++){if(!j[k](h)){d=!1;break}d=!0}}return d},removeFromLeftMemory:function(){return this._super(arguments)},assertLeft:function(a){this.__addToLeftMemory(a),this.__findMatches(a)},assertRight:function(){throw new Error("Shouldnt have gotten here")},retractRight:function(){throw new Error("Shouldnt have gotten here")},toString:function(){return"FromNode"+this.__count}}}).as(b)},{"../constraint":8,"../context":10,"../extended":12,"./joinNode":24}],23:[function(a,b,c){"use strict";var d=a("../extended"),e=d.forEach,f=d.some,g=d.declare,h=a("../pattern.js"),i=h.ObjectPattern,j=h.FromPattern,k=h.FromNotPattern,l=h.NotPattern,m=h.CompositePattern,n=h.InitialFactPattern,o=a("../constraint"),p=o.HashConstraint,q=o.ReferenceConstraint,r=a("./aliasNode"),s=a("./equalityNode"),t=a("./joinNode"),u=a("./notNode"),v=a("./fromNode"),w=a("./fromNotNode"),x=a("./leftAdapterNode"),y=a("./rightAdapterNode"),z=a("./typeNode"),A=a("./terminalNode"),B=a("./propertyNode");g({instance:{constructor:function(a,b){this.terminalNodes=[],this.joinNodes=[],this.nodes=[],this.constraints=[],this.typeNodes=[],this.__ruleCount=0,this.bucket={counter:0,recency:0},this.agendaTree=b,this.workingMemory=a},assertRule:function(a){var b=new A(this.bucket,this.__ruleCount++,a,this.agendaTree);this.__addToNetwork(a,a.pattern,b),this.__mergeJoinNodes(),this.terminalNodes.push(b)},resetCounter:function(){this.bucket.counter=0},incrementCounter:function(){this.bucket.counter++},assertFact:function(a){for(var b=this.typeNodes,c=b.length-1;c>=0;c--)b[c].assert(a)},retractFact:function(a){for(var b=this.typeNodes,c=b.length-1;c>=0;c--)b[c].retract(a)},modifyFact:function(a){for(var b=this.typeNodes,c=b.length-1;c>=0;c--)b[c].modify(a)},containsRule:function(a){return f(this.terminalNodes,function(b){return b.rule.name===a})},dispose:function(){for(var a=this.typeNodes,b=a.length-1;b>=0;b--)a[b].dispose()},__mergeJoinNodes:function(){for(var a=this.joinNodes,b=0;b=0;c--){var d=b[c];if(a.equal(d))return d}return b.push(a),a},__createTypeNode:function(a,b){for(var c=new z(b.get("constraints")[0]),d=this.typeNodes,e=d.length-1;e>=0;e--){var f=d[e];if(c.equal(f))return f}return d.push(c),c},__createEqualityNode:function(a,b){return this.__checkEqual(new s(b)).addRule(a)},__createPropertyNode:function(a,b){return this.__checkEqual(new B(b)).addRule(a)},__createAliasNode:function(a,b){return this.__checkEqual(new r(b)).addRule(a)},__createAdapterNode:function(a,b){return("left"===b?new x:new y).addRule(a)},__createJoinNode:function(a,b,c,d){var e;b.rightPattern instanceof l?e=new u:b.rightPattern instanceof k?e=new w(b.rightPattern,this.workingMemory):b.rightPattern instanceof j?e=new v(b.rightPattern,this.workingMemory):(e=new t,this.joinNodes.push(e)),e.__rule__=a;var f=e;if(c instanceof t){var g=this.__createAdapterNode(a,d);f.addOutNode(g,b),f=g}return f.addOutNode(c,b),e.addRule(a)},__addToNetwork:function(a,b,c,d){b instanceof i?!(b instanceof l||b instanceof j||b instanceof k)||d&&"left"!==d?this.__createAlphaNode(a,b,c,d):b instanceof k?this.__createBetaNode(a,new m(new n,b),c,d):this.__createBetaNode(a,new m(new n,b),c,d):b instanceof m&&this.__createBetaNode(a,b,c,d)},__createBetaNode:function(a,b,c,d){var e=this.__createJoinNode(a,b,c,d);return this.__addToNetwork(a,b.rightPattern,e,"right"),this.__addToNetwork(a,b.leftPattern,e,"left"),c.addParentNode(e),e},__createAlphaNode:function(a,b,c,d){var e,f;if(!(b instanceof j)){var g=b.get("constraints");e=this.__createTypeNode(a,b);var h=this.__createAliasNode(a,b);e.addOutNode(h,b),h.addParentNode(e),f=h;for(var i=g.length-1;i>0;i--){var k,l=g[i];if(l instanceof p)k=this.__createPropertyNode(a,l);else{if(l instanceof q){c.constraint.addConstraint(l);continue}k=this.__createEqualityNode(a,l)}f.addOutNode(k,b),k.addParentNode(f),f=k}if(c instanceof t){var m=this.__createAdapterNode(a,d);m.addParentNode(f),f.addOutNode(m,b),f=m}return c.addParentNode(f),f.addOutNode(c,b),e}},print:function(){e(this.terminalNodes,function(a){a.print(" ")})}}}).as(c,"RootNode")},{"../constraint":8,"../extended":12,"../pattern.js":38,"./aliasNode":18,"./equalityNode":20,"./fromNode":21,"./fromNotNode":22,"./joinNode":24,"./leftAdapterNode":26,"./notNode":28,"./propertyNode":29,"./rightAdapterNode":30,"./terminalNode":31,"./typeNode":32}],24:[function(a,b){var c=a("../extended"),d=c.hash.values,e=a("./node"),f=a("./joinReferenceNode"),g=a("../linkedList");e.extend({instance:{constructor:function(){this._super([]),this.constraint=new f,this.leftMemory={},this.rightMemory={},this.leftTuples=new g,this.rightTuples=new g},dispose:function(){this.leftMemory={},this.rightMemory={},this.leftTuples.clear(),this.rightTuples.clear()},disposeLeft:function(a){this.leftMemory={},this.leftTuples.clear(),this.propagateDispose(a)},disposeRight:function(a){this.rightMemory={},this.rightTuples.clear(),this.propagateDispose(a)},hashCode:function(){return"JoinNode "+this.__count},toString:function(){return"JoinNode "+this.__count},retractLeft:function(a){if(a=this.removeFromLeftMemory(a),!a)throw new Error;a=a.data;for(var b=d(a.rightMatches),c=-1,e=b.length;++ce;e++)this.addOutNode(d,c[e]);a.nodes.remove(d)},this);for(var b=a.parentNodes,c=0,d=a.parentNodes.l;d>c;c++){var e=b[c];this.addParentNode(e),e.nodes.remove(a)}return this},resolve:function(a,b){return a.hashCode===b.hashCode},print:function(a){console.log(a+this.toString()),d(this.parentNodes,function(b){b.print(" "+a)})},addOutNode:function(a,b){this.nodes.contains(a)||this.nodes.put(a,[]),this.nodes.get(a).push(b),this.__entrySet=this.nodes.entrySet()},addParentNode:function(a){-1===e(this.parentNodes,a)&&this.parentNodes.push(a)},shareable:function(){return!1},__propagate:function(a,b){for(var c,d,e,g,h=this.__entrySet,j=h.length;--j>-1;)c=h[j],d=c.key,e=c.value,b.paths?(g=f(e,b.paths)).length&&d[a](new i(b.fact,g,b.match)):d[a](b)},dispose:function(a){this.propagateDispose(a)},retract:function(a){this.propagateRetract(a)},propagateDispose:function(a,b){b=b||this.nodes;for(var c=this.__entrySet,d=c.length-1;d>=0;d--){var e=c[d],f=e.key;f.dispose(a)}},propagateAssert:function(a){this.__propagate("assert",a)},propagateRetract:function(a){this.__propagate("retract",a)},assert:function(a){this.propagateAssert(a)},modify:function(a){this.propagateModify(a)},propagateModify:function(a){this.__propagate("modify",a)}}}).as(b)},{"../context":10,"../extended":12}],28:[function(a,b){var c=a("./joinNode"),d=a("../linkedList"),e=a("../context"),f=a("../pattern").InitialFact;c.extend({instance:{constructor:function(){this._super(arguments),this.leftTupleMemory={},this.notMatch=new e(new f).match},toString:function(){return"NotNode "+this.__count},__cloneContext:function(a){return a.clone(null,null,a.match.merge(this.notMatch))},retractRight:function(a){var b=this.removeFromRightMemory(a);if(!b)throw new Error;var c=b.data,d=c.blocking;if(d.length){for(var e,f,g,h=this.rightTuples,i=this.constraint,j={next:d.head},k=h.length;j=j.next;){if(e=j.data,this.removeFromLeftBlockedMemory(e),0!==k){for(i.setLeftContext(e),f=b;f=f.next;)if(i.setRightContext(g=f.data).isMatch()){e.blocker=g,this.addToLeftBlockedMemory(g.blocking.push(e)),e=null;break}i.clearContexts()}e&&(this.__addToLeftMemory(e),this.__propagate("assert",this.__cloneContext(e)))}d.clear()}},retractLeft:function(a){var b=this.removeFromLeftMemory(a);if(b)b=b.data,this.__propagate("retract",this.__cloneContext(b));else if(!this.removeFromLeftBlockedMemory(a))throw new Error},assertLeft:function(a){var b,c,d=this.rightTuples,e=this.constraint;if(d.length){for(b={next:d.head},e.setLeftContext(a);(b=b.next)&&a;)e.setRightContext(c=b.data).isMatch()&&(a.blocker=c,this.addToLeftBlockedMemory(c.blocking.push(a)),a=null);e.clearContexts()}a&&(this.__addToLeftMemory(a),this.__propagate("assert",this.__cloneContext(a)))},assertRight:function(a){this.__addToRightMemory(a),a.blocking=new d;var b,c,e=this.leftTuples,f=this.constraint;if(e.length){for(c={next:e.head},f.setRightContext(a);c=c.next;)b=c.data,f.setLeftContext(b).isMatch()&&(this.__propagate("retract",this.__cloneContext(b)),this.removeFromLeftMemory(b),b.blocker=a,this.addToLeftBlockedMemory(a.blocking.push(b)));f.clearContexts()}},addToLeftBlockedMemory:function(a){var b=a.data,c=b.hashCode,d=this.leftMemory[c];return this.leftTupleMemory[c]=a,d&&this.leftTuples.remove(d),this},removeFromLeftBlockedMemory:function(a){var b=this.leftTupleMemory[a.hashCode]||null;return b&&(delete this.leftTupleMemory[a.hashCode],b.data.blocker.blocking.remove(b)),b},modifyLeft:function(a){var b,c,d,e,f=this.removeFromLeftMemory(a),g=this.constraint,h=this.rightTuples,i=h.length,j=!1;if(f||(f=this.removeFromLeftBlockedMemory(a),j=!0),!f)throw new Error;if(b=f.data,b&&b.blocker&&(e=this.rightMemory[b.blocker.hashCode]),e?(g.setLeftContext(a),g.setRightContext(d=e.data).isMatch()&&(j||this.__propagate("retract",this.__cloneContext(b)),a.blocker=d,this.addToLeftBlockedMemory(d.blocking.push(a)),a=null),a&&(c={next:e.next})):c={next:h.head},a&&i){for(c={next:h.head},g.setLeftContext(a);c=c.next;)if(g.setRightContext(d=c.data).isMatch()){j||this.__propagate("retract",this.__cloneContext(b)),this.addToLeftBlockedMemory(d.blocking.push(a)),a.blocker=d,a=null;break}g.clearContexts()}a&&(this.__addToLeftMemory(a),j?this.__propagate("assert",this.__cloneContext(a)):this.__propagate("modify",this.__cloneContext(a)))},modifyRight:function(a){var b=this.removeFromRightMemory(a);if(!b)throw new Error;var c,e,f=b.data,g=this.leftTuples,h=g.length,i=this.constraint,j=f.blocking;if(this.__addToRightMemory(a),a.blocking=new d,h||j.length){if(j.length){for(var k,l={next:j.head};l=l.next;)if(c=l.data,c.blocker=null,i.setRightContext(a),i.setLeftContext(c),i.isMatch())c.blocker=a,this.addToLeftBlockedMemory(a.blocking.push(c)),c=null;else{for(c.blocker=null,e=b;e=e.next;)if(i.setRightContext(k=e.data).isMatch()){c.blocker=k,this.addToLeftBlockedMemory(k.blocking.push(c)),c=null;break}c&&(this.__addToLeftMemory(c),this.__propagate("assert",this.__cloneContext(c))),i.clearContexts()}i.clearContexts()}if(h)for(i.setRightContext(a),e={next:g.head};e=e.next;)c=e.data,i.setLeftContext(c).isMatch()&&(this.__propagate("retract",this.__cloneContext(c)),this.removeFromLeftMemory(c),this.addToLeftBlockedMemory(a.blocking.push(c)),c.blocker=a)}}}}).as(b)},{"../context":10,"../linkedList":16,"../pattern":38,"./joinNode":24}],29:[function(a,b){var c=a("./alphaNode"),d=a("../context"),e=a("../extended");c.extend({instance:{constructor:function(){this._super(arguments),this.alias=this.constraint.get("alias"),this.varLength=(this.variables=e(this.constraint.get("variables")).toArray().value()).length},assert:function(a){var b,c=new d(a.fact,a.paths),e=this.variables,f=a.fact.object;c.set(this.alias,f);for(var g=0,h=this.varLength;h>g;g++)b=e[g],c.set(b[1],f[b[0]]);this.__propagate("assert",c)},retract:function(a){this.__propagate("retract",new d(a.fact,a.paths))},modify:function(a){var b,c=new d(a.fact,a.paths),e=this.variables,f=a.fact.object;c.set(this.alias,f);for(var g=0,h=this.varLength;h>g;g++)b=e[g],c.set(b[1],f[b[0]]);this.__propagate("modify",c)},toString:function(){return"PropertyNode"+this.__count}}}).as(b)},{"../context":10,"../extended":12,"./alphaNode":19}],30:[function(a,b){var c=a("./node");c.extend({instance:{retractResolve:function(a){this.__propagate("retractResolve",a)},dispose:function(a){this.propagateDispose(a)},propagateAssert:function(a){this.__propagate("assertRight",a)},propagateRetract:function(a){this.__propagate("retractRight",a)},propagateResolve:function(a){this.__propagate("retractResolve",a)},propagateModify:function(a){this.__propagate("modifyRight",a)},toString:function(){return"RightAdapterNode "+this.__count}}}).as(b)},{"./node":27}],31:[function(a,b){var c=a("./node"),d=a("../extended"),e=d.bind,f=d.removeDuplicates;c.extend({instance:{constructor:function(a,b,c,d){this._super([]),this.resolve=e(this,this.resolve),this.rule=c,this.index=b,this.name=this.rule.name,this.agenda=d,this.bucket=a,d.register(this)},__assertModify:function(a){var b=a.match;if(b.recency.sort(function(a,b){return a-b}).reverse(),b.facts=f(b.facts),b.isMatch){var c=this.rule,d=this.bucket;this.agenda.insert(this,{rule:c,hashCode:a.hashCode,index:this.index,name:c.name,recency:d.recency++,match:b,counter:d.counter})}},assert:function(a){this.__assertModify(a)},modify:function(a){this.agenda.retract(this,a),this.__assertModify(a)},retract:function(a){this.agenda.retract(this,a)},retractRight:function(a){this.agenda.retract(this,a)},retractLeft:function(a){this.agenda.retract(this,a)},assertLeft:function(a){this.__assertModify(a)},assertRight:function(a){this.__assertModify(a)},toString:function(){return"TerminalNode "+this.rule.name}}}).as(b)},{"../extended":12,"./node":27}],32:[function(a,b){var c=a("./alphaNode"),d=a("../context");c.extend({instance:{assert:function(a){this.constraintAssert(a.object)&&this.__propagate("assert",a)},modify:function(a){this.constraintAssert(a.object)&&this.__propagate("modify",a)},retract:function(a){this.constraintAssert(a.object)&&this.__propagate("retract",a)},toString:function(){return"TypeNode"+this.__count},dispose:function(){for(var a=this.__entrySet,b=a.length-1;b>=0;b--){var c=a[b],d=c.key,e=c.value;d.dispose({paths:e})}},__propagate:function(a,b){for(var c=this.__entrySet,e=-1,f=c.length;++e":20,"<=":21,">=":22,EQUALITY_EXPRESSION:23,"==":24,"!=":25,"=~":26,"!=~":27,IN_EXPRESSION:28,"in":29,ARRAY_EXPRESSION:30,notIn:31,OBJECT_EXPRESSION:32,AND_EXPRESSION:33,"&&":34,OR_EXPRESSION:35,"||":36,ARGUMENT_LIST:37,",":38,IDENTIFIER_EXPRESSION:39,IDENTIFIER:40,".":41,"[":42,STRING_EXPRESSION:43,"]":44,NUMBER_EXPRESSION:45,"(":46,")":47,STRING:48,NUMBER:49,REGEXP_EXPRESSION:50,REGEXP:51,BOOLEAN_EXPRESSION:52,BOOLEAN:53,NULL_EXPRESSION:54,NULL:55,$accept:0,$end:1},terminals_:{2:"error",5:"EOF",8:"-",9:"!",11:"*",12:"/",13:"%",15:"+",17:"^",19:"<",20:">",21:"<=",22:">=",24:"==",25:"!=",26:"=~",27:"!=~",29:"in",31:"notIn",34:"&&",36:"||",38:",",40:"IDENTIFIER",41:".",42:"[",44:"]",46:"(",47:")",48:"STRING",49:"NUMBER",51:"REGEXP",53:"BOOLEAN",55:"NULL"},productions_:[0,[3,2],[6,1],[6,2],[6,2],[10,1],[10,3],[10,3],[10,3],[14,1],[14,3],[14,3],[16,1],[16,3],[18,1],[18,3],[18,3],[18,3],[18,3],[23,1],[23,3],[23,3],[23,3],[23,3],[28,1],[28,3],[28,3],[28,3],[28,3],[33,1],[33,3],[35,1],[35,3],[37,1],[37,3],[39,1],[32,1],[32,3],[32,4],[32,4],[32,4],[32,3],[32,4],[43,1],[45,1],[50,1],[52,1],[54,1],[30,2],[30,3],[7,1],[7,1],[7,1],[7,1],[7,1],[7,1],[7,1],[7,3],[4,1]],performAction:function(a,b,c,d,e,f){var g=f.length-1;switch(e){case 1:return f[g-1];case 3:this.$=[f[g],null,"unary"];break;case 4:this.$=[f[g],null,"logicalNot"];break;case 6:this.$=[f[g-2],f[g],"mult"];break;case 7:this.$=[f[g-2],f[g],"div"];break;case 8:this.$=[f[g-2],f[g],"mod"];break;case 10:this.$=[f[g-2],f[g],"plus"];break;case 11:this.$=[f[g-2],f[g],"minus"];break;case 13:this.$=[f[g-2],f[g],"pow"];break;case 15:this.$=[f[g-2],f[g],"lt"];break;case 16:this.$=[f[g-2],f[g],"gt"];break;case 17:this.$=[f[g-2],f[g],"lte"];break;case 18:this.$=[f[g-2],f[g],"gte"];break;case 20:this.$=[f[g-2],f[g],"eq"];break;case 21:this.$=[f[g-2],f[g],"neq"];break;case 22:this.$=[f[g-2],f[g],"like"];break;case 23:this.$=[f[g-2],f[g],"notLike"];break;case 25:this.$=[f[g-2],f[g],"in"];break;case 26:this.$=[f[g-2],f[g],"notIn"];break;case 27:this.$=[f[g-2],f[g],"in"];break;case 28:this.$=[f[g-2],f[g],"notIn"];break;case 30:this.$=[f[g-2],f[g],"and"];break;case 32:this.$=[f[g-2],f[g],"or"];break;case 34:this.$=[f[g-2],f[g],"arguments"];break;case 35:this.$=[String(a),null,"identifier"];break;case 37:this.$=[f[g-2],f[g],"prop"];break;case 38:this.$=[f[g-3],f[g-1],"propLookup"];break;case 39:this.$=[f[g-3],f[g-1],"propLookup"];break;case 40:this.$=[f[g-3],f[g-1],"propLookup"];break;case 41:this.$=[f[g-2],[null,null,"arguments"],"function"];break;case 42:this.$=[f[g-3],f[g-1],"function"];break;case 43:this.$=[String(a.replace(/^['|"]|['|"]$/g,"")),null,"string"];break;case 44:this.$=[Number(a),null,"number"];break;case 45:this.$=[a,null,"regexp"];break;case 46:this.$=["true"==a.replace(/^\s+/,""),null,"boolean"];break;case 47:this.$=[null,null,"null"];break;case 48:this.$=[null,null,"array"];break;case 49:this.$=[f[g-1],null,"array"];break;case 57:this.$=[f[g-1],null,"composite"]}},table:[{3:1,4:2,6:28,7:7,8:[1,29],9:[1,30],10:27,14:25,16:17,18:8,23:6,28:5,30:15,32:14,33:4,35:3,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{1:[3]},{5:[1,31]},{5:[2,58],36:[1,32],47:[2,58]},{5:[2,31],34:[1,33],36:[2,31],47:[2,31]},{5:[2,29],34:[2,29],36:[2,29],47:[2,29]},{5:[2,24],24:[1,34],25:[1,35],26:[1,36],27:[1,37],34:[2,24],36:[2,24],47:[2,24]},{5:[2,2],8:[2,2],11:[2,2],12:[2,2],13:[2,2],15:[2,2],17:[2,2],19:[2,2],20:[2,2],21:[2,2],22:[2,2],24:[2,2],25:[2,2],26:[2,2],27:[2,2],29:[1,38],31:[1,39],34:[2,2],36:[2,2],47:[2,2]},{5:[2,19],19:[1,40],20:[1,41],21:[1,42],22:[1,43],24:[2,19],25:[2,19],26:[2,19],27:[2,19],34:[2,19],36:[2,19],47:[2,19]},{5:[2,50],8:[2,50],11:[2,50],12:[2,50],13:[2,50],15:[2,50],17:[2,50],19:[2,50],20:[2,50],21:[2,50],22:[2,50],24:[2,50],25:[2,50],26:[2,50],27:[2,50],29:[2,50],31:[2,50],34:[2,50],36:[2,50],38:[2,50],44:[2,50],47:[2,50]},{5:[2,51],8:[2,51],11:[2,51],12:[2,51],13:[2,51],15:[2,51],17:[2,51],19:[2,51],20:[2,51],21:[2,51],22:[2,51],24:[2,51],25:[2,51],26:[2,51],27:[2,51],29:[2,51],31:[2,51],34:[2,51],36:[2,51],38:[2,51],44:[2,51],47:[2,51]},{5:[2,52],8:[2,52],11:[2,52],12:[2,52],13:[2,52],15:[2,52],17:[2,52],19:[2,52],20:[2,52],21:[2,52],22:[2,52],24:[2,52],25:[2,52],26:[2,52],27:[2,52],29:[2,52],31:[2,52],34:[2,52],36:[2,52],38:[2,52],44:[2,52],47:[2,52]},{5:[2,53],8:[2,53],11:[2,53],12:[2,53],13:[2,53],15:[2,53],17:[2,53],19:[2,53],20:[2,53],21:[2,53],22:[2,53],24:[2,53],25:[2,53],26:[2,53],27:[2,53],29:[2,53],31:[2,53],34:[2,53],36:[2,53],38:[2,53],44:[2,53],47:[2,53]},{5:[2,54],8:[2,54],11:[2,54],12:[2,54],13:[2,54],15:[2,54],17:[2,54],19:[2,54],20:[2,54],21:[2,54],22:[2,54],24:[2,54],25:[2,54],26:[2,54],27:[2,54],29:[2,54],31:[2,54],34:[2,54],36:[2,54],38:[2,54],44:[2,54],47:[2,54]},{5:[2,55],8:[2,55],11:[2,55],12:[2,55],13:[2,55],15:[2,55],17:[2,55],19:[2,55],20:[2,55],21:[2,55],22:[2,55],24:[2,55],25:[2,55],26:[2,55],27:[2,55],29:[2,55],31:[2,55],34:[2,55],36:[2,55],38:[2,55],41:[1,44],42:[1,45],44:[2,55],46:[1,46],47:[2,55]},{5:[2,56],8:[2,56],11:[2,56],12:[2,56],13:[2,56],15:[2,56],17:[2,56],19:[2,56],20:[2,56],21:[2,56],22:[2,56],24:[2,56],25:[2,56],26:[2,56],27:[2,56],29:[2,56],31:[2,56],34:[2,56],36:[2,56],38:[2,56],44:[2,56],47:[2,56]},{4:47,6:28,7:7,8:[1,29],9:[1,30],10:27,14:25,16:17,18:8,23:6,28:5,30:15,32:14,33:4,35:3,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{5:[2,14],17:[1,48],19:[2,14],20:[2,14],21:[2,14],22:[2,14],24:[2,14],25:[2,14],26:[2,14],27:[2,14],34:[2,14],36:[2,14],47:[2,14]},{5:[2,43],8:[2,43],11:[2,43],12:[2,43],13:[2,43],15:[2,43],17:[2,43],19:[2,43],20:[2,43],21:[2,43],22:[2,43],24:[2,43],25:[2,43],26:[2,43],27:[2,43],29:[2,43],31:[2,43],34:[2,43],36:[2,43],38:[2,43],44:[2,43],47:[2,43]},{5:[2,44],8:[2,44],11:[2,44],12:[2,44],13:[2,44],15:[2,44],17:[2,44],19:[2,44],20:[2,44],21:[2,44],22:[2,44],24:[2,44],25:[2,44],26:[2,44],27:[2,44],29:[2,44],31:[2,44],34:[2,44],36:[2,44],38:[2,44],44:[2,44],47:[2,44]},{5:[2,45],8:[2,45],11:[2,45],12:[2,45],13:[2,45],15:[2,45],17:[2,45],19:[2,45],20:[2,45],21:[2,45],22:[2,45],24:[2,45],25:[2,45],26:[2,45],27:[2,45],29:[2,45],31:[2,45],34:[2,45],36:[2,45],38:[2,45],44:[2,45],47:[2,45]},{5:[2,46],8:[2,46],11:[2,46],12:[2,46],13:[2,46],15:[2,46],17:[2,46],19:[2,46],20:[2,46],21:[2,46],22:[2,46],24:[2,46],25:[2,46],26:[2,46],27:[2,46],29:[2,46],31:[2,46],34:[2,46],36:[2,46],38:[2,46],44:[2,46],47:[2,46]},{5:[2,47],8:[2,47],11:[2,47],12:[2,47],13:[2,47],15:[2,47],17:[2,47],19:[2,47],20:[2,47],21:[2,47],22:[2,47],24:[2,47],25:[2,47],26:[2,47],27:[2,47],29:[2,47],31:[2,47],34:[2,47],36:[2,47],38:[2,47],44:[2,47],47:[2,47]},{5:[2,36],8:[2,36],11:[2,36],12:[2,36],13:[2,36],15:[2,36],17:[2,36],19:[2,36],20:[2,36],21:[2,36],22:[2,36],24:[2,36],25:[2,36],26:[2,36],27:[2,36],29:[2,36],31:[2,36],34:[2,36],36:[2,36],38:[2,36],41:[2,36],42:[2,36],44:[2,36],46:[2,36],47:[2,36]},{7:51,30:15,32:14,37:50,39:23,40:[1,26],42:[1,24],43:9,44:[1,49],45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{5:[2,12],8:[1,53],15:[1,52],17:[2,12],19:[2,12],20:[2,12],21:[2,12],22:[2,12],24:[2,12],25:[2,12],26:[2,12],27:[2,12],34:[2,12],36:[2,12],47:[2,12]},{5:[2,35],8:[2,35],11:[2,35],12:[2,35],13:[2,35],15:[2,35],17:[2,35],19:[2,35],20:[2,35],21:[2,35],22:[2,35],24:[2,35],25:[2,35],26:[2,35],27:[2,35],29:[2,35],31:[2,35],34:[2,35],36:[2,35],38:[2,35],41:[2,35],42:[2,35],44:[2,35],46:[2,35],47:[2,35]},{5:[2,9],8:[2,9],11:[1,54],12:[1,55],13:[1,56],15:[2,9],17:[2,9],19:[2,9],20:[2,9],21:[2,9],22:[2,9],24:[2,9],25:[2,9],26:[2,9],27:[2,9],34:[2,9],36:[2,9],47:[2,9]},{5:[2,5],8:[2,5],11:[2,5],12:[2,5],13:[2,5],15:[2,5],17:[2,5],19:[2,5],20:[2,5],21:[2,5],22:[2,5],24:[2,5],25:[2,5],26:[2,5],27:[2,5],34:[2,5],36:[2,5],47:[2,5]},{6:57,7:58,8:[1,29],9:[1,30],30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:59,7:58,8:[1,29],9:[1,30],30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{1:[2,1]},{6:28,7:7,8:[1,29],9:[1,30],10:27,14:25,16:17,18:8,23:6,28:5,30:15,32:14,33:60,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:28,7:7,8:[1,29],9:[1,30],10:27,14:25,16:17,18:8,23:6,28:61,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:28,7:58,8:[1,29],9:[1,30],10:27,14:25,16:17,18:62,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:28,7:58,8:[1,29],9:[1,30],10:27,14:25,16:17,18:63,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:28,7:58,8:[1,29],9:[1,30],10:27,14:25,16:17,18:64,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:28,7:58,8:[1,29],9:[1,30],10:27,14:25,16:17,18:65,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{30:66,32:67,39:23,40:[1,26],42:[1,24]},{30:68,32:69,39:23,40:[1,26],42:[1,24]},{6:28,7:58,8:[1,29],9:[1,30],10:27,14:25,16:70,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:28,7:58,8:[1,29],9:[1,30],10:27,14:25,16:71,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:28,7:58,8:[1,29],9:[1,30],10:27,14:25,16:72,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:28,7:58,8:[1,29],9:[1,30],10:27,14:25,16:73,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{39:74,40:[1,26]},{32:77,39:23,40:[1,26],43:75,45:76,48:[1,18],49:[1,19]},{7:51,30:15,32:14,37:79,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],47:[1,78],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{47:[1,80]},{6:28,7:58,8:[1,29],9:[1,30],10:27,14:81,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{5:[2,48],8:[2,48],11:[2,48],12:[2,48],13:[2,48],15:[2,48],17:[2,48],19:[2,48],20:[2,48],21:[2,48],22:[2,48],24:[2,48],25:[2,48],26:[2,48],27:[2,48],29:[2,48],31:[2,48],34:[2,48],36:[2,48],38:[2,48],44:[2,48],47:[2,48]},{38:[1,83],44:[1,82]},{38:[2,33],44:[2,33],47:[2,33]},{6:28,7:58,8:[1,29],9:[1,30],10:84,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:28,7:58,8:[1,29],9:[1,30],10:85,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:86,7:58,8:[1,29],9:[1,30],30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:87,7:58,8:[1,29],9:[1,30],30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:88,7:58,8:[1,29],9:[1,30],30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{5:[2,3],8:[2,3],11:[2,3],12:[2,3],13:[2,3],15:[2,3],17:[2,3],19:[2,3],20:[2,3],21:[2,3],22:[2,3],24:[2,3],25:[2,3],26:[2,3],27:[2,3],34:[2,3],36:[2,3],47:[2,3]},{5:[2,2],8:[2,2],11:[2,2],12:[2,2],13:[2,2],15:[2,2],17:[2,2],19:[2,2],20:[2,2],21:[2,2],22:[2,2],24:[2,2],25:[2,2],26:[2,2],27:[2,2],34:[2,2],36:[2,2],47:[2,2]},{5:[2,4],8:[2,4],11:[2,4],12:[2,4],13:[2,4],15:[2,4],17:[2,4],19:[2,4],20:[2,4],21:[2,4],22:[2,4],24:[2,4],25:[2,4],26:[2,4],27:[2,4],34:[2,4],36:[2,4],47:[2,4]},{5:[2,32],34:[1,33],36:[2,32],47:[2,32]},{5:[2,30],34:[2,30],36:[2,30],47:[2,30]},{5:[2,20],19:[1,40],20:[1,41],21:[1,42],22:[1,43],24:[2,20],25:[2,20],26:[2,20],27:[2,20],34:[2,20],36:[2,20],47:[2,20]},{5:[2,21],19:[1,40],20:[1,41],21:[1,42],22:[1,43],24:[2,21],25:[2,21],26:[2,21],27:[2,21],34:[2,21],36:[2,21],47:[2,21]},{5:[2,22],19:[1,40],20:[1,41],21:[1,42],22:[1,43],24:[2,22],25:[2,22],26:[2,22],27:[2,22],34:[2,22],36:[2,22],47:[2,22]},{5:[2,23],19:[1,40],20:[1,41],21:[1,42],22:[1,43],24:[2,23],25:[2,23],26:[2,23],27:[2,23],34:[2,23],36:[2,23],47:[2,23]},{5:[2,25],34:[2,25],36:[2,25],47:[2,25]},{5:[2,27],34:[2,27],36:[2,27],41:[1,44],42:[1,45],46:[1,46],47:[2,27]},{5:[2,26],34:[2,26],36:[2,26],47:[2,26]},{5:[2,28],34:[2,28],36:[2,28],41:[1,44],42:[1,45],46:[1,46],47:[2,28]},{5:[2,15],17:[1,48],19:[2,15],20:[2,15],21:[2,15],22:[2,15],24:[2,15],25:[2,15],26:[2,15],27:[2,15],34:[2,15],36:[2,15],47:[2,15]},{5:[2,16],17:[1,48],19:[2,16],20:[2,16],21:[2,16],22:[2,16],24:[2,16],25:[2,16],26:[2,16],27:[2,16],34:[2,16],36:[2,16],47:[2,16]},{5:[2,17],17:[1,48],19:[2,17],20:[2,17],21:[2,17],22:[2,17],24:[2,17],25:[2,17],26:[2,17],27:[2,17],34:[2,17],36:[2,17],47:[2,17]},{5:[2,18],17:[1,48],19:[2,18],20:[2,18],21:[2,18],22:[2,18],24:[2,18],25:[2,18],26:[2,18],27:[2,18],34:[2,18],36:[2,18],47:[2,18]},{5:[2,37],8:[2,37],11:[2,37],12:[2,37],13:[2,37],15:[2,37],17:[2,37],19:[2,37],20:[2,37],21:[2,37],22:[2,37],24:[2,37],25:[2,37],26:[2,37],27:[2,37],29:[2,37],31:[2,37],34:[2,37],36:[2,37],38:[2,37],41:[2,37],42:[2,37],44:[2,37],46:[2,37],47:[2,37]},{44:[1,89]},{44:[1,90]},{41:[1,44],42:[1,45],44:[1,91],46:[1,46]},{5:[2,41],8:[2,41],11:[2,41],12:[2,41],13:[2,41],15:[2,41],17:[2,41],19:[2,41],20:[2,41],21:[2,41],22:[2,41],24:[2,41],25:[2,41],26:[2,41],27:[2,41],29:[2,41],31:[2,41],34:[2,41],36:[2,41],38:[2,41],41:[2,41],42:[2,41],44:[2,41],46:[2,41],47:[2,41]},{38:[1,83],47:[1,92]},{5:[2,57],8:[2,57],11:[2,57],12:[2,57],13:[2,57],15:[2,57],17:[2,57],19:[2,57],20:[2,57],21:[2,57],22:[2,57],24:[2,57],25:[2,57],26:[2,57],27:[2,57],29:[2,57],31:[2,57],34:[2,57],36:[2,57],38:[2,57],44:[2,57],47:[2,57]},{5:[2,13],8:[1,53],15:[1,52],17:[2,13],19:[2,13],20:[2,13],21:[2,13],22:[2,13],24:[2,13],25:[2,13],26:[2,13],27:[2,13],34:[2,13],36:[2,13],47:[2,13]},{5:[2,49],8:[2,49],11:[2,49],12:[2,49],13:[2,49],15:[2,49],17:[2,49],19:[2,49],20:[2,49],21:[2,49],22:[2,49],24:[2,49],25:[2,49],26:[2,49],27:[2,49],29:[2,49],31:[2,49],34:[2,49],36:[2,49],38:[2,49],44:[2,49],47:[2,49]},{7:93,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{5:[2,10],8:[2,10],11:[1,54],12:[1,55],13:[1,56],15:[2,10],17:[2,10],19:[2,10],20:[2,10],21:[2,10],22:[2,10],24:[2,10],25:[2,10],26:[2,10],27:[2,10],34:[2,10],36:[2,10],47:[2,10]},{5:[2,11],8:[2,11],11:[1,54],12:[1,55],13:[1,56],15:[2,11],17:[2,11],19:[2,11],20:[2,11],21:[2,11],22:[2,11],24:[2,11],25:[2,11],26:[2,11],27:[2,11],34:[2,11],36:[2,11],47:[2,11]},{5:[2,6],8:[2,6],11:[2,6],12:[2,6],13:[2,6],15:[2,6],17:[2,6],19:[2,6],20:[2,6],21:[2,6],22:[2,6],24:[2,6],25:[2,6],26:[2,6],27:[2,6],34:[2,6],36:[2,6],47:[2,6]},{5:[2,7],8:[2,7],11:[2,7],12:[2,7],13:[2,7],15:[2,7],17:[2,7],19:[2,7],20:[2,7],21:[2,7],22:[2,7],24:[2,7],25:[2,7],26:[2,7],27:[2,7],34:[2,7],36:[2,7],47:[2,7]},{5:[2,8],8:[2,8],11:[2,8],12:[2,8],13:[2,8],15:[2,8],17:[2,8],19:[2,8],20:[2,8],21:[2,8],22:[2,8],24:[2,8],25:[2,8],26:[2,8],27:[2,8],34:[2,8],36:[2,8],47:[2,8]},{5:[2,38],8:[2,38],11:[2,38],12:[2,38],13:[2,38],15:[2,38],17:[2,38],19:[2,38],20:[2,38],21:[2,38],22:[2,38],24:[2,38],25:[2,38],26:[2,38],27:[2,38],29:[2,38],31:[2,38],34:[2,38],36:[2,38],38:[2,38],41:[2,38],42:[2,38],44:[2,38],46:[2,38],47:[2,38]},{5:[2,39],8:[2,39],11:[2,39],12:[2,39],13:[2,39],15:[2,39],17:[2,39],19:[2,39],20:[2,39],21:[2,39],22:[2,39],24:[2,39],25:[2,39],26:[2,39],27:[2,39],29:[2,39],31:[2,39],34:[2,39],36:[2,39],38:[2,39],41:[2,39],42:[2,39],44:[2,39],46:[2,39],47:[2,39]},{5:[2,40],8:[2,40],11:[2,40],12:[2,40],13:[2,40],15:[2,40],17:[2,40],19:[2,40],20:[2,40],21:[2,40],22:[2,40],24:[2,40],25:[2,40],26:[2,40],27:[2,40],29:[2,40],31:[2,40],34:[2,40],36:[2,40],38:[2,40],41:[2,40],42:[2,40],44:[2,40],46:[2,40],47:[2,40]},{5:[2,42],8:[2,42],11:[2,42],12:[2,42],13:[2,42],15:[2,42],17:[2,42],19:[2,42],20:[2,42],21:[2,42],22:[2,42],24:[2,42],25:[2,42],26:[2,42],27:[2,42],29:[2,42],31:[2,42],34:[2,42],36:[2,42],38:[2,42],41:[2,42],42:[2,42],44:[2,42],46:[2,42],47:[2,42]},{38:[2,34],44:[2,34],47:[2,34]}],defaultActions:{31:[2,1]},parseError:function(a,b){if(!b.recoverable)throw new Error(a); -this.trace(a)},parse:function(a){function b(){var a;return a=c.lexer.lex()||m,"number"!=typeof a&&(a=c.symbols_[a]||a),a}var c=this,d=[0],e=[null],f=[],g=this.table,h="",i=0,j=0,k=0,l=2,m=1;this.lexer.setInput(a),this.lexer.yy=this.yy,this.yy.lexer=this.lexer,this.yy.parser=this,"undefined"==typeof this.lexer.yylloc&&(this.lexer.yylloc={});var n=this.lexer.yylloc;f.push(n);var o=this.lexer.options&&this.lexer.options.ranges;this.parseError="function"==typeof this.yy.parseError?this.yy.parseError:Object.getPrototypeOf(this).parseError;for(var p,q,r,s,t,u,v,w,x,y={};;){if(r=d[d.length-1],this.defaultActions[r]?s=this.defaultActions[r]:((null===p||"undefined"==typeof p)&&(p=b()),s=g[r]&&g[r][p]),"undefined"==typeof s||!s.length||!s[0]){var z="";x=[];for(u in g[r])this.terminals_[u]&&u>l&&x.push("'"+this.terminals_[u]+"'");z=this.lexer.showPosition?"Parse error on line "+(i+1)+":\n"+this.lexer.showPosition()+"\nExpecting "+x.join(", ")+", got '"+(this.terminals_[p]||p)+"'":"Parse error on line "+(i+1)+": Unexpected "+(p==m?"end of input":"'"+(this.terminals_[p]||p)+"'"),this.parseError(z,{text:this.lexer.match,token:this.terminals_[p]||p,line:this.lexer.yylineno,loc:n,expected:x})}if(s[0]instanceof Array&&s.length>1)throw new Error("Parse Error: multiple actions possible at state: "+r+", token: "+p);switch(s[0]){case 1:d.push(p),e.push(this.lexer.yytext),f.push(this.lexer.yylloc),d.push(s[1]),p=null,q?(p=q,q=null):(j=this.lexer.yyleng,h=this.lexer.yytext,i=this.lexer.yylineno,n=this.lexer.yylloc,k>0&&k--);break;case 2:if(v=this.productions_[s[1]][1],y.$=e[e.length-v],y._$={first_line:f[f.length-(v||1)].first_line,last_line:f[f.length-1].last_line,first_column:f[f.length-(v||1)].first_column,last_column:f[f.length-1].last_column},o&&(y._$.range=[f[f.length-(v||1)].range[0],f[f.length-1].range[1]]),t=this.performAction.call(y,h,j,i,this.yy,s[1],e,f),"undefined"!=typeof t)return t;v&&(d=d.slice(0,2*-1*v),e=e.slice(0,-1*v),f=f.slice(0,-1*v)),d.push(this.productions_[s[1]][0]),e.push(y.$),f.push(y._$),w=g[d[d.length-2]][d[d.length-1]],d.push(w);break;case 3:return!0}}return!0}},c=function(){var a={EOF:1,parseError:function(a,b){if(!this.yy.parser)throw new Error(a);this.yy.parser.parseError(a,b)},setInput:function(a){return this._input=a,this._more=this._backtrack=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},input:function(){var a=this._input[0];this.yytext+=a,this.yyleng++,this.offset++,this.match+=a,this.matched+=a;var b=a.match(/(?:\r\n?|\n).*/g);return b?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),a},unput:function(a){var b=a.length,c=a.split(/(?:\r\n?|\n)/g);this._input=a+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-b-1),this.offset-=b;var d=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),c.length-1&&(this.yylineno-=c.length-1);var e=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:c?(c.length===d.length?this.yylloc.first_column:0)+d[d.length-c.length].length-c[0].length:this.yylloc.first_column-b},this.options.ranges&&(this.yylloc.range=[e[0],e[0]+this.yyleng-b]),this.yyleng=this.yytext.length,this},more:function(){return this._more=!0,this},reject:function(){return this.options.backtrack_lexer?(this._backtrack=!0,this):this.parseError("Lexical error on line "+(this.yylineno+1)+". You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},less:function(a){this.unput(this.match.slice(a))},pastInput:function(){var a=this.matched.substr(0,this.matched.length-this.match.length);return(a.length>20?"...":"")+a.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var a=this.match;return a.length<20&&(a+=this._input.substr(0,20-a.length)),(a.substr(0,20)+(a.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var a=this.pastInput(),b=new Array(a.length+1).join("-");return a+this.upcomingInput()+"\n"+b+"^"},test_match:function(a,b){var c,d,e;if(this.options.backtrack_lexer&&(e={yylineno:this.yylineno,yylloc:{first_line:this.yylloc.first_line,last_line:this.last_line,first_column:this.yylloc.first_column,last_column:this.yylloc.last_column},yytext:this.yytext,match:this.match,matches:this.matches,matched:this.matched,yyleng:this.yyleng,offset:this.offset,_more:this._more,_input:this._input,yy:this.yy,conditionStack:this.conditionStack.slice(0),done:this.done},this.options.ranges&&(e.yylloc.range=this.yylloc.range.slice(0))),d=a[0].match(/(?:\r\n?|\n).*/g),d&&(this.yylineno+=d.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:d?d[d.length-1].length-d[d.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+a[0].length},this.yytext+=a[0],this.match+=a[0],this.matches=a,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._backtrack=!1,this._input=this._input.slice(a[0].length),this.matched+=a[0],c=this.performAction.call(this,this.yy,this,b,this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),c)return c;if(this._backtrack){for(var f in e)this[f]=e[f];return!1}return!1},next:function(){if(this.done)return this.EOF;this._input||(this.done=!0);var a,b,c,d;this._more||(this.yytext="",this.match="");for(var e=this._currentRules(),f=0;fb[0].length)){if(b=c,d=f,this.options.backtrack_lexer){if(a=this.test_match(c,e[f]),a!==!1)return a;if(this._backtrack){b=!1;continue}return!1}if(!this.options.flex)break}return b?(a=this.test_match(b,e[d]),a!==!1?a:!1):""===this._input?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+". Unrecognized text.\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){var a=this.next();return a?a:this.lex()},begin:function(a){this.conditionStack.push(a)},popState:function(){var a=this.conditionStack.length-1;return a>0?this.conditionStack.pop():this.conditionStack[0]},_currentRules:function(){return this.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]?this.conditions[this.conditionStack[this.conditionStack.length-1]].rules:this.conditions.INITIAL.rules},topState:function(a){return a=this.conditionStack.length-1-Math.abs(a||0),a>=0?this.conditionStack[a]:"INITIAL"},pushState:function(a){this.begin(a)},stateStackSize:function(){return this.conditionStack.length},options:{},performAction:function(a,b,c,d){switch(c){case 0:return 29;case 1:return 31;case 2:return"from";case 3:return 24;case 4:return 25;case 5:return 21;case 6:return 19;case 7:return 22;case 8:return 20;case 9:return 26;case 10:return 27;case 11:return 34;case 12:return 36;case 13:return 55;case 14:return 53;case 15:break;case 16:return 49;case 17:return 48;case 18:return 48;case 19:return 40;case 20:return 51;case 21:return 41;case 22:return 11;case 23:return 12;case 24:return 13;case 25:return 38;case 26:return 8;case 27:return 26;case 28:return 27;case 29:return 24;case 30:return 24;case 31:return 25;case 32:return 25;case 33:return 21;case 34:return 22;case 35:return 20;case 36:return 19;case 37:return 34;case 38:return 36;case 39:return 15;case 40:return 17;case 41:return 46;case 42:return 44;case 43:return 42;case 44:return 47;case 45:return 9;case 46:return 5}},rules:[/^(?:\s+in\b)/,/^(?:\s+notIn\b)/,/^(?:\s+from\b)/,/^(?:\s+(eq|EQ)\b)/,/^(?:\s+(neq|NEQ)\b)/,/^(?:\s+(lte|LTE)\b)/,/^(?:\s+(lt|LT)\b)/,/^(?:\s+(gte|GTE)\b)/,/^(?:\s+(gt|GT)\b)/,/^(?:\s+(like|LIKE)\b)/,/^(?:\s+(notLike|NOT_LIKE)\b)/,/^(?:\s+(and|AND)\b)/,/^(?:\s+(or|OR)\b)/,/^(?:\s+null\b)/,/^(?:\s+(true|false)\b)/,/^(?:\s+)/,/^(?:-?[0-9]+(?:\.[0-9]+)?\b)/,/^(?:'[^']*')/,/^(?:"[^"]*")/,/^(?:([a-zA-Z_$][0-9a-zA-Z_$]*))/,/^(?:^\/((?![\s=])[^[\/\n\\]*(?:(?:\\[\s\S]|\[[^\]\n\\]*(?:\\[\s\S][^\]\n\\]*)*])[^[\/\n\\]*)*\/[imgy]{0,4})(?!\w))/,/^(?:\.)/,/^(?:\*)/,/^(?:\/)/,/^(?:\%)/,/^(?:,)/,/^(?:-)/,/^(?:=~)/,/^(?:!=~)/,/^(?:==)/,/^(?:===)/,/^(?:!=)/,/^(?:!==)/,/^(?:<=)/,/^(?:>=)/,/^(?:>)/,/^(?:<)/,/^(?:&&)/,/^(?:\|\|)/,/^(?:\+)/,/^(?:\^)/,/^(?:\()/,/^(?:\])/,/^(?:\[)/,/^(?:\))/,/^(?:!)/,/^(?:$)/],conditions:{INITIAL:{rules:[0,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],inclusive:!0}}};return a}();return b.lexer=c,a.prototype=b,b.Parser=a,new a}();"undefined"!=typeof a&&"undefined"!=typeof c&&(c.parser=e,c.Parser=e.Parser,c.parse=function(){return e.parse.apply(e,arguments)},c.main=function(b){b[1]||(console.log("Usage: "+b[0]+" FILE"),d.exit(1));var e=a("fs").readFileSync(a("path").normalize(b[1]),"utf8");return c.parser.parse(e)},"undefined"!=typeof b&&a.main===b&&c.main(d.argv.slice(1)))},{__browserify_process:54,fs:51,path:52}],34:[function(a,b,c){!function(){"use strict";var b=a("./constraint/parser"),d=a("./nools/nool.parser");c.parseConstraint=function(a){try{return b.parse(a)}catch(c){throw new Error("Invalid expression '"+a+"'")}},c.parseRuleSet=function(a,b){return d.parse(a,b)}}()},{"./constraint/parser":33,"./nools/nool.parser":35}],35:[function(a,b,c){"use strict";var d=a("./tokens.js"),e=a("../../extended"),f=e.hash.keys,g=a("./util.js"),h=function(a,b,c){var d=a;a=a.replace(/\/\/(.*)/g,"").replace(/\n|\r|\r\n/g," ");for(var e,i=new RegExp("^("+f(b).join("|")+")");a&&-1!==(e=g.findNextTokenIndex(a));){a=a.substr(e);var j=a.match(i);if(null===j)throw new Error("Error parsing "+a);if(j=j[1],!(j in b))throw new Error("Unknown token"+j);try{a=b[j](a,c,h).replace(/^\s*|\s*$/g,"")}catch(k){throw new Error("Invalid "+j+" definition \n"+k.message+"; \nstarting at : "+d)}}};c.parse=function(a,b){var c={define:[],rules:[],scope:[],loaded:[],file:b};return h(a,d,c),c}},{"../../extended":12,"./tokens.js":36,"./util.js":37}],36:[function(require,module,exports){var process=require("__browserify_process"),utils=require("./util.js"),fs=require("fs"),extd=require("../../extended"),filter=extd.filter,indexOf=extd.indexOf,isWhiteSpace=function(a){return 0===a.replace(/[\s|\n|\r|\t]/g,"").length},joinFunc=function(a,b){return"; "+b},splitRuleLineByPredicateExpressions=function(a){var b=a.replace(/,\s*(\$?\w+\s*:)/g,joinFunc),c=filter(b.split(/ *(not|or) *\(/g),function(a){return""!==a}),d=c.length,e=[];if(!d)return b;for(var f=0;d>f;f++)"not"===c[f]||"or"===c[f]?e.push([c[f],"(",c[++f].replace(/, *$/,"")].join("")):e.push(c[f].replace(/, *$/,""));return e.join(";")},ruleTokens={salience:function(){var a=/^(salience|priority)\s*:\s*(-?\d+)\s*[,;]?/;return function(b,c){if(a.test(b)){var d=b.match(a),e=parseInt(d[2],10);if(isNaN(e))throw new Error("Invalid salience/priority "+d[2]);return c.options.priority=e,b.replace(d[0],"")}throw new Error("invalid format")}}(),agendaGroup:function(){var a=/^(agenda-group|agendaGroup)\s*:\s*([a-zA-Z_$][0-9a-zA-Z_$]*|"[^"]*"|'[^']*')\s*[,;]?/;return function(b,c){if(a.test(b)){var d=b.match(a),e=d[2];if(!e)throw new Error("Invalid agenda-group "+d[2]);return c.options.agendaGroup=e.replace(/^["']|["']$/g,""),b.replace(d[0],"")}throw new Error("invalid format")}}(),autoFocus:function(){var a=/^(auto-focus|autoFocus)\s*:\s*(true|false)\s*[,;]?/;return function(b,c){if(a.test(b)){var d=b.match(a),e=d[2];if(!e)throw new Error("Invalid auto-focus "+d[2]);return c.options.autoFocus="true"===e?!0:!1,b.replace(d[0],"")}throw new Error("invalid format")}}(),"agenda-group":function(){return this.agendaGroup.apply(this,arguments)},"auto-focus":function(){return this.autoFocus.apply(this,arguments)},priority:function(){return this.salience.apply(this,arguments)},when:function(){var ruleRegExp=/^(\$?\w+) *: *(\w+)(.*)/,constraintRegExp=/(\{ *(?:["']?\$?\w+["']?\s*:\s*["']?\$?\w+["']? *(?:, *["']?\$?\w+["']?\s*:\s*["']?\$?\w+["']?)*)+ *\})/,predicateExp=/^(not|or) *\((.*)\)$/m,fromRegExp=/(\bfrom\s+.*)/,parseRules=function(str){for(var rules=[],ruleLines=str.split(";"),l=ruleLines.length,ruleLine,i=0;l>i&&(ruleLine=ruleLines[i].replace(/^\s*|\s*$/g,"").replace(/\n/g,""));i++)if(!isWhiteSpace(ruleLine)){var rule=[];if(predicateExp.test(ruleLine)){var m=ruleLine.match(predicateExp),pred=m[1].replace(/^\s*|\s*$/g,"");if(rule.push(pred),ruleLine=m[2].replace(/^\s*|\s*$/g,""),"or"===pred){rule=rule.concat(parseRules(splitRuleLineByPredicateExpressions(ruleLine))),rules.push(rule);continue}}var parts=ruleLine.match(ruleRegExp);if(!parts||!parts.length)throw new Error("Invalid constraint "+ruleLine);rule.push(parts[2],parts[1]);var constraints=parts[3].replace(/^\s*|\s*$/g,""),hashParts=constraints.match(constraintRegExp),from=null,fromMatch;if(hashParts){var hash=hashParts[1],constraint=constraints.replace(hash,"");fromRegExp.test(constraint)&&(fromMatch=constraint.match(fromRegExp),from=fromMatch[0],constraint=constraint.replace(fromMatch[0],"")),constraint&&rule.push(constraint.replace(/^\s*|\s*$/g,"")),hash&&rule.push(eval("("+hash.replace(/(\$?\w+)\s*:\s*(\$?\w+)/g,'"$1" : "$2"')+")"))}else constraints&&!isWhiteSpace(constraints)&&(fromRegExp.test(constraints)&&(fromMatch=constraints.match(fromRegExp),from=fromMatch[0],constraints=constraints.replace(fromMatch[0],"")),rule.push(constraints));from&&rule.push(from),rules.push(rule)}return rules};return function(a,b){var c=a.replace(/^when\s*/,"").replace(/^\s*|\s*$/g,"");if("{"===utils.findNextToken(c)){var d=utils.getTokensBetween(c,"{","}",!0).join("");return c=c.replace(d,""),b.constraints=parseRules(d.replace(/^\{\s*|\}\s*$/g,"")),c}throw new Error("unexpected token : expected : '{' found : '"+utils.findNextToken(c)+"'")}}(),then:function(){return function(a,b){if(b.action)throw new Error("action already defined for rule"+b.name);var c=a.replace(/^then\s*/,"").replace(/^\s*|\s*$/g,"");if("{"===utils.findNextToken(c)){var d=utils.getTokensBetween(c,"{","}",!0).join("");if(c=c.replace(d,""),b.action||(b.action=d.replace(/^\{\s*|\}\s*$/g,"")),!isWhiteSpace(c))throw new Error("Error parsing then block "+a);return c}throw new Error("unexpected token : expected : '{' found : '"+utils.findNextToken(c)+"'")}}()},topLevelTokens={"/":function(a){return a.match(/^\/\*/)?a.replace(/\/\*.*?\*\//,""):a},define:function(a,b){var c=a.replace(/^define\s*/,""),d=c.match(/^([a-zA-Z_$][0-9a-zA-Z_$]*)/);if(d){if(c=c.replace(d[0],"").replace(/^\s*|\s*$/g,""),"{"===utils.findNextToken(c)){d=d[1];var e=utils.getTokensBetween(c,"{","}",!0).join("");return c=c.replace(e,""),b.define.push({name:d,properties:"("+e+")"}),c}throw new Error("unexpected token : expected : '{' found : '"+utils.findNextToken(c)+"'")}throw new Error("missing name")},"import":function(a,b,c){if("undefined"!=typeof window)throw new Error("import cannot be used in a browser");var d=a.replace(/^import\s*/,"");if("("===utils.findNextToken(d)){var e=utils.getParamList(d);if(d=d.replace(e,"").replace(/^\s*|\s*$/g,""),";"===utils.findNextToken(d)&&(d=d.replace(/\s*;/,"")),e=e.replace(/[\(|\)]/g,"").split(","),1===e.length){if(e=utils.resolve(b.file||process.cwd(),e[0].replace(/["|']/g,"")),-1===indexOf(b.loaded,e)){var f=b.file;b.file=e,c(fs.readFileSync(e,"utf8"),topLevelTokens,b),b.loaded.push(e),b.file=f}return d}throw new Error("import accepts a single file")}throw new Error("unexpected token : expected : '(' found : '"+utils.findNextToken(d)+"'")},global:function(a,b){var c=a.replace(/^global\s*/,""),d=c.match(/^([a-zA-Z_$][0-9a-zA-Z_$]*\s*)/);if(d){if(c=c.replace(d[0],"").replace(/^\s*|\s*$/g,""),"="===utils.findNextToken(c)){d=d[1].replace(/^\s+|\s+$/g,"");var e=utils.getTokensBetween(c,"=",";",!0).join(""),f=e.substring(1,e.length-1);if(f=f.replace(/^\s+|\s+$/g,""),/^require\(/.test(f)){var g=utils.getParamList(f.replace("require")).replace(/[\(|\)]/g,"").split(",");1===g.length&&(g=g[0].replace(/["|']/g,""),f=["require('",utils.resolve(b.file||process.cwd(),g),"')"].join(""))}return b.scope.push({name:d,body:f}),c=c.replace(e,"")}throw new Error("unexpected token : expected : '=' found : '"+utils.findNextToken(c)+"'")}throw new Error("missing name")},"function":function(a,b){var c=a.replace(/^function\s*/,""),d=c.match(/^([a-zA-Z_$][0-9a-zA-Z_$]*)\s*/);if(d){if(c=c.replace(d[0],""),"("===utils.findNextToken(c)){d=d[1];var e=utils.getParamList(c);if(c=c.replace(e,"").replace(/^\s*|\s*$/g,""),"{"===utils.findNextToken(c)){var f=utils.getTokensBetween(c,"{","}",!0).join("");return c=c.replace(f,""),b.scope.push({name:d,body:"function"+e+f}),c}throw new Error("unexpected token : expected : '{' found : '"+utils.findNextToken(c)+"'")}throw new Error("unexpected token : expected : '(' found : '"+utils.findNextToken(c)+"'")}throw new Error("missing name")},rule:function(a,b,c){var d=a.replace(/^rule\s*/,""),e=d.match(/^([a-zA-Z_$][0-9a-zA-Z_$]*|"[^"]*"|'[^']*')/);if(e){if(d=d.replace(e[0],"").replace(/^\s*|\s*$/g,""),"{"===utils.findNextToken(d)){e=e[1].replace(/^["']|["']$/g,"");var f={name:e,options:{},constraints:null,action:null},g=utils.getTokensBetween(d,"{","}",!0).join("");return d=d.replace(g,""),c(g.replace(/^\{\s*|\}\s*$/g,""),ruleTokens,f),b.rules.push(f),d}throw new Error("unexpected token : expected : '{' found : '"+utils.findNextToken(d)+"'")}throw new Error("missing name")}};module.exports=topLevelTokens},{"../../extended":12,"./util.js":37,__browserify_process:54,fs:51}],37:[function(a,b,c){var d=a("__browserify_process"),e=a("path"),f=/[\s|\n|\r|\t]/,g=e.sep||("win32"===d.platform?"\\":"/"),h={"{":"}","}":"{","(":")",")":"(","[":"]"},i=c.getTokensBetween=function(a,b,c,d){var e=0,f=[];b||(b=h[c],e=1),c||(c=h[b]),a=Object(a);for(var g,i=!1,j=0,k=!1;g=a.charAt(j++);)if(g===b)e++,i?f.push(g):(i=!0,d&&f.push(g));else if(g===c&&j){if(e--,0===e){d&&f.push(g),k=!0;break}f.push(g)}else i&&f.push(g);if(!k)throw new Error("Unable to match "+b+" in "+a);return f};c.getParamList=function(a){return i(a,"(",")",!0).join("")},c.resolve=function(a,b){return""!==e.extname(a)&&(a=e.dirname(a)),1===b.split(g).length?b:e.resolve(a,b)};var j=c.findNextTokenIndex=function(a,b,c){b=b||0,c=c||a.length;var d=-1,e=a.length;for((!c||c>e)&&(c=e);c>b;b++){var g=a.charAt(b);if(!f.test(g)){d=b;break}}return d};c.findNextToken=function(a,b,c){return a.charAt(j(a,b,c))}},{__browserify_process:54,path:52}],38:[function(a,b,c){"use strict";var d=a("./extended"),e=d.isEmpty,f=d.merge,g=d.forEach,h=d.declare,i=a("./constraintMatcher"),j=a("./constraint"),k=j.EqualityConstraint,l=j.FromConstraint,m=0,n=h({}),o=n.extend({instance:{constructor:function(a,b,c,d,h){h=h||{},this.id=m++,this.type=a,this.alias=b,this.conditions=c,this.pattern=h.pattern;var k=[new j.ObjectConstraint(a)],l=i.toConstraints(c,f({alias:b},h));if(l.length)k=k.concat(l);else{var n=new j.TrueConstraint;k.push(n)}if(d&&!e(d)){var o=new j.HashConstraint(d);k.push(o)}g(k,function(a){a.set("alias",b)}),this.constraints=k},getSpecificity:function(){for(var a=this.constraints,b=0,c=0,d=a.length;d>c;c++)a[c]instanceof k&&b++;return b},hasConstraint:function(a){return d.some(this.constraints,function(b){return b instanceof a})},hashCode:function(){return[this.type,this.alias,d.format("%j",this.conditions)].join(":")},toString:function(){return d.format("%j",this.constraints)}}}).as(c,"ObjectPattern"),p=o.extend({instance:{constructor:function(a,b,c,d,e,f){this._super([a,b,c,d,f]),this.from=new l(e,f)},hasConstraint:function(a){return d.some(this.constraints,function(b){return b instanceof a})},getSpecificity:function(){return this._super(arguments)+1},hashCode:function(){return[this.type,this.alias,d.format("%j",this.conditions),this.from.from].join(":")},toString:function(){return d.format("%j from %s",this.constraints,this.from.from)}}}).as(c,"FromPattern");p.extend().as(c,"FromNotPattern"),o.extend().as(c,"NotPattern"),n.extend({instance:{constructor:function(a,b){this.id=m++,this.leftPattern=a,this.rightPattern=b},hashCode:function(){return[this.leftPattern.hashCode(),this.rightPattern.hashCode()].join(":")},getSpecificity:function(){return this.rightPattern.getSpecificity()+this.leftPattern.getSpecificity()},getters:{constraints:function(){return this.leftPattern.constraints.concat(this.rightPattern.constraints)}}}}).as(c,"CompositePattern");var q=h({instance:{constructor:function(){this.id=m++,this.recency=0}}}).as(c,"InitialFact");o.extend({instance:{constructor:function(){this._super([q,"i",[],{}])},assert:function(){return!0}}}).as(c,"InitialFactPattern")},{"./constraint":8,"./constraintMatcher":9,"./extended":12}],39:[function(a,b,c){"use strict";function d(a,b,c,d){f(b)?(d=c,c=b):b=b||{};var g=e.every(c,function(a){return f(a)});g&&1===c.length&&(c=c[0],g=!1);var h=[],i=b.scope||{};if(c.scope=i,g){for(var j,k=function(a,b){m[b]?e(m).forEach(function(b){b.push(a)}):(m[b]=0===b?[]:m[b-1].slice(),0!==b&&m[b].pop(),m[b].push(a))},l=c.length,m=[],n=0;l>n;n++)j=c[n],j.scope=i,e.forEach(w(j),k);h=e.map(m,function(c){for(var e=null,f=0;f>>0;if(0===d)return-1;var e=d;arguments.length>2&&(e=Number(arguments[2]),e!==e?e=0:0!==e&&e!==1/0&&e!==-(1/0)&&(e=(e>0||-1)*P(Q(e))));for(var f=e>=0?R(e,d-1):d-Q(e);f>=0;f--)if(f in c&&c[f]===b)return f;return-1}function i(a,b,c){if(a&&X&&X===a.filter)return a.filter(b,c);if(!N(a)||"function"!=typeof b)throw new TypeError;for(var d=Object(a),e=d.length>>>0,f=[],g=0;e>g;g++)if(g in d){var h=d[g];b.call(c,h,g,d)&&f.push(h)}return f}function j(a,b,c){if(!N(a)||"function"!=typeof b)throw new TypeError;if(a&&T&&T===a.forEach)return a.forEach(b,c),a;for(var d=0,e=a.length;e>d;++d)b.call(c||a,a[d],d,a);return a}function k(a,b,c){if(a&&Y&&Y===a.every)return a.every(b,c);if(!N(a)||"function"!=typeof b)throw new TypeError;for(var d=Object(a),e=d.length>>>0,f=0;e>f;f++)if(f in d&&!b.call(c,d[f],f,d))return!1;return!0}function l(a,b,c){if(a&&Z&&Z===a.some)return a.some(b,c);if(!N(a)||"function"!=typeof b)throw new TypeError;for(var d=Object(a),e=d.length>>>0,f=0;e>f;f++)if(f in d&&b.call(c,d[f],f,d))return!0;return!1}function m(a,b,c){if(a&&U&&U===a.map)return a.map(b,c);if(!N(a)||"function"!=typeof b)throw new TypeError;for(var d=Object(a),e=d.length>>>0,f=[],g=0;e>g;g++)g in d&&f.push(b.call(c,d[g],g,d));return f}function n(a,b,c){var d=arguments.length>2;if(a&&V&&V===a.reduce)return d?a.reduce(b,c):a.reduce(b);if(!N(a)||"function"!=typeof b)throw new TypeError;var e=0,f=a.length>>0;if(arguments.length<3){if(0===f)throw new TypeError("Array length is 0 and no second argument");c=a[0],e=1}else c=arguments[2];for(;f>e;)e in a&&(c=b.call(void 0,c,a[e],e,a)),++e;return c}function o(a,b,c){var d=arguments.length>2;if(a&&W&&W===a.reduceRight)return d?a.reduceRight(b,c):a.reduceRight(b);if(!N(a)||"function"!=typeof b)throw new TypeError;var e=Object(a),f=e.length>>>0;if(0===f&&2===arguments.length)throw new TypeError;var g=f-1;if(arguments.length>=3)c=arguments[2];else for(;;)if(g in a){c=a[g--];break}for(;g>=0;)g in e&&(c=b.call(void 0,c,e[g],g,e)),g--;return c}function p(a){var c=[];if(null!==a){var d=$(arguments);if(1===d.length)if(N(a))c=a;else if(b.isHash(a))for(var e in a)a.hasOwnProperty(e)&&c.push([e,a[e]]);else c.push(a);else j(d,function(a){c=c.concat(p(a))})}return c}function q(a){return a=a||[],a.length?n(a,function(a,b){return a+b}):0}function r(a){if(a=a||[],a.length){var c=q(a);if(b.isNumber(c))return c/a.length;throw new Error("Cannot average an array of non numbers.")}return 0}function s(a,b){return _(a,b)}function t(a,b){return _(a,b)[0]}function u(a,b){return _(a,b)[a.length-1]}function v(a){var b=a,c=J($(arguments,1));return N(a)&&(b=i(a,function(a){return-1===g(c,a)})),b}function w(a){var b,c=[],d=-1,e=0;if(a)for(b=a.length;++d0?(c.push(c.shift()),b--):(c.unshift(c.pop()),b++),y(c,b)):c}function z(a,b){var c=[];if(N(a)){var d=a.slice(0);"number"!=typeof b&&(b=a.length),b?b<=a.length&&(c=n(a,function(a,c,f){var g;return g=b>1?e(c,y(d,f).slice(1),b):[[c]],a.concat(g)},[])):c=[[]]}return c}function A(){var a=[],c=$(arguments);if(c.length>1){var d=c.shift();N(d)&&(a=n(d,function(a,d,e){for(var f=[d],g=0;gd;d++)c.push(a[b[d]]||null);return c}function D(){var a=[],b=$(arguments);if(b.length>1){for(var c=0,d=b.length;d>c;c++)a=a.concat(b[c]);a=w(a)}return a}function E(){var a,b,c=[],d=-1;if(a=arguments.length>1?$(arguments):arguments[0],N(a))for(c=a[0],d=0,b=a.length;++d1?c:p(a),n(b,function(a,b){return a.concat(b)},[])}function K(a,b){b=b.split(".");var c=a.slice(0);return j(b,function(a){var b=a.match(/(\w+)\(\)$/);c=m(c,function(c){return b?c[b[1]]():c[a]})}),c}function L(a,b,c){return c=$(arguments,2),m(a,function(a){var d=M(b)?a[b]:b;return d.apply(a,c)})}var M=b.isString,N=Array.isArray||b.isArray,O=b.isDate,P=Math.floor,Q=Math.abs,R=(Math.max,Math.min),S=Array.prototype,T=(S.indexOf,S.forEach),U=S.map,V=S.reduce,W=S.reduceRight,X=S.filter,Y=S.every,Z=S.some,$=c.argsToArray,_=function(){var a=function(a,b){return k(a,b)},b=function(a,b){return a-b},c=function(a,b){return a.getTime()-b.getTime()};return function(d,e){var f=[];return N(d)&&(f=d.slice(),e?"function"==typeof e?f.sort(e):f.sort(function(a,b){var c=a[e],d=b[e];return M(c)&&M(d)?c>d?1:d>c?-1:0:O(c)&&O(d)?c.getTime()-d.getTime():c-d}):a(f,M)?f.sort():a(f,O)?f.sort(c):f.sort(b)),f}}(),ab={toArray:p,sum:q,avg:r,sort:s,min:t,max:u,difference:v,removeDuplicates:w,unique:x,rotate:y,permutations:z,zip:A,transpose:B,valuesAt:C,union:D,intersect:E,powerSet:F,cartesian:G,compact:H,multiply:I,flatten:J,pluck:K,invoke:L,forEach:j,map:m,filter:i,reduce:n,reduceRight:o,some:l,every:k,indexOf:g,lastIndexOf:h};return a.define(N,ab).expose(ab)}"undefined"!=typeof c?"undefined"!=typeof b&&b.exports&&(b.exports=d(a("extended"),a("is-extended"),a("arguments-extended"))):"function"==typeof define&&define.amd?define(["extended","is-extended","arguments-extended"],function(a,b,c){return d(a,b,c) -}):this.arrayExtended=d(this.extended,this.isExtended,this.argumentsExtended)}.call(this)},{"arguments-extended":41,extended:46,"is-extended":56}],43:[function(a,b,c){!function(){"use strict";function d(a,b,c){function d(a,b,c,d){a=""+a,c=c||" ";for(var e=a.length;b>e;)d?a+=c:a=c+a,e++;return a}function e(a,c,d){var f=a;if(b.isString(f)){if(a.length>c)if(d){var g=a.length;f=a.substring(g-c,g)}else f=a.substring(0,c)}else f=e(""+f,c);return f}function f(a,c,d){if(!b.isArray(a)||"function"!=typeof c)throw new TypeError;for(var e=Object(a),f=e.length>>>0,g=0;f>g;g++)if(g in e&&!c.call(d,e[g],g,e))return!1;return!0}function g(a,b){return A.difference(new Date(a.getFullYear(),0,1,a.getHours()),a,null,b)+1}function h(a,b,c){b=b||0;var d=a[c?"getUTCFullYear":"getFullYear"](),e=new Date(d,0,1).getDay(),f=(e-b+7)%7,h=o((g(a)+f-1)/7);return e===b&&h++,h}function i(a){var b=a.toString(),c="",d=b.indexOf("(");return d>-1&&(c=b.substring(++d,b.indexOf(")"))),c}function j(a,b){return a.replace(/([a-z])\1*/gi,function(a){var c,d=a.charAt(0),e=a.length,f="0?",g="0{0,2}";if("y"===d)c="\\d{2,4}";else if("M"===d)c=e>2?"\\S+?":"1[0-2]|"+f+"[1-9]";else if("D"===d)c="[12][0-9][0-9]|3[0-5][0-9]|36[0-6]|"+g+"[1-9][0-9]|"+f+"[1-9]";else if("d"===d)c="3[01]|[12]\\d|"+f+"[1-9]";else if("w"===d)c="[1-4][0-9]|5[0-3]|"+f+"[1-9]";else if("E"===d)c="\\S+";else if("h"===d)c="1[0-2]|"+f+"[1-9]";else if("K"===d)c="1[01]|"+f+"\\d";else if("H"===d)c="1\\d|2[0-3]|"+f+"\\d";else if("k"===d)c="1\\d|2[0-4]|"+f+"[1-9]";else if("m"===d||"s"===d)c="[0-5]\\d";else if("S"===d)c="\\d{"+e+"}";else if("a"===d){var h="AM",i="PM";c=h+"|"+i,h!==h.toLowerCase()&&(c+="|"+h.toLowerCase()),i!==i.toLowerCase()&&(c+="|"+i.toLowerCase()),c=c.replace(/\./g,"\\.")}else c="v"===d||"z"===d||"Z"===d||"G"===d||"q"===d||"Q"===d?".*":" "===d?"\\s*":d+"*";return b&&b.push(a),"("+c+")"}).replace(/[\xa0 ]/g,"[\\s\\xa0]")}function k(a){B[a+"sFromNow"]=function(b){return A.add(new Date,a,b)},B[a+"sAgo"]=function(b){return A.add(new Date,a,-b)}}for(var l=function(){function a(a,b,c){return a=a.replace(/s$/,""),e.hasOwnProperty(a)?e[a](b,c):[c,"UTC"+a.charAt(0).toUpperCase()+a.substring(1)+"s",!1]}function b(a,b,c,e){return a=a.replace(/s$/,""),d(f[a](b,c,e))}var c=Math.floor,d=Math.round,e={day:function(a,b){return[b,"Date",!1]},weekday:function(a,b){var c,d,e=b%5,f=a.getDay(),g=0;e?(c=e,d=parseInt(b/5,10)):(c=b>0?5:-5,d=b>0?(b-5)/5:(b+5)/5),6===f&&b>0?g=1:0===f&&0>b&&(g=-1);var h=f+c;return(0===h||6===h)&&(g=b>0?2:-2),[7*d+c+g,"Date",!1]},year:function(a,b){return[b,"FullYear",!0]},week:function(a,b){return[7*b,"Date",!1]},quarter:function(a,b){return[3*b,"Month",!0]},month:function(a,b){return[b,"Month",!0]}},f={quarter:function(a,b,d){var e=b.getFullYear()-a.getFullYear(),f=a[d?"getUTCMonth":"getMonth"](),g=b[d?"getUTCMonth":"getMonth"](),h=c(f/3)+1,i=c(g/3)+1;return i+=4*e,i-h},weekday:function(a,c,d){var e,f=b("day",a,c,d),g=f%7;if(0===g)f=5*b("week",a,c,d);else{var h=0,i=a[d?"getUTCDay":"getDay"](),j=c[d?"getUTCDay":"getDay"]();e=parseInt(f/7,10);var k=new Date(+a);k.setDate(k[d?"getUTCDate":"getDate"]()+7*e);var l=k[d?"getUTCDay":"getDay"]();f>0?6===i||6===j?h=-1:0===i?h=0:(0===j||l+g>5)&&(h=-2):0>f&&(6===i?h=0:0===i||0===j?h=1:(6===j||0>l+g)&&(h=2)),f+=h,f-=2*e}return f},year:function(a,b){return b.getFullYear()-a.getFullYear()},month:function(a,b,c){var d=a[c?"getUTCMonth":"getMonth"](),e=b[c?"getUTCMonth":"getMonth"]();return e-d+12*(b.getFullYear()-a.getFullYear())},week:function(a,c,e){return d(b("day",a,c,e)/7)},day:function(a,b){return 1.1574074074074074e-8*(b.getTime()-a.getTime())},hour:function(a,b){return 2.7777777777777776e-7*(b.getTime()-a.getTime())},minute:function(a,b){return 16666666666666667e-21*(b.getTime()-a.getTime())},second:function(a,b){return.001*(b.getTime()-a.getTime())},millisecond:function(a,b){return b.getTime()-a.getTime()}};return{addTransform:a,differenceTransform:b}}(),m=l.addTransform,n=l.differenceTransform,o=Math.floor,p=Math.round,q=Math.min,r=Math.pow,s=Math.ceil,t=Math.abs,u=["January","February","March","April","May","June","July","August","September","October","November","December"],v=["Jan.","Feb.","Mar.","Apr.","May.","Jun.","Jul.","Aug.","Sep.","Oct.","Nov.","Dec."],w=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],x=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],y=["Before Christ","Anno Domini"],z=["BC","AD"],A={getDaysInMonth:function(a){var b=a.getMonth(),c=[31,28,31,30,31,30,31,31,30,31,30,31];return 1===b&&A.isLeapYear(a)?29:c[b]},isLeapYear:function(a,b){var c=a[b?"getUTCFullYear":"getFullYear"]();return 0===c%400||0===c%4&&0!==c%100},isWeekend:function(a,b){var c=(a||new Date)[b?"getUTCDay":"getDay"]();return 0===c||6===c},getTimezoneName:i,compare:function(a,b,c){return a=new Date(+a),b=new Date(+(b||new Date)),"date"===c?(a.setHours(0,0,0,0),b.setHours(0,0,0,0)):"time"===c&&(a.setFullYear(0,0,0),b.setFullYear(0,0,0)),a>b?1:b>a?-1:0},add:function(a,b,c){var d=m(b,a,c||0);c=d[0];var e=d[1],f=new Date(+a),g=d[2];return e&&f["set"+e](f["get"+e]()+c),g&&f.getDate()E?z:y)[0>f?0:1];else if("y"===D)B=f,E>1&&(2===E?B=e(""+B,2,!0):C=!0);else if("Q"===D.toUpperCase())B=s((j+1)/3),C=!0;else if("M"===D)3>E?(B=j+1,C=!0):B=(3===E?v:u)[j];else if("w"===D)B=h(a,0,c),C=!0;else if("D"===D)B=g(a,c),C=!0;else if("E"===D)3>E?(B=k+1,C=!0):B=(-3===E?x:w)[k];else if("a"===D)B=12>m?"AM":"PM";else if("h"===D)B=m%12||12,C=!0;else if("K"===D)B=m%12,C=!0;else if("k"===D)B=m||24,C=!0;else if("S"===D)B=p(A*r(10,E-3)),C=!0;else if("z"===D||"v"===D||"Z"===D){if(B=i(a),"z"!==D&&"v"!==D||B||(E=4),!B||"Z"===D){var F=a.getTimezoneOffset(),G=[F>=0?"-":"+",d(o(t(F)/60),2,"0"),d(t(F)%60,2,"0")];4===E&&(G.splice(0,0,"GMT"),G.splice(3,0,":")),B=G.join("")}}else B=b;else B=""+n,C=!0;else B=""+m,C=!0;return C&&(B=d(B,E,"0")),B})}},B={},C=["year","month","day","hour","minute","second"],D=0,E=C.length;E>D;D++)k(C[D]);var F={parseDate:function(a,b){if(!b)throw new Error("format required when calling dateExtender.parse");var d=[],e=j(b,d),g=new RegExp("^"+e+"$","i"),h=g.exec(a);if(!h)return null;var i=[1970,0,1,0,0,0,0],k="",l=f(h,function(a,b){if(b){var e=d[b-1],f=e.length,g=e.charAt(0);if("y"===g)if(100>a){a=parseInt(a,10);var h=""+(new Date).getFullYear(),j=100*h.substring(0,2),l=q(h.substring(2,4)+20,99);i[0]=l>a?j+a:j-100+a}else i[0]=a;else if("M"===g){if(f>2){var m,n,o=u;3===f&&(o=v),a=a.replace(".","").toLowerCase();var p=!1;for(m=0,n=o.length;n>m&&!p;m++){var r=o[m].replace(".","").toLocaleLowerCase();r===a&&(a=m,p=!0)}if(!p)return!1}else a--;i[1]=a}else if("E"===g||"e"===g){var s=w;3===f&&(s=x),a=a.toLowerCase(),s=c.map(s,function(a){return a.toLowerCase()});var t=c.indexOf(s,a);if(-1===t){if(a=parseInt(a,10),isNaN(a)||a>s.length)return!1}else a=t}else if("D"===g||"d"===g)"D"===g&&(i[1]=0),i[2]=a;else if("a"===g){var y="am",z="pm",A=/\./g;a=a.replace(A,"").toLowerCase(),k=a===z?"p":a===y?"a":""}else"k"===g||"h"===g||"H"===g||"K"===g?("k"===g&&24===+a&&(a=0),i[3]=a):"m"===g?i[4]=a:"s"===g?i[5]=a:"S"===g&&(i[6]=a)}return!0});if(l){var m=+i[3];"p"===k&&12>m?i[3]=m+12:"a"===k&&12===m&&(i[3]=0);var n=new Date(i[0],i[1],i[2],i[3],i[4],i[5],i[6]),o=-1!==c.indexOf(d,"d"),p=-1!==c.indexOf(d,"M"),r=i[1],s=i[2],t=n.getMonth(),y=n.getDate();return p&&t>r||o&&y>s?null:n}return null}},G=a.define(b.isDate,A).define(b.isString,F).define(b.isNumber,B);for(D in A)A.hasOwnProperty(D)&&(G[D]=A[D]);for(D in F)F.hasOwnProperty(D)&&(G[D]=F[D]);for(D in B)B.hasOwnProperty(D)&&(G[D]=B[D]);return G}"undefined"!=typeof c?"undefined"!=typeof b&&b.exports&&(b.exports=d(a("extended"),a("is-extended"),a("array-extended"))):"function"==typeof define&&define.amd?define(["extended","is-extended","array-extended"],function(a,b,c){return d(a,b,c)}):this.dateExtended=d(this.extended,this.isExtended,this.arrayExtended)}.call(this)},{"array-extended":42,extended:46,"is-extended":56}],44:[function(a,b,c){!function(){function a(){function a(a,b){return b=b||0,x.call(a,b)}function b(a){return"[object Array]"===Object.prototype.toString.call(a)}function c(a){var b;return null!==a&&a!==b&&"object"==typeof a}function d(a){var b=c(a);return b&&a.constructor===Object}function e(a,b){if(a&&a.length)for(var c=0,d=a.length;d>c;c++)if(a[c]===b)return c;return-1}function f(a,b,c){var d,f;for(d in b)b.hasOwnProperty(d)&&-1===e(c,d)&&(f=b[d],d in a&&a[d]===f||(a[d]=f));return a}function g(a){var c=this.__meta,d=c.supers,e=d.length,f=c.superMeta,g=f.pos;if(e>g){a=a?B(a)||b(a)?a:[a]:[];var h,i=f.name,j=f.f;do if(h=d[g][i],"function"==typeof h&&(h=h._f||h)!==j)return f.pos=1+g,h.apply(this,a);while(e>++g)}return null}function h(){var a=this.__meta,b=a.supers,c=b.length,d=a.superMeta,e=d.pos;if(c>e){var f,g=d.name,h=d.f;do if(f=b[e][g],"function"==typeof f&&(f=f._f||f)!==h)return d.pos=1+e,f.bind(this);while(c>++e)}return null}function i(a){var b=this.__getters__;return b.hasOwnProperty(a)?b[a].apply(this):this[a]}function j(b,c){var e=this.__setters__;if(!d(b))return e.hasOwnProperty(b)?e[b].apply(this,a(arguments,1)):this[b]=c;for(var f in b){var g=b[f];e.hasOwnProperty(f)?e[b].call(this,g):this[f]=g}}function k(){var a=this.__meta||{},b=a.supers,c=b.length,d=a.superMeta,e=d.pos;if(c>e){var f,g=d.name,h=d.f;do if(f=b[e][g],"function"==typeof f&&(f=f._f||f)!==h)return d.pos=1+e,f.apply(this,arguments);while(c>++e)}return null}function l(a,b){if(a.toString().match(A)){var c=function(){var c,d=this.__meta||{},e=d.superMeta;switch(d.superMeta={f:a,pos:0,name:b},arguments.length){case 0:c=a.call(this);break;case 1:c=a.call(this,arguments[0]);break;case 2:c=a.call(this,arguments[0],arguments[1]);break;case 3:c=a.call(this,arguments[0],arguments[1],arguments[2]);break;default:c=a.apply(this,arguments)}return d.superMeta=e,c};return c._f=a,c}return a._f=a,a}function m(a,b){var c=b.setters||{},d=a.__setters__,e=a.__getters__;for(var f in c)d.hasOwnProperty(f)||(d[f]=c[f]);c=b.getters||{};for(f in c)e.hasOwnProperty(f)||(e[f]=c[f]);for(var g in b)if("getters"!==g&&"setters"!==g){var h=b[g];"function"==typeof h?a.hasOwnProperty(g)||(a[g]=l(k,g)):a[g]=h}}function n(){for(var b=a(arguments),c=b.length,d=this.prototype,e=d.__meta,f=this.__meta,g=d.__meta.bases,h=g.slice(),i=f.supers||[],j=e.supers||[],k=0;c>k;k++){var l=b[k],n=l.prototype,p=n.__meta,q=l.__meta;!p&&(p=n.__meta={proto:n||{}}),!q&&(q=l.__meta={proto:l.__proto__||{}}),m(d,p.proto||{}),m(this,q.proto||{}),o(l.prototype,j,g),o(l,i,h)}return this}function o(a,b,c){var d=a.__meta;!d&&(d=a.__meta={});var f=a.__meta.unique;if(!f&&(d.unique="declare"+ ++y),-1===e(c,f)){c.push(f);for(var g=a.__meta.supers||[],h=g.length-1||0;h>=0;)o(g[h--],b,c);b.unshift(a)}}function p(a,b){var c=b.setters,d=a.__setters__,e=a.__getters__;if(c)for(var f in c)d[f]=c[f];if(c=b.getters||{})for(f in c)e[f]=c[f];for(f in b)if("getters"!=f&&"setters"!=f){var g=b[f];if("function"==typeof g){var h=g.__meta||{};a[f]=h.isConstructor?g:l(g,f)}else a[f]=g}}function q(a,b){return a&&b?a[b]=this:a.exports=a=this,this}function r(a){return u(this,a)}function s(a){z.prototype=a.prototype;var b=new z;return z.prototype=null,b}function t(a,c,e){var i={},j=[],m="declare"+ ++y,q=[],r=[],t=[],u=[],v={supers:t,unique:m,bases:q,superMeta:{f:null,pos:0,name:null}},x={supers:u,unique:m,bases:r,isConstructor:!0,superMeta:{f:null,pos:0,name:null}};if(d(c)&&!e&&(e=c,c=w),"function"==typeof c||b(c)?(j=b(c)?c:[c],c=j.shift(),a.__meta=x,i=s(c),i.__meta=v,i.__getters__=f({},i.__getters__||{}),i.__setters__=f({},i.__setters__||{}),a.__getters__=f({},a.__getters__||{}),a.__setters__=f({},a.__setters__||{}),o(c.prototype,t,q),o(c,u,r)):(a.__meta=x,i.__meta=v,i.__getters__=i.__getters__||{},i.__setters__=i.__setters__||{},a.__getters__=a.__getters__||{},a.__setters__=a.__setters__||{}),a.prototype=i,e){var z=v.proto=e.instance||{},A=x.proto=e.static||{};A.init=A.init||k,p(i,z),p(a,A),i.constructor=z.hasOwnProperty("constructor")?l(z.constructor,"constructor"):z.constructor=l(k,"constructor")}else v.proto={},x.proto={},a.init=l(k,"init"),i.constructor=l(k,"constructor");j.length&&n.apply(a,j),c&&f(a,f(f({},c),a)),i._super=a._super=g,i._getSuper=a._getSuper=h,i._static=a}function u(a,b){function c(){switch(arguments.length){case 0:this.constructor.call(this);break;case 1:this.constructor.call(this,arguments[0]);break;case 2:this.constructor.call(this,arguments[0],arguments[1]);break;case 3:this.constructor.call(this,arguments[0],arguments[1],arguments[2]);break;default:this.constructor.apply(this,arguments)}}return t(c,a,b),c.init()||c}function v(a,b){function c(){return d||(this.constructor.apply(this,arguments),d=this),d}var d;return t(c,a,b),c.init()||c}var w,x=Array.prototype.slice,y=0,z=new Function,A=/(super)/g,B=function(a){return"[object Arguments]"===Object.prototype.toString.call(a)};return B(arguments)||(B=function(a){return!(!a||!a.hasOwnProperty("callee"))}),w=u({instance:{get:i,set:j},"static":{get:i,set:j,mixin:n,extend:r,as:q}}),u.singleton=v,u}"undefined"!=typeof c?"undefined"!=typeof b&&b.exports&&(b.exports=a()):"function"==typeof define&&define.amd?define(a):this.declare=a()}()},{}],45:[function(a,b){b.exports=a("./declare.js")},{"./declare.js":44}],46:[function(a,b,c){!function(){"use strict";function d(a){function b(){var b=a.define();return b.expose({register:function(a,c){c||(c=a,a=null);var d=typeof c;if(a)b[a]=c;else if(c&&"function"===d)b.extend(c);else{if("object"!==d)throw new TypeError("extended.register must be called with an extender function");b.expose(c)}return b},define:function(){return a.define.apply(a,arguments)}}),b}function c(){return b()}return function(){function a(a,b){var c,d;for(c in b)b.hasOwnProperty(c)&&(d=b[c],c in a&&a[c]===d||(a[c]=d));return a}return function(b){b||(b={});for(var c=1,d=arguments.length;d>c;c++)a(b,arguments[c]);return b}}(),c.define=function(){return a.define.apply(a,arguments)},c}"undefined"!=typeof c?"undefined"!=typeof b&&b.exports&&(b.exports=d(a("extender"))):"function"==typeof define&&define.amd?define(["extender"],function(a){return d(a)}):this.extended=d(this.extender)}.call(this)},{extender:48}],47:[function(a,b,c){!function(){function d(a){function b(a,b){if(a&&a.length)for(var c=0,d=a.length;d>c;c++)if(a[c]===b)return c;return-1}function c(a){return"[object Array]"===Object.prototype.toString.call(a)}function d(b){function c(a,b,c){if("function"!=typeof c)throw new TypeError("when extending type you must provide a function");var d;d="constructor"===b?function(){this._super(arguments),c.apply(this,arguments)}:function(){var a=f.call(arguments);a.unshift(this._value);var b=c.apply(this,a);return b!==e?this.__extender__(b):this},a[b]=d}function d(a,b,c){if("function"!=typeof c)throw new TypeError("when extending type you must provide a function");var d;d="constructor"===b?function(){this._super(arguments),c.apply(this,arguments)}:function(){var a=f.call(arguments);return a.unshift(this._value),c.apply(this,a)},a[b]=d}function h(a,b,e){for(var f in b)b.hasOwnProperty(f)&&("getters"!==f&&"setters"!==f?"noWrap"===f?h(a,b[f],!0):e?d(a,f,b[f]):c(a,f,b[f]):a[f]=b[f])}function i(a){var b,c,d=a;if(!(a instanceof m)){var e=m;for(b=0,c=n.length;c>b;b++){var f=n[b];f[0](a)&&(e=e.extend({instance:f[1]}))}d=new e(a),d.__extender__=i}return d}function j(){return!0}function k(a,b){if(arguments.length){"object"==typeof a&&(b=a,a=j),b=b||{};var d={};h(d,b),d.hasOwnProperty("constructor")||(b.hasOwnProperty("constructor")?c(d,"constructor",b.constructor):d.constructor=function(){this._super(arguments)}),n.push([a,d])}return i}function l(a){return a&&a.hasOwnProperty("__defined__")&&(i.__defined__=n=n.concat(a.__defined__)),g(i,a,["define","extend","expose","__defined__"]),i}b=b||[];var m=a({instance:{constructor:function(a){this._value=a},value:function(){return this._value},eq:function(a){return this.__extender__(this._value===a)},neq:function(a){return this.__extender__(this._value!==a)},print:function(){return console.log(this._value),this}}}),n=[];return i.define=k,i.extend=l,i.expose=function(){for(var a,b=0,c=arguments.length;c>b;b++)a=arguments[b],"object"==typeof a&&g(i,a,["define","extend","expose","__defined__"]);return i},i.__defined__=n,i}var e,f=Array.prototype.slice,g=function(){function a(a,c,d){var e,f;for(e in c)c.hasOwnProperty(e)&&-1===b(d,e)&&(f=c[e],e in a&&a[e]===f||(a[e]=f));return a}return function(b){b||(b={});var d=arguments.length,e=arguments[arguments.length-1];c(e)?d--:e=[];for(var f=1;d>f;f++)a(b,arguments[f],e);return b}}();return{define:function(){return d().define.apply(d,arguments)},extend:function(a){return d().define().extend(a)}}}"undefined"!=typeof c?"undefined"!=typeof b&&b.exports&&(b.exports=d(a("declare.js"))):"function"==typeof define&&define.amd?define(["declare"],function(a){return d(a)}):this.extender=d(this.declare)}.call(this)},{"declare.js":45}],48:[function(a,b){b.exports=a("./extender.js")},{"./extender.js":47}],49:[function(a,b,c){!function(){"use strict";function d(a,b,c){function d(a,b,c){if(c=o(arguments,2),m(b)&&!(b in a))throw new Error(b+" property not defined in scope");if(!m(b)&&!n(b))throw new Error(b+" is not a function");return m(b)?function(){var d=a[b];if(n(d)){var e=c.concat(o(arguments));return d.apply(a,e)}return d}:c.length?function(){var d=c.concat(o(arguments));return b.apply(a,d)}:function(){return b.apply(a,arguments)}}function e(a,b){if(b=o(arguments,1),!m(a)&&!n(a))throw new Error(a+" must be the name of a property or function to execute");return m(a)?function(){var c=o(arguments),d=c.shift(),e=d[a];return n(e)?(c=b.concat(c),e.apply(d,c)):e}:function(){var c=o(arguments),d=c.shift();return c=b.concat(c),a.apply(d,c)}}function f(a,b,c){if(c=o(arguments,2),m(b)&&!(b in a))throw new Error(b+" property not defined in scope");if(!m(b)&&!n(b))throw new Error(b+" is not a function");return m(b)?function(){var d=a[b];return n(d)?d.apply(a,c):d}:function(){return b.apply(a,c)}}function g(a){var b=o(arguments,1);if(!l(a)&&!n(a))throw new TypeError("scope must be an object");if(1===b.length&&k(b[0])&&(b=b[0]),!b.length){b=[];for(var c in a)a.hasOwnProperty(c)&&n(a[c])&&b.push(c)}for(var e=0,f=b.length;f>e;e++)a[b[e]]=d(a,a[b[e]]);return a}function h(a,b){if(b=o(arguments,1),!m(a)&&!n(a))throw new Error(a+" must be the name of a property or function to execute");return m(a)?function(){var c=this[a];if(n(c)){var d=b.concat(o(arguments));return c.apply(this,d)}return c}:function(){var c=b.concat(o(arguments));return a.apply(this,c)}}function i(a,b){return function(){var c=o(arguments);return b?a.apply(this,arguments):function(){return a.apply(this,c.concat(o(arguments)))}}}function j(a,b,c){var e;if(e=c?d(c,b):b,a)for(var f=a-1,g=f;g>=0;g--)e=i(e,g===f);return e}var k=b.isArray,l=b.isObject,m=b.isString,n=b.isFunction,o=c.argsToArray;return a.define(l,{bind:d,bindAll:g,bindIgnore:f,curry:function(a,b,c){return j(b,c,a)}}).define(n,{bind:function(a,b){return d.apply(this,[b,a].concat(o(arguments,2)))},bindIgnore:function(a,b){return f.apply(this,[b,a].concat(o(arguments,2)))},partial:h,applyFirst:e,curry:function(a,b,c){return j(b,a,c)},noWrap:{f:function(){return this.value()}}}).define(m,{bind:function(a,b){return d(b,a)},bindIgnore:function(a,b){return f(b,a)},partial:h,applyFirst:e,curry:function(a,b,c){return j(b,a,c)}}).expose({bind:d,bindAll:g,bindIgnore:f,partial:h,applyFirst:e,curry:j})}"undefined"!=typeof c?"undefined"!=typeof b&&b.exports&&(b.exports=d(a("extended"),a("is-extended"),a("arguments-extended"))):"function"==typeof define&&define.amd?define(["extended","is-extended","arguments-extended"],function(a,b,c){return d(a,b,c)}):this.functionExtended=d(this.extended,this.isExtended,this.argumentsExtended)}.call(this)},{"arguments-extended":41,extended:46,"is-extended":56}],50:[function(a,b,c){function d(a,b){if(a.indexOf)return a.indexOf(b);for(var c=0;ce;e++)d[e].apply(this,c);return!0}return!1},f.prototype.addListener=function(a,b){if("function"!=typeof b)throw new Error("addListener only takes instances of Function");if(this._events||(this._events={}),this.emit("newListener",a,b),this._events[a])if(g(this._events[a])){if(!this._events[a].warned){var c;c=void 0!==this._events.maxListeners?this._events.maxListeners:h,c&&c>0&&this._events[a].length>c&&(this._events[a].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[a].length),console.trace())}this._events[a].push(b)}else this._events[a]=[this._events[a],b];else this._events[a]=b;return this},f.prototype.on=f.prototype.addListener,f.prototype.once=function(a,b){var c=this;return c.on(a,function d(){c.removeListener(a,d),b.apply(this,arguments)}),this},f.prototype.removeListener=function(a,b){if("function"!=typeof b)throw new Error("removeListener only takes instances of Function");if(!this._events||!this._events[a])return this;var c=this._events[a];if(g(c)){var e=d(c,b);if(0>e)return this;c.splice(e,1),0==c.length&&delete this._events[a]}else this._events[a]===b&&delete this._events[a];return this},f.prototype.removeAllListeners=function(a){return 0===arguments.length?(this._events={},this):(a&&this._events&&this._events[a]&&(this._events[a]=null),this)},f.prototype.listeners=function(a){return this._events||(this._events={}),this._events[a]||(this._events[a]=[]),g(this._events[a])||(this._events[a]=[this._events[a]]),this._events[a]},f.listenerCount=function(a,b){var c;return c=a._events&&a._events[b]?"function"==typeof a._events[b]?1:a._events[b].length:0}},{__browserify_process:54}],51:[function(){},{}],52:[function(a,b,c){function d(a,b){for(var c=[],d=0;d=0;d--){var e=a[d];"."==e?a.splice(d,1):".."===e?(a.splice(d,1),c++):c&&(a.splice(d,1),c--)}if(b)for(;c--;c)a.unshift("..");return a}var f=a("__browserify_process"),g=/^(.+\/(?!$)|\/)?((?:.+?)?(\.[^.]*)?)$/;c.resolve=function(){for(var a="",b=!1,c=arguments.length;c>=-1&&!b;c--){var g=c>=0?arguments[c]:f.cwd();"string"==typeof g&&g&&(a=g+"/"+a,b="/"===g.charAt(0))}return a=e(d(a.split("/"),function(a){return!!a}),!b).join("/"),(b?"/":"")+a||"."},c.normalize=function(a){var b="/"===a.charAt(0),c="/"===a.slice(-1);return a=e(d(a.split("/"),function(a){return!!a}),!b).join("/"),a||b||(a="."),a&&c&&(a+="/"),(b?"/":"")+a},c.join=function(){var a=Array.prototype.slice.call(arguments,0);return c.normalize(d(a,function(a){return a&&"string"==typeof a}).join("/"))},c.dirname=function(a){var b=g.exec(a)[1]||"",c=!1;return b?1===b.length||c&&b.length<=3&&":"===b.charAt(1)?b:b.substring(0,b.length-1):"."},c.basename=function(a,b){var c=g.exec(a)[2]||"";return b&&c.substr(-1*b.length)===b&&(c=c.substr(0,c.length-b.length)),c},c.extname=function(a){return g.exec(a)[3]||""},c.relative=function(a,b){function d(a){for(var b=0;b=0&&""===a[c];c--);return b>c?[]:a.slice(b,c-b+1)}a=c.resolve(a).substr(1),b=c.resolve(b).substr(1);for(var e=d(a.split("/")),f=d(b.split("/")),g=Math.min(e.length,f.length),h=g,i=0;g>i;i++)if(e[i]!==f[i]){h=i;break}for(var j=[],i=h;i=0;e--)if(f[e]!=g[e])return!1;for(e=f.length-1;e>=0;e--)if(d=f[e],!h(a[d],b[d]))return!1;return!0}function l(a,b){return a&&b?b instanceof RegExp?b.test(a):a instanceof b?!0:b.call({},a)===!0?!0:!1:!1}function m(a,b,c,d){var e;"string"==typeof c&&(d=c,c=null);try{b()}catch(g){e=g}if(d=(c&&c.name?" ("+c.name+").":".")+(d?" "+d:"."),a&&!e&&f("Missing expected exception"+d),!a&&l(e,c)&&f("Got unwanted exception"+d),a&&e&&c&&!l(e,c)||!a&&e)throw e}var n=a("util"),o=a("buffer").Buffer,p=Array.prototype.slice,q=b.exports=g;q.AssertionError=function(a){this.name="AssertionError",this.message=a.message,this.actual=a.actual,this.expected=a.expected,this.operator=a.operator;var b=a.stackStartFunction||f;Error.captureStackTrace&&Error.captureStackTrace(this,b)},n.inherits(q.AssertionError,Error),q.AssertionError.prototype.toString=function(){return this.message?[this.name+":",this.message].join(" "):[this.name+":",e(JSON.stringify(this.actual,d),128),this.operator,e(JSON.stringify(this.expected,d),128)].join(" ")},q.AssertionError.__proto__=Error.prototype,q.fail=f,q.ok=g,q.equal=function(a,b,c){a!=b&&f(a,b,c,"==",q.equal)},q.notEqual=function(a,b,c){a==b&&f(a,b,c,"!=",q.notEqual)},q.deepEqual=function(a,b,c){h(a,b)||f(a,b,c,"deepEqual",q.deepEqual)},q.notDeepEqual=function(a,b,c){h(a,b)&&f(a,b,c,"notDeepEqual",q.notDeepEqual)},q.strictEqual=function(a,b,c){a!==b&&f(a,b,c,"===",q.strictEqual)},q.notStrictEqual=function(a,b,c){a===b&&f(a,b,c,"!==",q.notStrictEqual)},q.throws=function(){m.apply(this,[!0].concat(p.call(arguments)))},q.doesNotThrow=function(){m.apply(this,[!1].concat(p.call(arguments)))},q.ifError=function(a){if(a)throw a}},{util:2,buffer:3}],2:[function(a,b,c){function d(a){return a instanceof Array||Array.isArray(a)||a&&a!==Object.prototype&&d(a.__proto__)}function e(a){return a instanceof RegExp||"object"==typeof a&&"[object RegExp]"===Object.prototype.toString.call(a)}function f(a){if(a instanceof Date)return!0;if("object"!=typeof a)return!1;var b=Date.prototype&&h(Date.prototype),c=a.__proto__&&h(a.__proto__);return JSON.stringify(c)===JSON.stringify(b)}a("events"),c.isArray=d,c.isDate=function(a){return"[object Date]"===Object.prototype.toString.call(a)},c.isRegExp=function(a){return"[object RegExp]"===Object.prototype.toString.call(a)},c.print=function(){},c.puts=function(){},c.debug=function(){},c.inspect=function(a,b,i,j){function k(a,i){if(a&&"function"==typeof a.inspect&&a!==c&&(!a.constructor||a.constructor.prototype!==a))return a.inspect(i);switch(typeof a){case"undefined":return m("undefined","undefined");case"string":var j="'"+JSON.stringify(a).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return m(j,"string");case"number":return m(""+a,"number");case"boolean":return m(""+a,"boolean")}if(null===a)return m("null","null");var n=g(a),o=b?h(a):n;if("function"==typeof a&&0===o.length){if(e(a))return m(""+a,"regexp");var p=a.name?": "+a.name:"";return m("[Function"+p+"]","special")}if(f(a)&&0===o.length)return m(a.toUTCString(),"date");var q,r,s;if(d(a)?(r="Array",s=["[","]"]):(r="Object",s=["{","}"]),"function"==typeof a){var t=a.name?": "+a.name:"";q=e(a)?" "+a:" [Function"+t+"]"}else q="";if(f(a)&&(q=" "+a.toUTCString()),0===o.length)return s[0]+q+s[1];if(0>i)return e(a)?m(""+a,"regexp"):m("[Object]","special");l.push(a);var u=o.map(function(b){var c,e;if(a.__lookupGetter__&&(a.__lookupGetter__(b)?e=a.__lookupSetter__(b)?m("[Getter/Setter]","special"):m("[Getter]","special"):a.__lookupSetter__(b)&&(e=m("[Setter]","special"))),n.indexOf(b)<0&&(c="["+b+"]"),e||(l.indexOf(a[b])<0?(e=null===i?k(a[b]):k(a[b],i-1),e.indexOf("\n")>-1&&(e=d(a)?e.split("\n").map(function(a){return" "+a}).join("\n").substr(2):"\n"+e.split("\n").map(function(a){return" "+a}).join("\n"))):e=m("[Circular]","special")),"undefined"==typeof c){if("Array"===r&&b.match(/^\d+$/))return e;c=JSON.stringify(""+b),c.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(c=c.substr(1,c.length-2),c=m(c,"name")):(c=c.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),c=m(c,"string"))}return c+": "+e});l.pop();var v=0,w=u.reduce(function(a,b){return v++,b.indexOf("\n")>=0&&v++,a+b.length+1},0);return u=w>50?s[0]+(""===q?"":q+"\n ")+" "+u.join(",\n ")+" "+s[1]:s[0]+q+" "+u.join(", ")+" "+s[1]}var l=[],m=function(a,b){var c={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]},d={special:"cyan",number:"blue","boolean":"yellow",undefined:"grey","null":"bold",string:"green",date:"magenta",regexp:"red"}[b];return d?"["+c[d][0]+"m"+a+"["+c[d][1]+"m":a};return j||(m=function(a){return a}),k(a,"undefined"==typeof i?2:i)},c.log=function(){},c.pump=null;var g=Object.keys||function(a){var b=[];for(var c in a)b.push(c);return b},h=Object.getOwnPropertyNames||function(a){var b=[];for(var c in a)Object.hasOwnProperty.call(a,c)&&b.push(c);return b},i=Object.create||function(a,b){var c;if(null===a)c={__proto__:null};else{if("object"!=typeof a)throw new TypeError("typeof prototype["+typeof a+"] != 'object'");var d=function(){};d.prototype=a,c=new d,c.__proto__=a}return"undefined"!=typeof b&&Object.defineProperties&&Object.defineProperties(c,b),c};c.inherits=function(a,b){a.super_=b,a.prototype=i(b.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}})};var j=/%[sdj%]/g;c.format=function(a){if("string"!=typeof a){for(var b=[],d=0;d=f)return a;switch(a){case"%s":return String(e[d++]);case"%d":return Number(e[d++]); -case"%j":return JSON.stringify(e[d++]);default:return a}}),h=e[d];f>d;h=e[++d])g+=null===h||"object"!=typeof h?" "+h:" "+c.inspect(h);return g}},{events:4}],5:[function(a,b,c){c.readIEEE754=function(a,b,c,d,e){var f,g,h=8*e-d-1,i=(1<>1,k=-7,l=c?0:e-1,m=c?1:-1,n=a[b+l];for(l+=m,f=n&(1<<-k)-1,n>>=-k,k+=h;k>0;f=256*f+a[b+l],l+=m,k-=8);for(g=f&(1<<-k)-1,f>>=-k,k+=d;k>0;g=256*g+a[b+l],l+=m,k-=8);if(0===f)f=1-j;else{if(f===i)return g?0/0:1/0*(n?-1:1);g+=Math.pow(2,d),f-=j}return(n?-1:1)*g*Math.pow(2,f-d)},c.writeIEEE754=function(a,b,c,d,e,f){var g,h,i,j=8*f-e-1,k=(1<>1,m=23===e?Math.pow(2,-24)-Math.pow(2,-77):0,n=d?f-1:0,o=d?-1:1,p=0>b||0===b&&0>1/b?1:0;for(b=Math.abs(b),isNaN(b)||1/0===b?(h=isNaN(b)?1:0,g=k):(g=Math.floor(Math.log(b)/Math.LN2),b*(i=Math.pow(2,-g))<1&&(g--,i*=2),b+=g+l>=1?m/i:m*Math.pow(2,1-l),b*i>=2&&(g++,i/=2),g+l>=k?(h=0,g=k):g+l>=1?(h=(b*i-1)*Math.pow(2,e),g+=l):(h=b*Math.pow(2,l-1)*Math.pow(2,e),g=0));e>=8;a[c+n]=255&h,n+=o,h/=256,e-=8);for(g=g<0;a[c+n]=255&g,n+=o,g/=256,j-=8);a[c+n-o]|=128*p}},{}],6:[function(a,b){var c=b.exports={};c.nextTick=function(){var a="undefined"!=typeof window&&window.setImmediate,b="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(a)return function(a){return window.setImmediate(a)};if(b){var c=[];return window.addEventListener("message",function(a){if(a.source===window&&"process-tick"===a.data&&(a.stopPropagation(),c.length>0)){var b=c.shift();b()}},!0),function(a){c.push(a),window.postMessage("process-tick","*")}}return function(a){setTimeout(a,0)}}(),c.title="browser",c.browser=!0,c.env={},c.argv=[],c.binding=function(){throw new Error("process.binding is not supported")},c.cwd=function(){return"/"},c.chdir=function(){throw new Error("process.chdir is not supported")}},{}],4:[function(a,b,c){!function(a){function b(a,b){if(a.indexOf)return a.indexOf(b);for(var c=0;cf;f++)d[f].apply(this,c);return!0}return!1},d.prototype.addListener=function(a,b){if("function"!=typeof b)throw new Error("addListener only takes instances of Function");if(this._events||(this._events={}),this.emit("newListener",a,b),this._events[a])if(e(this._events[a])){if(!this._events[a].warned){var c;c=void 0!==this._events.maxListeners?this._events.maxListeners:f,c&&c>0&&this._events[a].length>c&&(this._events[a].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[a].length),console.trace())}this._events[a].push(b)}else this._events[a]=[this._events[a],b];else this._events[a]=b;return this},d.prototype.on=d.prototype.addListener,d.prototype.once=function(a,b){var c=this;return c.on(a,function d(){c.removeListener(a,d),b.apply(this,arguments)}),this},d.prototype.removeListener=function(a,c){if("function"!=typeof c)throw new Error("removeListener only takes instances of Function");if(!this._events||!this._events[a])return this;var d=this._events[a];if(e(d)){var f=b(d,c);if(0>f)return this;d.splice(f,1),0==d.length&&delete this._events[a]}else this._events[a]===c&&delete this._events[a];return this},d.prototype.removeAllListeners=function(a){return 0===arguments.length?(this._events={},this):(a&&this._events&&this._events[a]&&(this._events[a]=null),this)},d.prototype.listeners=function(a){return this._events||(this._events={}),this._events[a]||(this._events[a]=[]),e(this._events[a])||(this._events[a]=[this._events[a]]),this._events[a]}}(a("__browserify_process"))},{__browserify_process:6}],"buffer-browserify":[function(a,b){b.exports=a("q9TxCC")},{}],q9TxCC:[function(a,b,c){function d(a){this.length=a}function e(a){return 16>a?"0"+a.toString(16):a.toString(16)}function f(a){for(var b=[],c=0;ce&&!(e+c>=b.length||e>=a.length);)b[e+c]=a[e],e++;return e}function j(a){try{return decodeURIComponent(a)}catch(b){return String.fromCharCode(65533)}}function k(a){return a=~~Math.ceil(+a),0>a?0:a}function l(a,b,c){if(!(this instanceof l))return new l(a,b,c);var e;if("number"==typeof c)this.length=k(b),this.parent=a,this.offset=c;else{switch(e=typeof a){case"number":this.length=k(a);break;case"string":this.length=l.byteLength(a,b);break;case"object":this.length=k(a.length);break;default:throw new Error("First argument needs to be a number, array or string.")}if(this.length>l.poolSize?(this.parent=new d(this.length),this.offset=0):((!E||E.length-E.used=a.length?0:(c?(e=a.parent[a.offset+b]<<8,b+1=a.length?0:(c?(b+1>>0):(b+2>>0)),e)}function q(a,b,c,d){var e,f;return d||(D.ok("boolean"==typeof c,"missing or invalid endian"),D.ok(void 0!==b&&null!==b,"missing offset"),D.ok(b+1=0,"specified a negative value for writing an unsigned value"),D.ok(b>=a,"value is larger than maximum value for type"),D.ok(Math.floor(a)===a,"value has a fractional component")}function v(a,b,c,d,e){e||(D.ok(void 0!==b&&null!==b,"missing value"),D.ok("boolean"==typeof d,"missing or invalid endian"),D.ok(void 0!==c&&null!==c,"missing offset"),D.ok(c+1>>8*(d?1-f:f)}function w(a,b,c,d,e){e||(D.ok(void 0!==b&&null!==b,"missing value"),D.ok("boolean"==typeof d,"missing or invalid endian"),D.ok(void 0!==c&&null!==c,"missing offset"),D.ok(c+3>>8*(d?3-f:f)}function x(a,b,c){D.ok("number"==typeof a,"cannot write a non-number as a number"),D.ok(b>=a,"value larger than maximum allowed value"),D.ok(a>=c,"value smaller than minimum allowed value"),D.ok(Math.floor(a)===a,"value has a fractional component")}function y(a,b,c){D.ok("number"==typeof a,"cannot write a non-number as a number"),D.ok(b>=a,"value larger than maximum allowed value"),D.ok(a>=c,"value smaller than minimum allowed value")}function z(a,b,c,d,e){e||(D.ok(void 0!==b&&null!==b,"missing value"),D.ok("boolean"==typeof d,"missing or invalid endian"),D.ok(void 0!==c&&null!==c,"missing offset"),D.ok(c+1=0?v(a,b,c,d,e):v(a,65535+b+1,c,d,e)}function A(a,b,c,d,e){e||(D.ok(void 0!==b&&null!==b,"missing value"),D.ok("boolean"==typeof d,"missing or invalid endian"),D.ok(void 0!==c&&null!==c,"missing offset"),D.ok(c+3=0?w(a,b,c,d,e):w(a,4294967295+b+1,c,d,e)}function B(b,c,d,e,f){f||(D.ok(void 0!==c&&null!==c,"missing value"),D.ok("boolean"==typeof e,"missing or invalid endian"),D.ok(void 0!==d&&null!==d,"missing offset"),D.ok(d+3d;d++)if(a[d]=e(this[d]),d==c.INSPECT_MAX_BYTES){a[d+1]="...";break}return""},d.prototype.hexSlice=function(a,b){var c=this.length;(!a||0>a)&&(a=0),(!b||0>b||b>c)&&(b=c);for(var d="",f=a;b>f;f++)d+=e(this[f]);return d},d.prototype.toString=function(a,b,c){if(a=String(a||"utf8").toLowerCase(),b=+b||0,"undefined"==typeof c&&(c=this.length),+c==b)return"";switch(a){case"hex":return this.hexSlice(b,c);case"utf8":case"utf-8":return this.utf8Slice(b,c);case"ascii":return this.asciiSlice(b,c);case"binary":return this.binarySlice(b,c);case"base64":return this.base64Slice(b,c);case"ucs2":case"ucs-2":return this.ucs2Slice(b,c);default:throw new Error("Unknown encoding")}},d.prototype.hexWrite=function(a,b,c){b=+b||0;var e=this.length-b;c?(c=+c,c>e&&(c=e)):c=e;var f=a.length;if(f%2)throw new Error("Invalid hex string");c>f/2&&(c=f/2);for(var g=0;c>g;g++){var h=parseInt(a.substr(2*g,2),16);if(isNaN(h))throw new Error("Invalid hex string");this[b+g]=h}return d._charsWritten=2*g,g},d.prototype.write=function(a,b,c,d){if(isFinite(b))isFinite(c)||(d=c,c=void 0);else{var e=d;d=b,b=c,c=e}b=+b||0;var f=this.length-b;switch(c?(c=+c,c>f&&(c=f)):c=f,d=String(d||"utf8").toLowerCase()){case"hex":return this.hexWrite(a,b,c);case"utf8":case"utf-8":return this.utf8Write(a,b,c);case"ascii":return this.asciiWrite(a,b,c);case"binary":return this.binaryWrite(a,b,c);case"base64":return this.base64Write(a,b,c);case"ucs2":case"ucs-2":return this.ucs2Write(a,b,c);default:throw new Error("Unknown encoding")}},d.prototype.slice=function(a,b){if(void 0===b&&(b=this.length),b>this.length)throw new Error("oob");if(a>b)throw new Error("oob");return new l(this,b-a,+a)},d.prototype.copy=function(a,b,c,d){for(var e=[],f=c;d>f;f++)D.ok("undefined"!=typeof this[f],"copying undefined buffer bytes!"),e.push(this[f]);for(var f=b;fthis.length)throw new Error("oob");if(b>c)throw new Error("oob");for(var d=b;c>d;d++)this[d]=a},c.SlowBuffer=d,c.Buffer=l,l.poolSize=8192;var E;l.isBuffer=function(a){return a instanceof l||a instanceof d},l.concat=function(a,b){if(!Array.isArray(a))throw new Error("Usage: Buffer.concat(list, [totalLength])\n list should be an Array.");if(0===a.length)return new l(0);if(1===a.length)return a[0];if("number"!=typeof b){b=0;for(var c=0;cd;d++)if(a[d]=e(this.parent[d+this.offset]),d==c.INSPECT_MAX_BYTES){a[d+1]="...";break}return""},l.prototype.get=function(a){if(0>a||a>=this.length)throw new Error("oob");return this.parent[this.offset+a]},l.prototype.set=function(a,b){if(0>a||a>=this.length)throw new Error("oob");return this.parent[this.offset+a]=b},l.prototype.write=function(a,b,c,e){if(isFinite(b))isFinite(c)||(e=c,c=void 0);else{var f=e;e=b,b=c,c=f}b=+b||0;var g=this.length-b;c?(c=+c,c>g&&(c=g)):c=g,e=String(e||"utf8").toLowerCase();var h;switch(e){case"hex":h=this.parent.hexWrite(a,this.offset+b,c);break;case"utf8":case"utf-8":h=this.parent.utf8Write(a,this.offset+b,c);break;case"ascii":h=this.parent.asciiWrite(a,this.offset+b,c);break;case"binary":h=this.parent.binaryWrite(a,this.offset+b,c);break;case"base64":h=this.parent.base64Write(a,this.offset+b,c);break;case"ucs2":case"ucs-2":h=this.parent.ucs2Write(a,this.offset+b,c);break;default:throw new Error("Unknown encoding")}return l._charsWritten=d._charsWritten,h},l.prototype.toString=function(a,b,c){switch(a=String(a||"utf8").toLowerCase(),"undefined"==typeof b||0>b?b=0:b>this.length&&(b=this.length),"undefined"==typeof c||c>this.length?c=this.length:0>c&&(c=0),b+=this.offset,c+=this.offset,a){case"hex":return this.parent.hexSlice(b,c);case"utf8":case"utf-8":return this.parent.utf8Slice(b,c);case"ascii":return this.parent.asciiSlice(b,c);case"binary":return this.parent.binarySlice(b,c);case"base64":return this.parent.base64Slice(b,c);case"ucs2":case"ucs-2":return this.parent.ucs2Slice(b,c);default:throw new Error("Unknown encoding")}},l.byteLength=d.byteLength,l.prototype.fill=function(a,b,c){if(a||(a=0),b||(b=0),c||(c=this.length),"string"==typeof a&&(a=a.charCodeAt(0)),"number"!=typeof a||isNaN(a))throw new Error("value is not a number");if(b>c)throw new Error("end < start");if(c===b)return 0;if(0==this.length)return 0;if(0>b||b>=this.length)throw new Error("start out of bounds");if(0>c||c>this.length)throw new Error("end out of bounds");return this.parent.fill(a,b+this.offset,c+this.offset)},l.prototype.copy=function(a,b,c,d){var e=this;if(c||(c=0),d||(d=this.length),b||(b=0),c>d)throw new Error("sourceEnd < sourceStart");if(d===c)return 0;if(0==a.length||0==e.length)return 0;if(0>b||b>=a.length)throw new Error("targetStart out of bounds");if(0>c||c>=e.length)throw new Error("sourceStart out of bounds");if(0>d||d>e.length)throw new Error("sourceEnd out of bounds");return d>this.length&&(d=this.length),a.length-bthis.length)throw new Error("oob");if(a>b)throw new Error("oob");return new l(this.parent,b-a,+a+this.offset)},l.prototype.utf8Slice=function(a,b){return this.toString("utf8",a,b)},l.prototype.binarySlice=function(a,b){return this.toString("binary",a,b)},l.prototype.asciiSlice=function(a,b){return this.toString("ascii",a,b)},l.prototype.utf8Write=function(a,b){return this.write(a,b,"utf8")},l.prototype.binaryWrite=function(a,b){return this.write(a,b,"binary")},l.prototype.asciiWrite=function(a,b){return this.write(a,b,"ascii")},l.prototype.readUInt8=function(a,b){var c=this;return b||(D.ok(void 0!==a&&null!==a,"missing offset"),D.ok(a=c.length?void 0:c.parent[c.offset+a]},l.prototype.readUInt16LE=function(a,b){return o(this,a,!1,b)},l.prototype.readUInt16BE=function(a,b){return o(this,a,!0,b)},l.prototype.readUInt32LE=function(a,b){return p(this,a,!1,b)},l.prototype.readUInt32BE=function(a,b){return p(this,a,!0,b)},l.prototype.readInt8=function(a,b){var c,d=this;return b||(D.ok(void 0!==a&&null!==a,"missing offset"),D.ok(a=d.length?void 0:(c=128&d.parent[d.offset+a],c?-1*(255-d.parent[d.offset+a]+1):d.parent[d.offset+a])},l.prototype.readInt16LE=function(a,b){return q(this,a,!1,b)},l.prototype.readInt16BE=function(a,b){return q(this,a,!0,b)},l.prototype.readInt32LE=function(a,b){return r(this,a,!1,b)},l.prototype.readInt32BE=function(a,b){return r(this,a,!0,b)},l.prototype.readFloatLE=function(a,b){return s(this,a,!1,b)},l.prototype.readFloatBE=function(a,b){return s(this,a,!0,b)},l.prototype.readDoubleLE=function(a,b){return t(this,a,!1,b)},l.prototype.readDoubleBE=function(a,b){return t(this,a,!0,b)},l.prototype.writeUInt8=function(a,b,c){var d=this;c||(D.ok(void 0!==a&&null!==a,"missing value"),D.ok(void 0!==b&&null!==b,"missing offset"),D.ok(b=0?d.writeUInt8(a,b,c):d.writeUInt8(255+a+1,b,c)},l.prototype.writeInt16LE=function(a,b,c){z(this,a,b,!1,c)},l.prototype.writeInt16BE=function(a,b,c){z(this,a,b,!0,c)},l.prototype.writeInt32LE=function(a,b,c){A(this,a,b,!1,c)},l.prototype.writeInt32BE=function(a,b,c){A(this,a,b,!0,c)},l.prototype.writeFloatLE=function(a,b,c){B(this,a,b,!1,c)},l.prototype.writeFloatBE=function(a,b,c){B(this,a,b,!0,c)},l.prototype.writeDoubleLE=function(a,b,c){C(this,a,b,!1,c)},l.prototype.writeDoubleBE=function(a,b,c){C(this,a,b,!0,c)},d.prototype.readUInt8=l.prototype.readUInt8,d.prototype.readUInt16LE=l.prototype.readUInt16LE,d.prototype.readUInt16BE=l.prototype.readUInt16BE,d.prototype.readUInt32LE=l.prototype.readUInt32LE,d.prototype.readUInt32BE=l.prototype.readUInt32BE,d.prototype.readInt8=l.prototype.readInt8,d.prototype.readInt16LE=l.prototype.readInt16LE,d.prototype.readInt16BE=l.prototype.readInt16BE,d.prototype.readInt32LE=l.prototype.readInt32LE,d.prototype.readInt32BE=l.prototype.readInt32BE,d.prototype.readFloatLE=l.prototype.readFloatLE,d.prototype.readFloatBE=l.prototype.readFloatBE,d.prototype.readDoubleLE=l.prototype.readDoubleLE,d.prototype.readDoubleBE=l.prototype.readDoubleBE,d.prototype.writeUInt8=l.prototype.writeUInt8,d.prototype.writeUInt16LE=l.prototype.writeUInt16LE,d.prototype.writeUInt16BE=l.prototype.writeUInt16BE,d.prototype.writeUInt32LE=l.prototype.writeUInt32LE,d.prototype.writeUInt32BE=l.prototype.writeUInt32BE,d.prototype.writeInt8=l.prototype.writeInt8,d.prototype.writeInt16LE=l.prototype.writeInt16LE,d.prototype.writeInt16BE=l.prototype.writeInt16BE,d.prototype.writeInt32LE=l.prototype.writeInt32LE,d.prototype.writeInt32BE=l.prototype.writeInt32BE,d.prototype.writeFloatLE=l.prototype.writeFloatLE,d.prototype.writeFloatBE=l.prototype.writeFloatBE,d.prototype.writeDoubleLE=l.prototype.writeDoubleLE,d.prototype.writeDoubleBE=l.prototype.writeDoubleBE},{assert:1,"./buffer_ieee754":5,"base64-js":7}],7:[function(a,b){!function(){"use strict";function a(a){var b,c,e,f,g,h;if(a.length%4>0)throw"Invalid string. Length must be a multiple of 4";for(g=a.indexOf("="),g=g>0?a.length-g:0,h=[],e=g>0?a.length-4:a.length,b=0,c=0;e>b;b+=4,c+=3)f=d.indexOf(a[b])<<18|d.indexOf(a[b+1])<<12|d.indexOf(a[b+2])<<6|d.indexOf(a[b+3]),h.push((16711680&f)>>16),h.push((65280&f)>>8),h.push(255&f);return 2===g?(f=d.indexOf(a[b])<<2|d.indexOf(a[b+1])>>4,h.push(255&f)):1===g&&(f=d.indexOf(a[b])<<10|d.indexOf(a[b+1])<<4|d.indexOf(a[b+2])>>2,h.push(255&f>>8),h.push(255&f)),h}function c(a){function b(a){return d[63&a>>18]+d[63&a>>12]+d[63&a>>6]+d[63&a]}var c,e,f,g=a.length%3,h="";for(c=0,f=a.length-g;f>c;c+=3)e=(a[c]<<16)+(a[c+1]<<8)+a[c+2],h+=b(e);switch(g){case 1:e=a[a.length-1],h+=d[e>>2],h+=d[63&e<<4],h+="==";break;case 2:e=(a[a.length-2]<<8)+a[a.length-1],h+=d[e>>10],h+=d[63&e>>4],h+=d[63&e<<2],h+="="}return h}var d="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";b.exports.toByteArray=a,b.exports.fromByteArray=c}()},{}],8:[function(a,b,c){c.readIEEE754=function(a,b,c,d,e){var f,g,h=8*e-d-1,i=(1<>1,k=-7,l=c?0:e-1,m=c?1:-1,n=a[b+l];for(l+=m,f=n&(1<<-k)-1,n>>=-k,k+=h;k>0;f=256*f+a[b+l],l+=m,k-=8);for(g=f&(1<<-k)-1,f>>=-k,k+=d;k>0;g=256*g+a[b+l],l+=m,k-=8);if(0===f)f=1-j;else{if(f===i)return g?0/0:1/0*(n?-1:1);g+=Math.pow(2,d),f-=j}return(n?-1:1)*g*Math.pow(2,f-d)},c.writeIEEE754=function(a,b,c,d,e,f){var g,h,i,j=8*f-e-1,k=(1<>1,m=23===e?Math.pow(2,-24)-Math.pow(2,-77):0,n=d?f-1:0,o=d?-1:1,p=0>b||0===b&&0>1/b?1:0;for(b=Math.abs(b),isNaN(b)||1/0===b?(h=isNaN(b)?1:0,g=k):(g=Math.floor(Math.log(b)/Math.LN2),b*(i=Math.pow(2,-g))<1&&(g--,i*=2),b+=g+l>=1?m/i:m*Math.pow(2,1-l),b*i>=2&&(g++,i/=2),g+l>=k?(h=0,g=k):g+l>=1?(h=(b*i-1)*Math.pow(2,e),g+=l):(h=b*Math.pow(2,l-1)*Math.pow(2,e),g=0));e>=8;a[c+n]=255&h,n+=o,h/=256,e-=8);for(g=g<0;a[c+n]=255&g,n+=o,g/=256,j-=8);a[c+n-o]|=128*p}},{}],3:[function(a,b,c){function d(a){this.length=a}function e(a){return 16>a?"0"+a.toString(16):a.toString(16)}function f(a){for(var b=[],c=0;ce&&!(e+c>=b.length||e>=a.length);)b[e+c]=a[e],e++;return e}function j(a){try{return decodeURIComponent(a)}catch(b){return String.fromCharCode(65533)}}function k(a){return a=~~Math.ceil(+a),0>a?0:a}function l(a,b,c){if(!(this instanceof l))return new l(a,b,c);var e;if("number"==typeof c)this.length=k(b),this.parent=a,this.offset=c;else{switch(e=typeof a){case"number":this.length=k(a);break;case"string":this.length=l.byteLength(a,b);break;case"object":this.length=k(a.length);break;default:throw new Error("First argument needs to be a number, array or string.")}if(this.length>l.poolSize?(this.parent=new d(this.length),this.offset=0):((!E||E.length-E.used>>0):(e=a.parent[a.offset+b+2]<<16,e|=a.parent[a.offset+b+1]<<8,e|=a.parent[a.offset+b],e+=a.parent[a.offset+b+3]<<24>>>0),e}function q(a,b,c,d){var e,f;return d||(D.ok("boolean"==typeof c,"missing or invalid endian"),D.ok(void 0!==b&&null!==b,"missing offset"),D.ok(b+1=0,"specified a negative value for writing an unsigned value"),D.ok(b>=a,"value is larger than maximum value for type"),D.ok(Math.floor(a)===a,"value has a fractional component")}function v(a,b,c,d,e){e||(D.ok(void 0!==b&&null!==b,"missing value"),D.ok("boolean"==typeof d,"missing or invalid endian"),D.ok(void 0!==c&&null!==c,"missing offset"),D.ok(c+1>>8,a.parent[a.offset+c+1]=255&b):(a.parent[a.offset+c+1]=(65280&b)>>>8,a.parent[a.offset+c]=255&b)}function w(a,b,c,d,e){e||(D.ok(void 0!==b&&null!==b,"missing value"),D.ok("boolean"==typeof d,"missing or invalid endian"),D.ok(void 0!==c&&null!==c,"missing offset"),D.ok(c+3>>24,a.parent[a.offset+c+1]=255&b>>>16,a.parent[a.offset+c+2]=255&b>>>8,a.parent[a.offset+c+3]=255&b):(a.parent[a.offset+c+3]=255&b>>>24,a.parent[a.offset+c+2]=255&b>>>16,a.parent[a.offset+c+1]=255&b>>>8,a.parent[a.offset+c]=255&b)}function x(a,b,c){D.ok("number"==typeof a,"cannot write a non-number as a number"),D.ok(b>=a,"value larger than maximum allowed value"),D.ok(a>=c,"value smaller than minimum allowed value"),D.ok(Math.floor(a)===a,"value has a fractional component")}function y(a,b,c){D.ok("number"==typeof a,"cannot write a non-number as a number"),D.ok(b>=a,"value larger than maximum allowed value"),D.ok(a>=c,"value smaller than minimum allowed value")}function z(a,b,c,d,e){e||(D.ok(void 0!==b&&null!==b,"missing value"),D.ok("boolean"==typeof d,"missing or invalid endian"),D.ok(void 0!==c&&null!==c,"missing offset"),D.ok(c+1=0?v(a,b,c,d,e):v(a,65535+b+1,c,d,e)}function A(a,b,c,d,e){e||(D.ok(void 0!==b&&null!==b,"missing value"),D.ok("boolean"==typeof d,"missing or invalid endian"),D.ok(void 0!==c&&null!==c,"missing offset"),D.ok(c+3=0?w(a,b,c,d,e):w(a,4294967295+b+1,c,d,e)}function B(b,c,d,e,f){f||(D.ok(void 0!==c&&null!==c,"missing value"),D.ok("boolean"==typeof e,"missing or invalid endian"),D.ok(void 0!==d&&null!==d,"missing offset"),D.ok(d+3d;d++)if(a[d]=e(this[d]),d==c.INSPECT_MAX_BYTES){a[d+1]="...";break}return""},d.prototype.hexSlice=function(a,b){var c=this.length;(!a||0>a)&&(a=0),(!b||0>b||b>c)&&(b=c);for(var d="",f=a;b>f;f++)d+=e(this[f]);return d},d.prototype.toString=function(a,b,c){if(a=String(a||"utf8").toLowerCase(),b=+b||0,"undefined"==typeof c&&(c=this.length),+c==b)return"";switch(a){case"hex":return this.hexSlice(b,c);case"utf8":case"utf-8":return this.utf8Slice(b,c);case"ascii":return this.asciiSlice(b,c);case"binary":return this.binarySlice(b,c);case"base64":return this.base64Slice(b,c);case"ucs2":case"ucs-2":return this.ucs2Slice(b,c);default:throw new Error("Unknown encoding")}},d.prototype.hexWrite=function(a,b,c){b=+b||0;var e=this.length-b;c?(c=+c,c>e&&(c=e)):c=e;var f=a.length;if(f%2)throw new Error("Invalid hex string");c>f/2&&(c=f/2);for(var g=0;c>g;g++){var h=parseInt(a.substr(2*g,2),16);if(isNaN(h))throw new Error("Invalid hex string");this[b+g]=h}return d._charsWritten=2*g,g},d.prototype.write=function(a,b,c,d){if(isFinite(b))isFinite(c)||(d=c,c=void 0);else{var e=d;d=b,b=c,c=e}b=+b||0;var f=this.length-b;switch(c?(c=+c,c>f&&(c=f)):c=f,d=String(d||"utf8").toLowerCase()){case"hex":return this.hexWrite(a,b,c);case"utf8":case"utf-8":return this.utf8Write(a,b,c);case"ascii":return this.asciiWrite(a,b,c);case"binary":return this.binaryWrite(a,b,c);case"base64":return this.base64Write(a,b,c);case"ucs2":case"ucs-2":return this.ucs2Write(a,b,c);default:throw new Error("Unknown encoding")}},d.prototype.slice=function(a,b){if(void 0===b&&(b=this.length),b>this.length)throw new Error("oob");if(a>b)throw new Error("oob");return new l(this,b-a,+a)},d.prototype.copy=function(a,b,c,d){for(var e=[],f=c;d>f;f++)D.ok("undefined"!=typeof this[f],"copying undefined buffer bytes!"),e.push(this[f]);for(var f=b;fd;d++)if(a[d]=e(this.parent[d+this.offset]),d==c.INSPECT_MAX_BYTES){a[d+1]="...";break}return""},l.prototype.get=function(a){if(0>a||a>=this.length)throw new Error("oob");return this.parent[this.offset+a]},l.prototype.set=function(a,b){if(0>a||a>=this.length)throw new Error("oob");return this.parent[this.offset+a]=b},l.prototype.write=function(a,b,c,e){if(isFinite(b))isFinite(c)||(e=c,c=void 0);else{var f=e;e=b,b=c,c=f}b=+b||0;var g=this.length-b;c?(c=+c,c>g&&(c=g)):c=g,e=String(e||"utf8").toLowerCase();var h;switch(e){case"hex":h=this.parent.hexWrite(a,this.offset+b,c);break;case"utf8":case"utf-8":h=this.parent.utf8Write(a,this.offset+b,c);break;case"ascii":h=this.parent.asciiWrite(a,this.offset+b,c);break;case"binary":h=this.parent.binaryWrite(a,this.offset+b,c);break;case"base64":h=this.parent.base64Write(a,this.offset+b,c);break;case"ucs2":case"ucs-2":h=this.parent.ucs2Write(a,this.offset+b,c);break;default:throw new Error("Unknown encoding")}return l._charsWritten=d._charsWritten,h},l.prototype.toString=function(a,b,c){switch(a=String(a||"utf8").toLowerCase(),"undefined"==typeof b||0>b?b=0:b>this.length&&(b=this.length),"undefined"==typeof c||c>this.length?c=this.length:0>c&&(c=0),b+=this.offset,c+=this.offset,a){case"hex":return this.parent.hexSlice(b,c);case"utf8":case"utf-8":return this.parent.utf8Slice(b,c);case"ascii":return this.parent.asciiSlice(b,c);case"binary":return this.parent.binarySlice(b,c);case"base64":return this.parent.base64Slice(b,c);case"ucs2":case"ucs-2":return this.parent.ucs2Slice(b,c);default:throw new Error("Unknown encoding")}},l.byteLength=d.byteLength,l.prototype.fill=function(a,b,c){if(a||(a=0),b||(b=0),c||(c=this.length),"string"==typeof a&&(a=a.charCodeAt(0)),"number"!=typeof a||isNaN(a))throw new Error("value is not a number");if(b>c)throw new Error("end < start");if(c===b)return 0;if(0==this.length)return 0;if(0>b||b>=this.length)throw new Error("start out of bounds");if(0>c||c>this.length)throw new Error("end out of bounds");return this.parent.fill(a,b+this.offset,c+this.offset)},l.prototype.copy=function(a,b,c,d){var e=this;if(c||(c=0),d||(d=this.length),b||(b=0),c>d)throw new Error("sourceEnd < sourceStart");if(d===c)return 0;if(0==a.length||0==e.length)return 0;if(0>b||b>=a.length)throw new Error("targetStart out of bounds");if(0>c||c>=e.length)throw new Error("sourceStart out of bounds");if(0>d||d>e.length)throw new Error("sourceEnd out of bounds");return d>this.length&&(d=this.length),a.length-bthis.length)throw new Error("oob");if(a>b)throw new Error("oob");return new l(this.parent,b-a,+a+this.offset)},l.prototype.utf8Slice=function(a,b){return this.toString("utf8",a,b)},l.prototype.binarySlice=function(a,b){return this.toString("binary",a,b)},l.prototype.asciiSlice=function(a,b){return this.toString("ascii",a,b)},l.prototype.utf8Write=function(a,b){return this.write(a,b,"utf8")},l.prototype.binaryWrite=function(a,b){return this.write(a,b,"binary")},l.prototype.asciiWrite=function(a,b){return this.write(a,b,"ascii")},l.prototype.readUInt8=function(a,b){var c=this;return b||(D.ok(void 0!==a&&null!==a,"missing offset"),D.ok(a=0?d.writeUInt8(a,b,c):d.writeUInt8(255+a+1,b,c)},l.prototype.writeInt16LE=function(a,b,c){z(this,a,b,!1,c)},l.prototype.writeInt16BE=function(a,b,c){z(this,a,b,!0,c)},l.prototype.writeInt32LE=function(a,b,c){A(this,a,b,!1,c)},l.prototype.writeInt32BE=function(a,b,c){A(this,a,b,!0,c)},l.prototype.writeFloatLE=function(a,b,c){B(this,a,b,!1,c)},l.prototype.writeFloatBE=function(a,b,c){B(this,a,b,!0,c)},l.prototype.writeDoubleLE=function(a,b,c){C(this,a,b,!1,c)},l.prototype.writeDoubleBE=function(a,b,c){C(this,a,b,!0,c)},d.prototype.readUInt8=l.prototype.readUInt8,d.prototype.readUInt16LE=l.prototype.readUInt16LE,d.prototype.readUInt16BE=l.prototype.readUInt16BE,d.prototype.readUInt32LE=l.prototype.readUInt32LE,d.prototype.readUInt32BE=l.prototype.readUInt32BE,d.prototype.readInt8=l.prototype.readInt8,d.prototype.readInt16LE=l.prototype.readInt16LE,d.prototype.readInt16BE=l.prototype.readInt16BE,d.prototype.readInt32LE=l.prototype.readInt32LE,d.prototype.readInt32BE=l.prototype.readInt32BE,d.prototype.readFloatLE=l.prototype.readFloatLE,d.prototype.readFloatBE=l.prototype.readFloatBE,d.prototype.readDoubleLE=l.prototype.readDoubleLE,d.prototype.readDoubleBE=l.prototype.readDoubleBE,d.prototype.writeUInt8=l.prototype.writeUInt8,d.prototype.writeUInt16LE=l.prototype.writeUInt16LE,d.prototype.writeUInt16BE=l.prototype.writeUInt16BE,d.prototype.writeUInt32LE=l.prototype.writeUInt32LE,d.prototype.writeUInt32BE=l.prototype.writeUInt32BE,d.prototype.writeInt8=l.prototype.writeInt8,d.prototype.writeInt16LE=l.prototype.writeInt16LE,d.prototype.writeInt16BE=l.prototype.writeInt16BE,d.prototype.writeInt32LE=l.prototype.writeInt32LE,d.prototype.writeInt32BE=l.prototype.writeInt32BE,d.prototype.writeFloatLE=l.prototype.writeFloatLE,d.prototype.writeFloatBE=l.prototype.writeFloatBE,d.prototype.writeDoubleLE=l.prototype.writeDoubleLE,d.prototype.writeDoubleBE=l.prototype.writeDoubleBE},{assert:1,"./buffer_ieee754":8,"base64-js":9}],9:[function(a,b){!function(){"use strict";function a(a){var b,c,e,f,g,h;if(a.length%4>0)throw"Invalid string. Length must be a multiple of 4";for(g=a.indexOf("="),g=g>0?a.length-g:0,h=[],e=g>0?a.length-4:a.length,b=0,c=0;e>b;b+=4,c+=3)f=d.indexOf(a[b])<<18|d.indexOf(a[b+1])<<12|d.indexOf(a[b+2])<<6|d.indexOf(a[b+3]),h.push((16711680&f)>>16),h.push((65280&f)>>8),h.push(255&f);return 2===g?(f=d.indexOf(a[b])<<2|d.indexOf(a[b+1])>>4,h.push(255&f)):1===g&&(f=d.indexOf(a[b])<<10|d.indexOf(a[b+1])<<4|d.indexOf(a[b+2])>>2,h.push(255&f>>8),h.push(255&f)),h}function c(a){function b(a){return d[63&a>>18]+d[63&a>>12]+d[63&a>>6]+d[63&a]}var c,e,f,g=a.length%3,h="";for(c=0,f=a.length-g;f>c;c+=3)e=(a[c]<<16)+(a[c+1]<<8)+a[c+2],h+=b(e);switch(g){case 1:e=a[a.length-1],h+=d[e>>2],h+=d[63&e<<4],h+="==";break;case 2:e=(a[a.length-2]<<8)+a[a.length-1],h+=d[e>>10],h+=d[63&e>>4],h+=d[63&e<<2],h+="="}return h}var d="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";b.exports.toByteArray=a,b.exports.fromByteArray=c}()},{}]},{},[]),b.exports=a("buffer-browserify")},{}],54:[function(a,b){var c=b.exports={};c.nextTick=function(){var a="undefined"!=typeof window&&window.setImmediate,b="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(a)return function(a){return window.setImmediate(a)};if(b){var c=[];return window.addEventListener("message",function(a){if(a.source===window&&"process-tick"===a.data&&(a.stopPropagation(),c.length>0)){var b=c.shift();b()}},!0),function(a){c.push(a),window.postMessage("process-tick","*")}}return function(a){setTimeout(a,0)}}(),c.title="browser",c.browser=!0,c.env={},c.argv=[],c.binding=function(){throw new Error("process.binding is not supported")},c.cwd=function(){return"/"},c.chdir=function(){throw new Error("process.chdir is not supported")}},{}],55:[function(a,b,c){!function(){"use strict";function d(a){var b=function(a){return"string"==typeof a?a:"object"==typeof a?a.hashCode?a.hashCode():""+a:""+a},c=a.declare({instance:{constructor:function(){this.__entries=[],this.__keys=[],this.__values=[]},pushValue:function(a,b){return this.__keys.push(a),this.__values.push(b),this.__entries.push({key:a,value:b}),b},remove:function(a){for(var b,c=null,d=this.__entries,e=this.__keys,f=this.__values,g=d.length-1;g>=0;g--)if((b=d[g])&&b.key===a)return d.splice(g,1),e.splice(g,1),f.splice(g,1),b.value;return c},set:function(a,b){for(var c=null,d=this.__entries,e=this.__values,f=d.length-1;f>=0;f--){var g=d[f];if(g&&a===g.key){e[f]=b,g.value=b,c=b;break}}return c||d.push({key:a,value:b}),c},find:function(a){for(var b,c=null,d=this.__entries,e=d.length-1;e>=0;e--)if(b=d[e],b&&a===b.key){c=b.value;break}return c},getEntrySet:function(){return this.__entries},getKeys:function(){return this.__keys},getValues:function(){return this.__values}}});return a.declare({instance:{constructor:function(){this.__map={}},entrySet:function(){var a=[],b=this.__map;for(var c in b)b.hasOwnProperty(c)&&(a=a.concat(b[c].getEntrySet()));return a},put:function(a,d){var e=b(a),f=null;return(f=this.__map[e])||(f=this.__map[e]=new c),f.pushValue(a,d),d},remove:function(a){var c=b(a),d=null,e=this.__map[c];return e&&(d=e.remove(a)),d},get:function(a){var c,d=b(a),e=null;return(c=this.__map[d])&&(e=c.find(a)),e},set:function(a,d){var e=b(a),f=null,g=null,h=this.__map;return f=(g=h[e])?g.set(a,d):(h[e]=new c).pushValue(a,d)},contains:function(a){var c=b(a),d=!1,e=null;return(e=this.__map[c])&&(d=!!e.find(a)),d},concat:function(a){if(a instanceof this._static){for(var b=new this._static,c=a.entrySet().concat(this.entrySet()),d=c.length-1;d>=0;d--){var e=c[d];b.put(e.key,e.value)}return b}throw new TypeError("When joining hashtables the joining arg must be a HashTable")},filter:function(b,c){var d=this.entrySet(),e=new this._static;d=a.filter(d,b,c);for(var f=d.length-1;f>=0;f--){var g=d[f];e.put(g.key,g.value)}return e},forEach:function(b,c){var d=this.entrySet();a.forEach(d,b,c)},every:function(b,c){var d=this.entrySet();return a.every(d,b,c)},map:function(b,c){var d=this.entrySet();return a.map(d,b,c)},some:function(b,c){var d=this.entrySet();return a.some(d,b,c)},reduce:function(b,c){var d=this.entrySet();return a.reduce(d,b,c)},reduceRight:function(b,c){var d=this.entrySet();return a.reduceRight(d,b,c)},clear:function(){this.__map={}},keys:function(){var a=[],b=this.__map;for(var c in b)a=a.concat(b[c].getKeys());return a},values:function(){var a=[],b=this.__map;for(var c in b)a=a.concat(b[c].getValues());return a},isEmpty:function(){return 0===this.keys().length}}})}"undefined"!=typeof c?"undefined"!=typeof b&&b.exports&&(b.exports=d(a("extended")().register("declare",a("declare.js")).register(a("is-extended")).register(a("array-extended")))):"function"==typeof define?define(["extended","declare","is-extended","array-extended"],function(a,b,c,e){return d(a().register("declare",b).register(c).register(e))}):this.Ht=d(this.extended().register("declare",this.declare).register(this.isExtended).register(this.arrayExtended))}.call(this)},{"array-extended":42,"declare.js":45,extended:46,"is-extended":56}],56:[function(a,b,c){var d=a("__browserify_Buffer").Buffer;!function(){"use strict";function e(a){function b(a,b){var c=-1,d=0,e=a.length,f=[];for(b=b||0,c+=b;++c=0;f--)if(g[f]!==h[f])return!1;for(f=g.length-1;f>=0;f--)if(d=g[f],!e(a[d],b[d]))return!1}catch(i){return!1}return!0}function g(a){return null!==a&&"object"==typeof a}function h(a){var b=g(a);return b&&a.constructor===Object&&!a.nodeType&&!a.setInterval}function i(a){return W(a)?0===a.length:g(a)?0===c(a).length:r(a)||X(a)?0===a.length:!0}function j(a){return a===!0||a===!1||"[object Boolean]"===U.call(a)}function k(a){return"undefined"==typeof a}function l(a){return!k(a)}function m(a){return k(a)||n(a)}function n(a){return null===a}function o(a,b){return V(b)?a instanceof b:!1}function p(a){return"[object RegExp]"===U.call(a)}function q(a){return"[object Date]"===U.call(a)}function r(a){return"[object String]"===U.call(a)}function s(a){return"[object Number]"===U.call(a)}function t(a){return a===!0}function u(a){return a===!1}function v(a){return!n(a)}function w(a,b){return a==b}function x(a,b){return a!=b}function y(a,b){return a===b}function z(a,b){return a!==b}function A(a,b){if(X(b)&&Array.prototype.indexOf||r(b))return b.indexOf(a)>-1;if(X(b))for(var c=0,d=b.length;d>c;c++)if(w(a,b[c]))return!0;return!1}function B(a,b){return!A(a,b)}function C(a,b){return b>a}function D(a,b){return b>=a}function E(a,b){return a>b}function F(a,b){return a>=b}function G(a,b){return r(b)?null!==(""+a).match(b):p(b)?b.test(a):!1}function H(a,b){return!G(a,b)}function I(a,b){return A(b,a)}function J(a,b){return!A(b,a)}function K(a,b,c){return X(a)&&a.length>c?w(a[c],b):!1}function L(a,b,c){return X(a)?!w(a[c],b):!1}function M(a,b){return T.call(a,b)}function N(a,b){return!M(a,b)}function O(a,b){return M(a,"length")?a.length===b:!1}function P(a,b){return M(a,"length")?a.length!==b:!1}function Q(a){Z[a]=function(){this._testers.push(Y[a])}}function R(a){$[a]=function(){var c,d=b(arguments,1),e=Y[a],f=!0;if(d.length<=e.length-1)throw new TypeError("A handler must be defined when calling using switch");if(c=d.pop(),j(c)&&(f=c,c=d.pop()),!V(c))throw new TypeError("handler must be defined");this._cases.push(function(a){return e.apply(Y,a.concat(d))?[f,c.apply(this,a)]:[!1]})}}var S=Array.prototype.slice,T=Object.prototype.hasOwnProperty,U=Object.prototype.toString,V=function(a){return"[object Function]"===U.call(a)};"undefined"==typeof window||V(window.alert)||function(a){V=function(b){return"[object Function]"===U.call(b)||b===a}}(window.alert);var W=function(a){return"[object Arguments]"===U.call(a)};W(arguments)||(W=function(a){return!(!a||!T.call(a,"callee"))});var X=Array.isArray||function(a){return"[object Array]"===U.call(a)},Y={isFunction:V,isObject:g,isEmpty:i,isHash:h,isNumber:s,isString:r,isDate:q,isArray:X,isBoolean:j,isUndefined:k,isDefined:l,isUndefinedOrNull:m,isNull:n,isArguments:W,instanceOf:o,isRegExp:p,deepEqual:e,isTrue:t,isFalse:u,isNotNull:v,isEq:w,isNeq:x,isSeq:y,isSneq:z,isIn:A,isNotIn:B,isLt:C,isLte:D,isGt:E,isGte:F,isLike:G,isNotLike:H,contains:I,notContains:J,has:M,notHas:N,isLength:O,isNotLength:P,containsAt:K,notContainsAt:L},Z={constructor:function(){this._testers=[]},noWrap:{tester:function(){var a=this._testers;return function(b){for(var c=!1,d=0,e=a.length;e>d&&!c;d++)c=a[d](b);return c}}}},$={constructor:function(){this._cases=[],this.__default=null},def:function(a,b){this.__default=b},noWrap:{switcher:function(){var a=this._cases,c=this.__default;return function(){for(var d,e=!1,f=b(arguments),g=0,h=a.length;h>g&&!e;g++)if(d=a[g](f),d.length>1&&(d[1]||d[0]))return d[1];return!e&&c?c.apply(this,f):void 0}}}};for(var _ in Y)T.call(Y,_)&&(R(_),Q(_));var ab=a.define(Y).expose(Y);return ab.tester=a.define(Z),ab.switcher=a.define($),ab}"undefined"!=typeof c?"undefined"!=typeof b&&b.exports&&(b.exports=e(a("extended"))):"function"==typeof define&&define.amd?define(["extended"],function(a){return e(a)}):this.isExtended=e(this.extended)}.call(this)},{__browserify_Buffer:53,extended:46}],57:[function(a,b,c){!function(){"use strict";function d(a){function b(a,b){var c=0;return a>b?1:b>a?-1:b?c:1}var c=a.multiply,d=a.declare({instance:{__printNode:function(b,d){var e=[];a.isUndefinedOrNull(b)?(e.push(c(" ",d)),e.push("~"),console.log(e.join(""))):(this.__printNode(b.right,d+1),e.push(c(" ",d)),e.push(b.data+"\n"),console.log(e.join("")),this.__printNode(b.left,d+1))},constructor:function(a){a=a||{},this.compare=a.compare||b,this.__root=null},insert:function(){throw new Error("Not Implemented")},remove:function(){throw new Error("Not Implemented")},clear:function(){this.__root=null},isEmpty:function(){return!this.__root},traverseWithCondition:function(a,b,c){var e=!0;return a&&(b=b||d.PRE_ORDER,b===d.PRE_ORDER?(e=c(a.data),e&&(e=this.traverseWithCondition(a.left,b,c),e&&(e=this.traverseWithCondition(a.right,b,c)))):b===d.IN_ORDER?(e=this.traverseWithCondition(a.left,b,c),e&&(e=c(a.data),e&&(e=this.traverseWithCondition(a.right,b,c)))):b===d.POST_ORDER?(e=this.traverseWithCondition(a.left,b,c),e&&(e&&(e=this.traverseWithCondition(a.right,b,c)),e&&(e=c(a.data)))):b===d.REVERSE_ORDER&&(e=this.traverseWithCondition(a.right,b,c),e&&(e=c(a.data),e&&(e=this.traverseWithCondition(a.left,b,c))))),e},traverse:function(a,b,c){a&&(b=b||d.PRE_ORDER,b===d.PRE_ORDER?(c(a.data),this.traverse(a.left,b,c),this.traverse(a.right,b,c)):b===d.IN_ORDER?(this.traverse(a.left,b,c),c(a.data),this.traverse(a.right,b,c)):b===d.POST_ORDER?(this.traverse(a.left,b,c),this.traverse(a.right,b,c),c(a.data)):b===d.REVERSE_ORDER&&(this.traverse(a.right,b,c),c(a.data),this.traverse(a.left,b,c)))},forEach:function(a,b,c){if("function"!=typeof a)throw new TypeError;c=c||d.IN_ORDER,b=b||this,this.traverse(this.__root,c,function(c){a.call(b,c,this)})},map:function(a,b,c){if("function"!=typeof a)throw new TypeError;c=c||d.IN_ORDER,b=b||this;var e=new this._static;return this.traverse(this.__root,c,function(c){e.insert(a.call(b,c,this))}),e},filter:function(a,b,c){if("function"!=typeof a)throw new TypeError;c=c||d.IN_ORDER,b=b||this;var e=new this._static;return this.traverse(this.__root,c,function(c){a.call(b,c,this)&&e.insert(c)}),e},reduce:function(b,c,d){var e=this.toArray(d),f=[e,b];return a.isUndefinedOrNull(c)||f.push(c),a.reduce.apply(a,f)},reduceRight:function(b,c,d){var e=this.toArray(d),f=[e,b];return a.isUndefinedOrNull(c)||f.push(c),a.reduceRight.apply(a,f)},every:function(a,b,c){if("function"!=typeof a)throw new TypeError;c=c||d.IN_ORDER,b=b||this;var e=!1;return this.traverseWithCondition(this.__root,c,function(c){return e=a.call(b,c,this)}),e},some:function(a,b,c){if("function"!=typeof a)throw new TypeError;c=c||d.IN_ORDER,b=b||this;var e;return this.traverseWithCondition(this.__root,c,function(c){return e=a.call(b,c,this),!e}),e},toArray:function(a){a=a||d.IN_ORDER;var b=[];return this.traverse(this.__root,a,function(a){b.push(a)}),b},contains:function(a){for(var b=!1,c=this.__root;null!==c;){var d=this.compare(a,c.data);d?c=c[-1===d?"left":"right"]:(b=!0,c=null)}return b},find:function(a){for(var b,c=this.__root;c;){var d=this.compare(a,c.data);if(!d){b=c.data;break}c=c[-1===d?"left":"right"]}return b},findLessThan:function(a,b){var c=[],e=this.compare;return this.traverseWithCondition(this.__root,d.IN_ORDER,function(d){var f=e(a,d);return!b&&0===f||1===f?(c.push(d),!0):!1}),c},findGreaterThan:function(a,b){var c=[],e=this.compare;return this.traverse(this.__root,d.REVERSE_ORDER,function(d){var f=e(a,d);return!b&&0===f||-1===f?(c.push(d),!0):!1}),c},print:function(){this.__printNode(this.__root,0)}},"static":{PRE_ORDER:"pre_order",IN_ORDER:"in_order",POST_ORDER:"post_order",REVERSE_ORDER:"reverse_order"}}),e=function(){var a=Math.abs,b=function(a){return{data:a,balance:0,left:null,right:null}},e=function(a,b,c){var d=a[c];return a[c]=d[b],d[b]=a,d},f=function(a,b,c){return a[c]=e(a[c],c,b),e(a,b,c)},g=function(a,b,c){var d="left"===b?"right":"left",e=a[b],f=e[d];0===f.balance?a.balance=e.balance=0:f.balance===c?(a.balance=-c,e.balance=0):(a.balance=0,e.balance=c),f.balance=0},h=function(a,b){var c="left"===b?"right":"left",d=a[b],h="left"===b?-1:1;return d.balance===h?(a.balance=d.balance=0,a=e(a,c,b)):(g(a,b,h),a=f(a,c,b)),a},i=function(a,b,c){var d="left"===b?"right":"left",h=a[d],i="left"===b?-1:1;return h.balance===-i?(a.balance=h.balance=0,a=e(a,b,d)):h.balance===i?(g(a,d,-i),a=f(a,b,d)):(a.balance=-i,h.balance=i,a=e(a,b,d),c.done=!0),a},j=function(c,d,e,f){if(null===c||void 0===c)c=b(d);else{var g=-1===f(d,c.data)?"left":"right";c[g]=j(c[g],d,e,f),e.done||(c.balance+="left"===g?-1:1,0===c.balance?e.done=!0:a(c.balance)>1&&(c=h(c,g),e.done=!0))}return c},k=function(b,c,d,e){var f,g,h,j;if(b){if(g=e(c,b.data),0===g){var l=b.left,m=b.right;if(!l||!m)return f=l?"left":"right",h=b[f];for(var n=l;null!==(m=n.right);)n=m;b.data=n.data,c=n.data}if(f=-1===e(b.data,c)?"right":"left",b[f]=k(b[f],c,d,e),!d.done){j=b.balance+="left"===f?1:-1;var o=a(j);1===o?d.done=!0:o>1&&(b=i(b,f,d))}}return b};return d.extend({instance:{insert:function(a){var b={done:!1};this.__root=j(this.__root,a,b,this.compare)},remove:function(a){this.__root=k(this.__root,a,{done:!1},this.compare)},__printNode:function(a,b){var d=[];a?(this.__printNode(a.right,b+1),d.push(c(" ",b)),d.push(a.data+":"+a.balance+"\n"),console.log(d.join("")),this.__printNode(a.left,b+1)):(d.push(c(" ",b)),d.push("~"),console.log(d.join("")))}}})}(),f=function(){function a(a,b){return{data:a,level:b,left:g,right:g}}function b(a){if(0!==a.level&&a.left.level===a.level){var b=a.left;a.left=b.right,b.right=a,a=b}return a}function e(a){if(0!==a.level&&a.right.right.level===a.level){var b=a.right;a.right=b.left,b.left=a,a=b,a.level++}return a}function f(c,d,h){if(c===g)c=a(d,1);else{var i=-1===h(d,c.data)?"left":"right";c[i]=f(c[i],d,h),c=b(c),c=e(c)}return c}var g={level:0,data:null},h=function(a,c,d){var f,i;if(a!==g){var j=d(c,a.data);if(0===j)if(f=a.left,i=a.right,f!==g&&i!==g){for(var k=f;k.right!==g;)k=k.right;a.data=k.data,a.left=h(f,k.data,d)}else a=a[f===g?"right":"left"];else{var l=-1===j?"left":"right";a[l]=h(a[l],c,d)}}if(a!==g){var m=a.level,n=a.left.level,o=a.right.level;(m-1>n||m-1>o)&&(o>--a.level&&(a.right.level=a.level),a=b(a),a=e(a))}return a};return d.extend({instance:{isEmpty:function(){return this.__root===g||this._super(arguments)},insert:function(a){this.__root||(this.__root=g),this.__root=f(this.__root,a,this.compare)},remove:function(a){this.__root=h(this.__root,a,this.compare)},traverseWithCondition:function(a){var b=!0;return a!==g?this._super(arguments):b},traverse:function(a){a!==g&&this._super(arguments)},contains:function(){return this.__root!==g?this._super(arguments):!1},__printNode:function(a,b){var d=[];a&&a.data?(this.__printNode(a.right,b+1),d.push(c(" ",b)),d.push(a.data+":"+a.level+"\n"),console.log(d.join("")),this.__printNode(a.left,b+1)):(d.push(c(" ",b)),d.push("~"),console.log(d.join("")))}}})}(),g=d.extend({instance:{insert:function(a){if(!this.__root)return this.__root={data:a,parent:null,left:null,right:null};for(var b=this.compare,c=this.__root;null!==c;){var d=b(a,c.data);if(!d)return;var e=-1===d?"left":"right",f=c[e];if(!f)return c[e]={data:a,parent:c,left:null,right:null};c=f}},remove:function(a){if(null!==this.__root){for(var b,c={right:this.__root},d=c,e=null,f="right";null!==d[f];){b=d,d=d[f];var g=this.compare(a,d.data);g||(e=d),f=-1===g?"left":"right"}null!==e&&(e.data=d.data,b[b.right===d?"right":"left"]=d[null===d.left?"right":"left"]),this.__root=c.right}}}}),h=function(){var a="RED",b="BLACK",e=function(a){return null!==a&&a.red},f=function(a){return{data:a,red:!0,left:null,right:null}},g=function(a,b,c){if(!a)return f(b);var d=c(b,a.data);if(d){var j=-1===d?"left":"right",k="left"===j?"right":"left";a[j]=g(a[j],b,c);var l=a[j];if(e(l)){var m=a[k];e(m)?(a.red=!0,l.red=!1,m.red=!1):e(l[j])?a=h(a,k):e(l[k])&&(a=i(a,k))}}return a},h=function(a,b){var c="left"===b?"right":"left",d=a[c];return a[c]=d[b],d[b]=a,a.red=!0,d.red=!1,d},i=function(a,b){var c="left"===b?"right":"left";return a[c]=h(a[c],c),h(a,b)},j=function(a,b,c,d){if(a){var f;if(0===d(b,a.data)){if(!a.left||!a.right){var g=a[a.left?"left":"right"];return e(a)?c.done=!0:e(g)&&(g.red=!1,c.done=!0),g}for(var h,i=a.right;null!==i.left;)h=i,i=i.left;h&&(h.left=null),a.data=i.data,b=i.data}f=-1===d(b,a.data)?"left":"right",a[f]=j(a[f],b,c,d),c.done||(a=k(a,f,c))}else c.done=!0;return a},k=function(a,b,c){var d="left"===b?"right":"left",f=a,g=f[d];if(e(g)&&(a=h(a,b),g=f[d]),null!==g)if(e(g.left)||e(g.right)){var j=f.red,k=a===f;f=(e(g[d])?h:i)(f,b),f.red=j,f.left.red=f.right.red=0,k?a=f:a[b]=f,c.done=!0}else e(f)&&(c.done=!0),f.red=0,g.red=1;return a};return d.extend({instance:{insert:function(a){this.__root=g(this.__root,a,this.compare),this.__root.red=!1},remove:function(a){var b={done:!1},c=j(this.__root,a,b,this.compare);return null!==c&&(c.red=0),this.__root=c,a},__printNode:function(d,e){var f=[];d?(this.__printNode(d.right,e+1),f.push(c(" ",e)),f.push((d.red?a:b)+":"+d.data+"\n"),console.log(f.join("")),this.__printNode(d.left,e+1)):(f.push(c(" ",e)),f.push("~"),console.log(f.join("")))}}})}();return{Tree:d,AVLTree:e,AnderssonTree:f,BinaryTree:g,RedBlackTree:h,IN_ORDER:d.IN_ORDER,PRE_ORDER:d.PRE_ORDER,POST_ORDER:d.POST_ORDER,REVERSE_ORDER:d.REVERSE_ORDER}}"undefined"!=typeof c?"undefined"!=typeof b&&b.exports&&(b.exports=d(a("extended")().register("declare",a("declare.js")).register(a("is-extended")).register(a("array-extended")).register(a("string-extended")))):"function"==typeof define?define(["extended","declare.js","is-extended","array-extended","string-extended"],function(a,b,c,e,f){return d(a().register("declare",b).register(c).register(e).register(f))}):this.leafy=d(this.extended().register("declare",this.declare).register(this.isExtended).register(this.arrayExtended).register(this.stringExtended))}.call(this)},{"array-extended":42,"declare.js":45,extended:46,"is-extended":56,"string-extended":60}],58:[function(a,b,c){!function(){"use strict";function d(a,b,c){function d(a,b){var c,d;for(c in b)t.call(b,c)&&(d=b[c],c in a&&a[c]===d||(a[c]=d));return a}function e(a,b){var c,d,f;for(c in b)t.call(b,c)&&(d=b[c],f=a[c],p(f,d)||(a[c]=r(f)&&r(d)?e(f,d):r(d)?e({},d):d));return a}function f(a){a||(a={});for(var b=1,c=arguments.length;c>b;b++)d(a,arguments[b]);return a}function g(a){a||(a={});for(var b=1,c=arguments.length;c>b;b++)e(a,arguments[b]);return a}function h(a,b){var c=a.prototype||a;return f(c,b),a}function i(a,b,c){if(!r(a)||!u(b))throw new TypeError;for(var d,e=l(a),f=0,g=e.length;g>f;++f)d=e[f],b.call(c||a,a[d],d,a);return a}function j(a,b,c){if(!r(a)||!u(b))throw new TypeError;for(var d,e,f=l(a),g={},h=0,i=f.length;i>h;++h)d=f[h],e=a[d],b.call(c||a,e,d,a)&&(g[d]=e);return g}function k(a){if(!r(a))throw new TypeError;for(var b=l(a),c=[],d=0,e=b.length;e>d;++d)c.push(a[b[d]]);return c}function l(a){if(!r(a))throw new TypeError;var b=[];for(var c in a)t.call(a,c)&&b.push(c);return b}function m(a){if(!r(a))throw new TypeError;for(var b,c=l(a),d={},e=0,f=c.length;f>e;++e)b=c[e],d[a[b]]=b;return d}function n(a){if(!r(a))throw new TypeError;for(var b,c=l(a),d=[],e=0,f=c.length;f>e;++e)b=c[e],d.push([b,a[b]]);return d}function o(a,b){if(!r(a))throw new TypeError;q(b)&&(b=[b]);for(var c,d=s(l(a),b),e={},f=0,g=d.length;g>f;++f)c=d[f],e[c]=a[c];return e}var p=b.deepEqual,q=b.isString,r=b.isHash,s=c.difference,t=Object.prototype.hasOwnProperty,u=b.isFunction,v={forEach:i,filter:j,invert:m,values:k,toArray:n,keys:l,omit:o},w={extend:h,merge:f,deepMerge:g,omit:o},x=a.define(b.isObject,w).define(r,v).define(b.isFunction,{extend:h}).expose({hash:v}).expose(w),y=x.extend;return x.extend=function(){return 1===arguments.length?y.extend.apply(x,arguments):(h.apply(null,arguments),void 0)},x}"undefined"!=typeof c?"undefined"!=typeof b&&b.exports&&(b.exports=d(a("extended"),a("is-extended"),a("array-extended"))):"function"==typeof define&&define.amd?define(["extended","is-extended","array-extended"],function(a,b,c){return d(a,b,c)}):this.objectExtended=d(this.extended,this.isExtended,this.arrayExtended)}.call(this)},{"array-extended":42,extended:46,"is-extended":56}],59:[function(a,b,c){var d=a("__browserify_process");!function(){"use strict";function e(a,b,c,e,f,g){function h(a,b){return function(){try{l(a.apply(null,arguments)).addCallback(b).addErrback(b)}catch(c){b.errback(c)}}}function i(a,b,c){var d=(new G).callback();return v(a,function(a){d=d.then(c?a:B(null,a)),c||(d=d.then(function(a){return b.push(a),b}))}),d}function j(a){return!w(a)&&y(a.then)}function k(a){var b=new G;return a.then(A(b,"callback"),A(b,"errback")),b.promise()}function l(a){var b;return a=C(arguments),a.length?1===a.length?(a=a.pop(),j(a)?a.addCallback&&a.addErrback?(b=new G,a.addCallback(b.callback),a.addErrback(b.errback)):b=k(a):b=x(a)&&c.every(a,j)?new H(a,!0).promise():(new G).callback(a)):b=new H(c.map(a,function(a){return l(a)}),!0).promise():b=(new G).callback(a).promise(),b}function m(a,b){return function(){var c=new G,d=C(arguments);return d.push(c.resolve),a.apply(b||this,d),c.promise()}}function n(a){if(x(a))return i(a,[],!1);throw new Error("When calling promise.serial the first argument must be an array")}function o(a){if(x(a))return i(a,[],!0);throw new Error("When calling promise.serial the first argument must be an array")}function p(a,b){a=C(arguments);var c=!1;b=a.pop();var d=l(a);return function(){return c?l(b.apply(this,arguments)):(a=arguments,d.then(A(this,function(){return c=!0,b.apply(this,a)})))}}function q(){return new G}function r(a){return new H(a,!0).promise()}function s(a){return q().errback(a)}function t(a){return q().callback(a)}var u,v=c.forEach,w=e.isUndefinedOrNull,x=e.isArray,y=e.isFunction,z=e.isBoolean,A=f.bind,B=f.bindIgnore,C=g.argsToArray;if("function"==typeof setImmediate)u="undefined"!=typeof window?setImmediate.bind(window):setImmediate;else if("undefined"!=typeof d)u=function(a){d.nextTick(a)};else if("undefined"!=typeof MessageChannel){var D=new MessageChannel,E={},F=E;D.port1.onmessage=function(){E=E.next;var a=E.task;delete E.task,a()},u=function(a){F=F.next={task:a},D.port2.postMessage(0)}}else u=function(a){setTimeout(a,0)};var G=a({instance:{__fired:!1,__results:null,__error:null,__errorCbs:null,__cbs:null,constructor:function(){this.__errorCbs=[],this.__cbs=[],f.bindAll(this,["callback","errback","resolve","classic","__resolve","addCallback","addErrback"])},__resolve:function(){if(!this.__fired){this.__fired=!0;var a,b=this.__error?this.__errorCbs:this.__cbs,c=b.length,d=this.__error||this.__results;for(a=0;c>a;a++)this.__callNextTick(b[a],d)}},__callNextTick:function(a,b){u(function(){a.apply(this,b) -})},addCallback:function(a){return a&&(j(a)&&a.callback&&(a=a.callback),this.__fired&&this.__results?this.__callNextTick(a,this.__results):this.__cbs.push(a)),this},addErrback:function(a){return a&&(j(a)&&a.errback&&(a=a.errback),this.__fired&&this.__error?this.__callNextTick(a,this.__error):this.__errorCbs.push(a)),this},callback:function(){return this.__fired||(this.__results=arguments,this.__resolve()),this.promise()},errback:function(){return this.__fired||(this.__error=arguments,this.__resolve()),this.promise()},resolve:function(a){return a?this.errback(a):this.callback.apply(this,C(arguments,1)),this},classic:function(a){return"function"==typeof a&&(this.addErrback(function(b){a(b)}),this.addCallback(function(){a.apply(this,[null].concat(C(arguments)))})),this},then:function(a,b){var c=new G,d=c;return y(b)&&(d=h(b,c)),this.addErrback(d),y(a)?this.addCallback(h(a,c)):this.addCallback(c),c.promise()},both:function(a){return this.then(a,a)},promise:function(){var a={then:A(this,"then"),both:A(this,"both"),promise:function(){return a}};return v(["addCallback","addErrback","classic"],function(b){a[b]=A(this,function(){return this[b].apply(this,arguments),a})},this),a}}}),H=G.extend({instance:{__results:null,__errors:null,__promiseLength:0,__defLength:0,__firedLength:0,normalizeResults:!1,constructor:function(a,b){this.__errors=[],this.__results=[],this.normalizeResults=z(b)?b:!1,this._super(arguments),a&&a.length?(this.__defLength=a.length,v(a,this.__addPromise,this)):this.__resolve()},__addPromise:function(a,b){a.then(A(this,function(){var a=C(arguments);a.unshift(b),this.callback.apply(this,a)}),A(this,function(){var a=C(arguments);a.unshift(b),this.errback.apply(this,a)}))},__resolve:function(){if(!this.__fired){this.__fired=!0;var a,b=this.__errors.length?this.__errorCbs:this.__cbs,c=b.length,d=this.__errors.length?this.__errors:this.__results;for(a=0;c>a;a++)this.__callNextTick(b[a],d)}},__callNextTick:function(a,b){u(function(){a.apply(null,[b])})},addCallback:function(a){return a&&(j(a)&&a.callback&&(a=A(a,"callback")),this.__fired&&!this.__errors.length?this.__callNextTick(a,this.__results):this.__cbs.push(a)),this},addErrback:function(a){return a&&(j(a)&&a.errback&&(a=A(a,"errback")),this.__fired&&this.__errors.length?this.__callNextTick(a,this.__errors):this.__errorCbs.push(a)),this},callback:function(a){if(this.__fired)throw new Error("Already fired!");var b=C(arguments);return this.normalizeResults&&(b=b.slice(1),b=1===b.length?b.pop():b),this.__results[a]=b,this.__firedLength++,this.__firedLength===this.__defLength&&this.__resolve(),this.promise()},errback:function(a){if(this.__fired)throw new Error("Already fired!");var b=C(arguments);return this.normalizeResults&&(b=b.slice(1),b=1===b.length?b.pop():b),this.__errors[a]=b,this.__firedLength++,this.__firedLength===this.__defLength&&this.__resolve(),this.promise()}}});return b.define({isPromiseLike:j}).expose({isPromiseLike:j,when:l,wrap:m,wait:p,serial:n,chain:o,Promise:G,PromiseList:H,promise:q,defer:q,deferredList:r,reject:s,resolve:t})}"undefined"!=typeof c?"undefined"!=typeof b&&b.exports&&(b.exports=e(a("declare.js"),a("extended"),a("array-extended"),a("is-extended"),a("function-extended"),a("arguments-extended"))):"function"==typeof define&&define.amd?define(["declare","extended","array-extended","is-extended","function-extended","arguments-extended"],function(a,b,c,d,f,g){return e(a,b,c,d,f,g)}):this.promiseExtended=e(this.declare,this.extended,this.arrayExtended,this.isExtended,this.functionExtended,this.argumentsExtended)}.call(this)},{__browserify_process:54,"arguments-extended":41,"array-extended":42,"declare.js":45,extended:46,"function-extended":49,"is-extended":56}],60:[function(a,b,c){!function(){"use strict";function d(a,b,c,d){function e(a,b){var c=a;if(x.test(b)){var d=b.match(x),e=d[1],f=d[3],g=d[4];g&&(g=parseInt(g,10),c=c.length0?"+":"")+d),k&&(k=parseInt(k,10),d=d.lengthe;)d?a+=c:a=c+a,e++;return a}function i(a,c,d){var e=a;if(b.isString(e)){if(a.length>c)if(d){var f=a.length;e=a.substring(f-c,f)}else e=a.substring(0,c)}else e=i(""+e,c);return e}function j(a,d){if(d instanceof Array){var h=0,i=d.length;return a.replace(v,function(a,b,j){var k,l;if(!(i>h))return a;if(k=d[h++],"%s"===a||"%d"===a||"%D"===a)l=k+"";else if("%Z"===a)l=k.toUTCString();else if("%j"===a)try{l=s(k)}catch(m){throw new Error("stringExtended.format : Unable to parse json from ",k)}else switch(b=b.replace(/^\[|\]$/g,""),j){case"s":l=e(k,b);break;case"d":l=f(k,b);break;case"j":l=g(k,b);break;case"D":l=c.format(k,b);break;case"Z":l=c.format(k,b,!0)}return l})}if(t(d))return a.replace(w,function(a,h,i){if(i=d[i],!b.isUndefined(i)){if(!h)return""+i;if(b.isString(i))return e(i,h);if(b.isNumber(i))return f(i,h);if(b.isDate(i))return c.format(i,h);if(b.isObject(i))return g(i,h)}return a});var k=u.call(arguments).slice(1);return j(a,k)}function k(a,b){var c=[];return a&&(a.indexOf(b)>0?c=a.replace(/\s+/g,"").split(b):c.push(a)),c}function l(a,b){var c=[];if(b)for(var d=0;b>d;d++)c.push(a);return c.join("")}function m(a,c){var d,e,f;if(c)if(b.isArray(a))for(d=[],e=0,f=a.length;f>e;e++)d.push(m(a[e],c));else if(c instanceof Array)for(d=a,e=0,f=c.length;f>e;e++)d=m(d,c[e]);else c in z&&(d="["+z[c]+"m"+a+"");return d}function n(a,b){return a.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g,function(a){return b&&-1!==d.indexOf(b,a)?a:"\\"+a})}function o(a){return a.replace(/^\s*|\s*$/g,"")}function p(a){return a.replace(/^\s*/,"")}function q(a){return a.replace(/\s*$/,"")}function r(a){return 0===a.length}var s;"undefined"==typeof JSON?function(){function a(a){return 10>a?"0"+a:a}function c(c){return b.isDate(c)?isFinite(c.valueOf())?c.getUTCFullYear()+"-"+a(c.getUTCMonth()+1)+"-"+a(c.getUTCDate())+"T"+a(c.getUTCHours())+":"+a(c.getUTCMinutes())+":"+a(c.getUTCSeconds())+"Z":null:i(c)?c.valueOf():c}function d(a){return j.lastIndex=0,j.test(a)?'"'+a.replace(j,function(a){var b=k[a];return"string"==typeof b?b:"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+a+'"'}function e(a,b){var i,j,k,l,m,n=f,o=b[a];switch(o&&(o=c(o)),"function"==typeof h&&(o=h.call(b,a,o)),typeof o){case"string":return d(o);case"number":return isFinite(o)?String(o):"null";case"boolean":case"null":return String(o);case"object":if(!o)return"null";if(f+=g,m=[],"[object Array]"===Object.prototype.toString.apply(o)){for(l=o.length,i=0;l>i;i+=1)m[i]=e(i,o)||"null";return k=0===m.length?"[]":f?"[\n"+f+m.join(",\n"+f)+"\n"+n+"]":"["+m.join(",")+"]",f=n,k}if(h&&"object"==typeof h)for(l=h.length,i=0;l>i;i+=1)"string"==typeof h[i]&&(j=h[i],k=e(j,o),k&&m.push(d(j)+(f?": ":":")+k));else for(j in o)Object.prototype.hasOwnProperty.call(o,j)&&(k=e(j,o),k&&m.push(d(j)+(f?": ":":")+k));return k=0===m.length?"{}":f?"{\n"+f+m.join(",\n"+f)+"\n"+n+"}":"{"+m.join(",")+"}",f=n,k}}var f,g,h,i=b.tester().isString().isNumber().isBoolean().tester(),j=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,k={"\b":"\\b"," ":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"};s=function(a,b,c){var d;if(f="",g="","number"==typeof c)for(d=0;c>d;d+=1)g+=" ";else"string"==typeof c&&(g=c);if(h=b,b&&"function"!=typeof b&&("object"!=typeof b||"number"!=typeof b.length))throw new Error("JSON.stringify");return e("",{"":a})}}():s=JSON.stringify;var t=b.isHash,u=Array.prototype.slice,v=/%((?:-?\+?.?\d*)?|(?:\[[^\[|\]]*\]))?([sjdDZ])/g,w=/\{(?:\[([^\[|\]]*)\])?(\w+)\}/g,x=/(-?)(\+?)([A-Z|a-z|\W]?)([1-9][0-9]*)?$/,y=/([1-9][0-9]*)$/g,z={bold:1,bright:1,italic:3,underline:4,blink:5,inverse:7,crossedOut:9,red:31,green:32,yellow:33,blue:34,magenta:35,cyan:36,white:37,redBackground:41,greenBackground:42,yellowBackground:43,blueBackground:44,magentaBackground:45,cyanBackground:46,whiteBackground:47,encircled:52,overlined:53,grey:90,black:90},A={SMILEY:"☺",SOLID_SMILEY:"☻",HEART:"♥",DIAMOND:"♦",CLOVE:"♣",SPADE:"♠",DOT:"•",SQUARE_CIRCLE:"◘",CIRCLE:"○",FILLED_SQUARE_CIRCLE:"◙",MALE:"♂",FEMALE:"♀",EIGHT_NOTE:"♪",DOUBLE_EIGHTH_NOTE:"♫",SUN:"☼",PLAY:"►",REWIND:"◄",UP_DOWN:"↕",PILCROW:"¶",SECTION:"§",THICK_MINUS:"▬",SMALL_UP_DOWN:"↨",UP_ARROW:"↑",DOWN_ARROW:"↓",RIGHT_ARROW:"→",LEFT_ARROW:"←",RIGHT_ANGLE:"∟",LEFT_RIGHT_ARROW:"↔",TRIANGLE:"▲",DOWN_TRIANGLE:"▼",HOUSE:"⌂",C_CEDILLA:"Ç",U_UMLAUT:"ü",E_ACCENT:"é",A_LOWER_CIRCUMFLEX:"â",A_LOWER_UMLAUT:"ä",A_LOWER_GRAVE_ACCENT:"à",A_LOWER_CIRCLE_OVER:"å",C_LOWER_CIRCUMFLEX:"ç",E_LOWER_CIRCUMFLEX:"ê",E_LOWER_UMLAUT:"ë",E_LOWER_GRAVE_ACCENT:"è",I_LOWER_UMLAUT:"ï",I_LOWER_CIRCUMFLEX:"î",I_LOWER_GRAVE_ACCENT:"ì",A_UPPER_UMLAUT:"Ä",A_UPPER_CIRCLE:"Å",E_UPPER_ACCENT:"É",A_E_LOWER:"æ",A_E_UPPER:"Æ",O_LOWER_CIRCUMFLEX:"ô",O_LOWER_UMLAUT:"ö",O_LOWER_GRAVE_ACCENT:"ò",U_LOWER_CIRCUMFLEX:"û",U_LOWER_GRAVE_ACCENT:"ù",Y_LOWER_UMLAUT:"ÿ",O_UPPER_UMLAUT:"Ö",U_UPPER_UMLAUT:"Ü",CENTS:"¢",POUND:"£",YEN:"¥",CURRENCY:"¤",PTS:"₧",FUNCTION:"ƒ",A_LOWER_ACCENT:"á",I_LOWER_ACCENT:"í",O_LOWER_ACCENT:"ó",U_LOWER_ACCENT:"ú",N_LOWER_TILDE:"ñ",N_UPPER_TILDE:"Ñ",A_SUPER:"ª",O_SUPER:"º",UPSIDEDOWN_QUESTION:"¿",SIDEWAYS_L:"⌐",NEGATION:"¬",ONE_HALF:"½",ONE_FOURTH:"¼",UPSIDEDOWN_EXCLAMATION:"¡",DOUBLE_LEFT:"«",DOUBLE_RIGHT:"»",LIGHT_SHADED_BOX:"░",MEDIUM_SHADED_BOX:"▒",DARK_SHADED_BOX:"▓",VERTICAL_LINE:"│",MAZE__SINGLE_RIGHT_T:"┤",MAZE_SINGLE_RIGHT_TOP:"┐",MAZE_SINGLE_RIGHT_BOTTOM_SMALL:"┘",MAZE_SINGLE_LEFT_TOP_SMALL:"┌",MAZE_SINGLE_LEFT_BOTTOM_SMALL:"└",MAZE_SINGLE_LEFT_T:"├",MAZE_SINGLE_BOTTOM_T:"┴",MAZE_SINGLE_TOP_T:"┬",MAZE_SINGLE_CENTER:"┼",MAZE_SINGLE_HORIZONTAL_LINE:"─",MAZE_SINGLE_RIGHT_DOUBLECENTER_T:"╡",MAZE_SINGLE_RIGHT_DOUBLE_BL:"╛",MAZE_SINGLE_RIGHT_DOUBLE_T:"╢",MAZE_SINGLE_RIGHT_DOUBLEBOTTOM_TOP:"╖",MAZE_SINGLE_RIGHT_DOUBLELEFT_TOP:"╕",MAZE_SINGLE_LEFT_DOUBLE_T:"╞",MAZE_SINGLE_BOTTOM_DOUBLE_T:"╧",MAZE_SINGLE_TOP_DOUBLE_T:"╤",MAZE_SINGLE_TOP_DOUBLECENTER_T:"╥",MAZE_SINGLE_BOTTOM_DOUBLECENTER_T:"╨",MAZE_SINGLE_LEFT_DOUBLERIGHT_BOTTOM:"╘",MAZE_SINGLE_LEFT_DOUBLERIGHT_TOP:"╒",MAZE_SINGLE_LEFT_DOUBLEBOTTOM_TOP:"╓",MAZE_SINGLE_LEFT_DOUBLETOP_BOTTOM:"╙",MAZE_SINGLE_LEFT_TOP:"Γ",MAZE_SINGLE_RIGHT_BOTTOM:"╜",MAZE_SINGLE_LEFT_CENTER:"╟",MAZE_SINGLE_DOUBLECENTER_CENTER:"╫",MAZE_SINGLE_DOUBLECROSS_CENTER:"╪",MAZE_DOUBLE_LEFT_CENTER:"╣",MAZE_DOUBLE_VERTICAL:"║",MAZE_DOUBLE_RIGHT_TOP:"╗",MAZE_DOUBLE_RIGHT_BOTTOM:"╝",MAZE_DOUBLE_LEFT_BOTTOM:"╚",MAZE_DOUBLE_LEFT_TOP:"╔",MAZE_DOUBLE_BOTTOM_T:"╩",MAZE_DOUBLE_TOP_T:"╦",MAZE_DOUBLE_LEFT_T:"╠",MAZE_DOUBLE_HORIZONTAL:"═",MAZE_DOUBLE_CROSS:"╬",SOLID_RECTANGLE:"█",THICK_LEFT_VERTICAL:"▌",THICK_RIGHT_VERTICAL:"▐",SOLID_SMALL_RECTANGLE_BOTTOM:"▄",SOLID_SMALL_RECTANGLE_TOP:"▀",PHI_UPPER:"Φ",INFINITY:"∞",INTERSECTION:"∩",DEFINITION:"≡",PLUS_MINUS:"±",GT_EQ:"≥",LT_EQ:"≤",THEREFORE:"⌠",SINCE:"∵",DOESNOT_EXIST:"∄",EXISTS:"∃",FOR_ALL:"∀",EXCLUSIVE_OR:"⊕",BECAUSE:"⌡",DIVIDE:"÷",APPROX:"≈",DEGREE:"°",BOLD_DOT:"∙",DOT_SMALL:"·",CHECK:"√",ITALIC_X:"✗",SUPER_N:"ⁿ",SQUARED:"²",CUBED:"³",SOLID_BOX:"■",PERMILE:"‰",REGISTERED_TM:"®",COPYRIGHT:"©",TRADEMARK:"™",BETA:"β",GAMMA:"γ",ZETA:"ζ",ETA:"η",IOTA:"ι",KAPPA:"κ",LAMBDA:"λ",NU:"ν",XI:"ξ",OMICRON:"ο",RHO:"ρ",UPSILON:"υ",CHI_LOWER:"φ",CHI_UPPER:"χ",PSI:"ψ",ALPHA:"α",ESZETT:"ß",PI:"π",SIGMA_UPPER:"Σ",SIGMA_LOWER:"σ",MU:"µ",TAU:"τ",THETA:"Θ",OMEGA:"Ω",DELTA:"δ",PHI_LOWER:"φ",EPSILON:"ε"},B={toArray:k,pad:h,truncate:i,multiply:l,format:j,style:m,escape:n,trim:o,trimLeft:p,trimRight:q,isEmpty:r};return a.define(b.isString,B).define(b.isArray,{style:m}).expose(B).expose({characters:A})}"undefined"!=typeof c?"undefined"!=typeof b&&b.exports&&(b.exports=d(a("extended"),a("is-extended"),a("date-extended"),a("array-extended"))):"function"==typeof define&&define.amd?define(["extended","is-extended","date-extended","array-extended"],function(a,b,c,e){return d(a,b,c,e)}):this.stringExtended=d(this.extended,this.isExtended,this.dateExtended,this.arrayExtended)}.call(this)},{"array-extended":42,"date-extended":43,extended:46,"is-extended":56}]},{},[1]); \ No newline at end of file +!function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);throw new Error("Cannot find module '"+g+"'")}var j=c[g]={exports:{}};b[g][0].call(j.exports,function(a){var c=b[g][1][a];return e(c?c:a)},j,j.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;gc&&g>c&&c++;);var h=d[c]-e[c];return h||(h=f-g),h}function g(a,b){return a.recency-b.recency}var h=a("./extended").map,i={salience:d,bucketCounter:e,factRecency:f,activationRecency:g};c.strategies=i,c.strategy=function(a){a=h(a,function(a){return i[a]});var b=a.length;return function(c,d){var e=-1,f=0,g=c===d||c.name===d.name&&c.hashCode===d.hashCode;if(!g){for(;++e0?1:-1}return f}}},{"./extended":12}],8:[function(a,b,c){"use strict";var d,e=a("./extended"),f=e.deepEqual,g=e.merge,h=e.instanceOf,i=e.filter,j=e.declare,k=0,l=j({type:null,instance:{constructor:function(b){d||(d=a("./constraintMatcher")),this.id=k++,this.constraint=b,e.bindAll(this,["assert"])},assert:function(){throw new Error("not implemented")},getIndexableProperties:function(){return[]},equal:function(a){return h(a,this._static)&&this.get("alias")===a.get("alias")&&e.deepEqual(this.constraint,a.constraint)},getters:{variables:function(){return[this.get("alias")]}}}});l.extend({instance:{type:"object",constructor:function(a){this._super([a])},assert:function(a){return a instanceof this.constraint||a.constructor===this.constraint},equal:function(a){return h(a,this._static)&&this.constraint===a.constraint}}}).as(c,"ObjectConstraint");var m=l.extend({instance:{type:"equality",constructor:function(a,b){this._super([a]),b=b||{},this.pattern=b.pattern,this._matcher=d.getMatcher(a,b,!0)},assert:function(a){return this._matcher(a)}}}).as(c,"EqualityConstraint");m.extend({instance:{type:"inequality"}}).as(c,"InequalityConstraint"),m.extend({instance:{type:"comparison"}}).as(c,"ComparisonConstraint"),l.extend({instance:{type:"equality",constructor:function(){this._super([[!0]])},equal:function(a){return h(a,this._static)&&this.get("alias")===a.get("alias")},assert:function(){return!0}}}).as(c,"TrueConstraint");var n=l.extend({instance:{type:"reference",constructor:function(a,b){this.cache={},this._super([a]),b=b||{},this.values=[],this.pattern=b.pattern,this._options=b,this._matcher=d.getMatcher(a,b,!1)},assert:function(a,b){try{return this._matcher(a,b)}catch(c){throw new Error("Error with evaluating pattern "+this.pattern+" "+c.message)}},merge:function(a){var b=this;return a instanceof n&&(b=new this._static([this.constraint,a.constraint,"and"],g({},this._options,this._options)),b._alias=this._alias||a._alias,b.vars=this.vars.concat(a.vars)),b},equal:function(a){return h(a,this._static)&&e.deepEqual(this.constraint,a.constraint)},getters:{variables:function(){return this.vars},alias:function(){return this._alias}},setters:{alias:function(a){this._alias=a,this.vars=i(d.getIdentifiers(this.constraint),function(b){return b!==a})}}}}).as(c,"ReferenceConstraint");n.extend({instance:{type:"reference_equality",op:"eq",getIndexableProperties:function(){return d.getIndexableProperties(this.constraint)}}}).as(c,"ReferenceEqualityConstraint").extend({instance:{type:"reference_inequality",op:"neq"}}).as(c,"ReferenceInequalityConstraint"),l.extend({instance:{type:"hash",constructor:function(a){this._super([a])},equal:function(a){return e.instanceOf(a,this._static)&&this.get("alias")===a.get("alias")&&e.deepEqual(this.constraint,a.constraint)},assert:function(){return!0},getters:{variables:function(){return this.constraint}}}}).as(c,"HashConstraint"),l.extend({instance:{constructor:function(a,b){this.type="from",this.constraints=d.getSourceMatcher(a,b||{},!0),e.bindAll(this,["assert"])},equal:function(a){return h(a,this._static)&&this.get("alias")===a.get("alias")&&f(this.constraints,a.constraints)},assert:function(a,b){return this.constraints(a,b)},getters:{variables:function(){return this.constraint}}}}).as(c,"FromConstraint")},{"./constraintMatcher":9,"./extended":12}],9:[function(a,b,c){"use strict";function d(a){return e(a).map(function(a){return f(a)?f(a[0])?d(a).value():a.reverse().join("."):a}).flatten().filter(function(a){return!!a})}var e=a("./extended"),f=e.isArray,g=e.forEach,h=e.some,i=e.indexOf,j=e.isNumber,k=e.removeDuplicates,l=a("./constraint"),m={indexOf:e.indexOf,now:function(){return new Date},Date:function(a,b,c,d,e,f,g){var h=new Date;return j(a)&&h.setYear(a),j(b)&&h.setMonth(b),j(c)&&h.setDate(c),j(d)&&h.setHours(d),j(e)&&h.setMinutes(e),j(f)&&h.setSeconds(f),j(g)&&h.setMilliseconds(g),h},lengthOf:function(a,b){return a.length===b},isTrue:function(a){return a===!0},isFalse:function(a){return a===!1},isNotNull:function(a){return null!==a},dateCmp:function(a,b){return e.compare(a,b)}};g(["years","days","months","hours","minutes","seconds"],function(a){m[a+"FromNow"]=e[a+"FromNow"],m[a+"Ago"]=e[a+"Ago"]}),g(["isArray","isNumber","isHash","isObject","isDate","isBoolean","isString","isRegExp","isNull","isEmpty","isUndefined","isDefined","isUndefinedOrNull","isPromiseLike","isFunction","deepEqual"],function(a){var b=e[a];m[a]=function(){return b.apply(e,arguments)}});var n={equal:function(a,b){var c=!1;return a===b?c=!0:a[2]===b[2]&&(c=-1!==i(["string","number","boolean","regexp","identifier","null"],a[2])?a[0]===b[0]:"unary"===a[2]||"logicalNot"===a[2]?this.equal(a[0],b[0]):this.equal(a[0],b[0])&&this.equal(a[1],b[1])),c},__getProperties:function(a){var b=[];if(a){var c=a[2];if(!c)return b;"prop"!==c&&"identifier"!==c&&"string"!==c&&"number"!==c&&"boolean"!==c&&"regexp"!==c&&"unary"!==c&&"unary"!==c?(b[0]=this.__getProperties(a[0]),b[1]=this.__getProperties(a[1])):b="identifier"===c?[a[0]]:n.__getProperties(a[1]).concat(n.__getProperties(a[0]))}return b},getIndexableProperties:function(a){return"composite"===a[2]?this.getIndexableProperties(a[0]):/^(\w+(\['[^']*'])*) *[!=]== (\w+(\['[^']*'])*)$/.test(this.parse(a))?d(this.__getProperties(a)).flatten().value():[]},getIdentifiers:function(a){var b=[],c=a[2];if("identifier"===c)return[a[0]];if("function"===c)b=b.concat(this.getIdentifiers(a[0])).concat(this.getIdentifiers(a[1]));else if("string"!==c&&"number"!==c&&"boolean"!==c&&"regexp"!==c&&"unary"!==c&&"unary"!==c)if("prop"===c){if(b=b.concat(this.getIdentifiers(a[0])),a[1])for(var d=a[1];f(d);){if("function"===d[2]){b=b.concat(this.getIdentifiers(d[1]));break}d=d[1]}}else a[0]&&(b=b.concat(this.getIdentifiers(a[0]))),a[1]&&(b=b.concat(this.getIdentifiers(a[1])));return k(b)},toConstraints:function(a,b){var c=[],d=b.alias,e=b.scope||{},f=a[2];if("and"===f)c=c.concat(this.toConstraints(a[0],b)).concat(this.toConstraints(a[1],b));else if("composite"===f||"or"===f||"lt"===f||"gt"===f||"lte"===f||"gte"===f||"like"===f||"notLike"===f||"eq"===f||"neq"===f||"in"===f||"notIn"===f||"prop"===f||"propLookup"===f||"function"===f||"logicalNot"===f){var g=h(this.getIdentifiers(a),function(a){return!(a===d||a in m||a in e)});"eq"===f?c.push(new l[g?"ReferenceEqualityConstraint":"EqualityConstraint"](a,b)):"neq"===f?c.push(new l[g?"ReferenceInequalityConstraint":"InequalityConstraint"](a,b)):c.push(new l[g?"ReferenceConstraint":"ComparisonConstraint"](a,b))}return c},parse:function(a){return this[a[2]](a[0],a[1])},composite:function(a){return this.parse(a)},and:function(a,b){return["(",this.parse(a),"&&",this.parse(b),")"].join(" ")},or:function(a,b){return["(",this.parse(a),"||",this.parse(b),")"].join(" ")},prop:function(a,b){return"function"===b[2]?[this.parse(a),this.parse(b)].join("."):[this.parse(a),"['",this.parse(b),"']"].join("")},propLookup:function(a,b){return"function"===b[2]?[this.parse(a),this.parse(b)].join("."):[this.parse(a),"[",this.parse(b),"]"].join("")},unary:function(a){return-1*this.parse(a)},plus:function(a,b){return[this.parse(a),"+",this.parse(b)].join(" ")},minus:function(a,b){return[this.parse(a),"-",this.parse(b)].join(" ")},mult:function(a,b){return[this.parse(a),"*",this.parse(b)].join(" ")},div:function(a,b){return[this.parse(a),"/",this.parse(b)].join(" ")},mod:function(a,b){return[this.parse(a),"%",this.parse(b)].join(" ")},lt:function(a,b){return[this.parse(a),"<",this.parse(b)].join(" ")},gt:function(a,b){return[this.parse(a),">",this.parse(b)].join(" ")},lte:function(a,b){return[this.parse(a),"<=",this.parse(b)].join(" ")},gte:function(a,b){return[this.parse(a),">=",this.parse(b)].join(" ")},like:function(a,b){return[this.parse(b),".test(",this.parse(a),")"].join("")},notLike:function(a,b){return["!",this.parse(b),".test(",this.parse(a),")"].join("")},eq:function(a,b){return[this.parse(a),"===",this.parse(b)].join(" ")},neq:function(a,b){return[this.parse(a),"!==",this.parse(b)].join(" ")},"in":function(a,b){return["(indexOf(",this.parse(b),",",this.parse(a),")) != -1"].join("")},notIn:function(a,b){return["(indexOf(",this.parse(b),",",this.parse(a),")) == -1"].join("")},arguments:function(a,b){var c=[];return a&&c.push(this.parse(a)),b&&c.push(this.parse(b)),c.join(",")},array:function(a){var b=[];return a?(b=this.parse(a),f(b)?b:["[",b,"]"].join("")):["[",b.join(","),"]"].join("")},"function":function(a,b){var c=this.parse(b);return[this.parse(a),"(",c,")"].join("")},string:function(a){return"'"+a+"'"},number:function(a){return a},"boolean":function(a){return a},regexp:function(a){return a},identifier:function(a){return a},"null":function(){return"null"},logicalNot:function(a){return["!(",this.parse(a),")"].join("")}},o=0,p=c.toJs=function(a,b,c,d,f){var g=n.parse(a);b=b||{};var h=n.getIdentifiers(a),i=["var indexOf = definedFuncs.indexOf; var hasOwnProperty = Object.prototype.hasOwnProperty;"],j=[];e(h).filter(function(a){var c=["var ",a," = "];if(m.hasOwnProperty(a))c.push("definedFuncs['",a,"']");else{if(!b.hasOwnProperty(a))return!0;c.push("scope['",a,"']")}return c.push(";"),i.push(c.join("")),!1}).forEach(function(a){var b=["var ",a," = "];d||a!==c?b.push("fact."+a):a===c&&b.push("hash.",a,""),b.push(";"),j.push(b.join(""))});var k=i.join("")+"return function matcher"+o++ +(d?"(fact){":"(fact, hash){")+j.join("")+" return "+(f?f(g):g)+";}",l=new Function("definedFuncs, scope",k)(m,b);return l};c.getMatcher=function(a,b,c){return b=b||{},p(a,b.scope,b.alias,c,function(a){return"!!("+a+")"})},c.getSourceMatcher=function(a,b,c){return b=b||{},p(a,b.scope,b.alias,c,function(a){return a})},c.toConstraints=function(a,b){return n.toConstraints(a,b)},c.equal=function(a,b){return n.equal(a,b)},c.getIdentifiers=function(a){return n.getIdentifiers(a)},c.getIndexableProperties=function(a){return n.getIndexableProperties(a)}},{"./constraint":8,"./extended":12}],10:[function(a,b){"use strict";function c(a,b){for(var c=[],d=-1,e=a.length;++di){for(f=a.slice();++gb;b++)a.assert(arguments[b]);return a},containsRule:function(a){return c.some(this.__rules,function(b){return b.name===a})}},"static":{getFlow:function(a){return l[a]},hasFlow:function(a){return c.has(l,a)},deleteFlow:function(a){return d(a,m)&&(a=a.name),delete l[a],m},deleteFlows:function(){for(var a in l)a in l&&delete l[a];return m},create:function(a,b){return new m(a,b)}}}).as(b)},{"./conflict":7,"./extended":12,"./flow":13,"./pattern":45,"./rule":46}],15:[function(a,b,c){"use strict";function d(a){return/\.nools$/.test(a)}function e(a){var b;return b=d(a)?i.parse(g.readFileSync(a,"utf8"),a):i.parse(a)}var f=a("./extended"),g=a("fs"),h=a("path"),i=a("./compile"),j=a("./flowContainer");c.Flow=j,c.getFlow=j.getFlow,c.hasFlow=j.hasFlow,c.deleteFlow=function(a){return j.deleteFlow(a),this},c.deleteFlows=function(){return j.deleteFlows(),this},c.flow=j.create,c.compile=function(a,b,c){if(f.isFunction(b)?(c=b,b={}):(b=b||{},c=null),f.isString(a)&&(b.name=b.name||(d(a)?h.basename(a,h.extname(a)):null),a=e(a)),!b.name)throw new Error("Name required when compiling nools source");return i.compile(a,b,c,j)},c.transpile=function(a,b){return b=b||{},f.isString(a)&&(b.name=b.name||(d(a)?h.basename(a,h.extname(a)):null),a=e(a)),i.transpile(a,b)},c.parse=e},{"./compile":5,"./extended":12,"./flowContainer":14,fs:65,path:66}],16:[function(a,b){var c=a("declare.js");c({instance:{constructor:function(){this.head=null,this.tail=null,this.length=null},push:function(a){var b=this.tail,c=this.head,d={data:a,prev:b,next:null};return b&&(this.tail.next=d),this.tail=d,c||(this.head=d),this.length++,d},remove:function(a){a.prev?a.prev.next=a.next:this.head=a.next,a.next?a.next.prev=a.prev:this.tail=a.prev,this.length--},forEach:function(a){for(var b={next:this.head};b=b.next;)a(b.data)},toArray:function(){for(var a={next:this.head},b=[];a=a.next;)b.push(a);return b},removeByData:function(a){for(var b={next:this.head};b=b.next;)if(b.data===a){this.remove(b);break}},getByData:function(a){for(var b={next:this.head};b=b.next;)if(b.data===a)return b},clear:function(){this.head=this.tail=null,this.length=0}}}).as(b)},{"declare.js":52}],17:[function(a,b){var c,d=a("__browserify_process"),e=a("./extended");if("function"==typeof setImmediate)c="undefined"!=typeof window?e.bind(window,setImmediate):setImmediate;else if("undefined"!=typeof d)c=d.nextTick;else if("undefined"!=typeof MessageChannel){var f=new MessageChannel,g={},h=g;f.port1.onmessage=function(){g=g.next;var a=g.task;delete g.task,a()},c=function(a){h=h.next={task:a},f.port2.postMessage(0)}}else c=function(a){setTimeout(a,0)};b.exports=c},{"./extended":12,__browserify_process:68}],18:[function(a,b){var c=a("./node"),d=a("../extended").intersection,e=a("../context");c.extend({instance:{__propagatePaths:function(a,b){for(var c,f,g,h,i=this.__entrySet,j=i.length;--j>-1;)c=i[j],f=c.key,g=c.value,(h=d(g,b.paths)).length&&f[a](new e(b.fact,h,b.match))},__propagateNoPaths:function(a,b){for(var c=this.__entrySet,d=c.length;--d>-1;)c[d].key[a](b)},__propagate:function(a,b){b.paths?this.__propagatePaths(a,b):this.__propagateNoPaths(a,b)}}}).as(b)},{"../context":10,"../extended":12,"./node":34}],19:[function(a,b){var c=a("./alphaNode");c.extend({instance:{constructor:function(){this._super(arguments),this.alias=this.constraint.get("alias")},toString:function(){return"AliasNode"+this.__count +},assert:function(a){return this.__propagate("assert",a.set(this.alias,a.fact.object))},modify:function(a){return this.__propagate("modify",a.set(this.alias,a.fact.object))},retract:function(a){return this.__propagate("retract",a.set(this.alias,a.fact.object))},equal:function(a){return a instanceof this._static&&this.alias===a.alias}}}).as(b)},{"./alphaNode":20}],20:[function(a,b){"use strict";var c=a("./node");c.extend({instance:{constructor:function(a){this._super([]),this.constraint=a,this.constraintAssert=this.constraint.assert},toString:function(){return"AlphaNode "+this.__count},equal:function(a){return this.constraint.equal(a.constraint)}}}).as(b)},{"./node":34}],21:[function(a,b){var c=a("../extended"),d=c.hash.values,e=c.hash.keys,f=a("./node"),g=a("./misc/leftMemory"),h=a("./misc/rightMemory");f.extend({instance:{nodeType:"BetaNode",constructor:function(){this._super([]),this.leftMemory={},this.rightMemory={},this.leftTuples=new g,this.rightTuples=new h},__propagate:function(a,b){for(var c,d,e=this.__entrySet,f=e.length;--f>-1;)c=e[f],d=c.key,d[a](b)},dispose:function(){this.leftMemory={},this.rightMemory={},this.leftTuples.clear(),this.rightTuples.clear()},disposeLeft:function(a){this.leftMemory={},this.leftTuples.clear(),this.propagateDispose(a)},disposeRight:function(a){this.rightMemory={},this.rightTuples.clear(),this.propagateDispose(a)},hashCode:function(){return this.nodeType+" "+this.__count},toString:function(){return this.nodeType+" "+this.__count},retractLeft:function(a){a=this.removeFromLeftMemory(a).data;for(var b=d(a.rightMatches),c=-1,e=b.length;++ch;h++)if(this.__isMatch(a,e[h],!0)){a.blocked=!0;break}}else f(e)&&(a.blocked=this.__isMatch(a,e,!0));var j=a.blocked;j?c?this.__propagate("modify",a.clone()):this.__propagate("assert",a.clone()):c&&this.__propagate("retract",a.clone())},__findMatches:function(a){var b=a.factHash,c=this.from(b),d=!1;if(g(c)){for(var e=0,h=c.length;h>e;e++)if(this.__isMatch(a,c[e],!0))return a.blocked=!0,this.__propagate("assert",a.clone()),void 0}else f(c)&&this.__isMatch(a,c,!0)&&(a.blocked=!0,this.__propagate("assert",a.clone()));return d},__isMatch:function(a,b,c){var d=!1;if(this.type(b)){var f=this.workingMemory.getFactHandle(b),g=new e(f,null).mergeMatch(a.match).set(this.alias,b);if(c){var h=this.fromMemory[f.id];h||(h=this.fromMemory[f.id]={}),h[a.hashCode]=a}for(var i=g.factHash,j=this.__equalityConstraints,k=0,l=j.length;l>k;k++){if(!j[k](i)){d=!1;break}d=!0}}return d},assertLeft:function(a){this.__addToLeftMemory(a),this.__findMatches(a)}}}).as(b)},{"../context":10,"../extended":12,"./fromNotNode":26}],24:[function(a,b){var c=a("./notNode"),d=a("../linkedList");c.extend({instance:{nodeType:"ExistsNode",blockedContext:function(a,b){a.blocker=b,this.removeFromLeftMemory(a),this.addToLeftBlockedMemory(b.blocking.push(a)),this.__propagate("assert",this.__cloneContext(a))},notBlockedContext:function(a,b){this.__addToLeftMemory(a),b&&this.__propagate("retract",this.__cloneContext(a))},propagateFromLeft:function(a){this.notBlockedContext(a,!1)},retractLeft:function(a){var b;if(!this.removeFromLeftMemory(a)){if(!(b=this.removeFromLeftBlockedMemory(a)))throw new Error;this.__propagate("retract",this.__cloneContext(b.data))}},modifyLeft:function(a){var b,c,d,e,f=this.removeFromLeftMemory(a),g=this.constraint,h=this.rightTuples,i=h.length,j=!1;if(f||(f=this.removeFromLeftBlockedMemory(a),j=!0),!f)throw new Error;if(b=f.data,b&&b.blocker&&(e=this.rightMemory[b.blocker.hashCode]),e?(g.isMatch(a,d=e.data)&&(this.__propagate(j?"modify":"assert",this.__cloneContext(b)),a.blocker=d,this.addToLeftBlockedMemory(d.blocking.push(a)),a=null),a&&(c={next:e.next})):c={next:h.head},a&&i)for(c={next:h.head};c=c.next;)if(g.isMatch(a,d=c.data)){this.__propagate(j?"modify":"assert",this.__cloneContext(b)),this.addToLeftBlockedMemory(d.blocking.push(a)),a.blocker=d,a=null;break}a&&(this.__addToLeftMemory(a),j&&this.__propagate("retract",this.__cloneContext(a)))},modifyRight:function(a){var b=this.removeFromRightMemory(a);if(!b)throw new Error;var c,e,f=b.data,g=this.leftTuples,h=g.length,i=this.constraint,j=f.blocking;if(this.__addToRightMemory(a),a.blocking=new d,h||j.length){if(j.length)for(var k,l={next:j.head};l=l.next;)if(c=l.data,c.blocker=null,i.isMatch(c,a))c.blocker=a,this.addToLeftBlockedMemory(a.blocking.push(c)),this.__propagate("assert",this.__cloneContext(c)),c=null;else{for(c.blocker=null,e=b;e=e.next;)if(i.isMatch(c,k=e.data)){c.blocker=k,this.addToLeftBlockedMemory(k.blocking.push(c)),this.__propagate("assert",this.__cloneContext(c)),c=null;break}c&&this.__addToLeftMemory(c)}if(h)for(e={next:g.head};e=e.next;)c=e.data,i.isMatch(c,a)&&(this.__propagate("assert",this.__cloneContext(c)),this.removeFromLeftMemory(c),this.addToLeftBlockedMemory(a.blocking.push(c)),c.blocker=a)}}}}).as(b)},{"../linkedList":16,"./notNode":35}],25:[function(a,b){var c=a("./joinNode"),d=a("../extended"),e=a("../constraint"),f=e.EqualityConstraint,g=e.HashConstraint,h=e.ReferenceConstraint,i=a("../context"),j=d.isDefined,k=d.isEmpty,l=d.forEach,m=d.isArray,n={isMatch:function(){return!1}};c.extend({instance:{nodeType:"FromNode",constructor:function(a,b){this._super(arguments),this.workingMemory=b,this.fromMemory={},this.pattern=a,this.type=a.get("constraints")[0].assert,this.alias=a.get("alias"),this.from=a.from.assert;var c=this.__equalityConstraints=[],d=[];l(this.constraints=this.pattern.get("constraints").slice(1),function(a){a instanceof f||a instanceof h?c.push(a.assert):a instanceof g&&(d=d.concat(a.get("variables")))}),this.__variables=d},__createMatches:function(a){var b=a.factHash,c=this.from(b);if(m(c))for(var d=0,e=c.length;e>d;d++)this.__checkMatch(a,c[d],!0);else j(c)&&this.__checkMatch(a,c,!0)},__checkMatch:function(a,b,c){var d;return(d=this.__createMatch(a,b)).isMatch()&&c&&this.__propagate("assert",d.clone()),d},__createMatch:function(a,b){if(this.type(b)){var c,d=this.workingMemory.getFactHandle(b,!0),e=new i(d).set(this.alias,b),f=d.id,g=e.factHash,h=a.factHash;for(var j in h)g[j]=h[j];for(var k=this.__equalityConstraints,l=this.__variables,m=-1,o=k.length;++mc;c++)b=this.__checkMatch(a,l[c],!1),b.isMatch()&&(e=b.fact.id,e in k?this.__propagate("modify",b.clone()):this.__propagate("assert",b.clone()));else j(l)&&(b=this.__checkMatch(a,l,!1),b.isMatch()&&(e=b.fact.id,e in k?this.__propagate("modify",b.clone()):this.__propagate("assert",b.clone())));for(c in k)c in i||(this.removeFromFromMemory(k[c]),this.__propagate("retract",k[c].clone()))}else this.assertLeft(a);f=a.fact,e=f.id;var n=this.fromMemory[e];if(this.fromMemory[e]={},n){var o,p,q,r,s=f.object;for(c in n)p=n[c],o=p[0],q=p[1],r=q.isMatch(),o.hashCode!==a.hashCode&&(b=this.__createMatch(o,s,!1),r&&this.__propagate("retract",q.clone()),b.isMatch()&&this.__propagate(r?"modify":"assert",b.clone()))}},assertLeft:function(a){this.__addToLeftMemory(a),a.fromMatches={},this.__createMatches(a)},assertRight:function(){throw new Error("Shouldnt have gotten here")}}}).as(b)},{"../constraint":8,"../context":10,"../extended":12,"./joinNode":28}],26:[function(a,b){var c=a("./joinNode"),d=a("../extended"),e=a("../constraint"),f=e.EqualityConstraint,g=e.HashConstraint,h=e.ReferenceConstraint,i=a("../context"),j=d.isDefined,k=d.forEach,l=d.isArray;c.extend({instance:{nodeType:"FromNotNode",constructor:function(a,b){this._super(arguments),this.workingMemory=b,this.pattern=a,this.type=a.get("constraints")[0].assert,this.alias=a.get("alias"),this.from=a.from.assert,this.fromMemory={};var c=this.__equalityConstraints=[],d=[];k(this.constraints=this.pattern.get("constraints").slice(1),function(a){a instanceof f||a instanceof h?c.push(a.assert):a instanceof g&&(d=d.concat(a.get("variables")))}),this.__variables=d},retractLeft:function(a){var b=this.removeFromLeftMemory(a);b&&(b=b.data,b.blocked||this.__propagate("retract",b.clone()))},__modify:function(a,b){var c=b.blocked,d=a.factHash,e=this.from(d);if(l(e)){for(var f=0,g=e.length;g>f;f++)if(this.__isMatch(a,e[f],!0)){a.blocked=!0;break}}else j(e)&&(a.blocked=this.__isMatch(a,e,!0));var h=a.blocked;h?c||this.__propagate("retract",b.clone()):c?this.__propagate("assert",a.clone()):this.__propagate("modify",a.clone())},modifyLeft:function(a){var b=this.removeFromLeftMemory(a);if(!b)throw new Error;this.__addToLeftMemory(a),this.__modify(a,b.data);var c=this.fromMemory[a.fact.id];if(this.fromMemory[a.fact.id]={},c)for(var d in c)if(d!==a.hashCode){var e=c[d];b=this.removeFromLeftMemory(e),b&&(e=e.clone(),e.blocked=!1,this.__addToLeftMemory(e),this.__modify(e,b.data))}},__findMatches:function(a){var b=a.factHash,c=this.from(b),d=!1;if(l(c)){for(var e=0,f=c.length;f>e;e++)if(this.__isMatch(a,c[e],!0))return a.blocked=!0,void 0;this.__propagate("assert",a.clone())}else j(c)&&!(a.blocked=this.__isMatch(a,c,!0))&&this.__propagate("assert",a.clone());return d},__isMatch:function(a,b,c){var d=!1;if(this.type(b)){var e=this.workingMemory.getFactHandle(b),f=new i(e,null).mergeMatch(a.match).set(this.alias,b);if(c){var g=this.fromMemory[e.id];g||(g=this.fromMemory[e.id]={}),g[a.hashCode]=a}for(var h=f.factHash,j=this.__equalityConstraints,k=0,l=j.length;l>k;k++){if(!j[k](h,h)){d=!1;break}d=!0}}return d},assertLeft:function(a){this.__addToLeftMemory(a),this.__findMatches(a)},assertRight:function(){throw new Error("Shouldnt have gotten here")},retractRight:function(){throw new Error("Shouldnt have gotten here")}}}).as(b)},{"../constraint":8,"../context":10,"../extended":12,"./joinNode":28}],27:[function(a,b,c){"use strict";function d(a){return g(a.constraints||[],function(a){return a instanceof t})}var e=a("../extended"),f=e.forEach,g=e.some,h=e.declare,i=a("../pattern.js"),j=i.ObjectPattern,k=i.FromPattern,l=i.FromNotPattern,m=i.ExistsPattern,n=i.FromExistsPattern,o=i.NotPattern,p=i.CompositePattern,q=i.InitialFactPattern,r=a("../constraint"),s=r.HashConstraint,t=r.ReferenceConstraint,u=a("./aliasNode"),v=a("./equalityNode"),w=a("./joinNode"),x=a("./betaNode"),y=a("./notNode"),z=a("./fromNode"),A=a("./fromNotNode"),B=a("./existsNode"),C=a("./existsFromNode"),D=a("./leftAdapterNode"),E=a("./rightAdapterNode"),F=a("./typeNode"),G=a("./terminalNode"),H=a("./propertyNode");h({instance:{constructor:function(a,b){this.terminalNodes=[],this.joinNodes=[],this.nodes=[],this.constraints=[],this.typeNodes=[],this.__ruleCount=0,this.bucket={counter:0,recency:0},this.agendaTree=b,this.workingMemory=a},assertRule:function(a){var b=new G(this.bucket,this.__ruleCount++,a,this.agendaTree);this.__addToNetwork(a,a.pattern,b),this.__mergeJoinNodes(),this.terminalNodes.push(b)},resetCounter:function(){this.bucket.counter=0},incrementCounter:function(){this.bucket.counter++},assertFact:function(a){for(var b=this.typeNodes,c=b.length-1;c>=0;c--)b[c].assert(a)},retractFact:function(a){for(var b=this.typeNodes,c=b.length-1;c>=0;c--)b[c].retract(a)},modifyFact:function(a){for(var b=this.typeNodes,c=b.length-1;c>=0;c--)b[c].modify(a)},containsRule:function(a){return g(this.terminalNodes,function(b){return b.rule.name===a})},dispose:function(){for(var a=this.typeNodes,b=a.length-1;b>=0;b--)a[b].dispose()},__mergeJoinNodes:function(){for(var a=this.joinNodes,b=0;b=0;c--){var d=b[c];if(a.equal(d))return d}return b.push(a),a},__createTypeNode:function(a,b){for(var c=new F(b.get("constraints")[0]),d=this.typeNodes,e=d.length-1;e>=0;e--){var f=d[e];if(c.equal(f))return f}return d.push(c),c},__createEqualityNode:function(a,b){return this.__checkEqual(new v(b)).addRule(a)},__createPropertyNode:function(a,b){return this.__checkEqual(new H(b)).addRule(a)},__createAliasNode:function(a,b){return this.__checkEqual(new u(b)).addRule(a)},__createAdapterNode:function(a,b){return("left"===b?new D:new E).addRule(a)},__createJoinNode:function(a,b,c,e){var f;b.rightPattern instanceof o?f=new y:b.rightPattern instanceof n?f=new C(b.rightPattern,this.workingMemory):b.rightPattern instanceof m?f=new B:b.rightPattern instanceof l?f=new A(b.rightPattern,this.workingMemory):b.rightPattern instanceof k?f=new z(b.rightPattern,this.workingMemory):b instanceof p&&!d(b.leftPattern)&&!d(b.rightPattern)?(f=new x,this.joinNodes.push(f)):(f=new w,this.joinNodes.push(f)),f.__rule__=a;var g=f;if(c instanceof x){var h=this.__createAdapterNode(a,e);g.addOutNode(h,b),g=h}return g.addOutNode(c,b),f.addRule(a)},__addToNetwork:function(a,b,c,d){b instanceof j?b instanceof q||d&&"left"!==d?this.__createAlphaNode(a,b,c,d):this.__createBetaNode(a,new p(new q,b),c,d):b instanceof p&&this.__createBetaNode(a,b,c,d)},__createBetaNode:function(a,b,c,d){var e=this.__createJoinNode(a,b,c,d);return this.__addToNetwork(a,b.rightPattern,e,"right"),this.__addToNetwork(a,b.leftPattern,e,"left"),c.addParentNode(e),e},__createAlphaNode:function(a,b,c,d){var e,f;if(!(b instanceof k)){var g=b.get("constraints");e=this.__createTypeNode(a,b);var h=this.__createAliasNode(a,b);e.addOutNode(h,b),h.addParentNode(e),f=h;for(var i=g.length-1;i>0;i--){var j,l=g[i];if(l instanceof s)j=this.__createPropertyNode(a,l);else{if(l instanceof t){c.constraint.addConstraint(l);continue}j=this.__createEqualityNode(a,l)}f.addOutNode(j,b),j.addParentNode(f),f=j}if(c instanceof x){var m=this.__createAdapterNode(a,d);m.addParentNode(f),f.addOutNode(m,b),f=m}return c.addParentNode(f),f.addOutNode(c,b),e}},print:function(){f(this.terminalNodes,function(a){a.print(" ")})}}}).as(c,"RootNode")},{"../constraint":8,"../extended":12,"../pattern.js":45,"./aliasNode":19,"./betaNode":21,"./equalityNode":22,"./existsFromNode":23,"./existsNode":24,"./fromNode":25,"./fromNotNode":26,"./joinNode":28,"./leftAdapterNode":30,"./notNode":35,"./propertyNode":36,"./rightAdapterNode":37,"./terminalNode":38,"./typeNode":39}],28:[function(a,b){var c=a("./betaNode"),d=a("./joinReferenceNode");c.extend({instance:{constructor:function(){this._super(arguments),this.constraint=new d(this.leftTuples,this.rightTuples)},nodeType:"JoinNode",propagateFromLeft:function(a,b){var c;return(c=this.constraint.match(a,b)).isMatch&&this.__propagate("assert",this.__addToMemoryMatches(b,a,a.clone(null,null,c))),this},propagateFromRight:function(a,b){var c;return(c=this.constraint.match(b,a)).isMatch&&this.__propagate("assert",this.__addToMemoryMatches(a,b,a.clone(null,null,c))),this},propagateAssertModifyFromLeft:function(a,b,c){var d,e=c.hashCode;if(e in b){d=this.constraint.match(a,c);var f=d.isMatch;f?this.__propagate("modify",this.__addToMemoryMatches(c,a,a.clone(null,null,d))):this.__propagate("retract",b[e].clone())}else this.propagateFromLeft(a,c)},propagateAssertModifyFromRight:function(a,b,c){var d,e=c.hashCode;if(e in b){d=this.constraint.match(c,a);var f=d.isMatch;f?this.__propagate("modify",this.__addToMemoryMatches(a,c,a.clone(null,null,d))):this.__propagate("retract",b[e].clone())}else this.propagateFromRight(a,c)}}}).as(b)},{"./betaNode":21,"./joinReferenceNode":29}],29:[function(a,b){var c=a("./node"),d=a("../constraint"),e=d.ReferenceEqualityConstraint,f={isDefault:!0,assert:function(){return!0},equal:function(){return!1}};c.extend({instance:{constraint:f,constructor:function(a,b){this._super(arguments),this.constraint=f,this.constraintAssert=f.assert,this.rightIndexes=[],this.leftIndexes=[],this.constraintLength=0,this.leftMemory=a,this.rightMemory=b},addConstraint:function(a){if(a instanceof e){var b=a.getIndexableProperties(),c=a.get("alias");if(2===b.length&&c){for(var d,f,g=-1;++g<2;){var h=b[g];null===h.match(new RegExp("^"+c+"(\\.?)"))?d=h:f=h}d&&f&&(this.rightMemory.addIndex(f,d,a.op),this.leftMemory.addIndex(d,f,a.op))}}this.constraint.isDefault?(this.constraint=a,this.isDefault=!1):this.constraint=this.constraint.merge(a),this.constraintAssert=this.constraint.assert},equal:function(a){return this.constraint.equal(a.constraint)},isMatch:function(a,b){return this.constraintAssert(a.factHash,b.factHash)},match:function(a,b){var c={isMatch:!1};return this.constraintAssert(a.factHash,b.factHash)&&(c=a.match.merge(b.match)),c}}}).as(b)},{"../constraint":8,"./node":34}],30:[function(a,b){var c=a("./adapterNode");c.extend({instance:{propagateAssert:function(a){this.__propagate("assertLeft",a)},propagateRetract:function(a){this.__propagate("retractLeft",a)},propagateResolve:function(a){this.__propagate("retractResolve",a)},propagateModify:function(a){this.__propagate("modifyLeft",a)},retractResolve:function(a){this.__propagate("retractResolve",a)},dispose:function(a){this.propagateDispose(a)},toString:function(){return"LeftAdapterNode "+this.__count}}}).as(b)},{"./adapterNode":18}],31:[function(a,b){var c=a("./memory");c.extend({instance:{getLeftMemory:function(a){return this.getMemory(a)}}}).as(b)},{"./memory":32}],32:[function(a,b){var c=a("../../extended"),d=c.indexOf,e=c.plucker,f=c.diffArr,g=Array.prototype.push,h=c.declare,i=c.HashTable;h({instance:{constructor:function(){this.head=null,this.tail=null,this.length=null,this.indexes=[],this.tables={tuples:[],tables:[]}},inequalityThreshold:.5,push:function(a){var b=this.tail,c=this.head,d={data:a,prev:b,next:null};return b&&(this.tail.next=d),this.tail=d,c||(this.head=d),this.length++,this.__index(d),this.tables.tuples.push(d),d},remove:function(a){a.prev?a.prev.next=a.next:this.head=a.next,a.next?a.next.prev=a.prev:this.tail=a.prev;var b=d(this.tables.tuples,a);-1!==b&&this.tables.tuples.splice(b,1),this.__removeFromIndex(a),this.length--},forEach:function(a){for(var b={next:this.head};b=b.next;)a(b.data)},toArray:function(){for(var a={next:this.head},b=[];a=a.next;)b.push(a);return b},clear:function(){this.head=this.tail=null,this.length=0,this.clearIndexes()},clearIndexes:function(){this.tables={},this.indexes.length=0},__index:function(a){for(var b,c,d,e,f,g,h,j=a.data,k=j.factHash,l=this.indexes,m=this.tables,n=-1,o=l.length;++nm&&(k=f(k,n)),k.slice()},__createIndexTree:function(){var a=this.tables.tables={},b=this.indexes;a[b[0][0]]=new i},addIndex:function(a,b,c){this.indexes.push([a,b,e(a),e(b),c||"eq"]),this.indexes.sort(function(a,b){var c=a[4],d=b[4];return c===d?0:c>d?1:-1}),this.__createIndexTree()}}}).as(b)},{"../../extended":12}],33:[function(a,b){var c=a("./memory");c.extend({instance:{getRightMemory:function(a){return this.getMemory(a)}}}).as(b)},{"./memory":32}],34:[function(a,b){var c=a("../extended"),d=c.forEach,e=c.indexOf,f=c.intersection,g=c.declare,h=c.HashTable,i=a("../context"),j=0;g({instance:{constructor:function(){this.nodes=new h,this.rules=[],this.parentNodes=[],this.__count=j++,this.__entrySet=[]},addRule:function(a){return-1===e(this.rules,a)&&this.rules.push(a),this},merge:function(a){a.nodes.forEach(function(b){for(var c=b.value,d=b.key,e=0,f=c.length;f>e;e++)this.addOutNode(d,c[e]);a.nodes.remove(d)},this);for(var b=a.parentNodes,c=0,d=a.parentNodes.l;d>c;c++){var e=b[c];this.addParentNode(e),e.nodes.remove(a)}return this},resolve:function(a,b){return a.hashCode===b.hashCode},print:function(a){console.log(a+this.toString()),d(this.parentNodes,function(b){b.print(" "+a)})},addOutNode:function(a,b){this.nodes.contains(a)||this.nodes.put(a,[]),this.nodes.get(a).push(b),this.__entrySet=this.nodes.entrySet()},addParentNode:function(a){-1===e(this.parentNodes,a)&&this.parentNodes.push(a)},shareable:function(){return!1},__propagate:function(a,b){for(var c,d,e,g,h=this.__entrySet,j=h.length;--j>-1;)c=h[j],d=c.key,e=c.value,(g=f(e,b.paths)).length&&d[a](new i(b.fact,g,b.match))},dispose:function(a){this.propagateDispose(a)},retract:function(a){this.propagateRetract(a)},propagateDispose:function(a,b){b=b||this.nodes;for(var c=this.__entrySet,d=c.length-1;d>=0;d--){var e=c[d],f=e.key;f.dispose(a)}},propagateAssert:function(a){this.__propagate("assert",a)},propagateRetract:function(a){this.__propagate("retract",a)},assert:function(a){this.propagateAssert(a)},modify:function(a){this.propagateModify(a)},propagateModify:function(a){this.__propagate("modify",a)}}}).as(b)},{"../context":10,"../extended":12}],35:[function(a,b){var c=a("./joinNode"),d=a("../linkedList"),e=a("../context"),f=a("../pattern").InitialFact;c.extend({instance:{nodeType:"NotNode",constructor:function(){this._super(arguments),this.leftTupleMemory={},this.notMatch=new e(new f).match},__cloneContext:function(a){return a.clone(null,null,a.match.merge(this.notMatch))},retractRight:function(a){var b=this.removeFromRightMemory(a),c=b.data,d=c.blocking;if(d.length){for(var e,f,g,h=this.rightTuples.getSimilarMemory(c),i=h.length,j=this.constraint,k={next:d.head};k=k.next;){for(f=k.data,e=-1;++eg;g++)b=e[g],c.set(b[1],f[b[0]]);this.__propagate("assert",c)},retract:function(a){this.__propagate("retract",new d(a.fact,a.paths))},modify:function(a){var b,c=new d(a.fact,a.paths),e=this.variables,f=a.fact.object;c.set(this.alias,f);for(var g=0,h=this.varLength;h>g;g++)b=e[g],c.set(b[1],f[b[0]]);this.__propagate("modify",c)},toString:function(){return"PropertyNode"+this.__count}}}).as(b)},{"../context":10,"../extended":12,"./alphaNode":20}],37:[function(a,b){var c=a("./adapterNode");c.extend({instance:{retractResolve:function(a){this.__propagate("retractResolve",a)},dispose:function(a){this.propagateDispose(a)},propagateAssert:function(a){this.__propagate("assertRight",a)},propagateRetract:function(a){this.__propagate("retractRight",a)},propagateResolve:function(a){this.__propagate("retractResolve",a)},propagateModify:function(a){this.__propagate("modifyRight",a)},toString:function(){return"RightAdapterNode "+this.__count}}}).as(b)},{"./adapterNode":18}],38:[function(a,b){var c=a("./node"),d=a("../extended"),e=d.bind;c.extend({instance:{constructor:function(a,b,c,d){this._super([]),this.resolve=e(this,this.resolve),this.rule=c,this.index=b,this.name=this.rule.name,this.agenda=d,this.bucket=a,d.register(this)},__assertModify:function(a){var b=a.match;if(b.isMatch){var c=this.rule,d=this.bucket;this.agenda.insert(this,{rule:c,hashCode:a.hashCode,index:this.index,name:c.name,recency:d.recency++,match:b,counter:d.counter})}},assert:function(a){this.__assertModify(a)},modify:function(a){this.agenda.retract(this,a),this.__assertModify(a)},retract:function(a){this.agenda.retract(this,a)},retractRight:function(a){this.agenda.retract(this,a)},retractLeft:function(a){this.agenda.retract(this,a)},assertLeft:function(a){this.__assertModify(a)},assertRight:function(a){this.__assertModify(a)},toString:function(){return"TerminalNode "+this.rule.name}}}).as(b)},{"../extended":12,"./node":34}],39:[function(a,b){var c=a("./alphaNode"),d=a("../context"); +c.extend({instance:{assert:function(a){this.constraintAssert(a.object)&&this.__propagate("assert",a)},modify:function(a){this.constraintAssert(a.object)&&this.__propagate("modify",a)},retract:function(a){this.constraintAssert(a.object)&&this.__propagate("retract",a)},toString:function(){return"TypeNode"+this.__count},dispose:function(){for(var a=this.__entrySet,b=a.length-1;b>=0;b--){var c=a[b],d=c.key,e=c.value;d.dispose({paths:e})}},__propagate:function(a,b){for(var c=this.__entrySet,e=-1,f=c.length;++e":20,"<=":21,">=":22,EQUALITY_EXPRESSION:23,"==":24,"!=":25,"=~":26,"!=~":27,IN_EXPRESSION:28,"in":29,ARRAY_EXPRESSION:30,notIn:31,OBJECT_EXPRESSION:32,AND_EXPRESSION:33,"&&":34,OR_EXPRESSION:35,"||":36,ARGUMENT_LIST:37,",":38,IDENTIFIER_EXPRESSION:39,IDENTIFIER:40,".":41,"[":42,STRING_EXPRESSION:43,"]":44,NUMBER_EXPRESSION:45,"(":46,")":47,STRING:48,NUMBER:49,REGEXP_EXPRESSION:50,REGEXP:51,BOOLEAN_EXPRESSION:52,BOOLEAN:53,NULL_EXPRESSION:54,NULL:55,$accept:0,$end:1},terminals_:{2:"error",5:"EOF",8:"-",9:"!",11:"*",12:"/",13:"%",15:"+",17:"^",19:"<",20:">",21:"<=",22:">=",24:"==",25:"!=",26:"=~",27:"!=~",29:"in",31:"notIn",34:"&&",36:"||",38:",",40:"IDENTIFIER",41:".",42:"[",44:"]",46:"(",47:")",48:"STRING",49:"NUMBER",51:"REGEXP",53:"BOOLEAN",55:"NULL"},productions_:[0,[3,2],[6,1],[6,2],[6,2],[10,1],[10,3],[10,3],[10,3],[14,1],[14,3],[14,3],[16,1],[16,3],[18,1],[18,3],[18,3],[18,3],[18,3],[23,1],[23,3],[23,3],[23,3],[23,3],[28,1],[28,3],[28,3],[28,3],[28,3],[33,1],[33,3],[35,1],[35,3],[37,1],[37,3],[39,1],[32,1],[32,3],[32,4],[32,4],[32,4],[32,3],[32,4],[43,1],[45,1],[50,1],[52,1],[54,1],[30,2],[30,3],[7,1],[7,1],[7,1],[7,1],[7,1],[7,1],[7,1],[7,3],[4,1]],performAction:function(a,b,c,d,e,f){var g=f.length-1;switch(e){case 1:return f[g-1];case 3:this.$=[f[g],null,"unary"];break;case 4:this.$=[f[g],null,"logicalNot"];break;case 6:this.$=[f[g-2],f[g],"mult"];break;case 7:this.$=[f[g-2],f[g],"div"];break;case 8:this.$=[f[g-2],f[g],"mod"];break;case 10:this.$=[f[g-2],f[g],"plus"];break;case 11:this.$=[f[g-2],f[g],"minus"];break;case 13:this.$=[f[g-2],f[g],"pow"];break;case 15:this.$=[f[g-2],f[g],"lt"];break;case 16:this.$=[f[g-2],f[g],"gt"];break;case 17:this.$=[f[g-2],f[g],"lte"];break;case 18:this.$=[f[g-2],f[g],"gte"];break;case 20:this.$=[f[g-2],f[g],"eq"];break;case 21:this.$=[f[g-2],f[g],"neq"];break;case 22:this.$=[f[g-2],f[g],"like"];break;case 23:this.$=[f[g-2],f[g],"notLike"];break;case 25:this.$=[f[g-2],f[g],"in"];break;case 26:this.$=[f[g-2],f[g],"notIn"];break;case 27:this.$=[f[g-2],f[g],"in"];break;case 28:this.$=[f[g-2],f[g],"notIn"];break;case 30:this.$=[f[g-2],f[g],"and"];break;case 32:this.$=[f[g-2],f[g],"or"];break;case 34:this.$=[f[g-2],f[g],"arguments"];break;case 35:this.$=[String(a),null,"identifier"];break;case 37:this.$=[f[g-2],f[g],"prop"];break;case 38:this.$=[f[g-3],f[g-1],"propLookup"];break;case 39:this.$=[f[g-3],f[g-1],"propLookup"];break;case 40:this.$=[f[g-3],f[g-1],"propLookup"];break;case 41:this.$=[f[g-2],[null,null,"arguments"],"function"];break;case 42:this.$=[f[g-3],f[g-1],"function"];break;case 43:this.$=[String(a.replace(/^['|"]|['|"]$/g,"")),null,"string"];break;case 44:this.$=[Number(a),null,"number"];break;case 45:this.$=[a,null,"regexp"];break;case 46:this.$=["true"==a.replace(/^\s+/,""),null,"boolean"];break;case 47:this.$=[null,null,"null"];break;case 48:this.$=[null,null,"array"];break;case 49:this.$=[f[g-1],null,"array"];break;case 57:this.$=[f[g-1],null,"composite"]}},table:[{3:1,4:2,6:28,7:7,8:[1,29],9:[1,30],10:27,14:25,16:17,18:8,23:6,28:5,30:15,32:14,33:4,35:3,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{1:[3]},{5:[1,31]},{5:[2,58],36:[1,32],47:[2,58]},{5:[2,31],34:[1,33],36:[2,31],47:[2,31]},{5:[2,29],34:[2,29],36:[2,29],47:[2,29]},{5:[2,24],24:[1,34],25:[1,35],26:[1,36],27:[1,37],34:[2,24],36:[2,24],47:[2,24]},{5:[2,2],8:[2,2],11:[2,2],12:[2,2],13:[2,2],15:[2,2],17:[2,2],19:[2,2],20:[2,2],21:[2,2],22:[2,2],24:[2,2],25:[2,2],26:[2,2],27:[2,2],29:[1,38],31:[1,39],34:[2,2],36:[2,2],47:[2,2]},{5:[2,19],19:[1,40],20:[1,41],21:[1,42],22:[1,43],24:[2,19],25:[2,19],26:[2,19],27:[2,19],34:[2,19],36:[2,19],47:[2,19]},{5:[2,50],8:[2,50],11:[2,50],12:[2,50],13:[2,50],15:[2,50],17:[2,50],19:[2,50],20:[2,50],21:[2,50],22:[2,50],24:[2,50],25:[2,50],26:[2,50],27:[2,50],29:[2,50],31:[2,50],34:[2,50],36:[2,50],38:[2,50],44:[2,50],47:[2,50]},{5:[2,51],8:[2,51],11:[2,51],12:[2,51],13:[2,51],15:[2,51],17:[2,51],19:[2,51],20:[2,51],21:[2,51],22:[2,51],24:[2,51],25:[2,51],26:[2,51],27:[2,51],29:[2,51],31:[2,51],34:[2,51],36:[2,51],38:[2,51],44:[2,51],47:[2,51]},{5:[2,52],8:[2,52],11:[2,52],12:[2,52],13:[2,52],15:[2,52],17:[2,52],19:[2,52],20:[2,52],21:[2,52],22:[2,52],24:[2,52],25:[2,52],26:[2,52],27:[2,52],29:[2,52],31:[2,52],34:[2,52],36:[2,52],38:[2,52],44:[2,52],47:[2,52]},{5:[2,53],8:[2,53],11:[2,53],12:[2,53],13:[2,53],15:[2,53],17:[2,53],19:[2,53],20:[2,53],21:[2,53],22:[2,53],24:[2,53],25:[2,53],26:[2,53],27:[2,53],29:[2,53],31:[2,53],34:[2,53],36:[2,53],38:[2,53],44:[2,53],47:[2,53]},{5:[2,54],8:[2,54],11:[2,54],12:[2,54],13:[2,54],15:[2,54],17:[2,54],19:[2,54],20:[2,54],21:[2,54],22:[2,54],24:[2,54],25:[2,54],26:[2,54],27:[2,54],29:[2,54],31:[2,54],34:[2,54],36:[2,54],38:[2,54],44:[2,54],47:[2,54]},{5:[2,55],8:[2,55],11:[2,55],12:[2,55],13:[2,55],15:[2,55],17:[2,55],19:[2,55],20:[2,55],21:[2,55],22:[2,55],24:[2,55],25:[2,55],26:[2,55],27:[2,55],29:[2,55],31:[2,55],34:[2,55],36:[2,55],38:[2,55],41:[1,44],42:[1,45],44:[2,55],46:[1,46],47:[2,55]},{5:[2,56],8:[2,56],11:[2,56],12:[2,56],13:[2,56],15:[2,56],17:[2,56],19:[2,56],20:[2,56],21:[2,56],22:[2,56],24:[2,56],25:[2,56],26:[2,56],27:[2,56],29:[2,56],31:[2,56],34:[2,56],36:[2,56],38:[2,56],44:[2,56],47:[2,56]},{4:47,6:28,7:7,8:[1,29],9:[1,30],10:27,14:25,16:17,18:8,23:6,28:5,30:15,32:14,33:4,35:3,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{5:[2,14],17:[1,48],19:[2,14],20:[2,14],21:[2,14],22:[2,14],24:[2,14],25:[2,14],26:[2,14],27:[2,14],34:[2,14],36:[2,14],47:[2,14]},{5:[2,43],8:[2,43],11:[2,43],12:[2,43],13:[2,43],15:[2,43],17:[2,43],19:[2,43],20:[2,43],21:[2,43],22:[2,43],24:[2,43],25:[2,43],26:[2,43],27:[2,43],29:[2,43],31:[2,43],34:[2,43],36:[2,43],38:[2,43],44:[2,43],47:[2,43]},{5:[2,44],8:[2,44],11:[2,44],12:[2,44],13:[2,44],15:[2,44],17:[2,44],19:[2,44],20:[2,44],21:[2,44],22:[2,44],24:[2,44],25:[2,44],26:[2,44],27:[2,44],29:[2,44],31:[2,44],34:[2,44],36:[2,44],38:[2,44],44:[2,44],47:[2,44]},{5:[2,45],8:[2,45],11:[2,45],12:[2,45],13:[2,45],15:[2,45],17:[2,45],19:[2,45],20:[2,45],21:[2,45],22:[2,45],24:[2,45],25:[2,45],26:[2,45],27:[2,45],29:[2,45],31:[2,45],34:[2,45],36:[2,45],38:[2,45],44:[2,45],47:[2,45]},{5:[2,46],8:[2,46],11:[2,46],12:[2,46],13:[2,46],15:[2,46],17:[2,46],19:[2,46],20:[2,46],21:[2,46],22:[2,46],24:[2,46],25:[2,46],26:[2,46],27:[2,46],29:[2,46],31:[2,46],34:[2,46],36:[2,46],38:[2,46],44:[2,46],47:[2,46]},{5:[2,47],8:[2,47],11:[2,47],12:[2,47],13:[2,47],15:[2,47],17:[2,47],19:[2,47],20:[2,47],21:[2,47],22:[2,47],24:[2,47],25:[2,47],26:[2,47],27:[2,47],29:[2,47],31:[2,47],34:[2,47],36:[2,47],38:[2,47],44:[2,47],47:[2,47]},{5:[2,36],8:[2,36],11:[2,36],12:[2,36],13:[2,36],15:[2,36],17:[2,36],19:[2,36],20:[2,36],21:[2,36],22:[2,36],24:[2,36],25:[2,36],26:[2,36],27:[2,36],29:[2,36],31:[2,36],34:[2,36],36:[2,36],38:[2,36],41:[2,36],42:[2,36],44:[2,36],46:[2,36],47:[2,36]},{7:51,30:15,32:14,37:50,39:23,40:[1,26],42:[1,24],43:9,44:[1,49],45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{5:[2,12],8:[1,53],15:[1,52],17:[2,12],19:[2,12],20:[2,12],21:[2,12],22:[2,12],24:[2,12],25:[2,12],26:[2,12],27:[2,12],34:[2,12],36:[2,12],47:[2,12]},{5:[2,35],8:[2,35],11:[2,35],12:[2,35],13:[2,35],15:[2,35],17:[2,35],19:[2,35],20:[2,35],21:[2,35],22:[2,35],24:[2,35],25:[2,35],26:[2,35],27:[2,35],29:[2,35],31:[2,35],34:[2,35],36:[2,35],38:[2,35],41:[2,35],42:[2,35],44:[2,35],46:[2,35],47:[2,35]},{5:[2,9],8:[2,9],11:[1,54],12:[1,55],13:[1,56],15:[2,9],17:[2,9],19:[2,9],20:[2,9],21:[2,9],22:[2,9],24:[2,9],25:[2,9],26:[2,9],27:[2,9],34:[2,9],36:[2,9],47:[2,9]},{5:[2,5],8:[2,5],11:[2,5],12:[2,5],13:[2,5],15:[2,5],17:[2,5],19:[2,5],20:[2,5],21:[2,5],22:[2,5],24:[2,5],25:[2,5],26:[2,5],27:[2,5],34:[2,5],36:[2,5],47:[2,5]},{6:57,7:58,8:[1,29],9:[1,30],30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:59,7:58,8:[1,29],9:[1,30],30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{1:[2,1]},{6:28,7:7,8:[1,29],9:[1,30],10:27,14:25,16:17,18:8,23:6,28:5,30:15,32:14,33:60,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:28,7:7,8:[1,29],9:[1,30],10:27,14:25,16:17,18:8,23:6,28:61,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:28,7:58,8:[1,29],9:[1,30],10:27,14:25,16:17,18:62,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:28,7:58,8:[1,29],9:[1,30],10:27,14:25,16:17,18:63,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:28,7:58,8:[1,29],9:[1,30],10:27,14:25,16:17,18:64,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:28,7:58,8:[1,29],9:[1,30],10:27,14:25,16:17,18:65,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{30:66,32:67,39:23,40:[1,26],42:[1,24]},{30:68,32:69,39:23,40:[1,26],42:[1,24]},{6:28,7:58,8:[1,29],9:[1,30],10:27,14:25,16:70,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:28,7:58,8:[1,29],9:[1,30],10:27,14:25,16:71,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:28,7:58,8:[1,29],9:[1,30],10:27,14:25,16:72,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:28,7:58,8:[1,29],9:[1,30],10:27,14:25,16:73,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{39:74,40:[1,26]},{32:77,39:23,40:[1,26],43:75,45:76,48:[1,18],49:[1,19]},{7:51,30:15,32:14,37:79,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],47:[1,78],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{47:[1,80]},{6:28,7:58,8:[1,29],9:[1,30],10:27,14:81,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{5:[2,48],8:[2,48],11:[2,48],12:[2,48],13:[2,48],15:[2,48],17:[2,48],19:[2,48],20:[2,48],21:[2,48],22:[2,48],24:[2,48],25:[2,48],26:[2,48],27:[2,48],29:[2,48],31:[2,48],34:[2,48],36:[2,48],38:[2,48],44:[2,48],47:[2,48]},{38:[1,83],44:[1,82]},{38:[2,33],44:[2,33],47:[2,33]},{6:28,7:58,8:[1,29],9:[1,30],10:84,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:28,7:58,8:[1,29],9:[1,30],10:85,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:86,7:58,8:[1,29],9:[1,30],30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:87,7:58,8:[1,29],9:[1,30],30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:88,7:58,8:[1,29],9:[1,30],30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{5:[2,3],8:[2,3],11:[2,3],12:[2,3],13:[2,3],15:[2,3],17:[2,3],19:[2,3],20:[2,3],21:[2,3],22:[2,3],24:[2,3],25:[2,3],26:[2,3],27:[2,3],34:[2,3],36:[2,3],47:[2,3]},{5:[2,2],8:[2,2],11:[2,2],12:[2,2],13:[2,2],15:[2,2],17:[2,2],19:[2,2],20:[2,2],21:[2,2],22:[2,2],24:[2,2],25:[2,2],26:[2,2],27:[2,2],34:[2,2],36:[2,2],47:[2,2]},{5:[2,4],8:[2,4],11:[2,4],12:[2,4],13:[2,4],15:[2,4],17:[2,4],19:[2,4],20:[2,4],21:[2,4],22:[2,4],24:[2,4],25:[2,4],26:[2,4],27:[2,4],34:[2,4],36:[2,4],47:[2,4]},{5:[2,32],34:[1,33],36:[2,32],47:[2,32]},{5:[2,30],34:[2,30],36:[2,30],47:[2,30]},{5:[2,20],19:[1,40],20:[1,41],21:[1,42],22:[1,43],24:[2,20],25:[2,20],26:[2,20],27:[2,20],34:[2,20],36:[2,20],47:[2,20]},{5:[2,21],19:[1,40],20:[1,41],21:[1,42],22:[1,43],24:[2,21],25:[2,21],26:[2,21],27:[2,21],34:[2,21],36:[2,21],47:[2,21]},{5:[2,22],19:[1,40],20:[1,41],21:[1,42],22:[1,43],24:[2,22],25:[2,22],26:[2,22],27:[2,22],34:[2,22],36:[2,22],47:[2,22]},{5:[2,23],19:[1,40],20:[1,41],21:[1,42],22:[1,43],24:[2,23],25:[2,23],26:[2,23],27:[2,23],34:[2,23],36:[2,23],47:[2,23]},{5:[2,25],34:[2,25],36:[2,25],47:[2,25]},{5:[2,27],34:[2,27],36:[2,27],41:[1,44],42:[1,45],46:[1,46],47:[2,27]},{5:[2,26],34:[2,26],36:[2,26],47:[2,26]},{5:[2,28],34:[2,28],36:[2,28],41:[1,44],42:[1,45],46:[1,46],47:[2,28]},{5:[2,15],17:[1,48],19:[2,15],20:[2,15],21:[2,15],22:[2,15],24:[2,15],25:[2,15],26:[2,15],27:[2,15],34:[2,15],36:[2,15],47:[2,15]},{5:[2,16],17:[1,48],19:[2,16],20:[2,16],21:[2,16],22:[2,16],24:[2,16],25:[2,16],26:[2,16],27:[2,16],34:[2,16],36:[2,16],47:[2,16]},{5:[2,17],17:[1,48],19:[2,17],20:[2,17],21:[2,17],22:[2,17],24:[2,17],25:[2,17],26:[2,17],27:[2,17],34:[2,17],36:[2,17],47:[2,17]},{5:[2,18],17:[1,48],19:[2,18],20:[2,18],21:[2,18],22:[2,18],24:[2,18],25:[2,18],26:[2,18],27:[2,18],34:[2,18],36:[2,18],47:[2,18]},{5:[2,37],8:[2,37],11:[2,37],12:[2,37],13:[2,37],15:[2,37],17:[2,37],19:[2,37],20:[2,37],21:[2,37],22:[2,37],24:[2,37],25:[2,37],26:[2,37],27:[2,37],29:[2,37],31:[2,37],34:[2,37],36:[2,37],38:[2,37],41:[2,37],42:[2,37],44:[2,37],46:[2,37],47:[2,37]},{44:[1,89]},{44:[1,90]},{41:[1,44],42:[1,45],44:[1,91],46:[1,46]},{5:[2,41],8:[2,41],11:[2,41],12:[2,41],13:[2,41],15:[2,41],17:[2,41],19:[2,41],20:[2,41],21:[2,41],22:[2,41],24:[2,41],25:[2,41],26:[2,41],27:[2,41],29:[2,41],31:[2,41],34:[2,41],36:[2,41],38:[2,41],41:[2,41],42:[2,41],44:[2,41],46:[2,41],47:[2,41]},{38:[1,83],47:[1,92]},{5:[2,57],8:[2,57],11:[2,57],12:[2,57],13:[2,57],15:[2,57],17:[2,57],19:[2,57],20:[2,57],21:[2,57],22:[2,57],24:[2,57],25:[2,57],26:[2,57],27:[2,57],29:[2,57],31:[2,57],34:[2,57],36:[2,57],38:[2,57],44:[2,57],47:[2,57]},{5:[2,13],8:[1,53],15:[1,52],17:[2,13],19:[2,13],20:[2,13],21:[2,13],22:[2,13],24:[2,13],25:[2,13],26:[2,13],27:[2,13],34:[2,13],36:[2,13],47:[2,13]},{5:[2,49],8:[2,49],11:[2,49],12:[2,49],13:[2,49],15:[2,49],17:[2,49],19:[2,49],20:[2,49],21:[2,49],22:[2,49],24:[2,49],25:[2,49],26:[2,49],27:[2,49],29:[2,49],31:[2,49],34:[2,49],36:[2,49],38:[2,49],44:[2,49],47:[2,49]},{7:93,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{5:[2,10],8:[2,10],11:[1,54],12:[1,55],13:[1,56],15:[2,10],17:[2,10],19:[2,10],20:[2,10],21:[2,10],22:[2,10],24:[2,10],25:[2,10],26:[2,10],27:[2,10],34:[2,10],36:[2,10],47:[2,10]},{5:[2,11],8:[2,11],11:[1,54],12:[1,55],13:[1,56],15:[2,11],17:[2,11],19:[2,11],20:[2,11],21:[2,11],22:[2,11],24:[2,11],25:[2,11],26:[2,11],27:[2,11],34:[2,11],36:[2,11],47:[2,11]},{5:[2,6],8:[2,6],11:[2,6],12:[2,6],13:[2,6],15:[2,6],17:[2,6],19:[2,6],20:[2,6],21:[2,6],22:[2,6],24:[2,6],25:[2,6],26:[2,6],27:[2,6],34:[2,6],36:[2,6],47:[2,6]},{5:[2,7],8:[2,7],11:[2,7],12:[2,7],13:[2,7],15:[2,7],17:[2,7],19:[2,7],20:[2,7],21:[2,7],22:[2,7],24:[2,7],25:[2,7],26:[2,7],27:[2,7],34:[2,7],36:[2,7],47:[2,7]},{5:[2,8],8:[2,8],11:[2,8],12:[2,8],13:[2,8],15:[2,8],17:[2,8],19:[2,8],20:[2,8],21:[2,8],22:[2,8],24:[2,8],25:[2,8],26:[2,8],27:[2,8],34:[2,8],36:[2,8],47:[2,8]},{5:[2,38],8:[2,38],11:[2,38],12:[2,38],13:[2,38],15:[2,38],17:[2,38],19:[2,38],20:[2,38],21:[2,38],22:[2,38],24:[2,38],25:[2,38],26:[2,38],27:[2,38],29:[2,38],31:[2,38],34:[2,38],36:[2,38],38:[2,38],41:[2,38],42:[2,38],44:[2,38],46:[2,38],47:[2,38]},{5:[2,39],8:[2,39],11:[2,39],12:[2,39],13:[2,39],15:[2,39],17:[2,39],19:[2,39],20:[2,39],21:[2,39],22:[2,39],24:[2,39],25:[2,39],26:[2,39],27:[2,39],29:[2,39],31:[2,39],34:[2,39],36:[2,39],38:[2,39],41:[2,39],42:[2,39],44:[2,39],46:[2,39],47:[2,39]},{5:[2,40],8:[2,40],11:[2,40],12:[2,40],13:[2,40],15:[2,40],17:[2,40],19:[2,40],20:[2,40],21:[2,40],22:[2,40],24:[2,40],25:[2,40],26:[2,40],27:[2,40],29:[2,40],31:[2,40],34:[2,40],36:[2,40],38:[2,40],41:[2,40],42:[2,40],44:[2,40],46:[2,40],47:[2,40]},{5:[2,42],8:[2,42],11:[2,42],12:[2,42],13:[2,42],15:[2,42],17:[2,42],19:[2,42],20:[2,42],21:[2,42],22:[2,42],24:[2,42],25:[2,42],26:[2,42],27:[2,42],29:[2,42],31:[2,42],34:[2,42],36:[2,42],38:[2,42],41:[2,42],42:[2,42],44:[2,42],46:[2,42],47:[2,42]},{38:[2,34],44:[2,34],47:[2,34]}],defaultActions:{31:[2,1]},parseError:function(a,b){if(!b.recoverable)throw new Error(a);this.trace(a)},parse:function(a){function b(){var a;return a=c.lexer.lex()||m,"number"!=typeof a&&(a=c.symbols_[a]||a),a}var c=this,d=[0],e=[null],f=[],g=this.table,h="",i=0,j=0,k=0,l=2,m=1;this.lexer.setInput(a),this.lexer.yy=this.yy,this.yy.lexer=this.lexer,this.yy.parser=this,"undefined"==typeof this.lexer.yylloc&&(this.lexer.yylloc={});var n=this.lexer.yylloc;f.push(n);var o=this.lexer.options&&this.lexer.options.ranges;this.parseError="function"==typeof this.yy.parseError?this.yy.parseError:Object.getPrototypeOf(this).parseError;for(var p,q,r,s,t,u,v,w,x,y={};;){if(r=d[d.length-1],this.defaultActions[r]?s=this.defaultActions[r]:((null===p||"undefined"==typeof p)&&(p=b()),s=g[r]&&g[r][p]),"undefined"==typeof s||!s.length||!s[0]){var z="";x=[];for(u in g[r])this.terminals_[u]&&u>l&&x.push("'"+this.terminals_[u]+"'");z=this.lexer.showPosition?"Parse error on line "+(i+1)+":\n"+this.lexer.showPosition()+"\nExpecting "+x.join(", ")+", got '"+(this.terminals_[p]||p)+"'":"Parse error on line "+(i+1)+": Unexpected "+(p==m?"end of input":"'"+(this.terminals_[p]||p)+"'"),this.parseError(z,{text:this.lexer.match,token:this.terminals_[p]||p,line:this.lexer.yylineno,loc:n,expected:x})}if(s[0]instanceof Array&&s.length>1)throw new Error("Parse Error: multiple actions possible at state: "+r+", token: "+p);switch(s[0]){case 1:d.push(p),e.push(this.lexer.yytext),f.push(this.lexer.yylloc),d.push(s[1]),p=null,q?(p=q,q=null):(j=this.lexer.yyleng,h=this.lexer.yytext,i=this.lexer.yylineno,n=this.lexer.yylloc,k>0&&k--);break;case 2:if(v=this.productions_[s[1]][1],y.$=e[e.length-v],y._$={first_line:f[f.length-(v||1)].first_line,last_line:f[f.length-1].last_line,first_column:f[f.length-(v||1)].first_column,last_column:f[f.length-1].last_column},o&&(y._$.range=[f[f.length-(v||1)].range[0],f[f.length-1].range[1]]),t=this.performAction.call(y,h,j,i,this.yy,s[1],e,f),"undefined"!=typeof t)return t;v&&(d=d.slice(0,2*-1*v),e=e.slice(0,-1*v),f=f.slice(0,-1*v)),d.push(this.productions_[s[1]][0]),e.push(y.$),f.push(y._$),w=g[d[d.length-2]][d[d.length-1]],d.push(w);break;case 3:return!0}}return!0}},c=function(){var a={EOF:1,parseError:function(a,b){if(!this.yy.parser)throw new Error(a);this.yy.parser.parseError(a,b)},setInput:function(a){return this._input=a,this._more=this._backtrack=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},input:function(){var a=this._input[0];this.yytext+=a,this.yyleng++,this.offset++,this.match+=a,this.matched+=a;var b=a.match(/(?:\r\n?|\n).*/g);return b?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),a},unput:function(a){var b=a.length,c=a.split(/(?:\r\n?|\n)/g);this._input=a+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-b-1),this.offset-=b;var d=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),c.length-1&&(this.yylineno-=c.length-1);var e=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:c?(c.length===d.length?this.yylloc.first_column:0)+d[d.length-c.length].length-c[0].length:this.yylloc.first_column-b},this.options.ranges&&(this.yylloc.range=[e[0],e[0]+this.yyleng-b]),this.yyleng=this.yytext.length,this},more:function(){return this._more=!0,this},reject:function(){return this.options.backtrack_lexer?(this._backtrack=!0,this):this.parseError("Lexical error on line "+(this.yylineno+1)+". You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},less:function(a){this.unput(this.match.slice(a))},pastInput:function(){var a=this.matched.substr(0,this.matched.length-this.match.length);return(a.length>20?"...":"")+a.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var a=this.match;return a.length<20&&(a+=this._input.substr(0,20-a.length)),(a.substr(0,20)+(a.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var a=this.pastInput(),b=new Array(a.length+1).join("-");return a+this.upcomingInput()+"\n"+b+"^"},test_match:function(a,b){var c,d,e;if(this.options.backtrack_lexer&&(e={yylineno:this.yylineno,yylloc:{first_line:this.yylloc.first_line,last_line:this.last_line,first_column:this.yylloc.first_column,last_column:this.yylloc.last_column},yytext:this.yytext,match:this.match,matches:this.matches,matched:this.matched,yyleng:this.yyleng,offset:this.offset,_more:this._more,_input:this._input,yy:this.yy,conditionStack:this.conditionStack.slice(0),done:this.done},this.options.ranges&&(e.yylloc.range=this.yylloc.range.slice(0))),d=a[0].match(/(?:\r\n?|\n).*/g),d&&(this.yylineno+=d.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:d?d[d.length-1].length-d[d.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+a[0].length},this.yytext+=a[0],this.match+=a[0],this.matches=a,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._backtrack=!1,this._input=this._input.slice(a[0].length),this.matched+=a[0],c=this.performAction.call(this,this.yy,this,b,this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),c)return c;if(this._backtrack){for(var f in e)this[f]=e[f];return!1}return!1},next:function(){if(this.done)return this.EOF;this._input||(this.done=!0);var a,b,c,d;this._more||(this.yytext="",this.match="");for(var e=this._currentRules(),f=0;fb[0].length)){if(b=c,d=f,this.options.backtrack_lexer){if(a=this.test_match(c,e[f]),a!==!1)return a;if(this._backtrack){b=!1;continue}return!1}if(!this.options.flex)break}return b?(a=this.test_match(b,e[d]),a!==!1?a:!1):""===this._input?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+". Unrecognized text.\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){var a=this.next();return a?a:this.lex()},begin:function(a){this.conditionStack.push(a)},popState:function(){var a=this.conditionStack.length-1;return a>0?this.conditionStack.pop():this.conditionStack[0]},_currentRules:function(){return this.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]?this.conditions[this.conditionStack[this.conditionStack.length-1]].rules:this.conditions.INITIAL.rules},topState:function(a){return a=this.conditionStack.length-1-Math.abs(a||0),a>=0?this.conditionStack[a]:"INITIAL"},pushState:function(a){this.begin(a)},stateStackSize:function(){return this.conditionStack.length},options:{},performAction:function(a,b,c,d){switch(c){case 0:return 29;case 1:return 31;case 2:return"from";case 3:return 24;case 4:return 25;case 5:return 21;case 6:return 19;case 7:return 22;case 8:return 20;case 9:return 26;case 10:return 27;case 11:return 34;case 12:return 36;case 13:return 55;case 14:return 53;case 15:break;case 16:return 49;case 17:return 48;case 18:return 48;case 19:return 40;case 20:return 51;case 21:return 41;case 22:return 11;case 23:return 12;case 24:return 13;case 25:return 38;case 26:return 8;case 27:return 26;case 28:return 27;case 29:return 24;case 30:return 24;case 31:return 25;case 32:return 25;case 33:return 21;case 34:return 22;case 35:return 20;case 36:return 19;case 37:return 34;case 38:return 36;case 39:return 15;case 40:return 17;case 41:return 46;case 42:return 44;case 43:return 42;case 44:return 47;case 45:return 9;case 46:return 5}},rules:[/^(?:\s+in\b)/,/^(?:\s+notIn\b)/,/^(?:\s+from\b)/,/^(?:\s+(eq|EQ)\b)/,/^(?:\s+(neq|NEQ)\b)/,/^(?:\s+(lte|LTE)\b)/,/^(?:\s+(lt|LT)\b)/,/^(?:\s+(gte|GTE)\b)/,/^(?:\s+(gt|GT)\b)/,/^(?:\s+(like|LIKE)\b)/,/^(?:\s+(notLike|NOT_LIKE)\b)/,/^(?:\s+(and|AND)\b)/,/^(?:\s+(or|OR)\b)/,/^(?:\s+null\b)/,/^(?:\s+(true|false)\b)/,/^(?:\s+)/,/^(?:-?[0-9]+(?:\.[0-9]+)?\b)/,/^(?:'[^']*')/,/^(?:"[^"]*")/,/^(?:([a-zA-Z_$][0-9a-zA-Z_$]*))/,/^(?:^\/((?![\s=])[^[\/\n\\]*(?:(?:\\[\s\S]|\[[^\]\n\\]*(?:\\[\s\S][^\]\n\\]*)*])[^[\/\n\\]*)*\/[imgy]{0,4})(?!\w))/,/^(?:\.)/,/^(?:\*)/,/^(?:\/)/,/^(?:\%)/,/^(?:,)/,/^(?:-)/,/^(?:=~)/,/^(?:!=~)/,/^(?:==)/,/^(?:===)/,/^(?:!=)/,/^(?:!==)/,/^(?:<=)/,/^(?:>=)/,/^(?:>)/,/^(?:<)/,/^(?:&&)/,/^(?:\|\|)/,/^(?:\+)/,/^(?:\^)/,/^(?:\()/,/^(?:\])/,/^(?:\[)/,/^(?:\))/,/^(?:!)/,/^(?:$)/],conditions:{INITIAL:{rules:[0,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],inclusive:!0}}};return a}();return b.lexer=c,a.prototype=b,b.Parser=a,new a}();"undefined"!=typeof a&&"undefined"!=typeof c&&(c.parser=e,c.Parser=e.Parser,c.parse=function(){return e.parse.apply(e,arguments)},c.main=function(b){b[1]||(console.log("Usage: "+b[0]+" FILE"),d.exit(1));var e=a("fs").readFileSync(a("path").normalize(b[1]),"utf8");return c.parser.parse(e)},"undefined"!=typeof b&&a.main===b&&c.main(d.argv.slice(1)))},{__browserify_process:68,fs:65,path:66}],41:[function(a,b,c){!function(){"use strict";var b=a("./constraint/parser"),d=a("./nools/nool.parser");c.parseConstraint=function(a){try{return b.parse(a)}catch(c){throw new Error("Invalid expression '"+a+"'")}},c.parseRuleSet=function(a,b){return d.parse(a,b)}}()},{"./constraint/parser":40,"./nools/nool.parser":42}],42:[function(a,b,c){"use strict";var d=a("./tokens.js"),e=a("../../extended"),f=e.hash.keys,g=a("./util.js"),h=function(a,b,c){var d=a;a=a.replace(/\/\/(.*)/g,"").replace(/\n|\r|\r\n/g," ");for(var e,i=new RegExp("^("+f(b).join("|")+")");a&&-1!==(e=g.findNextTokenIndex(a));){a=a.substr(e);var j=a.match(i);if(null===j)throw new Error("Error parsing "+a);if(j=j[1],!(j in b))throw new Error("Unknown token"+j);try{a=b[j](a,c,h).replace(/^\s*|\s*$/g,"")}catch(k){throw new Error("Invalid "+j+" definition \n"+k.message+"; \nstarting at : "+d)}}};c.parse=function(a,b){var c={define:[],rules:[],scope:[],loaded:[],file:b};return h(a,d,c),c}},{"../../extended":12,"./tokens.js":43,"./util.js":44}],43:[function(require,module,exports){var process=require("__browserify_process"),utils=require("./util.js"),fs=require("fs"),extd=require("../../extended"),filter=extd.filter,indexOf=extd.indexOf,predicates=["not","or","exists"],predicateRegExp=new RegExp("^("+predicates.join("|")+") *\\((.*)\\)$","m"),predicateBeginExp=new RegExp(" *("+predicates.join("|")+") *\\(","g"),isWhiteSpace=function(a){return 0===a.replace(/[\s|\n|\r|\t]/g,"").length},joinFunc=function(a,b){return"; "+b},splitRuleLineByPredicateExpressions=function(a){var b=a.replace(/,\s*(\$?\w+\s*:)/g,joinFunc),c=filter(b.split(predicateBeginExp),function(a){return""!==a}),d=c.length,e=[];if(!d)return b;for(var f=0;d>f;f++)-1!==indexOf(predicates,c[f])?e.push([c[f],"(",c[++f].replace(/, *$/,"")].join("")):e.push(c[f].replace(/, *$/,""));return e.join(";")},ruleTokens={salience:function(){var a=/^(salience|priority)\s*:\s*(-?\d+)\s*[,;]?/;return function(b,c){if(a.test(b)){var d=b.match(a),e=parseInt(d[2],10);if(isNaN(e))throw new Error("Invalid salience/priority "+d[2]);return c.options.priority=e,b.replace(d[0],"")}throw new Error("invalid format")}}(),agendaGroup:function(){var a=/^(agenda-group|agendaGroup)\s*:\s*([a-zA-Z_$][0-9a-zA-Z_$]*|"[^"]*"|'[^']*')\s*[,;]?/;return function(b,c){if(a.test(b)){var d=b.match(a),e=d[2];if(!e)throw new Error("Invalid agenda-group "+d[2]);return c.options.agendaGroup=e.replace(/^["']|["']$/g,""),b.replace(d[0],"")}throw new Error("invalid format")}}(),autoFocus:function(){var a=/^(auto-focus|autoFocus)\s*:\s*(true|false)\s*[,;]?/;return function(b,c){if(a.test(b)){var d=b.match(a),e=d[2];if(!e)throw new Error("Invalid auto-focus "+d[2]);return c.options.autoFocus="true"===e?!0:!1,b.replace(d[0],"")}throw new Error("invalid format")}}(),"agenda-group":function(){return this.agendaGroup.apply(this,arguments)},"auto-focus":function(){return this.autoFocus.apply(this,arguments)},priority:function(){return this.salience.apply(this,arguments)},when:function(){var ruleRegExp=/^(\$?\w+) *: *(\w+)(.*)/,constraintRegExp=/(\{ *(?:["']?\$?\w+["']?\s*:\s*["']?\$?\w+["']? *(?:, *["']?\$?\w+["']?\s*:\s*["']?\$?\w+["']?)*)+ *\})/,fromRegExp=/(\bfrom\s+.*)/,parseRules=function(str){for(var rules=[],ruleLines=str.split(";"),l=ruleLines.length,ruleLine,i=0;l>i&&(ruleLine=ruleLines[i].replace(/^\s*|\s*$/g,"").replace(/\n/g,""));i++)if(!isWhiteSpace(ruleLine)){var rule=[];if(predicateRegExp.test(ruleLine)){var m=ruleLine.match(predicateRegExp),pred=m[1].replace(/^\s*|\s*$/g,"");if(rule.push(pred),ruleLine=m[2].replace(/^\s*|\s*$/g,""),"or"===pred){rule=rule.concat(parseRules(splitRuleLineByPredicateExpressions(ruleLine))),rules.push(rule);continue}}var parts=ruleLine.match(ruleRegExp);if(!parts||!parts.length)throw new Error("Invalid constraint "+ruleLine);rule.push(parts[2],parts[1]);var constraints=parts[3].replace(/^\s*|\s*$/g,""),hashParts=constraints.match(constraintRegExp),from=null,fromMatch;if(hashParts){var hash=hashParts[1],constraint=constraints.replace(hash,"");fromRegExp.test(constraint)&&(fromMatch=constraint.match(fromRegExp),from=fromMatch[0],constraint=constraint.replace(fromMatch[0],"")),constraint&&rule.push(constraint.replace(/^\s*|\s*$/g,"")),hash&&rule.push(eval("("+hash.replace(/(\$?\w+)\s*:\s*(\$?\w+)/g,'"$1" : "$2"')+")"))}else constraints&&!isWhiteSpace(constraints)&&(fromRegExp.test(constraints)&&(fromMatch=constraints.match(fromRegExp),from=fromMatch[0],constraints=constraints.replace(fromMatch[0],"")),rule.push(constraints));from&&rule.push(from),rules.push(rule)}return rules};return function(a,b){var c=a.replace(/^when\s*/,"").replace(/^\s*|\s*$/g,"");if("{"===utils.findNextToken(c)){var d=utils.getTokensBetween(c,"{","}",!0).join("");return c=c.replace(d,""),b.constraints=parseRules(d.replace(/^\{\s*|\}\s*$/g,"")),c}throw new Error("unexpected token : expected : '{' found : '"+utils.findNextToken(c)+"'")}}(),then:function(){return function(a,b){if(b.action)throw new Error("action already defined for rule"+b.name);var c=a.replace(/^then\s*/,"").replace(/^\s*|\s*$/g,"");if("{"===utils.findNextToken(c)){var d=utils.getTokensBetween(c,"{","}",!0).join(""); +if(c=c.replace(d,""),b.action||(b.action=d.replace(/^\{\s*|\}\s*$/g,"")),!isWhiteSpace(c))throw new Error("Error parsing then block "+a);return c}throw new Error("unexpected token : expected : '{' found : '"+utils.findNextToken(c)+"'")}}()},topLevelTokens={"/":function(a){return a.match(/^\/\*/)?a.replace(/\/\*.*?\*\//,""):a},define:function(a,b){var c=a.replace(/^define\s*/,""),d=c.match(/^([a-zA-Z_$][0-9a-zA-Z_$]*)/);if(d){if(c=c.replace(d[0],"").replace(/^\s*|\s*$/g,""),"{"===utils.findNextToken(c)){d=d[1];var e=utils.getTokensBetween(c,"{","}",!0).join("");return c=c.replace(e,""),b.define.push({name:d,properties:"("+e+")"}),c}throw new Error("unexpected token : expected : '{' found : '"+utils.findNextToken(c)+"'")}throw new Error("missing name")},"import":function(a,b,c){if("undefined"!=typeof window)throw new Error("import cannot be used in a browser");var d=a.replace(/^import\s*/,"");if("("===utils.findNextToken(d)){var e=utils.getParamList(d);if(d=d.replace(e,"").replace(/^\s*|\s*$/g,""),";"===utils.findNextToken(d)&&(d=d.replace(/\s*;/,"")),e=e.replace(/[\(|\)]/g,"").split(","),1===e.length){if(e=utils.resolve(b.file||process.cwd(),e[0].replace(/["|']/g,"")),-1===indexOf(b.loaded,e)){var f=b.file;b.file=e,c(fs.readFileSync(e,"utf8"),topLevelTokens,b),b.loaded.push(e),b.file=f}return d}throw new Error("import accepts a single file")}throw new Error("unexpected token : expected : '(' found : '"+utils.findNextToken(d)+"'")},global:function(a,b){var c=a.replace(/^global\s*/,""),d=c.match(/^([a-zA-Z_$][0-9a-zA-Z_$]*\s*)/);if(d){if(c=c.replace(d[0],"").replace(/^\s*|\s*$/g,""),"="===utils.findNextToken(c)){d=d[1].replace(/^\s+|\s+$/g,"");var e=utils.getTokensBetween(c,"=",";",!0).join(""),f=e.substring(1,e.length-1);if(f=f.replace(/^\s+|\s+$/g,""),/^require\(/.test(f)){var g=utils.getParamList(f.replace("require")).replace(/[\(|\)]/g,"").split(",");1===g.length&&(g=g[0].replace(/["|']/g,""),f=["require('",utils.resolve(b.file||process.cwd(),g),"')"].join(""))}return b.scope.push({name:d,body:f}),c=c.replace(e,"")}throw new Error("unexpected token : expected : '=' found : '"+utils.findNextToken(c)+"'")}throw new Error("missing name")},"function":function(a,b){var c=a.replace(/^function\s*/,""),d=c.match(/^([a-zA-Z_$][0-9a-zA-Z_$]*)\s*/);if(d){if(c=c.replace(d[0],""),"("===utils.findNextToken(c)){d=d[1];var e=utils.getParamList(c);if(c=c.replace(e,"").replace(/^\s*|\s*$/g,""),"{"===utils.findNextToken(c)){var f=utils.getTokensBetween(c,"{","}",!0).join("");return c=c.replace(f,""),b.scope.push({name:d,body:"function"+e+f}),c}throw new Error("unexpected token : expected : '{' found : '"+utils.findNextToken(c)+"'")}throw new Error("unexpected token : expected : '(' found : '"+utils.findNextToken(c)+"'")}throw new Error("missing name")},rule:function(a,b,c){var d=a.replace(/^rule\s*/,""),e=d.match(/^([a-zA-Z_$][0-9a-zA-Z_$]*|"[^"]*"|'[^']*')/);if(e){if(d=d.replace(e[0],"").replace(/^\s*|\s*$/g,""),"{"===utils.findNextToken(d)){e=e[1].replace(/^["']|["']$/g,"");var f={name:e,options:{},constraints:null,action:null},g=utils.getTokensBetween(d,"{","}",!0).join("");return d=d.replace(g,""),c(g.replace(/^\{\s*|\}\s*$/g,""),ruleTokens,f),b.rules.push(f),d}throw new Error("unexpected token : expected : '{' found : '"+utils.findNextToken(d)+"'")}throw new Error("missing name")}};module.exports=topLevelTokens},{"../../extended":12,"./util.js":44,__browserify_process:68,fs:65}],44:[function(a,b,c){var d=a("__browserify_process"),e=a("path"),f=/[\s|\n|\r|\t]/,g=e.sep||("win32"===d.platform?"\\":"/"),h={"{":"}","}":"{","(":")",")":"(","[":"]"},i=c.getTokensBetween=function(a,b,c,d){var e=0,f=[];b||(b=h[c],e=1),c||(c=h[b]),a=Object(a);for(var g,i=!1,j=0,k=!1;g=a.charAt(j++);)if(g===b)e++,i?f.push(g):(i=!0,d&&f.push(g));else if(g===c&&j){if(e--,0===e){d&&f.push(g),k=!0;break}f.push(g)}else i&&f.push(g);if(!k)throw new Error("Unable to match "+b+" in "+a);return f};c.getParamList=function(a){return i(a,"(",")",!0).join("")},c.resolve=function(a,b){return""!==e.extname(a)&&(a=e.dirname(a)),1===b.split(g).length?b:e.resolve(a,b)};var j=c.findNextTokenIndex=function(a,b,c){b=b||0,c=c||a.length;var d=-1,e=a.length;for((!c||c>e)&&(c=e);c>b;b++){var g=a.charAt(b);if(!f.test(g)){d=b;break}}return d};c.findNextToken=function(a,b,c){return a.charAt(j(a,b,c))}},{__browserify_process:68,path:66}],45:[function(a,b,c){"use strict";var d=a("./extended"),e=d.isEmpty,f=d.merge,g=d.forEach,h=d.declare,i=a("./constraintMatcher"),j=a("./constraint"),k=j.EqualityConstraint,l=j.FromConstraint,m=0,n=h({}),o=n.extend({instance:{constructor:function(a,b,c,d,h){h=h||{},this.id=m++,this.type=a,this.alias=b,this.conditions=c,this.pattern=h.pattern;var k=[new j.ObjectConstraint(a)],l=i.toConstraints(c,f({alias:b},h));if(l.length)k=k.concat(l);else{var n=new j.TrueConstraint;k.push(n)}if(d&&!e(d)){var o=new j.HashConstraint(d);k.push(o)}g(k,function(a){a.set("alias",b)}),this.constraints=k},getSpecificity:function(){for(var a=this.constraints,b=0,c=0,d=a.length;d>c;c++)a[c]instanceof k&&b++;return b},hasConstraint:function(a){return d.some(this.constraints,function(b){return b instanceof a})},hashCode:function(){return[this.type,this.alias,d.format("%j",this.conditions)].join(":")},toString:function(){return d.format("%j",this.constraints)}}}).as(c,"ObjectPattern"),p=o.extend({instance:{constructor:function(a,b,c,d,e,f){this._super([a,b,c,d,f]),this.from=new l(e,f)},hasConstraint:function(a){return d.some(this.constraints,function(b){return b instanceof a})},getSpecificity:function(){return this._super(arguments)+1},hashCode:function(){return[this.type,this.alias,d.format("%j",this.conditions),this.from.from].join(":")},toString:function(){return d.format("%j from %s",this.constraints,this.from.from)}}}).as(c,"FromPattern");p.extend().as(c,"FromNotPattern"),o.extend().as(c,"NotPattern"),o.extend().as(c,"ExistsPattern"),p.extend().as(c,"FromExistsPattern"),n.extend({instance:{constructor:function(a,b){this.id=m++,this.leftPattern=a,this.rightPattern=b},hashCode:function(){return[this.leftPattern.hashCode(),this.rightPattern.hashCode()].join(":")},getSpecificity:function(){return this.rightPattern.getSpecificity()+this.leftPattern.getSpecificity()},getters:{constraints:function(){return this.leftPattern.constraints.concat(this.rightPattern.constraints)}}}}).as(c,"CompositePattern");var q=h({instance:{constructor:function(){this.id=m++,this.recency=0}}}).as(c,"InitialFact");o.extend({instance:{constructor:function(){this._super([q,"__i__",[],{}])},assert:function(){return!0}}}).as(c,"InitialFactPattern")},{"./constraint":8,"./constraintMatcher":9,"./extended":12}],46:[function(a,b,c){"use strict";function d(a,b,c,d){f(b)?(d=c,c=b):b=b||{};var g=e.every(c,function(a){return f(a)});g&&1===c.length&&(c=c[0],g=!1);var h=[],i=b.scope||{};if(c.scope=i,g){for(var j,k=function(a,b){m[b]?e(m).forEach(function(b){b.push(a)}):(m[b]=0===b?[]:m[b-1].slice(),0!==b&&m[b].pop(),m[b].push(a))},l=c.length,m=[],n=0;l>n;n++)j=c[n],j.scope=i,e.forEach(y(j),k);h=e.map(m,function(c){for(var e=null,f=0;f>>0;if(0===d)return-1;var e=d;arguments.length>2&&(e=Number(arguments[2]),e!==e?e=0:0!==e&&e!==1/0&&e!==-(1/0)&&(e=(e>0||-1)*P(Q(e))));for(var f=e>=0?R(e,d-1):d-Q(e);f>=0;f--)if(f in c&&c[f]===b)return f;return-1}function i(a,b,c){if(a&&X&&X===a.filter)return a.filter(b,c);if(!N(a)||"function"!=typeof b)throw new TypeError;for(var d=Object(a),e=d.length>>>0,f=[],g=0;e>g;g++)if(g in d){var h=d[g];b.call(c,h,g,d)&&f.push(h)}return f}function j(a,b,c){if(!N(a)||"function"!=typeof b)throw new TypeError;if(a&&T&&T===a.forEach)return a.forEach(b,c),a;for(var d=0,e=a.length;e>d;++d)b.call(c||a,a[d],d,a);return a}function k(a,b,c){if(a&&Y&&Y===a.every)return a.every(b,c);if(!N(a)||"function"!=typeof b)throw new TypeError;for(var d=Object(a),e=d.length>>>0,f=0;e>f;f++)if(f in d&&!b.call(c,d[f],f,d))return!1;return!0}function l(a,b,c){if(a&&Z&&Z===a.some)return a.some(b,c);if(!N(a)||"function"!=typeof b)throw new TypeError;for(var d=Object(a),e=d.length>>>0,f=0;e>f;f++)if(f in d&&b.call(c,d[f],f,d))return!0;return!1}function m(a,b,c){if(a&&U&&U===a.map)return a.map(b,c);if(!N(a)||"function"!=typeof b)throw new TypeError;for(var d=Object(a),e=d.length>>>0,f=[],g=0;e>g;g++)g in d&&f.push(b.call(c,d[g],g,d));return f}function n(a,b,c){var d=arguments.length>2;if(a&&V&&V===a.reduce)return d?a.reduce(b,c):a.reduce(b);if(!N(a)||"function"!=typeof b)throw new TypeError;var e=0,f=a.length>>0;if(arguments.length<3){if(0===f)throw new TypeError("Array length is 0 and no second argument");c=a[0],e=1}else c=arguments[2];for(;f>e;)e in a&&(c=b.call(void 0,c,a[e],e,a)),++e;return c}function o(a,b,c){var d=arguments.length>2;if(a&&W&&W===a.reduceRight)return d?a.reduceRight(b,c):a.reduceRight(b);if(!N(a)||"function"!=typeof b)throw new TypeError;var e=Object(a),f=e.length>>>0;if(0===f&&2===arguments.length)throw new TypeError;var g=f-1;if(arguments.length>=3)c=arguments[2];else for(;;)if(g in a){c=a[g--];break}for(;g>=0;)g in e&&(c=b.call(void 0,c,e[g],g,e)),g--;return c}function p(a){var c=[];if(null!==a){var d=$(arguments);if(1===d.length)if(N(a))c=a;else if(b.isHash(a))for(var e in a)a.hasOwnProperty(e)&&c.push([e,a[e]]);else c.push(a);else j(d,function(a){c=c.concat(p(a))})}return c}function q(a){return a=a||[],a.length?n(a,function(a,b){return a+b}):0}function r(a){if(a=a||[],a.length){var c=q(a);if(b.isNumber(c))return c/a.length;throw new Error("Cannot average an array of non numbers.")}return 0}function s(a,b){return _(a,b)}function t(a,b){return _(a,b)[0]}function u(a,b){return _(a,b)[a.length-1]}function v(a){var b=a,c=J($(arguments,1));return N(a)&&(b=i(a,function(a){return-1===g(c,a)})),b}function w(a){var b,c=[],d=-1,e=0;if(a)for(b=a.length;++d0?(c.push(c.shift()),b--):(c.unshift(c.pop()),b++),y(c,b)):c}function z(a,b){var c=[];if(N(a)){var d=a.slice(0);"number"!=typeof b&&(b=a.length),b?b<=a.length&&(c=n(a,function(a,c,f){var g;return g=b>1?e(c,y(d,f).slice(1),b):[[c]],a.concat(g)},[])):c=[[]]}return c}function A(){var a=[],c=$(arguments);if(c.length>1){var d=c.shift();N(d)&&(a=n(d,function(a,d,e){for(var f=[d],g=0;gd;d++)c.push(a[b[d]]||null);return c}function D(){var a=[],b=$(arguments);if(b.length>1){for(var c=0,d=b.length;d>c;c++)a=a.concat(b[c]);a=w(a)}return a}function E(){var a,b,c=[],d=-1;if(a=arguments.length>1?$(arguments):arguments[0],N(a))for(c=a[0],d=0,b=a.length;++d1?c:p(a),n(b,function(a,b){return a.concat(b)},[])}function K(a,b){b=b.split(".");var c=a.slice(0);return j(b,function(a){var b=a.match(/(\w+)\(\)$/);c=m(c,function(c){return b?c[b[1]]():c[a]})}),c}function L(a,b,c){return c=$(arguments,2),m(a,function(a){var d=M(b)?a[b]:b;return d.apply(a,c)})}var M=b.isString,N=Array.isArray||b.isArray,O=b.isDate,P=Math.floor,Q=Math.abs,R=(Math.max,Math.min),S=Array.prototype,T=(S.indexOf,S.forEach),U=S.map,V=S.reduce,W=S.reduceRight,X=S.filter,Y=S.every,Z=S.some,$=c.argsToArray,_=function(){var a=function(a,b){return k(a,b)},b=function(a,b){return a-b},c=function(a,b){return a.getTime()-b.getTime()};return function(d,e){var f=[];return N(d)&&(f=d.slice(),e?"function"==typeof e?f.sort(e):f.sort(function(a,b){var c=a[e],d=b[e];return M(c)&&M(d)?c>d?1:d>c?-1:0:O(c)&&O(d)?c.getTime()-d.getTime():c-d}):a(f,M)?f.sort():a(f,O)?f.sort(c):f.sort(b)),f}}(),ab={toArray:p,sum:q,avg:r,sort:s,min:t,max:u,difference:v,removeDuplicates:w,unique:x,rotate:y,permutations:z,zip:A,transpose:B,valuesAt:C,union:D,intersect:E,powerSet:F,cartesian:G,compact:H,multiply:I,flatten:J,pluck:K,invoke:L,forEach:j,map:m,filter:i,reduce:n,reduceRight:o,some:l,every:k,indexOf:g,lastIndexOf:h};return a.define(N,ab).expose(ab)}"undefined"!=typeof c?"undefined"!=typeof b&&b.exports&&(b.exports=d(a("extended"),a("is-extended"),a("arguments-extended"))):"function"==typeof define&&define.amd?define(["extended","is-extended","arguments-extended"],function(a,b,c){return d(a,b,c)}):this.arrayExtended=d(this.extended,this.isExtended,this.argumentsExtended)}.call(this)},{"arguments-extended":48,extended:53,"is-extended":70}],50:[function(a,b,c){!function(){"use strict";function d(a,b,c){function d(a,b,c,d){a=""+a,c=c||" ";for(var e=a.length;b>e;)d?a+=c:a=c+a,e++;return a}function e(a,c,d){var f=a;if(b.isString(f)){if(a.length>c)if(d){var g=a.length;f=a.substring(g-c,g)}else f=a.substring(0,c)}else f=e(""+f,c);return f}function f(a,c,d){if(!b.isArray(a)||"function"!=typeof c)throw new TypeError;for(var e=Object(a),f=e.length>>>0,g=0;f>g;g++)if(g in e&&!c.call(d,e[g],g,e))return!1;return!0}function g(a,b){return A.difference(new Date(a.getFullYear(),0,1,a.getHours()),a,null,b)+1}function h(a,b,c){b=b||0;var d=a[c?"getUTCFullYear":"getFullYear"](),e=new Date(d,0,1).getDay(),f=(e-b+7)%7,h=o((g(a)+f-1)/7);return e===b&&h++,h}function i(a){var b=a.toString(),c="",d=b.indexOf("(");return d>-1&&(c=b.substring(++d,b.indexOf(")"))),c}function j(a,b){return a.replace(/([a-z])\1*/gi,function(a){var c,d=a.charAt(0),e=a.length,f="0?",g="0{0,2}";if("y"===d)c="\\d{2,4}";else if("M"===d)c=e>2?"\\S+?":"1[0-2]|"+f+"[1-9]";else if("D"===d)c="[12][0-9][0-9]|3[0-5][0-9]|36[0-6]|"+g+"[1-9][0-9]|"+f+"[1-9]";else if("d"===d)c="3[01]|[12]\\d|"+f+"[1-9]";else if("w"===d)c="[1-4][0-9]|5[0-3]|"+f+"[1-9]";else if("E"===d)c="\\S+";else if("h"===d)c="1[0-2]|"+f+"[1-9]";else if("K"===d)c="1[01]|"+f+"\\d";else if("H"===d)c="1\\d|2[0-3]|"+f+"\\d";else if("k"===d)c="1\\d|2[0-4]|"+f+"[1-9]";else if("m"===d||"s"===d)c="[0-5]\\d";else if("S"===d)c="\\d{"+e+"}";else if("a"===d){var h="AM",i="PM";c=h+"|"+i,h!==h.toLowerCase()&&(c+="|"+h.toLowerCase()),i!==i.toLowerCase()&&(c+="|"+i.toLowerCase()),c=c.replace(/\./g,"\\.")}else c="v"===d||"z"===d||"Z"===d||"G"===d||"q"===d||"Q"===d?".*":" "===d?"\\s*":d+"*";return b&&b.push(a),"("+c+")"}).replace(/[\xa0 ]/g,"[\\s\\xa0]")}function k(a){B[a+"sFromNow"]=function(b){return A.add(new Date,a,b)},B[a+"sAgo"]=function(b){return A.add(new Date,a,-b)}}for(var l=function(){function a(a,b,c){return a=a.replace(/s$/,""),e.hasOwnProperty(a)?e[a](b,c):[c,"UTC"+a.charAt(0).toUpperCase()+a.substring(1)+"s",!1]}function b(a,b,c,e){return a=a.replace(/s$/,""),d(f[a](b,c,e))}var c=Math.floor,d=Math.round,e={day:function(a,b){return[b,"Date",!1]},weekday:function(a,b){var c,d,e=b%5,f=a.getDay(),g=0;e?(c=e,d=parseInt(b/5,10)):(c=b>0?5:-5,d=b>0?(b-5)/5:(b+5)/5),6===f&&b>0?g=1:0===f&&0>b&&(g=-1);var h=f+c;return(0===h||6===h)&&(g=b>0?2:-2),[7*d+c+g,"Date",!1]},year:function(a,b){return[b,"FullYear",!0]},week:function(a,b){return[7*b,"Date",!1]},quarter:function(a,b){return[3*b,"Month",!0]},month:function(a,b){return[b,"Month",!0]}},f={quarter:function(a,b,d){var e=b.getFullYear()-a.getFullYear(),f=a[d?"getUTCMonth":"getMonth"](),g=b[d?"getUTCMonth":"getMonth"](),h=c(f/3)+1,i=c(g/3)+1;return i+=4*e,i-h},weekday:function(a,c,d){var e,f=b("day",a,c,d),g=f%7;if(0===g)f=5*b("week",a,c,d);else{var h=0,i=a[d?"getUTCDay":"getDay"](),j=c[d?"getUTCDay":"getDay"]();e=parseInt(f/7,10);var k=new Date(+a);k.setDate(k[d?"getUTCDate":"getDate"]()+7*e);var l=k[d?"getUTCDay":"getDay"]();f>0?6===i||6===j?h=-1:0===i?h=0:(0===j||l+g>5)&&(h=-2):0>f&&(6===i?h=0:0===i||0===j?h=1:(6===j||0>l+g)&&(h=2)),f+=h,f-=2*e}return f},year:function(a,b){return b.getFullYear()-a.getFullYear()},month:function(a,b,c){var d=a[c?"getUTCMonth":"getMonth"](),e=b[c?"getUTCMonth":"getMonth"]();return e-d+12*(b.getFullYear()-a.getFullYear())},week:function(a,c,e){return d(b("day",a,c,e)/7)},day:function(a,b){return 1.1574074074074074e-8*(b.getTime()-a.getTime())},hour:function(a,b){return 2.7777777777777776e-7*(b.getTime()-a.getTime())},minute:function(a,b){return 16666666666666667e-21*(b.getTime()-a.getTime())},second:function(a,b){return.001*(b.getTime()-a.getTime())},millisecond:function(a,b){return b.getTime()-a.getTime()}};return{addTransform:a,differenceTransform:b}}(),m=l.addTransform,n=l.differenceTransform,o=Math.floor,p=Math.round,q=Math.min,r=Math.pow,s=Math.ceil,t=Math.abs,u=["January","February","March","April","May","June","July","August","September","October","November","December"],v=["Jan.","Feb.","Mar.","Apr.","May.","Jun.","Jul.","Aug.","Sep.","Oct.","Nov.","Dec."],w=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],x=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],y=["Before Christ","Anno Domini"],z=["BC","AD"],A={getDaysInMonth:function(a){var b=a.getMonth(),c=[31,28,31,30,31,30,31,31,30,31,30,31];return 1===b&&A.isLeapYear(a)?29:c[b]},isLeapYear:function(a,b){var c=a[b?"getUTCFullYear":"getFullYear"]();return 0===c%400||0===c%4&&0!==c%100},isWeekend:function(a,b){var c=(a||new Date)[b?"getUTCDay":"getDay"]();return 0===c||6===c},getTimezoneName:i,compare:function(a,b,c){return a=new Date(+a),b=new Date(+(b||new Date)),"date"===c?(a.setHours(0,0,0,0),b.setHours(0,0,0,0)):"time"===c&&(a.setFullYear(0,0,0),b.setFullYear(0,0,0)),a>b?1:b>a?-1:0},add:function(a,b,c){var d=m(b,a,c||0);c=d[0];var e=d[1],f=new Date(+a),g=d[2];return e&&f["set"+e](f["get"+e]()+c),g&&f.getDate()E?z:y)[0>f?0:1];else if("y"===D)B=f,E>1&&(2===E?B=e(""+B,2,!0):C=!0);else if("Q"===D.toUpperCase())B=s((j+1)/3),C=!0;else if("M"===D)3>E?(B=j+1,C=!0):B=(3===E?v:u)[j];else if("w"===D)B=h(a,0,c),C=!0;else if("D"===D)B=g(a,c),C=!0;else if("E"===D)3>E?(B=k+1,C=!0):B=(-3===E?x:w)[k];else if("a"===D)B=12>m?"AM":"PM";else if("h"===D)B=m%12||12,C=!0;else if("K"===D)B=m%12,C=!0;else if("k"===D)B=m||24,C=!0;else if("S"===D)B=p(A*r(10,E-3)),C=!0;else if("z"===D||"v"===D||"Z"===D){if(B=i(a),"z"!==D&&"v"!==D||B||(E=4),!B||"Z"===D){var F=a.getTimezoneOffset(),G=[F>=0?"-":"+",d(o(t(F)/60),2,"0"),d(t(F)%60,2,"0")];4===E&&(G.splice(0,0,"GMT"),G.splice(3,0,":")),B=G.join("")}}else B=b;else B=""+n,C=!0;else B=""+m,C=!0;return C&&(B=d(B,E,"0")),B})}},B={},C=["year","month","day","hour","minute","second"],D=0,E=C.length;E>D;D++)k(C[D]);var F={parseDate:function(a,b){if(!b)throw new Error("format required when calling dateExtender.parse");var d=[],e=j(b,d),g=new RegExp("^"+e+"$","i"),h=g.exec(a);if(!h)return null;var i=[1970,0,1,0,0,0,0],k="",l=f(h,function(a,b){if(b){var e=d[b-1],f=e.length,g=e.charAt(0);if("y"===g)if(100>a){a=parseInt(a,10);var h=""+(new Date).getFullYear(),j=100*h.substring(0,2),l=q(h.substring(2,4)+20,99);i[0]=l>a?j+a:j-100+a}else i[0]=a;else if("M"===g){if(f>2){var m,n,o=u;3===f&&(o=v),a=a.replace(".","").toLowerCase();var p=!1;for(m=0,n=o.length;n>m&&!p;m++){var r=o[m].replace(".","").toLocaleLowerCase();r===a&&(a=m,p=!0)}if(!p)return!1}else a--;i[1]=a}else if("E"===g||"e"===g){var s=w;3===f&&(s=x),a=a.toLowerCase(),s=c.map(s,function(a){return a.toLowerCase()});var t=c.indexOf(s,a);if(-1===t){if(a=parseInt(a,10),isNaN(a)||a>s.length)return!1}else a=t}else if("D"===g||"d"===g)"D"===g&&(i[1]=0),i[2]=a;else if("a"===g){var y="am",z="pm",A=/\./g;a=a.replace(A,"").toLowerCase(),k=a===z?"p":a===y?"a":""}else"k"===g||"h"===g||"H"===g||"K"===g?("k"===g&&24===+a&&(a=0),i[3]=a):"m"===g?i[4]=a:"s"===g?i[5]=a:"S"===g&&(i[6]=a)}return!0});if(l){var m=+i[3];"p"===k&&12>m?i[3]=m+12:"a"===k&&12===m&&(i[3]=0);var n=new Date(i[0],i[1],i[2],i[3],i[4],i[5],i[6]),o=-1!==c.indexOf(d,"d"),p=-1!==c.indexOf(d,"M"),r=i[1],s=i[2],t=n.getMonth(),y=n.getDate();return p&&t>r||o&&y>s?null:n}return null}},G=a.define(b.isDate,A).define(b.isString,F).define(b.isNumber,B);for(D in A)A.hasOwnProperty(D)&&(G[D]=A[D]);for(D in F)F.hasOwnProperty(D)&&(G[D]=F[D]);for(D in B)B.hasOwnProperty(D)&&(G[D]=B[D]);return G}"undefined"!=typeof c?"undefined"!=typeof b&&b.exports&&(b.exports=d(a("extended"),a("is-extended"),a("array-extended"))):"function"==typeof define&&define.amd?define(["extended","is-extended","array-extended"],function(a,b,c){return d(a,b,c)}):this.dateExtended=d(this.extended,this.isExtended,this.arrayExtended)}.call(this)},{"array-extended":49,extended:53,"is-extended":70}],51:[function(a,b,c){!function(){function a(){function a(a,b){return b=b||0,x.call(a,b)}function b(a){return"[object Array]"===Object.prototype.toString.call(a)}function c(a){var b;return null!==a&&a!==b&&"object"==typeof a}function d(a){var b=c(a);return b&&a.constructor===Object}function e(a,b){if(a&&a.length)for(var c=0,d=a.length;d>c;c++)if(a[c]===b)return c;return-1}function f(a,b,c){var d,f;for(d in b)b.hasOwnProperty(d)&&-1===e(c,d)&&(f=b[d],d in a&&a[d]===f||(a[d]=f));return a}function g(a){var c=this.__meta,d=c.supers,e=d.length,f=c.superMeta,g=f.pos;if(e>g){a=a?B(a)||b(a)?a:[a]:[];var h,i=f.name,j=f.f;do if(h=d[g][i],"function"==typeof h&&(h=h._f||h)!==j)return f.pos=1+g,h.apply(this,a);while(e>++g)}return null}function h(){var a=this.__meta,b=a.supers,c=b.length,d=a.superMeta,e=d.pos;if(c>e){var f,g=d.name,h=d.f;do if(f=b[e][g],"function"==typeof f&&(f=f._f||f)!==h)return d.pos=1+e,f.bind(this);while(c>++e)}return null}function i(a){var b=this.__getters__;return b.hasOwnProperty(a)?b[a].apply(this):this[a]}function j(b,c){var e=this.__setters__;if(!d(b))return e.hasOwnProperty(b)?e[b].apply(this,a(arguments,1)):this[b]=c;for(var f in b){var g=b[f];e.hasOwnProperty(f)?e[b].call(this,g):this[f]=g}}function k(){var a=this.__meta||{},b=a.supers,c=b.length,d=a.superMeta,e=d.pos;if(c>e){var f,g=d.name,h=d.f;do if(f=b[e][g],"function"==typeof f&&(f=f._f||f)!==h)return d.pos=1+e,f.apply(this,arguments);while(c>++e)}return null}function l(a,b){if(a.toString().match(A)){var c=function(){var c,d=this.__meta||{},e=d.superMeta;switch(d.superMeta={f:a,pos:0,name:b},arguments.length){case 0:c=a.call(this);break;case 1:c=a.call(this,arguments[0]);break;case 2:c=a.call(this,arguments[0],arguments[1]);break;case 3:c=a.call(this,arguments[0],arguments[1],arguments[2]);break;default:c=a.apply(this,arguments)}return d.superMeta=e,c};return c._f=a,c}return a._f=a,a}function m(a,b){var c=b.setters||{},d=a.__setters__,e=a.__getters__;for(var f in c)d.hasOwnProperty(f)||(d[f]=c[f]);c=b.getters||{};for(f in c)e.hasOwnProperty(f)||(e[f]=c[f]);for(var g in b)if("getters"!==g&&"setters"!==g){var h=b[g];"function"==typeof h?a.hasOwnProperty(g)||(a[g]=l(k,g)):a[g]=h}}function n(){for(var b=a(arguments),c=b.length,d=this.prototype,e=d.__meta,f=this.__meta,g=d.__meta.bases,h=g.slice(),i=f.supers||[],j=e.supers||[],k=0;c>k;k++){var l=b[k],n=l.prototype,p=n.__meta,q=l.__meta;!p&&(p=n.__meta={proto:n||{}}),!q&&(q=l.__meta={proto:l.__proto__||{}}),m(d,p.proto||{}),m(this,q.proto||{}),o(l.prototype,j,g),o(l,i,h)}return this}function o(a,b,c){var d=a.__meta;!d&&(d=a.__meta={});var f=a.__meta.unique;if(!f&&(d.unique="declare"+ ++y),-1===e(c,f)){c.push(f);for(var g=a.__meta.supers||[],h=g.length-1||0;h>=0;)o(g[h--],b,c);b.unshift(a)}}function p(a,b){var c=b.setters,d=a.__setters__,e=a.__getters__;if(c)for(var f in c)d[f]=c[f];if(c=b.getters||{})for(f in c)e[f]=c[f];for(f in b)if("getters"!=f&&"setters"!=f){var g=b[f];if("function"==typeof g){var h=g.__meta||{};a[f]=h.isConstructor?g:l(g,f)}else a[f]=g}}function q(a,b){return a&&b?a[b]=this:a.exports=a=this,this}function r(a){return u(this,a)}function s(a){z.prototype=a.prototype;var b=new z;return z.prototype=null,b}function t(a,c,e){var i={},j=[],m="declare"+ ++y,q=[],r=[],t=[],u=[],v={supers:t,unique:m,bases:q,superMeta:{f:null,pos:0,name:null}},x={supers:u,unique:m,bases:r,isConstructor:!0,superMeta:{f:null,pos:0,name:null}};if(d(c)&&!e&&(e=c,c=w),"function"==typeof c||b(c)?(j=b(c)?c:[c],c=j.shift(),a.__meta=x,i=s(c),i.__meta=v,i.__getters__=f({},i.__getters__||{}),i.__setters__=f({},i.__setters__||{}),a.__getters__=f({},a.__getters__||{}),a.__setters__=f({},a.__setters__||{}),o(c.prototype,t,q),o(c,u,r)):(a.__meta=x,i.__meta=v,i.__getters__=i.__getters__||{},i.__setters__=i.__setters__||{},a.__getters__=a.__getters__||{},a.__setters__=a.__setters__||{}),a.prototype=i,e){var z=v.proto=e.instance||{},A=x.proto=e.static||{};A.init=A.init||k,p(i,z),p(a,A),i.constructor=z.hasOwnProperty("constructor")?l(z.constructor,"constructor"):z.constructor=l(k,"constructor")}else v.proto={},x.proto={},a.init=l(k,"init"),i.constructor=l(k,"constructor");j.length&&n.apply(a,j),c&&f(a,f(f({},c),a)),i._super=a._super=g,i._getSuper=a._getSuper=h,i._static=a}function u(a,b){function c(){switch(arguments.length){case 0:this.constructor.call(this);break;case 1:this.constructor.call(this,arguments[0]);break;case 2:this.constructor.call(this,arguments[0],arguments[1]);break;case 3:this.constructor.call(this,arguments[0],arguments[1],arguments[2]);break;default:this.constructor.apply(this,arguments)}}return t(c,a,b),c.init()||c}function v(a,b){function c(){return d||(this.constructor.apply(this,arguments),d=this),d}var d;return t(c,a,b),c.init()||c}var w,x=Array.prototype.slice,y=0,z=new Function,A=/(super)/g,B=function(a){return"[object Arguments]"===Object.prototype.toString.call(a)};return B(arguments)||(B=function(a){return!(!a||!a.hasOwnProperty("callee"))}),w=u({instance:{get:i,set:j},"static":{get:i,set:j,mixin:n,extend:r,as:q}}),u.singleton=v,u}"undefined"!=typeof c?"undefined"!=typeof b&&b.exports&&(b.exports=a()):"function"==typeof define&&define.amd?define(a):this.declare=a()}()},{}],52:[function(a,b){b.exports=a("./declare.js")},{"./declare.js":51}],53:[function(a,b,c){!function(){"use strict";function d(a){function b(){var b=a.define(); +return b.expose({register:function(a,c){c||(c=a,a=null);var d=typeof c;if(a)b[a]=c;else if(c&&"function"===d)b.extend(c);else{if("object"!==d)throw new TypeError("extended.register must be called with an extender function");b.expose(c)}return b},define:function(){return a.define.apply(a,arguments)}}),b}function c(){return b()}return function(){function a(a,b){var c,d;for(c in b)b.hasOwnProperty(c)&&(d=b[c],c in a&&a[c]===d||(a[c]=d));return a}return function(b){b||(b={});for(var c=1,d=arguments.length;d>c;c++)a(b,arguments[c]);return b}}(),c.define=function(){return a.define.apply(a,arguments)},c}"undefined"!=typeof c?"undefined"!=typeof b&&b.exports&&(b.exports=d(a("extender"))):"function"==typeof define&&define.amd?define(["extender"],function(a){return d(a)}):this.extended=d(this.extender)}.call(this)},{extender:55}],54:[function(a,b,c){!function(){function d(a){function b(a,b){if(a&&a.length)for(var c=0,d=a.length;d>c;c++)if(a[c]===b)return c;return-1}function c(a){return"[object Array]"===Object.prototype.toString.call(a)}function d(b){function c(a,b,c){if("function"!=typeof c)throw new TypeError("when extending type you must provide a function");var d;d="constructor"===b?function(){this._super(arguments),c.apply(this,arguments)}:function(){var a=f.call(arguments);a.unshift(this._value);var b=c.apply(this,a);return b!==e?this.__extender__(b):this},a[b]=d}function d(a,b,c){if("function"!=typeof c)throw new TypeError("when extending type you must provide a function");var d;d="constructor"===b?function(){this._super(arguments),c.apply(this,arguments)}:function(){var a=f.call(arguments);return a.unshift(this._value),c.apply(this,a)},a[b]=d}function h(a,b,e){for(var f in b)b.hasOwnProperty(f)&&("getters"!==f&&"setters"!==f?"noWrap"===f?h(a,b[f],!0):e?d(a,f,b[f]):c(a,f,b[f]):a[f]=b[f])}function i(a){var b,c,d=a;if(!(a instanceof m)){var e=m;for(b=0,c=n.length;c>b;b++){var f=n[b];f[0](a)&&(e=e.extend({instance:f[1]}))}d=new e(a),d.__extender__=i}return d}function j(){return!0}function k(a,b){if(arguments.length){"object"==typeof a&&(b=a,a=j),b=b||{};var d={};h(d,b),d.hasOwnProperty("constructor")||(b.hasOwnProperty("constructor")?c(d,"constructor",b.constructor):d.constructor=function(){this._super(arguments)}),n.push([a,d])}return i}function l(a){return a&&a.hasOwnProperty("__defined__")&&(i.__defined__=n=n.concat(a.__defined__)),g(i,a,["define","extend","expose","__defined__"]),i}b=b||[];var m=a({instance:{constructor:function(a){this._value=a},value:function(){return this._value},eq:function(a){return this.__extender__(this._value===a)},neq:function(a){return this.__extender__(this._value!==a)},print:function(){return console.log(this._value),this}}}),n=[];return i.define=k,i.extend=l,i.expose=function(){for(var a,b=0,c=arguments.length;c>b;b++)a=arguments[b],"object"==typeof a&&g(i,a,["define","extend","expose","__defined__"]);return i},i.__defined__=n,i}var e,f=Array.prototype.slice,g=function(){function a(a,c,d){var e,f;for(e in c)c.hasOwnProperty(e)&&-1===b(d,e)&&(f=c[e],e in a&&a[e]===f||(a[e]=f));return a}return function(b){b||(b={});var d=arguments.length,e=arguments[arguments.length-1];c(e)?d--:e=[];for(var f=1;d>f;f++)a(b,arguments[f],e);return b}}();return{define:function(){return d().define.apply(d,arguments)},extend:function(a){return d().define().extend(a)}}}"undefined"!=typeof c?"undefined"!=typeof b&&b.exports&&(b.exports=d(a("declare.js"))):"function"==typeof define&&define.amd?define(["declare"],function(a){return d(a)}):this.extender=d(this.declare)}.call(this)},{"declare.js":52}],55:[function(a,b){b.exports=a("./extender.js")},{"./extender.js":54}],56:[function(a,b,c){!function(){"use strict";function d(a,b,c){function d(a,b,c){var d;switch((b||[]).length){case 0:d=a.call(c);break;case 1:d=a.call(c,b[0]);break;case 2:d=a.call(c,b[0],b[1]);break;case 3:d=a.call(c,b[0],b[1],b[2]);break;default:d=a.apply(c,b)}return d}function e(a,b,c){if(c=p(arguments,2),n(b)&&!(b in a))throw new Error(b+" property not defined in scope");if(!n(b)&&!o(b))throw new Error(b+" is not a function");return n(b)?function(){var d=a[b];if(o(d)){var e=c.concat(p(arguments));return d.apply(a,e)}return d}:c.length?function(){return c.concat(p(arguments)),d(b,arguments,a)}:function(){return d(b,arguments,a)}}function f(a,b){if(b=p(arguments,1),!n(a)&&!o(a))throw new Error(a+" must be the name of a property or function to execute");return n(a)?function(){var c=p(arguments),d=c.shift(),e=d[a];return o(e)?(c=b.concat(c),e.apply(d,c)):e}:function(){var c=p(arguments),d=c.shift();return c=b.concat(c),a.apply(d,c)}}function g(a,b,c){if(c=p(arguments,2),n(b)&&!(b in a))throw new Error(b+" property not defined in scope");if(!n(b)&&!o(b))throw new Error(b+" is not a function");return n(b)?function(){var d=a[b];return o(d)?d.apply(a,c):d}:function(){return b.apply(a,c)}}function h(a){var b=p(arguments,1);if(!m(a)&&!o(a))throw new TypeError("scope must be an object");if(1===b.length&&l(b[0])&&(b=b[0]),!b.length){b=[];for(var c in a)a.hasOwnProperty(c)&&o(a[c])&&b.push(c)}for(var d=0,f=b.length;f>d;d++)a[b[d]]=e(a,a[b[d]]);return a}function i(a,b){if(b=p(arguments,1),!n(a)&&!o(a))throw new Error(a+" must be the name of a property or function to execute");return n(a)?function(){var c=this[a];if(o(c)){var d=b.concat(p(arguments));return c.apply(this,d)}return c}:function(){var c=b.concat(p(arguments));return a.apply(this,c)}}function j(a,b){return function(){var c=p(arguments);return b?a.apply(this,arguments):function(){return a.apply(this,c.concat(p(arguments)))}}}function k(a,b,c){var d;if(d=c?e(c,b):b,a)for(var f=a-1,g=f;g>=0;g--)d=j(d,g===f);return d}var l=b.isArray,m=b.isObject,n=b.isString,o=b.isFunction,p=c.argsToArray;return a.define(m,{bind:e,bindAll:h,bindIgnore:g,curry:function(a,b,c){return k(b,c,a)}}).define(o,{bind:function(a,b){return e.apply(this,[b,a].concat(p(arguments,2)))},bindIgnore:function(a,b){return g.apply(this,[b,a].concat(p(arguments,2)))},partial:i,applyFirst:f,curry:function(a,b,c){return k(b,a,c)},noWrap:{f:function(){return this.value()}}}).define(n,{bind:function(a,b){return e(b,a)},bindIgnore:function(a,b){return g(b,a)},partial:i,applyFirst:f,curry:function(a,b,c){return k(b,a,c)}}).expose({bind:e,bindAll:h,bindIgnore:g,partial:i,applyFirst:f,curry:k})}"undefined"!=typeof c?"undefined"!=typeof b&&b.exports&&(b.exports=d(a("extended"),a("is-extended"),a("arguments-extended"))):"function"==typeof define&&define.amd?define(["extended","is-extended","arguments-extended"],function(a,b,c){return d(a,b,c)}):this.functionExtended=d(this.extended,this.isExtended,this.argumentsExtended)}.call(this)},{"arguments-extended":57,extended:58,"is-extended":63}],57:[function(a,b,c){!function(){"use strict";function d(a,b){function c(a,b){var c=-1,d=0,e=a.length,f=[];for(b=b||0,c+=b;++cc;c++)a(b,arguments[c]);return b}}(),c.define=function(){return a.define.apply(a,arguments)},c}"undefined"!=typeof c?"undefined"!=typeof b&&b.exports&&(b.exports=d(a("extender"))):"function"==typeof define&&define.amd?define(["extender"],function(a){return d(a)}):this.extended=d(this.extender)}.call(this)},{extender:60}],59:[function(a,b,c){!function(){function d(a){function b(a,b){if(a&&a.length)for(var c=0,d=a.length;d>c;c++)if(a[c]===b)return c;return-1}function c(a){return"[object Array]"===Object.prototype.toString.call(a)}function d(b){function c(a,b,c){if("function"!=typeof c)throw new TypeError("when extending type you must provide a function");var d;d="constructor"===b?function(){this._super(arguments),c.apply(this,arguments)}:function(){var a=f.call(arguments);a.unshift(this._value);var b=c.apply(this,a);return b!==e?this.__extender__(b):this},a[b]=d}function d(a,b,c){if("function"!=typeof c)throw new TypeError("when extending type you must provide a function");var d;d="constructor"===b?function(){this._super(arguments),c.apply(this,arguments)}:function(){var a=f.call(arguments);return a.unshift(this._value),c.apply(this,a)},a[b]=d}function h(a,b,e){for(var f in b)b.hasOwnProperty(f)&&("getters"!==f&&"setters"!==f?"noWrap"===f?h(a,b[f],!0):e?d(a,f,b[f]):c(a,f,b[f]):a[f]=b[f])}function i(a){var b,c,d=a;if(!(a instanceof m)){var e=m;for(b=0,c=n.length;c>b;b++){var f=n[b];f[0](a)&&(e=e.extend({instance:f[1]}))}d=new e(a),d.__extender__=i}return d}function j(){return!0}function k(a,b){if(arguments.length){"object"==typeof a&&(b=a,a=j),b=b||{};var d={};h(d,b),d.hasOwnProperty("constructor")||(b.hasOwnProperty("constructor")?c(d,"constructor",b.constructor):d.constructor=function(){this._super(arguments)}),n.push([a,d])}return i}function l(a){return a&&a.hasOwnProperty("__defined__")&&(i.__defined__=n=n.concat(a.__defined__)),g(i,a,["define","extend","expose","__defined__"]),i}b=b||[];var m=a({instance:{constructor:function(a){this._value=a},value:function(){return this._value},eq:function(a){return this.__extender__(this._value===a)},neq:function(a){return this.__extender__(this._value!==a)},print:function(){return console.log(this._value),this}}}),n=[];return i.define=k,i.extend=l,i.expose=function(){for(var a,b=0,c=arguments.length;c>b;b++)a=arguments[b],"object"==typeof a&&g(i,a,["define","extend","expose","__defined__"]);return i},i.__defined__=n,i}var e,f=Array.prototype.slice,g=function(){function a(a,c,d){var e,f;for(e in c)c.hasOwnProperty(e)&&-1===b(d,e)&&(f=c[e],e in a&&a[e]===f||(a[e]=f));return a}return function(b){b||(b={});var d=arguments.length,e=arguments[arguments.length-1];c(e)?d--:e=[];for(var f=1;d>f;f++)a(b,arguments[f],e);return b}}();return{define:function(){return d().define.apply(d,arguments)},extend:function(a){return d().define().extend(a)}}}"undefined"!=typeof c?"undefined"!=typeof b&&b.exports&&(b.exports=d(a("declare.js"))):"function"==typeof define&&define.amd?define(["declare"],function(a){return d(a)}):this.extender=d(this.declare)}.call(this)},{"declare.js":62}],60:[function(a,b){b.exports=a("./extender.js")},{"./extender.js":59}],61:[function(a,b,c){!function(){function a(){function a(a,b){return b=b||0,x.call(a,b)}function b(a){return"[object Array]"===Object.prototype.toString.call(a)}function c(a){var b;return null!==a&&a!==b&&"object"==typeof a}function d(a){var b=c(a);return b&&a.constructor===Object}function e(a,b){if(a&&a.length)for(var c=0,d=a.length;d>c;c++)if(a[c]===b)return c;return-1}function f(a,b,c){var d,f;for(d in b)b.hasOwnProperty(d)&&-1===e(c,d)&&(f=b[d],d in a&&a[d]===f||(a[d]=f));return a}function g(a){var c=this.__meta,d=c.supers,e=d.length,f=c.superMeta,g=f.pos;if(e>g){a=a?B(a)||b(a)?a:[a]:[];var h,i=f.name,j=f.f;do if(h=d[g][i],"function"==typeof h&&(h=h._f||h)!==j)return f.pos=1+g,h.apply(this,a);while(e>++g)}return null}function h(){var a=this.__meta,b=a.supers,c=b.length,d=a.superMeta,e=d.pos;if(c>e){var f,g=d.name,h=d.f;do if(f=b[e][g],"function"==typeof f&&(f=f._f||f)!==h)return d.pos=1+e,f.bind(this);while(c>++e)}return null}function i(a){var b=this.__getters__;return b.hasOwnProperty(a)?b[a].apply(this):this[a]}function j(b,c){var e=this.__setters__;if(!d(b))return e.hasOwnProperty(b)?e[b].apply(this,a(arguments,1)):this[b]=c;for(var f in b){var g=b[f];e.hasOwnProperty(f)?e[b].call(this,g):this[f]=g}}function k(){var a=this.__meta||{},b=a.supers,c=b.length,d=a.superMeta,e=d.pos;if(c>e){var f,g=d.name,h=d.f;do if(f=b[e][g],"function"==typeof f&&(f=f._f||f)!==h)return d.pos=1+e,f.apply(this,arguments);while(c>++e)}return null}function l(a,b){if(a.toString().match(A)){var c=function(){var c,d=this.__meta||{},e=d.superMeta;switch(d.superMeta={f:a,pos:0,name:b},arguments.length){case 0:c=a.call(this);break;case 1:c=a.call(this,arguments[0]);break;case 2:c=a.call(this,arguments[0],arguments[1]);break;case 3:c=a.call(this,arguments[0],arguments[1],arguments[2]);break;default:c=a.apply(this,arguments)}return d.superMeta=e,c};return c._f=a,c}return a._f=a,a}function m(a,b){var c=b.setters||{},d=a.__setters__,e=a.__getters__;for(var f in c)d.hasOwnProperty(f)||(d[f]=c[f]);c=b.getters||{};for(f in c)e.hasOwnProperty(f)||(e[f]=c[f]);for(var g in b)if("getters"!==g&&"setters"!==g){var h=b[g];"function"==typeof h?a.hasOwnProperty(g)||(a[g]=l(k,g)):a[g]=h}}function n(){for(var b=a(arguments),c=b.length,d=this.prototype,e=d.__meta,f=this.__meta,g=d.__meta.bases,h=g.slice(),i=f.supers||[],j=e.supers||[],k=0;c>k;k++){var l=b[k],n=l.prototype,p=n.__meta,q=l.__meta;!p&&(p=n.__meta={proto:n||{}}),!q&&(q=l.__meta={proto:l.__proto__||{}}),m(d,p.proto||{}),m(this,q.proto||{}),o(l.prototype,j,g),o(l,i,h)}return this}function o(a,b,c){var d=a.__meta;!d&&(d=a.__meta={});var f=a.__meta.unique;if(!f&&(d.unique="declare"+ ++y),-1===e(c,f)){c.push(f);for(var g=a.__meta.supers||[],h=g.length-1||0;h>=0;)o(g[h--],b,c);b.unshift(a)}}function p(a,b){var c=b.setters,d=a.__setters__,e=a.__getters__;if(c)for(var f in c)d[f]=c[f];if(c=b.getters||{})for(f in c)e[f]=c[f];for(f in b)if("getters"!=f&&"setters"!=f){var g=b[f];if("function"==typeof g){var h=g.__meta||{};a[f]=h.isConstructor?g:l(g,f)}else a[f]=g}}function q(a,b){return a&&b?a[b]=this:a.exports=a=this,this}function r(a){return u(this,a)}function s(a){z.prototype=a.prototype;var b=new z;return z.prototype=null,b}function t(a,c,e){var i={},j=[],m="declare"+ ++y,q=[],r=[],t=[],u=[],v={supers:t,unique:m,bases:q,superMeta:{f:null,pos:0,name:null}},x={supers:u,unique:m,bases:r,isConstructor:!0,superMeta:{f:null,pos:0,name:null}};if(d(c)&&!e&&(e=c,c=w),"function"==typeof c||b(c)?(j=b(c)?c:[c],c=j.shift(),a.__meta=x,i=s(c),i.__meta=v,i.__getters__=f({},i.__getters__||{}),i.__setters__=f({},i.__setters__||{}),a.__getters__=f({},a.__getters__||{}),a.__setters__=f({},a.__setters__||{}),o(c.prototype,t,q),o(c,u,r)):(a.__meta=x,i.__meta=v,i.__getters__=i.__getters__||{},i.__setters__=i.__setters__||{},a.__getters__=a.__getters__||{},a.__setters__=a.__setters__||{}),a.prototype=i,e){var z=v.proto=e.instance||{},A=x.proto=e.static||{};A.init=A.init||k,p(i,z),p(a,A),i.constructor=z.hasOwnProperty("constructor")?l(z.constructor,"constructor"):z.constructor=l(k,"constructor")}else v.proto={},x.proto={},a.init=l(k,"init"),i.constructor=l(k,"constructor");j.length&&n.apply(a,j),c&&f(a,f(f({},c),a)),i._super=a._super=g,i._getSuper=a._getSuper=h,i._static=a}function u(a,b){function c(){this.constructor.apply(this,arguments)}return t(c,a,b),c.init()||c}function v(a,b){function c(){return d||(this.constructor.apply(this,arguments),d=this),d}var d;return t(c,a,b),c.init()||c}var w,x=Array.prototype.slice,y=0,z=new Function,A=/(super)/g,B=function(a){return"[object Arguments]"===Object.prototype.toString.call(a)};return B(arguments)||(B=function(a){return!(!a||!a.hasOwnProperty("callee"))}),w=u({instance:{get:i,set:j},"static":{get:i,set:j,mixin:n,extend:r,as:q}}),u.singleton=v,u}"undefined"!=typeof c?"undefined"!=typeof b&&b.exports&&(b.exports=a()):"function"==typeof define&&define.amd?define(a):this.declare=a()}()},{}],62:[function(a,b){b.exports=a("./declare.js")},{"./declare.js":61}],63:[function(a,b,c){var d=a("__browserify_Buffer").Buffer;!function(){"use strict";function e(a){function b(a,b){return b=b||0,S.call(a,b)}function c(a){var b=[];for(var c in a)T.call(a,c)&&b.push(c);return b}function e(a,b){if(a===b)return!0;if("undefined"!=typeof d&&d.isBuffer(a)&&d.isBuffer(b)){if(a.length!==b.length)return!1;for(var c=0;c=0;f--)if(g[f]!==h[f])return!1;for(f=g.length-1;f>=0;f--)if(d=g[f],!e(a[d],b[d]))return!1}catch(i){return!1}return!0}function g(a){return null!==a&&"object"==typeof a}function h(a){var b=g(a);return b&&a.constructor===Object&&!a.nodeType&&!a.setInterval}function i(a){return W(a)?0===a.length:g(a)?0===c(a).length:r(a)||X(a)?0===a.length:!0}function j(a){return a===!0||a===!1||"[object Boolean]"===U.call(a)}function k(a){return"undefined"==typeof a}function l(a){return!k(a)}function m(a){return k(a)||n(a)}function n(a){return null===a}function o(a,b){return V(b)?a instanceof b:!1}function p(a){return"[object RegExp]"===U.call(a)}function q(a){return"[object Date]"===U.call(a)}function r(a){return"[object String]"===U.call(a)}function s(a){return"[object Number]"===U.call(a)}function t(a){return a===!0}function u(a){return a===!1}function v(a){return!n(a)}function w(a,b){return a==b}function x(a,b){return a!=b}function y(a,b){return a===b}function z(a,b){return a!==b}function A(a,b){if(X(b)&&Array.prototype.indexOf||r(b))return b.indexOf(a)>-1;if(X(b))for(var c=0,d=b.length;d>c;c++)if(w(a,b[c]))return!0;return!1}function B(a,b){return!A(a,b)}function C(a,b){return b>a}function D(a,b){return b>=a}function E(a,b){return a>b}function F(a,b){return a>=b}function G(a,b){return r(b)?null!==(""+a).match(b):p(b)?b.test(a):!1}function H(a,b){return!G(a,b)}function I(a,b){return A(b,a)}function J(a,b){return!A(b,a)}function K(a,b,c){return X(a)&&a.length>c?w(a[c],b):!1}function L(a,b,c){return X(a)?!w(a[c],b):!1}function M(a,b){return T.call(a,b)}function N(a,b){return!M(a,b)}function O(a,b){return M(a,"length")?a.length===b:!1}function P(a,b){return M(a,"length")?a.length!==b:!1}function Q(a){Z[a]=function(){this._testers.push(Y[a])}}function R(a){$[a]=function(){var c,d=b(arguments,1),e=Y[a],f=!0;if(d.length<=e.length-1)throw new TypeError("A handler must be defined when calling using switch");if(c=d.pop(),j(c)&&(f=c,c=d.pop()),!V(c))throw new TypeError("handler must be defined");this._cases.push(function(a){return e.apply(Y,a.concat(d))?[f,c.apply(this,a)]:[!1]})}}var S=Array.prototype.slice,T=Object.prototype.hasOwnProperty,U=Object.prototype.toString,V=function(a){return"[object Function]"===U.call(a)};"undefined"==typeof window||V(window.alert)||function(a){V=function(b){return"[object Function]"===U.call(b)||b===a}}(window.alert);var W=function(a){return"[object Arguments]"===U.call(a)};W(arguments)||(W=function(a){return!(!a||!T.call(a,"callee"))});var X=Array.isArray||function(a){return"[object Array]"===U.call(a)},Y={isFunction:V,isObject:g,isEmpty:i,isHash:h,isNumber:s,isString:r,isDate:q,isArray:X,isBoolean:j,isUndefined:k,isDefined:l,isUndefinedOrNull:m,isNull:n,isArguments:W,instanceOf:o,isRegExp:p,deepEqual:e,isTrue:t,isFalse:u,isNotNull:v,isEq:w,isNeq:x,isSeq:y,isSneq:z,isIn:A,isNotIn:B,isLt:C,isLte:D,isGt:E,isGte:F,isLike:G,isNotLike:H,contains:I,notContains:J,has:M,notHas:N,isLength:O,isNotLength:P,containsAt:K,notContainsAt:L},Z={constructor:function(){this._testers=[]},noWrap:{tester:function(){var a=this._testers;return function(b){for(var c=!1,d=0,e=a.length;e>d&&!c;d++)c=a[d](b);return c}}}},$={constructor:function(){this._cases=[],this.__default=null},def:function(a,b){this.__default=b},noWrap:{switcher:function(){var a=this._cases,c=this.__default;return function(){for(var d,e=!1,f=b(arguments),g=0,h=a.length;h>g&&!e;g++)if(d=a[g](f),d.length>1&&(d[1]||d[0]))return d[1];return!e&&c?c.apply(this,f):void 0}}}};for(var _ in Y)T.call(Y,_)&&(R(_),Q(_));var ab=a.define(Y).expose(Y);return ab.tester=a.define(Z),ab.switcher=a.define($),ab}"undefined"!=typeof c?"undefined"!=typeof b&&b.exports&&(b.exports=e(a("extended"))):"function"==typeof define&&define.amd?define(["extended"],function(a){return e(a)}):this.isExtended=e(this.extended)}.call(this)},{__browserify_Buffer:67,extended:58}],64:[function(a,b,c){function d(a,b){if(a.indexOf)return a.indexOf(b);for(var c=0;ce;e++)d[e].apply(this,c);return!0}return!1},f.prototype.addListener=function(a,b){if("function"!=typeof b)throw new Error("addListener only takes instances of Function");if(this._events||(this._events={}),this.emit("newListener",a,b),this._events[a])if(g(this._events[a])){if(!this._events[a].warned){var c;c=void 0!==this._events.maxListeners?this._events.maxListeners:h,c&&c>0&&this._events[a].length>c&&(this._events[a].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[a].length),console.trace())}this._events[a].push(b)}else this._events[a]=[this._events[a],b];else this._events[a]=b;return this},f.prototype.on=f.prototype.addListener,f.prototype.once=function(a,b){var c=this;return c.on(a,function d(){c.removeListener(a,d),b.apply(this,arguments)}),this},f.prototype.removeListener=function(a,b){if("function"!=typeof b)throw new Error("removeListener only takes instances of Function");if(!this._events||!this._events[a])return this;var c=this._events[a];if(g(c)){var e=d(c,b);if(0>e)return this;c.splice(e,1),0==c.length&&delete this._events[a]}else this._events[a]===b&&delete this._events[a];return this},f.prototype.removeAllListeners=function(a){return 0===arguments.length?(this._events={},this):(a&&this._events&&this._events[a]&&(this._events[a]=null),this)},f.prototype.listeners=function(a){return this._events||(this._events={}),this._events[a]||(this._events[a]=[]),g(this._events[a])||(this._events[a]=[this._events[a]]),this._events[a]},f.listenerCount=function(a,b){var c;return c=a._events&&a._events[b]?"function"==typeof a._events[b]?1:a._events[b].length:0}},{__browserify_process:68}],65:[function(){},{}],66:[function(a,b,c){function d(a,b){for(var c=[],d=0;d=0;d--){var e=a[d];"."==e?a.splice(d,1):".."===e?(a.splice(d,1),c++):c&&(a.splice(d,1),c--)}if(b)for(;c--;c)a.unshift("..");return a}var f=a("__browserify_process"),g=/^(.+\/(?!$)|\/)?((?:.+?)?(\.[^.]*)?)$/;c.resolve=function(){for(var a="",b=!1,c=arguments.length;c>=-1&&!b;c--){var g=c>=0?arguments[c]:f.cwd();"string"==typeof g&&g&&(a=g+"/"+a,b="/"===g.charAt(0))}return a=e(d(a.split("/"),function(a){return!!a}),!b).join("/"),(b?"/":"")+a||"."},c.normalize=function(a){var b="/"===a.charAt(0),c="/"===a.slice(-1);return a=e(d(a.split("/"),function(a){return!!a}),!b).join("/"),a||b||(a="."),a&&c&&(a+="/"),(b?"/":"")+a},c.join=function(){var a=Array.prototype.slice.call(arguments,0);return c.normalize(d(a,function(a){return a&&"string"==typeof a}).join("/"))},c.dirname=function(a){var b=g.exec(a)[1]||"",c=!1;return b?1===b.length||c&&b.length<=3&&":"===b.charAt(1)?b:b.substring(0,b.length-1):"."},c.basename=function(a,b){var c=g.exec(a)[2]||"";return b&&c.substr(-1*b.length)===b&&(c=c.substr(0,c.length-b.length)),c},c.extname=function(a){return g.exec(a)[3]||""},c.relative=function(a,b){function d(a){for(var b=0;b=0&&""===a[c];c--);return b>c?[]:a.slice(b,c-b+1)}a=c.resolve(a).substr(1),b=c.resolve(b).substr(1);for(var e=d(a.split("/")),f=d(b.split("/")),g=Math.min(e.length,f.length),h=g,i=0;g>i;i++)if(e[i]!==f[i]){h=i;break}for(var j=[],i=h;i=0;e--)if(f[e]!=g[e])return!1;for(e=f.length-1;e>=0;e--)if(d=f[e],!h(a[d],b[d]))return!1;return!0}function l(a,b){return a&&b?b instanceof RegExp?b.test(a):a instanceof b?!0:b.call({},a)===!0?!0:!1:!1}function m(a,b,c,d){var e;"string"==typeof c&&(d=c,c=null);try{b()}catch(g){e=g}if(d=(c&&c.name?" ("+c.name+").":".")+(d?" "+d:"."),a&&!e&&f("Missing expected exception"+d),!a&&l(e,c)&&f("Got unwanted exception"+d),a&&e&&c&&!l(e,c)||!a&&e)throw e}var n=a("util"),o=a("buffer").Buffer,p=Array.prototype.slice,q=b.exports=g;q.AssertionError=function(a){this.name="AssertionError",this.message=a.message,this.actual=a.actual,this.expected=a.expected,this.operator=a.operator;var b=a.stackStartFunction||f;Error.captureStackTrace&&Error.captureStackTrace(this,b)},n.inherits(q.AssertionError,Error),q.AssertionError.prototype.toString=function(){return this.message?[this.name+":",this.message].join(" "):[this.name+":",e(JSON.stringify(this.actual,d),128),this.operator,e(JSON.stringify(this.expected,d),128)].join(" ")},q.AssertionError.__proto__=Error.prototype,q.fail=f,q.ok=g,q.equal=function(a,b,c){a!=b&&f(a,b,c,"==",q.equal)},q.notEqual=function(a,b,c){a==b&&f(a,b,c,"!=",q.notEqual)},q.deepEqual=function(a,b,c){h(a,b)||f(a,b,c,"deepEqual",q.deepEqual)},q.notDeepEqual=function(a,b,c){h(a,b)&&f(a,b,c,"notDeepEqual",q.notDeepEqual)},q.strictEqual=function(a,b,c){a!==b&&f(a,b,c,"===",q.strictEqual)},q.notStrictEqual=function(a,b,c){a===b&&f(a,b,c,"!==",q.notStrictEqual)},q.throws=function(){m.apply(this,[!0].concat(p.call(arguments)))},q.doesNotThrow=function(){m.apply(this,[!1].concat(p.call(arguments)))},q.ifError=function(a){if(a)throw a}},{util:2,buffer:3}],2:[function(a,b,c){function d(a){return a instanceof Array||Array.isArray(a)||a&&a!==Object.prototype&&d(a.__proto__)}function e(a){return a instanceof RegExp||"object"==typeof a&&"[object RegExp]"===Object.prototype.toString.call(a)}function f(a){if(a instanceof Date)return!0;if("object"!=typeof a)return!1;var b=Date.prototype&&h(Date.prototype),c=a.__proto__&&h(a.__proto__);return JSON.stringify(c)===JSON.stringify(b)}a("events"),c.isArray=d,c.isDate=function(a){return"[object Date]"===Object.prototype.toString.call(a)},c.isRegExp=function(a){return"[object RegExp]"===Object.prototype.toString.call(a)},c.print=function(){},c.puts=function(){},c.debug=function(){},c.inspect=function(a,b,i,j){function k(a,i){if(a&&"function"==typeof a.inspect&&a!==c&&(!a.constructor||a.constructor.prototype!==a))return a.inspect(i);switch(typeof a){case"undefined":return m("undefined","undefined");case"string":var j="'"+JSON.stringify(a).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return m(j,"string");case"number":return m(""+a,"number");case"boolean":return m(""+a,"boolean")}if(null===a)return m("null","null");var n=g(a),o=b?h(a):n;if("function"==typeof a&&0===o.length){if(e(a))return m(""+a,"regexp");var p=a.name?": "+a.name:"";return m("[Function"+p+"]","special")}if(f(a)&&0===o.length)return m(a.toUTCString(),"date");var q,r,s;if(d(a)?(r="Array",s=["[","]"]):(r="Object",s=["{","}"]),"function"==typeof a){var t=a.name?": "+a.name:"";q=e(a)?" "+a:" [Function"+t+"]"}else q="";if(f(a)&&(q=" "+a.toUTCString()),0===o.length)return s[0]+q+s[1];if(0>i)return e(a)?m(""+a,"regexp"):m("[Object]","special");l.push(a);var u=o.map(function(b){var c,e;if(a.__lookupGetter__&&(a.__lookupGetter__(b)?e=a.__lookupSetter__(b)?m("[Getter/Setter]","special"):m("[Getter]","special"):a.__lookupSetter__(b)&&(e=m("[Setter]","special"))),n.indexOf(b)<0&&(c="["+b+"]"),e||(l.indexOf(a[b])<0?(e=null===i?k(a[b]):k(a[b],i-1),e.indexOf("\n")>-1&&(e=d(a)?e.split("\n").map(function(a){return" "+a}).join("\n").substr(2):"\n"+e.split("\n").map(function(a){return" "+a}).join("\n"))):e=m("[Circular]","special")),"undefined"==typeof c){if("Array"===r&&b.match(/^\d+$/))return e;c=JSON.stringify(""+b),c.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(c=c.substr(1,c.length-2),c=m(c,"name")):(c=c.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),c=m(c,"string"))}return c+": "+e});l.pop();var v=0,w=u.reduce(function(a,b){return v++,b.indexOf("\n")>=0&&v++,a+b.length+1},0);return u=w>50?s[0]+(""===q?"":q+"\n ")+" "+u.join(",\n ")+" "+s[1]:s[0]+q+" "+u.join(", ")+" "+s[1]}var l=[],m=function(a,b){var c={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]},d={special:"cyan",number:"blue","boolean":"yellow",undefined:"grey","null":"bold",string:"green",date:"magenta",regexp:"red"}[b];return d?"["+c[d][0]+"m"+a+"["+c[d][1]+"m":a};return j||(m=function(a){return a}),k(a,"undefined"==typeof i?2:i)},c.log=function(){},c.pump=null;var g=Object.keys||function(a){var b=[];for(var c in a)b.push(c);return b},h=Object.getOwnPropertyNames||function(a){var b=[];for(var c in a)Object.hasOwnProperty.call(a,c)&&b.push(c);return b},i=Object.create||function(a,b){var c;if(null===a)c={__proto__:null};else{if("object"!=typeof a)throw new TypeError("typeof prototype["+typeof a+"] != 'object'");var d=function(){};d.prototype=a,c=new d,c.__proto__=a}return"undefined"!=typeof b&&Object.defineProperties&&Object.defineProperties(c,b),c};c.inherits=function(a,b){a.super_=b,a.prototype=i(b.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}}) +};var j=/%[sdj%]/g;c.format=function(a){if("string"!=typeof a){for(var b=[],d=0;d=f)return a;switch(a){case"%s":return String(e[d++]);case"%d":return Number(e[d++]);case"%j":return JSON.stringify(e[d++]);default:return a}}),h=e[d];f>d;h=e[++d])g+=null===h||"object"!=typeof h?" "+h:" "+c.inspect(h);return g}},{events:4}],5:[function(a,b,c){c.readIEEE754=function(a,b,c,d,e){var f,g,h=8*e-d-1,i=(1<>1,k=-7,l=c?0:e-1,m=c?1:-1,n=a[b+l];for(l+=m,f=n&(1<<-k)-1,n>>=-k,k+=h;k>0;f=256*f+a[b+l],l+=m,k-=8);for(g=f&(1<<-k)-1,f>>=-k,k+=d;k>0;g=256*g+a[b+l],l+=m,k-=8);if(0===f)f=1-j;else{if(f===i)return g?0/0:1/0*(n?-1:1);g+=Math.pow(2,d),f-=j}return(n?-1:1)*g*Math.pow(2,f-d)},c.writeIEEE754=function(a,b,c,d,e,f){var g,h,i,j=8*f-e-1,k=(1<>1,m=23===e?Math.pow(2,-24)-Math.pow(2,-77):0,n=d?f-1:0,o=d?-1:1,p=0>b||0===b&&0>1/b?1:0;for(b=Math.abs(b),isNaN(b)||1/0===b?(h=isNaN(b)?1:0,g=k):(g=Math.floor(Math.log(b)/Math.LN2),b*(i=Math.pow(2,-g))<1&&(g--,i*=2),b+=g+l>=1?m/i:m*Math.pow(2,1-l),b*i>=2&&(g++,i/=2),g+l>=k?(h=0,g=k):g+l>=1?(h=(b*i-1)*Math.pow(2,e),g+=l):(h=b*Math.pow(2,l-1)*Math.pow(2,e),g=0));e>=8;a[c+n]=255&h,n+=o,h/=256,e-=8);for(g=g<0;a[c+n]=255&g,n+=o,g/=256,j-=8);a[c+n-o]|=128*p}},{}],6:[function(a,b){var c=b.exports={};c.nextTick=function(){var a="undefined"!=typeof window&&window.setImmediate,b="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(a)return function(a){return window.setImmediate(a)};if(b){var c=[];return window.addEventListener("message",function(a){if(a.source===window&&"process-tick"===a.data&&(a.stopPropagation(),c.length>0)){var b=c.shift();b()}},!0),function(a){c.push(a),window.postMessage("process-tick","*")}}return function(a){setTimeout(a,0)}}(),c.title="browser",c.browser=!0,c.env={},c.argv=[],c.binding=function(){throw new Error("process.binding is not supported")},c.cwd=function(){return"/"},c.chdir=function(){throw new Error("process.chdir is not supported")}},{}],4:[function(a,b,c){!function(a){function b(a,b){if(a.indexOf)return a.indexOf(b);for(var c=0;cf;f++)d[f].apply(this,c);return!0}return!1},d.prototype.addListener=function(a,b){if("function"!=typeof b)throw new Error("addListener only takes instances of Function");if(this._events||(this._events={}),this.emit("newListener",a,b),this._events[a])if(e(this._events[a])){if(!this._events[a].warned){var c;c=void 0!==this._events.maxListeners?this._events.maxListeners:f,c&&c>0&&this._events[a].length>c&&(this._events[a].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[a].length),console.trace())}this._events[a].push(b)}else this._events[a]=[this._events[a],b];else this._events[a]=b;return this},d.prototype.on=d.prototype.addListener,d.prototype.once=function(a,b){var c=this;return c.on(a,function d(){c.removeListener(a,d),b.apply(this,arguments)}),this},d.prototype.removeListener=function(a,c){if("function"!=typeof c)throw new Error("removeListener only takes instances of Function");if(!this._events||!this._events[a])return this;var d=this._events[a];if(e(d)){var f=b(d,c);if(0>f)return this;d.splice(f,1),0==d.length&&delete this._events[a]}else this._events[a]===c&&delete this._events[a];return this},d.prototype.removeAllListeners=function(a){return 0===arguments.length?(this._events={},this):(a&&this._events&&this._events[a]&&(this._events[a]=null),this)},d.prototype.listeners=function(a){return this._events||(this._events={}),this._events[a]||(this._events[a]=[]),e(this._events[a])||(this._events[a]=[this._events[a]]),this._events[a]}}(a("__browserify_process"))},{__browserify_process:6}],"buffer-browserify":[function(a,b){b.exports=a("q9TxCC")},{}],q9TxCC:[function(a,b,c){function d(a){this.length=a}function e(a){return 16>a?"0"+a.toString(16):a.toString(16)}function f(a){for(var b=[],c=0;ce&&!(e+c>=b.length||e>=a.length);)b[e+c]=a[e],e++;return e}function j(a){try{return decodeURIComponent(a)}catch(b){return String.fromCharCode(65533)}}function k(a){return a=~~Math.ceil(+a),0>a?0:a}function l(a,b,c){if(!(this instanceof l))return new l(a,b,c);var e;if("number"==typeof c)this.length=k(b),this.parent=a,this.offset=c;else{switch(e=typeof a){case"number":this.length=k(a);break;case"string":this.length=l.byteLength(a,b);break;case"object":this.length=k(a.length);break;default:throw new Error("First argument needs to be a number, array or string.")}if(this.length>l.poolSize?(this.parent=new d(this.length),this.offset=0):((!E||E.length-E.used=a.length?0:(c?(e=a.parent[a.offset+b]<<8,b+1=a.length?0:(c?(b+1>>0):(b+2>>0)),e)}function q(a,b,c,d){var e,f;return d||(D.ok("boolean"==typeof c,"missing or invalid endian"),D.ok(void 0!==b&&null!==b,"missing offset"),D.ok(b+1=0,"specified a negative value for writing an unsigned value"),D.ok(b>=a,"value is larger than maximum value for type"),D.ok(Math.floor(a)===a,"value has a fractional component")}function v(a,b,c,d,e){e||(D.ok(void 0!==b&&null!==b,"missing value"),D.ok("boolean"==typeof d,"missing or invalid endian"),D.ok(void 0!==c&&null!==c,"missing offset"),D.ok(c+1>>8*(d?1-f:f)}function w(a,b,c,d,e){e||(D.ok(void 0!==b&&null!==b,"missing value"),D.ok("boolean"==typeof d,"missing or invalid endian"),D.ok(void 0!==c&&null!==c,"missing offset"),D.ok(c+3>>8*(d?3-f:f)}function x(a,b,c){D.ok("number"==typeof a,"cannot write a non-number as a number"),D.ok(b>=a,"value larger than maximum allowed value"),D.ok(a>=c,"value smaller than minimum allowed value"),D.ok(Math.floor(a)===a,"value has a fractional component")}function y(a,b,c){D.ok("number"==typeof a,"cannot write a non-number as a number"),D.ok(b>=a,"value larger than maximum allowed value"),D.ok(a>=c,"value smaller than minimum allowed value")}function z(a,b,c,d,e){e||(D.ok(void 0!==b&&null!==b,"missing value"),D.ok("boolean"==typeof d,"missing or invalid endian"),D.ok(void 0!==c&&null!==c,"missing offset"),D.ok(c+1=0?v(a,b,c,d,e):v(a,65535+b+1,c,d,e)}function A(a,b,c,d,e){e||(D.ok(void 0!==b&&null!==b,"missing value"),D.ok("boolean"==typeof d,"missing or invalid endian"),D.ok(void 0!==c&&null!==c,"missing offset"),D.ok(c+3=0?w(a,b,c,d,e):w(a,4294967295+b+1,c,d,e)}function B(b,c,d,e,f){f||(D.ok(void 0!==c&&null!==c,"missing value"),D.ok("boolean"==typeof e,"missing or invalid endian"),D.ok(void 0!==d&&null!==d,"missing offset"),D.ok(d+3d;d++)if(a[d]=e(this[d]),d==c.INSPECT_MAX_BYTES){a[d+1]="...";break}return""},d.prototype.hexSlice=function(a,b){var c=this.length;(!a||0>a)&&(a=0),(!b||0>b||b>c)&&(b=c);for(var d="",f=a;b>f;f++)d+=e(this[f]);return d},d.prototype.toString=function(a,b,c){if(a=String(a||"utf8").toLowerCase(),b=+b||0,"undefined"==typeof c&&(c=this.length),+c==b)return"";switch(a){case"hex":return this.hexSlice(b,c);case"utf8":case"utf-8":return this.utf8Slice(b,c);case"ascii":return this.asciiSlice(b,c);case"binary":return this.binarySlice(b,c);case"base64":return this.base64Slice(b,c);case"ucs2":case"ucs-2":return this.ucs2Slice(b,c);default:throw new Error("Unknown encoding")}},d.prototype.hexWrite=function(a,b,c){b=+b||0;var e=this.length-b;c?(c=+c,c>e&&(c=e)):c=e;var f=a.length;if(f%2)throw new Error("Invalid hex string");c>f/2&&(c=f/2);for(var g=0;c>g;g++){var h=parseInt(a.substr(2*g,2),16);if(isNaN(h))throw new Error("Invalid hex string");this[b+g]=h}return d._charsWritten=2*g,g},d.prototype.write=function(a,b,c,d){if(isFinite(b))isFinite(c)||(d=c,c=void 0);else{var e=d;d=b,b=c,c=e}b=+b||0;var f=this.length-b;switch(c?(c=+c,c>f&&(c=f)):c=f,d=String(d||"utf8").toLowerCase()){case"hex":return this.hexWrite(a,b,c);case"utf8":case"utf-8":return this.utf8Write(a,b,c);case"ascii":return this.asciiWrite(a,b,c);case"binary":return this.binaryWrite(a,b,c);case"base64":return this.base64Write(a,b,c);case"ucs2":case"ucs-2":return this.ucs2Write(a,b,c);default:throw new Error("Unknown encoding")}},d.prototype.slice=function(a,b){if(void 0===b&&(b=this.length),b>this.length)throw new Error("oob");if(a>b)throw new Error("oob");return new l(this,b-a,+a)},d.prototype.copy=function(a,b,c,d){for(var e=[],f=c;d>f;f++)D.ok("undefined"!=typeof this[f],"copying undefined buffer bytes!"),e.push(this[f]);for(var f=b;fthis.length)throw new Error("oob");if(b>c)throw new Error("oob");for(var d=b;c>d;d++)this[d]=a},c.SlowBuffer=d,c.Buffer=l,l.poolSize=8192;var E;l.isBuffer=function(a){return a instanceof l||a instanceof d},l.concat=function(a,b){if(!Array.isArray(a))throw new Error("Usage: Buffer.concat(list, [totalLength])\n list should be an Array.");if(0===a.length)return new l(0);if(1===a.length)return a[0];if("number"!=typeof b){b=0;for(var c=0;cd;d++)if(a[d]=e(this.parent[d+this.offset]),d==c.INSPECT_MAX_BYTES){a[d+1]="...";break}return""},l.prototype.get=function(a){if(0>a||a>=this.length)throw new Error("oob");return this.parent[this.offset+a]},l.prototype.set=function(a,b){if(0>a||a>=this.length)throw new Error("oob");return this.parent[this.offset+a]=b},l.prototype.write=function(a,b,c,e){if(isFinite(b))isFinite(c)||(e=c,c=void 0);else{var f=e;e=b,b=c,c=f}b=+b||0;var g=this.length-b;c?(c=+c,c>g&&(c=g)):c=g,e=String(e||"utf8").toLowerCase();var h;switch(e){case"hex":h=this.parent.hexWrite(a,this.offset+b,c);break;case"utf8":case"utf-8":h=this.parent.utf8Write(a,this.offset+b,c);break;case"ascii":h=this.parent.asciiWrite(a,this.offset+b,c);break;case"binary":h=this.parent.binaryWrite(a,this.offset+b,c);break;case"base64":h=this.parent.base64Write(a,this.offset+b,c);break;case"ucs2":case"ucs-2":h=this.parent.ucs2Write(a,this.offset+b,c);break;default:throw new Error("Unknown encoding")}return l._charsWritten=d._charsWritten,h},l.prototype.toString=function(a,b,c){switch(a=String(a||"utf8").toLowerCase(),"undefined"==typeof b||0>b?b=0:b>this.length&&(b=this.length),"undefined"==typeof c||c>this.length?c=this.length:0>c&&(c=0),b+=this.offset,c+=this.offset,a){case"hex":return this.parent.hexSlice(b,c);case"utf8":case"utf-8":return this.parent.utf8Slice(b,c);case"ascii":return this.parent.asciiSlice(b,c);case"binary":return this.parent.binarySlice(b,c);case"base64":return this.parent.base64Slice(b,c);case"ucs2":case"ucs-2":return this.parent.ucs2Slice(b,c);default:throw new Error("Unknown encoding")}},l.byteLength=d.byteLength,l.prototype.fill=function(a,b,c){if(a||(a=0),b||(b=0),c||(c=this.length),"string"==typeof a&&(a=a.charCodeAt(0)),"number"!=typeof a||isNaN(a))throw new Error("value is not a number");if(b>c)throw new Error("end < start");if(c===b)return 0;if(0==this.length)return 0;if(0>b||b>=this.length)throw new Error("start out of bounds");if(0>c||c>this.length)throw new Error("end out of bounds");return this.parent.fill(a,b+this.offset,c+this.offset)},l.prototype.copy=function(a,b,c,d){var e=this;if(c||(c=0),d||(d=this.length),b||(b=0),c>d)throw new Error("sourceEnd < sourceStart");if(d===c)return 0;if(0==a.length||0==e.length)return 0;if(0>b||b>=a.length)throw new Error("targetStart out of bounds");if(0>c||c>=e.length)throw new Error("sourceStart out of bounds");if(0>d||d>e.length)throw new Error("sourceEnd out of bounds");return d>this.length&&(d=this.length),a.length-bthis.length)throw new Error("oob");if(a>b)throw new Error("oob");return new l(this.parent,b-a,+a+this.offset)},l.prototype.utf8Slice=function(a,b){return this.toString("utf8",a,b)},l.prototype.binarySlice=function(a,b){return this.toString("binary",a,b)},l.prototype.asciiSlice=function(a,b){return this.toString("ascii",a,b)},l.prototype.utf8Write=function(a,b){return this.write(a,b,"utf8")},l.prototype.binaryWrite=function(a,b){return this.write(a,b,"binary")},l.prototype.asciiWrite=function(a,b){return this.write(a,b,"ascii")},l.prototype.readUInt8=function(a,b){var c=this;return b||(D.ok(void 0!==a&&null!==a,"missing offset"),D.ok(a=c.length?void 0:c.parent[c.offset+a]},l.prototype.readUInt16LE=function(a,b){return o(this,a,!1,b)},l.prototype.readUInt16BE=function(a,b){return o(this,a,!0,b)},l.prototype.readUInt32LE=function(a,b){return p(this,a,!1,b)},l.prototype.readUInt32BE=function(a,b){return p(this,a,!0,b)},l.prototype.readInt8=function(a,b){var c,d=this;return b||(D.ok(void 0!==a&&null!==a,"missing offset"),D.ok(a=d.length?void 0:(c=128&d.parent[d.offset+a],c?-1*(255-d.parent[d.offset+a]+1):d.parent[d.offset+a])},l.prototype.readInt16LE=function(a,b){return q(this,a,!1,b)},l.prototype.readInt16BE=function(a,b){return q(this,a,!0,b)},l.prototype.readInt32LE=function(a,b){return r(this,a,!1,b)},l.prototype.readInt32BE=function(a,b){return r(this,a,!0,b)},l.prototype.readFloatLE=function(a,b){return s(this,a,!1,b)},l.prototype.readFloatBE=function(a,b){return s(this,a,!0,b)},l.prototype.readDoubleLE=function(a,b){return t(this,a,!1,b)},l.prototype.readDoubleBE=function(a,b){return t(this,a,!0,b)},l.prototype.writeUInt8=function(a,b,c){var d=this;c||(D.ok(void 0!==a&&null!==a,"missing value"),D.ok(void 0!==b&&null!==b,"missing offset"),D.ok(b=0?d.writeUInt8(a,b,c):d.writeUInt8(255+a+1,b,c)},l.prototype.writeInt16LE=function(a,b,c){z(this,a,b,!1,c)},l.prototype.writeInt16BE=function(a,b,c){z(this,a,b,!0,c)},l.prototype.writeInt32LE=function(a,b,c){A(this,a,b,!1,c)},l.prototype.writeInt32BE=function(a,b,c){A(this,a,b,!0,c)},l.prototype.writeFloatLE=function(a,b,c){B(this,a,b,!1,c)},l.prototype.writeFloatBE=function(a,b,c){B(this,a,b,!0,c)},l.prototype.writeDoubleLE=function(a,b,c){C(this,a,b,!1,c)},l.prototype.writeDoubleBE=function(a,b,c){C(this,a,b,!0,c)},d.prototype.readUInt8=l.prototype.readUInt8,d.prototype.readUInt16LE=l.prototype.readUInt16LE,d.prototype.readUInt16BE=l.prototype.readUInt16BE,d.prototype.readUInt32LE=l.prototype.readUInt32LE,d.prototype.readUInt32BE=l.prototype.readUInt32BE,d.prototype.readInt8=l.prototype.readInt8,d.prototype.readInt16LE=l.prototype.readInt16LE,d.prototype.readInt16BE=l.prototype.readInt16BE,d.prototype.readInt32LE=l.prototype.readInt32LE,d.prototype.readInt32BE=l.prototype.readInt32BE,d.prototype.readFloatLE=l.prototype.readFloatLE,d.prototype.readFloatBE=l.prototype.readFloatBE,d.prototype.readDoubleLE=l.prototype.readDoubleLE,d.prototype.readDoubleBE=l.prototype.readDoubleBE,d.prototype.writeUInt8=l.prototype.writeUInt8,d.prototype.writeUInt16LE=l.prototype.writeUInt16LE,d.prototype.writeUInt16BE=l.prototype.writeUInt16BE,d.prototype.writeUInt32LE=l.prototype.writeUInt32LE,d.prototype.writeUInt32BE=l.prototype.writeUInt32BE,d.prototype.writeInt8=l.prototype.writeInt8,d.prototype.writeInt16LE=l.prototype.writeInt16LE,d.prototype.writeInt16BE=l.prototype.writeInt16BE,d.prototype.writeInt32LE=l.prototype.writeInt32LE,d.prototype.writeInt32BE=l.prototype.writeInt32BE,d.prototype.writeFloatLE=l.prototype.writeFloatLE,d.prototype.writeFloatBE=l.prototype.writeFloatBE,d.prototype.writeDoubleLE=l.prototype.writeDoubleLE,d.prototype.writeDoubleBE=l.prototype.writeDoubleBE},{assert:1,"./buffer_ieee754":5,"base64-js":7}],7:[function(a,b){!function(){"use strict";function a(a){var b,c,e,f,g,h;if(a.length%4>0)throw"Invalid string. Length must be a multiple of 4";for(g=a.indexOf("="),g=g>0?a.length-g:0,h=[],e=g>0?a.length-4:a.length,b=0,c=0;e>b;b+=4,c+=3)f=d.indexOf(a[b])<<18|d.indexOf(a[b+1])<<12|d.indexOf(a[b+2])<<6|d.indexOf(a[b+3]),h.push((16711680&f)>>16),h.push((65280&f)>>8),h.push(255&f);return 2===g?(f=d.indexOf(a[b])<<2|d.indexOf(a[b+1])>>4,h.push(255&f)):1===g&&(f=d.indexOf(a[b])<<10|d.indexOf(a[b+1])<<4|d.indexOf(a[b+2])>>2,h.push(255&f>>8),h.push(255&f)),h}function c(a){function b(a){return d[63&a>>18]+d[63&a>>12]+d[63&a>>6]+d[63&a]}var c,e,f,g=a.length%3,h="";for(c=0,f=a.length-g;f>c;c+=3)e=(a[c]<<16)+(a[c+1]<<8)+a[c+2],h+=b(e);switch(g){case 1:e=a[a.length-1],h+=d[e>>2],h+=d[63&e<<4],h+="==";break;case 2:e=(a[a.length-2]<<8)+a[a.length-1],h+=d[e>>10],h+=d[63&e>>4],h+=d[63&e<<2],h+="="}return h}var d="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";b.exports.toByteArray=a,b.exports.fromByteArray=c}()},{}],8:[function(a,b,c){c.readIEEE754=function(a,b,c,d,e){var f,g,h=8*e-d-1,i=(1<>1,k=-7,l=c?0:e-1,m=c?1:-1,n=a[b+l];for(l+=m,f=n&(1<<-k)-1,n>>=-k,k+=h;k>0;f=256*f+a[b+l],l+=m,k-=8);for(g=f&(1<<-k)-1,f>>=-k,k+=d;k>0;g=256*g+a[b+l],l+=m,k-=8);if(0===f)f=1-j;else{if(f===i)return g?0/0:1/0*(n?-1:1);g+=Math.pow(2,d),f-=j}return(n?-1:1)*g*Math.pow(2,f-d)},c.writeIEEE754=function(a,b,c,d,e,f){var g,h,i,j=8*f-e-1,k=(1<>1,m=23===e?Math.pow(2,-24)-Math.pow(2,-77):0,n=d?f-1:0,o=d?-1:1,p=0>b||0===b&&0>1/b?1:0;for(b=Math.abs(b),isNaN(b)||1/0===b?(h=isNaN(b)?1:0,g=k):(g=Math.floor(Math.log(b)/Math.LN2),b*(i=Math.pow(2,-g))<1&&(g--,i*=2),b+=g+l>=1?m/i:m*Math.pow(2,1-l),b*i>=2&&(g++,i/=2),g+l>=k?(h=0,g=k):g+l>=1?(h=(b*i-1)*Math.pow(2,e),g+=l):(h=b*Math.pow(2,l-1)*Math.pow(2,e),g=0));e>=8;a[c+n]=255&h,n+=o,h/=256,e-=8);for(g=g<0;a[c+n]=255&g,n+=o,g/=256,j-=8);a[c+n-o]|=128*p}},{}],3:[function(a,b,c){function d(a){this.length=a}function e(a){return 16>a?"0"+a.toString(16):a.toString(16)}function f(a){for(var b=[],c=0;ce&&!(e+c>=b.length||e>=a.length);)b[e+c]=a[e],e++;return e}function j(a){try{return decodeURIComponent(a)}catch(b){return String.fromCharCode(65533)}}function k(a){return a=~~Math.ceil(+a),0>a?0:a}function l(a,b,c){if(!(this instanceof l))return new l(a,b,c);var e;if("number"==typeof c)this.length=k(b),this.parent=a,this.offset=c;else{switch(e=typeof a){case"number":this.length=k(a);break;case"string":this.length=l.byteLength(a,b);break;case"object":this.length=k(a.length);break;default:throw new Error("First argument needs to be a number, array or string.")}if(this.length>l.poolSize?(this.parent=new d(this.length),this.offset=0):((!E||E.length-E.used>>0):(e=a.parent[a.offset+b+2]<<16,e|=a.parent[a.offset+b+1]<<8,e|=a.parent[a.offset+b],e+=a.parent[a.offset+b+3]<<24>>>0),e}function q(a,b,c,d){var e,f;return d||(D.ok("boolean"==typeof c,"missing or invalid endian"),D.ok(void 0!==b&&null!==b,"missing offset"),D.ok(b+1=0,"specified a negative value for writing an unsigned value"),D.ok(b>=a,"value is larger than maximum value for type"),D.ok(Math.floor(a)===a,"value has a fractional component")}function v(a,b,c,d,e){e||(D.ok(void 0!==b&&null!==b,"missing value"),D.ok("boolean"==typeof d,"missing or invalid endian"),D.ok(void 0!==c&&null!==c,"missing offset"),D.ok(c+1>>8,a.parent[a.offset+c+1]=255&b):(a.parent[a.offset+c+1]=(65280&b)>>>8,a.parent[a.offset+c]=255&b)}function w(a,b,c,d,e){e||(D.ok(void 0!==b&&null!==b,"missing value"),D.ok("boolean"==typeof d,"missing or invalid endian"),D.ok(void 0!==c&&null!==c,"missing offset"),D.ok(c+3>>24,a.parent[a.offset+c+1]=255&b>>>16,a.parent[a.offset+c+2]=255&b>>>8,a.parent[a.offset+c+3]=255&b):(a.parent[a.offset+c+3]=255&b>>>24,a.parent[a.offset+c+2]=255&b>>>16,a.parent[a.offset+c+1]=255&b>>>8,a.parent[a.offset+c]=255&b)}function x(a,b,c){D.ok("number"==typeof a,"cannot write a non-number as a number"),D.ok(b>=a,"value larger than maximum allowed value"),D.ok(a>=c,"value smaller than minimum allowed value"),D.ok(Math.floor(a)===a,"value has a fractional component")}function y(a,b,c){D.ok("number"==typeof a,"cannot write a non-number as a number"),D.ok(b>=a,"value larger than maximum allowed value"),D.ok(a>=c,"value smaller than minimum allowed value")}function z(a,b,c,d,e){e||(D.ok(void 0!==b&&null!==b,"missing value"),D.ok("boolean"==typeof d,"missing or invalid endian"),D.ok(void 0!==c&&null!==c,"missing offset"),D.ok(c+1=0?v(a,b,c,d,e):v(a,65535+b+1,c,d,e)}function A(a,b,c,d,e){e||(D.ok(void 0!==b&&null!==b,"missing value"),D.ok("boolean"==typeof d,"missing or invalid endian"),D.ok(void 0!==c&&null!==c,"missing offset"),D.ok(c+3=0?w(a,b,c,d,e):w(a,4294967295+b+1,c,d,e)}function B(b,c,d,e,f){f||(D.ok(void 0!==c&&null!==c,"missing value"),D.ok("boolean"==typeof e,"missing or invalid endian"),D.ok(void 0!==d&&null!==d,"missing offset"),D.ok(d+3d;d++)if(a[d]=e(this[d]),d==c.INSPECT_MAX_BYTES){a[d+1]="...";break}return""},d.prototype.hexSlice=function(a,b){var c=this.length;(!a||0>a)&&(a=0),(!b||0>b||b>c)&&(b=c);for(var d="",f=a;b>f;f++)d+=e(this[f]);return d},d.prototype.toString=function(a,b,c){if(a=String(a||"utf8").toLowerCase(),b=+b||0,"undefined"==typeof c&&(c=this.length),+c==b)return"";switch(a){case"hex":return this.hexSlice(b,c);case"utf8":case"utf-8":return this.utf8Slice(b,c);case"ascii":return this.asciiSlice(b,c);case"binary":return this.binarySlice(b,c);case"base64":return this.base64Slice(b,c);case"ucs2":case"ucs-2":return this.ucs2Slice(b,c);default:throw new Error("Unknown encoding")}},d.prototype.hexWrite=function(a,b,c){b=+b||0;var e=this.length-b;c?(c=+c,c>e&&(c=e)):c=e;var f=a.length;if(f%2)throw new Error("Invalid hex string");c>f/2&&(c=f/2);for(var g=0;c>g;g++){var h=parseInt(a.substr(2*g,2),16);if(isNaN(h))throw new Error("Invalid hex string");this[b+g]=h}return d._charsWritten=2*g,g},d.prototype.write=function(a,b,c,d){if(isFinite(b))isFinite(c)||(d=c,c=void 0);else{var e=d;d=b,b=c,c=e}b=+b||0;var f=this.length-b;switch(c?(c=+c,c>f&&(c=f)):c=f,d=String(d||"utf8").toLowerCase()){case"hex":return this.hexWrite(a,b,c);case"utf8":case"utf-8":return this.utf8Write(a,b,c);case"ascii":return this.asciiWrite(a,b,c);case"binary":return this.binaryWrite(a,b,c);case"base64":return this.base64Write(a,b,c);case"ucs2":case"ucs-2":return this.ucs2Write(a,b,c);default:throw new Error("Unknown encoding")}},d.prototype.slice=function(a,b){if(void 0===b&&(b=this.length),b>this.length)throw new Error("oob"); +if(a>b)throw new Error("oob");return new l(this,b-a,+a)},d.prototype.copy=function(a,b,c,d){for(var e=[],f=c;d>f;f++)D.ok("undefined"!=typeof this[f],"copying undefined buffer bytes!"),e.push(this[f]);for(var f=b;fd;d++)if(a[d]=e(this.parent[d+this.offset]),d==c.INSPECT_MAX_BYTES){a[d+1]="...";break}return""},l.prototype.get=function(a){if(0>a||a>=this.length)throw new Error("oob");return this.parent[this.offset+a]},l.prototype.set=function(a,b){if(0>a||a>=this.length)throw new Error("oob");return this.parent[this.offset+a]=b},l.prototype.write=function(a,b,c,e){if(isFinite(b))isFinite(c)||(e=c,c=void 0);else{var f=e;e=b,b=c,c=f}b=+b||0;var g=this.length-b;c?(c=+c,c>g&&(c=g)):c=g,e=String(e||"utf8").toLowerCase();var h;switch(e){case"hex":h=this.parent.hexWrite(a,this.offset+b,c);break;case"utf8":case"utf-8":h=this.parent.utf8Write(a,this.offset+b,c);break;case"ascii":h=this.parent.asciiWrite(a,this.offset+b,c);break;case"binary":h=this.parent.binaryWrite(a,this.offset+b,c);break;case"base64":h=this.parent.base64Write(a,this.offset+b,c);break;case"ucs2":case"ucs-2":h=this.parent.ucs2Write(a,this.offset+b,c);break;default:throw new Error("Unknown encoding")}return l._charsWritten=d._charsWritten,h},l.prototype.toString=function(a,b,c){switch(a=String(a||"utf8").toLowerCase(),"undefined"==typeof b||0>b?b=0:b>this.length&&(b=this.length),"undefined"==typeof c||c>this.length?c=this.length:0>c&&(c=0),b+=this.offset,c+=this.offset,a){case"hex":return this.parent.hexSlice(b,c);case"utf8":case"utf-8":return this.parent.utf8Slice(b,c);case"ascii":return this.parent.asciiSlice(b,c);case"binary":return this.parent.binarySlice(b,c);case"base64":return this.parent.base64Slice(b,c);case"ucs2":case"ucs-2":return this.parent.ucs2Slice(b,c);default:throw new Error("Unknown encoding")}},l.byteLength=d.byteLength,l.prototype.fill=function(a,b,c){if(a||(a=0),b||(b=0),c||(c=this.length),"string"==typeof a&&(a=a.charCodeAt(0)),"number"!=typeof a||isNaN(a))throw new Error("value is not a number");if(b>c)throw new Error("end < start");if(c===b)return 0;if(0==this.length)return 0;if(0>b||b>=this.length)throw new Error("start out of bounds");if(0>c||c>this.length)throw new Error("end out of bounds");return this.parent.fill(a,b+this.offset,c+this.offset)},l.prototype.copy=function(a,b,c,d){var e=this;if(c||(c=0),d||(d=this.length),b||(b=0),c>d)throw new Error("sourceEnd < sourceStart");if(d===c)return 0;if(0==a.length||0==e.length)return 0;if(0>b||b>=a.length)throw new Error("targetStart out of bounds");if(0>c||c>=e.length)throw new Error("sourceStart out of bounds");if(0>d||d>e.length)throw new Error("sourceEnd out of bounds");return d>this.length&&(d=this.length),a.length-bthis.length)throw new Error("oob");if(a>b)throw new Error("oob");return new l(this.parent,b-a,+a+this.offset)},l.prototype.utf8Slice=function(a,b){return this.toString("utf8",a,b)},l.prototype.binarySlice=function(a,b){return this.toString("binary",a,b)},l.prototype.asciiSlice=function(a,b){return this.toString("ascii",a,b)},l.prototype.utf8Write=function(a,b){return this.write(a,b,"utf8")},l.prototype.binaryWrite=function(a,b){return this.write(a,b,"binary")},l.prototype.asciiWrite=function(a,b){return this.write(a,b,"ascii")},l.prototype.readUInt8=function(a,b){var c=this;return b||(D.ok(void 0!==a&&null!==a,"missing offset"),D.ok(a=0?d.writeUInt8(a,b,c):d.writeUInt8(255+a+1,b,c)},l.prototype.writeInt16LE=function(a,b,c){z(this,a,b,!1,c)},l.prototype.writeInt16BE=function(a,b,c){z(this,a,b,!0,c)},l.prototype.writeInt32LE=function(a,b,c){A(this,a,b,!1,c)},l.prototype.writeInt32BE=function(a,b,c){A(this,a,b,!0,c)},l.prototype.writeFloatLE=function(a,b,c){B(this,a,b,!1,c)},l.prototype.writeFloatBE=function(a,b,c){B(this,a,b,!0,c)},l.prototype.writeDoubleLE=function(a,b,c){C(this,a,b,!1,c)},l.prototype.writeDoubleBE=function(a,b,c){C(this,a,b,!0,c)},d.prototype.readUInt8=l.prototype.readUInt8,d.prototype.readUInt16LE=l.prototype.readUInt16LE,d.prototype.readUInt16BE=l.prototype.readUInt16BE,d.prototype.readUInt32LE=l.prototype.readUInt32LE,d.prototype.readUInt32BE=l.prototype.readUInt32BE,d.prototype.readInt8=l.prototype.readInt8,d.prototype.readInt16LE=l.prototype.readInt16LE,d.prototype.readInt16BE=l.prototype.readInt16BE,d.prototype.readInt32LE=l.prototype.readInt32LE,d.prototype.readInt32BE=l.prototype.readInt32BE,d.prototype.readFloatLE=l.prototype.readFloatLE,d.prototype.readFloatBE=l.prototype.readFloatBE,d.prototype.readDoubleLE=l.prototype.readDoubleLE,d.prototype.readDoubleBE=l.prototype.readDoubleBE,d.prototype.writeUInt8=l.prototype.writeUInt8,d.prototype.writeUInt16LE=l.prototype.writeUInt16LE,d.prototype.writeUInt16BE=l.prototype.writeUInt16BE,d.prototype.writeUInt32LE=l.prototype.writeUInt32LE,d.prototype.writeUInt32BE=l.prototype.writeUInt32BE,d.prototype.writeInt8=l.prototype.writeInt8,d.prototype.writeInt16LE=l.prototype.writeInt16LE,d.prototype.writeInt16BE=l.prototype.writeInt16BE,d.prototype.writeInt32LE=l.prototype.writeInt32LE,d.prototype.writeInt32BE=l.prototype.writeInt32BE,d.prototype.writeFloatLE=l.prototype.writeFloatLE,d.prototype.writeFloatBE=l.prototype.writeFloatBE,d.prototype.writeDoubleLE=l.prototype.writeDoubleLE,d.prototype.writeDoubleBE=l.prototype.writeDoubleBE},{assert:1,"./buffer_ieee754":8,"base64-js":9}],9:[function(a,b){!function(){"use strict";function a(a){var b,c,e,f,g,h;if(a.length%4>0)throw"Invalid string. Length must be a multiple of 4";for(g=a.indexOf("="),g=g>0?a.length-g:0,h=[],e=g>0?a.length-4:a.length,b=0,c=0;e>b;b+=4,c+=3)f=d.indexOf(a[b])<<18|d.indexOf(a[b+1])<<12|d.indexOf(a[b+2])<<6|d.indexOf(a[b+3]),h.push((16711680&f)>>16),h.push((65280&f)>>8),h.push(255&f);return 2===g?(f=d.indexOf(a[b])<<2|d.indexOf(a[b+1])>>4,h.push(255&f)):1===g&&(f=d.indexOf(a[b])<<10|d.indexOf(a[b+1])<<4|d.indexOf(a[b+2])>>2,h.push(255&f>>8),h.push(255&f)),h}function c(a){function b(a){return d[63&a>>18]+d[63&a>>12]+d[63&a>>6]+d[63&a]}var c,e,f,g=a.length%3,h="";for(c=0,f=a.length-g;f>c;c+=3)e=(a[c]<<16)+(a[c+1]<<8)+a[c+2],h+=b(e);switch(g){case 1:e=a[a.length-1],h+=d[e>>2],h+=d[63&e<<4],h+="==";break;case 2:e=(a[a.length-2]<<8)+a[a.length-1],h+=d[e>>10],h+=d[63&e>>4],h+=d[63&e<<2],h+="="}return h}var d="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";b.exports.toByteArray=a,b.exports.fromByteArray=c}()},{}]},{},[]),b.exports=a("buffer-browserify")},{}],68:[function(a,b){var c=b.exports={};c.nextTick=function(){var a="undefined"!=typeof window&&window.setImmediate,b="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(a)return function(a){return window.setImmediate(a)};if(b){var c=[];return window.addEventListener("message",function(a){if(a.source===window&&"process-tick"===a.data&&(a.stopPropagation(),c.length>0)){var b=c.shift();b()}},!0),function(a){c.push(a),window.postMessage("process-tick","*")}}return function(a){setTimeout(a,0)}}(),c.title="browser",c.browser=!0,c.env={},c.argv=[],c.binding=function(){throw new Error("process.binding is not supported")},c.cwd=function(){return"/"},c.chdir=function(){throw new Error("process.chdir is not supported")}},{}],69:[function(a,b,c){!function(){"use strict";function d(a){var b=function(a){return"string"==typeof a?a:"object"==typeof a?a.hashCode?a.hashCode():""+a:""+a},c=a.declare({instance:{constructor:function(){this.__entries=[],this.__keys=[],this.__values=[]},pushValue:function(a,b){return this.__keys.push(a),this.__values.push(b),this.__entries.push({key:a,value:b}),b},remove:function(a){for(var b,c=null,d=this.__entries,e=this.__keys,f=this.__values,g=d.length-1;g>=0;g--)if((b=d[g])&&b.key===a)return d.splice(g,1),e.splice(g,1),f.splice(g,1),b.value;return c},set:function(a,b){for(var c=null,d=this.__entries,e=this.__values,f=d.length-1;f>=0;f--){var g=d[f];if(g&&a===g.key){e[f]=b,g.value=b,c=b;break}}return c||d.push({key:a,value:b}),c},find:function(a){for(var b,c=null,d=this.__entries,e=d.length-1;e>=0;e--)if(b=d[e],b&&a===b.key){c=b.value;break}return c},getEntrySet:function(){return this.__entries},getKeys:function(){return this.__keys},getValues:function(){return this.__values}}});return a.declare({instance:{constructor:function(){this.__map={}},entrySet:function(){var a=[],b=this.__map;for(var c in b)b.hasOwnProperty(c)&&(a=a.concat(b[c].getEntrySet()));return a},put:function(a,d){var e=b(a),f=null;return(f=this.__map[e])||(f=this.__map[e]=new c),f.pushValue(a,d),d},remove:function(a){var c=b(a),d=null,e=this.__map[c];return e&&(d=e.remove(a)),d},get:function(a){var c,d=b(a),e=null;return(c=this.__map[d])&&(e=c.find(a)),e},set:function(a,d){var e=b(a),f=null,g=null,h=this.__map;return f=(g=h[e])?g.set(a,d):(h[e]=new c).pushValue(a,d)},contains:function(a){var c=b(a),d=!1,e=null;return(e=this.__map[c])&&(d=!!e.find(a)),d},concat:function(a){if(a instanceof this._static){for(var b=new this._static,c=a.entrySet().concat(this.entrySet()),d=c.length-1;d>=0;d--){var e=c[d];b.put(e.key,e.value)}return b}throw new TypeError("When joining hashtables the joining arg must be a HashTable")},filter:function(b,c){var d=this.entrySet(),e=new this._static;d=a.filter(d,b,c);for(var f=d.length-1;f>=0;f--){var g=d[f];e.put(g.key,g.value)}return e},forEach:function(b,c){var d=this.entrySet();a.forEach(d,b,c)},every:function(b,c){var d=this.entrySet();return a.every(d,b,c)},map:function(b,c){var d=this.entrySet();return a.map(d,b,c)},some:function(b,c){var d=this.entrySet();return a.some(d,b,c)},reduce:function(b,c){var d=this.entrySet();return a.reduce(d,b,c)},reduceRight:function(b,c){var d=this.entrySet();return a.reduceRight(d,b,c)},clear:function(){this.__map={}},keys:function(){var a=[],b=this.__map;for(var c in b)a=a.concat(b[c].getKeys());return a},values:function(){var a=[],b=this.__map;for(var c in b)a=a.concat(b[c].getValues());return a},isEmpty:function(){return 0===this.keys().length}}})}"undefined"!=typeof c?"undefined"!=typeof b&&b.exports&&(b.exports=d(a("extended")().register("declare",a("declare.js")).register(a("is-extended")).register(a("array-extended")))):"function"==typeof define?define(["extended","declare","is-extended","array-extended"],function(a,b,c,e){return d(a().register("declare",b).register(c).register(e))}):this.Ht=d(this.extended().register("declare",this.declare).register(this.isExtended).register(this.arrayExtended))}.call(this)},{"array-extended":49,"declare.js":52,extended:53,"is-extended":70}],70:[function(a,b,c){var d=a("__browserify_Buffer").Buffer;!function(){"use strict";function e(a){function b(a,b){var c=-1,d=0,e=a.length,f=[];for(b=b||0,c+=b;++c=0;f--)if(g[f]!==h[f])return!1;for(f=g.length-1;f>=0;f--)if(d=g[f],!e(a[d],b[d]))return!1}catch(i){return!1}return!0}function g(a){return null!==a&&"object"==typeof a}function h(a){var b=g(a);return b&&a.constructor===Object&&!a.nodeType&&!a.setInterval}function i(a){return W(a)?0===a.length:g(a)?0===c(a).length:r(a)||X(a)?0===a.length:!0}function j(a){return a===!0||a===!1||"[object Boolean]"===U.call(a)}function k(a){return"undefined"==typeof a}function l(a){return!k(a)}function m(a){return k(a)||n(a)}function n(a){return null===a}function o(a,b){return V(b)?a instanceof b:!1}function p(a){return"[object RegExp]"===U.call(a)}function q(a){return"[object Date]"===U.call(a)}function r(a){return"[object String]"===U.call(a)}function s(a){return"[object Number]"===U.call(a)}function t(a){return a===!0}function u(a){return a===!1}function v(a){return!n(a)}function w(a,b){return a==b}function x(a,b){return a!=b}function y(a,b){return a===b}function z(a,b){return a!==b}function A(a,b){if(X(b)&&Array.prototype.indexOf||r(b))return b.indexOf(a)>-1;if(X(b))for(var c=0,d=b.length;d>c;c++)if(w(a,b[c]))return!0;return!1}function B(a,b){return!A(a,b)}function C(a,b){return b>a}function D(a,b){return b>=a}function E(a,b){return a>b}function F(a,b){return a>=b}function G(a,b){return r(b)?null!==(""+a).match(b):p(b)?b.test(a):!1}function H(a,b){return!G(a,b)}function I(a,b){return A(b,a)}function J(a,b){return!A(b,a)}function K(a,b,c){return X(a)&&a.length>c?w(a[c],b):!1}function L(a,b,c){return X(a)?!w(a[c],b):!1}function M(a,b){return T.call(a,b)}function N(a,b){return!M(a,b)}function O(a,b){return M(a,"length")?a.length===b:!1}function P(a,b){return M(a,"length")?a.length!==b:!1}function Q(a){Z[a]=function(){this._testers.push(Y[a])}}function R(a){$[a]=function(){var c,d=b(arguments,1),e=Y[a],f=!0;if(d.length<=e.length-1)throw new TypeError("A handler must be defined when calling using switch");if(c=d.pop(),j(c)&&(f=c,c=d.pop()),!V(c))throw new TypeError("handler must be defined");this._cases.push(function(a){return e.apply(Y,a.concat(d))?[f,c.apply(this,a)]:[!1]})}}var S=Array.prototype.slice,T=Object.prototype.hasOwnProperty,U=Object.prototype.toString,V=function(a){return"[object Function]"===U.call(a)};"undefined"==typeof window||V(window.alert)||function(a){V=function(b){return"[object Function]"===U.call(b)||b===a}}(window.alert);var W=function(a){return"[object Arguments]"===U.call(a)};W(arguments)||(W=function(a){return!(!a||!T.call(a,"callee"))});var X=Array.isArray||function(a){return"[object Array]"===U.call(a)},Y={isFunction:V,isObject:g,isEmpty:i,isHash:h,isNumber:s,isString:r,isDate:q,isArray:X,isBoolean:j,isUndefined:k,isDefined:l,isUndefinedOrNull:m,isNull:n,isArguments:W,instanceOf:o,isRegExp:p,deepEqual:e,isTrue:t,isFalse:u,isNotNull:v,isEq:w,isNeq:x,isSeq:y,isSneq:z,isIn:A,isNotIn:B,isLt:C,isLte:D,isGt:E,isGte:F,isLike:G,isNotLike:H,contains:I,notContains:J,has:M,notHas:N,isLength:O,isNotLength:P,containsAt:K,notContainsAt:L},Z={constructor:function(){this._testers=[]},noWrap:{tester:function(){var a=this._testers;return function(b){for(var c=!1,d=0,e=a.length;e>d&&!c;d++)c=a[d](b);return c}}}},$={constructor:function(){this._cases=[],this.__default=null},def:function(a,b){this.__default=b},noWrap:{switcher:function(){var a=this._cases,c=this.__default;return function(){for(var d,e=!1,f=b(arguments),g=0,h=a.length;h>g&&!e;g++)if(d=a[g](f),d.length>1&&(d[1]||d[0]))return d[1];return!e&&c?c.apply(this,f):void 0}}}};for(var _ in Y)T.call(Y,_)&&(R(_),Q(_));var ab=a.define(Y).expose(Y);return ab.tester=a.define(Z),ab.switcher=a.define($),ab}"undefined"!=typeof c?"undefined"!=typeof b&&b.exports&&(b.exports=e(a("extended"))):"function"==typeof define&&define.amd?define(["extended"],function(a){return e(a)}):this.isExtended=e(this.extended)}.call(this)},{__browserify_Buffer:67,extended:53}],71:[function(a,b,c){!function(){"use strict";function d(a){function b(a,b){var c=0;return a>b?1:b>a?-1:b?c:1}var c=a.multiply,d=a.declare({instance:{__printNode:function(b,d){var e=[];a.isUndefinedOrNull(b)?(e.push(c(" ",d)),e.push("~"),console.log(e.join(""))):(this.__printNode(b.right,d+1),e.push(c(" ",d)),e.push(b.data+"\n"),console.log(e.join("")),this.__printNode(b.left,d+1))},constructor:function(a){a=a||{},this.compare=a.compare||b,this.__root=null},insert:function(){throw new Error("Not Implemented")},remove:function(){throw new Error("Not Implemented")},clear:function(){this.__root=null},isEmpty:function(){return!this.__root},traverseWithCondition:function(a,b,c){var e=!0;return a&&(b=b||d.PRE_ORDER,b===d.PRE_ORDER?(e=c(a.data),e&&(e=this.traverseWithCondition(a.left,b,c),e&&(e=this.traverseWithCondition(a.right,b,c)))):b===d.IN_ORDER?(e=this.traverseWithCondition(a.left,b,c),e&&(e=c(a.data),e&&(e=this.traverseWithCondition(a.right,b,c)))):b===d.POST_ORDER?(e=this.traverseWithCondition(a.left,b,c),e&&(e&&(e=this.traverseWithCondition(a.right,b,c)),e&&(e=c(a.data)))):b===d.REVERSE_ORDER&&(e=this.traverseWithCondition(a.right,b,c),e&&(e=c(a.data),e&&(e=this.traverseWithCondition(a.left,b,c))))),e},traverse:function(a,b,c){a&&(b=b||d.PRE_ORDER,b===d.PRE_ORDER?(c(a.data),this.traverse(a.left,b,c),this.traverse(a.right,b,c)):b===d.IN_ORDER?(this.traverse(a.left,b,c),c(a.data),this.traverse(a.right,b,c)):b===d.POST_ORDER?(this.traverse(a.left,b,c),this.traverse(a.right,b,c),c(a.data)):b===d.REVERSE_ORDER&&(this.traverse(a.right,b,c),c(a.data),this.traverse(a.left,b,c)))},forEach:function(a,b,c){if("function"!=typeof a)throw new TypeError;c=c||d.IN_ORDER,b=b||this,this.traverse(this.__root,c,function(c){a.call(b,c,this)})},map:function(a,b,c){if("function"!=typeof a)throw new TypeError;c=c||d.IN_ORDER,b=b||this;var e=new this._static;return this.traverse(this.__root,c,function(c){e.insert(a.call(b,c,this))}),e},filter:function(a,b,c){if("function"!=typeof a)throw new TypeError;c=c||d.IN_ORDER,b=b||this;var e=new this._static;return this.traverse(this.__root,c,function(c){a.call(b,c,this)&&e.insert(c)}),e},reduce:function(b,c,d){var e=this.toArray(d),f=[e,b];return a.isUndefinedOrNull(c)||f.push(c),a.reduce.apply(a,f)},reduceRight:function(b,c,d){var e=this.toArray(d),f=[e,b];return a.isUndefinedOrNull(c)||f.push(c),a.reduceRight.apply(a,f)},every:function(a,b,c){if("function"!=typeof a)throw new TypeError;c=c||d.IN_ORDER,b=b||this;var e=!1;return this.traverseWithCondition(this.__root,c,function(c){return e=a.call(b,c,this)}),e},some:function(a,b,c){if("function"!=typeof a)throw new TypeError;c=c||d.IN_ORDER,b=b||this;var e;return this.traverseWithCondition(this.__root,c,function(c){return e=a.call(b,c,this),!e}),e},toArray:function(a){a=a||d.IN_ORDER;var b=[];return this.traverse(this.__root,a,function(a){b.push(a)}),b},contains:function(a){for(var b=!1,c=this.__root;null!==c;){var d=this.compare(a,c.data);d?c=c[-1===d?"left":"right"]:(b=!0,c=null)}return b},find:function(a){for(var b,c=this.__root;c;){var d=this.compare(a,c.data);if(!d){b=c.data;break}c=c[-1===d?"left":"right"]}return b},findLessThan:function(a,b){var c=[],e=this.compare;return this.traverseWithCondition(this.__root,d.IN_ORDER,function(d){var f=e(a,d);return!b&&0===f||1===f?(c.push(d),!0):!1}),c},findGreaterThan:function(a,b){var c=[],e=this.compare;return this.traverse(this.__root,d.REVERSE_ORDER,function(d){var f=e(a,d);return!b&&0===f||-1===f?(c.push(d),!0):!1}),c},print:function(){this.__printNode(this.__root,0)}},"static":{PRE_ORDER:"pre_order",IN_ORDER:"in_order",POST_ORDER:"post_order",REVERSE_ORDER:"reverse_order"}}),e=function(){function a(a,b,c){var d=a.__root;if(null===d||void 0===d)a.__root=f(b);else{for(var g,h=d,i=[],k=[],l=0;;){if(g=i[l]=-1===c(b,h.data)?"left":"right",k[l++]=h,!h[g]){h[g]=f(b);break}h=h[g]}if(!h[g])return null;for(;--l>=0&&(k[l].balance+="right"===i[l]?-1:1,0!==k[l].balance);)if(e(k[l].balance)>1){k[l]=j(k[l],i[l]),0!==l?k[l-1][i[l-1]]=k[l]:a.__root=k[0];break}}}function b(a,b,c){var d=a.__root;if(null!==d&&void 0!==d){for(var f,g,h=d,i=0,j=[],l=[],m={done:!1};;){if(!h)return;if(0===(g=c(b,h.data)))break;f=l[i]=-1===g?"left":"right",j[i++]=h,h=h[f]}var n=h.left,o=h.right;if(n&&o){var p=n;for(l[i]="left",j[i++]=h;p.right;)l[i]="right",j[i++]=p,p=p.right;h.data=p.data,j[i-1][j[i-1]===h?"left":"right"]=p.left}else f=n?"left":"right",0!==i?j[i-1][l[i-1]]=h[f]:a.__root=h[f];for(;--i>=0&&!m.done&&(j[i].balance+="left"===l[i]?-1:1,1!==e(j[i].balance));)e(j[i].balance)>1&&(j[i]=k(j[i],l[i],m),0!==i?j[i-1][l[i-1]]=j[i]:a.__root=j[0])}}var e=Math.abs,f=function(a){return{data:a,balance:0,left:null,right:null}},g=function(a,b,c){var d=a[c];return a[c]=d[b],d[b]=a,d},h=function(a,b,c){return a[c]=g(a[c],c,b),g(a,b,c)},i=function(a,b,c){var d="left"===b?"right":"left",e=a[b],f=e[d];0===f.balance?a.balance=e.balance=0:f.balance===c?(a.balance=-c,e.balance=0):(a.balance=0,e.balance=c),f.balance=0},j=function(a,b){var c="left"===b?"right":"left",d=a[b],e="right"===b?-1:1;return d.balance===e?(a.balance=d.balance=0,a=g(a,c,b)):(i(a,b,e),a=h(a,c,b)),a},k=function(a,b,c){var d="left"===b?"right":"left",e=a[d],f="right"===b?-1:1;return e.balance===-f?(a.balance=e.balance=0,a=g(a,b,d)):e.balance===f?(i(a,d,-f),a=h(a,b,d)):(a.balance=-f,e.balance=f,a=g(a,b,d),c.done=!0),a};return d.extend({instance:{insert:function(b){a(this,b,this.compare)},remove:function(a){b(this,a,this.compare)},__printNode:function(a,b){var d=[];a?(this.__printNode(a.right,b+1),d.push(c(" ",b)),d.push(a.data+":"+a.balance+"\n"),console.log(d.join("")),this.__printNode(a.left,b+1)):(d.push(c(" ",b)),d.push("~"),console.log(d.join("")))}}})}(),f=function(){function a(a,b){return{data:a,level:b,left:g,right:g}}function b(a){if(0!==a.level&&a.left.level===a.level){var b=a.left;a.left=b.right,b.right=a,a=b}return a}function e(a){if(0!==a.level&&a.right.right.level===a.level){var b=a.right;a.right=b.left,b.left=a,a=b,a.level++}return a}function f(c,d,h){if(c===g)c=a(d,1);else{var i=-1===h(d,c.data)?"left":"right";c[i]=f(c[i],d,h),c=b(c),c=e(c)}return c}var g={level:0,data:null},h=function(a,c,d){var f,i;if(a!==g){var j=d(c,a.data);if(0===j)if(f=a.left,i=a.right,f!==g&&i!==g){for(var k=f;k.right!==g;)k=k.right;a.data=k.data,a.left=h(f,k.data,d)}else a=a[f===g?"right":"left"];else{var l=-1===j?"left":"right";a[l]=h(a[l],c,d)}}if(a!==g){var m=a.level,n=a.left.level,o=a.right.level;(m-1>n||m-1>o)&&(o>--a.level&&(a.right.level=a.level),a=b(a),a=e(a))}return a};return d.extend({instance:{isEmpty:function(){return this.__root===g||this._super(arguments)},insert:function(a){this.__root||(this.__root=g),this.__root=f(this.__root,a,this.compare)},remove:function(a){this.__root=h(this.__root,a,this.compare)},traverseWithCondition:function(a){var b=!0;return a!==g?this._super(arguments):b},traverse:function(a){a!==g&&this._super(arguments)},contains:function(){return this.__root!==g?this._super(arguments):!1},__printNode:function(a,b){var d=[];a&&a.data?(this.__printNode(a.right,b+1),d.push(c(" ",b)),d.push(a.data+":"+a.level+"\n"),console.log(d.join("")),this.__printNode(a.left,b+1)):(d.push(c(" ",b)),d.push("~"),console.log(d.join("")))}}})}(),g=d.extend({instance:{insert:function(a){if(!this.__root)return this.__root={data:a,parent:null,left:null,right:null},this.__root;for(var b=this.compare,c=this.__root;null!==c;){var d=b(a,c.data);if(!d)return;var e=-1===d?"left":"right",f=c[e];if(!f)return c[e]={data:a,parent:c,left:null,right:null};c=f}},remove:function(a){if(null!==this.__root){for(var b,c={right:this.__root},d=c,e=null,f="right";null!==d[f];){b=d,d=d[f];var g=this.compare(a,d.data);g||(e=d),f=-1===g?"left":"right"}null!==e&&(e.data=d.data,b[b.right===d?"right":"left"]=d[null===d.left?"right":"left"]),this.__root=c.right}}}}),h=function(){var a="RED",b="BLACK",e=function(a){return null!==a&&a.red},f=function(a){return{data:a,red:!0,left:null,right:null}},g=function(a,b,c){if(!a)return f(b);var d=c(b,a.data);if(d){var j=-1===d?"left":"right",k="left"===j?"right":"left";a[j]=g(a[j],b,c);var l=a[j];if(e(l)){var m=a[k];e(m)?(a.red=!0,l.red=!1,m.red=!1):e(l[j])?a=h(a,k):e(l[k])&&(a=i(a,k))}}return a},h=function(a,b){var c="left"===b?"right":"left",d=a[c];return a[c]=d[b],d[b]=a,a.red=!0,d.red=!1,d},i=function(a,b){var c="left"===b?"right":"left";return a[c]=h(a[c],c),h(a,b)},j=function(a,b,c,d){if(a){var f;if(0===d(b,a.data)){if(!a.left||!a.right){var g=a[a.left?"left":"right"];return e(a)?c.done=!0:e(g)&&(g.red=!1,c.done=!0),g}for(var h,i=a.right;null!==i.left;)h=i,i=i.left;h&&(h.left=null),a.data=i.data,b=i.data}f=-1===d(b,a.data)?"left":"right",a[f]=j(a[f],b,c,d),c.done||(a=k(a,f,c))}else c.done=!0;return a},k=function(a,b,c){var d="left"===b?"right":"left",f=a,g=f[d];if(e(g)&&(a=h(a,b),g=f[d]),null!==g)if(e(g.left)||e(g.right)){var j=f.red,k=a===f;f=(e(g[d])?h:i)(f,b),f.red=j,f.left.red=f.right.red=0,k?a=f:a[b]=f,c.done=!0}else e(f)&&(c.done=!0),f.red=0,g.red=1;return a};return d.extend({instance:{insert:function(a){this.__root=g(this.__root,a,this.compare),this.__root.red=!1},remove:function(a){var b={done:!1},c=j(this.__root,a,b,this.compare);return null!==c&&(c.red=0),this.__root=c,a},__printNode:function(d,e){var f=[];d?(this.__printNode(d.right,e+1),f.push(c(" ",e)),f.push((d.red?a:b)+":"+d.data+"\n"),console.log(f.join("")),this.__printNode(d.left,e+1)):(f.push(c(" ",e)),f.push("~"),console.log(f.join("")))}}})}();return{Tree:d,AVLTree:e,AnderssonTree:f,BinaryTree:g,RedBlackTree:h,IN_ORDER:d.IN_ORDER,PRE_ORDER:d.PRE_ORDER,POST_ORDER:d.POST_ORDER,REVERSE_ORDER:d.REVERSE_ORDER}}"undefined"!=typeof c?"undefined"!=typeof b&&b.exports&&(b.exports=d(a("extended")().register("declare",a("declare.js")).register(a("is-extended")).register(a("array-extended")).register(a("string-extended")))):"function"==typeof define?define(["extended","declare.js","is-extended","array-extended","string-extended"],function(a,b,c,e,f){return d(a().register("declare",b).register(c).register(e).register(f))}):this.leafy=d(this.extended().register("declare",this.declare).register(this.isExtended).register(this.arrayExtended).register(this.stringExtended))}.call(this)},{"array-extended":49,"declare.js":52,extended:53,"is-extended":70,"string-extended":74}],72:[function(a,b,c){!function(){"use strict";function d(a,b,c){function d(a,b){var c,d;for(c in b)t.call(b,c)&&(d=b[c],c in a&&a[c]===d||(a[c]=d));return a}function e(a,b){var c,d,f;for(c in b)t.call(b,c)&&(d=b[c],f=a[c],p(f,d)||(a[c]=r(f)&&r(d)?e(f,d):r(d)?e({},d):d));return a}function f(a){a||(a={});for(var b=1,c=arguments.length;c>b;b++)d(a,arguments[b]);return a}function g(a){a||(a={});for(var b=1,c=arguments.length;c>b;b++)e(a,arguments[b]);return a}function h(a,b){var c=a.prototype||a;return f(c,b),a}function i(a,b,c){if(!r(a)||!u(b))throw new TypeError;for(var d,e=l(a),f=0,g=e.length;g>f;++f)d=e[f],b.call(c||a,a[d],d,a);return a}function j(a,b,c){if(!r(a)||!u(b))throw new TypeError;for(var d,e,f=l(a),g={},h=0,i=f.length;i>h;++h)d=f[h],e=a[d],b.call(c||a,e,d,a)&&(g[d]=e);return g}function k(a){if(!r(a))throw new TypeError;for(var b=l(a),c=[],d=0,e=b.length;e>d;++d)c.push(a[b[d]]);return c}function l(a){if(!r(a))throw new TypeError;var b=[];for(var c in a)t.call(a,c)&&b.push(c);return b}function m(a){if(!r(a))throw new TypeError;for(var b,c=l(a),d={},e=0,f=c.length;f>e;++e)b=c[e],d[a[b]]=b;return d}function n(a){if(!r(a))throw new TypeError;for(var b,c=l(a),d=[],e=0,f=c.length;f>e;++e)b=c[e],d.push([b,a[b]]);return d}function o(a,b){if(!r(a))throw new TypeError;q(b)&&(b=[b]);for(var c,d=s(l(a),b),e={},f=0,g=d.length;g>f;++f)c=d[f],e[c]=a[c];return e}var p=b.deepEqual,q=b.isString,r=b.isHash,s=c.difference,t=Object.prototype.hasOwnProperty,u=b.isFunction,v={forEach:i,filter:j,invert:m,values:k,toArray:n,keys:l,omit:o},w={extend:h,merge:f,deepMerge:g,omit:o},x=a.define(b.isObject,w).define(r,v).define(b.isFunction,{extend:h}).expose({hash:v}).expose(w),y=x.extend;return x.extend=function(){return 1===arguments.length?y.extend.apply(x,arguments):(h.apply(null,arguments),void 0)},x}"undefined"!=typeof c?"undefined"!=typeof b&&b.exports&&(b.exports=d(a("extended"),a("is-extended"),a("array-extended"))):"function"==typeof define&&define.amd?define(["extended","is-extended","array-extended"],function(a,b,c){return d(a,b,c)}):this.objectExtended=d(this.extended,this.isExtended,this.arrayExtended)}.call(this)},{"array-extended":49,extended:53,"is-extended":70}],73:[function(a,b,c){var d=a("__browserify_process");!function(){"use strict";function e(a,b,c,e,f,g){function h(a,b){return function(){try{l(a.apply(null,arguments)).addCallback(b).addErrback(b)}catch(c){b.errback(c)}}}function i(a,b,c){var d=(new G).callback();return v(a,function(a){d=d.then(c?a:B(null,a)),c||(d=d.then(function(a){return b.push(a),b}))}),d}function j(a){return!w(a)&&y(a.then)}function k(a){var b=new G;return a.then(A(b,"callback"),A(b,"errback")),b.promise()}function l(a){var b;return a=C(arguments),a.length?1===a.length?(a=a.pop(),j(a)?a.addCallback&&a.addErrback?(b=new G,a.addCallback(b.callback),a.addErrback(b.errback)):b=k(a):b=x(a)&&c.every(a,j)?new H(a,!0).promise():(new G).callback(a)):b=new H(c.map(a,function(a){return l(a)}),!0).promise():b=(new G).callback(a).promise(),b}function m(a,b){return function(){var c=new G,d=C(arguments);return d.push(c.resolve),a.apply(b||this,d),c.promise()}}function n(a){if(x(a))return i(a,[],!1);throw new Error("When calling promise.serial the first argument must be an array")}function o(a){if(x(a))return i(a,[],!0);throw new Error("When calling promise.serial the first argument must be an array")}function p(a,b){a=C(arguments);var c=!1;b=a.pop();var d=l(a);return function(){return c?l(b.apply(this,arguments)):(a=arguments,d.then(A(this,function(){return c=!0,b.apply(this,a)})))}}function q(){return new G}function r(a){return new H(a,!0).promise()}function s(a){return q().errback(a)}function t(a){return q().callback(a)}var u,v=c.forEach,w=e.isUndefinedOrNull,x=e.isArray,y=e.isFunction,z=e.isBoolean,A=f.bind,B=f.bindIgnore,C=g.argsToArray;if("function"==typeof setImmediate)u="undefined"!=typeof window?setImmediate.bind(window):setImmediate;else if("undefined"!=typeof d)u=function(a){d.nextTick(a)};else if("undefined"!=typeof MessageChannel){var D=new MessageChannel,E={},F=E;D.port1.onmessage=function(){E=E.next; +var a=E.task;delete E.task,a()},u=function(a){F=F.next={task:a},D.port2.postMessage(0)}}else u=function(a){setTimeout(a,0)};var G=a({instance:{__fired:!1,__results:null,__error:null,__errorCbs:null,__cbs:null,constructor:function(){this.__errorCbs=[],this.__cbs=[],f.bindAll(this,["callback","errback","resolve","classic","__resolve","addCallback","addErrback"])},__resolve:function(){if(!this.__fired){this.__fired=!0;var a,b=this.__error?this.__errorCbs:this.__cbs,c=b.length,d=this.__error||this.__results;for(a=0;c>a;a++)this.__callNextTick(b[a],d)}},__callNextTick:function(a,b){u(function(){a.apply(this,b)})},addCallback:function(a){return a&&(j(a)&&a.callback&&(a=a.callback),this.__fired&&this.__results?this.__callNextTick(a,this.__results):this.__cbs.push(a)),this},addErrback:function(a){return a&&(j(a)&&a.errback&&(a=a.errback),this.__fired&&this.__error?this.__callNextTick(a,this.__error):this.__errorCbs.push(a)),this},callback:function(){return this.__fired||(this.__results=arguments,this.__resolve()),this.promise()},errback:function(){return this.__fired||(this.__error=arguments,this.__resolve()),this.promise()},resolve:function(a){return a?this.errback(a):this.callback.apply(this,C(arguments,1)),this},classic:function(a){return"function"==typeof a&&(this.addErrback(function(b){a(b)}),this.addCallback(function(){a.apply(this,[null].concat(C(arguments)))})),this},then:function(a,b){var c=new G,d=c;return y(b)&&(d=h(b,c)),this.addErrback(d),y(a)?this.addCallback(h(a,c)):this.addCallback(c),c.promise()},both:function(a){return this.then(a,a)},promise:function(){var a={then:A(this,"then"),both:A(this,"both"),promise:function(){return a}};return v(["addCallback","addErrback","classic"],function(b){a[b]=A(this,function(){return this[b].apply(this,arguments),a})},this),a}}}),H=G.extend({instance:{__results:null,__errors:null,__promiseLength:0,__defLength:0,__firedLength:0,normalizeResults:!1,constructor:function(a,b){this.__errors=[],this.__results=[],this.normalizeResults=z(b)?b:!1,this._super(arguments),a&&a.length?(this.__defLength=a.length,v(a,this.__addPromise,this)):this.__resolve()},__addPromise:function(a,b){a.then(A(this,function(){var a=C(arguments);a.unshift(b),this.callback.apply(this,a)}),A(this,function(){var a=C(arguments);a.unshift(b),this.errback.apply(this,a)}))},__resolve:function(){if(!this.__fired){this.__fired=!0;var a,b=this.__errors.length?this.__errorCbs:this.__cbs,c=b.length,d=this.__errors.length?this.__errors:this.__results;for(a=0;c>a;a++)this.__callNextTick(b[a],d)}},__callNextTick:function(a,b){u(function(){a.apply(null,[b])})},addCallback:function(a){return a&&(j(a)&&a.callback&&(a=A(a,"callback")),this.__fired&&!this.__errors.length?this.__callNextTick(a,this.__results):this.__cbs.push(a)),this},addErrback:function(a){return a&&(j(a)&&a.errback&&(a=A(a,"errback")),this.__fired&&this.__errors.length?this.__callNextTick(a,this.__errors):this.__errorCbs.push(a)),this},callback:function(a){if(this.__fired)throw new Error("Already fired!");var b=C(arguments);return this.normalizeResults&&(b=b.slice(1),b=1===b.length?b.pop():b),this.__results[a]=b,this.__firedLength++,this.__firedLength===this.__defLength&&this.__resolve(),this.promise()},errback:function(a){if(this.__fired)throw new Error("Already fired!");var b=C(arguments);return this.normalizeResults&&(b=b.slice(1),b=1===b.length?b.pop():b),this.__errors[a]=b,this.__firedLength++,this.__firedLength===this.__defLength&&this.__resolve(),this.promise()}}});return b.define({isPromiseLike:j}).expose({isPromiseLike:j,when:l,wrap:m,wait:p,serial:n,chain:o,Promise:G,PromiseList:H,promise:q,defer:q,deferredList:r,reject:s,resolve:t})}"undefined"!=typeof c?"undefined"!=typeof b&&b.exports&&(b.exports=e(a("declare.js"),a("extended"),a("array-extended"),a("is-extended"),a("function-extended"),a("arguments-extended"))):"function"==typeof define&&define.amd?define(["declare","extended","array-extended","is-extended","function-extended","arguments-extended"],function(a,b,c,d,f,g){return e(a,b,c,d,f,g)}):this.promiseExtended=e(this.declare,this.extended,this.arrayExtended,this.isExtended,this.functionExtended,this.argumentsExtended)}.call(this)},{__browserify_process:68,"arguments-extended":48,"array-extended":49,"declare.js":52,extended:53,"function-extended":56,"is-extended":70}],74:[function(a,b,c){!function(){"use strict";function d(a,b,c,d){function e(a,b){var c=a;if(x.test(b)){var d=b.match(x),e=d[1],f=d[3],g=d[4];g&&(g=parseInt(g,10),c=c.length0?"+":"")+d),k&&(k=parseInt(k,10),d=d.lengthe;)d?a+=c:a=c+a,e++;return a}function i(a,c,d){var e=a;if(b.isString(e)){if(a.length>c)if(d){var f=a.length;e=a.substring(f-c,f)}else e=a.substring(0,c)}else e=i(""+e,c);return e}function j(a,d){if(d instanceof Array){var h=0,i=d.length;return a.replace(v,function(a,b,j){var k,l;if(!(i>h))return a;if(k=d[h++],"%s"===a||"%d"===a||"%D"===a)l=k+"";else if("%Z"===a)l=k.toUTCString();else if("%j"===a)try{l=s(k)}catch(m){throw new Error("stringExtended.format : Unable to parse json from ",k)}else switch(b=b.replace(/^\[|\]$/g,""),j){case"s":l=e(k,b);break;case"d":l=f(k,b);break;case"j":l=g(k,b);break;case"D":l=c.format(k,b);break;case"Z":l=c.format(k,b,!0)}return l})}if(t(d))return a.replace(w,function(a,h,i){if(i=d[i],!b.isUndefined(i)){if(!h)return""+i;if(b.isString(i))return e(i,h);if(b.isNumber(i))return f(i,h);if(b.isDate(i))return c.format(i,h);if(b.isObject(i))return g(i,h)}return a});var k=u.call(arguments).slice(1);return j(a,k)}function k(a,b){var c=[];return a&&(a.indexOf(b)>0?c=a.replace(/\s+/g,"").split(b):c.push(a)),c}function l(a,b){var c=[];if(b)for(var d=0;b>d;d++)c.push(a);return c.join("")}function m(a,c){var d,e,f;if(c)if(b.isArray(a))for(d=[],e=0,f=a.length;f>e;e++)d.push(m(a[e],c));else if(c instanceof Array)for(d=a,e=0,f=c.length;f>e;e++)d=m(d,c[e]);else c in z&&(d="["+z[c]+"m"+a+"");return d}function n(a,b){return a.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g,function(a){return b&&-1!==d.indexOf(b,a)?a:"\\"+a})}function o(a){return a.replace(/^\s*|\s*$/g,"")}function p(a){return a.replace(/^\s*/,"")}function q(a){return a.replace(/\s*$/,"")}function r(a){return 0===a.length}var s;"undefined"==typeof JSON?function(){function a(a){return 10>a?"0"+a:a}function c(c){return b.isDate(c)?isFinite(c.valueOf())?c.getUTCFullYear()+"-"+a(c.getUTCMonth()+1)+"-"+a(c.getUTCDate())+"T"+a(c.getUTCHours())+":"+a(c.getUTCMinutes())+":"+a(c.getUTCSeconds())+"Z":null:i(c)?c.valueOf():c}function d(a){return j.lastIndex=0,j.test(a)?'"'+a.replace(j,function(a){var b=k[a];return"string"==typeof b?b:"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+a+'"'}function e(a,b){var i,j,k,l,m,n=f,o=b[a];switch(o&&(o=c(o)),"function"==typeof h&&(o=h.call(b,a,o)),typeof o){case"string":return d(o);case"number":return isFinite(o)?String(o):"null";case"boolean":case"null":return String(o);case"object":if(!o)return"null";if(f+=g,m=[],"[object Array]"===Object.prototype.toString.apply(o)){for(l=o.length,i=0;l>i;i+=1)m[i]=e(i,o)||"null";return k=0===m.length?"[]":f?"[\n"+f+m.join(",\n"+f)+"\n"+n+"]":"["+m.join(",")+"]",f=n,k}if(h&&"object"==typeof h)for(l=h.length,i=0;l>i;i+=1)"string"==typeof h[i]&&(j=h[i],k=e(j,o),k&&m.push(d(j)+(f?": ":":")+k));else for(j in o)Object.prototype.hasOwnProperty.call(o,j)&&(k=e(j,o),k&&m.push(d(j)+(f?": ":":")+k));return k=0===m.length?"{}":f?"{\n"+f+m.join(",\n"+f)+"\n"+n+"}":"{"+m.join(",")+"}",f=n,k}}var f,g,h,i=b.tester().isString().isNumber().isBoolean().tester(),j=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,k={"\b":"\\b"," ":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"};s=function(a,b,c){var d;if(f="",g="","number"==typeof c)for(d=0;c>d;d+=1)g+=" ";else"string"==typeof c&&(g=c);if(h=b,b&&"function"!=typeof b&&("object"!=typeof b||"number"!=typeof b.length))throw new Error("JSON.stringify");return e("",{"":a})}}():s=JSON.stringify;var t=b.isHash,u=Array.prototype.slice,v=/%((?:-?\+?.?\d*)?|(?:\[[^\[|\]]*\]))?([sjdDZ])/g,w=/\{(?:\[([^\[|\]]*)\])?(\w+)\}/g,x=/(-?)(\+?)([A-Z|a-z|\W]?)([1-9][0-9]*)?$/,y=/([1-9][0-9]*)$/g,z={bold:1,bright:1,italic:3,underline:4,blink:5,inverse:7,crossedOut:9,red:31,green:32,yellow:33,blue:34,magenta:35,cyan:36,white:37,redBackground:41,greenBackground:42,yellowBackground:43,blueBackground:44,magentaBackground:45,cyanBackground:46,whiteBackground:47,encircled:52,overlined:53,grey:90,black:90},A={SMILEY:"☺",SOLID_SMILEY:"☻",HEART:"♥",DIAMOND:"♦",CLOVE:"♣",SPADE:"♠",DOT:"•",SQUARE_CIRCLE:"◘",CIRCLE:"○",FILLED_SQUARE_CIRCLE:"◙",MALE:"♂",FEMALE:"♀",EIGHT_NOTE:"♪",DOUBLE_EIGHTH_NOTE:"♫",SUN:"☼",PLAY:"►",REWIND:"◄",UP_DOWN:"↕",PILCROW:"¶",SECTION:"§",THICK_MINUS:"▬",SMALL_UP_DOWN:"↨",UP_ARROW:"↑",DOWN_ARROW:"↓",RIGHT_ARROW:"→",LEFT_ARROW:"←",RIGHT_ANGLE:"∟",LEFT_RIGHT_ARROW:"↔",TRIANGLE:"▲",DOWN_TRIANGLE:"▼",HOUSE:"⌂",C_CEDILLA:"Ç",U_UMLAUT:"ü",E_ACCENT:"é",A_LOWER_CIRCUMFLEX:"â",A_LOWER_UMLAUT:"ä",A_LOWER_GRAVE_ACCENT:"à",A_LOWER_CIRCLE_OVER:"å",C_LOWER_CIRCUMFLEX:"ç",E_LOWER_CIRCUMFLEX:"ê",E_LOWER_UMLAUT:"ë",E_LOWER_GRAVE_ACCENT:"è",I_LOWER_UMLAUT:"ï",I_LOWER_CIRCUMFLEX:"î",I_LOWER_GRAVE_ACCENT:"ì",A_UPPER_UMLAUT:"Ä",A_UPPER_CIRCLE:"Å",E_UPPER_ACCENT:"É",A_E_LOWER:"æ",A_E_UPPER:"Æ",O_LOWER_CIRCUMFLEX:"ô",O_LOWER_UMLAUT:"ö",O_LOWER_GRAVE_ACCENT:"ò",U_LOWER_CIRCUMFLEX:"û",U_LOWER_GRAVE_ACCENT:"ù",Y_LOWER_UMLAUT:"ÿ",O_UPPER_UMLAUT:"Ö",U_UPPER_UMLAUT:"Ü",CENTS:"¢",POUND:"£",YEN:"¥",CURRENCY:"¤",PTS:"₧",FUNCTION:"ƒ",A_LOWER_ACCENT:"á",I_LOWER_ACCENT:"í",O_LOWER_ACCENT:"ó",U_LOWER_ACCENT:"ú",N_LOWER_TILDE:"ñ",N_UPPER_TILDE:"Ñ",A_SUPER:"ª",O_SUPER:"º",UPSIDEDOWN_QUESTION:"¿",SIDEWAYS_L:"⌐",NEGATION:"¬",ONE_HALF:"½",ONE_FOURTH:"¼",UPSIDEDOWN_EXCLAMATION:"¡",DOUBLE_LEFT:"«",DOUBLE_RIGHT:"»",LIGHT_SHADED_BOX:"░",MEDIUM_SHADED_BOX:"▒",DARK_SHADED_BOX:"▓",VERTICAL_LINE:"│",MAZE__SINGLE_RIGHT_T:"┤",MAZE_SINGLE_RIGHT_TOP:"┐",MAZE_SINGLE_RIGHT_BOTTOM_SMALL:"┘",MAZE_SINGLE_LEFT_TOP_SMALL:"┌",MAZE_SINGLE_LEFT_BOTTOM_SMALL:"└",MAZE_SINGLE_LEFT_T:"├",MAZE_SINGLE_BOTTOM_T:"┴",MAZE_SINGLE_TOP_T:"┬",MAZE_SINGLE_CENTER:"┼",MAZE_SINGLE_HORIZONTAL_LINE:"─",MAZE_SINGLE_RIGHT_DOUBLECENTER_T:"╡",MAZE_SINGLE_RIGHT_DOUBLE_BL:"╛",MAZE_SINGLE_RIGHT_DOUBLE_T:"╢",MAZE_SINGLE_RIGHT_DOUBLEBOTTOM_TOP:"╖",MAZE_SINGLE_RIGHT_DOUBLELEFT_TOP:"╕",MAZE_SINGLE_LEFT_DOUBLE_T:"╞",MAZE_SINGLE_BOTTOM_DOUBLE_T:"╧",MAZE_SINGLE_TOP_DOUBLE_T:"╤",MAZE_SINGLE_TOP_DOUBLECENTER_T:"╥",MAZE_SINGLE_BOTTOM_DOUBLECENTER_T:"╨",MAZE_SINGLE_LEFT_DOUBLERIGHT_BOTTOM:"╘",MAZE_SINGLE_LEFT_DOUBLERIGHT_TOP:"╒",MAZE_SINGLE_LEFT_DOUBLEBOTTOM_TOP:"╓",MAZE_SINGLE_LEFT_DOUBLETOP_BOTTOM:"╙",MAZE_SINGLE_LEFT_TOP:"Γ",MAZE_SINGLE_RIGHT_BOTTOM:"╜",MAZE_SINGLE_LEFT_CENTER:"╟",MAZE_SINGLE_DOUBLECENTER_CENTER:"╫",MAZE_SINGLE_DOUBLECROSS_CENTER:"╪",MAZE_DOUBLE_LEFT_CENTER:"╣",MAZE_DOUBLE_VERTICAL:"║",MAZE_DOUBLE_RIGHT_TOP:"╗",MAZE_DOUBLE_RIGHT_BOTTOM:"╝",MAZE_DOUBLE_LEFT_BOTTOM:"╚",MAZE_DOUBLE_LEFT_TOP:"╔",MAZE_DOUBLE_BOTTOM_T:"╩",MAZE_DOUBLE_TOP_T:"╦",MAZE_DOUBLE_LEFT_T:"╠",MAZE_DOUBLE_HORIZONTAL:"═",MAZE_DOUBLE_CROSS:"╬",SOLID_RECTANGLE:"█",THICK_LEFT_VERTICAL:"▌",THICK_RIGHT_VERTICAL:"▐",SOLID_SMALL_RECTANGLE_BOTTOM:"▄",SOLID_SMALL_RECTANGLE_TOP:"▀",PHI_UPPER:"Φ",INFINITY:"∞",INTERSECTION:"∩",DEFINITION:"≡",PLUS_MINUS:"±",GT_EQ:"≥",LT_EQ:"≤",THEREFORE:"⌠",SINCE:"∵",DOESNOT_EXIST:"∄",EXISTS:"∃",FOR_ALL:"∀",EXCLUSIVE_OR:"⊕",BECAUSE:"⌡",DIVIDE:"÷",APPROX:"≈",DEGREE:"°",BOLD_DOT:"∙",DOT_SMALL:"·",CHECK:"√",ITALIC_X:"✗",SUPER_N:"ⁿ",SQUARED:"²",CUBED:"³",SOLID_BOX:"■",PERMILE:"‰",REGISTERED_TM:"®",COPYRIGHT:"©",TRADEMARK:"™",BETA:"β",GAMMA:"γ",ZETA:"ζ",ETA:"η",IOTA:"ι",KAPPA:"κ",LAMBDA:"λ",NU:"ν",XI:"ξ",OMICRON:"ο",RHO:"ρ",UPSILON:"υ",CHI_LOWER:"φ",CHI_UPPER:"χ",PSI:"ψ",ALPHA:"α",ESZETT:"ß",PI:"π",SIGMA_UPPER:"Σ",SIGMA_LOWER:"σ",MU:"µ",TAU:"τ",THETA:"Θ",OMEGA:"Ω",DELTA:"δ",PHI_LOWER:"φ",EPSILON:"ε"},B={toArray:k,pad:h,truncate:i,multiply:l,format:j,style:m,escape:n,trim:o,trimLeft:p,trimRight:q,isEmpty:r};return a.define(b.isString,B).define(b.isArray,{style:m}).expose(B).expose({characters:A})}"undefined"!=typeof c?"undefined"!=typeof b&&b.exports&&(b.exports=d(a("extended"),a("is-extended"),a("date-extended"),a("array-extended"))):"function"==typeof define&&define.amd?define(["extended","is-extended","date-extended","array-extended"],function(a,b,c,e){return d(a,b,c,e)}):this.stringExtended=d(this.extended,this.isExtended,this.dateExtended,this.arrayExtended)}.call(this)},{"array-extended":49,"date-extended":50,extended:53,"is-extended":70}]},{},[1]); \ No newline at end of file diff --git a/examples/browser/assets/conways.css b/examples/browser/assets/conways.css index b4eced4..5a08222 100644 --- a/examples/browser/assets/conways.css +++ b/examples/browser/assets/conways.css @@ -16,45 +16,91 @@ body { height: 100%; } -#fibonacci div.inline { +.fibonacci div.inline { height: 100%; margin: 10px; } -#fibonacci #results_container { +.fibonacci .results_container { word-wrap: break-word; max-width: 100%; line-height: 50px; } -#diagnose { - width: 500px; - padding: 10px; - border: 1px solid rgba(0, 0, 0, 0.1); - -webkit-box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.1); - -moz-box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.1); - box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.1); +.diagnose { + width: 100%; } -#manners { - width: 50%; +.diagnose .diagnose-container{ + width: 49%; + vertical-align: top; padding: 10px; - border: 1px solid rgba(0, 0, 0, 0.1); - -webkit-box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.1); - -moz-box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.1); - box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.1); +} +.waltz-db, +.manners { + width: 100%; } -#manners #results_container { +.waltz-db .editor-container, +.manners .editor-container, +.diagnose .editor-container, +.send-more-money .editor-container { + width: 49%; + height: 100%; + display: inline-block; +} + +.waltz-db .results_container, +.manners .results_container { + width: 49%; + vertical-align: top; + display: inline-block; + height: 100%; overflow: auto; - height: 400px; - width: 95%; background: #dfdfdf; color: #09C; font-family: Tahoma, Geneva, sans-serif; + padding-left: 10px; +} + +.editor-container { + width: 100%; + height: 400px; + position: relative; + border: 1px solid lightgray; +} + +.editor-container .editor { + width: 100%; + height: 100%; + position: relative; +} + +.send-more-money { + width: 100%; +} + +.send-more-money .equation-container { + vertical-align: top; + width: 49%; +} + +.send-more-money .equation { + font-size: 6em; + text-align: right; + width: 400px; +} + +.send-more-money .equation > div > span { + width: 30px; + display: inline-block; + height: 50px; padding: 10px; - border-radius: 10px; +} + +.send-more-money .equation > div:last-child { + border-top: solid black 1px; } .container > header { @@ -108,6 +154,12 @@ input[type="submit"], input[type="button"] { margin: 10px; } +input[type="submit"]:disabled, +input[type="button"]:disabled { + background-color: lightgray; + cursor: not-allowed; +} + #grid { overflow: hidden; @@ -136,6 +188,7 @@ input[type="submit"], input[type="button"] { box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.2); position: absolute; bottom: 5px; + right: 5px; } .row { @@ -152,6 +205,10 @@ input[type="submit"], input[type="button"] { box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.2); } +.sudoku { + width: 100%; +} + .sudoku .col { width: 50px; height: 50px; @@ -164,11 +221,20 @@ input[type="submit"], input[type="button"] { background-color: rgba(255, 0, 0, 0.43); } -.sudoku #grid{ +.sudoku #grid { width: 465px; height: 470px; } +.sudoku .grid-container { + vertical-align: top; + width: 49%; +} + +.sudoku .editor-container { + width: 49%; +} + .col.live { background-color: black; } diff --git a/examples/browser/diagnose.html b/examples/browser/diagnose.html index 4d70368..699138c 100644 --- a/examples/browser/diagnose.html +++ b/examples/browser/diagnose.html @@ -11,56 +11,58 @@ -

    -

    Diagnose Me

    - - -
    -
    - - - - - -
    - - -
    -
    - - -
    -
    - - -
    -
    - - -
    - -
    -
    -

    Diagnoses

    - -
    +
    +
    +

    Diagnose Me

    +
    + +
    +
    +
    + +
    +
    +
    + + + + + +
    + + +
    +
    + + +
    +
    + + +
    +
    + + +
    + +
    +
    +

    Diagnoses

    + +
    +
    -
    -
    -
    - - - + + - diff --git a/examples/browser/fibonacci.html b/examples/browser/fibonacci.html index d53f1ec..76b25bd 100644 --- a/examples/browser/fibonacci.html +++ b/examples/browser/fibonacci.html @@ -9,7 +9,7 @@ -
    +

    Fibonacci

    @@ -20,7 +20,7 @@

    Fibonacci

    =
    -
    +
    @@ -90,7 +90,7 @@

    Fibonacci

    } - var resultsContainer = $("#results_container"), valInput = $("#val"); + var resultsContainer = $(".results_container"), valInput = $("#val"); $("#fibonacci_form").on('submit', function () { var num = parseInt(valInput.val(), 10); resultsContainer.text("Calculating..."); diff --git a/examples/browser/manners.html b/examples/browser/manners.html index 9c36d5b..de6a8e1 100644 --- a/examples/browser/manners.html +++ b/examples/browser/manners.html @@ -4,43 +4,42 @@ - Manners Benchmark -
    -

    Manners Benchmark

    +
    +
    +

    Manners Benchmark

    -
    + + + +
    +
    - - - +
    +
    +
    -
    -
    - - +
    +
    -
    -
    -
    - - + + @@ -52,7 +51,7 @@

    Manners Benchmark

    }).then(function (res) { var session, dataset, - resultsContainer = $("#results_container"), + resultsContainer = $(".results_container"), statsListener = stats(), flowStr = res, flow = nools.compile(res, {name: "manners"}), @@ -83,6 +82,7 @@

    Manners Benchmark

    session .on("pathDone", function (obj) { resultsContainer.append(createSeat(obj.seating)); + resultsContainer.scrollTop(resultsContainer.prop("scrollHeight")); }) .match().then(function () { console.log("done"); @@ -114,30 +114,19 @@

    Manners Benchmark

    return false; }); - $("#editor-dialog").dialog({ - autoOpen: false, - modal: true, - width: window.innerWidth * 0.9, - height: window.innerHeight * 0.9, - open: function () { - (editor = ace.edit("editor").getSession()).setValue(flowStr); - }, - buttons: { - "Save": function () { - $(this).dialog("close"); - nools.deleteFlow("manners"); - stop(); - flow = nools.compile((flowStr = editor.getValue()), {name: "manners"}); - }, - Cancel: function () { - $(this).dialog("close"); - } - } - }); + var height = $(document).height() - $("#manners .header").height() - 100; + $(".editor-container").height(height); + resultsContainer.height(height); + + var editor = ace.edit("editor"); + //editor.setTheme("ace/theme/monokai"); + var editorSession = editor.getSession(); + editorSession.setMode("ace/mode/javascript"); + editorSession.setValue(res); + editor.setReadOnly(true); }); - }) - ; + }); diff --git a/examples/browser/rules/sendMoreMoney.nools b/examples/browser/rules/sendMoreMoney.nools new file mode 100644 index 0000000..c7d5bd1 --- /dev/null +++ b/examples/browser/rules/sendMoreMoney.nools @@ -0,0 +1,16 @@ +rule SendMoreMoney { + when { + s : Number s != 0; + e : Number e != s; + n : Number n != s && n != e; + d : Number d != s && d != e && d != n; + m : Number m != 0 && m != s && m != e && m != n && m != d; + o : Number o != s && o != e && o != n && o != d && o != m; + r : Number r != s && r != e && r != n && r != d && r != m && r != o; + y : Number y != s && y != e && y != n && y != d && y != m && y != o && y != r + && (s*1000 + e*100 + n*10 + d + m*1000 + o*100 + r*10 + e) == (m*10000 + o*1000 + n*100 + e*10 + y); + } + then { + emit("solved", {s : s, e : e, n : n, d : d, m : m, o: o, r : r, y : y}); + } +} \ No newline at end of file diff --git a/examples/browser/sendMoreMoney.html b/examples/browser/sendMoreMoney.html new file mode 100644 index 0000000..fb90c1c --- /dev/null +++ b/examples/browser/sendMoreMoney.html @@ -0,0 +1,106 @@ + + + + + + + + + Send More Money Benchmark + + + + +
    +
    +

    Send More Money

    + Warning: This can take a while! +
    + +
    +
    +
    +
    +
    +
    + + + S + E + N + D +
    +
    + + + + M + O + R + E +
    +
    + + M + O + N + E + Y +
    +
    + +
    +
    + + + + + + + + + diff --git a/examples/browser/src/common.js b/examples/browser/src/common.js index 146ff3f..9ab0d04 100644 --- a/examples/browser/src/common.js +++ b/examples/browser/src/common.js @@ -64,7 +64,7 @@ } setInterval(function () { - runningTimeSpan.text("running Time:" + Math.round(transCum / 1000 / 60) + "min"); + runningTimeSpan.text("running time:" + Math.round(transCum / 1000 / 60) + "min"); firesSpan.text('rules fired: : ' + fires); retractionsSpan.text('facts retracted: ' + retractions); modifiesSpan.text('facts modified: ' + modified); diff --git a/examples/browser/src/sudoku.js b/examples/browser/src/sudoku.js index 31da919..1e4741f 100644 --- a/examples/browser/src/sudoku.js +++ b/examples/browser/src/sudoku.js @@ -6,6 +6,13 @@ var allNine = [1, 2, 3, 4, 5, 6, 7, 8, 9]; + if (typeof console === 'undefined') { + console = { + log: function () { + } + }; + } + var SetOfNine = declare({ instance: { @@ -102,7 +109,7 @@ }, valueAsString: function () { - return this.value === null ? " ": this.value; + return this.value === null ? " " : this.value; }, posAsString: function () { @@ -206,35 +213,39 @@ }, step: function () { - this.session.modify(this.counter, function () { - this.count = 1; - }); - if (!this.stepping) { - this.session.assert(new Stepping()); - } - return this.session.matchUntilHalt(function (err) { - if (err) { - console.log(err); + if (!this.invalid) { + this.session.modify(this.counter, function () { + this.count = 1; + }); + if (!this.stepping) { + this.session.assert(new Stepping()); } - }); + return this.session.matchUntilHalt(function (err) { + if (err) { + console.log(err); + } + }); + } }, solve: function () { - this.session.modify(this.counter, function () { - this.count = Infinity; - }); - if (this.stepping) { - this.session.retract(this.stepping); - } - return this.session.match(function (err) { - if (err) { - console.log(err); + if (!this.invalid) { + this.session.modify(this.counter, function () { + this.count = Infinity; + }); + if (this.stepping) { + this.session.retract(this.stepping); } - }); + return this.session.match(function (err) { + if (err) { + console.log(err); + } + }); + } }, setCellValue: function setCellValue(cell) { - cell.el.text(cell.value ? cell.value: ""); + cell.el.text(cell.value ? cell.value : ""); return cell; }, @@ -296,7 +307,6 @@ if (value) { session.assert(new Setting(iRow, iCol, value)); initial++; - //console.log(initial); } } } @@ -340,11 +350,13 @@ }, setInvalidCellValue: function setCellValue(cell) { + this.invalid = true; cell.el.addClass("error"); return cell; }, validate: function () { + this.invalid = false; this.session.assert("validate"); return this.session.focus("validate") .on("invalid", this.setInvalidCellValue) diff --git a/examples/browser/sudoku.html b/examples/browser/sudoku.html index 81afdba..2729f44 100644 --- a/examples/browser/sudoku.html +++ b/examples/browser/sudoku.html @@ -11,28 +11,32 @@
    -
    -

    Sudoku

    +
    +

    Sudoku

    -
    - + + -
    -
    -
    -
    +
    + +
    +
    +
    + +
    +
    +
    + -
    -
    - - + + @@ -44,7 +48,6 @@

    Sudoku

    - - - + + + @@ -50,10 +49,11 @@

    WaltzDB Benchmark

    }).then(function (res) { var session, dataset, - resultsContainer = $("#results_container"), + resultsContainer = $(".results_container"), statsListener = stats(), flowStr = res, - flow = nools.compile(res, {name: "waltzDb"}); + flow = nools.compile(res, {name: "waltzDb"}) + .conflictResolution(["salience", "factRecency", "activationRecency"]); function stop() { if (session) { @@ -81,7 +81,7 @@

    WaltzDB Benchmark

    session .on("log", function (data) { resultsContainer.append(data + "
    "); - resultsContainer.scrollTop(resultsContainer.scrollHeight); + resultsContainer.scrollTop(resultsContainer.prop("scrollHeight")); }) .match().then(function () { console.profileEnd(); @@ -114,26 +114,16 @@

    WaltzDB Benchmark

    return false; }); - $("#editor-dialog").dialog({ - autoOpen: false, - modal: true, - width: window.innerWidth * 0.9, - height: window.innerHeight * 0.9, - open: function () { - (editor = ace.edit("editor").getSession()).setValue(flowStr); - }, - buttons: { - "Save": function () { - $(this).dialog("close"); - nools.deleteFlow("manners"); - stop(); - flow = nools.compile((flowStr = editor.getValue()), {name: "manners"}); - }, - Cancel: function () { - $(this).dialog("close"); - } - } - }); + var height = $(document).height() - $("#manners .header").height() - 100; + $(".editor-container").height(height); + resultsContainer.height(height); + + var editor = ace.edit("editor"); + //editor.setTheme("ace/theme/monokai"); + var editorSession = editor.getSession(); + editorSession.setMode("ace/mode/javascript"); + editorSession.setValue(res); + editor.setReadOnly(true); }); }); diff --git a/history.md b/history.md index 484c56e..8b9af4e 100644 --- a/history.md +++ b/history.md @@ -1,3 +1,12 @@ +#0.2.2 + +* Performance Upgrades + * Added BetaNode indexing + * Abstracted out JoinNode to extend BetaNode (Prevents the checking of constraints if there are not any constraints to check) + * Refactored BetaNetwork + * Created a new Memory Class to encapusulate left and right memory for BetaNodes +* Added new `exists` logic operator to check for existence of fact (opposite of `not`) + #0.2.1 * Added support for js expression in the `from` node addressing issue [#86](https://github.com/C2FO/nools/issues/86) diff --git a/lib/agenda.js b/lib/agenda.js index 18c857a..1158181 100644 --- a/lib/agenda.js +++ b/lib/agenda.js @@ -38,7 +38,6 @@ var FactHash = declare({ this.memoryValues.push((this.memory[hashCode] = insert)); } } - }); diff --git a/lib/conflict.js b/lib/conflict.js index d5e600c..8e7c36e 100644 --- a/lib/conflict.js +++ b/lib/conflict.js @@ -10,6 +10,7 @@ function bucketCounter(a, b) { function factRecency(a, b) { /*jshint noempty: false*/ + var i = 0; var aMatchRecency = a.match.recency, bMatchRecency = b.match.recency, aLength = aMatchRecency.length - 1, bLength = bMatchRecency.length - 1; @@ -47,7 +48,7 @@ exports.strategy = function (strats) { while (++i < stratsLength && !ret) { ret = strats[i](a, b); } - ret = ret > 0 ? 1: -1; + ret = ret > 0 ? 1 : -1; } return ret; }; diff --git a/lib/constraint.js b/lib/constraint.js index 02bdde0..b3aab84 100644 --- a/lib/constraint.js +++ b/lib/constraint.js @@ -11,13 +11,14 @@ var extd = require("./extended"), var id = 0; var Constraint = declare({ + type: null, + instance: { - constructor: function (type, constraint) { + constructor: function (constraint) { if (!constraintMatcher) { constraintMatcher = require("./constraintMatcher"); } this.id = id++; - this.type = type; this.constraint = constraint; extd.bindAll(this, ["assert"]); }, @@ -25,6 +26,10 @@ var Constraint = declare({ throw new Error("not implemented"); }, + getIndexableProperties: function () { + return []; + }, + equal: function (constraint) { return instanceOf(constraint, this._static) && this.get("alias") === constraint.get("alias") && extd.deepEqual(this.constraint, constraint.constraint); }, @@ -41,8 +46,11 @@ var Constraint = declare({ Constraint.extend({ instance: { + + type: "object", + constructor: function (type) { - this._super(["object", type]); + this._super([type]); }, "assert": function (param) { @@ -55,14 +63,17 @@ Constraint.extend({ } }).as(exports, "ObjectConstraint"); -Constraint.extend({ +var EqualityConstraint = Constraint.extend({ instance: { + + type: "equality", + constructor: function (constraint, options) { - this._super(["equality", constraint]); + this._super([constraint]); options = options || {}; this.pattern = options.pattern; - this._matcher = constraintMatcher.getMatcher(constraint, options.scope || {}); + this._matcher = constraintMatcher.getMatcher(constraint, options, true); }, "assert": function (values) { @@ -71,11 +82,19 @@ Constraint.extend({ } }).as(exports, "EqualityConstraint"); +EqualityConstraint.extend({instance: {type: "inequality"}}).as(exports, "InequalityConstraint"); +EqualityConstraint.extend({instance: {type: "comparison"}}).as(exports, "ComparisonConstraint"); + Constraint.extend({ instance: { + + type: "equality", + constructor: function () { - this._super(["equality", [true]]); + this._super([ + [true] + ]); }, equal: function (constraint) { @@ -89,22 +108,25 @@ Constraint.extend({ } }).as(exports, "TrueConstraint"); -Constraint.extend({ +var ReferenceConstraint = Constraint.extend({ instance: { + + type: "reference", + constructor: function (constraint, options) { this.cache = {}; - this._super(["reference", constraint]); + this._super([constraint]); options = options || {}; this.values = []; this.pattern = options.pattern; this._options = options; - this._matcher = constraintMatcher.getMatcher(constraint, options.scope || {}); + this._matcher = constraintMatcher.getMatcher(constraint, options, false); }, - "assert": function (values) { + "assert": function (fact, fh) { try { - return this._matcher(values); + return this._matcher(fact, fh); } catch (e) { throw new Error("Error with evaluating pattern " + this.pattern + " " + e.message); } @@ -113,7 +135,7 @@ Constraint.extend({ merge: function (that) { var ret = this; - if (that instanceof this._static) { + if (that instanceof ReferenceConstraint) { ret = new this._static([this.constraint, that.constraint, "and"], merge({}, this._options, this._options)); ret._alias = this._alias || that._alias; ret.vars = this.vars.concat(that.vars); @@ -149,10 +171,23 @@ Constraint.extend({ }).as(exports, "ReferenceConstraint"); +ReferenceConstraint.extend({instance: { + type: "reference_equality", + op: "eq", + getIndexableProperties: function () { + return constraintMatcher.getIndexableProperties(this.constraint); + } +}}).as(exports, "ReferenceEqualityConstraint") + .extend({instance: {type: "reference_inequality", op: "neq"}}).as(exports, "ReferenceInequalityConstraint"); + + Constraint.extend({ instance: { + + type: "hash", + constructor: function (hash) { - this._super(["hash", hash]); + this._super([hash]); }, equal: function (constraint) { @@ -176,7 +211,7 @@ Constraint.extend({ instance: { constructor: function (constraints, options) { this.type = "from"; - this.constraints = constraintMatcher.getSourceMatcher(constraints, (options || {}).scope || {}); + this.constraints = constraintMatcher.getSourceMatcher(constraints, (options || {}), true); extd.bindAll(this, ["assert"]); }, diff --git a/lib/constraintMatcher.js b/lib/constraintMatcher.js index 7de294b..3155abf 100644 --- a/lib/constraintMatcher.js +++ b/lib/constraintMatcher.js @@ -4,12 +4,19 @@ var extd = require("./extended"), isArray = extd.isArray, forEach = extd.forEach, some = extd.some, - map = extd.map, indexOf = extd.indexOf, isNumber = extd.isNumber, removeDups = extd.removeDuplicates, atoms = require("./constraint"); +function getProps(val) { + return extd(val).map(function mapper(val) { + return isArray(val) ? isArray(val[0]) ? getProps(val).value() : val.reverse().join(".") : val; + }).flatten().filter(function (v) { + return !!v; + }); +} + var definedFuncs = { indexOf: extd.indexOf, now: function () { @@ -99,6 +106,43 @@ var lang = { return ret; }, + __getProperties: function (rule) { + var ret = []; + if (rule) { + var rule2 = rule[2]; + if (!rule2) { + return ret; + } + if (rule2 !== "prop" && + rule2 !== "identifier" && + rule2 !== "string" && + rule2 !== "number" && + rule2 !== "boolean" && + rule2 !== "regexp" && + rule2 !== "unary" && + rule2 !== "unary") { + ret[0] = this.__getProperties(rule[0]); + ret[1] = this.__getProperties(rule[1]); + } else if (rule2 === "identifier") { + //at the bottom + ret = [rule[0]]; + } else { + ret = lang.__getProperties(rule[1]).concat(lang.__getProperties(rule[0])); + } + } + return ret; + }, + + getIndexableProperties: function (rule) { + if (rule[2] === "composite") { + return this.getIndexableProperties(rule[0]); + } else if (/^(\w+(\['[^']*'])*) *[!=]== (\w+(\['[^']*'])*)$/.test(this.parse(rule))) { + return getProps(this.__getProperties(rule)).flatten().value(); + } else { + return []; + } + }, + getIdentifiers: function (rule) { var ret = []; var rule2 = rule[2]; @@ -170,13 +214,17 @@ var lang = { rule2 === "propLookup" || rule2 === "function" || rule2 === "logicalNot") { - if (some(this.getIdentifiers(rule), function (i) { + var isReference = some(this.getIdentifiers(rule), function (i) { return i !== alias && !(i in definedFuncs) && !(i in scope); - })) { - ret.push(new atoms.ReferenceConstraint(rule, options)); + }); + if (rule2 === "eq") { + ret.push(new atoms[isReference ? "ReferenceEqualityConstraint" : "EqualityConstraint"](rule, options)); + } else if (rule2 === "neq") { + ret.push(new atoms[isReference ? "ReferenceInequalityConstraint" : "InequalityConstraint"](rule, options)); } else { - ret.push(new atoms.EqualityConstraint(rule, options)); + ret.push(new atoms[isReference ? "ReferenceConstraint" : "ComparisonConstraint"](rule, options)); } + } return ret; }, @@ -328,37 +376,51 @@ var lang = { } }; -var toJs = exports.toJs = function (rule, scope, wrap) { +var matcherCount = 0; +var toJs = exports.toJs = function (rule, scope, alias, equality, wrap) { /*jshint evil:true*/ var js = lang.parse(rule); scope = scope || {}; var vars = lang.getIdentifiers(rule); - var body = "var indexOf = definedFuncs.indexOf;" + map(vars,function (v) { + var closureVars = ["var indexOf = definedFuncs.indexOf; var hasOwnProperty = Object.prototype.hasOwnProperty;"], funcVars = []; + extd(vars).filter(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("'", v, "' in fact ? fact['", v, "'] : hash['", v, "']"); + return true; } ret.push(";"); - return ret.join(""); - }).join("") + " return " + (wrap ? wrap(js) : js) + ""; - var f = new Function("fact, hash, definedFuncs, scope", body); - return function (fact, hash) { - return f(fact, hash, definedFuncs, scope); - }; + closureVars.push(ret.join("")); + return false; + }).forEach(function (v) { + var ret = ["var ", v, " = "]; + if (equality || v !== alias) { + ret.push("fact." + v); + } else if (v === alias) { + ret.push("hash.", v, ""); + } + ret.push(";"); + funcVars.push(ret.join("")); + }); + var closureBody = closureVars.join("") + "return function matcher" + (matcherCount++) + (!equality ? "(fact, hash){" : "(fact){") + funcVars.join("") + " return " + (wrap ? wrap(js) : js) + ";}"; + var f = new Function("definedFuncs, scope", closureBody)(definedFuncs, scope); + //console.log(f.toString()); + return f; }; -exports.getMatcher = function (rule, scope) { - return toJs(rule, scope, function (src) { +exports.getMatcher = function (rule, options, equality) { + options = options || {}; + return toJs(rule, options.scope, options.alias, equality, function (src) { return "!!(" + src + ")"; }); }; -exports.getSourceMatcher = function (rule, scope) { - return toJs(rule, scope, function (src) { +exports.getSourceMatcher = function (rule, options, equality) { + options = options || {}; + return toJs(rule, options.scope, options.alias, equality, function (src) { return src; }); }; @@ -376,4 +438,6 @@ exports.getIdentifiers = function (constraint) { return lang.getIdentifiers(constraint); }; - +exports.getIndexableProperties = function (constraint) { + return lang.getIndexableProperties(constraint); +}; diff --git a/lib/context.js b/lib/context.js index 246b9db..ec06216 100644 --- a/lib/context.js +++ b/lib/context.js @@ -6,6 +6,17 @@ var extd = require("./extended"), union = extd.union, pSlice = Array.prototype.slice; +function createContextHash(paths, hashCode) { + var ret = [], + i = -1, + l = paths.length; + while (++i < l) { + ret.push(paths[i].id); + } + ret.push(hashCode); + return ret.join(":"); +} + var Match = declare({ instance: { constructor: function (assertable) { @@ -57,7 +68,8 @@ var Context = declare({ this.paths = paths || null; var match = this.match = mr || new Match(fact); this.factHash = match.factHash; - this.hashCode = match.hashCode; + var hashCode = this.hashCode = match.hashCode; + this.pathsHash = paths ? createContextHash(paths || [], hashCode) : hashCode; this.factIds = match.factIds; }, diff --git a/lib/extended.js b/lib/extended.js index 08f132f..ad77279 100644 --- a/lib/extended.js +++ b/lib/extended.js @@ -1,11 +1,107 @@ +var arr = require("array-extended"), + unique = arr.unique, + indexOf = arr.indexOf, + map = arr.map, + pSlice = Array.prototype.slice, + pSplice = Array.prototype.splice; + +function plucked(prop) { + var exec = prop.match(/(\w+)\(\)$/); + if (exec) { + prop = exec[1]; + return function (item) { + return item[prop](); + }; + } else { + return function (item) { + return item[prop]; + }; + } +} + +function plucker(prop) { + prop = prop.split("."); + if (prop.length === 1) { + return plucked(prop[0]); + } else { + var pluckers = map(prop, function (prop) { + return plucked(prop); + }); + var l = pluckers.length; + return function (item) { + var i = -1, res = item; + while (++i < l) { + res = pluckers[i](res); + } + return res; + }; + } +} + +function intersection(a, b) { + a = pSlice.call(a); + var aOne, i = -1, l; + l = a.length; + while (++i < l) { + aOne = a[i]; + if (indexOf(b, aOne) === -1) { + pSplice.call(a, i--, 1); + l--; + } + } + return a; +} + +function diffArr(arr1, arr2) { + var ret = [], i = -1, j, l2 = arr2.length, l1 = arr1.length, a, found; + if (l2 > l1) { + ret = arr1.slice(); + while (++i < l2) { + a = arr2[i]; + j = -1; + l1 = ret.length; + while (++j < l1) { + if (ret[j] === a) { + ret.splice(j, 1); + break; + } + } + } + } else { + while (++i < l1) { + a = arr1[i]; + j = -1; + found = false; + while (++j < l2) { + if (arr2[j] === a) { + found = true; + break; + } + } + if (!found) { + ret.push(a); + } + } + } + return ret; +} + +function union(arr1, arr2) { + return unique(arr1.concat(arr2)); +} + module.exports = require("extended")() - .register(require("array-extended")) .register(require("date-extended")) + .register(arr) .register(require("object-extended")) .register(require("string-extended")) .register(require("promise-extended")) .register(require("function-extended")) .register(require("is-extended")) + .register("intersection", intersection) + .register("diffArr", diffArr) + .register("unionArr", union) + .register("plucker", plucker) .register("HashTable", require("ht")) .register("declare", require("declare.js")) .register(require("leafy")) diff --git a/lib/linkedList.js b/lib/linkedList.js index e551e8d..dc6f26b 100644 --- a/lib/linkedList.js +++ b/lib/linkedList.js @@ -43,6 +43,33 @@ declare({ } }, + toArray: function () { + var head = {next: this.head}, ret = []; + while ((head = head.next)) { + ret.push(head); + } + return ret; + }, + + removeByData: function (data) { + var head = {next: this.head}; + while ((head = head.next)) { + if (head.data === data) { + this.remove(head); + break; + } + } + }, + + getByData: function (data) { + var head = {next: this.head}; + while ((head = head.next)) { + if (head.data === data) { + return head; + } + } + }, + clear: function () { this.head = this.tail = null; this.length = 0; diff --git a/lib/nodes/adapterNode.js b/lib/nodes/adapterNode.js new file mode 100644 index 0000000..b49eb49 --- /dev/null +++ b/lib/nodes/adapterNode.js @@ -0,0 +1,35 @@ +var Node = require("./node"), + intersection = require("../extended").intersection, + Context = require("../context"); + +Node.extend({ + instance: { + + __propagatePaths: function (method, context) { + var entrySet = this.__entrySet, i = entrySet.length, entry, outNode, paths, continuingPaths; + while (--i > -1) { + entry = entrySet[i]; + outNode = entry.key; + paths = entry.value; + if ((continuingPaths = intersection(paths, context.paths)).length) { + outNode[method](new Context(context.fact, continuingPaths, context.match)); + } + } + }, + + __propagateNoPaths: function (method, context) { + var entrySet = this.__entrySet, i = entrySet.length; + while (--i > -1) { + entrySet[i].key[method](context); + } + }, + + __propagate: function (method, context) { + if (context.paths) { + this.__propagatePaths(method, context); + } else { + this.__propagateNoPaths(method, context); + } + } + } +}).as(module); \ No newline at end of file diff --git a/lib/nodes/betaNode.js b/lib/nodes/betaNode.js new file mode 100644 index 0000000..2c7887b --- /dev/null +++ b/lib/nodes/betaNode.js @@ -0,0 +1,234 @@ +var extd = require("../extended"), + values = extd.hash.values, + keys = extd.hash.keys, + Node = require("./node"), + LeftMemory = require("./misc/leftMemory"), RightMemory = require("./misc/rightMemory"); + +Node.extend({ + + instance: { + + nodeType: "BetaNode", + + constructor: function () { + this._super([]); + this.leftMemory = {}; + this.rightMemory = {}; + this.leftTuples = new LeftMemory(); + this.rightTuples = new RightMemory(); + }, + + __propagate: function (method, context) { + var entrySet = this.__entrySet, i = entrySet.length, entry, outNode; + while (--i > -1) { + entry = entrySet[i]; + outNode = entry.key; + outNode[method](context); + } + }, + + dispose: function () { + this.leftMemory = {}; + this.rightMemory = {}; + this.leftTuples.clear(); + this.rightTuples.clear(); + }, + + disposeLeft: function (fact) { + this.leftMemory = {}; + this.leftTuples.clear(); + this.propagateDispose(fact); + }, + + disposeRight: function (fact) { + this.rightMemory = {}; + this.rightTuples.clear(); + this.propagateDispose(fact); + }, + + hashCode: function () { + return this.nodeType + " " + this.__count; + }, + + toString: function () { + return this.nodeType + " " + this.__count; + }, + + retractLeft: function (context) { + context = this.removeFromLeftMemory(context).data; + var rightMathces = values(context.rightMatches), + i = -1, + l = rightMathces.length; + while (++i < l) { + this.__propagate("retract", rightMathces[i].clone()); + } + }, + + retractRight: function (context) { + context = this.removeFromRightMemory(context).data; + var leftMatches = values(context.leftMatches), + i = -1, + l = leftMatches.length; + while (++i < l) { + this.__propagate("retract", leftMatches[i].clone()); + } + }, + + assertLeft: function (context) { + this.__addToLeftMemory(context); + var rm = this.rightTuples.getRightMemory(context), i = -1, l = rm.length; + while (++i < l) { + this.propagateFromLeft(context, rm[i].data); + } + }, + + assertRight: function (context) { + this.__addToRightMemory(context); + var lm = this.leftTuples.getLeftMemory(context), i = -1, l = lm.length; + while (++i < l) { + this.propagateFromRight(context, lm[i].data); + } + }, + + modifyLeft: function (context) { + var previousContext = this.removeFromLeftMemory(context).data; + this.__addToLeftMemory(context); + var rm = this.rightTuples.getRightMemory(context), l = rm.length; + if (!l) { + this.propagateRetract(context); + } else { + var i = -1, + rightMatches = previousContext.rightMatches; + while (++i < l) { + this.propagateAssertModifyFromLeft(context, rightMatches, rm[i].data); + } + + } + }, + + modifyRight: function (context) { + var previousContext = this.removeFromRightMemory(context).data; + this.__addToRightMemory(context); + var lm = this.leftTuples.getLeftMemory(context); + if (!lm.length) { + this.propagateRetract(context); + } else { + var leftMatches = previousContext.leftMatches, i = -1, l = lm.length; + while (++i < l) { + this.propagateAssertModifyFromRight(context, leftMatches, lm[i].data); + } + } + }, + + propagateFromLeft: function (context, rc) { + this.__propagate("assert", this.__addToMemoryMatches(rc, context, context.clone(null, null, context.match.merge(rc.match)))); + }, + + propagateFromRight: function (context, lc) { + this.__propagate("assert", this.__addToMemoryMatches(context, lc, lc.clone(null, null, lc.match.merge(context.match)))); + }, + + propagateAssertModifyFromLeft: function (context, rightMatches, rm) { + var factId = rm.hashCode; + if (factId in rightMatches) { + this.__propagate("modify", this.__addToMemoryMatches(rm, context, context.clone(null, null, context.match.merge(rm.match)))); + } else { + this.propagateFromLeft(context, rm); + } + }, + + propagateAssertModifyFromRight: function (context, leftMatches, lm) { + var factId = lm.hashCode; + if (factId in leftMatches) { + this.__propagate("modify", this.__addToMemoryMatches(context, lm, context.clone(null, null, lm.match.merge(context.match)))); + } else { + this.propagateFromRight(context, lm); + } + }, + + removeFromRightMemory: function (context) { + var hashCode = context.hashCode, ret; + context = this.rightMemory[hashCode] || null; + var tuples = this.rightTuples; + if (context) { + var leftMemory = this.leftMemory; + ret = context.data; + var leftMatches = ret.leftMatches; + tuples.remove(context); + var hashCodes = keys(leftMatches), i = -1, l = hashCodes.length; + while (++i < l) { + delete leftMemory[hashCodes[i]].data.rightMatches[hashCode]; + } + delete this.rightMemory[hashCode]; + } + return context; + }, + + removeFromLeftMemory: function (context) { + var hashCode = context.hashCode; + context = this.leftMemory[hashCode] || null; + if (context) { + var rightMemory = this.rightMemory; + var rightMatches = context.data.rightMatches; + this.leftTuples.remove(context); + for (var i in rightMatches) { + delete rightMemory[i].data.leftMatches[hashCode]; + } + delete this.leftMemory[hashCode]; + } + return context; + }, + + getRightMemoryMatches: function (context) { + var lm = this.leftMemory[context.hashCode], ret = {}; + if (lm) { + ret = lm.rightMatches; + } + return ret; + }, + + __addToMemoryMatches: function (rightContext, leftContext, createdContext) { + var rightFactId = rightContext.hashCode, + rm = this.rightMemory[rightFactId], + lm, leftFactId = leftContext.hashCode; + if (rm) { + rm = rm.data; + if (leftFactId in rm.leftMatches) { + throw new Error("Duplicate left fact entry"); + } + rm.leftMatches[leftFactId] = createdContext; + } + lm = this.leftMemory[leftFactId]; + if (lm) { + lm = lm.data; + if (rightFactId in lm.rightMatches) { + throw new Error("Duplicate right fact entry"); + } + lm.rightMatches[rightFactId] = createdContext; + } + return createdContext; + }, + + __addToRightMemory: function (context) { + var hashCode = context.hashCode, rm = this.rightMemory; + if (hashCode in rm) { + return false; + } + rm[hashCode] = this.rightTuples.push(context); + context.leftMatches = {}; + return true; + }, + + + __addToLeftMemory: function (context) { + var hashCode = context.hashCode, lm = this.leftMemory; + if (hashCode in lm) { + return false; + } + lm[hashCode] = this.leftTuples.push(context); + context.rightMatches = {}; + return true; + } + } + +}).as(module); \ No newline at end of file diff --git a/lib/nodes/equalityNode.js b/lib/nodes/equalityNode.js index 58c9d94..16d8113 100644 --- a/lib/nodes/equalityNode.js +++ b/lib/nodes/equalityNode.js @@ -1,18 +1,5 @@ var AlphaNode = require("./alphaNode"); -function createContextHash(context) { - var ret = [], - paths = context.paths, - i = -1, - l = paths.length; - while (++i < l) { - ret.push(paths[i].id); - } - ret.push(context.hashCode); - return ret.join(":"); - -} - AlphaNode.extend({ instance: { @@ -23,15 +10,14 @@ AlphaNode.extend({ }, assert: function (context) { - var hashCode = createContextHash(context); - if ((this.memory[hashCode] = this.constraintAssert(context.factHash))) { + if ((this.memory[context.pathsHash] = this.constraintAssert(context.factHash))) { this.__propagate("assert", context); } }, modify: function (context) { var memory = this.memory, - hashCode = createContextHash(context), + hashCode = context.pathsHash, wasMatch = memory[hashCode]; if ((memory[hashCode] = this.constraintAssert(context.factHash))) { this.__propagate(wasMatch ? "modify" : "assert", context); @@ -41,7 +27,7 @@ AlphaNode.extend({ }, retract: function (context) { - var hashCode = createContextHash(context), + var hashCode = context.pathsHash, memory = this.memory; if (memory[hashCode]) { this.__propagate("retract", context); diff --git a/lib/nodes/existsFromNode.js b/lib/nodes/existsFromNode.js new file mode 100644 index 0000000..474011a --- /dev/null +++ b/lib/nodes/existsFromNode.js @@ -0,0 +1,99 @@ +var FromNotNode = require("./fromNotNode"), + extd = require("../extended"), + Context = require("../context"), + isDefined = extd.isDefined, + isArray = extd.isArray; + +FromNotNode.extend({ + instance: { + + nodeType: "ExistsFromNode", + + retractLeft: function (context) { + var ctx = this.removeFromLeftMemory(context); + if (ctx) { + ctx = ctx.data; + if (ctx.blocked) { + this.__propagate("retract", ctx.clone()); + } + } + }, + + __modify: function (context, leftContext) { + var leftContextBlocked = leftContext.blocked; + var fh = context.factHash, o = this.from(fh); + if (isArray(o)) { + for (var i = 0, l = o.length; i < l; i++) { + if (this.__isMatch(context, o[i], true)) { + context.blocked = true; + break; + } + } + } else if (isDefined(o)) { + context.blocked = this.__isMatch(context, o, true); + } + var newContextBlocked = context.blocked; + if (newContextBlocked) { + if (leftContextBlocked) { + this.__propagate("modify", context.clone()); + } else { + this.__propagate("assert", context.clone()); + } + } else if (leftContextBlocked) { + this.__propagate("retract", context.clone()); + } + + }, + + __findMatches: function (context) { + var fh = context.factHash, o = this.from(fh), isMatch = false; + if (isArray(o)) { + for (var i = 0, l = o.length; i < l; i++) { + if (this.__isMatch(context, o[i], true)) { + context.blocked = true; + this.__propagate("assert", context.clone()); + return; + } + } + } else if (isDefined(o) && (this.__isMatch(context, o, true))) { + context.blocked = true; + this.__propagate("assert", context.clone()); + } + return isMatch; + }, + + __isMatch: function (oc, o, add) { + var ret = false; + if (this.type(o)) { + var createdFact = this.workingMemory.getFactHandle(o); + var context = new Context(createdFact, null) + .mergeMatch(oc.match) + .set(this.alias, o); + if (add) { + var fm = this.fromMemory[createdFact.id]; + if (!fm) { + fm = this.fromMemory[createdFact.id] = {}; + } + fm[oc.hashCode] = oc; + } + var fh = context.factHash; + var eqConstraints = this.__equalityConstraints; + for (var i = 0, l = eqConstraints.length; i < l; i++) { + if (eqConstraints[i](fh)) { + ret = true; + } else { + ret = false; + break; + } + } + } + return ret; + }, + + assertLeft: function (context) { + this.__addToLeftMemory(context); + this.__findMatches(context); + } + + } +}).as(module); \ No newline at end of file diff --git a/lib/nodes/existsNode.js b/lib/nodes/existsNode.js new file mode 100644 index 0000000..7184630 --- /dev/null +++ b/lib/nodes/existsNode.js @@ -0,0 +1,173 @@ +var NotNode = require("./notNode"), + LinkedList = require("../linkedList"); + + +NotNode.extend({ + instance: { + + nodeType: "ExistsNode", + + blockedContext: function (leftContext, rightContext) { + leftContext.blocker = rightContext; + this.removeFromLeftMemory(leftContext); + this.addToLeftBlockedMemory(rightContext.blocking.push(leftContext)); + this.__propagate("assert", this.__cloneContext(leftContext)); + }, + + notBlockedContext: function (leftContext, propagate) { + this.__addToLeftMemory(leftContext); + propagate && this.__propagate("retract", this.__cloneContext(leftContext)); + }, + + propagateFromLeft: function (leftContext) { + this.notBlockedContext(leftContext, false); + }, + + + retractLeft: function (context) { + var ctx; + if (!this.removeFromLeftMemory(context)) { + if ((ctx = this.removeFromLeftBlockedMemory(context))) { + this.__propagate("retract", this.__cloneContext(ctx.data)); + } else { + throw new Error(); + } + } + }, + + modifyLeft: function (context) { + var ctx = this.removeFromLeftMemory(context), + leftContext, + thisConstraint = this.constraint, + rightTuples = this.rightTuples, + l = rightTuples.length, + isBlocked = false, + node, rc, blocker; + if (!ctx) { + //blocked before + ctx = this.removeFromLeftBlockedMemory(context); + isBlocked = true; + } + if (ctx) { + leftContext = ctx.data; + + if (leftContext && leftContext.blocker) { + //we were blocked before so only check nodes previous to our blocker + blocker = this.rightMemory[leftContext.blocker.hashCode]; + } + if (blocker) { + if (thisConstraint.isMatch(context, rc = blocker.data)) { + //propogate as a modify or assert + this.__propagate(!isBlocked ? "assert" : "modify", this.__cloneContext(leftContext)); + context.blocker = rc; + this.addToLeftBlockedMemory(rc.blocking.push(context)); + context = null; + } + if (context) { + node = {next: blocker.next}; + } + } else { + node = {next: rightTuples.head}; + } + if (context && l) { + node = {next: rightTuples.head}; + //we were propagated before + while ((node = node.next)) { + if (thisConstraint.isMatch(context, rc = node.data)) { + //we cant be proagated so retract previous + + //we were asserted before so retract + this.__propagate(!isBlocked ? "assert" : "modify", this.__cloneContext(leftContext)); + + this.addToLeftBlockedMemory(rc.blocking.push(context)); + context.blocker = rc; + context = null; + break; + } + } + } + if (context) { + //we can still be propogated + this.__addToLeftMemory(context); + if (isBlocked) { + //we were blocked so retract + this.__propagate("retract", this.__cloneContext(context)); + } + + } + } else { + throw new Error(); + } + + }, + + modifyRight: function (context) { + var ctx = this.removeFromRightMemory(context); + if (ctx) { + var rightContext = ctx.data, + leftTuples = this.leftTuples, + leftTuplesLength = leftTuples.length, + leftContext, + thisConstraint = this.constraint, + node, + blocking = rightContext.blocking; + this.__addToRightMemory(context); + context.blocking = new LinkedList(); + if (leftTuplesLength || blocking.length) { + if (blocking.length) { + var rc; + //check old blocked contexts + //check if the same contexts blocked before are still blocked + var blockingNode = {next: blocking.head}; + while ((blockingNode = blockingNode.next)) { + leftContext = blockingNode.data; + leftContext.blocker = null; + if (thisConstraint.isMatch(leftContext, context)) { + leftContext.blocker = context; + this.addToLeftBlockedMemory(context.blocking.push(leftContext)); + this.__propagate("assert", this.__cloneContext(leftContext)); + leftContext = null; + } else { + //we arent blocked anymore + leftContext.blocker = null; + node = ctx; + while ((node = node.next)) { + if (thisConstraint.isMatch(leftContext, rc = node.data)) { + leftContext.blocker = rc; + this.addToLeftBlockedMemory(rc.blocking.push(leftContext)); + this.__propagate("assert", this.__cloneContext(leftContext)); + leftContext = null; + break; + } + } + if (leftContext) { + this.__addToLeftMemory(leftContext); + } + } + } + } + + if (leftTuplesLength) { + //check currently left tuples in memory + node = {next: leftTuples.head}; + while ((node = node.next)) { + leftContext = node.data; + if (thisConstraint.isMatch(leftContext, context)) { + this.__propagate("assert", this.__cloneContext(leftContext)); + this.removeFromLeftMemory(leftContext); + this.addToLeftBlockedMemory(context.blocking.push(leftContext)); + leftContext.blocker = context; + } + } + } + + + } + } else { + throw new Error(); + } + + + } + } +}).as(module); \ No newline at end of file diff --git a/lib/nodes/fromNode.js b/lib/nodes/fromNode.js index c39ae28..031c5cc 100644 --- a/lib/nodes/fromNode.js +++ b/lib/nodes/fromNode.js @@ -1,4 +1,4 @@ -var Node = require("./joinNode"), +var JoinNode = require("./joinNode"), extd = require("../extended"), constraint = require("../constraint"), EqualityConstraint = constraint.EqualityConstraint, @@ -16,9 +16,11 @@ var DEFAULT_MATCH = { } }; -Node.extend({ +JoinNode.extend({ instance: { + nodeType: "FromNode", + constructor: function (pattern, wm) { this._super(arguments); this.workingMemory = wm; @@ -71,7 +73,7 @@ Node.extend({ } var eqConstraints = this.__equalityConstraints, vars = this.__variables, i = -1, l = eqConstraints.length; while (++i < l) { - if (!eqConstraints[i](fh)) { + if (!eqConstraints[i](fh, fh)) { createdContext = DEFAULT_MATCH; break; } @@ -206,11 +208,6 @@ Node.extend({ assertRight: function () { throw new Error("Shouldnt have gotten here"); - }, - - - toString: function () { - return "FromNode" + this.__count; } } diff --git a/lib/nodes/fromNotNode.js b/lib/nodes/fromNotNode.js index dc2ec03..66900dc 100644 --- a/lib/nodes/fromNotNode.js +++ b/lib/nodes/fromNotNode.js @@ -1,4 +1,4 @@ -var Node = require("./joinNode"), +var JoinNode = require("./joinNode"), extd = require("../extended"), constraint = require("../constraint"), EqualityConstraint = constraint.EqualityConstraint, @@ -9,9 +9,11 @@ var Node = require("./joinNode"), forEach = extd.forEach, isArray = extd.isArray; -Node.extend({ +JoinNode.extend({ instance: { + nodeType: "FromNotNode", + constructor: function (pattern, workingMemory) { this._super(arguments); this.workingMemory = workingMemory; @@ -53,7 +55,7 @@ Node.extend({ break; } } - } else if(isDefined(o)){ + } else if (isDefined(o)) { context.blocked = this.__isMatch(context, o, true); } var newContextBlocked = context.blocked; @@ -129,7 +131,7 @@ Node.extend({ var fh = context.factHash; var eqConstraints = this.__equalityConstraints; for (var i = 0, l = eqConstraints.length; i < l; i++) { - if (eqConstraints[i](fh)) { + if (eqConstraints[i](fh, fh)) { ret = true; } else { ret = false; @@ -140,10 +142,6 @@ Node.extend({ return ret; }, - removeFromLeftMemory: function () { - return this._super(arguments); - }, - assertLeft: function (context) { this.__addToLeftMemory(context); this.__findMatches(context); @@ -155,10 +153,6 @@ Node.extend({ retractRight: function () { throw new Error("Shouldnt have gotten here"); - }, - - toString: function () { - return "FromNode" + this.__count; } } diff --git a/lib/nodes/index.js b/lib/nodes/index.js index 27b7923..2f4e6ed 100644 --- a/lib/nodes/index.js +++ b/lib/nodes/index.js @@ -7,6 +7,8 @@ var extd = require("../extended"), ObjectPattern = pattern.ObjectPattern, FromPattern = pattern.FromPattern, FromNotPattern = pattern.FromNotPattern, + ExistsPattern = pattern.ExistsPattern, + FromExistsPattern = pattern.FromExistsPattern, NotPattern = pattern.NotPattern, CompositePattern = pattern.CompositePattern, InitialFactPattern = pattern.InitialFactPattern, @@ -16,15 +18,24 @@ var extd = require("../extended"), AliasNode = require("./aliasNode"), EqualityNode = require("./equalityNode"), JoinNode = require("./joinNode"), + BetaNode = require("./betaNode"), NotNode = require("./notNode"), FromNode = require("./fromNode"), FromNotNode = require("./fromNotNode"), + ExistsNode = require("./existsNode"), + ExistsFromNode = require("./existsFromNode"), LeftAdapterNode = require("./leftAdapterNode"), RightAdapterNode = require("./rightAdapterNode"), TypeNode = require("./typeNode"), TerminalNode = require("./terminalNode"), PropertyNode = require("./propertyNode"); +function hasRefernceConstraints(pattern) { + return some(pattern.constraints || [], function (c) { + return c instanceof ReferenceConstraint; + }); +} + declare({ instance: { constructor: function (wm, agendaTree) { @@ -96,7 +107,7 @@ declare({ var joinNodes = this.joinNodes; for (var i = 0; i < joinNodes.length; i++) { var j1 = joinNodes[i], j2 = joinNodes[i + 1]; - if (j1 && j2 && j1.constraint.equal(j2.constraint)) { + if (j1 && j2 && (j1.constraint && j2.constraint && j1.constraint.equal(j2.constraint))) { j1.merge(j2); joinNodes.splice(i + 1, 1); } @@ -141,24 +152,31 @@ declare({ }, __createAdapterNode: function (rule, side) { - return (side === "left" ? new LeftAdapterNode(): new RightAdapterNode()).addRule(rule); + return (side === "left" ? new LeftAdapterNode() : new RightAdapterNode()).addRule(rule); }, __createJoinNode: function (rule, pattern, outNode, side) { var joinNode; if (pattern.rightPattern instanceof NotPattern) { joinNode = new NotNode(); + } else if (pattern.rightPattern instanceof FromExistsPattern) { + joinNode = new ExistsFromNode(pattern.rightPattern, this.workingMemory); + } else if (pattern.rightPattern instanceof ExistsPattern) { + joinNode = new ExistsNode(); } else if (pattern.rightPattern instanceof FromNotPattern) { joinNode = new FromNotNode(pattern.rightPattern, this.workingMemory); } else if (pattern.rightPattern instanceof FromPattern) { joinNode = new FromNode(pattern.rightPattern, this.workingMemory); + } else if (pattern instanceof CompositePattern && !hasRefernceConstraints(pattern.leftPattern) && !hasRefernceConstraints(pattern.rightPattern)) { + joinNode = new BetaNode(); + this.joinNodes.push(joinNode); } else { joinNode = new JoinNode(); this.joinNodes.push(joinNode); } joinNode["__rule__"] = rule; var parentNode = joinNode; - if (outNode instanceof JoinNode) { + if (outNode instanceof BetaNode) { var adapterNode = this.__createAdapterNode(rule, side); parentNode.addOutNode(adapterNode, pattern); parentNode = adapterNode; @@ -169,12 +187,8 @@ declare({ __addToNetwork: function (rule, pattern, outNode, side) { if (pattern instanceof ObjectPattern) { - if ((pattern instanceof NotPattern || pattern instanceof FromPattern || pattern instanceof FromNotPattern) && (!side || side === "left")) { - if (pattern instanceof FromNotPattern) { - this.__createBetaNode(rule, new CompositePattern(new InitialFactPattern(), pattern), outNode, side); - } else { - this.__createBetaNode(rule, new CompositePattern(new InitialFactPattern(), pattern), outNode, side); - } + if (!(pattern instanceof InitialFactPattern) && (!side || side === "left")) { + this.__createBetaNode(rule, new CompositePattern(new InitialFactPattern(), pattern), outNode, side); } else { this.__createAlphaNode(rule, pattern, outNode, side); } @@ -218,7 +232,7 @@ declare({ parentNode = node; } - if (outNode instanceof JoinNode) { + if (outNode instanceof BetaNode) { var adapterNode = this.__createAdapterNode(rule, side); adapterNode.addParentNode(parentNode); parentNode.addOutNode(adapterNode, pattern); diff --git a/lib/nodes/joinNode.js b/lib/nodes/joinNode.js index 3c2489a..9d81a52 100644 --- a/lib/nodes/joinNode.js +++ b/lib/nodes/joinNode.js @@ -1,180 +1,36 @@ -var extd = require("../extended"), - values = extd.hash.values, - Node = require("./node"), - JoinReferenceNode = require("./joinReferenceNode"), - LinkedList = require("../linkedList"); +var BetaNode = require("./betaNode"), + JoinReferenceNode = require("./joinReferenceNode"); -Node.extend({ +BetaNode.extend({ instance: { constructor: function () { - this._super([]); - this.constraint = new JoinReferenceNode(); - this.leftMemory = {}; - this.rightMemory = {}; - this.leftTuples = new LinkedList(); - this.rightTuples = new LinkedList(); + this._super(arguments); + this.constraint = new JoinReferenceNode(this.leftTuples, this.rightTuples); }, - dispose: function () { - this.leftMemory = {}; - this.rightMemory = {}; - this.leftTuples.clear(); - this.rightTuples.clear(); - }, - - disposeLeft: function (fact) { - this.leftMemory = {}; - this.leftTuples.clear(); - this.propagateDispose(fact); - }, - - disposeRight: function (fact) { - this.rightMemory = {}; - this.rightTuples.clear(); - this.propagateDispose(fact); - }, - - hashCode: function () { - return "JoinNode " + this.__count; - }, - - toString: function () { - return "JoinNode " + this.__count; - }, + nodeType: "JoinNode", - retractLeft: function (context) { - context = this.removeFromLeftMemory(context); - if (context) { - context = context.data; - var rightMathces = values(context.rightMatches), - i = -1, - l = rightMathces.length; - while (++i < l) { - this.__propagate("retract", rightMathces[i]); - } - } else { - throw new Error(); - } - return this; - }, - - retractRight: function (context) { - context = this.removeFromRightMemory(context); - if (context) { - context = context.data; - var leftMatches = values(context.leftMatches), - i = -1, - l = leftMatches.length; - while (++i < l) { - this.__propagate("retract", leftMatches[i]); - } - } else { - throw new Error(); - } - return this; - }, - - propagateFromLeft: function (context, constraint, rm) { + propagateFromLeft: function (context, rm) { var mr; - if ((mr = constraint.setRightContext(rm).match()).isMatch) { + if ((mr = this.constraint.match(context, rm)).isMatch) { this.__propagate("assert", this.__addToMemoryMatches(rm, context, context.clone(null, null, mr))); } return this; }, - propagateFromRight: function (context, constraint, lm) { + propagateFromRight: function (context, lm) { var mr; - if ((mr = constraint.setLeftContext(lm).match()).isMatch) { + if ((mr = this.constraint.match(lm, context)).isMatch) { this.__propagate("assert", this.__addToMemoryMatches(context, lm, context.clone(null, null, mr))); } return this; }, - assertLeft: function (context) { - if (this.__addToLeftMemory(context)) { - var rm = this.rightTuples, node = {next: rm.head}, thisConstraint = this.constraint; - if (rm.length) { - thisConstraint.setLeftContext(context); - while ((node = node.next)) { - this.propagateFromLeft(context, thisConstraint, node.data); - } - thisConstraint.clearContexts(); - } - } else { - this.modifyLeft(context); - } - }, - - assertRight: function (context) { - if (this.__addToRightMemory(context)) { - var lm = this.leftTuples; - if (lm.length) { - var node = {next: lm.head}, thisConstraint = this.constraint; - thisConstraint.setRightContext(context); - while ((node = node.next)) { - this.propagateFromRight(context, thisConstraint, node.data); - } - thisConstraint.clearContexts(); - } - } else { - this.modifyRight(context); - } - }, - - modifyLeft: function (context) { - var previousContext; - if ((previousContext = this.removeFromLeftMemory(context))) { - previousContext = previousContext.data; - this.__addToLeftMemory(context); - var rm = this.rightTuples, l = rm.length; - if (!l) { - this.propagateRetract(context); - } else { - var thisConstraint = this.constraint, - node = {next: rm.head}, - rightMatches = previousContext.rightMatches; - thisConstraint.setLeftContext(context); - while ((node = node.next)) { - this.propagateAssertModifyFromLeft(context, rightMatches, thisConstraint, node.data); - } - thisConstraint.clearContexts(); - - } - } else { - throw new Error(); - } - - }, - - modifyRight: function (context) { - var previousContext; - if ((previousContext = this.removeFromRightMemory(context))) { - previousContext = previousContext.data; - this.__addToRightMemory(context); - var lm = this.leftTuples; - if (!lm.length) { - this.propagateRetract(context); - } else { - var thisConstraint = this.constraint, - leftMatches = previousContext.leftMatches, - node = {next: lm.head}; - thisConstraint.setRightContext(context); - while ((node = node.next)) { - this.propagateAssertModifyFromRight(context, leftMatches, thisConstraint, node.data); - } - thisConstraint.clearContexts(); - } - } else { - throw new Error(); - } - - }, - - propagateAssertModifyFromLeft: function (context, rightMatches, constraint, rm) { + propagateAssertModifyFromLeft: function (context, rightMatches, rm) { var factId = rm.hashCode, mr; if (factId in rightMatches) { - mr = constraint.setRightContext(rm).match(); + mr = this.constraint.match(context, rm); var mrIsMatch = mr.isMatch; if (!mrIsMatch) { this.__propagate("retract", rightMatches[factId].clone()); @@ -182,14 +38,14 @@ Node.extend({ this.__propagate("modify", this.__addToMemoryMatches(rm, context, context.clone(null, null, mr))); } } else { - this.propagateFromLeft(context, constraint, rm); + this.propagateFromLeft(context, rm); } }, - propagateAssertModifyFromRight: function (context, leftMatches, constraint, lm) { + propagateAssertModifyFromRight: function (context, leftMatches, lm) { var factId = lm.hashCode, mr; if (factId in leftMatches) { - mr = constraint.setLeftContext(lm).match(); + mr = this.constraint.match(lm, context); var mrIsMatch = mr.isMatch; if (!mrIsMatch) { this.__propagate("retract", leftMatches[factId].clone()); @@ -197,91 +53,8 @@ Node.extend({ this.__propagate("modify", this.__addToMemoryMatches(context, lm, context.clone(null, null, mr))); } } else { - this.propagateFromRight(context, constraint, lm); - } - }, - - removeFromRightMemory: function (context) { - var hashCode = context.hashCode, ret; - context = this.rightMemory[hashCode] || null; - var tuples = this.rightTuples; - if (context) { - var leftMemory = this.leftMemory; - ret = context.data; - var leftMatches = ret.leftMatches; - tuples.remove(context); - for (var i in leftMatches) { - delete leftMemory[i].data.rightMatches[hashCode]; - } - delete this.rightMemory[hashCode]; - } - return context; - }, - - removeFromLeftMemory: function (context) { - var hashCode = context.hashCode; - context = this.leftMemory[hashCode] || null; - if (context) { - var rightMemory = this.rightMemory; - var rightMatches = context.data.rightMatches; - this.leftTuples.remove(context); - for (var i in rightMatches) { - delete rightMemory[i].data.leftMatches[hashCode]; - } - delete this.leftMemory[hashCode]; - } - return context; - }, - - getRightMemoryMatches: function (context) { - var lm = this.leftMemory[context.hashCode], ret = {}; - if (lm) { - ret = lm.rightMatches; - } - return ret; - }, - - __addToMemoryMatches: function (rightContext, leftContext, createdContext) { - var rightFactId = rightContext.hashCode, - rm = this.rightMemory[rightFactId], - lm, leftFactId = leftContext.hashCode; - if (rm) { - rm = rm.data; - if (leftFactId in rm.leftMatches) { - throw new Error("Duplicate left fact entry"); - } - rm.leftMatches[leftFactId] = createdContext; - } - lm = this.leftMemory[leftFactId]; - if (lm) { - lm = lm.data; - if (rightFactId in lm.rightMatches) { - throw new Error("Duplicate right fact entry"); - } - lm.rightMatches[rightFactId] = createdContext; - } - return createdContext; - }, - - __addToRightMemory: function (context) { - var hashCode = context.hashCode, rm = this.rightMemory; - if (hashCode in rm) { - return false; - } - rm[hashCode] = this.rightTuples.push(context); - context.leftMatches = {}; - return true; - }, - - - __addToLeftMemory: function (context) { - var hashCode = context.hashCode, lm = this.leftMemory; - if (hashCode in lm) { - return false; + this.propagateFromRight(context, lm); } - lm[hashCode] = this.leftTuples.push(context); - context.rightMatches = {}; - return true; } } diff --git a/lib/nodes/joinReferenceNode.js b/lib/nodes/joinReferenceNode.js index 5dcc0d5..e9a27fd 100644 --- a/lib/nodes/joinReferenceNode.js +++ b/lib/nodes/joinReferenceNode.js @@ -1,9 +1,15 @@ -var Node = require("./node"); +var Node = require("./node"), + constraints = require("../constraint"), + ReferenceEqualityConstraint = constraints.ReferenceEqualityConstraint; var DEFUALT_CONSTRAINT = { isDefault: true, assert: function () { return true; + }, + + equal: function () { + return false; } }; @@ -12,101 +18,60 @@ Node.extend({ instance: { constraint: DEFUALT_CONSTRAINT, - __lc: null, - __rc: null, - __varLength: 0, - __count: 0, - __rcMatch: null, - __lcMatch: null, - constructor: function () { + constructor: function (leftMemory, rightMemory) { this._super(arguments); - this.__fh = {}; - this.__variables = []; - this.isDefault = true; + this.constraint = DEFUALT_CONSTRAINT; this.constraintAssert = DEFUALT_CONSTRAINT.assert; + this.rightIndexes = []; + this.leftIndexes = []; + this.constraintLength = 0; + this.leftMemory = leftMemory; + this.rightMemory = rightMemory; }, - setLeftContext: function (lc) { - this.__lc = lc; - var match = this.__lcMatch = lc.match; - if (!this.isDefault) { - var newFh = match.factHash, - fh = this.__fh, - prop, - vars = this.__variables, - i = -1, - l = this.__varLength; - while (++i < l) { - prop = vars[i]; - fh[prop] = newFh[prop]; + addConstraint: function (constraint) { + if (constraint instanceof ReferenceEqualityConstraint) { + var identifiers = constraint.getIndexableProperties(); + var alias = constraint.get("alias"); + if (identifiers.length === 2 && alias) { + var leftIndex, rightIndex, i = -1; + while (++i < 2) { + var index = identifiers[i]; + if (index.match(new RegExp("^" + alias + "(\\.?)")) === null) { + leftIndex = index; + } else { + rightIndex = index; + } + } + if (leftIndex && rightIndex) { + this.rightMemory.addIndex(rightIndex, leftIndex, constraint.op); + this.leftMemory.addIndex(leftIndex, rightIndex, constraint.op); + } } } - return this; - }, - - setRightContext: function (rc) { - this.__rc = rc; - this.__rcMatch = rc.match; - if (!this.isDefault) { - this.__fh[this.__alias] = rc.fact.object; - } - return this; - }, - - clearContexts: function () { - this.__fh = {}; - this.__lc = null; - this.__rc = null; - this.__lcMatch = this.__rcMatch = null; - return this; - }, - - clearRightContext: function () { - this.__rc = null; - this.__fh[this.__alias] = null; - return this; - }, - - clearLeftContext: function () { - this.__lc = null; - var fh = this.__fh = {}, rc = this.__rc; - fh[this.__alias] = rc ? rc.fact.object : null; - return this; - }, - - addConstraint: function (constraint) { if (this.constraint.isDefault) { this.constraint = constraint; this.isDefault = false; } else { this.constraint = this.constraint.merge(constraint); } - this.__alias = this.constraint.get("alias"); - this.__varLength = (this.__variables = this.__variables.concat(this.constraint.get("variables"))).length; this.constraintAssert = this.constraint.assert; + }, equal: function (constraint) { - if (this.isDefault !== true) { - return this.constraint.equal(constraint.constraint); - } + return this.constraint.equal(constraint.constraint); }, - isMatch: function () { - return this.isDefault || this.constraintAssert(this.__fh); + isMatch: function (lc, rc) { + return this.constraintAssert(lc.factHash, rc.factHash); }, - match: function () { - var ret; - if (this.isDefault) { - ret = this.__lcMatch.merge(this.__rcMatch); - } else { - ret = {isMatch: false}; - var fh = this.__fh; - if (this.constraintAssert(fh)) { - ret = this.__lcMatch.merge(this.__rcMatch); - } + match: function (lc, rc) { + var ret = {isMatch: false}; + if (this.constraintAssert(lc.factHash, rc.factHash)) { + ret = lc.match.merge(rc.match); } return ret; } diff --git a/lib/nodes/leftAdapterNode.js b/lib/nodes/leftAdapterNode.js index 3f96a6d..1b542c7 100644 --- a/lib/nodes/leftAdapterNode.js +++ b/lib/nodes/leftAdapterNode.js @@ -1,4 +1,4 @@ -var Node = require("./node"); +var Node = require("./adapterNode"); Node.extend({ instance: { diff --git a/lib/nodes/misc/leftMemory.js b/lib/nodes/misc/leftMemory.js new file mode 100644 index 0000000..d6456f3 --- /dev/null +++ b/lib/nodes/misc/leftMemory.js @@ -0,0 +1,12 @@ +var Memory = require("./memory"); + +Memory.extend({ + + instance: { + + getLeftMemory: function (tuple) { + return this.getMemory(tuple); + } + } + +}).as(module); \ No newline at end of file diff --git a/lib/nodes/misc/memory.js b/lib/nodes/misc/memory.js new file mode 100644 index 0000000..6ec9045 --- /dev/null +++ b/lib/nodes/misc/memory.js @@ -0,0 +1,219 @@ +var extd = require("../../extended"), + indexOf = extd.indexOf, + plucker = extd.plucker, + difference = extd.diffArr, + pPush = Array.prototype.push, + declare = extd.declare, + HashTable = extd.HashTable; +declare({ + + instance: { + constructor: function () { + this.head = null; + this.tail = null; + this.length = null; + this.indexes = []; + this.tables = {tuples: [], tables: []}; + }, + + inequalityThreshold: 0.5, + + push: function (data) { + var tail = this.tail, head = this.head, node = {data: data, prev: tail, next: null}; + if (tail) { + this.tail.next = node; + } + this.tail = node; + if (!head) { + this.head = node; + } + this.length++; + this.__index(node); + this.tables.tuples.push(node); + return node; + }, + + remove: function (node) { + if (node.prev) { + node.prev.next = node.next; + } else { + this.head = node.next; + } + if (node.next) { + node.next.prev = node.prev; + } else { + this.tail = node.prev; + } + var index = indexOf(this.tables.tuples, node); + if (index !== -1) { + this.tables.tuples.splice(index, 1); + } + this.__removeFromIndex(node); + this.length--; + }, + + forEach: function (cb) { + var head = {next: this.head}; + while ((head = head.next)) { + cb(head.data); + } + }, + + toArray: function () { + var head = {next: this.head}, ret = []; + while ((head = head.next)) { + ret.push(head); + } + return ret; + }, + + clear: function () { + this.head = this.tail = null; + this.length = 0; + this.clearIndexes(); + }, + + clearIndexes: function () { + this.tables = {}; + this.indexes.length = 0; + }, + + __index: function (node) { + var data = node.data, + factHash = data.factHash, + indexes = this.indexes, + entry = this.tables, + i = -1, l = indexes.length, + tuples, index, val, path, tables, currEntry, prevLookup; + while (++i < l) { + index = indexes[i]; + val = index[2](factHash); + path = index[0]; + tables = entry.tables; + currEntry = tables[path]; + if (!currEntry) { + currEntry = tables[path] = new HashTable(); + tuples = {tuples: [node], tables: {}}; + currEntry.put(val, tuples); + } else if (!(tuples = currEntry.get(val))) { + tuples = {tuples: [node], tables: {}}; + currEntry.put(val, tuples); + } else if (prevLookup !== path) { + tuples.tuples.push(node); + } + prevLookup = path; + if (index[4] === "eq") { + entry = tuples; + } + } + }, + + getSimilarMemory: function (tuple) { + return this.getMemory(tuple, true); + }, + + __removeFromIndex: function (node) { + var data = node.data, + factHash = data.factHash, + indexes = this.indexes, + entry = this.tables, + i = -1, l = indexes.length; + while (++i < l) { + var index = indexes[i], + val = index[2](factHash); + var currEntry = entry.tables[index[0]]; + if (currEntry) { + var tuples = currEntry.get(val); + if (tuples) { + var currTuples = tuples.tuples, ind = indexOf(currTuples, node); + if (ind !== -1) { + currTuples.splice(ind, 1); + } + if (index[4] === "eq") { + entry = tuples; + } + } + } + } + }, + + getMemory: function (tuple, usePrimary) { + var factHash = tuple.factHash, + indexes = this.indexes, + entry = this.tables, + i = -1, l = indexes.length, + ret = entry.tuples, + lookup = usePrimary ? 2 : 3, + inequalityThreshold = this.inequalityThreshold, + notPossibles = [], npl = 0, rl; + + while (++i < l) { + var index = indexes[i], + val = index[lookup](factHash), + currEntry = entry.tables[index[0]]; + if (currEntry) { + var nextEntry = currEntry.get(val), tuples, tl; + if (index[4] === "neq") { + rl = ret.length; + if (!nextEntry) { + ret = rl ? ret : entry.tuples; + } else { + tuples = nextEntry.tuples; + tl = tuples.length; + if (!tl || !rl) { + ret = entry.tuples; + } else if (tl === entry.tuples.length) { + ret = []; + i = l; + } else if (tl) { + pPush.apply(notPossibles, tuples); + npl += tl; + } + } + } else if (nextEntry) { + tuples = nextEntry.tuples; + tl = tuples.length; + if (tl) { + ret = nextEntry.tuples; + entry = nextEntry; + } else { + i = l; + ret = []; + } + } else { + i = l; + ret = []; + } + } else { + ret = []; + i = l; + } + } + rl = ret.length; + if (npl && rl && (npl / rl) > inequalityThreshold) { + //console.log(npl); + ret = difference(ret, notPossibles); + } + return ret.slice(); + }, + + __createIndexTree: function () { + var table = this.tables.tables = {}; + var indexes = this.indexes; + table[indexes[0][0]] = new HashTable(); + + }, + + + addIndex: function (primary, lookup, op) { + this.indexes.push([primary, lookup, plucker(primary), plucker(lookup), op || "eq"]); + this.indexes.sort(function (a, b) { + var aOp = a[4], bOp = b[4]; + return aOp === bOp ? 0 : aOp > bOp ? 1 : -1; + }); + this.__createIndexTree(); + } + + } + +}).as(module); diff --git a/lib/nodes/misc/rightMemory.js b/lib/nodes/misc/rightMemory.js new file mode 100644 index 0000000..f77c2b1 --- /dev/null +++ b/lib/nodes/misc/rightMemory.js @@ -0,0 +1,12 @@ +var Memory = require("./memory"); + +Memory.extend({ + + instance: { + + getRightMemory: function (tuple) { + return this.getMemory(tuple); + } + } + +}).as(module); \ No newline at end of file diff --git a/lib/nodes/node.js b/lib/nodes/node.js index 4039847..b486aa2 100644 --- a/lib/nodes/node.js +++ b/lib/nodes/node.js @@ -1,7 +1,7 @@ var extd = require("../extended"), forEach = extd.forEach, indexOf = extd.indexOf, - intersect = extd.intersect, + intersection = extd.intersection, declare = extd.declare, HashTable = extd.HashTable, Context = require("../context"); @@ -76,13 +76,11 @@ declare({ entry = entrySet[i]; outNode = entry.key; paths = entry.value; - if (context.paths) { - if ((continuingPaths = intersect(paths, context.paths)).length) { - outNode[method](new Context(context.fact, continuingPaths, context.match)); - } - } else { - outNode[method](context); + + if ((continuingPaths = intersection(paths, context.paths)).length) { + outNode[method](new Context(context.fact, continuingPaths, context.match)); } + } }, diff --git a/lib/nodes/notNode.js b/lib/nodes/notNode.js index 245325e..a6e5ec5 100644 --- a/lib/nodes/notNode.js +++ b/lib/nodes/notNode.js @@ -7,6 +7,8 @@ var JoinNode = require("./joinNode"), JoinNode.extend({ instance: { + nodeType: "NotNode", + constructor: function () { this._super(arguments); this.leftTupleMemory = {}; @@ -14,53 +16,67 @@ JoinNode.extend({ this.notMatch = new Context(new InitialFact()).match; }, - - toString: function () { - return "NotNode " + this.__count; - }, - __cloneContext: function (context) { return context.clone(null, null, context.match.merge(this.notMatch)); }, retractRight: function (context) { - var ctx = this.removeFromRightMemory(context); - if (ctx) { - var rightContext = ctx.data; - var blocking = rightContext.blocking; - if (blocking.length) { - //if we are blocking left contexts - var leftContext, rightTuples = this.rightTuples, thisConstraint = this.constraint, blockingNode = {next: blocking.head}, node, l = rightTuples.length, rc; - while ((blockingNode = blockingNode.next)) { - leftContext = blockingNode.data; - this.removeFromLeftBlockedMemory(leftContext); - if (l !== 0) { - thisConstraint.setLeftContext(leftContext); - node = ctx; - while ((node = node.next)) { - if (thisConstraint.setRightContext(rc = node.data).isMatch()) { - leftContext.blocker = rc; - this.addToLeftBlockedMemory(rc.blocking.push(leftContext)); - leftContext = null; - break; - } - } - thisConstraint.clearContexts(); - } - if (leftContext) { - this.__addToLeftMemory(leftContext); - this.__propagate("assert", this.__cloneContext(leftContext)); + var ctx = this.removeFromRightMemory(context), + rightContext = ctx.data, + blocking = rightContext.blocking; + if (blocking.length) { + //if we are blocking left contexts + var rm = this.rightTuples.getSimilarMemory(rightContext), l = rm.length, i; + var leftContext, thisConstraint = this.constraint, blockingNode = {next: blocking.head}, rc; + while ((blockingNode = blockingNode.next)) { + leftContext = blockingNode.data; + //this.removeFromLeftBlockedMemory(leftContext); + i = -1; + while (++i < l) { + if (thisConstraint.isMatch(leftContext, rc = rm[i].data)) { + this.blockedContext(leftContext, rc); + leftContext = null; + break; } } - blocking.clear(); + if (leftContext) { + this.notBlockedContext(leftContext, true); + } } - } else { - throw new Error(); + blocking.clear(); } }, + blockedContext: function (leftContext, rightContext, propagate) { + leftContext.blocker = rightContext; + this.removeFromLeftMemory(leftContext); + this.addToLeftBlockedMemory(rightContext.blocking.push(leftContext)); + propagate && this.__propagate("retract", this.__cloneContext(leftContext)); + }, + + notBlockedContext: function (leftContext, propagate) { + this.__addToLeftMemory(leftContext); + propagate && this.__propagate("assert", this.__cloneContext(leftContext)); + }, + + propagateFromLeft: function (leftContext) { + this.notBlockedContext(leftContext, true); + }, + + propagateFromRight: function (leftContext) { + this.notBlockedContext(leftContext, true); + }, + + blockFromAssertRight: function (leftContext, rightContext) { + this.blockedContext(leftContext, rightContext, true); + }, + + blockFromAssertLeft: function (leftContext, rightContext) { + this.blockedContext(leftContext, rightContext, false); + }, + retractLeft: function (context) { var ctx = this.removeFromLeftMemory(context); @@ -75,44 +91,31 @@ JoinNode.extend({ }, assertLeft: function (context) { - var values = this.rightTuples, - node, - thisConstraint = this.constraint, rc; - if (values.length) { - node = {next: values.head}; - thisConstraint.setLeftContext(context); - while ((node = node.next) && context) { - if (thisConstraint.setRightContext(rc = node.data).isMatch()) { - context.blocker = rc; - this.addToLeftBlockedMemory(rc.blocking.push(context)); - context = null; - } + var values = this.rightTuples.getRightMemory(context), + thisConstraint = this.constraint, rc, i = -1, l = values.length; + while (++i < l) { + if (thisConstraint.isMatch(context, rc = values[i].data)) { + this.blockFromAssertLeft(context, rc); + context = null; + i = l; } - thisConstraint.clearContexts(); } if (context) { - this.__addToLeftMemory(context); - this.__propagate("assert", this.__cloneContext(context)); + this.propagateFromLeft(context); } }, assertRight: function (context) { this.__addToRightMemory(context); context.blocking = new LinkedList(); - var fl = this.leftTuples, leftContext, node, thisConstraint = this.constraint; - if (fl.length) { - node = {next: fl.head}; - thisConstraint.setRightContext(context); - while ((node = node.next)) { - leftContext = node.data; - if (thisConstraint.setLeftContext(leftContext).isMatch()) { - this.__propagate("retract", this.__cloneContext(leftContext)); - this.removeFromLeftMemory(leftContext); - leftContext.blocker = context; - this.addToLeftBlockedMemory(context.blocking.push(leftContext)); - } + var fl = this.leftTuples.getLeftMemory(context), + i = -1, l = fl.length, + leftContext, thisConstraint = this.constraint; + while (++i < l) { + leftContext = fl[i].data; + if (thisConstraint.isMatch(leftContext, context)) { + this.blockFromAssertRight(leftContext, context); } - thisConstraint.clearContexts(); } }, @@ -139,10 +142,10 @@ JoinNode.extend({ var ctx = this.removeFromLeftMemory(context), leftContext, thisConstraint = this.constraint, - rightTuples = this.rightTuples, + rightTuples = this.rightTuples.getRightMemory(context), l = rightTuples.length, isBlocked = false, - node, rc, blocker; + i, rc, blocker; if (!ctx) { //blocked before ctx = this.removeFromLeftBlockedMemory(context); @@ -156,8 +159,7 @@ JoinNode.extend({ blocker = this.rightMemory[leftContext.blocker.hashCode]; } if (blocker) { - thisConstraint.setLeftContext(context); - if (thisConstraint.setRightContext(rc = blocker.data).isMatch()) { + if (thisConstraint.isMatch(context, rc = blocker.data)) { //we cant be proagated so retract previous if (!isBlocked) { //we were asserted before so retract @@ -167,18 +169,12 @@ JoinNode.extend({ this.addToLeftBlockedMemory(rc.blocking.push(context)); context = null; } - if (context) { - node = {next: blocker.next}; - } - } else { - node = {next: rightTuples.head}; } if (context && l) { - node = {next: rightTuples.head}; + i = -1; //we were propogated before - thisConstraint.setLeftContext(context); - while ((node = node.next)) { - if (thisConstraint.setRightContext(rc = node.data).isMatch()) { + while (++i < l) { + if (thisConstraint.isMatch(context, rc = rightTuples[i].data)) { //we cant be proagated so retract previous if (!isBlocked) { //we were asserted before so retract @@ -190,7 +186,6 @@ JoinNode.extend({ break; } } - thisConstraint.clearContexts(); } if (context) { //we can still be propogated @@ -214,58 +209,50 @@ JoinNode.extend({ var ctx = this.removeFromRightMemory(context); if (ctx) { var rightContext = ctx.data, - leftTuples = this.leftTuples, + leftTuples = this.leftTuples.getLeftMemory(context), leftTuplesLength = leftTuples.length, leftContext, thisConstraint = this.constraint, - node, + i, node, blocking = rightContext.blocking; this.__addToRightMemory(context); context.blocking = new LinkedList(); - if (leftTuplesLength || blocking.length) { - if (blocking.length) { - var rc; - //check old blocked contexts - //check if the same contexts blocked before are still blocked - var blockingNode = {next: blocking.head}; - while ((blockingNode = blockingNode.next)) { - leftContext = blockingNode.data; - leftContext.blocker = null; - thisConstraint.setRightContext(context); - thisConstraint.setLeftContext(leftContext); - if (thisConstraint.isMatch()) { - leftContext.blocker = context; - this.addToLeftBlockedMemory(context.blocking.push(leftContext)); + + var rc; + //check old blocked contexts + //check if the same contexts blocked before are still blocked + var blockingNode = {next: blocking.head}; + while ((blockingNode = blockingNode.next)) { + leftContext = blockingNode.data; + leftContext.blocker = null; + if (thisConstraint.isMatch(leftContext, context)) { + leftContext.blocker = context; + this.addToLeftBlockedMemory(context.blocking.push(leftContext)); + leftContext = null; + } else { + //we arent blocked anymore + leftContext.blocker = null; + node = ctx; + while ((node = node.next)) { + if (thisConstraint.isMatch(leftContext, rc = node.data)) { + leftContext.blocker = rc; + this.addToLeftBlockedMemory(rc.blocking.push(leftContext)); leftContext = null; - } else { - //we arent blocked anymore - leftContext.blocker = null; - node = ctx; - while ((node = node.next)) { - if (thisConstraint.setRightContext(rc = node.data).isMatch()) { - leftContext.blocker = rc; - this.addToLeftBlockedMemory(rc.blocking.push(leftContext)); - leftContext = null; - break; - } - } - if (leftContext) { - this.__addToLeftMemory(leftContext); - this.__propagate("assert", this.__cloneContext(leftContext)); - } - thisConstraint.clearContexts(); + break; } } - thisConstraint.clearContexts(); + if (leftContext) { + this.__addToLeftMemory(leftContext); + this.__propagate("assert", this.__cloneContext(leftContext)); + } } if (leftTuplesLength) { //check currently left tuples in memory - thisConstraint.setRightContext(context); - node = {next: leftTuples.head}; - while ((node = node.next)) { - leftContext = node.data; - if (thisConstraint.setLeftContext(leftContext).isMatch()) { + i = -1; + while (++i < leftTuplesLength) { + leftContext = leftTuples[i].data; + if (thisConstraint.isMatch(leftContext, context)) { this.__propagate("retract", this.__cloneContext(leftContext)); this.removeFromLeftMemory(leftContext); this.addToLeftBlockedMemory(context.blocking.push(leftContext)); diff --git a/lib/nodes/rightAdapterNode.js b/lib/nodes/rightAdapterNode.js index 98fa684..100570a 100644 --- a/lib/nodes/rightAdapterNode.js +++ b/lib/nodes/rightAdapterNode.js @@ -1,4 +1,4 @@ -var Node = require("./node"); +var Node = require("./adapterNode"); Node.extend({ instance: { diff --git a/lib/nodes/terminalNode.js b/lib/nodes/terminalNode.js index 5e9d7b2..6e04df5 100644 --- a/lib/nodes/terminalNode.js +++ b/lib/nodes/terminalNode.js @@ -1,7 +1,6 @@ var Node = require("./node"), extd = require("../extended"), - bind = extd.bind, - removeDuplicates = extd.removeDuplicates; + bind = extd.bind; Node.extend({ instance: { @@ -18,11 +17,6 @@ Node.extend({ __assertModify: function (context) { var match = context.match; - match.recency.sort( - function (a, b) { - return a - b; - }).reverse(); - match.facts = removeDuplicates(match.facts); if (match.isMatch) { var rule = this.rule, bucket = this.bucket; this.agenda.insert(this, { diff --git a/lib/nodes/typeNode.js b/lib/nodes/typeNode.js index 987fe5e..dbcf821 100644 --- a/lib/nodes/typeNode.js +++ b/lib/nodes/typeNode.js @@ -42,4 +42,5 @@ AlphaNode.extend({ } } } -}).as(module); \ No newline at end of file +}).as(module); + diff --git a/lib/parser/nools/tokens.js b/lib/parser/nools/tokens.js index 495a7db..3ac7080 100644 --- a/lib/parser/nools/tokens.js +++ b/lib/parser/nools/tokens.js @@ -4,7 +4,10 @@ var utils = require("./util.js"), fs = require("fs"), extd = require("../../extended"), filter = extd.filter, - indexOf = extd.indexOf; + indexOf = extd.indexOf, + predicates = ["not", "or", "exists"], + predicateRegExp = new RegExp("^(" + predicates.join("|") + ") *\\((.*)\\)$", "m"), + predicateBeginExp = new RegExp(" *(" + predicates.join("|") + ") *\\(", "g"); var isWhiteSpace = function (str) { return str.replace(/[\s|\n|\r|\t]/g, "").length === 0; @@ -16,14 +19,14 @@ var joinFunc = function (m, str) { var splitRuleLineByPredicateExpressions = function (ruleLine) { var str = ruleLine.replace(/,\s*(\$?\w+\s*:)/g, joinFunc); - var parts = filter(str.split(/ *(not|or) *\(/g), function (str) { + var parts = filter(str.split(predicateBeginExp), function (str) { return str !== ""; }), l = parts.length, ret = []; if (l) { for (var i = 0; i < l; i++) { - if (parts[i] === "not" || parts[i] === "or") { + if (indexOf(predicates, parts[i]) !== -1) { ret.push([parts[i], "(", parts[++i].replace(/, *$/, "")].join("")); } else { ret.push(parts[i].replace(/, *$/, "")); @@ -109,7 +112,6 @@ var ruleTokens = { var ruleRegExp = /^(\$?\w+) *: *(\w+)(.*)/; var constraintRegExp = /(\{ *(?:["']?\$?\w+["']?\s*:\s*["']?\$?\w+["']? *(?:, *["']?\$?\w+["']?\s*:\s*["']?\$?\w+["']?)*)+ *\})/; - var predicateExp = /^(not|or) *\((.*)\)$/m; var fromRegExp = /(\bfrom\s+.*)/; var parseRules = function (str) { var rules = []; @@ -117,8 +119,8 @@ var ruleTokens = { for (var i = 0; i < l && (ruleLine = ruleLines[i].replace(/^\s*|\s*$/g, "").replace(/\n/g, "")); i++) { if (!isWhiteSpace(ruleLine)) { var rule = []; - if (predicateExp.test(ruleLine)) { - var m = ruleLine.match(predicateExp); + if (predicateRegExp.test(ruleLine)) { + var m = ruleLine.match(predicateRegExp); var pred = m[1].replace(/^\s*|\s*$/g, ""); rule.push(pred); ruleLine = m[2].replace(/^\s*|\s*$/g, ""); diff --git a/lib/pattern.js b/lib/pattern.js index b4abf38..c776e2f 100644 --- a/lib/pattern.js +++ b/lib/pattern.js @@ -96,6 +96,8 @@ var FromPattern = ObjectPattern.extend({ FromPattern.extend().as(exports, "FromNotPattern"); ObjectPattern.extend().as(exports, "NotPattern"); +ObjectPattern.extend().as(exports, "ExistsPattern"); +FromPattern.extend().as(exports, "FromExistsPattern"); Pattern.extend({ @@ -136,7 +138,7 @@ var InitialFact = declare({ ObjectPattern.extend({ instance: { constructor: function () { - this._super([InitialFact, "i", [], {}]); + this._super([InitialFact, "__i__", [], {}]); }, assert: function () { diff --git a/lib/rule.js b/lib/rule.js index 7fce389..fe44bc6 100644 --- a/lib/rule.js +++ b/lib/rule.js @@ -11,7 +11,9 @@ var extd = require("./extended"), ObjectPattern = pattern.ObjectPattern, FromPattern = pattern.FromPattern, NotPattern = pattern.NotPattern, + ExistsPattern = pattern.ExistsPattern, FromNotPattern = pattern.FromNotPattern, + FromExistsPattern = pattern.FromExistsPattern, CompositePattern = pattern.CompositePattern; var parseExtra = extd @@ -122,7 +124,7 @@ var parsePattern = extd return parsePattern(cond); }).flatten().value(); }) - .contains("not", 0, function (condition) { + .containsAt("not", 0, function (condition) { condition.shift(); condition = normailizeConstraint(condition); if (condition[4] && condition[4].from) { @@ -148,6 +150,32 @@ var parsePattern = extd ]; } }) + .containsAt("exists", 0, function (condition) { + condition.shift(); + condition = normailizeConstraint(condition); + if (condition[4] && condition[4].from) { + return [ + new FromExistsPattern( + getParamType(condition[0]), + condition[1] || "m", + parser.parseConstraint(condition[2] || "true"), + condition[3] || {}, + parser.parseConstraint(condition[4].from), + {scope: condition.scope, pattern: condition[2]} + ) + ]; + } else { + return [ + new ExistsPattern( + getParamType(condition[0]), + condition[1] || "m", + parser.parseConstraint(condition[2] || "true"), + condition[3] || {}, + {scope: condition.scope, pattern: condition[2]} + ) + ]; + } + }) .def(function (condition) { condition = normailizeConstraint(condition); if (condition[4] && condition[4].from) { diff --git a/nools.js b/nools.js index 74ecac1..24444d4 100644 --- a/nools.js +++ b/nools.js @@ -66,7 +66,6 @@ var FactHash = declare({ this.memoryValues.push((this.memory[hashCode] = insert)); } } - }); @@ -218,7 +217,7 @@ module.exports = declare(EventEmitter, { } }); -},{"./extended":12,"events":50}],4:[function(require,module,exports){ +},{"./extended":12,"events":64}],4:[function(require,module,exports){ /*jshint evil:true*/ "use strict"; var extd = require("../extended"), @@ -474,7 +473,7 @@ exports.transpile = require("./transpile").transpile; -},{"../constraintMatcher.js":9,"../extended":12,"../parser":34,"../rule":39,"./common":4,"./transpile":6,"__browserify_Buffer":53}],6:[function(require,module,exports){ +},{"../constraintMatcher.js":9,"../extended":12,"../parser":41,"../rule":46,"./common":4,"./transpile":6,"__browserify_Buffer":67}],6:[function(require,module,exports){ var Buffer=require("__browserify_Buffer").Buffer;var extd = require("../extended"), forEach = extd.forEach, indexOf = extd.indexOf, @@ -647,7 +646,7 @@ exports.transpile = function (flowObj, options) { -},{"../constraintMatcher":9,"../extended":12,"../parser":34,"__browserify_Buffer":53}],7:[function(require,module,exports){ +},{"../constraintMatcher":9,"../extended":12,"../parser":41,"__browserify_Buffer":67}],7:[function(require,module,exports){ var map = require("./extended").map; function salience(a, b) { @@ -660,6 +659,7 @@ function bucketCounter(a, b) { function factRecency(a, b) { /*jshint noempty: false*/ + var i = 0; var aMatchRecency = a.match.recency, bMatchRecency = b.match.recency, aLength = aMatchRecency.length - 1, bLength = bMatchRecency.length - 1; @@ -697,7 +697,7 @@ exports.strategy = function (strats) { while (++i < stratsLength && !ret) { ret = strats[i](a, b); } - ret = ret > 0 ? 1: -1; + ret = ret > 0 ? 1 : -1; } return ret; }; @@ -716,13 +716,14 @@ var extd = require("./extended"), var id = 0; var Constraint = declare({ + type: null, + instance: { - constructor: function (type, constraint) { + constructor: function (constraint) { if (!constraintMatcher) { constraintMatcher = require("./constraintMatcher"); } this.id = id++; - this.type = type; this.constraint = constraint; extd.bindAll(this, ["assert"]); }, @@ -730,6 +731,10 @@ var Constraint = declare({ throw new Error("not implemented"); }, + getIndexableProperties: function () { + return []; + }, + equal: function (constraint) { return instanceOf(constraint, this._static) && this.get("alias") === constraint.get("alias") && extd.deepEqual(this.constraint, constraint.constraint); }, @@ -746,8 +751,11 @@ var Constraint = declare({ Constraint.extend({ instance: { + + type: "object", + constructor: function (type) { - this._super(["object", type]); + this._super([type]); }, "assert": function (param) { @@ -760,14 +768,17 @@ Constraint.extend({ } }).as(exports, "ObjectConstraint"); -Constraint.extend({ +var EqualityConstraint = Constraint.extend({ instance: { + + type: "equality", + constructor: function (constraint, options) { - this._super(["equality", constraint]); + this._super([constraint]); options = options || {}; this.pattern = options.pattern; - this._matcher = constraintMatcher.getMatcher(constraint, options.scope || {}); + this._matcher = constraintMatcher.getMatcher(constraint, options, true); }, "assert": function (values) { @@ -776,11 +787,19 @@ Constraint.extend({ } }).as(exports, "EqualityConstraint"); +EqualityConstraint.extend({instance: {type: "inequality"}}).as(exports, "InequalityConstraint"); +EqualityConstraint.extend({instance: {type: "comparison"}}).as(exports, "ComparisonConstraint"); + Constraint.extend({ instance: { + + type: "equality", + constructor: function () { - this._super(["equality", [true]]); + this._super([ + [true] + ]); }, equal: function (constraint) { @@ -794,22 +813,25 @@ Constraint.extend({ } }).as(exports, "TrueConstraint"); -Constraint.extend({ +var ReferenceConstraint = Constraint.extend({ instance: { + + type: "reference", + constructor: function (constraint, options) { this.cache = {}; - this._super(["reference", constraint]); + this._super([constraint]); options = options || {}; this.values = []; this.pattern = options.pattern; this._options = options; - this._matcher = constraintMatcher.getMatcher(constraint, options.scope || {}); + this._matcher = constraintMatcher.getMatcher(constraint, options, false); }, - "assert": function (values) { + "assert": function (fact, fh) { try { - return this._matcher(values); + return this._matcher(fact, fh); } catch (e) { throw new Error("Error with evaluating pattern " + this.pattern + " " + e.message); } @@ -818,7 +840,7 @@ Constraint.extend({ merge: function (that) { var ret = this; - if (that instanceof this._static) { + if (that instanceof ReferenceConstraint) { ret = new this._static([this.constraint, that.constraint, "and"], merge({}, this._options, this._options)); ret._alias = this._alias || that._alias; ret.vars = this.vars.concat(that.vars); @@ -854,10 +876,23 @@ Constraint.extend({ }).as(exports, "ReferenceConstraint"); +ReferenceConstraint.extend({instance: { + type: "reference_equality", + op: "eq", + getIndexableProperties: function () { + return constraintMatcher.getIndexableProperties(this.constraint); + } +}}).as(exports, "ReferenceEqualityConstraint") + .extend({instance: {type: "reference_inequality", op: "neq"}}).as(exports, "ReferenceInequalityConstraint"); + + Constraint.extend({ instance: { + + type: "hash", + constructor: function (hash) { - this._super(["hash", hash]); + this._super([hash]); }, equal: function (constraint) { @@ -881,7 +916,7 @@ Constraint.extend({ instance: { constructor: function (constraints, options) { this.type = "from"; - this.constraints = constraintMatcher.getSourceMatcher(constraints, (options || {}).scope || {}); + this.constraints = constraintMatcher.getSourceMatcher(constraints, (options || {}), true); extd.bindAll(this, ["assert"]); }, @@ -912,12 +947,19 @@ var extd = require("./extended"), isArray = extd.isArray, forEach = extd.forEach, some = extd.some, - map = extd.map, indexOf = extd.indexOf, isNumber = extd.isNumber, removeDups = extd.removeDuplicates, atoms = require("./constraint"); +function getProps(val) { + return extd(val).map(function mapper(val) { + return isArray(val) ? isArray(val[0]) ? getProps(val).value() : val.reverse().join(".") : val; + }).flatten().filter(function (v) { + return !!v; + }); +} + var definedFuncs = { indexOf: extd.indexOf, now: function () { @@ -1007,6 +1049,43 @@ var lang = { return ret; }, + __getProperties: function (rule) { + var ret = []; + if (rule) { + var rule2 = rule[2]; + if (!rule2) { + return ret; + } + if (rule2 !== "prop" && + rule2 !== "identifier" && + rule2 !== "string" && + rule2 !== "number" && + rule2 !== "boolean" && + rule2 !== "regexp" && + rule2 !== "unary" && + rule2 !== "unary") { + ret[0] = this.__getProperties(rule[0]); + ret[1] = this.__getProperties(rule[1]); + } else if (rule2 === "identifier") { + //at the bottom + ret = [rule[0]]; + } else { + ret = lang.__getProperties(rule[1]).concat(lang.__getProperties(rule[0])); + } + } + return ret; + }, + + getIndexableProperties: function (rule) { + if (rule[2] === "composite") { + return this.getIndexableProperties(rule[0]); + } else if (/^(\w+(\['[^']*'])*) *[!=]== (\w+(\['[^']*'])*)$/.test(this.parse(rule))) { + return getProps(this.__getProperties(rule)).flatten().value(); + } else { + return []; + } + }, + getIdentifiers: function (rule) { var ret = []; var rule2 = rule[2]; @@ -1078,13 +1157,17 @@ var lang = { rule2 === "propLookup" || rule2 === "function" || rule2 === "logicalNot") { - if (some(this.getIdentifiers(rule), function (i) { + var isReference = some(this.getIdentifiers(rule), function (i) { return i !== alias && !(i in definedFuncs) && !(i in scope); - })) { - ret.push(new atoms.ReferenceConstraint(rule, options)); + }); + if (rule2 === "eq") { + ret.push(new atoms[isReference ? "ReferenceEqualityConstraint" : "EqualityConstraint"](rule, options)); + } else if (rule2 === "neq") { + ret.push(new atoms[isReference ? "ReferenceInequalityConstraint" : "InequalityConstraint"](rule, options)); } else { - ret.push(new atoms.EqualityConstraint(rule, options)); + ret.push(new atoms[isReference ? "ReferenceConstraint" : "ComparisonConstraint"](rule, options)); } + } return ret; }, @@ -1236,37 +1319,51 @@ var lang = { } }; -var toJs = exports.toJs = function (rule, scope, wrap) { +var matcherCount = 0; +var toJs = exports.toJs = function (rule, scope, alias, equality, wrap) { /*jshint evil:true*/ var js = lang.parse(rule); scope = scope || {}; var vars = lang.getIdentifiers(rule); - var body = "var indexOf = definedFuncs.indexOf;" + map(vars,function (v) { + var closureVars = ["var indexOf = definedFuncs.indexOf; var hasOwnProperty = Object.prototype.hasOwnProperty;"], funcVars = []; + extd(vars).filter(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("'", v, "' in fact ? fact['", v, "'] : hash['", v, "']"); + return true; } ret.push(";"); - return ret.join(""); - }).join("") + " return " + (wrap ? wrap(js) : js) + ""; - var f = new Function("fact, hash, definedFuncs, scope", body); - return function (fact, hash) { - return f(fact, hash, definedFuncs, scope); - }; + closureVars.push(ret.join("")); + return false; + }).forEach(function (v) { + var ret = ["var ", v, " = "]; + if (equality || v !== alias) { + ret.push("fact." + v); + } else if (v === alias) { + ret.push("hash.", v, ""); + } + ret.push(";"); + funcVars.push(ret.join("")); + }); + var closureBody = closureVars.join("") + "return function matcher" + (matcherCount++) + (!equality ? "(fact, hash){" : "(fact){") + funcVars.join("") + " return " + (wrap ? wrap(js) : js) + ";}"; + var f = new Function("definedFuncs, scope", closureBody)(definedFuncs, scope); + //console.log(f.toString()); + return f; }; -exports.getMatcher = function (rule, scope) { - return toJs(rule, scope, function (src) { +exports.getMatcher = function (rule, options, equality) { + options = options || {}; + return toJs(rule, options.scope, options.alias, equality, function (src) { return "!!(" + src + ")"; }); }; -exports.getSourceMatcher = function (rule, scope) { - return toJs(rule, scope, function (src) { +exports.getSourceMatcher = function (rule, options, equality) { + options = options || {}; + return toJs(rule, options.scope, options.alias, equality, function (src) { return src; }); }; @@ -1284,7 +1381,9 @@ exports.getIdentifiers = function (constraint) { return lang.getIdentifiers(constraint); }; - +exports.getIndexableProperties = function (constraint) { + return lang.getIndexableProperties(constraint); +}; },{"./constraint":8,"./extended":12}],10:[function(require,module,exports){ "use strict"; @@ -1295,6 +1394,17 @@ var extd = require("./extended"), union = extd.union, pSlice = Array.prototype.slice; +function createContextHash(paths, hashCode) { + var ret = [], + i = -1, + l = paths.length; + while (++i < l) { + ret.push(paths[i].id); + } + ret.push(hashCode); + return ret.join(":"); +} + var Match = declare({ instance: { constructor: function (assertable) { @@ -1346,7 +1456,8 @@ var Context = declare({ this.paths = paths || null; var match = this.match = mr || new Match(fact); this.factHash = match.factHash; - this.hashCode = match.hashCode; + var hashCode = this.hashCode = match.hashCode; + this.pathsHash = paths ? createContextHash(paths || [], hashCode) : hashCode; this.factIds = match.factIds; }, @@ -1486,21 +1597,117 @@ Promise.extend({ } }).as(module); },{"./extended":12,"./nextTick":17}],12:[function(require,module,exports){ +var arr = require("array-extended"), + unique = arr.unique, + indexOf = arr.indexOf, + map = arr.map, + pSlice = Array.prototype.slice, + pSplice = Array.prototype.splice; + +function plucked(prop) { + var exec = prop.match(/(\w+)\(\)$/); + if (exec) { + prop = exec[1]; + return function (item) { + return item[prop](); + }; + } else { + return function (item) { + return item[prop]; + }; + } +} + +function plucker(prop) { + prop = prop.split("."); + if (prop.length === 1) { + return plucked(prop[0]); + } else { + var pluckers = map(prop, function (prop) { + return plucked(prop); + }); + var l = pluckers.length; + return function (item) { + var i = -1, res = item; + while (++i < l) { + res = pluckers[i](res); + } + return res; + }; + } +} + +function intersection(a, b) { + a = pSlice.call(a); + var aOne, i = -1, l; + l = a.length; + while (++i < l) { + aOne = a[i]; + if (indexOf(b, aOne) === -1) { + pSplice.call(a, i--, 1); + l--; + } + } + return a; +} + +function diffArr(arr1, arr2) { + var ret = [], i = -1, j, l2 = arr2.length, l1 = arr1.length, a, found; + if (l2 > l1) { + ret = arr1.slice(); + while (++i < l2) { + a = arr2[i]; + j = -1; + l1 = ret.length; + while (++j < l1) { + if (ret[j] === a) { + ret.splice(j, 1); + break; + } + } + } + } else { + while (++i < l1) { + a = arr1[i]; + j = -1; + found = false; + while (++j < l2) { + if (arr2[j] === a) { + found = true; + break; + } + } + if (!found) { + ret.push(a); + } + } + } + return ret; +} + +function union(arr1, arr2) { + return unique(arr1.concat(arr2)); +} + module.exports = require("extended")() - .register(require("array-extended")) .register(require("date-extended")) + .register(arr) .register(require("object-extended")) .register(require("string-extended")) .register(require("promise-extended")) .register(require("function-extended")) .register(require("is-extended")) + .register("intersection", intersection) + .register("diffArr", diffArr) + .register("unionArr", union) + .register("plucker", plucker) .register("HashTable", require("ht")) .register("declare", require("declare.js")) .register(require("leafy")) .register("LinkedList", require("./linkedList")); -},{"./linkedList":16,"array-extended":42,"date-extended":43,"declare.js":45,"extended":46,"function-extended":49,"ht":55,"is-extended":56,"leafy":57,"object-extended":58,"promise-extended":59,"string-extended":60}],13:[function(require,module,exports){ +},{"./linkedList":16,"array-extended":49,"date-extended":50,"declare.js":52,"extended":53,"function-extended":56,"ht":69,"is-extended":70,"leafy":71,"object-extended":72,"promise-extended":73,"string-extended":74}],13:[function(require,module,exports){ "use strict"; var extd = require("./extended"), bind = extd.bind, @@ -1600,7 +1807,7 @@ module.exports = declare(EventEmitter, { } }); -},{"./agenda":3,"./executionStrategy":11,"./extended":12,"./nodes":23,"./workingMemory":40,"events":50}],14:[function(require,module,exports){ +},{"./agenda":3,"./executionStrategy":11,"./extended":12,"./nodes":27,"./workingMemory":47,"events":64}],14:[function(require,module,exports){ "use strict"; var extd = require("./extended"), instanceOf = extd.instanceOf, @@ -1709,7 +1916,7 @@ var FlowContainer = declare({ } }).as(module); -},{"./conflict":7,"./extended":12,"./flow":13,"./pattern":38,"./rule":39}],15:[function(require,module,exports){ +},{"./conflict":7,"./extended":12,"./flow":13,"./pattern":45,"./rule":46}],15:[function(require,module,exports){ /** * * @projectName nools @@ -1785,7 +1992,7 @@ exports.transpile = function (file, options) { }; exports.parse = parse; -},{"./compile":5,"./extended":12,"./flowContainer":14,"fs":51,"path":52}],16:[function(require,module,exports){ +},{"./compile":5,"./extended":12,"./flowContainer":14,"fs":65,"path":66}],16:[function(require,module,exports){ var declare = require("declare.js"); declare({ @@ -1831,6 +2038,33 @@ declare({ } }, + toArray: function () { + var head = {next: this.head}, ret = []; + while ((head = head.next)) { + ret.push(head); + } + return ret; + }, + + removeByData: function (data) { + var head = {next: this.head}; + while ((head = head.next)) { + if (head.data === data) { + this.remove(head); + break; + } + } + }, + + getByData: function (data) { + var head = {next: this.head}; + while ((head = head.next)) { + if (head.data === data) { + return head; + } + } + }, + clear: function () { this.head = this.tail = null; this.length = 0; @@ -1840,7 +2074,7 @@ declare({ }).as(module); -},{"declare.js":45}],17:[function(require,module,exports){ +},{"declare.js":52}],17:[function(require,module,exports){ var process=require("__browserify_process");/*global setImmediate, window, MessageChannel*/ var extd = require("./extended"); var nextTick; @@ -1878,7 +2112,43 @@ if (typeof setImmediate === "function") { } module.exports = nextTick; -},{"./extended":12,"__browserify_process":54}],18:[function(require,module,exports){ +},{"./extended":12,"__browserify_process":68}],18:[function(require,module,exports){ +var Node = require("./node"), + intersection = require("../extended").intersection, + Context = require("../context"); + +Node.extend({ + instance: { + + __propagatePaths: function (method, context) { + var entrySet = this.__entrySet, i = entrySet.length, entry, outNode, paths, continuingPaths; + while (--i > -1) { + entry = entrySet[i]; + outNode = entry.key; + paths = entry.value; + if ((continuingPaths = intersection(paths, context.paths)).length) { + outNode[method](new Context(context.fact, continuingPaths, context.match)); + } + } + }, + + __propagateNoPaths: function (method, context) { + var entrySet = this.__entrySet, i = entrySet.length; + while (--i > -1) { + entrySet[i].key[method](context); + } + }, + + __propagate: function (method, context) { + if (context.paths) { + this.__propagatePaths(method, context); + } else { + this.__propagateNoPaths(method, context); + } + } + } +}).as(module); +},{"../context":10,"../extended":12,"./node":34}],19:[function(require,module,exports){ var AlphaNode = require("./alphaNode"); AlphaNode.extend({ @@ -1910,7 +2180,7 @@ AlphaNode.extend({ } } }).as(module); -},{"./alphaNode":19}],19:[function(require,module,exports){ +},{"./alphaNode":20}],20:[function(require,module,exports){ "use strict"; var Node = require("./node"); @@ -1931,322 +2201,301 @@ Node.extend({ } } }).as(module); -},{"./node":27}],20:[function(require,module,exports){ -var AlphaNode = require("./alphaNode"); - -function createContextHash(context) { - var ret = [], - paths = context.paths, - i = -1, - l = paths.length; - while (++i < l) { - ret.push(paths[i].id); - } - ret.push(context.hashCode); - return ret.join(":"); +},{"./node":34}],21:[function(require,module,exports){ +var extd = require("../extended"), + values = extd.hash.values, + keys = extd.hash.keys, + Node = require("./node"), + LeftMemory = require("./misc/leftMemory"), RightMemory = require("./misc/rightMemory"); -} +Node.extend({ -AlphaNode.extend({ instance: { + nodeType: "BetaNode", + constructor: function () { - this.memory = {}; - this._super(arguments); - this.constraintAssert = this.constraint.assert; + this._super([]); + this.leftMemory = {}; + this.rightMemory = {}; + this.leftTuples = new LeftMemory(); + this.rightTuples = new RightMemory(); }, - assert: function (context) { - var hashCode = createContextHash(context); - if ((this.memory[hashCode] = this.constraintAssert(context.factHash))) { - this.__propagate("assert", context); + __propagate: function (method, context) { + var entrySet = this.__entrySet, i = entrySet.length, entry, outNode; + while (--i > -1) { + entry = entrySet[i]; + outNode = entry.key; + outNode[method](context); } }, - modify: function (context) { - var memory = this.memory, - hashCode = createContextHash(context), - wasMatch = memory[hashCode]; - if ((memory[hashCode] = this.constraintAssert(context.factHash))) { - this.__propagate(wasMatch ? "modify" : "assert", context); - } else if (wasMatch) { - this.__propagate("retract", context); - } + dispose: function () { + this.leftMemory = {}; + this.rightMemory = {}; + this.leftTuples.clear(); + this.rightTuples.clear(); }, - retract: function (context) { - var hashCode = createContextHash(context), - memory = this.memory; - if (memory[hashCode]) { - this.__propagate("retract", context); - } - memory[hashCode] = null; + disposeLeft: function (fact) { + this.leftMemory = {}; + this.leftTuples.clear(); + this.propagateDispose(fact); }, - toString: function () { - return "EqualityNode" + this.__count; - } - } -}).as(module); -},{"./alphaNode":19}],21:[function(require,module,exports){ -var Node = require("./joinNode"), - extd = require("../extended"), - constraint = require("../constraint"), - EqualityConstraint = constraint.EqualityConstraint, - HashConstraint = constraint.HashConstraint, - ReferenceConstraint = constraint.ReferenceConstraint, - Context = require("../context"), - isDefined = extd.isDefined, - isEmpty = extd.isEmpty, - forEach = extd.forEach, - isArray = extd.isArray; - -var DEFAULT_MATCH = { - isMatch: function () { - return false; - } -}; + disposeRight: function (fact) { + this.rightMemory = {}; + this.rightTuples.clear(); + this.propagateDispose(fact); + }, -Node.extend({ - instance: { + hashCode: function () { + return this.nodeType + " " + this.__count; + }, - constructor: function (pattern, wm) { - this._super(arguments); - this.workingMemory = wm; - this.fromMemory = {}; - this.pattern = pattern; - this.type = pattern.get("constraints")[0].assert; - this.alias = pattern.get("alias"); - this.from = pattern.from.assert; - var eqConstraints = this.__equalityConstraints = []; - var vars = []; - forEach(this.constraints = this.pattern.get("constraints").slice(1), function (c) { - if (c instanceof EqualityConstraint || c instanceof ReferenceConstraint) { - eqConstraints.push(c.assert); - } else if (c instanceof HashConstraint) { - vars = vars.concat(c.get("variables")); - } - }); - this.__variables = vars; + toString: function () { + return this.nodeType + " " + this.__count; }, - __createMatches: function (context) { - var fh = context.factHash, o = this.from(fh); - if (isArray(o)) { - for (var i = 0, l = o.length; i < l; i++) { - this.__checkMatch(context, o[i], true); - } - } else if (isDefined(o)) { - this.__checkMatch(context, o, true); + retractLeft: function (context) { + context = this.removeFromLeftMemory(context).data; + var rightMathces = values(context.rightMatches), + i = -1, + l = rightMathces.length; + while (++i < l) { + this.__propagate("retract", rightMathces[i].clone()); } }, - __checkMatch: function (context, o, propogate) { - var newContext; - if ((newContext = this.__createMatch(context, o)).isMatch() && propogate) { - this.__propagate("assert", newContext.clone()); + retractRight: function (context) { + context = this.removeFromRightMemory(context).data; + var leftMatches = values(context.leftMatches), + i = -1, + l = leftMatches.length; + while (++i < l) { + this.__propagate("retract", leftMatches[i].clone()); } - return newContext; }, - __createMatch: function (lc, o) { - if (this.type(o)) { - var createdFact = this.workingMemory.getFactHandle(o, true), - createdContext, - rc = new Context(createdFact) - .set(this.alias, o), - createdFactId = createdFact.id; - var fh = rc.factHash, lcFh = lc.factHash; - for (var key in lcFh) { - fh[key] = lcFh[key]; - } - var eqConstraints = this.__equalityConstraints, vars = this.__variables, i = -1, l = eqConstraints.length; - while (++i < l) { - if (!eqConstraints[i](fh)) { - createdContext = DEFAULT_MATCH; - break; - } - } - var fm = this.fromMemory[createdFactId]; - if (!fm) { - fm = this.fromMemory[createdFactId] = {}; - } - if (!createdContext) { - var prop; - i = -1; - l = vars.length; - while (++i < l) { - prop = vars[i]; - fh[prop] = o[prop]; - } - lc.fromMatches[createdFact.id] = createdContext = rc.clone(createdFact, null, lc.match.merge(rc.match)); - } - fm[lc.hashCode] = [lc, createdContext]; - return createdContext; + assertLeft: function (context) { + this.__addToLeftMemory(context); + var rm = this.rightTuples.getRightMemory(context), i = -1, l = rm.length; + while (++i < l) { + this.propagateFromLeft(context, rm[i].data); } - return DEFAULT_MATCH; }, - retractRight: function () { - throw new Error("Shouldnt have gotten here"); + assertRight: function (context) { + this.__addToRightMemory(context); + var lm = this.leftTuples.getLeftMemory(context), i = -1, l = lm.length; + while (++i < l) { + this.propagateFromRight(context, lm[i].data); + } }, - removeFromFromMemory: function (context) { - var factId = context.fact.id; - var fm = this.fromMemory[factId]; - if (fm) { - var entry; - for (var i in fm) { - entry = fm[i]; - if (entry[1] === context) { - delete fm[i]; - if (isEmpty(fm)) { - delete this.fromMemory[factId]; - } - break; - } + modifyLeft: function (context) { + var previousContext = this.removeFromLeftMemory(context).data; + this.__addToLeftMemory(context); + var rm = this.rightTuples.getRightMemory(context), l = rm.length; + if (!l) { + this.propagateRetract(context); + } else { + var i = -1, + rightMatches = previousContext.rightMatches; + while (++i < l) { + this.propagateAssertModifyFromLeft(context, rightMatches, rm[i].data); } - } + } }, - retractLeft: function (context) { - var ctx = this.removeFromLeftMemory(context); - if (ctx) { - ctx = ctx.data; - var fromMatches = ctx.fromMatches; - for (var i in fromMatches) { - this.removeFromFromMemory(fromMatches[i]); - this.__propagate("retract", fromMatches[i].clone()); + modifyRight: function (context) { + var previousContext = this.removeFromRightMemory(context).data; + this.__addToRightMemory(context); + var lm = this.leftTuples.getLeftMemory(context); + if (!lm.length) { + this.propagateRetract(context); + } else { + var leftMatches = previousContext.leftMatches, i = -1, l = lm.length; + while (++i < l) { + this.propagateAssertModifyFromRight(context, leftMatches, lm[i].data); } } }, - modifyLeft: function (context) { - var ctx = this.removeFromLeftMemory(context), newContext, i, l, factId, fact; - if (ctx) { - this.__addToLeftMemory(context); + propagateFromLeft: function (context, rc) { + this.__propagate("assert", this.__addToMemoryMatches(rc, context, context.clone(null, null, context.match.merge(rc.match)))); + }, - var leftContext = ctx.data, - fromMatches = (context.fromMatches = {}), - rightMatches = leftContext.fromMatches, - o = this.from(context.factHash); + propagateFromRight: function (context, lc) { + this.__propagate("assert", this.__addToMemoryMatches(context, lc, lc.clone(null, null, lc.match.merge(context.match)))); + }, - if (isArray(o)) { - for (i = 0, l = o.length; i < l; i++) { - newContext = this.__checkMatch(context, o[i], false); - if (newContext.isMatch()) { - factId = newContext.fact.id; - if (factId in rightMatches) { - this.__propagate("modify", newContext.clone()); - } else { - this.__propagate("assert", newContext.clone()); - } - } - } - } else if (isDefined(o)) { - newContext = this.__checkMatch(context, o, false); - if (newContext.isMatch()) { - factId = newContext.fact.id; - if (factId in rightMatches) { - this.__propagate("modify", newContext.clone()); - } else { - this.__propagate("assert", newContext.clone()); - } - } - } - for (i in rightMatches) { - if (!(i in fromMatches)) { - this.removeFromFromMemory(rightMatches[i]); - this.__propagate("retract", rightMatches[i].clone()); - } - } + propagateAssertModifyFromLeft: function (context, rightMatches, rm) { + var factId = rm.hashCode; + if (factId in rightMatches) { + this.__propagate("modify", this.__addToMemoryMatches(rm, context, context.clone(null, null, context.match.merge(rm.match)))); } else { - this.assertLeft(context); + this.propagateFromLeft(context, rm); } - fact = context.fact; - factId = fact.id; - var fm = this.fromMemory[factId]; - this.fromMemory[factId] = {}; - if (fm) { - var lc, entry, cc, createdIsMatch, factObject = fact.object; - for (i in fm) { - entry = fm[i]; - lc = entry[0]; - cc = entry[1]; - createdIsMatch = cc.isMatch(); - if (lc.hashCode !== context.hashCode) { - newContext = this.__createMatch(lc, factObject, false); - if (createdIsMatch) { - this.__propagate("retract", cc.clone()); - } - if (newContext.isMatch()) { - this.__propagate(createdIsMatch ? "modify" : "assert", newContext.clone()); - } + }, - } + propagateAssertModifyFromRight: function (context, leftMatches, lm) { + var factId = lm.hashCode; + if (factId in leftMatches) { + this.__propagate("modify", this.__addToMemoryMatches(context, lm, context.clone(null, null, lm.match.merge(context.match)))); + } else { + this.propagateFromRight(context, lm); + } + }, + + removeFromRightMemory: function (context) { + var hashCode = context.hashCode, ret; + context = this.rightMemory[hashCode] || null; + var tuples = this.rightTuples; + if (context) { + var leftMemory = this.leftMemory; + ret = context.data; + var leftMatches = ret.leftMatches; + tuples.remove(context); + var hashCodes = keys(leftMatches), i = -1, l = hashCodes.length; + while (++i < l) { + delete leftMemory[hashCodes[i]].data.rightMatches[hashCode]; } + delete this.rightMemory[hashCode]; } + return context; }, - assertLeft: function (context) { - this.__addToLeftMemory(context); - context.fromMatches = {}; - this.__createMatches(context); + removeFromLeftMemory: function (context) { + var hashCode = context.hashCode; + context = this.leftMemory[hashCode] || null; + if (context) { + var rightMemory = this.rightMemory; + var rightMatches = context.data.rightMatches; + this.leftTuples.remove(context); + for (var i in rightMatches) { + delete rightMemory[i].data.leftMatches[hashCode]; + } + delete this.leftMemory[hashCode]; + } + return context; }, - assertRight: function () { - throw new Error("Shouldnt have gotten here"); + getRightMemoryMatches: function (context) { + var lm = this.leftMemory[context.hashCode], ret = {}; + if (lm) { + ret = lm.rightMatches; + } + return ret; + }, + + __addToMemoryMatches: function (rightContext, leftContext, createdContext) { + var rightFactId = rightContext.hashCode, + rm = this.rightMemory[rightFactId], + lm, leftFactId = leftContext.hashCode; + if (rm) { + rm = rm.data; + if (leftFactId in rm.leftMatches) { + throw new Error("Duplicate left fact entry"); + } + rm.leftMatches[leftFactId] = createdContext; + } + lm = this.leftMemory[leftFactId]; + if (lm) { + lm = lm.data; + if (rightFactId in lm.rightMatches) { + throw new Error("Duplicate right fact entry"); + } + lm.rightMatches[rightFactId] = createdContext; + } + return createdContext; }, + __addToRightMemory: function (context) { + var hashCode = context.hashCode, rm = this.rightMemory; + if (hashCode in rm) { + return false; + } + rm[hashCode] = this.rightTuples.push(context); + context.leftMatches = {}; + return true; + }, - toString: function () { - return "FromNode" + this.__count; - } + __addToLeftMemory: function (context) { + var hashCode = context.hashCode, lm = this.leftMemory; + if (hashCode in lm) { + return false; + } + lm[hashCode] = this.leftTuples.push(context); + context.rightMatches = {}; + return true; + } } + }).as(module); -},{"../constraint":8,"../context":10,"../extended":12,"./joinNode":24}],22:[function(require,module,exports){ -var Node = require("./joinNode"), - extd = require("../extended"), - constraint = require("../constraint"), - EqualityConstraint = constraint.EqualityConstraint, - HashConstraint = constraint.HashConstraint, - ReferenceConstraint = constraint.ReferenceConstraint, - Context = require("../context"), - isDefined = extd.isDefined, - forEach = extd.forEach, - isArray = extd.isArray; +},{"../extended":12,"./misc/leftMemory":31,"./misc/rightMemory":33,"./node":34}],22:[function(require,module,exports){ +var AlphaNode = require("./alphaNode"); -Node.extend({ +AlphaNode.extend({ instance: { - constructor: function (pattern, workingMemory) { + constructor: function () { + this.memory = {}; this._super(arguments); - this.workingMemory = workingMemory; - this.pattern = pattern; - this.type = pattern.get("constraints")[0].assert; - this.alias = pattern.get("alias"); - this.from = pattern.from.assert; - this.fromMemory = {}; - var eqConstraints = this.__equalityConstraints = []; - var vars = []; - forEach(this.constraints = this.pattern.get("constraints").slice(1), function (c) { - if (c instanceof EqualityConstraint || c instanceof ReferenceConstraint) { - eqConstraints.push(c.assert); - } else if (c instanceof HashConstraint) { - vars = vars.concat(c.get("variables")); - } - }); - this.__variables = vars; + this.constraintAssert = this.constraint.assert; + }, + + assert: function (context) { + if ((this.memory[context.pathsHash] = this.constraintAssert(context.factHash))) { + this.__propagate("assert", context); + } + }, + + modify: function (context) { + var memory = this.memory, + hashCode = context.pathsHash, + wasMatch = memory[hashCode]; + if ((memory[hashCode] = this.constraintAssert(context.factHash))) { + this.__propagate(wasMatch ? "modify" : "assert", context); + } else if (wasMatch) { + this.__propagate("retract", context); + } + }, + retract: function (context) { + var hashCode = context.pathsHash, + memory = this.memory; + if (memory[hashCode]) { + this.__propagate("retract", context); + } + memory[hashCode] = null; }, + toString: function () { + return "EqualityNode" + this.__count; + } + } +}).as(module); +},{"./alphaNode":20}],23:[function(require,module,exports){ +var FromNotNode = require("./fromNotNode"), + extd = require("../extended"), + Context = require("../context"), + isDefined = extd.isDefined, + isArray = extd.isArray; + +FromNotNode.extend({ + instance: { + + nodeType: "ExistsFromNode", + retractLeft: function (context) { var ctx = this.removeFromLeftMemory(context); if (ctx) { ctx = ctx.data; - if (!ctx.blocked) { + if (ctx.blocked) { this.__propagate("retract", ctx.clone()); } } @@ -2262,60 +2511,34 @@ Node.extend({ break; } } - } else if(isDefined(o)){ + } else if (isDefined(o)) { context.blocked = this.__isMatch(context, o, true); } var newContextBlocked = context.blocked; - if (!newContextBlocked) { + if (newContextBlocked) { if (leftContextBlocked) { - this.__propagate("assert", context.clone()); - } else { this.__propagate("modify", context.clone()); + } else { + this.__propagate("assert", context.clone()); } - } else if (!leftContextBlocked) { - this.__propagate("retract", leftContext.clone()); + } else if (leftContextBlocked) { + this.__propagate("retract", context.clone()); } }, - modifyLeft: function (context) { - var ctx = this.removeFromLeftMemory(context); - if (ctx) { - this.__addToLeftMemory(context); - this.__modify(context, ctx.data); - } else { - throw new Error(); - } - var fm = this.fromMemory[context.fact.id]; - this.fromMemory[context.fact.id] = {}; - if (fm) { - for (var i in fm) { - // update any contexts associated with this fact - if (i !== context.hashCode) { - var lc = fm[i]; - ctx = this.removeFromLeftMemory(lc); - if (ctx) { - lc = lc.clone(); - lc.blocked = false; - this.__addToLeftMemory(lc); - this.__modify(lc, ctx.data); - } - } - } - } - }, - __findMatches: function (context) { var fh = context.factHash, o = this.from(fh), isMatch = false; if (isArray(o)) { for (var i = 0, l = o.length; i < l; i++) { if (this.__isMatch(context, o[i], true)) { context.blocked = true; + this.__propagate("assert", context.clone()); return; } } - this.__propagate("assert", context.clone()); - } else if (isDefined(o) && !(context.blocked = this.__isMatch(context, o, true))) { + } else if (isDefined(o) && (this.__isMatch(context, o, true))) { + context.blocked = true; this.__propagate("assert", context.clone()); } return isMatch; @@ -2349,1203 +2572,977 @@ Node.extend({ return ret; }, - removeFromLeftMemory: function () { - return this._super(arguments); - }, - assertLeft: function (context) { this.__addToLeftMemory(context); this.__findMatches(context); - }, - - assertRight: function () { - throw new Error("Shouldnt have gotten here"); - }, - - retractRight: function () { - throw new Error("Shouldnt have gotten here"); - }, - - toString: function () { - return "FromNode" + this.__count; } } }).as(module); -},{"../constraint":8,"../context":10,"../extended":12,"./joinNode":24}],23:[function(require,module,exports){ -"use strict"; -var extd = require("../extended"), - forEach = extd.forEach, - some = extd.some, - declare = extd.declare, - pattern = require("../pattern.js"), - ObjectPattern = pattern.ObjectPattern, - FromPattern = pattern.FromPattern, - FromNotPattern = pattern.FromNotPattern, - NotPattern = pattern.NotPattern, - CompositePattern = pattern.CompositePattern, - InitialFactPattern = pattern.InitialFactPattern, - constraints = require("../constraint"), - HashConstraint = constraints.HashConstraint, - ReferenceConstraint = constraints.ReferenceConstraint, - AliasNode = require("./aliasNode"), - EqualityNode = require("./equalityNode"), - JoinNode = require("./joinNode"), - NotNode = require("./notNode"), - FromNode = require("./fromNode"), - FromNotNode = require("./fromNotNode"), - LeftAdapterNode = require("./leftAdapterNode"), - RightAdapterNode = require("./rightAdapterNode"), - TypeNode = require("./typeNode"), - TerminalNode = require("./terminalNode"), - PropertyNode = require("./propertyNode"); +},{"../context":10,"../extended":12,"./fromNotNode":26}],24:[function(require,module,exports){ +var NotNode = require("./notNode"), + LinkedList = require("../linkedList"); -declare({ + +NotNode.extend({ instance: { - constructor: function (wm, agendaTree) { - this.terminalNodes = []; - this.joinNodes = []; - this.nodes = []; - this.constraints = []; - this.typeNodes = []; - this.__ruleCount = 0; - this.bucket = { - counter: 0, - recency: 0 - }; - this.agendaTree = agendaTree; - this.workingMemory = wm; - }, - assertRule: function (rule) { - var terminalNode = new TerminalNode(this.bucket, this.__ruleCount++, rule, this.agendaTree); - this.__addToNetwork(rule, rule.pattern, terminalNode); - this.__mergeJoinNodes(); - this.terminalNodes.push(terminalNode); - }, + nodeType: "ExistsNode", - resetCounter: function () { - this.bucket.counter = 0; + blockedContext: function (leftContext, rightContext) { + leftContext.blocker = rightContext; + this.removeFromLeftMemory(leftContext); + this.addToLeftBlockedMemory(rightContext.blocking.push(leftContext)); + this.__propagate("assert", this.__cloneContext(leftContext)); }, - incrementCounter: function () { - this.bucket.counter++; + notBlockedContext: function (leftContext, propagate) { + this.__addToLeftMemory(leftContext); + propagate && this.__propagate("retract", this.__cloneContext(leftContext)); }, - assertFact: function (fact) { - var typeNodes = this.typeNodes, i = typeNodes.length - 1; - for (; i >= 0; i--) { - typeNodes[i].assert(fact); - } + propagateFromLeft: function (leftContext) { + this.notBlockedContext(leftContext, false); }, - retractFact: function (fact) { - var typeNodes = this.typeNodes, i = typeNodes.length - 1; - for (; i >= 0; i--) { - typeNodes[i].retract(fact); - } - }, - modifyFact: function (fact) { - var typeNodes = this.typeNodes, i = typeNodes.length - 1; - for (; i >= 0; i--) { - typeNodes[i].modify(fact); + retractLeft: function (context) { + var ctx; + if (!this.removeFromLeftMemory(context)) { + if ((ctx = this.removeFromLeftBlockedMemory(context))) { + this.__propagate("retract", this.__cloneContext(ctx.data)); + } else { + throw new Error(); + } } }, - - - containsRule: function (name) { - return some(this.terminalNodes, function (n) { - return n.rule.name === name; - }); - }, - - dispose: function () { - var typeNodes = this.typeNodes, i = typeNodes.length - 1; - for (; i >= 0; i--) { - typeNodes[i].dispose(); + + modifyLeft: function (context) { + var ctx = this.removeFromLeftMemory(context), + leftContext, + thisConstraint = this.constraint, + rightTuples = this.rightTuples, + l = rightTuples.length, + isBlocked = false, + node, rc, blocker; + if (!ctx) { + //blocked before + ctx = this.removeFromLeftBlockedMemory(context); + isBlocked = true; } - }, + if (ctx) { + leftContext = ctx.data; - __mergeJoinNodes: function () { - var joinNodes = this.joinNodes; - for (var i = 0; i < joinNodes.length; i++) { - var j1 = joinNodes[i], j2 = joinNodes[i + 1]; - if (j1 && j2 && j1.constraint.equal(j2.constraint)) { - j1.merge(j2); - joinNodes.splice(i + 1, 1); + if (leftContext && leftContext.blocker) { + //we were blocked before so only check nodes previous to our blocker + blocker = this.rightMemory[leftContext.blocker.hashCode]; } - } - }, + if (blocker) { + if (thisConstraint.isMatch(context, rc = blocker.data)) { + //propogate as a modify or assert + this.__propagate(!isBlocked ? "assert" : "modify", this.__cloneContext(leftContext)); + context.blocker = rc; + this.addToLeftBlockedMemory(rc.blocking.push(context)); + context = null; + } + if (context) { + node = {next: blocker.next}; + } + } else { + node = {next: rightTuples.head}; + } + if (context && l) { + node = {next: rightTuples.head}; + //we were propagated before + while ((node = node.next)) { + if (thisConstraint.isMatch(context, rc = node.data)) { + //we cant be proagated so retract previous - __checkEqual: function (node) { - var constraints = this.constraints, i = constraints.length - 1; - for (; i >= 0; i--) { - var n = constraints[i]; - if (node.equal(n)) { - return n; + //we were asserted before so retract + this.__propagate(!isBlocked ? "assert" : "modify", this.__cloneContext(leftContext)); + + this.addToLeftBlockedMemory(rc.blocking.push(context)); + context.blocker = rc; + context = null; + break; + } + } } - } - constraints.push(node); - return node; - }, + if (context) { + //we can still be propogated + this.__addToLeftMemory(context); + if (isBlocked) { + //we were blocked so retract + this.__propagate("retract", this.__cloneContext(context)); + } - __createTypeNode: function (rule, pattern) { - var ret = new TypeNode(pattern.get("constraints")[0]); - var constraints = this.typeNodes, i = constraints.length - 1; - for (; i >= 0; i--) { - var n = constraints[i]; - if (ret.equal(n)) { - return n; } + } else { + throw new Error(); } - constraints.push(ret); - return ret; - }, - __createEqualityNode: function (rule, constraint) { - return this.__checkEqual(new EqualityNode(constraint)).addRule(rule); - }, - - __createPropertyNode: function (rule, constraint) { - return this.__checkEqual(new PropertyNode(constraint)).addRule(rule); }, - __createAliasNode: function (rule, pattern) { - return this.__checkEqual(new AliasNode(pattern)).addRule(rule); - }, - - __createAdapterNode: function (rule, side) { - return (side === "left" ? new LeftAdapterNode(): new RightAdapterNode()).addRule(rule); - }, - - __createJoinNode: function (rule, pattern, outNode, side) { - var joinNode; - if (pattern.rightPattern instanceof NotPattern) { - joinNode = new NotNode(); - } else if (pattern.rightPattern instanceof FromNotPattern) { - joinNode = new FromNotNode(pattern.rightPattern, this.workingMemory); - } else if (pattern.rightPattern instanceof FromPattern) { - joinNode = new FromNode(pattern.rightPattern, this.workingMemory); - } else { - joinNode = new JoinNode(); - this.joinNodes.push(joinNode); - } - joinNode["__rule__"] = rule; - var parentNode = joinNode; - if (outNode instanceof JoinNode) { - var adapterNode = this.__createAdapterNode(rule, side); - parentNode.addOutNode(adapterNode, pattern); - parentNode = adapterNode; - } - parentNode.addOutNode(outNode, pattern); - return joinNode.addRule(rule); - }, - - __addToNetwork: function (rule, pattern, outNode, side) { - if (pattern instanceof ObjectPattern) { - if ((pattern instanceof NotPattern || pattern instanceof FromPattern || pattern instanceof FromNotPattern) && (!side || side === "left")) { - if (pattern instanceof FromNotPattern) { - this.__createBetaNode(rule, new CompositePattern(new InitialFactPattern(), pattern), outNode, side); - } else { - this.__createBetaNode(rule, new CompositePattern(new InitialFactPattern(), pattern), outNode, side); + modifyRight: function (context) { + var ctx = this.removeFromRightMemory(context); + if (ctx) { + var rightContext = ctx.data, + leftTuples = this.leftTuples, + leftTuplesLength = leftTuples.length, + leftContext, + thisConstraint = this.constraint, + node, + blocking = rightContext.blocking; + this.__addToRightMemory(context); + context.blocking = new LinkedList(); + if (leftTuplesLength || blocking.length) { + if (blocking.length) { + var rc; + //check old blocked contexts + //check if the same contexts blocked before are still blocked + var blockingNode = {next: blocking.head}; + while ((blockingNode = blockingNode.next)) { + leftContext = blockingNode.data; + leftContext.blocker = null; + if (thisConstraint.isMatch(leftContext, context)) { + leftContext.blocker = context; + this.addToLeftBlockedMemory(context.blocking.push(leftContext)); + this.__propagate("assert", this.__cloneContext(leftContext)); + leftContext = null; + } else { + //we arent blocked anymore + leftContext.blocker = null; + node = ctx; + while ((node = node.next)) { + if (thisConstraint.isMatch(leftContext, rc = node.data)) { + leftContext.blocker = rc; + this.addToLeftBlockedMemory(rc.blocking.push(leftContext)); + this.__propagate("assert", this.__cloneContext(leftContext)); + leftContext = null; + break; + } + } + if (leftContext) { + this.__addToLeftMemory(leftContext); + } + } + } } - } else { - this.__createAlphaNode(rule, pattern, outNode, side); - } - } else if (pattern instanceof CompositePattern) { - this.__createBetaNode(rule, pattern, outNode, side); - } - }, - - __createBetaNode: function (rule, pattern, outNode, side) { - var joinNode = this.__createJoinNode(rule, pattern, outNode, side); - this.__addToNetwork(rule, pattern.rightPattern, joinNode, "right"); - this.__addToNetwork(rule, pattern.leftPattern, joinNode, "left"); - outNode.addParentNode(joinNode); - return joinNode; - }, - - - __createAlphaNode: function (rule, pattern, outNode, side) { - var typeNode, parentNode; - if (!(pattern instanceof FromPattern)) { - var constraints = pattern.get("constraints"); - typeNode = this.__createTypeNode(rule, pattern); - var aliasNode = this.__createAliasNode(rule, pattern); - typeNode.addOutNode(aliasNode, pattern); - aliasNode.addParentNode(typeNode); - parentNode = aliasNode; - var i = constraints.length - 1; - for (; i > 0; i--) { - var constraint = constraints[i], node; - if (constraint instanceof HashConstraint) { - node = this.__createPropertyNode(rule, constraint); - } else if (constraint instanceof ReferenceConstraint) { - outNode.constraint.addConstraint(constraint); - continue; - } else { - node = this.__createEqualityNode(rule, constraint); + if (leftTuplesLength) { + //check currently left tuples in memory + node = {next: leftTuples.head}; + while ((node = node.next)) { + leftContext = node.data; + if (thisConstraint.isMatch(leftContext, context)) { + this.__propagate("assert", this.__cloneContext(leftContext)); + this.removeFromLeftMemory(leftContext); + this.addToLeftBlockedMemory(context.blocking.push(leftContext)); + leftContext.blocker = context; + } + } } - parentNode.addOutNode(node, pattern); - node.addParentNode(parentNode); - parentNode = node; - } - if (outNode instanceof JoinNode) { - var adapterNode = this.__createAdapterNode(rule, side); - adapterNode.addParentNode(parentNode); - parentNode.addOutNode(adapterNode, pattern); - parentNode = adapterNode; + } - outNode.addParentNode(parentNode); - parentNode.addOutNode(outNode, pattern); - return typeNode; + } else { + throw new Error(); } - }, - print: function () { - forEach(this.terminalNodes, function (t) { - t.print(" "); - }); + } } -}).as(exports, "RootNode"); - - - - - - -},{"../constraint":8,"../extended":12,"../pattern.js":38,"./aliasNode":18,"./equalityNode":20,"./fromNode":21,"./fromNotNode":22,"./joinNode":24,"./leftAdapterNode":26,"./notNode":28,"./propertyNode":29,"./rightAdapterNode":30,"./terminalNode":31,"./typeNode":32}],24:[function(require,module,exports){ -var extd = require("../extended"), - values = extd.hash.values, - Node = require("./node"), - JoinReferenceNode = require("./joinReferenceNode"), - LinkedList = require("../linkedList"); +}).as(module); +},{"../linkedList":16,"./notNode":35}],25:[function(require,module,exports){ +var JoinNode = require("./joinNode"), + extd = require("../extended"), + constraint = require("../constraint"), + EqualityConstraint = constraint.EqualityConstraint, + HashConstraint = constraint.HashConstraint, + ReferenceConstraint = constraint.ReferenceConstraint, + Context = require("../context"), + isDefined = extd.isDefined, + isEmpty = extd.isEmpty, + forEach = extd.forEach, + isArray = extd.isArray; -Node.extend({ +var DEFAULT_MATCH = { + isMatch: function () { + return false; + } +}; +JoinNode.extend({ instance: { - constructor: function () { - this._super([]); - this.constraint = new JoinReferenceNode(); - this.leftMemory = {}; - this.rightMemory = {}; - this.leftTuples = new LinkedList(); - this.rightTuples = new LinkedList(); - }, - - dispose: function () { - this.leftMemory = {}; - this.rightMemory = {}; - this.leftTuples.clear(); - this.rightTuples.clear(); - }, - - disposeLeft: function (fact) { - this.leftMemory = {}; - this.leftTuples.clear(); - this.propagateDispose(fact); - }, - - disposeRight: function (fact) { - this.rightMemory = {}; - this.rightTuples.clear(); - this.propagateDispose(fact); - }, - - hashCode: function () { - return "JoinNode " + this.__count; - }, - toString: function () { - return "JoinNode " + this.__count; - }, + nodeType: "FromNode", - retractLeft: function (context) { - context = this.removeFromLeftMemory(context); - if (context) { - context = context.data; - var rightMathces = values(context.rightMatches), - i = -1, - l = rightMathces.length; - while (++i < l) { - this.__propagate("retract", rightMathces[i]); + constructor: function (pattern, wm) { + this._super(arguments); + this.workingMemory = wm; + this.fromMemory = {}; + this.pattern = pattern; + this.type = pattern.get("constraints")[0].assert; + this.alias = pattern.get("alias"); + this.from = pattern.from.assert; + var eqConstraints = this.__equalityConstraints = []; + var vars = []; + forEach(this.constraints = this.pattern.get("constraints").slice(1), function (c) { + if (c instanceof EqualityConstraint || c instanceof ReferenceConstraint) { + eqConstraints.push(c.assert); + } else if (c instanceof HashConstraint) { + vars = vars.concat(c.get("variables")); } - } else { - throw new Error(); - } - return this; + }); + this.__variables = vars; }, - retractRight: function (context) { - context = this.removeFromRightMemory(context); - if (context) { - context = context.data; - var leftMatches = values(context.leftMatches), - i = -1, - l = leftMatches.length; - while (++i < l) { - this.__propagate("retract", leftMatches[i]); + __createMatches: function (context) { + var fh = context.factHash, o = this.from(fh); + if (isArray(o)) { + for (var i = 0, l = o.length; i < l; i++) { + this.__checkMatch(context, o[i], true); } - } else { - throw new Error(); - } - return this; - }, - - propagateFromLeft: function (context, constraint, rm) { - var mr; - if ((mr = constraint.setRightContext(rm).match()).isMatch) { - this.__propagate("assert", this.__addToMemoryMatches(rm, context, context.clone(null, null, mr))); - } - return this; - }, - - propagateFromRight: function (context, constraint, lm) { - var mr; - if ((mr = constraint.setLeftContext(lm).match()).isMatch) { - this.__propagate("assert", this.__addToMemoryMatches(context, lm, context.clone(null, null, mr))); + } else if (isDefined(o)) { + this.__checkMatch(context, o, true); } - return this; }, - assertLeft: function (context) { - if (this.__addToLeftMemory(context)) { - var rm = this.rightTuples, node = {next: rm.head}, thisConstraint = this.constraint; - if (rm.length) { - thisConstraint.setLeftContext(context); - while ((node = node.next)) { - this.propagateFromLeft(context, thisConstraint, node.data); - } - thisConstraint.clearContexts(); - } - } else { - this.modifyLeft(context); + __checkMatch: function (context, o, propogate) { + var newContext; + if ((newContext = this.__createMatch(context, o)).isMatch() && propogate) { + this.__propagate("assert", newContext.clone()); } + return newContext; }, - assertRight: function (context) { - if (this.__addToRightMemory(context)) { - var lm = this.leftTuples; - if (lm.length) { - var node = {next: lm.head}, thisConstraint = this.constraint; - thisConstraint.setRightContext(context); - while ((node = node.next)) { - this.propagateFromRight(context, thisConstraint, node.data); + __createMatch: function (lc, o) { + if (this.type(o)) { + var createdFact = this.workingMemory.getFactHandle(o, true), + createdContext, + rc = new Context(createdFact) + .set(this.alias, o), + createdFactId = createdFact.id; + var fh = rc.factHash, lcFh = lc.factHash; + for (var key in lcFh) { + fh[key] = lcFh[key]; + } + var eqConstraints = this.__equalityConstraints, vars = this.__variables, i = -1, l = eqConstraints.length; + while (++i < l) { + if (!eqConstraints[i](fh, fh)) { + createdContext = DEFAULT_MATCH; + break; } - thisConstraint.clearContexts(); } - } else { - this.modifyRight(context); - } - }, - - modifyLeft: function (context) { - var previousContext; - if ((previousContext = this.removeFromLeftMemory(context))) { - previousContext = previousContext.data; - this.__addToLeftMemory(context); - var rm = this.rightTuples, l = rm.length; - if (!l) { - this.propagateRetract(context); - } else { - var thisConstraint = this.constraint, - node = {next: rm.head}, - rightMatches = previousContext.rightMatches; - thisConstraint.setLeftContext(context); - while ((node = node.next)) { - this.propagateAssertModifyFromLeft(context, rightMatches, thisConstraint, node.data); + var fm = this.fromMemory[createdFactId]; + if (!fm) { + fm = this.fromMemory[createdFactId] = {}; + } + if (!createdContext) { + var prop; + i = -1; + l = vars.length; + while (++i < l) { + prop = vars[i]; + fh[prop] = o[prop]; } - thisConstraint.clearContexts(); - + lc.fromMatches[createdFact.id] = createdContext = rc.clone(createdFact, null, lc.match.merge(rc.match)); } - } else { - throw new Error(); + fm[lc.hashCode] = [lc, createdContext]; + return createdContext; } + return DEFAULT_MATCH; + }, + retractRight: function () { + throw new Error("Shouldnt have gotten here"); }, - modifyRight: function (context) { - var previousContext; - if ((previousContext = this.removeFromRightMemory(context))) { - previousContext = previousContext.data; - this.__addToRightMemory(context); - var lm = this.leftTuples; - if (!lm.length) { - this.propagateRetract(context); - } else { - var thisConstraint = this.constraint, - leftMatches = previousContext.leftMatches, - node = {next: lm.head}; - thisConstraint.setRightContext(context); - while ((node = node.next)) { - this.propagateAssertModifyFromRight(context, leftMatches, thisConstraint, node.data); + removeFromFromMemory: function (context) { + var factId = context.fact.id; + var fm = this.fromMemory[factId]; + if (fm) { + var entry; + for (var i in fm) { + entry = fm[i]; + if (entry[1] === context) { + delete fm[i]; + if (isEmpty(fm)) { + delete this.fromMemory[factId]; + } + break; } - thisConstraint.clearContexts(); } - } else { - throw new Error(); } }, - propagateAssertModifyFromLeft: function (context, rightMatches, constraint, rm) { - var factId = rm.hashCode, mr; - if (factId in rightMatches) { - mr = constraint.setRightContext(rm).match(); - var mrIsMatch = mr.isMatch; - if (!mrIsMatch) { - this.__propagate("retract", rightMatches[factId].clone()); - } else { - this.__propagate("modify", this.__addToMemoryMatches(rm, context, context.clone(null, null, mr))); + retractLeft: function (context) { + var ctx = this.removeFromLeftMemory(context); + if (ctx) { + ctx = ctx.data; + var fromMatches = ctx.fromMatches; + for (var i in fromMatches) { + this.removeFromFromMemory(fromMatches[i]); + this.__propagate("retract", fromMatches[i].clone()); } - } else { - this.propagateFromLeft(context, constraint, rm); } }, - propagateAssertModifyFromRight: function (context, leftMatches, constraint, lm) { - var factId = lm.hashCode, mr; - if (factId in leftMatches) { - mr = constraint.setLeftContext(lm).match(); - var mrIsMatch = mr.isMatch; - if (!mrIsMatch) { - this.__propagate("retract", leftMatches[factId].clone()); - } else { - this.__propagate("modify", this.__addToMemoryMatches(context, lm, context.clone(null, null, mr))); - } - } else { - this.propagateFromRight(context, constraint, lm); - } - }, + modifyLeft: function (context) { + var ctx = this.removeFromLeftMemory(context), newContext, i, l, factId, fact; + if (ctx) { + this.__addToLeftMemory(context); - removeFromRightMemory: function (context) { - var hashCode = context.hashCode, ret; - context = this.rightMemory[hashCode] || null; - var tuples = this.rightTuples; - if (context) { - var leftMemory = this.leftMemory; - ret = context.data; - var leftMatches = ret.leftMatches; - tuples.remove(context); - for (var i in leftMatches) { - delete leftMemory[i].data.rightMatches[hashCode]; - } - delete this.rightMemory[hashCode]; - } - return context; - }, + var leftContext = ctx.data, + fromMatches = (context.fromMatches = {}), + rightMatches = leftContext.fromMatches, + o = this.from(context.factHash); - removeFromLeftMemory: function (context) { - var hashCode = context.hashCode; - context = this.leftMemory[hashCode] || null; - if (context) { - var rightMemory = this.rightMemory; - var rightMatches = context.data.rightMatches; - this.leftTuples.remove(context); - for (var i in rightMatches) { - delete rightMemory[i].data.leftMatches[hashCode]; + if (isArray(o)) { + for (i = 0, l = o.length; i < l; i++) { + newContext = this.__checkMatch(context, o[i], false); + if (newContext.isMatch()) { + factId = newContext.fact.id; + if (factId in rightMatches) { + this.__propagate("modify", newContext.clone()); + } else { + this.__propagate("assert", newContext.clone()); + } + } + } + } else if (isDefined(o)) { + newContext = this.__checkMatch(context, o, false); + if (newContext.isMatch()) { + factId = newContext.fact.id; + if (factId in rightMatches) { + this.__propagate("modify", newContext.clone()); + } else { + this.__propagate("assert", newContext.clone()); + } + } } - delete this.leftMemory[hashCode]; - } - return context; - }, - - getRightMemoryMatches: function (context) { - var lm = this.leftMemory[context.hashCode], ret = {}; - if (lm) { - ret = lm.rightMatches; - } - return ret; - }, - - __addToMemoryMatches: function (rightContext, leftContext, createdContext) { - var rightFactId = rightContext.hashCode, - rm = this.rightMemory[rightFactId], - lm, leftFactId = leftContext.hashCode; - if (rm) { - rm = rm.data; - if (leftFactId in rm.leftMatches) { - throw new Error("Duplicate left fact entry"); + for (i in rightMatches) { + if (!(i in fromMatches)) { + this.removeFromFromMemory(rightMatches[i]); + this.__propagate("retract", rightMatches[i].clone()); + } } - rm.leftMatches[leftFactId] = createdContext; + } else { + this.assertLeft(context); } - lm = this.leftMemory[leftFactId]; - if (lm) { - lm = lm.data; - if (rightFactId in lm.rightMatches) { - throw new Error("Duplicate right fact entry"); + fact = context.fact; + factId = fact.id; + var fm = this.fromMemory[factId]; + this.fromMemory[factId] = {}; + if (fm) { + var lc, entry, cc, createdIsMatch, factObject = fact.object; + for (i in fm) { + entry = fm[i]; + lc = entry[0]; + cc = entry[1]; + createdIsMatch = cc.isMatch(); + if (lc.hashCode !== context.hashCode) { + newContext = this.__createMatch(lc, factObject, false); + if (createdIsMatch) { + this.__propagate("retract", cc.clone()); + } + if (newContext.isMatch()) { + this.__propagate(createdIsMatch ? "modify" : "assert", newContext.clone()); + } + + } } - lm.rightMatches[rightFactId] = createdContext; } - return createdContext; }, - __addToRightMemory: function (context) { - var hashCode = context.hashCode, rm = this.rightMemory; - if (hashCode in rm) { - return false; - } - rm[hashCode] = this.rightTuples.push(context); - context.leftMatches = {}; - return true; + assertLeft: function (context) { + this.__addToLeftMemory(context); + context.fromMatches = {}; + this.__createMatches(context); }, - - __addToLeftMemory: function (context) { - var hashCode = context.hashCode, lm = this.leftMemory; - if (hashCode in lm) { - return false; - } - lm[hashCode] = this.leftTuples.push(context); - context.rightMatches = {}; - return true; + assertRight: function () { + throw new Error("Shouldnt have gotten here"); } - } -}).as(module); -},{"../extended":12,"../linkedList":16,"./joinReferenceNode":25,"./node":27}],25:[function(require,module,exports){ -var Node = require("./node"); - -var DEFUALT_CONSTRAINT = { - isDefault: true, - assert: function () { - return true; } -}; - -Node.extend({ +}).as(module); +},{"../constraint":8,"../context":10,"../extended":12,"./joinNode":28}],26:[function(require,module,exports){ +var JoinNode = require("./joinNode"), + extd = require("../extended"), + constraint = require("../constraint"), + EqualityConstraint = constraint.EqualityConstraint, + HashConstraint = constraint.HashConstraint, + ReferenceConstraint = constraint.ReferenceConstraint, + Context = require("../context"), + isDefined = extd.isDefined, + forEach = extd.forEach, + isArray = extd.isArray; +JoinNode.extend({ instance: { - constraint: DEFUALT_CONSTRAINT, - __lc: null, - __rc: null, - __varLength: 0, - __count: 0, - __rcMatch: null, - __lcMatch: null, + nodeType: "FromNotNode", - constructor: function () { + constructor: function (pattern, workingMemory) { this._super(arguments); - this.__fh = {}; - this.__variables = []; - this.isDefault = true; - this.constraintAssert = DEFUALT_CONSTRAINT.assert; - }, - - setLeftContext: function (lc) { - this.__lc = lc; - var match = this.__lcMatch = lc.match; - if (!this.isDefault) { - var newFh = match.factHash, - fh = this.__fh, - prop, - vars = this.__variables, - i = -1, - l = this.__varLength; - while (++i < l) { - prop = vars[i]; - fh[prop] = newFh[prop]; - } - } - return this; - }, + this.workingMemory = workingMemory; + this.pattern = pattern; + this.type = pattern.get("constraints")[0].assert; + this.alias = pattern.get("alias"); + this.from = pattern.from.assert; + this.fromMemory = {}; + var eqConstraints = this.__equalityConstraints = []; + var vars = []; + forEach(this.constraints = this.pattern.get("constraints").slice(1), function (c) { + if (c instanceof EqualityConstraint || c instanceof ReferenceConstraint) { + eqConstraints.push(c.assert); + } else if (c instanceof HashConstraint) { + vars = vars.concat(c.get("variables")); + } + }); + this.__variables = vars; - setRightContext: function (rc) { - this.__rc = rc; - this.__rcMatch = rc.match; - if (!this.isDefault) { - this.__fh[this.__alias] = rc.fact.object; - } - return this; }, - clearContexts: function () { - this.__fh = {}; - this.__lc = null; - this.__rc = null; - this.__lcMatch = this.__rcMatch = null; - return this; + retractLeft: function (context) { + var ctx = this.removeFromLeftMemory(context); + if (ctx) { + ctx = ctx.data; + if (!ctx.blocked) { + this.__propagate("retract", ctx.clone()); + } + } }, - clearRightContext: function () { - this.__rc = null; - this.__fh[this.__alias] = null; - return this; - }, + __modify: function (context, leftContext) { + var leftContextBlocked = leftContext.blocked; + var fh = context.factHash, o = this.from(fh); + if (isArray(o)) { + for (var i = 0, l = o.length; i < l; i++) { + if (this.__isMatch(context, o[i], true)) { + context.blocked = true; + break; + } + } + } else if (isDefined(o)) { + context.blocked = this.__isMatch(context, o, true); + } + var newContextBlocked = context.blocked; + if (!newContextBlocked) { + if (leftContextBlocked) { + this.__propagate("assert", context.clone()); + } else { + this.__propagate("modify", context.clone()); + } + } else if (!leftContextBlocked) { + this.__propagate("retract", leftContext.clone()); + } - clearLeftContext: function () { - this.__lc = null; - var fh = this.__fh = {}, rc = this.__rc; - fh[this.__alias] = rc ? rc.fact.object : null; - return this; }, - addConstraint: function (constraint) { - if (this.constraint.isDefault) { - this.constraint = constraint; - this.isDefault = false; + modifyLeft: function (context) { + var ctx = this.removeFromLeftMemory(context); + if (ctx) { + this.__addToLeftMemory(context); + this.__modify(context, ctx.data); } else { - this.constraint = this.constraint.merge(constraint); + throw new Error(); } - this.__alias = this.constraint.get("alias"); - this.__varLength = (this.__variables = this.__variables.concat(this.constraint.get("variables"))).length; - this.constraintAssert = this.constraint.assert; - }, - - equal: function (constraint) { - if (this.isDefault !== true) { - return this.constraint.equal(constraint.constraint); + var fm = this.fromMemory[context.fact.id]; + this.fromMemory[context.fact.id] = {}; + if (fm) { + for (var i in fm) { + // update any contexts associated with this fact + if (i !== context.hashCode) { + var lc = fm[i]; + ctx = this.removeFromLeftMemory(lc); + if (ctx) { + lc = lc.clone(); + lc.blocked = false; + this.__addToLeftMemory(lc); + this.__modify(lc, ctx.data); + } + } + } } }, - isMatch: function () { - return this.isDefault || this.constraintAssert(this.__fh); + __findMatches: function (context) { + var fh = context.factHash, o = this.from(fh), isMatch = false; + if (isArray(o)) { + for (var i = 0, l = o.length; i < l; i++) { + if (this.__isMatch(context, o[i], true)) { + context.blocked = true; + return; + } + } + this.__propagate("assert", context.clone()); + } else if (isDefined(o) && !(context.blocked = this.__isMatch(context, o, true))) { + this.__propagate("assert", context.clone()); + } + return isMatch; }, - match: function () { - var ret; - if (this.isDefault) { - ret = this.__lcMatch.merge(this.__rcMatch); - } else { - ret = {isMatch: false}; - var fh = this.__fh; - if (this.constraintAssert(fh)) { - ret = this.__lcMatch.merge(this.__rcMatch); + __isMatch: function (oc, o, add) { + var ret = false; + if (this.type(o)) { + var createdFact = this.workingMemory.getFactHandle(o); + var context = new Context(createdFact, null) + .mergeMatch(oc.match) + .set(this.alias, o); + if (add) { + var fm = this.fromMemory[createdFact.id]; + if (!fm) { + fm = this.fromMemory[createdFact.id] = {}; + } + fm[oc.hashCode] = oc; + } + var fh = context.factHash; + var eqConstraints = this.__equalityConstraints; + for (var i = 0, l = eqConstraints.length; i < l; i++) { + if (eqConstraints[i](fh, fh)) { + ret = true; + } else { + ret = false; + break; + } } } return ret; - } - - } - -}).as(module); -},{"./node":27}],26:[function(require,module,exports){ -var Node = require("./node"); - -Node.extend({ - instance: { - propagateAssert: function (context) { - this.__propagate("assertLeft", context); - }, - - propagateRetract: function (context) { - this.__propagate("retractLeft", context); - }, - - propagateResolve: function (context) { - this.__propagate("retractResolve", context); - }, - - propagateModify: function (context) { - this.__propagate("modifyLeft", context); }, - retractResolve: function (match) { - this.__propagate("retractResolve", match); + assertLeft: function (context) { + this.__addToLeftMemory(context); + this.__findMatches(context); }, - dispose: function (context) { - this.propagateDispose(context); + assertRight: function () { + throw new Error("Shouldnt have gotten here"); }, - toString: function () { - return "LeftAdapterNode " + this.__count; + retractRight: function () { + throw new Error("Shouldnt have gotten here"); } - } + } }).as(module); -},{"./node":27}],27:[function(require,module,exports){ +},{"../constraint":8,"../context":10,"../extended":12,"./joinNode":28}],27:[function(require,module,exports){ +"use strict"; var extd = require("../extended"), forEach = extd.forEach, - indexOf = extd.indexOf, - intersect = extd.intersect, + some = extd.some, declare = extd.declare, - HashTable = extd.HashTable, - Context = require("../context"); + pattern = require("../pattern.js"), + ObjectPattern = pattern.ObjectPattern, + FromPattern = pattern.FromPattern, + FromNotPattern = pattern.FromNotPattern, + ExistsPattern = pattern.ExistsPattern, + FromExistsPattern = pattern.FromExistsPattern, + NotPattern = pattern.NotPattern, + CompositePattern = pattern.CompositePattern, + InitialFactPattern = pattern.InitialFactPattern, + constraints = require("../constraint"), + HashConstraint = constraints.HashConstraint, + ReferenceConstraint = constraints.ReferenceConstraint, + AliasNode = require("./aliasNode"), + EqualityNode = require("./equalityNode"), + JoinNode = require("./joinNode"), + BetaNode = require("./betaNode"), + NotNode = require("./notNode"), + FromNode = require("./fromNode"), + FromNotNode = require("./fromNotNode"), + ExistsNode = require("./existsNode"), + ExistsFromNode = require("./existsFromNode"), + LeftAdapterNode = require("./leftAdapterNode"), + RightAdapterNode = require("./rightAdapterNode"), + TypeNode = require("./typeNode"), + TerminalNode = require("./terminalNode"), + PropertyNode = require("./propertyNode"); + +function hasRefernceConstraints(pattern) { + return some(pattern.constraints || [], function (c) { + return c instanceof ReferenceConstraint; + }); +} -var count = 0; declare({ instance: { - constructor: function () { - this.nodes = new HashTable(); - this.rules = []; - this.parentNodes = []; - this.__count = count++; - this.__entrySet = []; + constructor: function (wm, agendaTree) { + this.terminalNodes = []; + this.joinNodes = []; + this.nodes = []; + this.constraints = []; + this.typeNodes = []; + this.__ruleCount = 0; + this.bucket = { + counter: 0, + recency: 0 + }; + this.agendaTree = agendaTree; + this.workingMemory = wm; }, - addRule: function (rule) { - if (indexOf(this.rules, rule) === -1) { - this.rules.push(rule); - } - return this; + assertRule: function (rule) { + var terminalNode = new TerminalNode(this.bucket, this.__ruleCount++, rule, this.agendaTree); + this.__addToNetwork(rule, rule.pattern, terminalNode); + this.__mergeJoinNodes(); + this.terminalNodes.push(terminalNode); }, - merge: function (that) { - that.nodes.forEach(function (entry) { - var patterns = entry.value, node = entry.key; - for (var i = 0, l = patterns.length; i < l; i++) { - this.addOutNode(node, patterns[i]); - } - that.nodes.remove(node); - }, this); - var thatParentNodes = that.parentNodes; - for (var i = 0, l = that.parentNodes.l; i < l; i++) { - var parentNode = thatParentNodes[i]; - this.addParentNode(parentNode); - parentNode.nodes.remove(that); - } - return this; + resetCounter: function () { + this.bucket.counter = 0; }, - resolve: function (mr1, mr2) { - return mr1.hashCode === mr2.hashCode; + incrementCounter: function () { + this.bucket.counter++; }, - print: function (tab) { - console.log(tab + this.toString()); - forEach(this.parentNodes, function (n) { - n.print(" " + tab); - }); + assertFact: function (fact) { + var typeNodes = this.typeNodes, i = typeNodes.length - 1; + for (; i >= 0; i--) { + typeNodes[i].assert(fact); + } }, - addOutNode: function (outNode, pattern) { - if (!this.nodes.contains(outNode)) { - this.nodes.put(outNode, []); - } - this.nodes.get(outNode).push(pattern); - this.__entrySet = this.nodes.entrySet(); + retractFact: function (fact) { + var typeNodes = this.typeNodes, i = typeNodes.length - 1; + for (; i >= 0; i--) { + typeNodes[i].retract(fact); + } }, - addParentNode: function (n) { - if (indexOf(this.parentNodes, n) === -1) { - this.parentNodes.push(n); + modifyFact: function (fact) { + var typeNodes = this.typeNodes, i = typeNodes.length - 1; + for (; i >= 0; i--) { + typeNodes[i].modify(fact); } }, - shareable: function () { - return false; + + containsRule: function (name) { + return some(this.terminalNodes, function (n) { + return n.rule.name === name; + }); }, - __propagate: function (method, context) { - var entrySet = this.__entrySet, i = entrySet.length, entry, outNode, paths, continuingPaths; - while (--i > -1) { - entry = entrySet[i]; - outNode = entry.key; - paths = entry.value; - if (context.paths) { - if ((continuingPaths = intersect(paths, context.paths)).length) { - outNode[method](new Context(context.fact, continuingPaths, context.match)); - } - } else { - outNode[method](context); - } + dispose: function () { + var typeNodes = this.typeNodes, i = typeNodes.length - 1; + for (; i >= 0; i--) { + typeNodes[i].dispose(); } }, - dispose: function (assertable) { - this.propagateDispose(assertable); + __mergeJoinNodes: function () { + var joinNodes = this.joinNodes; + for (var i = 0; i < joinNodes.length; i++) { + var j1 = joinNodes[i], j2 = joinNodes[i + 1]; + if (j1 && j2 && (j1.constraint && j2.constraint && j1.constraint.equal(j2.constraint))) { + j1.merge(j2); + joinNodes.splice(i + 1, 1); + } + } }, - retract: function (assertable) { - this.propagateRetract(assertable); + __checkEqual: function (node) { + var constraints = this.constraints, i = constraints.length - 1; + for (; i >= 0; i--) { + var n = constraints[i]; + if (node.equal(n)) { + return n; + } + } + constraints.push(node); + return node; }, - propagateDispose: function (assertable, outNodes) { - outNodes = outNodes || this.nodes; - var entrySet = this.__entrySet, i = entrySet.length - 1; + __createTypeNode: function (rule, pattern) { + var ret = new TypeNode(pattern.get("constraints")[0]); + var constraints = this.typeNodes, i = constraints.length - 1; for (; i >= 0; i--) { - var entry = entrySet[i], outNode = entry.key; - outNode.dispose(assertable); + var n = constraints[i]; + if (ret.equal(n)) { + return n; + } } + constraints.push(ret); + return ret; }, - propagateAssert: function (assertable) { - this.__propagate("assert", assertable); + __createEqualityNode: function (rule, constraint) { + return this.__checkEqual(new EqualityNode(constraint)).addRule(rule); }, - propagateRetract: function (assertable) { - this.__propagate("retract", assertable); + __createPropertyNode: function (rule, constraint) { + return this.__checkEqual(new PropertyNode(constraint)).addRule(rule); }, - assert: function (assertable) { - this.propagateAssert(assertable); + __createAliasNode: function (rule, pattern) { + return this.__checkEqual(new AliasNode(pattern)).addRule(rule); }, - modify: function (assertable) { - this.propagateModify(assertable); + __createAdapterNode: function (rule, side) { + return (side === "left" ? new LeftAdapterNode() : new RightAdapterNode()).addRule(rule); }, - propagateModify: function (assertable) { - this.__propagate("modify", assertable); + __createJoinNode: function (rule, pattern, outNode, side) { + var joinNode; + if (pattern.rightPattern instanceof NotPattern) { + joinNode = new NotNode(); + } else if (pattern.rightPattern instanceof FromExistsPattern) { + joinNode = new ExistsFromNode(pattern.rightPattern, this.workingMemory); + } else if (pattern.rightPattern instanceof ExistsPattern) { + joinNode = new ExistsNode(); + } else if (pattern.rightPattern instanceof FromNotPattern) { + joinNode = new FromNotNode(pattern.rightPattern, this.workingMemory); + } else if (pattern.rightPattern instanceof FromPattern) { + joinNode = new FromNode(pattern.rightPattern, this.workingMemory); + } else if (pattern instanceof CompositePattern && !hasRefernceConstraints(pattern.leftPattern) && !hasRefernceConstraints(pattern.rightPattern)) { + joinNode = new BetaNode(); + this.joinNodes.push(joinNode); + } else { + joinNode = new JoinNode(); + this.joinNodes.push(joinNode); + } + joinNode["__rule__"] = rule; + var parentNode = joinNode; + if (outNode instanceof BetaNode) { + var adapterNode = this.__createAdapterNode(rule, side); + parentNode.addOutNode(adapterNode, pattern); + parentNode = adapterNode; + } + parentNode.addOutNode(outNode, pattern); + return joinNode.addRule(rule); + }, + + __addToNetwork: function (rule, pattern, outNode, side) { + if (pattern instanceof ObjectPattern) { + if (!(pattern instanceof InitialFactPattern) && (!side || side === "left")) { + this.__createBetaNode(rule, new CompositePattern(new InitialFactPattern(), pattern), outNode, side); + } else { + this.__createAlphaNode(rule, pattern, outNode, side); + } + } else if (pattern instanceof CompositePattern) { + this.__createBetaNode(rule, pattern, outNode, side); + } + }, + + __createBetaNode: function (rule, pattern, outNode, side) { + var joinNode = this.__createJoinNode(rule, pattern, outNode, side); + this.__addToNetwork(rule, pattern.rightPattern, joinNode, "right"); + this.__addToNetwork(rule, pattern.leftPattern, joinNode, "left"); + outNode.addParentNode(joinNode); + return joinNode; + }, + + + __createAlphaNode: function (rule, pattern, outNode, side) { + var typeNode, parentNode; + if (!(pattern instanceof FromPattern)) { + + var constraints = pattern.get("constraints"); + typeNode = this.__createTypeNode(rule, pattern); + var aliasNode = this.__createAliasNode(rule, pattern); + typeNode.addOutNode(aliasNode, pattern); + aliasNode.addParentNode(typeNode); + parentNode = aliasNode; + var i = constraints.length - 1; + for (; i > 0; i--) { + var constraint = constraints[i], node; + if (constraint instanceof HashConstraint) { + node = this.__createPropertyNode(rule, constraint); + } else if (constraint instanceof ReferenceConstraint) { + outNode.constraint.addConstraint(constraint); + continue; + } else { + node = this.__createEqualityNode(rule, constraint); + } + parentNode.addOutNode(node, pattern); + node.addParentNode(parentNode); + parentNode = node; + } + + if (outNode instanceof BetaNode) { + var adapterNode = this.__createAdapterNode(rule, side); + adapterNode.addParentNode(parentNode); + parentNode.addOutNode(adapterNode, pattern); + parentNode = adapterNode; + } + outNode.addParentNode(parentNode); + parentNode.addOutNode(outNode, pattern); + return typeNode; + } + }, + + print: function () { + forEach(this.terminalNodes, function (t) { + t.print(" "); + }); } } +}).as(exports, "RootNode"); -}).as(module); -},{"../context":10,"../extended":12}],28:[function(require,module,exports){ -var JoinNode = require("./joinNode"), - LinkedList = require("../linkedList"), - Context = require("../context"), - InitialFact = require("../pattern").InitialFact; -JoinNode.extend({ - instance: { - constructor: function () { - this._super(arguments); - this.leftTupleMemory = {}; - //use this ensure a unique match for and propagated context. - this.notMatch = new Context(new InitialFact()).match; - }, +},{"../constraint":8,"../extended":12,"../pattern.js":45,"./aliasNode":19,"./betaNode":21,"./equalityNode":22,"./existsFromNode":23,"./existsNode":24,"./fromNode":25,"./fromNotNode":26,"./joinNode":28,"./leftAdapterNode":30,"./notNode":35,"./propertyNode":36,"./rightAdapterNode":37,"./terminalNode":38,"./typeNode":39}],28:[function(require,module,exports){ +var BetaNode = require("./betaNode"), + JoinReferenceNode = require("./joinReferenceNode"); - toString: function () { - return "NotNode " + this.__count; - }, +BetaNode.extend({ - __cloneContext: function (context) { - return context.clone(null, null, context.match.merge(this.notMatch)); + instance: { + constructor: function () { + this._super(arguments); + this.constraint = new JoinReferenceNode(this.leftTuples, this.rightTuples); }, + nodeType: "JoinNode", - retractRight: function (context) { - var ctx = this.removeFromRightMemory(context); - if (ctx) { - var rightContext = ctx.data; - var blocking = rightContext.blocking; - if (blocking.length) { - //if we are blocking left contexts - var leftContext, rightTuples = this.rightTuples, thisConstraint = this.constraint, blockingNode = {next: blocking.head}, node, l = rightTuples.length, rc; - while ((blockingNode = blockingNode.next)) { - leftContext = blockingNode.data; - this.removeFromLeftBlockedMemory(leftContext); - if (l !== 0) { - thisConstraint.setLeftContext(leftContext); - node = ctx; - while ((node = node.next)) { - if (thisConstraint.setRightContext(rc = node.data).isMatch()) { - leftContext.blocker = rc; - this.addToLeftBlockedMemory(rc.blocking.push(leftContext)); - leftContext = null; - break; - } - } - thisConstraint.clearContexts(); - } - if (leftContext) { - this.__addToLeftMemory(leftContext); - this.__propagate("assert", this.__cloneContext(leftContext)); - } - } - blocking.clear(); - } - } else { - throw new Error(); + propagateFromLeft: function (context, rm) { + var mr; + if ((mr = this.constraint.match(context, rm)).isMatch) { + this.__propagate("assert", this.__addToMemoryMatches(rm, context, context.clone(null, null, mr))); } - + return this; }, - - retractLeft: function (context) { - var ctx = this.removeFromLeftMemory(context); - if (ctx) { - ctx = ctx.data; - this.__propagate("retract", this.__cloneContext(ctx)); - } else { - if (!this.removeFromLeftBlockedMemory(context)) { - throw new Error(); - } + propagateFromRight: function (context, lm) { + var mr; + if ((mr = this.constraint.match(lm, context)).isMatch) { + this.__propagate("assert", this.__addToMemoryMatches(context, lm, context.clone(null, null, mr))); } + return this; }, - assertLeft: function (context) { - var values = this.rightTuples, - node, - thisConstraint = this.constraint, rc; - if (values.length) { - node = {next: values.head}; - thisConstraint.setLeftContext(context); - while ((node = node.next) && context) { - if (thisConstraint.setRightContext(rc = node.data).isMatch()) { - context.blocker = rc; - this.addToLeftBlockedMemory(rc.blocking.push(context)); - context = null; - } + propagateAssertModifyFromLeft: function (context, rightMatches, rm) { + var factId = rm.hashCode, mr; + if (factId in rightMatches) { + mr = this.constraint.match(context, rm); + var mrIsMatch = mr.isMatch; + if (!mrIsMatch) { + this.__propagate("retract", rightMatches[factId].clone()); + } else { + this.__propagate("modify", this.__addToMemoryMatches(rm, context, context.clone(null, null, mr))); } - thisConstraint.clearContexts(); - } - if (context) { - this.__addToLeftMemory(context); - this.__propagate("assert", this.__cloneContext(context)); + } else { + this.propagateFromLeft(context, rm); } }, - assertRight: function (context) { - this.__addToRightMemory(context); - context.blocking = new LinkedList(); - var fl = this.leftTuples, leftContext, node, thisConstraint = this.constraint; - if (fl.length) { - node = {next: fl.head}; - thisConstraint.setRightContext(context); - while ((node = node.next)) { - leftContext = node.data; - if (thisConstraint.setLeftContext(leftContext).isMatch()) { - this.__propagate("retract", this.__cloneContext(leftContext)); - this.removeFromLeftMemory(leftContext); - leftContext.blocker = context; - this.addToLeftBlockedMemory(context.blocking.push(leftContext)); - } + propagateAssertModifyFromRight: function (context, leftMatches, lm) { + var factId = lm.hashCode, mr; + if (factId in leftMatches) { + mr = this.constraint.match(lm, context); + var mrIsMatch = mr.isMatch; + if (!mrIsMatch) { + this.__propagate("retract", leftMatches[factId].clone()); + } else { + this.__propagate("modify", this.__addToMemoryMatches(context, lm, context.clone(null, null, mr))); } - thisConstraint.clearContexts(); + } else { + this.propagateFromRight(context, lm); } - }, + } + } - addToLeftBlockedMemory: function (context) { - var data = context.data, hashCode = data.hashCode; - var ctx = this.leftMemory[hashCode]; - this.leftTupleMemory[hashCode] = context; - if (ctx) { - this.leftTuples.remove(ctx); - } - return this; - }, +}).as(module); +},{"./betaNode":21,"./joinReferenceNode":29}],29:[function(require,module,exports){ +var Node = require("./node"), + constraints = require("../constraint"), + ReferenceEqualityConstraint = constraints.ReferenceEqualityConstraint; - removeFromLeftBlockedMemory: function (context) { - var ret = this.leftTupleMemory[context.hashCode] || null; - if (ret) { - delete this.leftTupleMemory[context.hashCode]; - ret.data.blocker.blocking.remove(ret); - } - return ret; - }, +var DEFUALT_CONSTRAINT = { + isDefault: true, + assert: function () { + return true; + }, - modifyLeft: function (context) { - var ctx = this.removeFromLeftMemory(context), - leftContext, - thisConstraint = this.constraint, - rightTuples = this.rightTuples, - l = rightTuples.length, - isBlocked = false, - node, rc, blocker; - if (!ctx) { - //blocked before - ctx = this.removeFromLeftBlockedMemory(context); - isBlocked = true; - } - if (ctx) { - leftContext = ctx.data; + equal: function () { + return false; + } +}; - if (leftContext && leftContext.blocker) { - //we were blocked before so only check nodes previous to our blocker - blocker = this.rightMemory[leftContext.blocker.hashCode]; - } - if (blocker) { - thisConstraint.setLeftContext(context); - if (thisConstraint.setRightContext(rc = blocker.data).isMatch()) { - //we cant be proagated so retract previous - if (!isBlocked) { - //we were asserted before so retract - this.__propagate("retract", this.__cloneContext(leftContext)); - } - context.blocker = rc; - this.addToLeftBlockedMemory(rc.blocking.push(context)); - context = null; - } - if (context) { - node = {next: blocker.next}; - } - } else { - node = {next: rightTuples.head}; - } - if (context && l) { - node = {next: rightTuples.head}; - //we were propogated before - thisConstraint.setLeftContext(context); - while ((node = node.next)) { - if (thisConstraint.setRightContext(rc = node.data).isMatch()) { - //we cant be proagated so retract previous - if (!isBlocked) { - //we were asserted before so retract - this.__propagate("retract", this.__cloneContext(leftContext)); - } - this.addToLeftBlockedMemory(rc.blocking.push(context)); - context.blocker = rc; - context = null; - break; - } - } - thisConstraint.clearContexts(); - } - if (context) { - //we can still be propogated - this.__addToLeftMemory(context); - if (!isBlocked) { - //we weren't blocked before so modify - this.__propagate("modify", this.__cloneContext(context)); - } else { - //we were blocked before but aren't now - this.__propagate("assert", this.__cloneContext(context)); - } +Node.extend({ - } - } else { - throw new Error(); - } + instance: { + + constraint: DEFUALT_CONSTRAINT, + constructor: function (leftMemory, rightMemory) { + this._super(arguments); + this.constraint = DEFUALT_CONSTRAINT; + this.constraintAssert = DEFUALT_CONSTRAINT.assert; + this.rightIndexes = []; + this.leftIndexes = []; + this.constraintLength = 0; + this.leftMemory = leftMemory; + this.rightMemory = rightMemory; }, - modifyRight: function (context) { - var ctx = this.removeFromRightMemory(context); - if (ctx) { - var rightContext = ctx.data, - leftTuples = this.leftTuples, - leftTuplesLength = leftTuples.length, - leftContext, - thisConstraint = this.constraint, - node, - blocking = rightContext.blocking; - this.__addToRightMemory(context); - context.blocking = new LinkedList(); - if (leftTuplesLength || blocking.length) { - if (blocking.length) { - var rc; - //check old blocked contexts - //check if the same contexts blocked before are still blocked - var blockingNode = {next: blocking.head}; - while ((blockingNode = blockingNode.next)) { - leftContext = blockingNode.data; - leftContext.blocker = null; - thisConstraint.setRightContext(context); - thisConstraint.setLeftContext(leftContext); - if (thisConstraint.isMatch()) { - leftContext.blocker = context; - this.addToLeftBlockedMemory(context.blocking.push(leftContext)); - leftContext = null; - } else { - //we arent blocked anymore - leftContext.blocker = null; - node = ctx; - while ((node = node.next)) { - if (thisConstraint.setRightContext(rc = node.data).isMatch()) { - leftContext.blocker = rc; - this.addToLeftBlockedMemory(rc.blocking.push(leftContext)); - leftContext = null; - break; - } - } - if (leftContext) { - this.__addToLeftMemory(leftContext); - this.__propagate("assert", this.__cloneContext(leftContext)); - } - thisConstraint.clearContexts(); - } + addConstraint: function (constraint) { + if (constraint instanceof ReferenceEqualityConstraint) { + var identifiers = constraint.getIndexableProperties(); + var alias = constraint.get("alias"); + if (identifiers.length === 2 && alias) { + var leftIndex, rightIndex, i = -1; + while (++i < 2) { + var index = identifiers[i]; + if (index.match(new RegExp("^" + alias + "(\\.?)")) === null) { + leftIndex = index; + } else { + rightIndex = index; } - thisConstraint.clearContexts(); } - - if (leftTuplesLength) { - //check currently left tuples in memory - thisConstraint.setRightContext(context); - node = {next: leftTuples.head}; - while ((node = node.next)) { - leftContext = node.data; - if (thisConstraint.setLeftContext(leftContext).isMatch()) { - this.__propagate("retract", this.__cloneContext(leftContext)); - this.removeFromLeftMemory(leftContext); - this.addToLeftBlockedMemory(context.blocking.push(leftContext)); - leftContext.blocker = context; - } - } + if (leftIndex && rightIndex) { + this.rightMemory.addIndex(rightIndex, leftIndex, constraint.op); + this.leftMemory.addIndex(leftIndex, rightIndex, constraint.op); } - - } + } + if (this.constraint.isDefault) { + this.constraint = constraint; + this.isDefault = false; } else { - throw new Error(); + this.constraint = this.constraint.merge(constraint); } + this.constraintAssert = this.constraint.assert; - - } - } -}).as(module); -},{"../context":10,"../linkedList":16,"../pattern":38,"./joinNode":24}],29:[function(require,module,exports){ -var AlphaNode = require("./alphaNode"), - Context = require("../context"), - extd = require("../extended"); - -AlphaNode.extend({ - instance: { - - constructor: function () { - this._super(arguments); - this.alias = this.constraint.get("alias"); - this.varLength = (this.variables = extd(this.constraint.get("variables")).toArray().value()).length; }, - assert: function (context) { - var c = new Context(context.fact, context.paths); - var variables = this.variables, o = context.fact.object, item; - c.set(this.alias, o); - for (var i = 0, l = this.varLength; i < l; i++) { - item = variables[i]; - c.set(item[1], o[item[0]]); - } - - this.__propagate("assert", c); - + equal: function (constraint) { + return this.constraint.equal(constraint.constraint); }, - retract: function (context) { - this.__propagate("retract", new Context(context.fact, context.paths)); + isMatch: function (lc, rc) { + return this.constraintAssert(lc.factHash, rc.factHash); }, - modify: function (context) { - var c = new Context(context.fact, context.paths); - var variables = this.variables, o = context.fact.object, item; - c.set(this.alias, o); - for (var i = 0, l = this.varLength; i < l; i++) { - item = variables[i]; - c.set(item[1], o[item[0]]); + match: function (lc, rc) { + var ret = {isMatch: false}; + if (this.constraintAssert(lc.factHash, rc.factHash)) { + ret = lc.match.merge(rc.match); } - this.__propagate("modify", c); - }, - - - toString: function () { - return "PropertyNode" + this.__count; + return ret; } - } -}).as(module); - + } -},{"../context":10,"../extended":12,"./alphaNode":19}],30:[function(require,module,exports){ -var Node = require("./node"); +}).as(module); +},{"../constraint":8,"./node":34}],30:[function(require,module,exports){ +var Node = require("./adapterNode"); Node.extend({ instance: { - - retractResolve: function (match) { - this.__propagate("retractResolve", match); - }, - - dispose: function (context) { - this.propagateDispose(context); - }, - propagateAssert: function (context) { - this.__propagate("assertRight", context); + this.__propagate("assertLeft", context); }, propagateRetract: function (context) { - this.__propagate("retractRight", context); + this.__propagate("retractLeft", context); }, propagateResolve: function (context) { @@ -3553,5386 +3550,8276 @@ Node.extend({ }, propagateModify: function (context) { - this.__propagate("modifyRight", context); + this.__propagate("modifyLeft", context); + }, + + retractResolve: function (match) { + this.__propagate("retractResolve", match); + }, + + dispose: function (context) { + this.propagateDispose(context); }, toString: function () { - return "RightAdapterNode " + this.__count; + return "LeftAdapterNode " + this.__count; } } + }).as(module); -},{"./node":27}],31:[function(require,module,exports){ -var Node = require("./node"), - extd = require("../extended"), - bind = extd.bind, - removeDuplicates = extd.removeDuplicates; +},{"./adapterNode":18}],31:[function(require,module,exports){ +var Memory = require("./memory"); + +Memory.extend({ -Node.extend({ instance: { - constructor: function (bucket, index, rule, agenda) { - this._super([]); - this.resolve = bind(this, this.resolve); - this.rule = rule; - this.index = index; - this.name = this.rule.name; - this.agenda = agenda; - this.bucket = bucket; - agenda.register(this); - }, - __assertModify: function (context) { - var match = context.match; - match.recency.sort( - function (a, b) { - return a - b; - }).reverse(); - match.facts = removeDuplicates(match.facts); - if (match.isMatch) { - var rule = this.rule, bucket = this.bucket; - this.agenda.insert(this, { - rule: rule, - hashCode: context.hashCode, - index: this.index, - name: rule.name, - recency: bucket.recency++, - match: match, - counter: bucket.counter - }); + getLeftMemory: function (tuple) { + return this.getMemory(tuple); + } + } + +}).as(module); +},{"./memory":32}],32:[function(require,module,exports){ +var extd = require("../../extended"), + indexOf = extd.indexOf, + plucker = extd.plucker, + difference = extd.diffArr, + pPush = Array.prototype.push, + declare = extd.declare, + HashTable = extd.HashTable; +declare({ + + instance: { + constructor: function () { + this.head = null; + this.tail = null; + this.length = null; + this.indexes = []; + this.tables = {tuples: [], tables: []}; + }, + + inequalityThreshold: 0.5, + + push: function (data) { + var tail = this.tail, head = this.head, node = {data: data, prev: tail, next: null}; + if (tail) { + this.tail.next = node; + } + this.tail = node; + if (!head) { + this.head = node; } + this.length++; + this.__index(node); + this.tables.tuples.push(node); + return node; }, - assert: function (context) { - this.__assertModify(context); + remove: function (node) { + if (node.prev) { + node.prev.next = node.next; + } else { + this.head = node.next; + } + if (node.next) { + node.next.prev = node.prev; + } else { + this.tail = node.prev; + } + var index = indexOf(this.tables.tuples, node); + if (index !== -1) { + this.tables.tuples.splice(index, 1); + } + this.__removeFromIndex(node); + this.length--; }, - modify: function (context) { - this.agenda.retract(this, context); - this.__assertModify(context); + forEach: function (cb) { + var head = {next: this.head}; + while ((head = head.next)) { + cb(head.data); + } }, - retract: function (context) { - this.agenda.retract(this, context); + toArray: function () { + var head = {next: this.head}, ret = []; + while ((head = head.next)) { + ret.push(head); + } + return ret; }, - retractRight: function (context) { - this.agenda.retract(this, context); + clear: function () { + this.head = this.tail = null; + this.length = 0; + this.clearIndexes(); }, - retractLeft: function (context) { - this.agenda.retract(this, context); + clearIndexes: function () { + this.tables = {}; + this.indexes.length = 0; }, - assertLeft: function (context) { - this.__assertModify(context); + __index: function (node) { + var data = node.data, + factHash = data.factHash, + indexes = this.indexes, + entry = this.tables, + i = -1, l = indexes.length, + tuples, index, val, path, tables, currEntry, prevLookup; + while (++i < l) { + index = indexes[i]; + val = index[2](factHash); + path = index[0]; + tables = entry.tables; + currEntry = tables[path]; + if (!currEntry) { + currEntry = tables[path] = new HashTable(); + tuples = {tuples: [node], tables: {}}; + currEntry.put(val, tuples); + } else if (!(tuples = currEntry.get(val))) { + tuples = {tuples: [node], tables: {}}; + currEntry.put(val, tuples); + } else if (prevLookup !== path) { + tuples.tuples.push(node); + } + prevLookup = path; + if (index[4] === "eq") { + entry = tuples; + } + } }, - assertRight: function (context) { - this.__assertModify(context); + getSimilarMemory: function (tuple) { + return this.getMemory(tuple, true); }, - toString: function () { - return "TerminalNode " + this.rule.name; + __removeFromIndex: function (node) { + var data = node.data, + factHash = data.factHash, + indexes = this.indexes, + entry = this.tables, + i = -1, l = indexes.length; + while (++i < l) { + var index = indexes[i], + val = index[2](factHash); + var currEntry = entry.tables[index[0]]; + if (currEntry) { + var tuples = currEntry.get(val); + if (tuples) { + var currTuples = tuples.tuples, ind = indexOf(currTuples, node); + if (ind !== -1) { + currTuples.splice(ind, 1); + } + if (index[4] === "eq") { + entry = tuples; + } + } + } + } + }, + + getMemory: function (tuple, usePrimary) { + var factHash = tuple.factHash, + indexes = this.indexes, + entry = this.tables, + i = -1, l = indexes.length, + ret = entry.tuples, + lookup = usePrimary ? 2 : 3, + inequalityThreshold = this.inequalityThreshold, + notPossibles = [], npl = 0, rl; + + while (++i < l) { + var index = indexes[i], + val = index[lookup](factHash), + currEntry = entry.tables[index[0]]; + if (currEntry) { + var nextEntry = currEntry.get(val), tuples, tl; + if (index[4] === "neq") { + rl = ret.length; + if (!nextEntry) { + ret = rl ? ret : entry.tuples; + } else { + tuples = nextEntry.tuples; + tl = tuples.length; + if (!tl || !rl) { + ret = entry.tuples; + } else if (tl === entry.tuples.length) { + ret = []; + i = l; + } else if (tl) { + pPush.apply(notPossibles, tuples); + npl += tl; + } + } + } else if (nextEntry) { + tuples = nextEntry.tuples; + tl = tuples.length; + if (tl) { + ret = nextEntry.tuples; + entry = nextEntry; + } else { + i = l; + ret = []; + } + } else { + i = l; + ret = []; + } + } else { + ret = []; + i = l; + } + } + rl = ret.length; + if (npl && rl && (npl / rl) > inequalityThreshold) { + //console.log(npl); + ret = difference(ret, notPossibles); + } + return ret.slice(); + }, + + __createIndexTree: function () { + var table = this.tables.tables = {}; + var indexes = this.indexes; + table[indexes[0][0]] = new HashTable(); + + }, + + + addIndex: function (primary, lookup, op) { + this.indexes.push([primary, lookup, plucker(primary), plucker(lookup), op || "eq"]); + this.indexes.sort(function (a, b) { + var aOp = a[4], bOp = b[4]; + return aOp === bOp ? 0 : aOp > bOp ? 1 : -1; + }); + this.__createIndexTree(); } + } + }).as(module); -},{"../extended":12,"./node":27}],32:[function(require,module,exports){ -var AlphaNode = require("./alphaNode"), + +},{"../../extended":12}],33:[function(require,module,exports){ +var Memory = require("./memory"); + +Memory.extend({ + + instance: { + + getRightMemory: function (tuple) { + return this.getMemory(tuple); + } + } + +}).as(module); +},{"./memory":32}],34:[function(require,module,exports){ +var extd = require("../extended"), + forEach = extd.forEach, + indexOf = extd.indexOf, + intersection = extd.intersection, + declare = extd.declare, + HashTable = extd.HashTable, Context = require("../context"); -AlphaNode.extend({ +var count = 0; +declare({ instance: { + constructor: function () { + this.nodes = new HashTable(); + this.rules = []; + this.parentNodes = []; + this.__count = count++; + this.__entrySet = []; + }, - assert: function (fact) { - if (this.constraintAssert(fact.object)) { - this.__propagate("assert", fact); + addRule: function (rule) { + if (indexOf(this.rules, rule) === -1) { + this.rules.push(rule); } + return this; }, - modify: function (fact) { - if (this.constraintAssert(fact.object)) { - this.__propagate("modify", fact); + merge: function (that) { + that.nodes.forEach(function (entry) { + var patterns = entry.value, node = entry.key; + for (var i = 0, l = patterns.length; i < l; i++) { + this.addOutNode(node, patterns[i]); + } + that.nodes.remove(node); + }, this); + var thatParentNodes = that.parentNodes; + for (var i = 0, l = that.parentNodes.l; i < l; i++) { + var parentNode = thatParentNodes[i]; + this.addParentNode(parentNode); + parentNode.nodes.remove(that); } + return this; }, - retract: function (fact) { - if (this.constraintAssert(fact.object)) { - this.__propagate("retract", fact); - } + resolve: function (mr1, mr2) { + return mr1.hashCode === mr2.hashCode; }, - toString: function () { - return "TypeNode" + this.__count; + print: function (tab) { + console.log(tab + this.toString()); + forEach(this.parentNodes, function (n) { + n.print(" " + tab); + }); }, - dispose: function () { - var es = this.__entrySet, i = es.length - 1; - for (; i >= 0; i--) { - var e = es[i], outNode = e.key, paths = e.value; - outNode.dispose({paths: paths}); + addOutNode: function (outNode, pattern) { + if (!this.nodes.contains(outNode)) { + this.nodes.put(outNode, []); } + this.nodes.get(outNode).push(pattern); + this.__entrySet = this.nodes.entrySet(); }, - __propagate: function (method, fact) { - var es = this.__entrySet, i = -1, l = es.length; - while (++i < l) { - var e = es[i], outNode = e.key, paths = e.value; - outNode[method](new Context(fact, paths)); + addParentNode: function (n) { + if (indexOf(this.parentNodes, n) === -1) { + this.parentNodes.push(n); } - } - } -}).as(module); -},{"../context":10,"./alphaNode":19}],33:[function(require,module,exports){ -var process=require("__browserify_process");/* parser generated by jison 0.4.6 */ -/* - Returns a Parser object of the following structure: + }, - Parser: { - yy: {} - } + shareable: function () { + return false; + }, - Parser.prototype: { - yy: {}, - trace: function(), - symbols_: {associative list: name ==> number}, - terminals_: {associative list: number ==> name}, - productions_: [...], - performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate, $$, _$), - table: [...], - defaultActions: {...}, - parseError: function(str, hash), - parse: function(input), + __propagate: function (method, context) { + var entrySet = this.__entrySet, i = entrySet.length, entry, outNode, paths, continuingPaths; + while (--i > -1) { + entry = entrySet[i]; + outNode = entry.key; + paths = entry.value; - lexer: { - EOF: 1, - parseError: function(str, hash), - setInput: function(input), - input: function(), - unput: function(str), - more: function(), - less: function(n), - pastInput: function(), - upcomingInput: function(), - showPosition: function(), - test_match: function(regex_match_array, rule_index), - next: function(), - lex: function(), - begin: function(condition), - popState: function(), - _currentRules: function(), - topState: function(), - pushState: function(condition), + if ((continuingPaths = intersection(paths, context.paths)).length) { + outNode[method](new Context(context.fact, continuingPaths, context.match)); + } - options: { - ranges: boolean (optional: true ==> token location info will include a .range[] member) - flex: boolean (optional: true ==> flex-like lexing behaviour where the rules are tested exhaustively to find the longest match) - backtrack_lexer: boolean (optional: true ==> lexer regexes are tested in order and for each matching regex the action code is invoked; the lexer terminates the scan when a token is returned by the action code) + } }, - performAction: function(yy, yy_, $avoiding_name_collisions, YY_START), - rules: [...], - conditions: {associative list: name ==> set}, - } - } + dispose: function (assertable) { + this.propagateDispose(assertable); + }, + retract: function (assertable) { + this.propagateRetract(assertable); + }, - token location info (@$, _$, etc.): { - first_line: n, - last_line: n, - first_column: n, - last_column: n, - range: [start_number, end_number] (where the numbers are indexes into the input string, regular zero-based) - } + propagateDispose: function (assertable, outNodes) { + outNodes = outNodes || this.nodes; + var entrySet = this.__entrySet, i = entrySet.length - 1; + for (; i >= 0; i--) { + var entry = entrySet[i], outNode = entry.key; + outNode.dispose(assertable); + } + }, + propagateAssert: function (assertable) { + this.__propagate("assert", assertable); + }, - the parseError function receives a 'hash' object with these members for lexer and parser errors: { - text: (matched text) - token: (the produced terminal token, if any) - line: (yylineno) - } - while parser (grammar) errors will also provide these members, i.e. parser errors deliver a superset of attributes: { - loc: (yylloc) - expected: (string describing the set of expected tokens) - recoverable: (boolean: TRUE when the parser has a error recovery rule available for this particular error) - } -*/ -var parser = (function(){ -var parser = {trace: function trace() { }, -yy: {}, -symbols_: {"error":2,"expressions":3,"EXPRESSION":4,"EOF":5,"UNARY_EXPRESSION":6,"LITERAL_EXPRESSION":7,"-":8,"!":9,"MULTIPLICATIVE_EXPRESSION":10,"*":11,"/":12,"%":13,"ADDITIVE_EXPRESSION":14,"+":15,"EXPONENT_EXPRESSION":16,"^":17,"RELATIONAL_EXPRESSION":18,"<":19,">":20,"<=":21,">=":22,"EQUALITY_EXPRESSION":23,"==":24,"!=":25,"=~":26,"!=~":27,"IN_EXPRESSION":28,"in":29,"ARRAY_EXPRESSION":30,"notIn":31,"OBJECT_EXPRESSION":32,"AND_EXPRESSION":33,"&&":34,"OR_EXPRESSION":35,"||":36,"ARGUMENT_LIST":37,",":38,"IDENTIFIER_EXPRESSION":39,"IDENTIFIER":40,".":41,"[":42,"STRING_EXPRESSION":43,"]":44,"NUMBER_EXPRESSION":45,"(":46,")":47,"STRING":48,"NUMBER":49,"REGEXP_EXPRESSION":50,"REGEXP":51,"BOOLEAN_EXPRESSION":52,"BOOLEAN":53,"NULL_EXPRESSION":54,"NULL":55,"$accept":0,"$end":1}, -terminals_: {2:"error",5:"EOF",8:"-",9:"!",11:"*",12:"/",13:"%",15:"+",17:"^",19:"<",20:">",21:"<=",22:">=",24:"==",25:"!=",26:"=~",27:"!=~",29:"in",31:"notIn",34:"&&",36:"||",38:",",40:"IDENTIFIER",41:".",42:"[",44:"]",46:"(",47:")",48:"STRING",49:"NUMBER",51:"REGEXP",53:"BOOLEAN",55:"NULL"}, -productions_: [0,[3,2],[6,1],[6,2],[6,2],[10,1],[10,3],[10,3],[10,3],[14,1],[14,3],[14,3],[16,1],[16,3],[18,1],[18,3],[18,3],[18,3],[18,3],[23,1],[23,3],[23,3],[23,3],[23,3],[28,1],[28,3],[28,3],[28,3],[28,3],[33,1],[33,3],[35,1],[35,3],[37,1],[37,3],[39,1],[32,1],[32,3],[32,4],[32,4],[32,4],[32,3],[32,4],[43,1],[45,1],[50,1],[52,1],[54,1],[30,2],[30,3],[7,1],[7,1],[7,1],[7,1],[7,1],[7,1],[7,1],[7,3],[4,1]], -performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate /* action[1] */, $$ /* vstack */, _$ /* lstack */) { -/* this == yyval */ + propagateRetract: function (assertable) { + this.__propagate("retract", assertable); + }, -var $0 = $$.length - 1; -switch (yystate) { -case 1:return $$[$0-1]; -break; -case 3:this.$ = [$$[$0], null, 'unary']; -break; -case 4:this.$ = [$$[$0], null, 'logicalNot']; -break; -case 6:this.$ = [$$[$0-2], $$[$0], 'mult']; -break; -case 7:this.$ = [$$[$0-2], $$[$0], 'div']; -break; -case 8:this.$ = [$$[$0-2], $$[$0], 'mod']; -break; -case 10:this.$ = [$$[$0-2], $$[$0], 'plus']; -break; -case 11:this.$ = [$$[$0-2], $$[$0], 'minus']; -break; -case 13:this.$ = [$$[$0-2], $$[$0], 'pow']; -break; -case 15:this.$ = [$$[$0-2], $$[$0], 'lt']; -break; -case 16:this.$ = [$$[$0-2], $$[$0], 'gt']; -break; -case 17:this.$ = [$$[$0-2], $$[$0], 'lte']; -break; -case 18:this.$ = [$$[$0-2], $$[$0], 'gte']; -break; -case 20:this.$ = [$$[$0-2], $$[$0], 'eq']; -break; -case 21:this.$ = [$$[$0-2], $$[$0], 'neq']; -break; -case 22:this.$ = [$$[$0-2], $$[$0], 'like']; -break; -case 23:this.$ = [$$[$0-2], $$[$0], 'notLike']; -break; -case 25:this.$ = [$$[$0-2], $$[$0], 'in']; -break; -case 26:this.$ = [$$[$0-2], $$[$0], 'notIn']; -break; -case 27:this.$ = [$$[$0-2], $$[$0], 'in']; -break; -case 28:this.$ = [$$[$0-2], $$[$0], 'notIn']; -break; -case 30:this.$ = [$$[$0-2], $$[$0], 'and']; -break; -case 32:this.$ = [$$[$0-2], $$[$0], 'or']; -break; -case 34:this.$ = [$$[$0-2], $$[$0], 'arguments'] -break; -case 35:this.$ = [String(yytext), null, 'identifier']; -break; -case 37:this.$ = [$$[$0-2],$$[$0], 'prop']; -break; -case 38:this.$ = [$$[$0-3],$$[$0-1], 'propLookup']; -break; -case 39:this.$ = [$$[$0-3],$$[$0-1], 'propLookup']; -break; -case 40:this.$ = [$$[$0-3],$$[$0-1], 'propLookup']; -break; -case 41:this.$ = [$$[$0-2], [null, null, 'arguments'], 'function'] -break; -case 42:this.$ = [$$[$0-3], $$[$0-1], 'function'] -break; -case 43:this.$ = [String(yytext.replace(/^['|"]|['|"]$/g, '')), null, 'string']; -break; -case 44:this.$ = [Number(yytext), null, 'number']; -break; -case 45:this.$ = [yytext, null, 'regexp']; -break; -case 46:this.$ = [yytext.replace(/^\s+/, '') == 'true', null, 'boolean']; -break; -case 47:this.$ = [null, null, 'null']; -break; -case 48:this.$ = [null, null, 'array']; -break; -case 49:this.$ = [$$[$0-1], null, 'array']; -break; -case 57:this.$ = [$$[$0-1], null, 'composite'] -break; -} -}, -table: [{3:1,4:2,6:28,7:7,8:[1,29],9:[1,30],10:27,14:25,16:17,18:8,23:6,28:5,30:15,32:14,33:4,35:3,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{1:[3]},{5:[1,31]},{5:[2,58],36:[1,32],47:[2,58]},{5:[2,31],34:[1,33],36:[2,31],47:[2,31]},{5:[2,29],34:[2,29],36:[2,29],47:[2,29]},{5:[2,24],24:[1,34],25:[1,35],26:[1,36],27:[1,37],34:[2,24],36:[2,24],47:[2,24]},{5:[2,2],8:[2,2],11:[2,2],12:[2,2],13:[2,2],15:[2,2],17:[2,2],19:[2,2],20:[2,2],21:[2,2],22:[2,2],24:[2,2],25:[2,2],26:[2,2],27:[2,2],29:[1,38],31:[1,39],34:[2,2],36:[2,2],47:[2,2]},{5:[2,19],19:[1,40],20:[1,41],21:[1,42],22:[1,43],24:[2,19],25:[2,19],26:[2,19],27:[2,19],34:[2,19],36:[2,19],47:[2,19]},{5:[2,50],8:[2,50],11:[2,50],12:[2,50],13:[2,50],15:[2,50],17:[2,50],19:[2,50],20:[2,50],21:[2,50],22:[2,50],24:[2,50],25:[2,50],26:[2,50],27:[2,50],29:[2,50],31:[2,50],34:[2,50],36:[2,50],38:[2,50],44:[2,50],47:[2,50]},{5:[2,51],8:[2,51],11:[2,51],12:[2,51],13:[2,51],15:[2,51],17:[2,51],19:[2,51],20:[2,51],21:[2,51],22:[2,51],24:[2,51],25:[2,51],26:[2,51],27:[2,51],29:[2,51],31:[2,51],34:[2,51],36:[2,51],38:[2,51],44:[2,51],47:[2,51]},{5:[2,52],8:[2,52],11:[2,52],12:[2,52],13:[2,52],15:[2,52],17:[2,52],19:[2,52],20:[2,52],21:[2,52],22:[2,52],24:[2,52],25:[2,52],26:[2,52],27:[2,52],29:[2,52],31:[2,52],34:[2,52],36:[2,52],38:[2,52],44:[2,52],47:[2,52]},{5:[2,53],8:[2,53],11:[2,53],12:[2,53],13:[2,53],15:[2,53],17:[2,53],19:[2,53],20:[2,53],21:[2,53],22:[2,53],24:[2,53],25:[2,53],26:[2,53],27:[2,53],29:[2,53],31:[2,53],34:[2,53],36:[2,53],38:[2,53],44:[2,53],47:[2,53]},{5:[2,54],8:[2,54],11:[2,54],12:[2,54],13:[2,54],15:[2,54],17:[2,54],19:[2,54],20:[2,54],21:[2,54],22:[2,54],24:[2,54],25:[2,54],26:[2,54],27:[2,54],29:[2,54],31:[2,54],34:[2,54],36:[2,54],38:[2,54],44:[2,54],47:[2,54]},{5:[2,55],8:[2,55],11:[2,55],12:[2,55],13:[2,55],15:[2,55],17:[2,55],19:[2,55],20:[2,55],21:[2,55],22:[2,55],24:[2,55],25:[2,55],26:[2,55],27:[2,55],29:[2,55],31:[2,55],34:[2,55],36:[2,55],38:[2,55],41:[1,44],42:[1,45],44:[2,55],46:[1,46],47:[2,55]},{5:[2,56],8:[2,56],11:[2,56],12:[2,56],13:[2,56],15:[2,56],17:[2,56],19:[2,56],20:[2,56],21:[2,56],22:[2,56],24:[2,56],25:[2,56],26:[2,56],27:[2,56],29:[2,56],31:[2,56],34:[2,56],36:[2,56],38:[2,56],44:[2,56],47:[2,56]},{4:47,6:28,7:7,8:[1,29],9:[1,30],10:27,14:25,16:17,18:8,23:6,28:5,30:15,32:14,33:4,35:3,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{5:[2,14],17:[1,48],19:[2,14],20:[2,14],21:[2,14],22:[2,14],24:[2,14],25:[2,14],26:[2,14],27:[2,14],34:[2,14],36:[2,14],47:[2,14]},{5:[2,43],8:[2,43],11:[2,43],12:[2,43],13:[2,43],15:[2,43],17:[2,43],19:[2,43],20:[2,43],21:[2,43],22:[2,43],24:[2,43],25:[2,43],26:[2,43],27:[2,43],29:[2,43],31:[2,43],34:[2,43],36:[2,43],38:[2,43],44:[2,43],47:[2,43]},{5:[2,44],8:[2,44],11:[2,44],12:[2,44],13:[2,44],15:[2,44],17:[2,44],19:[2,44],20:[2,44],21:[2,44],22:[2,44],24:[2,44],25:[2,44],26:[2,44],27:[2,44],29:[2,44],31:[2,44],34:[2,44],36:[2,44],38:[2,44],44:[2,44],47:[2,44]},{5:[2,45],8:[2,45],11:[2,45],12:[2,45],13:[2,45],15:[2,45],17:[2,45],19:[2,45],20:[2,45],21:[2,45],22:[2,45],24:[2,45],25:[2,45],26:[2,45],27:[2,45],29:[2,45],31:[2,45],34:[2,45],36:[2,45],38:[2,45],44:[2,45],47:[2,45]},{5:[2,46],8:[2,46],11:[2,46],12:[2,46],13:[2,46],15:[2,46],17:[2,46],19:[2,46],20:[2,46],21:[2,46],22:[2,46],24:[2,46],25:[2,46],26:[2,46],27:[2,46],29:[2,46],31:[2,46],34:[2,46],36:[2,46],38:[2,46],44:[2,46],47:[2,46]},{5:[2,47],8:[2,47],11:[2,47],12:[2,47],13:[2,47],15:[2,47],17:[2,47],19:[2,47],20:[2,47],21:[2,47],22:[2,47],24:[2,47],25:[2,47],26:[2,47],27:[2,47],29:[2,47],31:[2,47],34:[2,47],36:[2,47],38:[2,47],44:[2,47],47:[2,47]},{5:[2,36],8:[2,36],11:[2,36],12:[2,36],13:[2,36],15:[2,36],17:[2,36],19:[2,36],20:[2,36],21:[2,36],22:[2,36],24:[2,36],25:[2,36],26:[2,36],27:[2,36],29:[2,36],31:[2,36],34:[2,36],36:[2,36],38:[2,36],41:[2,36],42:[2,36],44:[2,36],46:[2,36],47:[2,36]},{7:51,30:15,32:14,37:50,39:23,40:[1,26],42:[1,24],43:9,44:[1,49],45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{5:[2,12],8:[1,53],15:[1,52],17:[2,12],19:[2,12],20:[2,12],21:[2,12],22:[2,12],24:[2,12],25:[2,12],26:[2,12],27:[2,12],34:[2,12],36:[2,12],47:[2,12]},{5:[2,35],8:[2,35],11:[2,35],12:[2,35],13:[2,35],15:[2,35],17:[2,35],19:[2,35],20:[2,35],21:[2,35],22:[2,35],24:[2,35],25:[2,35],26:[2,35],27:[2,35],29:[2,35],31:[2,35],34:[2,35],36:[2,35],38:[2,35],41:[2,35],42:[2,35],44:[2,35],46:[2,35],47:[2,35]},{5:[2,9],8:[2,9],11:[1,54],12:[1,55],13:[1,56],15:[2,9],17:[2,9],19:[2,9],20:[2,9],21:[2,9],22:[2,9],24:[2,9],25:[2,9],26:[2,9],27:[2,9],34:[2,9],36:[2,9],47:[2,9]},{5:[2,5],8:[2,5],11:[2,5],12:[2,5],13:[2,5],15:[2,5],17:[2,5],19:[2,5],20:[2,5],21:[2,5],22:[2,5],24:[2,5],25:[2,5],26:[2,5],27:[2,5],34:[2,5],36:[2,5],47:[2,5]},{6:57,7:58,8:[1,29],9:[1,30],30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:59,7:58,8:[1,29],9:[1,30],30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{1:[2,1]},{6:28,7:7,8:[1,29],9:[1,30],10:27,14:25,16:17,18:8,23:6,28:5,30:15,32:14,33:60,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:28,7:7,8:[1,29],9:[1,30],10:27,14:25,16:17,18:8,23:6,28:61,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:28,7:58,8:[1,29],9:[1,30],10:27,14:25,16:17,18:62,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:28,7:58,8:[1,29],9:[1,30],10:27,14:25,16:17,18:63,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:28,7:58,8:[1,29],9:[1,30],10:27,14:25,16:17,18:64,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:28,7:58,8:[1,29],9:[1,30],10:27,14:25,16:17,18:65,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{30:66,32:67,39:23,40:[1,26],42:[1,24]},{30:68,32:69,39:23,40:[1,26],42:[1,24]},{6:28,7:58,8:[1,29],9:[1,30],10:27,14:25,16:70,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:28,7:58,8:[1,29],9:[1,30],10:27,14:25,16:71,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:28,7:58,8:[1,29],9:[1,30],10:27,14:25,16:72,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:28,7:58,8:[1,29],9:[1,30],10:27,14:25,16:73,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{39:74,40:[1,26]},{32:77,39:23,40:[1,26],43:75,45:76,48:[1,18],49:[1,19]},{7:51,30:15,32:14,37:79,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],47:[1,78],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{47:[1,80]},{6:28,7:58,8:[1,29],9:[1,30],10:27,14:81,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{5:[2,48],8:[2,48],11:[2,48],12:[2,48],13:[2,48],15:[2,48],17:[2,48],19:[2,48],20:[2,48],21:[2,48],22:[2,48],24:[2,48],25:[2,48],26:[2,48],27:[2,48],29:[2,48],31:[2,48],34:[2,48],36:[2,48],38:[2,48],44:[2,48],47:[2,48]},{38:[1,83],44:[1,82]},{38:[2,33],44:[2,33],47:[2,33]},{6:28,7:58,8:[1,29],9:[1,30],10:84,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:28,7:58,8:[1,29],9:[1,30],10:85,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:86,7:58,8:[1,29],9:[1,30],30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:87,7:58,8:[1,29],9:[1,30],30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:88,7:58,8:[1,29],9:[1,30],30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{5:[2,3],8:[2,3],11:[2,3],12:[2,3],13:[2,3],15:[2,3],17:[2,3],19:[2,3],20:[2,3],21:[2,3],22:[2,3],24:[2,3],25:[2,3],26:[2,3],27:[2,3],34:[2,3],36:[2,3],47:[2,3]},{5:[2,2],8:[2,2],11:[2,2],12:[2,2],13:[2,2],15:[2,2],17:[2,2],19:[2,2],20:[2,2],21:[2,2],22:[2,2],24:[2,2],25:[2,2],26:[2,2],27:[2,2],34:[2,2],36:[2,2],47:[2,2]},{5:[2,4],8:[2,4],11:[2,4],12:[2,4],13:[2,4],15:[2,4],17:[2,4],19:[2,4],20:[2,4],21:[2,4],22:[2,4],24:[2,4],25:[2,4],26:[2,4],27:[2,4],34:[2,4],36:[2,4],47:[2,4]},{5:[2,32],34:[1,33],36:[2,32],47:[2,32]},{5:[2,30],34:[2,30],36:[2,30],47:[2,30]},{5:[2,20],19:[1,40],20:[1,41],21:[1,42],22:[1,43],24:[2,20],25:[2,20],26:[2,20],27:[2,20],34:[2,20],36:[2,20],47:[2,20]},{5:[2,21],19:[1,40],20:[1,41],21:[1,42],22:[1,43],24:[2,21],25:[2,21],26:[2,21],27:[2,21],34:[2,21],36:[2,21],47:[2,21]},{5:[2,22],19:[1,40],20:[1,41],21:[1,42],22:[1,43],24:[2,22],25:[2,22],26:[2,22],27:[2,22],34:[2,22],36:[2,22],47:[2,22]},{5:[2,23],19:[1,40],20:[1,41],21:[1,42],22:[1,43],24:[2,23],25:[2,23],26:[2,23],27:[2,23],34:[2,23],36:[2,23],47:[2,23]},{5:[2,25],34:[2,25],36:[2,25],47:[2,25]},{5:[2,27],34:[2,27],36:[2,27],41:[1,44],42:[1,45],46:[1,46],47:[2,27]},{5:[2,26],34:[2,26],36:[2,26],47:[2,26]},{5:[2,28],34:[2,28],36:[2,28],41:[1,44],42:[1,45],46:[1,46],47:[2,28]},{5:[2,15],17:[1,48],19:[2,15],20:[2,15],21:[2,15],22:[2,15],24:[2,15],25:[2,15],26:[2,15],27:[2,15],34:[2,15],36:[2,15],47:[2,15]},{5:[2,16],17:[1,48],19:[2,16],20:[2,16],21:[2,16],22:[2,16],24:[2,16],25:[2,16],26:[2,16],27:[2,16],34:[2,16],36:[2,16],47:[2,16]},{5:[2,17],17:[1,48],19:[2,17],20:[2,17],21:[2,17],22:[2,17],24:[2,17],25:[2,17],26:[2,17],27:[2,17],34:[2,17],36:[2,17],47:[2,17]},{5:[2,18],17:[1,48],19:[2,18],20:[2,18],21:[2,18],22:[2,18],24:[2,18],25:[2,18],26:[2,18],27:[2,18],34:[2,18],36:[2,18],47:[2,18]},{5:[2,37],8:[2,37],11:[2,37],12:[2,37],13:[2,37],15:[2,37],17:[2,37],19:[2,37],20:[2,37],21:[2,37],22:[2,37],24:[2,37],25:[2,37],26:[2,37],27:[2,37],29:[2,37],31:[2,37],34:[2,37],36:[2,37],38:[2,37],41:[2,37],42:[2,37],44:[2,37],46:[2,37],47:[2,37]},{44:[1,89]},{44:[1,90]},{41:[1,44],42:[1,45],44:[1,91],46:[1,46]},{5:[2,41],8:[2,41],11:[2,41],12:[2,41],13:[2,41],15:[2,41],17:[2,41],19:[2,41],20:[2,41],21:[2,41],22:[2,41],24:[2,41],25:[2,41],26:[2,41],27:[2,41],29:[2,41],31:[2,41],34:[2,41],36:[2,41],38:[2,41],41:[2,41],42:[2,41],44:[2,41],46:[2,41],47:[2,41]},{38:[1,83],47:[1,92]},{5:[2,57],8:[2,57],11:[2,57],12:[2,57],13:[2,57],15:[2,57],17:[2,57],19:[2,57],20:[2,57],21:[2,57],22:[2,57],24:[2,57],25:[2,57],26:[2,57],27:[2,57],29:[2,57],31:[2,57],34:[2,57],36:[2,57],38:[2,57],44:[2,57],47:[2,57]},{5:[2,13],8:[1,53],15:[1,52],17:[2,13],19:[2,13],20:[2,13],21:[2,13],22:[2,13],24:[2,13],25:[2,13],26:[2,13],27:[2,13],34:[2,13],36:[2,13],47:[2,13]},{5:[2,49],8:[2,49],11:[2,49],12:[2,49],13:[2,49],15:[2,49],17:[2,49],19:[2,49],20:[2,49],21:[2,49],22:[2,49],24:[2,49],25:[2,49],26:[2,49],27:[2,49],29:[2,49],31:[2,49],34:[2,49],36:[2,49],38:[2,49],44:[2,49],47:[2,49]},{7:93,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{5:[2,10],8:[2,10],11:[1,54],12:[1,55],13:[1,56],15:[2,10],17:[2,10],19:[2,10],20:[2,10],21:[2,10],22:[2,10],24:[2,10],25:[2,10],26:[2,10],27:[2,10],34:[2,10],36:[2,10],47:[2,10]},{5:[2,11],8:[2,11],11:[1,54],12:[1,55],13:[1,56],15:[2,11],17:[2,11],19:[2,11],20:[2,11],21:[2,11],22:[2,11],24:[2,11],25:[2,11],26:[2,11],27:[2,11],34:[2,11],36:[2,11],47:[2,11]},{5:[2,6],8:[2,6],11:[2,6],12:[2,6],13:[2,6],15:[2,6],17:[2,6],19:[2,6],20:[2,6],21:[2,6],22:[2,6],24:[2,6],25:[2,6],26:[2,6],27:[2,6],34:[2,6],36:[2,6],47:[2,6]},{5:[2,7],8:[2,7],11:[2,7],12:[2,7],13:[2,7],15:[2,7],17:[2,7],19:[2,7],20:[2,7],21:[2,7],22:[2,7],24:[2,7],25:[2,7],26:[2,7],27:[2,7],34:[2,7],36:[2,7],47:[2,7]},{5:[2,8],8:[2,8],11:[2,8],12:[2,8],13:[2,8],15:[2,8],17:[2,8],19:[2,8],20:[2,8],21:[2,8],22:[2,8],24:[2,8],25:[2,8],26:[2,8],27:[2,8],34:[2,8],36:[2,8],47:[2,8]},{5:[2,38],8:[2,38],11:[2,38],12:[2,38],13:[2,38],15:[2,38],17:[2,38],19:[2,38],20:[2,38],21:[2,38],22:[2,38],24:[2,38],25:[2,38],26:[2,38],27:[2,38],29:[2,38],31:[2,38],34:[2,38],36:[2,38],38:[2,38],41:[2,38],42:[2,38],44:[2,38],46:[2,38],47:[2,38]},{5:[2,39],8:[2,39],11:[2,39],12:[2,39],13:[2,39],15:[2,39],17:[2,39],19:[2,39],20:[2,39],21:[2,39],22:[2,39],24:[2,39],25:[2,39],26:[2,39],27:[2,39],29:[2,39],31:[2,39],34:[2,39],36:[2,39],38:[2,39],41:[2,39],42:[2,39],44:[2,39],46:[2,39],47:[2,39]},{5:[2,40],8:[2,40],11:[2,40],12:[2,40],13:[2,40],15:[2,40],17:[2,40],19:[2,40],20:[2,40],21:[2,40],22:[2,40],24:[2,40],25:[2,40],26:[2,40],27:[2,40],29:[2,40],31:[2,40],34:[2,40],36:[2,40],38:[2,40],41:[2,40],42:[2,40],44:[2,40],46:[2,40],47:[2,40]},{5:[2,42],8:[2,42],11:[2,42],12:[2,42],13:[2,42],15:[2,42],17:[2,42],19:[2,42],20:[2,42],21:[2,42],22:[2,42],24:[2,42],25:[2,42],26:[2,42],27:[2,42],29:[2,42],31:[2,42],34:[2,42],36:[2,42],38:[2,42],41:[2,42],42:[2,42],44:[2,42],46:[2,42],47:[2,42]},{38:[2,34],44:[2,34],47:[2,34]}], -defaultActions: {31:[2,1]}, -parseError: function parseError(str, hash) { - if (hash.recoverable) { - this.trace(str); - } else { - throw new Error(str); - } -}, -parse: function parse(input) { - var self = this, stack = [0], vstack = [null], lstack = [], table = this.table, yytext = '', yylineno = 0, yyleng = 0, recovering = 0, TERROR = 2, EOF = 1; - this.lexer.setInput(input); - this.lexer.yy = this.yy; - this.yy.lexer = this.lexer; - this.yy.parser = this; - if (typeof this.lexer.yylloc == 'undefined') { - this.lexer.yylloc = {}; - } - var yyloc = this.lexer.yylloc; - lstack.push(yyloc); - var ranges = this.lexer.options && this.lexer.options.ranges; - if (typeof this.yy.parseError === 'function') { - this.parseError = this.yy.parseError; - } else { - this.parseError = Object.getPrototypeOf(this).parseError; - } - function popStack(n) { - stack.length = stack.length - 2 * n; - vstack.length = vstack.length - n; - lstack.length = lstack.length - n; - } - function lex() { - var token; - token = self.lexer.lex() || EOF; - if (typeof token !== 'number') { - token = self.symbols_[token] || token; + assert: function (assertable) { + this.propagateAssert(assertable); + }, + + modify: function (assertable) { + this.propagateModify(assertable); + }, + + propagateModify: function (assertable) { + this.__propagate("modify", assertable); } - return token; } - var symbol, preErrorSymbol, state, action, a, r, yyval = {}, p, len, newState, expected; - while (true) { - state = stack[stack.length - 1]; - if (this.defaultActions[state]) { - action = this.defaultActions[state]; - } else { - if (symbol === null || typeof symbol == 'undefined') { - symbol = lex(); - } - action = table[state] && table[state][symbol]; - } - if (typeof action === 'undefined' || !action.length || !action[0]) { - var errStr = ''; - expected = []; - for (p in table[state]) { - if (this.terminals_[p] && p > TERROR) { - expected.push('\'' + this.terminals_[p] + '\''); + +}).as(module); + +},{"../context":10,"../extended":12}],35:[function(require,module,exports){ +var JoinNode = require("./joinNode"), + LinkedList = require("../linkedList"), + Context = require("../context"), + InitialFact = require("../pattern").InitialFact; + + +JoinNode.extend({ + instance: { + + nodeType: "NotNode", + + constructor: function () { + this._super(arguments); + this.leftTupleMemory = {}; + //use this ensure a unique match for and propagated context. + this.notMatch = new Context(new InitialFact()).match; + }, + + __cloneContext: function (context) { + return context.clone(null, null, context.match.merge(this.notMatch)); + }, + + + retractRight: function (context) { + var ctx = this.removeFromRightMemory(context), + rightContext = ctx.data, + blocking = rightContext.blocking; + if (blocking.length) { + //if we are blocking left contexts + var rm = this.rightTuples.getSimilarMemory(rightContext), l = rm.length, i; + var leftContext, thisConstraint = this.constraint, blockingNode = {next: blocking.head}, rc; + while ((blockingNode = blockingNode.next)) { + leftContext = blockingNode.data; + //this.removeFromLeftBlockedMemory(leftContext); + i = -1; + while (++i < l) { + if (thisConstraint.isMatch(leftContext, rc = rm[i].data)) { + this.blockedContext(leftContext, rc); + leftContext = null; + break; + } + } + if (leftContext) { + this.notBlockedContext(leftContext, true); } } - if (this.lexer.showPosition) { - errStr = 'Parse error on line ' + (yylineno + 1) + ':\n' + this.lexer.showPosition() + '\nExpecting ' + expected.join(', ') + ', got \'' + (this.terminals_[symbol] || symbol) + '\''; - } else { - errStr = 'Parse error on line ' + (yylineno + 1) + ': Unexpected ' + (symbol == EOF ? 'end of input' : '\'' + (this.terminals_[symbol] || symbol) + '\''); + blocking.clear(); + } + + }, + + blockedContext: function (leftContext, rightContext, propagate) { + leftContext.blocker = rightContext; + this.removeFromLeftMemory(leftContext); + this.addToLeftBlockedMemory(rightContext.blocking.push(leftContext)); + propagate && this.__propagate("retract", this.__cloneContext(leftContext)); + }, + + notBlockedContext: function (leftContext, propagate) { + this.__addToLeftMemory(leftContext); + propagate && this.__propagate("assert", this.__cloneContext(leftContext)); + }, + + propagateFromLeft: function (leftContext) { + this.notBlockedContext(leftContext, true); + }, + + propagateFromRight: function (leftContext) { + this.notBlockedContext(leftContext, true); + }, + + blockFromAssertRight: function (leftContext, rightContext) { + this.blockedContext(leftContext, rightContext, true); + }, + + blockFromAssertLeft: function (leftContext, rightContext) { + this.blockedContext(leftContext, rightContext, false); + }, + + + retractLeft: function (context) { + var ctx = this.removeFromLeftMemory(context); + if (ctx) { + ctx = ctx.data; + this.__propagate("retract", this.__cloneContext(ctx)); + } else { + if (!this.removeFromLeftBlockedMemory(context)) { + throw new Error(); } - this.parseError(errStr, { - text: this.lexer.match, - token: this.terminals_[symbol] || symbol, - line: this.lexer.yylineno, - loc: yyloc, - expected: expected - }); } - if (action[0] instanceof Array && action.length > 1) { - throw new Error('Parse Error: multiple actions possible at state: ' + state + ', token: ' + symbol); - } - switch (action[0]) { - case 1: - stack.push(symbol); - vstack.push(this.lexer.yytext); - lstack.push(this.lexer.yylloc); - stack.push(action[1]); - symbol = null; - if (!preErrorSymbol) { - yyleng = this.lexer.yyleng; - yytext = this.lexer.yytext; - yylineno = this.lexer.yylineno; - yyloc = this.lexer.yylloc; - if (recovering > 0) { - recovering--; + }, + + assertLeft: function (context) { + var values = this.rightTuples.getRightMemory(context), + thisConstraint = this.constraint, rc, i = -1, l = values.length; + while (++i < l) { + if (thisConstraint.isMatch(context, rc = values[i].data)) { + this.blockFromAssertLeft(context, rc); + context = null; + i = l; } - } else { - symbol = preErrorSymbol; - preErrorSymbol = null; } - break; - case 2: - len = this.productions_[action[1]][1]; - yyval.$ = vstack[vstack.length - len]; - yyval._$ = { - first_line: lstack[lstack.length - (len || 1)].first_line, - last_line: lstack[lstack.length - 1].last_line, - first_column: lstack[lstack.length - (len || 1)].first_column, - last_column: lstack[lstack.length - 1].last_column - }; - if (ranges) { - yyval._$.range = [ - lstack[lstack.length - (len || 1)].range[0], - lstack[lstack.length - 1].range[1] - ]; + if (context) { + this.propagateFromLeft(context); } - r = this.performAction.call(yyval, yytext, yyleng, yylineno, this.yy, action[1], vstack, lstack); - if (typeof r !== 'undefined') { - return r; + }, + + assertRight: function (context) { + this.__addToRightMemory(context); + context.blocking = new LinkedList(); + var fl = this.leftTuples.getLeftMemory(context), + i = -1, l = fl.length, + leftContext, thisConstraint = this.constraint; + while (++i < l) { + leftContext = fl[i].data; + if (thisConstraint.isMatch(leftContext, context)) { + this.blockFromAssertRight(leftContext, context); + } } - if (len) { - stack = stack.slice(0, -1 * len * 2); - vstack = vstack.slice(0, -1 * len); - lstack = lstack.slice(0, -1 * len); + }, + + addToLeftBlockedMemory: function (context) { + var data = context.data, hashCode = data.hashCode; + var ctx = this.leftMemory[hashCode]; + this.leftTupleMemory[hashCode] = context; + if (ctx) { + this.leftTuples.remove(ctx); } - stack.push(this.productions_[action[1]][0]); - vstack.push(yyval.$); - lstack.push(yyval._$); - newState = table[stack[stack.length - 2]][stack[stack.length - 1]]; - stack.push(newState); - break; - case 3: - return true; - } - } - return true; -}}; -undefined/* generated by jison-lex 0.2.1 */ -var lexer = (function(){ -var lexer = { + return this; + }, -EOF:1, + removeFromLeftBlockedMemory: function (context) { + var ret = this.leftTupleMemory[context.hashCode] || null; + if (ret) { + delete this.leftTupleMemory[context.hashCode]; + ret.data.blocker.blocking.remove(ret); + } + return ret; + }, -parseError:function parseError(str, hash) { - if (this.yy.parser) { - this.yy.parser.parseError(str, hash); - } else { - throw new Error(str); - } - }, + modifyLeft: function (context) { + var ctx = this.removeFromLeftMemory(context), + leftContext, + thisConstraint = this.constraint, + rightTuples = this.rightTuples.getRightMemory(context), + l = rightTuples.length, + isBlocked = false, + i, rc, blocker; + if (!ctx) { + //blocked before + ctx = this.removeFromLeftBlockedMemory(context); + isBlocked = true; + } + if (ctx) { + leftContext = ctx.data; -// resets the lexer, sets new input -setInput:function (input) { - this._input = input; - this._more = this._backtrack = this.done = false; - this.yylineno = this.yyleng = 0; - this.yytext = this.matched = this.match = ''; - this.conditionStack = ['INITIAL']; - this.yylloc = { - first_line: 1, - first_column: 0, - last_line: 1, - last_column: 0 - }; - if (this.options.ranges) { - this.yylloc.range = [0,0]; - } - this.offset = 0; - return this; - }, + if (leftContext && leftContext.blocker) { + //we were blocked before so only check nodes previous to our blocker + blocker = this.rightMemory[leftContext.blocker.hashCode]; + } + if (blocker) { + if (thisConstraint.isMatch(context, rc = blocker.data)) { + //we cant be proagated so retract previous + if (!isBlocked) { + //we were asserted before so retract + this.__propagate("retract", this.__cloneContext(leftContext)); + } + context.blocker = rc; + this.addToLeftBlockedMemory(rc.blocking.push(context)); + context = null; + } + } + if (context && l) { + i = -1; + //we were propogated before + while (++i < l) { + if (thisConstraint.isMatch(context, rc = rightTuples[i].data)) { + //we cant be proagated so retract previous + if (!isBlocked) { + //we were asserted before so retract + this.__propagate("retract", this.__cloneContext(leftContext)); + } + this.addToLeftBlockedMemory(rc.blocking.push(context)); + context.blocker = rc; + context = null; + break; + } + } + } + if (context) { + //we can still be propogated + this.__addToLeftMemory(context); + if (!isBlocked) { + //we weren't blocked before so modify + this.__propagate("modify", this.__cloneContext(context)); + } else { + //we were blocked before but aren't now + this.__propagate("assert", this.__cloneContext(context)); + } -// consumes and returns one char from the input -input:function () { - var ch = this._input[0]; - this.yytext += ch; - this.yyleng++; - this.offset++; - this.match += ch; - this.matched += ch; - var lines = ch.match(/(?:\r\n?|\n).*/g); - if (lines) { - this.yylineno++; - this.yylloc.last_line++; - } else { - this.yylloc.last_column++; - } - if (this.options.ranges) { - this.yylloc.range[1]++; - } + } + } else { + throw new Error(); + } - this._input = this._input.slice(1); - return ch; - }, + }, -// unshifts one char (or a string) into the input -unput:function (ch) { - var len = ch.length; - var lines = ch.split(/(?:\r\n?|\n)/g); + modifyRight: function (context) { + var ctx = this.removeFromRightMemory(context); + if (ctx) { + var rightContext = ctx.data, + leftTuples = this.leftTuples.getLeftMemory(context), + leftTuplesLength = leftTuples.length, + leftContext, + thisConstraint = this.constraint, + i, node, + blocking = rightContext.blocking; + this.__addToRightMemory(context); + context.blocking = new LinkedList(); - this._input = ch + this._input; - this.yytext = this.yytext.substr(0, this.yytext.length - len - 1); - //this.yyleng -= len; - this.offset -= len; - var oldLines = this.match.split(/(?:\r\n?|\n)/g); - this.match = this.match.substr(0, this.match.length - 1); - this.matched = this.matched.substr(0, this.matched.length - 1); + var rc; + //check old blocked contexts + //check if the same contexts blocked before are still blocked + var blockingNode = {next: blocking.head}; + while ((blockingNode = blockingNode.next)) { + leftContext = blockingNode.data; + leftContext.blocker = null; + if (thisConstraint.isMatch(leftContext, context)) { + leftContext.blocker = context; + this.addToLeftBlockedMemory(context.blocking.push(leftContext)); + leftContext = null; + } else { + //we arent blocked anymore + leftContext.blocker = null; + node = ctx; + while ((node = node.next)) { + if (thisConstraint.isMatch(leftContext, rc = node.data)) { + leftContext.blocker = rc; + this.addToLeftBlockedMemory(rc.blocking.push(leftContext)); + leftContext = null; + break; + } + } + if (leftContext) { + this.__addToLeftMemory(leftContext); + this.__propagate("assert", this.__cloneContext(leftContext)); + } + } - if (lines.length - 1) { - this.yylineno -= lines.length - 1; - } - var r = this.yylloc.range; + if (leftTuplesLength) { + //check currently left tuples in memory + i = -1; + while (++i < leftTuplesLength) { + leftContext = leftTuples[i].data; + if (thisConstraint.isMatch(leftContext, context)) { + this.__propagate("retract", this.__cloneContext(leftContext)); + this.removeFromLeftMemory(leftContext); + this.addToLeftBlockedMemory(context.blocking.push(leftContext)); + leftContext.blocker = context; + } + } + } - this.yylloc = { - first_line: this.yylloc.first_line, - last_line: this.yylineno + 1, - first_column: this.yylloc.first_column, - last_column: lines ? - (lines.length === oldLines.length ? this.yylloc.first_column : 0) - + oldLines[oldLines.length - lines.length].length - lines[0].length : - this.yylloc.first_column - len - }; - if (this.options.ranges) { - this.yylloc.range = [r[0], r[0] + this.yyleng - len]; - } - this.yyleng = this.yytext.length; - return this; - }, + } + } else { + throw new Error(); + } -// When called from action, caches matched text and appends it on next action -more:function () { - this._more = true; - return this; - }, - -// When called from action, signals the lexer that this rule fails to match the input, so the next matching rule (regex) should be tested instead. -reject:function () { - if (this.options.backtrack_lexer) { - this._backtrack = true; - } else { - return this.parseError('Lexical error on line ' + (this.yylineno + 1) + '. You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n' + this.showPosition(), { - text: "", - token: null, - line: this.yylineno - }); } - return this; - }, + } +}).as(module); +},{"../context":10,"../linkedList":16,"../pattern":45,"./joinNode":28}],36:[function(require,module,exports){ +var AlphaNode = require("./alphaNode"), + Context = require("../context"), + extd = require("../extended"); -// retain first n characters of the match -less:function (n) { - this.unput(this.match.slice(n)); - }, +AlphaNode.extend({ + instance: { -// displays already matched input, i.e. for error messages -pastInput:function () { - var past = this.matched.substr(0, this.matched.length - this.match.length); - return (past.length > 20 ? '...':'') + past.substr(-20).replace(/\n/g, ""); - }, + constructor: function () { + this._super(arguments); + this.alias = this.constraint.get("alias"); + this.varLength = (this.variables = extd(this.constraint.get("variables")).toArray().value()).length; + }, -// displays upcoming input, i.e. for error messages -upcomingInput:function () { - var next = this.match; - if (next.length < 20) { - next += this._input.substr(0, 20-next.length); - } - return (next.substr(0,20) + (next.length > 20 ? '...' : '')).replace(/\n/g, ""); - }, + assert: function (context) { + var c = new Context(context.fact, context.paths); + var variables = this.variables, o = context.fact.object, item; + c.set(this.alias, o); + for (var i = 0, l = this.varLength; i < l; i++) { + item = variables[i]; + c.set(item[1], o[item[0]]); + } -// displays the character position where the lexing error occurred, i.e. for error messages -showPosition:function () { - var pre = this.pastInput(); - var c = new Array(pre.length + 1).join("-"); - return pre + this.upcomingInput() + "\n" + c + "^"; - }, + this.__propagate("assert", c); -// test the lexed token: return FALSE when not a match, otherwise return token -test_match:function (match, indexed_rule) { - var token, - lines, - backup; + }, - if (this.options.backtrack_lexer) { - // save context - backup = { - yylineno: this.yylineno, - yylloc: { - first_line: this.yylloc.first_line, - last_line: this.last_line, - first_column: this.yylloc.first_column, - last_column: this.yylloc.last_column - }, - yytext: this.yytext, - match: this.match, - matches: this.matches, - matched: this.matched, - yyleng: this.yyleng, - offset: this.offset, - _more: this._more, - _input: this._input, - yy: this.yy, - conditionStack: this.conditionStack.slice(0), - done: this.done - }; - if (this.options.ranges) { - backup.yylloc.range = this.yylloc.range.slice(0); - } - } + retract: function (context) { + this.__propagate("retract", new Context(context.fact, context.paths)); + }, - lines = match[0].match(/(?:\r\n?|\n).*/g); - if (lines) { - this.yylineno += lines.length; - } - this.yylloc = { - first_line: this.yylloc.last_line, - last_line: this.yylineno + 1, - first_column: this.yylloc.last_column, - last_column: lines ? - lines[lines.length - 1].length - lines[lines.length - 1].match(/\r?\n?/)[0].length : - this.yylloc.last_column + match[0].length - }; - this.yytext += match[0]; - this.match += match[0]; - this.matches = match; - this.yyleng = this.yytext.length; - if (this.options.ranges) { - this.yylloc.range = [this.offset, this.offset += this.yyleng]; - } - this._more = false; - this._backtrack = false; - this._input = this._input.slice(match[0].length); - this.matched += match[0]; - token = this.performAction.call(this, this.yy, this, indexed_rule, this.conditionStack[this.conditionStack.length - 1]); - if (this.done && this._input) { - this.done = false; - } - if (token) { - return token; - } else if (this._backtrack) { - // recover context - for (var k in backup) { - this[k] = backup[k]; + modify: function (context) { + var c = new Context(context.fact, context.paths); + var variables = this.variables, o = context.fact.object, item; + c.set(this.alias, o); + for (var i = 0, l = this.varLength; i < l; i++) { + item = variables[i]; + c.set(item[1], o[item[0]]); } - return false; // rule action called reject() implying the next rule should be tested instead. - } - return false; - }, + this.__propagate("modify", c); + }, -// return next match in input -next:function () { - if (this.done) { - return this.EOF; - } - if (!this._input) { - this.done = true; - } - var token, - match, - tempMatch, - index; - if (!this._more) { - this.yytext = ''; - this.match = ''; - } - var rules = this._currentRules(); - for (var i = 0; i < rules.length; i++) { - tempMatch = this._input.match(this.rules[rules[i]]); - if (tempMatch && (!match || tempMatch[0].length > match[0].length)) { - match = tempMatch; - index = i; - if (this.options.backtrack_lexer) { - token = this.test_match(tempMatch, rules[i]); - if (token !== false) { - return token; - } else if (this._backtrack) { - match = false; - continue; // rule action called reject() implying a rule MISmatch. - } else { - // else: this is a lexer rule which consumes input without producing a token (e.g. whitespace) - return false; - } - } else if (!this.options.flex) { - break; - } - } - } - if (match) { - token = this.test_match(match, rules[index]); - if (token !== false) { - return token; - } - // else: this is a lexer rule which consumes input without producing a token (e.g. whitespace) - return false; - } - if (this._input === "") { - return this.EOF; - } else { - return this.parseError('Lexical error on line ' + (this.yylineno + 1) + '. Unrecognized text.\n' + this.showPosition(), { - text: "", - token: null, - line: this.yylineno - }); + toString: function () { + return "PropertyNode" + this.__count; } - }, + } +}).as(module); -// return next match that has a token -lex:function lex() { - var r = this.next(); - if (r) { - return r; - } else { - return this.lex(); - } - }, -// activates a new lexer condition state (pushes the new lexer condition state onto the condition stack) -begin:function begin(condition) { - this.conditionStack.push(condition); - }, -// pop the previously active lexer condition state off the condition stack -popState:function popState() { - var n = this.conditionStack.length - 1; - if (n > 0) { - return this.conditionStack.pop(); - } else { - return this.conditionStack[0]; - } - }, +},{"../context":10,"../extended":12,"./alphaNode":20}],37:[function(require,module,exports){ +var Node = require("./adapterNode"); -// produce the lexer rule set which is active for the currently active lexer condition state -_currentRules:function _currentRules() { - if (this.conditionStack.length && this.conditionStack[this.conditionStack.length - 1]) { - return this.conditions[this.conditionStack[this.conditionStack.length - 1]].rules; - } else { - return this.conditions["INITIAL"].rules; - } - }, +Node.extend({ + instance: { -// return the currently active lexer condition state; when an index argument is provided it produces the N-th previous condition state, if available -topState:function topState(n) { - n = this.conditionStack.length - 1 - Math.abs(n || 0); - if (n >= 0) { - return this.conditionStack[n]; - } else { - return "INITIAL"; - } - }, + retractResolve: function (match) { + this.__propagate("retractResolve", match); + }, -// alias for begin(condition) -pushState:function pushState(condition) { - this.begin(condition); - }, + dispose: function (context) { + this.propagateDispose(context); + }, -// return the number of states currently on the stack -stateStackSize:function stateStackSize() { - return this.conditionStack.length; - }, -options: {}, -performAction: function anonymous(yy,yy_,$avoiding_name_collisions,YY_START) { + propagateAssert: function (context) { + this.__propagate("assertRight", context); + }, -var YYSTATE=YY_START; -switch($avoiding_name_collisions) { -case 0:return 29; + propagateRetract: function (context) { + this.__propagate("retractRight", context); + }, + + propagateResolve: function (context) { + this.__propagate("retractResolve", context); + }, + + propagateModify: function (context) { + this.__propagate("modifyRight", context); + }, + + toString: function () { + return "RightAdapterNode " + this.__count; + } + } +}).as(module); +},{"./adapterNode":18}],38:[function(require,module,exports){ +var Node = require("./node"), + extd = require("../extended"), + bind = extd.bind; + +Node.extend({ + instance: { + constructor: function (bucket, index, rule, agenda) { + this._super([]); + this.resolve = bind(this, this.resolve); + this.rule = rule; + this.index = index; + this.name = this.rule.name; + this.agenda = agenda; + this.bucket = bucket; + agenda.register(this); + }, + + __assertModify: function (context) { + var match = context.match; + if (match.isMatch) { + var rule = this.rule, bucket = this.bucket; + this.agenda.insert(this, { + rule: rule, + hashCode: context.hashCode, + index: this.index, + name: rule.name, + recency: bucket.recency++, + match: match, + counter: bucket.counter + }); + } + }, + + assert: function (context) { + this.__assertModify(context); + }, + + modify: function (context) { + this.agenda.retract(this, context); + this.__assertModify(context); + }, + + retract: function (context) { + this.agenda.retract(this, context); + }, + + retractRight: function (context) { + this.agenda.retract(this, context); + }, + + retractLeft: function (context) { + this.agenda.retract(this, context); + }, + + assertLeft: function (context) { + this.__assertModify(context); + }, + + assertRight: function (context) { + this.__assertModify(context); + }, + + toString: function () { + return "TerminalNode " + this.rule.name; + } + } +}).as(module); +},{"../extended":12,"./node":34}],39:[function(require,module,exports){ +var AlphaNode = require("./alphaNode"), + Context = require("../context"); + +AlphaNode.extend({ + instance: { + + assert: function (fact) { + if (this.constraintAssert(fact.object)) { + this.__propagate("assert", fact); + } + }, + + modify: function (fact) { + if (this.constraintAssert(fact.object)) { + this.__propagate("modify", fact); + } + }, + + retract: function (fact) { + if (this.constraintAssert(fact.object)) { + this.__propagate("retract", fact); + } + }, + + toString: function () { + return "TypeNode" + this.__count; + }, + + dispose: function () { + var es = this.__entrySet, i = es.length - 1; + for (; i >= 0; i--) { + var e = es[i], outNode = e.key, paths = e.value; + outNode.dispose({paths: paths}); + } + }, + + __propagate: function (method, fact) { + var es = this.__entrySet, i = -1, l = es.length; + while (++i < l) { + var e = es[i], outNode = e.key, paths = e.value; + outNode[method](new Context(fact, paths)); + } + } + } +}).as(module); + + +},{"../context":10,"./alphaNode":20}],40:[function(require,module,exports){ +var process=require("__browserify_process");/* parser generated by jison 0.4.6 */ +/* + Returns a Parser object of the following structure: + + Parser: { + yy: {} + } + + Parser.prototype: { + yy: {}, + trace: function(), + symbols_: {associative list: name ==> number}, + terminals_: {associative list: number ==> name}, + productions_: [...], + performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate, $$, _$), + table: [...], + defaultActions: {...}, + parseError: function(str, hash), + parse: function(input), + + lexer: { + EOF: 1, + parseError: function(str, hash), + setInput: function(input), + input: function(), + unput: function(str), + more: function(), + less: function(n), + pastInput: function(), + upcomingInput: function(), + showPosition: function(), + test_match: function(regex_match_array, rule_index), + next: function(), + lex: function(), + begin: function(condition), + popState: function(), + _currentRules: function(), + topState: function(), + pushState: function(condition), + + options: { + ranges: boolean (optional: true ==> token location info will include a .range[] member) + flex: boolean (optional: true ==> flex-like lexing behaviour where the rules are tested exhaustively to find the longest match) + backtrack_lexer: boolean (optional: true ==> lexer regexes are tested in order and for each matching regex the action code is invoked; the lexer terminates the scan when a token is returned by the action code) + }, + + performAction: function(yy, yy_, $avoiding_name_collisions, YY_START), + rules: [...], + conditions: {associative list: name ==> set}, + } + } + + + token location info (@$, _$, etc.): { + first_line: n, + last_line: n, + first_column: n, + last_column: n, + range: [start_number, end_number] (where the numbers are indexes into the input string, regular zero-based) + } + + + the parseError function receives a 'hash' object with these members for lexer and parser errors: { + text: (matched text) + token: (the produced terminal token, if any) + line: (yylineno) + } + while parser (grammar) errors will also provide these members, i.e. parser errors deliver a superset of attributes: { + loc: (yylloc) + expected: (string describing the set of expected tokens) + recoverable: (boolean: TRUE when the parser has a error recovery rule available for this particular error) + } +*/ +var parser = (function(){ +var parser = {trace: function trace() { }, +yy: {}, +symbols_: {"error":2,"expressions":3,"EXPRESSION":4,"EOF":5,"UNARY_EXPRESSION":6,"LITERAL_EXPRESSION":7,"-":8,"!":9,"MULTIPLICATIVE_EXPRESSION":10,"*":11,"/":12,"%":13,"ADDITIVE_EXPRESSION":14,"+":15,"EXPONENT_EXPRESSION":16,"^":17,"RELATIONAL_EXPRESSION":18,"<":19,">":20,"<=":21,">=":22,"EQUALITY_EXPRESSION":23,"==":24,"!=":25,"=~":26,"!=~":27,"IN_EXPRESSION":28,"in":29,"ARRAY_EXPRESSION":30,"notIn":31,"OBJECT_EXPRESSION":32,"AND_EXPRESSION":33,"&&":34,"OR_EXPRESSION":35,"||":36,"ARGUMENT_LIST":37,",":38,"IDENTIFIER_EXPRESSION":39,"IDENTIFIER":40,".":41,"[":42,"STRING_EXPRESSION":43,"]":44,"NUMBER_EXPRESSION":45,"(":46,")":47,"STRING":48,"NUMBER":49,"REGEXP_EXPRESSION":50,"REGEXP":51,"BOOLEAN_EXPRESSION":52,"BOOLEAN":53,"NULL_EXPRESSION":54,"NULL":55,"$accept":0,"$end":1}, +terminals_: {2:"error",5:"EOF",8:"-",9:"!",11:"*",12:"/",13:"%",15:"+",17:"^",19:"<",20:">",21:"<=",22:">=",24:"==",25:"!=",26:"=~",27:"!=~",29:"in",31:"notIn",34:"&&",36:"||",38:",",40:"IDENTIFIER",41:".",42:"[",44:"]",46:"(",47:")",48:"STRING",49:"NUMBER",51:"REGEXP",53:"BOOLEAN",55:"NULL"}, +productions_: [0,[3,2],[6,1],[6,2],[6,2],[10,1],[10,3],[10,3],[10,3],[14,1],[14,3],[14,3],[16,1],[16,3],[18,1],[18,3],[18,3],[18,3],[18,3],[23,1],[23,3],[23,3],[23,3],[23,3],[28,1],[28,3],[28,3],[28,3],[28,3],[33,1],[33,3],[35,1],[35,3],[37,1],[37,3],[39,1],[32,1],[32,3],[32,4],[32,4],[32,4],[32,3],[32,4],[43,1],[45,1],[50,1],[52,1],[54,1],[30,2],[30,3],[7,1],[7,1],[7,1],[7,1],[7,1],[7,1],[7,1],[7,3],[4,1]], +performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate /* action[1] */, $$ /* vstack */, _$ /* lstack */) { +/* this == yyval */ + +var $0 = $$.length - 1; +switch (yystate) { +case 1:return $$[$0-1]; break; -case 1:return 31; +case 3:this.$ = [$$[$0], null, 'unary']; break; -case 2:return 'from'; +case 4:this.$ = [$$[$0], null, 'logicalNot']; break; -case 3:return 24; +case 6:this.$ = [$$[$0-2], $$[$0], 'mult']; break; -case 4:return 25; +case 7:this.$ = [$$[$0-2], $$[$0], 'div']; break; -case 5:return 21; +case 8:this.$ = [$$[$0-2], $$[$0], 'mod']; break; -case 6:return 19; +case 10:this.$ = [$$[$0-2], $$[$0], 'plus']; break; -case 7:return 22; +case 11:this.$ = [$$[$0-2], $$[$0], 'minus']; break; -case 8:return 20; +case 13:this.$ = [$$[$0-2], $$[$0], 'pow']; break; -case 9:return 26; +case 15:this.$ = [$$[$0-2], $$[$0], 'lt']; break; -case 10:return 27; +case 16:this.$ = [$$[$0-2], $$[$0], 'gt']; break; -case 11:return 34; +case 17:this.$ = [$$[$0-2], $$[$0], 'lte']; break; -case 12:return 36; +case 18:this.$ = [$$[$0-2], $$[$0], 'gte']; break; -case 13:return 55; +case 20:this.$ = [$$[$0-2], $$[$0], 'eq']; break; -case 14:return 53; +case 21:this.$ = [$$[$0-2], $$[$0], 'neq']; break; -case 15:/* skip whitespace */ +case 22:this.$ = [$$[$0-2], $$[$0], 'like']; break; -case 16:return 49; +case 23:this.$ = [$$[$0-2], $$[$0], 'notLike']; break; -case 17:return 48; -break; -case 18:return 48; -break; -case 19:return 40; -break; -case 20:return 51; -break; -case 21:return 41; -break; -case 22:return 11; -break; -case 23:return 12; -break; -case 24:return 13; -break; -case 25:return 38; +case 25:this.$ = [$$[$0-2], $$[$0], 'in']; break; -case 26:return 8; +case 26:this.$ = [$$[$0-2], $$[$0], 'notIn']; break; -case 27:return 26; +case 27:this.$ = [$$[$0-2], $$[$0], 'in']; break; -case 28:return 27; +case 28:this.$ = [$$[$0-2], $$[$0], 'notIn']; break; -case 29:return 24; +case 30:this.$ = [$$[$0-2], $$[$0], 'and']; break; -case 30:return 24; +case 32:this.$ = [$$[$0-2], $$[$0], 'or']; break; -case 31:return 25; +case 34:this.$ = [$$[$0-2], $$[$0], 'arguments'] break; -case 32:return 25; +case 35:this.$ = [String(yytext), null, 'identifier']; break; -case 33:return 21; +case 37:this.$ = [$$[$0-2],$$[$0], 'prop']; break; -case 34:return 22; +case 38:this.$ = [$$[$0-3],$$[$0-1], 'propLookup']; break; -case 35:return 20; +case 39:this.$ = [$$[$0-3],$$[$0-1], 'propLookup']; break; -case 36:return 19; +case 40:this.$ = [$$[$0-3],$$[$0-1], 'propLookup']; break; -case 37:return 34; +case 41:this.$ = [$$[$0-2], [null, null, 'arguments'], 'function'] break; -case 38:return 36; +case 42:this.$ = [$$[$0-3], $$[$0-1], 'function'] break; -case 39:return 15; +case 43:this.$ = [String(yytext.replace(/^['|"]|['|"]$/g, '')), null, 'string']; break; -case 40:return 17; +case 44:this.$ = [Number(yytext), null, 'number']; break; -case 41:return 46; +case 45:this.$ = [yytext, null, 'regexp']; break; -case 42:return 44; +case 46:this.$ = [yytext.replace(/^\s+/, '') == 'true', null, 'boolean']; break; -case 43:return 42; +case 47:this.$ = [null, null, 'null']; break; -case 44:return 47; +case 48:this.$ = [null, null, 'array']; break; -case 45:return 9; +case 49:this.$ = [$$[$0-1], null, 'array']; break; -case 46:return 5; +case 57:this.$ = [$$[$0-1], null, 'composite'] break; } }, -rules: [/^(?:\s+in\b)/,/^(?:\s+notIn\b)/,/^(?:\s+from\b)/,/^(?:\s+(eq|EQ)\b)/,/^(?:\s+(neq|NEQ)\b)/,/^(?:\s+(lte|LTE)\b)/,/^(?:\s+(lt|LT)\b)/,/^(?:\s+(gte|GTE)\b)/,/^(?:\s+(gt|GT)\b)/,/^(?:\s+(like|LIKE)\b)/,/^(?:\s+(notLike|NOT_LIKE)\b)/,/^(?:\s+(and|AND)\b)/,/^(?:\s+(or|OR)\b)/,/^(?:\s+null\b)/,/^(?:\s+(true|false)\b)/,/^(?:\s+)/,/^(?:-?[0-9]+(?:\.[0-9]+)?\b)/,/^(?:'[^']*')/,/^(?:"[^"]*")/,/^(?:([a-zA-Z_$][0-9a-zA-Z_$]*))/,/^(?:^\/((?![\s=])[^[\/\n\\]*(?:(?:\\[\s\S]|\[[^\]\n\\]*(?:\\[\s\S][^\]\n\\]*)*])[^[\/\n\\]*)*\/[imgy]{0,4})(?!\w))/,/^(?:\.)/,/^(?:\*)/,/^(?:\/)/,/^(?:\%)/,/^(?:,)/,/^(?:-)/,/^(?:=~)/,/^(?:!=~)/,/^(?:==)/,/^(?:===)/,/^(?:!=)/,/^(?:!==)/,/^(?:<=)/,/^(?:>=)/,/^(?:>)/,/^(?:<)/,/^(?:&&)/,/^(?:\|\|)/,/^(?:\+)/,/^(?:\^)/,/^(?:\()/,/^(?:\])/,/^(?:\[)/,/^(?:\))/,/^(?:!)/,/^(?:$)/], -conditions: {"INITIAL":{"rules":[0,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],"inclusive":true}} -}; -return lexer; -})(); -parser.lexer = lexer; -function Parser () { - this.yy = {}; -} -Parser.prototype = parser;parser.Parser = Parser; -return new Parser; -})(); - - -if (typeof require !== 'undefined' && typeof exports !== 'undefined') { -exports.parser = parser; -exports.Parser = parser.Parser; -exports.parse = function () { return parser.parse.apply(parser, arguments); }; -exports.main = function commonjsMain(args) { - if (!args[1]) { - console.log('Usage: '+args[0]+' FILE'); - process.exit(1); +table: [{3:1,4:2,6:28,7:7,8:[1,29],9:[1,30],10:27,14:25,16:17,18:8,23:6,28:5,30:15,32:14,33:4,35:3,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{1:[3]},{5:[1,31]},{5:[2,58],36:[1,32],47:[2,58]},{5:[2,31],34:[1,33],36:[2,31],47:[2,31]},{5:[2,29],34:[2,29],36:[2,29],47:[2,29]},{5:[2,24],24:[1,34],25:[1,35],26:[1,36],27:[1,37],34:[2,24],36:[2,24],47:[2,24]},{5:[2,2],8:[2,2],11:[2,2],12:[2,2],13:[2,2],15:[2,2],17:[2,2],19:[2,2],20:[2,2],21:[2,2],22:[2,2],24:[2,2],25:[2,2],26:[2,2],27:[2,2],29:[1,38],31:[1,39],34:[2,2],36:[2,2],47:[2,2]},{5:[2,19],19:[1,40],20:[1,41],21:[1,42],22:[1,43],24:[2,19],25:[2,19],26:[2,19],27:[2,19],34:[2,19],36:[2,19],47:[2,19]},{5:[2,50],8:[2,50],11:[2,50],12:[2,50],13:[2,50],15:[2,50],17:[2,50],19:[2,50],20:[2,50],21:[2,50],22:[2,50],24:[2,50],25:[2,50],26:[2,50],27:[2,50],29:[2,50],31:[2,50],34:[2,50],36:[2,50],38:[2,50],44:[2,50],47:[2,50]},{5:[2,51],8:[2,51],11:[2,51],12:[2,51],13:[2,51],15:[2,51],17:[2,51],19:[2,51],20:[2,51],21:[2,51],22:[2,51],24:[2,51],25:[2,51],26:[2,51],27:[2,51],29:[2,51],31:[2,51],34:[2,51],36:[2,51],38:[2,51],44:[2,51],47:[2,51]},{5:[2,52],8:[2,52],11:[2,52],12:[2,52],13:[2,52],15:[2,52],17:[2,52],19:[2,52],20:[2,52],21:[2,52],22:[2,52],24:[2,52],25:[2,52],26:[2,52],27:[2,52],29:[2,52],31:[2,52],34:[2,52],36:[2,52],38:[2,52],44:[2,52],47:[2,52]},{5:[2,53],8:[2,53],11:[2,53],12:[2,53],13:[2,53],15:[2,53],17:[2,53],19:[2,53],20:[2,53],21:[2,53],22:[2,53],24:[2,53],25:[2,53],26:[2,53],27:[2,53],29:[2,53],31:[2,53],34:[2,53],36:[2,53],38:[2,53],44:[2,53],47:[2,53]},{5:[2,54],8:[2,54],11:[2,54],12:[2,54],13:[2,54],15:[2,54],17:[2,54],19:[2,54],20:[2,54],21:[2,54],22:[2,54],24:[2,54],25:[2,54],26:[2,54],27:[2,54],29:[2,54],31:[2,54],34:[2,54],36:[2,54],38:[2,54],44:[2,54],47:[2,54]},{5:[2,55],8:[2,55],11:[2,55],12:[2,55],13:[2,55],15:[2,55],17:[2,55],19:[2,55],20:[2,55],21:[2,55],22:[2,55],24:[2,55],25:[2,55],26:[2,55],27:[2,55],29:[2,55],31:[2,55],34:[2,55],36:[2,55],38:[2,55],41:[1,44],42:[1,45],44:[2,55],46:[1,46],47:[2,55]},{5:[2,56],8:[2,56],11:[2,56],12:[2,56],13:[2,56],15:[2,56],17:[2,56],19:[2,56],20:[2,56],21:[2,56],22:[2,56],24:[2,56],25:[2,56],26:[2,56],27:[2,56],29:[2,56],31:[2,56],34:[2,56],36:[2,56],38:[2,56],44:[2,56],47:[2,56]},{4:47,6:28,7:7,8:[1,29],9:[1,30],10:27,14:25,16:17,18:8,23:6,28:5,30:15,32:14,33:4,35:3,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{5:[2,14],17:[1,48],19:[2,14],20:[2,14],21:[2,14],22:[2,14],24:[2,14],25:[2,14],26:[2,14],27:[2,14],34:[2,14],36:[2,14],47:[2,14]},{5:[2,43],8:[2,43],11:[2,43],12:[2,43],13:[2,43],15:[2,43],17:[2,43],19:[2,43],20:[2,43],21:[2,43],22:[2,43],24:[2,43],25:[2,43],26:[2,43],27:[2,43],29:[2,43],31:[2,43],34:[2,43],36:[2,43],38:[2,43],44:[2,43],47:[2,43]},{5:[2,44],8:[2,44],11:[2,44],12:[2,44],13:[2,44],15:[2,44],17:[2,44],19:[2,44],20:[2,44],21:[2,44],22:[2,44],24:[2,44],25:[2,44],26:[2,44],27:[2,44],29:[2,44],31:[2,44],34:[2,44],36:[2,44],38:[2,44],44:[2,44],47:[2,44]},{5:[2,45],8:[2,45],11:[2,45],12:[2,45],13:[2,45],15:[2,45],17:[2,45],19:[2,45],20:[2,45],21:[2,45],22:[2,45],24:[2,45],25:[2,45],26:[2,45],27:[2,45],29:[2,45],31:[2,45],34:[2,45],36:[2,45],38:[2,45],44:[2,45],47:[2,45]},{5:[2,46],8:[2,46],11:[2,46],12:[2,46],13:[2,46],15:[2,46],17:[2,46],19:[2,46],20:[2,46],21:[2,46],22:[2,46],24:[2,46],25:[2,46],26:[2,46],27:[2,46],29:[2,46],31:[2,46],34:[2,46],36:[2,46],38:[2,46],44:[2,46],47:[2,46]},{5:[2,47],8:[2,47],11:[2,47],12:[2,47],13:[2,47],15:[2,47],17:[2,47],19:[2,47],20:[2,47],21:[2,47],22:[2,47],24:[2,47],25:[2,47],26:[2,47],27:[2,47],29:[2,47],31:[2,47],34:[2,47],36:[2,47],38:[2,47],44:[2,47],47:[2,47]},{5:[2,36],8:[2,36],11:[2,36],12:[2,36],13:[2,36],15:[2,36],17:[2,36],19:[2,36],20:[2,36],21:[2,36],22:[2,36],24:[2,36],25:[2,36],26:[2,36],27:[2,36],29:[2,36],31:[2,36],34:[2,36],36:[2,36],38:[2,36],41:[2,36],42:[2,36],44:[2,36],46:[2,36],47:[2,36]},{7:51,30:15,32:14,37:50,39:23,40:[1,26],42:[1,24],43:9,44:[1,49],45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{5:[2,12],8:[1,53],15:[1,52],17:[2,12],19:[2,12],20:[2,12],21:[2,12],22:[2,12],24:[2,12],25:[2,12],26:[2,12],27:[2,12],34:[2,12],36:[2,12],47:[2,12]},{5:[2,35],8:[2,35],11:[2,35],12:[2,35],13:[2,35],15:[2,35],17:[2,35],19:[2,35],20:[2,35],21:[2,35],22:[2,35],24:[2,35],25:[2,35],26:[2,35],27:[2,35],29:[2,35],31:[2,35],34:[2,35],36:[2,35],38:[2,35],41:[2,35],42:[2,35],44:[2,35],46:[2,35],47:[2,35]},{5:[2,9],8:[2,9],11:[1,54],12:[1,55],13:[1,56],15:[2,9],17:[2,9],19:[2,9],20:[2,9],21:[2,9],22:[2,9],24:[2,9],25:[2,9],26:[2,9],27:[2,9],34:[2,9],36:[2,9],47:[2,9]},{5:[2,5],8:[2,5],11:[2,5],12:[2,5],13:[2,5],15:[2,5],17:[2,5],19:[2,5],20:[2,5],21:[2,5],22:[2,5],24:[2,5],25:[2,5],26:[2,5],27:[2,5],34:[2,5],36:[2,5],47:[2,5]},{6:57,7:58,8:[1,29],9:[1,30],30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:59,7:58,8:[1,29],9:[1,30],30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{1:[2,1]},{6:28,7:7,8:[1,29],9:[1,30],10:27,14:25,16:17,18:8,23:6,28:5,30:15,32:14,33:60,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:28,7:7,8:[1,29],9:[1,30],10:27,14:25,16:17,18:8,23:6,28:61,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:28,7:58,8:[1,29],9:[1,30],10:27,14:25,16:17,18:62,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:28,7:58,8:[1,29],9:[1,30],10:27,14:25,16:17,18:63,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:28,7:58,8:[1,29],9:[1,30],10:27,14:25,16:17,18:64,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:28,7:58,8:[1,29],9:[1,30],10:27,14:25,16:17,18:65,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{30:66,32:67,39:23,40:[1,26],42:[1,24]},{30:68,32:69,39:23,40:[1,26],42:[1,24]},{6:28,7:58,8:[1,29],9:[1,30],10:27,14:25,16:70,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:28,7:58,8:[1,29],9:[1,30],10:27,14:25,16:71,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:28,7:58,8:[1,29],9:[1,30],10:27,14:25,16:72,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:28,7:58,8:[1,29],9:[1,30],10:27,14:25,16:73,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{39:74,40:[1,26]},{32:77,39:23,40:[1,26],43:75,45:76,48:[1,18],49:[1,19]},{7:51,30:15,32:14,37:79,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],47:[1,78],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{47:[1,80]},{6:28,7:58,8:[1,29],9:[1,30],10:27,14:81,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{5:[2,48],8:[2,48],11:[2,48],12:[2,48],13:[2,48],15:[2,48],17:[2,48],19:[2,48],20:[2,48],21:[2,48],22:[2,48],24:[2,48],25:[2,48],26:[2,48],27:[2,48],29:[2,48],31:[2,48],34:[2,48],36:[2,48],38:[2,48],44:[2,48],47:[2,48]},{38:[1,83],44:[1,82]},{38:[2,33],44:[2,33],47:[2,33]},{6:28,7:58,8:[1,29],9:[1,30],10:84,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:28,7:58,8:[1,29],9:[1,30],10:85,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:86,7:58,8:[1,29],9:[1,30],30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:87,7:58,8:[1,29],9:[1,30],30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:88,7:58,8:[1,29],9:[1,30],30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{5:[2,3],8:[2,3],11:[2,3],12:[2,3],13:[2,3],15:[2,3],17:[2,3],19:[2,3],20:[2,3],21:[2,3],22:[2,3],24:[2,3],25:[2,3],26:[2,3],27:[2,3],34:[2,3],36:[2,3],47:[2,3]},{5:[2,2],8:[2,2],11:[2,2],12:[2,2],13:[2,2],15:[2,2],17:[2,2],19:[2,2],20:[2,2],21:[2,2],22:[2,2],24:[2,2],25:[2,2],26:[2,2],27:[2,2],34:[2,2],36:[2,2],47:[2,2]},{5:[2,4],8:[2,4],11:[2,4],12:[2,4],13:[2,4],15:[2,4],17:[2,4],19:[2,4],20:[2,4],21:[2,4],22:[2,4],24:[2,4],25:[2,4],26:[2,4],27:[2,4],34:[2,4],36:[2,4],47:[2,4]},{5:[2,32],34:[1,33],36:[2,32],47:[2,32]},{5:[2,30],34:[2,30],36:[2,30],47:[2,30]},{5:[2,20],19:[1,40],20:[1,41],21:[1,42],22:[1,43],24:[2,20],25:[2,20],26:[2,20],27:[2,20],34:[2,20],36:[2,20],47:[2,20]},{5:[2,21],19:[1,40],20:[1,41],21:[1,42],22:[1,43],24:[2,21],25:[2,21],26:[2,21],27:[2,21],34:[2,21],36:[2,21],47:[2,21]},{5:[2,22],19:[1,40],20:[1,41],21:[1,42],22:[1,43],24:[2,22],25:[2,22],26:[2,22],27:[2,22],34:[2,22],36:[2,22],47:[2,22]},{5:[2,23],19:[1,40],20:[1,41],21:[1,42],22:[1,43],24:[2,23],25:[2,23],26:[2,23],27:[2,23],34:[2,23],36:[2,23],47:[2,23]},{5:[2,25],34:[2,25],36:[2,25],47:[2,25]},{5:[2,27],34:[2,27],36:[2,27],41:[1,44],42:[1,45],46:[1,46],47:[2,27]},{5:[2,26],34:[2,26],36:[2,26],47:[2,26]},{5:[2,28],34:[2,28],36:[2,28],41:[1,44],42:[1,45],46:[1,46],47:[2,28]},{5:[2,15],17:[1,48],19:[2,15],20:[2,15],21:[2,15],22:[2,15],24:[2,15],25:[2,15],26:[2,15],27:[2,15],34:[2,15],36:[2,15],47:[2,15]},{5:[2,16],17:[1,48],19:[2,16],20:[2,16],21:[2,16],22:[2,16],24:[2,16],25:[2,16],26:[2,16],27:[2,16],34:[2,16],36:[2,16],47:[2,16]},{5:[2,17],17:[1,48],19:[2,17],20:[2,17],21:[2,17],22:[2,17],24:[2,17],25:[2,17],26:[2,17],27:[2,17],34:[2,17],36:[2,17],47:[2,17]},{5:[2,18],17:[1,48],19:[2,18],20:[2,18],21:[2,18],22:[2,18],24:[2,18],25:[2,18],26:[2,18],27:[2,18],34:[2,18],36:[2,18],47:[2,18]},{5:[2,37],8:[2,37],11:[2,37],12:[2,37],13:[2,37],15:[2,37],17:[2,37],19:[2,37],20:[2,37],21:[2,37],22:[2,37],24:[2,37],25:[2,37],26:[2,37],27:[2,37],29:[2,37],31:[2,37],34:[2,37],36:[2,37],38:[2,37],41:[2,37],42:[2,37],44:[2,37],46:[2,37],47:[2,37]},{44:[1,89]},{44:[1,90]},{41:[1,44],42:[1,45],44:[1,91],46:[1,46]},{5:[2,41],8:[2,41],11:[2,41],12:[2,41],13:[2,41],15:[2,41],17:[2,41],19:[2,41],20:[2,41],21:[2,41],22:[2,41],24:[2,41],25:[2,41],26:[2,41],27:[2,41],29:[2,41],31:[2,41],34:[2,41],36:[2,41],38:[2,41],41:[2,41],42:[2,41],44:[2,41],46:[2,41],47:[2,41]},{38:[1,83],47:[1,92]},{5:[2,57],8:[2,57],11:[2,57],12:[2,57],13:[2,57],15:[2,57],17:[2,57],19:[2,57],20:[2,57],21:[2,57],22:[2,57],24:[2,57],25:[2,57],26:[2,57],27:[2,57],29:[2,57],31:[2,57],34:[2,57],36:[2,57],38:[2,57],44:[2,57],47:[2,57]},{5:[2,13],8:[1,53],15:[1,52],17:[2,13],19:[2,13],20:[2,13],21:[2,13],22:[2,13],24:[2,13],25:[2,13],26:[2,13],27:[2,13],34:[2,13],36:[2,13],47:[2,13]},{5:[2,49],8:[2,49],11:[2,49],12:[2,49],13:[2,49],15:[2,49],17:[2,49],19:[2,49],20:[2,49],21:[2,49],22:[2,49],24:[2,49],25:[2,49],26:[2,49],27:[2,49],29:[2,49],31:[2,49],34:[2,49],36:[2,49],38:[2,49],44:[2,49],47:[2,49]},{7:93,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{5:[2,10],8:[2,10],11:[1,54],12:[1,55],13:[1,56],15:[2,10],17:[2,10],19:[2,10],20:[2,10],21:[2,10],22:[2,10],24:[2,10],25:[2,10],26:[2,10],27:[2,10],34:[2,10],36:[2,10],47:[2,10]},{5:[2,11],8:[2,11],11:[1,54],12:[1,55],13:[1,56],15:[2,11],17:[2,11],19:[2,11],20:[2,11],21:[2,11],22:[2,11],24:[2,11],25:[2,11],26:[2,11],27:[2,11],34:[2,11],36:[2,11],47:[2,11]},{5:[2,6],8:[2,6],11:[2,6],12:[2,6],13:[2,6],15:[2,6],17:[2,6],19:[2,6],20:[2,6],21:[2,6],22:[2,6],24:[2,6],25:[2,6],26:[2,6],27:[2,6],34:[2,6],36:[2,6],47:[2,6]},{5:[2,7],8:[2,7],11:[2,7],12:[2,7],13:[2,7],15:[2,7],17:[2,7],19:[2,7],20:[2,7],21:[2,7],22:[2,7],24:[2,7],25:[2,7],26:[2,7],27:[2,7],34:[2,7],36:[2,7],47:[2,7]},{5:[2,8],8:[2,8],11:[2,8],12:[2,8],13:[2,8],15:[2,8],17:[2,8],19:[2,8],20:[2,8],21:[2,8],22:[2,8],24:[2,8],25:[2,8],26:[2,8],27:[2,8],34:[2,8],36:[2,8],47:[2,8]},{5:[2,38],8:[2,38],11:[2,38],12:[2,38],13:[2,38],15:[2,38],17:[2,38],19:[2,38],20:[2,38],21:[2,38],22:[2,38],24:[2,38],25:[2,38],26:[2,38],27:[2,38],29:[2,38],31:[2,38],34:[2,38],36:[2,38],38:[2,38],41:[2,38],42:[2,38],44:[2,38],46:[2,38],47:[2,38]},{5:[2,39],8:[2,39],11:[2,39],12:[2,39],13:[2,39],15:[2,39],17:[2,39],19:[2,39],20:[2,39],21:[2,39],22:[2,39],24:[2,39],25:[2,39],26:[2,39],27:[2,39],29:[2,39],31:[2,39],34:[2,39],36:[2,39],38:[2,39],41:[2,39],42:[2,39],44:[2,39],46:[2,39],47:[2,39]},{5:[2,40],8:[2,40],11:[2,40],12:[2,40],13:[2,40],15:[2,40],17:[2,40],19:[2,40],20:[2,40],21:[2,40],22:[2,40],24:[2,40],25:[2,40],26:[2,40],27:[2,40],29:[2,40],31:[2,40],34:[2,40],36:[2,40],38:[2,40],41:[2,40],42:[2,40],44:[2,40],46:[2,40],47:[2,40]},{5:[2,42],8:[2,42],11:[2,42],12:[2,42],13:[2,42],15:[2,42],17:[2,42],19:[2,42],20:[2,42],21:[2,42],22:[2,42],24:[2,42],25:[2,42],26:[2,42],27:[2,42],29:[2,42],31:[2,42],34:[2,42],36:[2,42],38:[2,42],41:[2,42],42:[2,42],44:[2,42],46:[2,42],47:[2,42]},{38:[2,34],44:[2,34],47:[2,34]}], +defaultActions: {31:[2,1]}, +parseError: function parseError(str, hash) { + if (hash.recoverable) { + this.trace(str); + } else { + throw new Error(str); } - var source = require('fs').readFileSync(require('path').normalize(args[1]), "utf8"); - return exports.parser.parse(source); -}; -if (typeof module !== 'undefined' && require.main === module) { - exports.main(process.argv.slice(1)); -} -} -},{"__browserify_process":54,"fs":51,"path":52}],34:[function(require,module,exports){ -(function () { - "use strict"; - var constraintParser = require("./constraint/parser"), - noolParser = require("./nools/nool.parser"); - - exports.parseConstraint = function (expression) { - try { - return constraintParser.parse(expression); - } catch (e) { - throw new Error("Invalid expression '" + expression + "'"); - } - }; - - exports.parseRuleSet = function (source, file) { - return noolParser.parse(source, file); - }; -})(); -},{"./constraint/parser":33,"./nools/nool.parser":35}],35:[function(require,module,exports){ -"use strict"; - -var tokens = require("./tokens.js"), - extd = require("../../extended"), - keys = extd.hash.keys, - utils = require("./util.js"); - -var parse = function (src, keywords, context) { - var orig = src; - src = src.replace(/\/\/(.*)/g, "").replace(/\n|\r|\r\n/g, " "); - - var blockTypes = new RegExp("^(" + keys(keywords).join("|") + ")"), index; - while (src && (index = utils.findNextTokenIndex(src)) !== -1) { - src = src.substr(index); - var blockType = src.match(blockTypes); - if (blockType !== null) { - blockType = blockType[1]; - if (blockType in keywords) { - try { - src = keywords[blockType](src, context, parse).replace(/^\s*|\s*$/g, ""); - } catch (e) { - throw new Error("Invalid " + blockType + " definition \n" + e.message + "; \nstarting at : " + orig); - } - } else { - throw new Error("Unknown token" + blockType); - } - } else { - throw new Error("Error parsing " + src); +}, +parse: function parse(input) { + var self = this, stack = [0], vstack = [null], lstack = [], table = this.table, yytext = '', yylineno = 0, yyleng = 0, recovering = 0, TERROR = 2, EOF = 1; + this.lexer.setInput(input); + this.lexer.yy = this.yy; + this.yy.lexer = this.lexer; + this.yy.parser = this; + if (typeof this.lexer.yylloc == 'undefined') { + this.lexer.yylloc = {}; + } + var yyloc = this.lexer.yylloc; + lstack.push(yyloc); + var ranges = this.lexer.options && this.lexer.options.ranges; + if (typeof this.yy.parseError === 'function') { + this.parseError = this.yy.parseError; + } else { + this.parseError = Object.getPrototypeOf(this).parseError; + } + function popStack(n) { + stack.length = stack.length - 2 * n; + vstack.length = vstack.length - n; + lstack.length = lstack.length - n; + } + function lex() { + var token; + token = self.lexer.lex() || EOF; + if (typeof token !== 'number') { + token = self.symbols_[token] || token; } + return token; } -}; - -exports.parse = function (src, file) { - var context = {define: [], rules: [], scope: [], loaded: [], file: file}; - parse(src, tokens, context); - return context; -}; - - -},{"../../extended":12,"./tokens.js":36,"./util.js":37}],36:[function(require,module,exports){ -var process=require("__browserify_process");"use strict"; - -var utils = require("./util.js"), - fs = require("fs"), - extd = require("../../extended"), - filter = extd.filter, - indexOf = extd.indexOf; - -var isWhiteSpace = function (str) { - return str.replace(/[\s|\n|\r|\t]/g, "").length === 0; -}; - -var joinFunc = function (m, str) { - return "; " + str; -}; - -var splitRuleLineByPredicateExpressions = function (ruleLine) { - var str = ruleLine.replace(/,\s*(\$?\w+\s*:)/g, joinFunc); - var parts = filter(str.split(/ *(not|or) *\(/g), function (str) { - return str !== ""; - }), - l = parts.length, ret = []; - - if (l) { - for (var i = 0; i < l; i++) { - if (parts[i] === "not" || parts[i] === "or") { - ret.push([parts[i], "(", parts[++i].replace(/, *$/, "")].join("")); - } else { - ret.push(parts[i].replace(/, *$/, "")); + var symbol, preErrorSymbol, state, action, a, r, yyval = {}, p, len, newState, expected; + while (true) { + state = stack[stack.length - 1]; + if (this.defaultActions[state]) { + action = this.defaultActions[state]; + } else { + if (symbol === null || typeof symbol == 'undefined') { + symbol = lex(); } + action = table[state] && table[state][symbol]; } - } else { - return str; - } - return ret.join(";"); -}; - -var ruleTokens = { - - salience: (function () { - var salienceRegexp = /^(salience|priority)\s*:\s*(-?\d+)\s*[,;]?/; - return function (src, context) { - if (salienceRegexp.test(src)) { - var parts = src.match(salienceRegexp), - priority = parseInt(parts[2], 10); - if (!isNaN(priority)) { - context.options.priority = priority; + if (typeof action === 'undefined' || !action.length || !action[0]) { + var errStr = ''; + expected = []; + for (p in table[state]) { + if (this.terminals_[p] && p > TERROR) { + expected.push('\'' + this.terminals_[p] + '\''); + } + } + if (this.lexer.showPosition) { + errStr = 'Parse error on line ' + (yylineno + 1) + ':\n' + this.lexer.showPosition() + '\nExpecting ' + expected.join(', ') + ', got \'' + (this.terminals_[symbol] || symbol) + '\''; } else { - throw new Error("Invalid salience/priority " + parts[2]); + errStr = 'Parse error on line ' + (yylineno + 1) + ': Unexpected ' + (symbol == EOF ? 'end of input' : '\'' + (this.terminals_[symbol] || symbol) + '\''); } - return src.replace(parts[0], ""); - } else { - throw new Error("invalid format"); + this.parseError(errStr, { + text: this.lexer.match, + token: this.terminals_[symbol] || symbol, + line: this.lexer.yylineno, + loc: yyloc, + expected: expected + }); } - }; - })(), - - agendaGroup: (function () { - var agendaGroupRegexp = /^(agenda-group|agendaGroup)\s*:\s*([a-zA-Z_$][0-9a-zA-Z_$]*|"[^"]*"|'[^']*')\s*[,;]?/; - return function (src, context) { - if (agendaGroupRegexp.test(src)) { - var parts = src.match(agendaGroupRegexp), - agendaGroup = parts[2]; - if (agendaGroup) { - context.options.agendaGroup = agendaGroup.replace(/^["']|["']$/g, ""); - } else { - throw new Error("Invalid agenda-group " + parts[2]); + if (action[0] instanceof Array && action.length > 1) { + throw new Error('Parse Error: multiple actions possible at state: ' + state + ', token: ' + symbol); + } + switch (action[0]) { + case 1: + stack.push(symbol); + vstack.push(this.lexer.yytext); + lstack.push(this.lexer.yylloc); + stack.push(action[1]); + symbol = null; + if (!preErrorSymbol) { + yyleng = this.lexer.yyleng; + yytext = this.lexer.yytext; + yylineno = this.lexer.yylineno; + yyloc = this.lexer.yylloc; + if (recovering > 0) { + recovering--; } - return src.replace(parts[0], ""); } else { - throw new Error("invalid format"); + symbol = preErrorSymbol; + preErrorSymbol = null; } - }; - })(), - - autoFocus: (function () { - var autoFocusRegexp = /^(auto-focus|autoFocus)\s*:\s*(true|false)\s*[,;]?/; - return function (src, context) { - if (autoFocusRegexp.test(src)) { - var parts = src.match(autoFocusRegexp), - autoFocus = parts[2]; - if (autoFocus) { - context.options.autoFocus = autoFocus === "true" ? true : false; - } else { - throw new Error("Invalid auto-focus " + parts[2]); - } - return src.replace(parts[0], ""); - } else { - throw new Error("invalid format"); + break; + case 2: + len = this.productions_[action[1]][1]; + yyval.$ = vstack[vstack.length - len]; + yyval._$ = { + first_line: lstack[lstack.length - (len || 1)].first_line, + last_line: lstack[lstack.length - 1].last_line, + first_column: lstack[lstack.length - (len || 1)].first_column, + last_column: lstack[lstack.length - 1].last_column + }; + if (ranges) { + yyval._$.range = [ + lstack[lstack.length - (len || 1)].range[0], + lstack[lstack.length - 1].range[1] + ]; } - }; - })(), + r = this.performAction.call(yyval, yytext, yyleng, yylineno, this.yy, action[1], vstack, lstack); + if (typeof r !== 'undefined') { + return r; + } + if (len) { + stack = stack.slice(0, -1 * len * 2); + vstack = vstack.slice(0, -1 * len); + lstack = lstack.slice(0, -1 * len); + } + stack.push(this.productions_[action[1]][0]); + vstack.push(yyval.$); + lstack.push(yyval._$); + newState = table[stack[stack.length - 2]][stack[stack.length - 1]]; + stack.push(newState); + break; + case 3: + return true; + } + } + return true; +}}; +undefined/* generated by jison-lex 0.2.1 */ +var lexer = (function(){ +var lexer = { - "agenda-group": function () { - return this.agendaGroup.apply(this, arguments); - }, +EOF:1, - "auto-focus": function () { - return this.autoFocus.apply(this, arguments); +parseError:function parseError(str, hash) { + if (this.yy.parser) { + this.yy.parser.parseError(str, hash); + } else { + throw new Error(str); + } }, - priority: function () { - return this.salience.apply(this, arguments); +// resets the lexer, sets new input +setInput:function (input) { + this._input = input; + this._more = this._backtrack = this.done = false; + this.yylineno = this.yyleng = 0; + this.yytext = this.matched = this.match = ''; + this.conditionStack = ['INITIAL']; + this.yylloc = { + first_line: 1, + first_column: 0, + last_line: 1, + last_column: 0 + }; + if (this.options.ranges) { + this.yylloc.range = [0,0]; + } + this.offset = 0; + return this; }, - when: (function () { - /*jshint evil:true*/ - - var ruleRegExp = /^(\$?\w+) *: *(\w+)(.*)/; +// consumes and returns one char from the input +input:function () { + var ch = this._input[0]; + this.yytext += ch; + this.yyleng++; + this.offset++; + this.match += ch; + this.matched += ch; + var lines = ch.match(/(?:\r\n?|\n).*/g); + if (lines) { + this.yylineno++; + this.yylloc.last_line++; + } else { + this.yylloc.last_column++; + } + if (this.options.ranges) { + this.yylloc.range[1]++; + } - var constraintRegExp = /(\{ *(?:["']?\$?\w+["']?\s*:\s*["']?\$?\w+["']? *(?:, *["']?\$?\w+["']?\s*:\s*["']?\$?\w+["']?)*)+ *\})/; - var predicateExp = /^(not|or) *\((.*)\)$/m; - var fromRegExp = /(\bfrom\s+.*)/; - var parseRules = function (str) { - var rules = []; - var ruleLines = str.split(";"), l = ruleLines.length, ruleLine; - for (var i = 0; i < l && (ruleLine = ruleLines[i].replace(/^\s*|\s*$/g, "").replace(/\n/g, "")); i++) { - if (!isWhiteSpace(ruleLine)) { - var rule = []; - if (predicateExp.test(ruleLine)) { - var m = ruleLine.match(predicateExp); - var pred = m[1].replace(/^\s*|\s*$/g, ""); - rule.push(pred); - ruleLine = m[2].replace(/^\s*|\s*$/g, ""); - if (pred === "or") { - rule = rule.concat(parseRules(splitRuleLineByPredicateExpressions(ruleLine))); - rules.push(rule); - continue; - } + this._input = this._input.slice(1); + return ch; + }, - } - var parts = ruleLine.match(ruleRegExp); - if (parts && parts.length) { - rule.push(parts[2], parts[1]); - var constraints = parts[3].replace(/^\s*|\s*$/g, ""); - var hashParts = constraints.match(constraintRegExp), from = null, fromMatch; - if (hashParts) { - var hash = hashParts[1], constraint = constraints.replace(hash, ""); - if (fromRegExp.test(constraint)) { - fromMatch = constraint.match(fromRegExp); - from = fromMatch[0]; - constraint = constraint.replace(fromMatch[0], ""); - } - if (constraint) { - rule.push(constraint.replace(/^\s*|\s*$/g, "")); - } - if (hash) { - rule.push(eval("(" + hash.replace(/(\$?\w+)\s*:\s*(\$?\w+)/g, '"$1" : "$2"') + ")")); - } - } else if (constraints && !isWhiteSpace(constraints)) { - if (fromRegExp.test(constraints)) { - fromMatch = constraints.match(fromRegExp); - from = fromMatch[0]; - constraints = constraints.replace(fromMatch[0], ""); - } - rule.push(constraints); - } - if (from) { - rule.push(from); - } - rules.push(rule); - } else { - throw new Error("Invalid constraint " + ruleLine); - } - } - } - return rules; - }; +// unshifts one char (or a string) into the input +unput:function (ch) { + var len = ch.length; + var lines = ch.split(/(?:\r\n?|\n)/g); - return function (orig, context) { - var src = orig.replace(/^when\s*/, "").replace(/^\s*|\s*$/g, ""); - if (utils.findNextToken(src) === "{") { - var body = utils.getTokensBetween(src, "{", "}", true).join(""); - src = src.replace(body, ""); - context.constraints = parseRules(body.replace(/^\{\s*|\}\s*$/g, "")); - return src; - } else { - throw new Error("unexpected token : expected : '{' found : '" + utils.findNextToken(src) + "'"); - } - }; - })(), + this._input = ch + this._input; + this.yytext = this.yytext.substr(0, this.yytext.length - len - 1); + //this.yyleng -= len; + this.offset -= len; + var oldLines = this.match.split(/(?:\r\n?|\n)/g); + this.match = this.match.substr(0, this.match.length - 1); + this.matched = this.matched.substr(0, this.matched.length - 1); - then: (function () { - return function (orig, context) { - if (!context.action) { - var src = orig.replace(/^then\s*/, "").replace(/^\s*|\s*$/g, ""); - if (utils.findNextToken(src) === "{") { - var body = utils.getTokensBetween(src, "{", "}", true).join(""); - src = src.replace(body, ""); - if (!context.action) { - context.action = body.replace(/^\{\s*|\}\s*$/g, ""); - } - if (!isWhiteSpace(src)) { - throw new Error("Error parsing then block " + orig); - } - return src; - } else { - throw new Error("unexpected token : expected : '{' found : '" + utils.findNextToken(src) + "'"); - } - } else { - throw new Error("action already defined for rule" + context.name); - } + if (lines.length - 1) { + this.yylineno -= lines.length - 1; + } + var r = this.yylloc.range; + this.yylloc = { + first_line: this.yylloc.first_line, + last_line: this.yylineno + 1, + first_column: this.yylloc.first_column, + last_column: lines ? + (lines.length === oldLines.length ? this.yylloc.first_column : 0) + + oldLines[oldLines.length - lines.length].length - lines[0].length : + this.yylloc.first_column - len }; - })() -}; -var topLevelTokens = { - "/": function (orig) { - if (orig.match(/^\/\*/)) { - // Block Comment parse - return orig.replace(/\/\*.*?\*\//, ""); - } else { - return orig; + if (this.options.ranges) { + this.yylloc.range = [r[0], r[0] + this.yyleng - len]; } + this.yyleng = this.yytext.length; + return this; }, - "define": function (orig, context) { - var src = orig.replace(/^define\s*/, ""); - var name = src.match(/^([a-zA-Z_$][0-9a-zA-Z_$]*)/); - if (name) { - src = src.replace(name[0], "").replace(/^\s*|\s*$/g, ""); - if (utils.findNextToken(src) === "{") { - name = name[1]; - var body = utils.getTokensBetween(src, "{", "}", true).join(""); - src = src.replace(body, ""); - //should - context.define.push({name: name, properties: "(" + body + ")"}); - return src; - } else { - throw new Error("unexpected token : expected : '{' found : '" + utils.findNextToken(src) + "'"); - } - } else { - throw new Error("missing name"); - } +// When called from action, caches matched text and appends it on next action +more:function () { + this._more = true; + return this; }, - "import": function (orig, context, parse) { - if (typeof window !== 'undefined') { - throw new Error("import cannot be used in a browser"); - } - var src = orig.replace(/^import\s*/, ""); - if (utils.findNextToken(src) === "(") { - var file = utils.getParamList(src); - src = src.replace(file, "").replace(/^\s*|\s*$/g, ""); - utils.findNextToken(src) === ";" && (src = src.replace(/\s*;/, "")); - file = file.replace(/[\(|\)]/g, "").split(","); - if (file.length === 1) { - file = utils.resolve(context.file || process.cwd(), file[0].replace(/["|']/g, "")); - if (indexOf(context.loaded, file) === -1) { - var origFile = context.file; - context.file = file; - parse(fs.readFileSync(file, "utf8"), topLevelTokens, context); - context.loaded.push(file); - context.file = origFile; - } - return src; - } else { - throw new Error("import accepts a single file"); - } +// When called from action, signals the lexer that this rule fails to match the input, so the next matching rule (regex) should be tested instead. +reject:function () { + if (this.options.backtrack_lexer) { + this._backtrack = true; } else { - throw new Error("unexpected token : expected : '(' found : '" + utils.findNextToken(src) + "'"); - } + return this.parseError('Lexical error on line ' + (this.yylineno + 1) + '. You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n' + this.showPosition(), { + text: "", + token: null, + line: this.yylineno + }); + } + return this; }, - //define a global - "global": function (orig, context) { - var src = orig.replace(/^global\s*/, ""); - var name = src.match(/^([a-zA-Z_$][0-9a-zA-Z_$]*\s*)/); - if (name) { - src = src.replace(name[0], "").replace(/^\s*|\s*$/g, ""); - if (utils.findNextToken(src) === "=") { - name = name[1].replace(/^\s+|\s+$/g, ''); - var fullbody = utils.getTokensBetween(src, "=", ";", true).join(""); - var body = fullbody.substring(1, fullbody.length - 1); - body = body.replace(/^\s+|\s+$/g, ''); - if (/^require\(/.test(body)) { - var file = utils.getParamList(body.replace("require")).replace(/[\(|\)]/g, "").split(","); - if (file.length === 1) { - //handle relative require calls - file = file[0].replace(/["|']/g, ""); - body = ["require('", utils.resolve(context.file || process.cwd(), file) , "')"].join(""); - } - } - context.scope.push({name: name, body: body}); - src = src.replace(fullbody, ""); - return src; - } else { - throw new Error("unexpected token : expected : '=' found : '" + utils.findNextToken(src) + "'"); - } - } else { - throw new Error("missing name"); - } +// retain first n characters of the match +less:function (n) { + this.unput(this.match.slice(n)); }, - //define a function - "function": function (orig, context) { - var src = orig.replace(/^function\s*/, ""); - //parse the function name - var name = src.match(/^([a-zA-Z_$][0-9a-zA-Z_$]*)\s*/); - if (name) { - src = src.replace(name[0], ""); - if (utils.findNextToken(src) === "(") { - name = name[1]; - var params = utils.getParamList(src); - src = src.replace(params, "").replace(/^\s*|\s*$/g, ""); - if (utils.findNextToken(src) === "{") { - var body = utils.getTokensBetween(src, "{", "}", true).join(""); - src = src.replace(body, ""); - //should - context.scope.push({name: name, body: "function" + params + body}); - return src; - } else { - throw new Error("unexpected token : expected : '{' found : '" + utils.findNextToken(src) + "'"); - } - } else { - throw new Error("unexpected token : expected : '(' found : '" + utils.findNextToken(src) + "'"); - } - } else { - throw new Error("missing name"); - } +// displays already matched input, i.e. for error messages +pastInput:function () { + var past = this.matched.substr(0, this.matched.length - this.match.length); + return (past.length > 20 ? '...':'') + past.substr(-20).replace(/\n/g, ""); }, - "rule": function (orig, context, parse) { - var src = orig.replace(/^rule\s*/, ""); - var name = src.match(/^([a-zA-Z_$][0-9a-zA-Z_$]*|"[^"]*"|'[^']*')/); - if (name) { - src = src.replace(name[0], "").replace(/^\s*|\s*$/g, ""); - if (utils.findNextToken(src) === "{") { - name = name[1].replace(/^["']|["']$/g, ""); - var rule = {name: name, options: {}, constraints: null, action: null}; - var body = utils.getTokensBetween(src, "{", "}", true).join(""); - src = src.replace(body, ""); - parse(body.replace(/^\{\s*|\}\s*$/g, ""), ruleTokens, rule); - context.rules.push(rule); - return src; - } else { - throw new Error("unexpected token : expected : '{' found : '" + utils.findNextToken(src) + "'"); - } - } else { - throw new Error("missing name"); +// displays upcoming input, i.e. for error messages +upcomingInput:function () { + var next = this.match; + if (next.length < 20) { + next += this._input.substr(0, 20-next.length); } + return (next.substr(0,20) + (next.length > 20 ? '...' : '')).replace(/\n/g, ""); + }, - } -}; -module.exports = topLevelTokens; - - -},{"../../extended":12,"./util.js":37,"__browserify_process":54,"fs":51}],37:[function(require,module,exports){ -var process=require("__browserify_process");"use strict"; - -var path = require("path"); -var WHITE_SPACE_REG = /[\s|\n|\r|\t]/, - pathSep = path.sep || ( process.platform === 'win32' ? '\\' : '/' ); +// displays the character position where the lexing error occurred, i.e. for error messages +showPosition:function () { + var pre = this.pastInput(); + var c = new Array(pre.length + 1).join("-"); + return pre + this.upcomingInput() + "\n" + c + "^"; + }, -var TOKEN_INVERTS = { - "{": "}", - "}": "{", - "(": ")", - ")": "(", - "[": "]" -}; +// test the lexed token: return FALSE when not a match, otherwise return token +test_match:function (match, indexed_rule) { + var token, + lines, + backup; -var getTokensBetween = exports.getTokensBetween = function (str, start, stop, includeStartEnd) { - var depth = 0, ret = []; - if (!start) { - start = TOKEN_INVERTS[stop]; - depth = 1; - } - if (!stop) { - stop = TOKEN_INVERTS[start]; - } - str = Object(str); - var startPushing = false, token, cursor = 0, found = false; - while ((token = str.charAt(cursor++))) { - if (token === start) { - depth++; - if (!startPushing) { - startPushing = true; - if (includeStartEnd) { - ret.push(token); - } - } else { - ret.push(token); - } - } else if (token === stop && cursor) { - depth--; - if (depth === 0) { - if (includeStartEnd) { - ret.push(token); - } - found = true; - break; + if (this.options.backtrack_lexer) { + // save context + backup = { + yylineno: this.yylineno, + yylloc: { + first_line: this.yylloc.first_line, + last_line: this.last_line, + first_column: this.yylloc.first_column, + last_column: this.yylloc.last_column + }, + yytext: this.yytext, + match: this.match, + matches: this.matches, + matched: this.matched, + yyleng: this.yyleng, + offset: this.offset, + _more: this._more, + _input: this._input, + yy: this.yy, + conditionStack: this.conditionStack.slice(0), + done: this.done + }; + if (this.options.ranges) { + backup.yylloc.range = this.yylloc.range.slice(0); } - ret.push(token); - } else if (startPushing) { - ret.push(token); } - } - if (!found) { - throw new Error("Unable to match " + start + " in " + str); - } - return ret; -}; - -exports.getParamList = function (str) { - return getTokensBetween(str, "(", ")", true).join(""); -}; -exports.resolve = function (from, to) { - if (path.extname(from) !== '') { - from = path.dirname(from); - } - if (to.split(pathSep).length === 1) { - return to; - } - return path.resolve(from, to); - -}; - -var findNextTokenIndex = exports.findNextTokenIndex = function (str, startIndex, endIndex) { - startIndex = startIndex || 0; - endIndex = endIndex || str.length; - var ret = -1, l = str.length; - if (!endIndex || endIndex > l) { - endIndex = l; - } - for (; startIndex < endIndex; startIndex++) { - var c = str.charAt(startIndex); - if (!WHITE_SPACE_REG.test(c)) { - ret = startIndex; - break; + lines = match[0].match(/(?:\r\n?|\n).*/g); + if (lines) { + this.yylineno += lines.length; } - } - return ret; -}; - -exports.findNextToken = function (str, startIndex, endIndex) { - return str.charAt(findNextTokenIndex(str, startIndex, endIndex)); -}; -},{"__browserify_process":54,"path":52}],38:[function(require,module,exports){ -"use strict"; -var extd = require("./extended"), - isEmpty = extd.isEmpty, - merge = extd.merge, - forEach = extd.forEach, - declare = extd.declare, - constraintMatcher = require("./constraintMatcher"), - constraint = require("./constraint"), - EqualityConstraint = constraint.EqualityConstraint, - FromConstraint = constraint.FromConstraint; - -var id = 0; -var Pattern = declare({}); - -var ObjectPattern = Pattern.extend({ - instance: { - constructor: function (type, alias, conditions, store, options) { - options = options || {}; - this.id = id++; - this.type = type; - this.alias = alias; - this.conditions = conditions; - this.pattern = options.pattern; - var constraints = [new constraint.ObjectConstraint(type)]; - var constrnts = constraintMatcher.toConstraints(conditions, merge({alias: alias}, options)); - if (constrnts.length) { - constraints = constraints.concat(constrnts); - } else { - var cnstrnt = new constraint.TrueConstraint(); - constraints.push(cnstrnt); - } - if (store && !isEmpty(store)) { - var atm = new constraint.HashConstraint(store); - constraints.push(atm); + this.yylloc = { + first_line: this.yylloc.last_line, + last_line: this.yylineno + 1, + first_column: this.yylloc.last_column, + last_column: lines ? + lines[lines.length - 1].length - lines[lines.length - 1].match(/\r?\n?/)[0].length : + this.yylloc.last_column + match[0].length + }; + this.yytext += match[0]; + this.match += match[0]; + this.matches = match; + this.yyleng = this.yytext.length; + if (this.options.ranges) { + this.yylloc.range = [this.offset, this.offset += this.yyleng]; + } + this._more = false; + this._backtrack = false; + this._input = this._input.slice(match[0].length); + this.matched += match[0]; + token = this.performAction.call(this, this.yy, this, indexed_rule, this.conditionStack[this.conditionStack.length - 1]); + if (this.done && this._input) { + this.done = false; + } + if (token) { + return token; + } else if (this._backtrack) { + // recover context + for (var k in backup) { + this[k] = backup[k]; } + return false; // rule action called reject() implying the next rule should be tested instead. + } + return false; + }, - forEach(constraints, function (constraint) { - constraint.set("alias", alias); - }); - this.constraints = constraints; - }, +// return next match in input +next:function () { + if (this.done) { + return this.EOF; + } + if (!this._input) { + this.done = true; + } - getSpecificity: function () { - var constraints = this.constraints, specificity = 0; - for (var i = 0, l = constraints.length; i < l; i++) { - if (constraints[i] instanceof EqualityConstraint) { - specificity++; + var token, + match, + tempMatch, + index; + if (!this._more) { + this.yytext = ''; + this.match = ''; + } + var rules = this._currentRules(); + for (var i = 0; i < rules.length; i++) { + tempMatch = this._input.match(this.rules[rules[i]]); + if (tempMatch && (!match || tempMatch[0].length > match[0].length)) { + match = tempMatch; + index = i; + if (this.options.backtrack_lexer) { + token = this.test_match(tempMatch, rules[i]); + if (token !== false) { + return token; + } else if (this._backtrack) { + match = false; + continue; // rule action called reject() implying a rule MISmatch. + } else { + // else: this is a lexer rule which consumes input without producing a token (e.g. whitespace) + return false; + } + } else if (!this.options.flex) { + break; } } - return specificity; - }, - - hasConstraint: function (type) { - return extd.some(this.constraints, function (c) { - return c instanceof type; - }); - }, - - hashCode: function () { - return [this.type, this.alias, extd.format("%j", this.conditions)].join(":"); - }, - - toString: function () { - return extd.format("%j", this.constraints); } - } -}).as(exports, "ObjectPattern"); - -var FromPattern = ObjectPattern.extend({ - instance: { - constructor: function (type, alias, conditions, store, from, options) { - this._super([type, alias, conditions, store, options]); - this.from = new FromConstraint(from, options); - }, - - hasConstraint: function (type) { - return extd.some(this.constraints, function (c) { - return c instanceof type; + if (match) { + token = this.test_match(match, rules[index]); + if (token !== false) { + return token; + } + // else: this is a lexer rule which consumes input without producing a token (e.g. whitespace) + return false; + } + if (this._input === "") { + return this.EOF; + } else { + return this.parseError('Lexical error on line ' + (this.yylineno + 1) + '. Unrecognized text.\n' + this.showPosition(), { + text: "", + token: null, + line: this.yylineno }); - }, + } + }, - getSpecificity: function () { - return this._super(arguments) + 1; - }, +// return next match that has a token +lex:function lex() { + var r = this.next(); + if (r) { + return r; + } else { + return this.lex(); + } + }, - hashCode: function () { - return [this.type, this.alias, extd.format("%j", this.conditions), this.from.from].join(":"); - }, +// activates a new lexer condition state (pushes the new lexer condition state onto the condition stack) +begin:function begin(condition) { + this.conditionStack.push(condition); + }, - toString: function () { - return extd.format("%j from %s", this.constraints, this.from.from); +// pop the previously active lexer condition state off the condition stack +popState:function popState() { + var n = this.conditionStack.length - 1; + if (n > 0) { + return this.conditionStack.pop(); + } else { + return this.conditionStack[0]; } - } -}).as(exports, "FromPattern"); - + }, -FromPattern.extend().as(exports, "FromNotPattern"); -ObjectPattern.extend().as(exports, "NotPattern"); +// produce the lexer rule set which is active for the currently active lexer condition state +_currentRules:function _currentRules() { + if (this.conditionStack.length && this.conditionStack[this.conditionStack.length - 1]) { + return this.conditions[this.conditionStack[this.conditionStack.length - 1]].rules; + } else { + return this.conditions["INITIAL"].rules; + } + }, -Pattern.extend({ +// return the currently active lexer condition state; when an index argument is provided it produces the N-th previous condition state, if available +topState:function topState(n) { + n = this.conditionStack.length - 1 - Math.abs(n || 0); + if (n >= 0) { + return this.conditionStack[n]; + } else { + return "INITIAL"; + } + }, - instance: { - constructor: function (left, right) { - this.id = id++; - this.leftPattern = left; - this.rightPattern = right; - }, +// alias for begin(condition) +pushState:function pushState(condition) { + this.begin(condition); + }, - hashCode: function () { - return [this.leftPattern.hashCode(), this.rightPattern.hashCode()].join(":"); - }, +// return the number of states currently on the stack +stateStackSize:function stateStackSize() { + return this.conditionStack.length; + }, +options: {}, +performAction: function anonymous(yy,yy_,$avoiding_name_collisions,YY_START) { - getSpecificity: function () { - return this.rightPattern.getSpecificity() + this.leftPattern.getSpecificity(); - }, +var YYSTATE=YY_START; +switch($avoiding_name_collisions) { +case 0:return 29; +break; +case 1:return 31; +break; +case 2:return 'from'; +break; +case 3:return 24; +break; +case 4:return 25; +break; +case 5:return 21; +break; +case 6:return 19; +break; +case 7:return 22; +break; +case 8:return 20; +break; +case 9:return 26; +break; +case 10:return 27; +break; +case 11:return 34; +break; +case 12:return 36; +break; +case 13:return 55; +break; +case 14:return 53; +break; +case 15:/* skip whitespace */ +break; +case 16:return 49; +break; +case 17:return 48; +break; +case 18:return 48; +break; +case 19:return 40; +break; +case 20:return 51; +break; +case 21:return 41; +break; +case 22:return 11; +break; +case 23:return 12; +break; +case 24:return 13; +break; +case 25:return 38; +break; +case 26:return 8; +break; +case 27:return 26; +break; +case 28:return 27; +break; +case 29:return 24; +break; +case 30:return 24; +break; +case 31:return 25; +break; +case 32:return 25; +break; +case 33:return 21; +break; +case 34:return 22; +break; +case 35:return 20; +break; +case 36:return 19; +break; +case 37:return 34; +break; +case 38:return 36; +break; +case 39:return 15; +break; +case 40:return 17; +break; +case 41:return 46; +break; +case 42:return 44; +break; +case 43:return 42; +break; +case 44:return 47; +break; +case 45:return 9; +break; +case 46:return 5; +break; +} +}, +rules: [/^(?:\s+in\b)/,/^(?:\s+notIn\b)/,/^(?:\s+from\b)/,/^(?:\s+(eq|EQ)\b)/,/^(?:\s+(neq|NEQ)\b)/,/^(?:\s+(lte|LTE)\b)/,/^(?:\s+(lt|LT)\b)/,/^(?:\s+(gte|GTE)\b)/,/^(?:\s+(gt|GT)\b)/,/^(?:\s+(like|LIKE)\b)/,/^(?:\s+(notLike|NOT_LIKE)\b)/,/^(?:\s+(and|AND)\b)/,/^(?:\s+(or|OR)\b)/,/^(?:\s+null\b)/,/^(?:\s+(true|false)\b)/,/^(?:\s+)/,/^(?:-?[0-9]+(?:\.[0-9]+)?\b)/,/^(?:'[^']*')/,/^(?:"[^"]*")/,/^(?:([a-zA-Z_$][0-9a-zA-Z_$]*))/,/^(?:^\/((?![\s=])[^[\/\n\\]*(?:(?:\\[\s\S]|\[[^\]\n\\]*(?:\\[\s\S][^\]\n\\]*)*])[^[\/\n\\]*)*\/[imgy]{0,4})(?!\w))/,/^(?:\.)/,/^(?:\*)/,/^(?:\/)/,/^(?:\%)/,/^(?:,)/,/^(?:-)/,/^(?:=~)/,/^(?:!=~)/,/^(?:==)/,/^(?:===)/,/^(?:!=)/,/^(?:!==)/,/^(?:<=)/,/^(?:>=)/,/^(?:>)/,/^(?:<)/,/^(?:&&)/,/^(?:\|\|)/,/^(?:\+)/,/^(?:\^)/,/^(?:\()/,/^(?:\])/,/^(?:\[)/,/^(?:\))/,/^(?:!)/,/^(?:$)/], +conditions: {"INITIAL":{"rules":[0,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],"inclusive":true}} +}; +return lexer; +})(); +parser.lexer = lexer; +function Parser () { + this.yy = {}; +} +Parser.prototype = parser;parser.Parser = Parser; +return new Parser; +})(); - getters: { - constraints: function () { - return this.leftPattern.constraints.concat(this.rightPattern.constraints); - } - } + +if (typeof require !== 'undefined' && typeof exports !== 'undefined') { +exports.parser = parser; +exports.Parser = parser.Parser; +exports.parse = function () { return parser.parse.apply(parser, arguments); }; +exports.main = function commonjsMain(args) { + if (!args[1]) { + console.log('Usage: '+args[0]+' FILE'); + process.exit(1); } + var source = require('fs').readFileSync(require('path').normalize(args[1]), "utf8"); + return exports.parser.parse(source); +}; +if (typeof module !== 'undefined' && require.main === module) { + exports.main(process.argv.slice(1)); +} +} +},{"__browserify_process":68,"fs":65,"path":66}],41:[function(require,module,exports){ +(function () { + "use strict"; + var constraintParser = require("./constraint/parser"), + noolParser = require("./nools/nool.parser"); -}).as(exports, "CompositePattern"); + exports.parseConstraint = function (expression) { + try { + return constraintParser.parse(expression); + } catch (e) { + throw new Error("Invalid expression '" + expression + "'"); + } + }; + exports.parseRuleSet = function (source, file) { + return noolParser.parse(source, file); + }; +})(); +},{"./constraint/parser":40,"./nools/nool.parser":42}],42:[function(require,module,exports){ +"use strict"; -var InitialFact = declare({ - instance: { - constructor: function () { - this.id = id++; - this.recency = 0; - } - } -}).as(exports, "InitialFact"); +var tokens = require("./tokens.js"), + extd = require("../../extended"), + keys = extd.hash.keys, + utils = require("./util.js"); -ObjectPattern.extend({ - instance: { - constructor: function () { - this._super([InitialFact, "i", [], {}]); - }, +var parse = function (src, keywords, context) { + var orig = src; + src = src.replace(/\/\/(.*)/g, "").replace(/\n|\r|\r\n/g, " "); - assert: function () { - return true; + var blockTypes = new RegExp("^(" + keys(keywords).join("|") + ")"), index; + while (src && (index = utils.findNextTokenIndex(src)) !== -1) { + src = src.substr(index); + var blockType = src.match(blockTypes); + if (blockType !== null) { + blockType = blockType[1]; + if (blockType in keywords) { + try { + src = keywords[blockType](src, context, parse).replace(/^\s*|\s*$/g, ""); + } catch (e) { + throw new Error("Invalid " + blockType + " definition \n" + e.message + "; \nstarting at : " + orig); + } + } else { + throw new Error("Unknown token" + blockType); + } + } else { + throw new Error("Error parsing " + src); } } -}).as(exports, "InitialFactPattern"); +}; +exports.parse = function (src, file) { + var context = {define: [], rules: [], scope: [], loaded: [], file: file}; + parse(src, tokens, context); + return context; +}; +},{"../../extended":12,"./tokens.js":43,"./util.js":44}],43:[function(require,module,exports){ +var process=require("__browserify_process");"use strict"; -},{"./constraint":8,"./constraintMatcher":9,"./extended":12}],39:[function(require,module,exports){ -"use strict"; -var extd = require("./extended"), - isArray = extd.isArray, - Promise = extd.Promise, - declare = extd.declare, - isHash = extd.isHash, - isString = extd.isString, - format = extd.format, - parser = require("./parser"), - pattern = require("./pattern"), - ObjectPattern = pattern.ObjectPattern, - FromPattern = pattern.FromPattern, - NotPattern = pattern.NotPattern, - FromNotPattern = pattern.FromNotPattern, - CompositePattern = pattern.CompositePattern; +var utils = require("./util.js"), + fs = require("fs"), + extd = require("../../extended"), + filter = extd.filter, + indexOf = extd.indexOf, + predicates = ["not", "or", "exists"], + predicateRegExp = new RegExp("^(" + predicates.join("|") + ") *\\((.*)\\)$", "m"), + predicateBeginExp = new RegExp(" *(" + predicates.join("|") + ") *\\(", "g"); -var parseExtra = extd - .switcher() - .isUndefinedOrNull(function () { - return null; - }) - .isLike(/^from +/, function (s) { - return {from: s.replace(/^from +/, "").replace(/^\s*|\s*$/g, "")}; - }) - .def(function (o) { - throw new Error("invalid rule constraint option " + o); - }) - .switcher(); - -var normailizeConstraint = extd - .switcher() - .isLength(1, function (c) { - throw new Error("invalid rule constraint " + format("%j", [c])); - }) - .isLength(2, function (c) { - c.push("true"); - return c; - }) - //handle case where c[2] is a hash rather than a constraint string - .isLength(3, function (c) { - if (isString(c[2]) && /^from +/.test(c[2])) { - var extra = c[2]; - c.splice(2, 0, "true"); - c[3] = null; - c[4] = parseExtra(extra); - } else if (isHash(c[2])) { - c.splice(2, 0, "true"); - } - return c; - }) - //handle case where c[3] is a from clause rather than a hash for references - .isLength(4, function (c) { - if (isString(c[3])) { - c.splice(3, 0, null); - c[4] = parseExtra(c[4]); - } - return c; - }) - .def(function (c) { - if (c.length === 5) { - c[4] = parseExtra(c[4]); - } - return c; - }) - .switcher(); - - -var getParamTypeSwitch = extd - .switcher() - .isEq("string", function () { - return String; - }) - .isEq("date", function () { - return Date; - }) - .isEq("array", function () { - return Array; - }) - .isEq("boolean", function () { - return Boolean; - }) - .isEq("regexp", function () { - return RegExp; - }) - .isEq("number", function () { - return Number; - }) - .isEq("object", function () { - return Object; - }) - .isEq("hash", function () { - return Object; - }) - .def(function (param) { - throw new TypeError("invalid param type " + param); - }) - .switcher(); +var isWhiteSpace = function (str) { + return str.replace(/[\s|\n|\r|\t]/g, "").length === 0; +}; +var joinFunc = function (m, str) { + return "; " + str; +}; -var getParamType = extd - .switcher() - .isString(function (param) { - return getParamTypeSwitch(param.toLowerCase()); - }) - .isFunction(function (func) { - return func; - }) - .deepEqual([], function () { - return Array; - }) - .def(function (param) { - throw new Error("invalid param type " + param); - }) - .switcher(); +var splitRuleLineByPredicateExpressions = function (ruleLine) { + var str = ruleLine.replace(/,\s*(\$?\w+\s*:)/g, joinFunc); + var parts = filter(str.split(predicateBeginExp), function (str) { + return str !== ""; + }), + l = parts.length, ret = []; -var parsePattern = extd - .switcher() - .containsAt("or", 0, function (condition) { - condition.shift(); - return extd(condition).map(function (cond) { - cond.scope = condition.scope; - return parsePattern(cond); - }).flatten().value(); - }) - .contains("not", 0, function (condition) { - condition.shift(); - condition = normailizeConstraint(condition); - if (condition[4] && condition[4].from) { - return [ - new FromNotPattern( - getParamType(condition[0]), - condition[1] || "m", - parser.parseConstraint(condition[2] || "true"), - condition[3] || {}, - parser.parseConstraint(condition[4].from), - {scope: condition.scope, pattern: condition[2]} - ) - ]; - } else { - return [ - new NotPattern( - getParamType(condition[0]), - condition[1] || "m", - parser.parseConstraint(condition[2] || "true"), - condition[3] || {}, - {scope: condition.scope, pattern: condition[2]} - ) - ]; - } - }) - .def(function (condition) { - condition = normailizeConstraint(condition); - if (condition[4] && condition[4].from) { - return [ - new FromPattern( - getParamType(condition[0]), - condition[1] || "m", - parser.parseConstraint(condition[2] || "true"), - condition[3] || {}, - parser.parseConstraint(condition[4].from), - {scope: condition.scope, pattern: condition[2]} - ) - ]; - } else { - return [ - new ObjectPattern( - getParamType(condition[0]), - condition[1] || "m", - parser.parseConstraint(condition[2] || "true"), - condition[3] || {}, - {scope: condition.scope, pattern: condition[2]} - ) - ]; + if (l) { + for (var i = 0; i < l; i++) { + if (indexOf(predicates, parts[i]) !== -1) { + ret.push([parts[i], "(", parts[++i].replace(/, *$/, "")].join("")); + } else { + ret.push(parts[i].replace(/, *$/, "")); + } } - }).switcher(); + } else { + return str; + } + return ret.join(";"); +}; -var Rule = declare({ - instance: { - constructor: function (name, options, pattern, cb) { - this.name = name; - this.pattern = pattern; - this.cb = cb; - if (options.agendaGroup) { - this.agendaGroup = options.agendaGroup; - this.autoFocus = extd.isBoolean(options.autoFocus) ? options.autoFocus : false; - } - this.priority = options.priority || options.salience || 0; - }, +var ruleTokens = { - fire: function (flow, match) { - var ret = new Promise(), cb = this.cb; - try { - if (cb.length === 3) { - cb.call(flow, match.factHash, flow, ret.resolve); + salience: (function () { + var salienceRegexp = /^(salience|priority)\s*:\s*(-?\d+)\s*[,;]?/; + return function (src, context) { + if (salienceRegexp.test(src)) { + var parts = src.match(salienceRegexp), + priority = parseInt(parts[2], 10); + if (!isNaN(priority)) { + context.options.priority = priority; } else { - ret = cb.call(flow, match.factHash, flow); + throw new Error("Invalid salience/priority " + parts[2]); } - } catch (e) { - ret.errback(e); + return src.replace(parts[0], ""); + } else { + throw new Error("invalid format"); } - return ret; - } - } -}); + }; + })(), -function createRule(name, options, conditions, cb) { - if (isArray(options)) { - cb = conditions; - conditions = options; - } else { - options = options || {}; - } - var isRules = extd.every(conditions, function (cond) { - return isArray(cond); - }); - if (isRules && conditions.length === 1) { - conditions = conditions[0]; - isRules = false; - } - var rules = []; - var scope = options.scope || {}; - conditions.scope = scope; - if (isRules) { - var _mergePatterns = function (patt, i) { - if (!patterns[i]) { - patterns[i] = i === 0 ? [] : patterns[i - 1].slice(); - //remove dup - if (i !== 0) { - patterns[i].pop(); + agendaGroup: (function () { + var agendaGroupRegexp = /^(agenda-group|agendaGroup)\s*:\s*([a-zA-Z_$][0-9a-zA-Z_$]*|"[^"]*"|'[^']*')\s*[,;]?/; + return function (src, context) { + if (agendaGroupRegexp.test(src)) { + var parts = src.match(agendaGroupRegexp), + agendaGroup = parts[2]; + if (agendaGroup) { + context.options.agendaGroup = agendaGroup.replace(/^["']|["']$/g, ""); + } else { + throw new Error("Invalid agenda-group " + parts[2]); } - patterns[i].push(patt); + return src.replace(parts[0], ""); } else { - extd(patterns).forEach(function (p) { - p.push(patt); - }); + throw new Error("invalid format"); } - }; - var l = conditions.length, patterns = [], condition; - for (var i = 0; i < l; i++) { - condition = conditions[i]; - condition.scope = scope; - extd.forEach(parsePattern(condition), _mergePatterns); + })(), - } - rules = extd.map(patterns, function (patterns) { - var compPat = null; - for (var i = 0; i < patterns.length; i++) { - if (compPat === null) { - compPat = new CompositePattern(patterns[i++], patterns[i]); + autoFocus: (function () { + var autoFocusRegexp = /^(auto-focus|autoFocus)\s*:\s*(true|false)\s*[,;]?/; + return function (src, context) { + if (autoFocusRegexp.test(src)) { + var parts = src.match(autoFocusRegexp), + autoFocus = parts[2]; + if (autoFocus) { + context.options.autoFocus = autoFocus === "true" ? true : false; } else { - compPat = new CompositePattern(compPat, patterns[i]); + throw new Error("Invalid auto-focus " + parts[2]); } + return src.replace(parts[0], ""); + } else { + throw new Error("invalid format"); } - return new Rule(name, options, compPat, cb); - }); - } else { - rules = extd.map(parsePattern(conditions), function (cond) { - return new Rule(name, options, cond, cb); - }); - } - return rules; -} + }; + })(), -exports.createRule = createRule; + "agenda-group": function () { + return this.agendaGroup.apply(this, arguments); + }, + "auto-focus": function () { + return this.autoFocus.apply(this, arguments); + }, + priority: function () { + return this.salience.apply(this, arguments); + }, + when: (function () { + /*jshint evil:true*/ -},{"./extended":12,"./parser":34,"./pattern":38}],40:[function(require,module,exports){ -"use strict"; -var declare = require("declare.js"), - LinkedList = require("./linkedList"), - id = 0; - -var Fact = declare({ - - instance: { - constructor: function (obj) { - this.object = obj; - this.recency = 0; - this.id = id++; - }, - - equals: function (fact) { - return fact === this.object; - }, - - hashCode: function () { - return this.id; - } - } - -}); - -declare({ - - instance: { - - constructor: function () { - this.recency = 0; - this.facts = new LinkedList(); - }, + var ruleRegExp = /^(\$?\w+) *: *(\w+)(.*)/; - dispose: function () { - this.facts.clear(); - }, + var constraintRegExp = /(\{ *(?:["']?\$?\w+["']?\s*:\s*["']?\$?\w+["']? *(?:, *["']?\$?\w+["']?\s*:\s*["']?\$?\w+["']?)*)+ *\})/; + var fromRegExp = /(\bfrom\s+.*)/; + var parseRules = function (str) { + var rules = []; + var ruleLines = str.split(";"), l = ruleLines.length, ruleLine; + for (var i = 0; i < l && (ruleLine = ruleLines[i].replace(/^\s*|\s*$/g, "").replace(/\n/g, "")); i++) { + if (!isWhiteSpace(ruleLine)) { + var rule = []; + if (predicateRegExp.test(ruleLine)) { + var m = ruleLine.match(predicateRegExp); + var pred = m[1].replace(/^\s*|\s*$/g, ""); + rule.push(pred); + ruleLine = m[2].replace(/^\s*|\s*$/g, ""); + if (pred === "or") { + rule = rule.concat(parseRules(splitRuleLineByPredicateExpressions(ruleLine))); + rules.push(rule); + continue; + } - getFactHandle: function (o) { - var head = {next: this.facts.head}, ret; - while ((head = head.next)) { - var existingFact = head.data; - if (existingFact.equals(o)) { - return existingFact; + } + var parts = ruleLine.match(ruleRegExp); + if (parts && parts.length) { + rule.push(parts[2], parts[1]); + var constraints = parts[3].replace(/^\s*|\s*$/g, ""); + var hashParts = constraints.match(constraintRegExp), from = null, fromMatch; + if (hashParts) { + var hash = hashParts[1], constraint = constraints.replace(hash, ""); + if (fromRegExp.test(constraint)) { + fromMatch = constraint.match(fromRegExp); + from = fromMatch[0]; + constraint = constraint.replace(fromMatch[0], ""); + } + if (constraint) { + rule.push(constraint.replace(/^\s*|\s*$/g, "")); + } + if (hash) { + rule.push(eval("(" + hash.replace(/(\$?\w+)\s*:\s*(\$?\w+)/g, '"$1" : "$2"') + ")")); + } + } else if (constraints && !isWhiteSpace(constraints)) { + if (fromRegExp.test(constraints)) { + fromMatch = constraints.match(fromRegExp); + from = fromMatch[0]; + constraints = constraints.replace(fromMatch[0], ""); + } + rule.push(constraints); + } + if (from) { + rule.push(from); + } + rules.push(rule); + } else { + throw new Error("Invalid constraint " + ruleLine); + } } } - if (!ret) { - ret = new Fact(o); - ret.recency = this.recency++; - //this.facts.push(ret); - } - return ret; - }, + return rules; + }; - modifyFact: function (fact) { - var head = {next: this.facts.head}; - while ((head = head.next)) { - var existingFact = head.data; - if (existingFact.equals(fact)) { - existingFact.recency = this.recency++; - return existingFact; - } + return function (orig, context) { + var src = orig.replace(/^when\s*/, "").replace(/^\s*|\s*$/g, ""); + if (utils.findNextToken(src) === "{") { + var body = utils.getTokensBetween(src, "{", "}", true).join(""); + src = src.replace(body, ""); + context.constraints = parseRules(body.replace(/^\{\s*|\}\s*$/g, "")); + return src; + } else { + throw new Error("unexpected token : expected : '{' found : '" + utils.findNextToken(src) + "'"); } - //if we made it here we did not find the fact - throw new Error("the fact to modify does not exist"); - }, - - assertFact: function (fact) { - var ret = new Fact(fact); - ret.recency = this.recency++; - this.facts.push(ret); - return ret; -// var head = {next: this.facts.head}, ret; -// while ((head = head.next)) { -// var existingFact = head.data; -// if (existingFact.equals(fact)) { -// ret = existingFact; -// break; -// } -// } -// if (!ret) { -// ret = new Fact(fact); -// ret.recency = this.recency++; -// this.facts.push(ret); -// } -// return ret; - }, + }; + })(), - retractFact: function (fact) { - var facts = this.facts, head = {next: facts.head}; - while ((head = head.next)) { - var existingFact = head.data; - if (existingFact.equals(fact)) { - facts.remove(head); - return existingFact; + then: (function () { + return function (orig, context) { + if (!context.action) { + var src = orig.replace(/^then\s*/, "").replace(/^\s*|\s*$/g, ""); + if (utils.findNextToken(src) === "{") { + var body = utils.getTokensBetween(src, "{", "}", true).join(""); + src = src.replace(body, ""); + if (!context.action) { + context.action = body.replace(/^\{\s*|\}\s*$/g, ""); + } + if (!isWhiteSpace(src)) { + throw new Error("Error parsing then block " + orig); + } + return src; + } else { + throw new Error("unexpected token : expected : '{' found : '" + utils.findNextToken(src) + "'"); } + } else { + throw new Error("action already defined for rule" + context.name); } - //if we made it here we did not find the fact - throw new Error("the fact to remove does not exist"); + }; + })() +}; +var topLevelTokens = { + "/": function (orig) { + if (orig.match(/^\/\*/)) { + // Block Comment parse + return orig.replace(/\/\*.*?\*\//, ""); + } else { + return orig; } - } - -}).as(exports, "WorkingMemory"); - - -},{"./linkedList":16,"declare.js":45}],41:[function(require,module,exports){ -(function () { - "use strict"; - - function defineArgumentsExtended(extended, is) { + }, - var pSlice = Array.prototype.slice, - isArguments = is.isArguments; + "define": function (orig, context) { + var src = orig.replace(/^define\s*/, ""); + var name = src.match(/^([a-zA-Z_$][0-9a-zA-Z_$]*)/); + if (name) { + src = src.replace(name[0], "").replace(/^\s*|\s*$/g, ""); + if (utils.findNextToken(src) === "{") { + name = name[1]; + var body = utils.getTokensBetween(src, "{", "}", true).join(""); + src = src.replace(body, ""); + //should + context.define.push({name: name, properties: "(" + body + ")"}); + return src; + } else { + throw new Error("unexpected token : expected : '{' found : '" + utils.findNextToken(src) + "'"); + } + } else { + throw new Error("missing name"); + } + }, - function argsToArray(args, slice) { - var i = -1, j = 0, l = args.length, ret = []; - slice = slice || 0; - i += slice; - while (++i < l) { - ret[j++] = args[i]; + "import": function (orig, context, parse) { + if (typeof window !== 'undefined') { + throw new Error("import cannot be used in a browser"); + } + var src = orig.replace(/^import\s*/, ""); + if (utils.findNextToken(src) === "(") { + var file = utils.getParamList(src); + src = src.replace(file, "").replace(/^\s*|\s*$/g, ""); + utils.findNextToken(src) === ";" && (src = src.replace(/\s*;/, "")); + file = file.replace(/[\(|\)]/g, "").split(","); + if (file.length === 1) { + file = utils.resolve(context.file || process.cwd(), file[0].replace(/["|']/g, "")); + if (indexOf(context.loaded, file) === -1) { + var origFile = context.file; + context.file = file; + parse(fs.readFileSync(file, "utf8"), topLevelTokens, context); + context.loaded.push(file); + context.file = origFile; + } + return src; + } else { + throw new Error("import accepts a single file"); } - return ret; + } else { + throw new Error("unexpected token : expected : '(' found : '" + utils.findNextToken(src) + "'"); } + }, - return extended - .define(isArguments, { - toArray: argsToArray - }) - .expose({ - argsToArray: argsToArray - }); - } - - if ("undefined" !== typeof exports) { - if ("undefined" !== typeof module && module.exports) { - module.exports = defineArgumentsExtended(require("extended"), require("is-extended")); - - } - } else if ("function" === typeof define && define.amd) { - define(["extended", "is-extended"], function (extended, is) { - return defineArgumentsExtended(extended, is); - }); - } else { - this.argumentsExtended = defineArgumentsExtended(this.extended, this.isExtended); - } - -}).call(this); - - -},{"extended":46,"is-extended":56}],42:[function(require,module,exports){ -(function () { - "use strict"; - /*global define*/ - - function defineArray(extended, is, args) { - - var isString = is.isString, - isArray = Array.isArray || is.isArray, - isDate = is.isDate, - floor = Math.floor, - abs = Math.abs, - mathMax = Math.max, - mathMin = Math.min, - arrayProto = Array.prototype, - arrayIndexOf = arrayProto.indexOf, - arrayForEach = arrayProto.forEach, - arrayMap = arrayProto.map, - arrayReduce = arrayProto.reduce, - arrayReduceRight = arrayProto.reduceRight, - arrayFilter = arrayProto.filter, - arrayEvery = arrayProto.every, - arraySome = arrayProto.some, - argsToArray = args.argsToArray; - - - function cross(num, cros) { - return reduceRight(cros, function (a, b) { - if (!isArray(b)) { - b = [b]; + //define a global + "global": function (orig, context) { + var src = orig.replace(/^global\s*/, ""); + var name = src.match(/^([a-zA-Z_$][0-9a-zA-Z_$]*\s*)/); + if (name) { + src = src.replace(name[0], "").replace(/^\s*|\s*$/g, ""); + if (utils.findNextToken(src) === "=") { + name = name[1].replace(/^\s+|\s+$/g, ''); + var fullbody = utils.getTokensBetween(src, "=", ";", true).join(""); + var body = fullbody.substring(1, fullbody.length - 1); + body = body.replace(/^\s+|\s+$/g, ''); + if (/^require\(/.test(body)) { + var file = utils.getParamList(body.replace("require")).replace(/[\(|\)]/g, "").split(","); + if (file.length === 1) { + //handle relative require calls + file = file[0].replace(/["|']/g, ""); + body = ["require('", utils.resolve(context.file || process.cwd(), file) , "')"].join(""); + } } - b.unshift(num); - a.unshift(b); - return a; - }, []); + context.scope.push({name: name, body: body}); + src = src.replace(fullbody, ""); + return src; + } else { + throw new Error("unexpected token : expected : '=' found : '" + utils.findNextToken(src) + "'"); + } + } else { + throw new Error("missing name"); } + }, - function permute(num, cross, length) { - var ret = []; - for (var i = 0; i < cross.length; i++) { - ret.push([num].concat(rotate(cross, i)).slice(0, length)); + //define a function + "function": function (orig, context) { + var src = orig.replace(/^function\s*/, ""); + //parse the function name + var name = src.match(/^([a-zA-Z_$][0-9a-zA-Z_$]*)\s*/); + if (name) { + src = src.replace(name[0], ""); + if (utils.findNextToken(src) === "(") { + name = name[1]; + var params = utils.getParamList(src); + src = src.replace(params, "").replace(/^\s*|\s*$/g, ""); + if (utils.findNextToken(src) === "{") { + var body = utils.getTokensBetween(src, "{", "}", true).join(""); + src = src.replace(body, ""); + //should + context.scope.push({name: name, body: "function" + params + body}); + return src; + } else { + throw new Error("unexpected token : expected : '{' found : '" + utils.findNextToken(src) + "'"); + } + } else { + throw new Error("unexpected token : expected : '(' found : '" + utils.findNextToken(src) + "'"); } - return ret; + } else { + throw new Error("missing name"); } + }, - - function intersection(a, b) { - var ret = [], aOne, i = -1, l; - l = a.length; - while (++i < l) { - aOne = a[i]; - if (indexOf(b, aOne) !== -1) { - ret.push(aOne); - } + "rule": function (orig, context, parse) { + var src = orig.replace(/^rule\s*/, ""); + var name = src.match(/^([a-zA-Z_$][0-9a-zA-Z_$]*|"[^"]*"|'[^']*')/); + if (name) { + src = src.replace(name[0], "").replace(/^\s*|\s*$/g, ""); + if (utils.findNextToken(src) === "{") { + name = name[1].replace(/^["']|["']$/g, ""); + var rule = {name: name, options: {}, constraints: null, action: null}; + var body = utils.getTokensBetween(src, "{", "}", true).join(""); + src = src.replace(body, ""); + parse(body.replace(/^\{\s*|\}\s*$/g, ""), ruleTokens, rule); + context.rules.push(rule); + return src; + } else { + throw new Error("unexpected token : expected : '{' found : '" + utils.findNextToken(src) + "'"); } - return ret; + } else { + throw new Error("missing name"); } + } +}; +module.exports = topLevelTokens; - var _sort = (function () { - var isAll = function (arr, test) { - return every(arr, test); - }; +},{"../../extended":12,"./util.js":44,"__browserify_process":68,"fs":65}],44:[function(require,module,exports){ +var process=require("__browserify_process");"use strict"; - var defaultCmp = function (a, b) { - return a - b; - }; +var path = require("path"); +var WHITE_SPACE_REG = /[\s|\n|\r|\t]/, + pathSep = path.sep || ( process.platform === 'win32' ? '\\' : '/' ); - var dateSort = function (a, b) { - return a.getTime() - b.getTime(); - }; +var TOKEN_INVERTS = { + "{": "}", + "}": "{", + "(": ")", + ")": "(", + "[": "]" +}; - return function _sort(arr, property) { - var ret = []; - if (isArray(arr)) { - ret = arr.slice(); - if (property) { - if (typeof property === "function") { - ret.sort(property); - } else { - ret.sort(function (a, b) { - var aProp = a[property], bProp = b[property]; - if (isString(aProp) && isString(bProp)) { - return aProp > bProp ? 1 : aProp < bProp ? -1 : 0; - } else if (isDate(aProp) && isDate(bProp)) { - return aProp.getTime() - bProp.getTime(); - } else { - return aProp - bProp; - } - }); - } - } else { - if (isAll(ret, isString)) { - ret.sort(); - } else if (isAll(ret, isDate)) { - ret.sort(dateSort); - } else { - ret.sort(defaultCmp); - } - } +var getTokensBetween = exports.getTokensBetween = function (str, start, stop, includeStartEnd) { + var depth = 0, ret = []; + if (!start) { + start = TOKEN_INVERTS[stop]; + depth = 1; + } + if (!stop) { + stop = TOKEN_INVERTS[start]; + } + str = Object(str); + var startPushing = false, token, cursor = 0, found = false; + while ((token = str.charAt(cursor++))) { + if (token === start) { + depth++; + if (!startPushing) { + startPushing = true; + if (includeStartEnd) { + ret.push(token); } - return ret; - }; - - })(); - - function indexOf(arr, searchElement, from) { - var index = (from || 0) - 1, - length = arr.length; - while (++index < length) { - if (arr[index] === searchElement) { - return index; + } else { + ret.push(token); + } + } else if (token === stop && cursor) { + depth--; + if (depth === 0) { + if (includeStartEnd) { + ret.push(token); } + found = true; + break; } - return -1; + ret.push(token); + } else if (startPushing) { + ret.push(token); } + } + if (!found) { + throw new Error("Unable to match " + start + " in " + str); + } + return ret; +}; - function lastIndexOf(arr, searchElement, from) { - if (!isArray(arr)) { - throw new TypeError(); - } - - var t = Object(arr); - var len = t.length >>> 0; - if (len === 0) { - return -1; - } +exports.getParamList = function (str) { + return getTokensBetween(str, "(", ")", true).join(""); +}; - var n = len; - if (arguments.length > 2) { - n = Number(arguments[2]); - if (n !== n) { - n = 0; - } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) { - n = (n > 0 || -1) * floor(abs(n)); - } - } +exports.resolve = function (from, to) { + if (path.extname(from) !== '') { + from = path.dirname(from); + } + if (to.split(pathSep).length === 1) { + return to; + } + return path.resolve(from, to); - var k = n >= 0 ? mathMin(n, len - 1) : len - abs(n); +}; - for (; k >= 0; k--) { - if (k in t && t[k] === searchElement) { - return k; - } - } - return -1; +var findNextTokenIndex = exports.findNextTokenIndex = function (str, startIndex, endIndex) { + startIndex = startIndex || 0; + endIndex = endIndex || str.length; + var ret = -1, l = str.length; + if (!endIndex || endIndex > l) { + endIndex = l; + } + for (; startIndex < endIndex; startIndex++) { + var c = str.charAt(startIndex); + if (!WHITE_SPACE_REG.test(c)) { + ret = startIndex; + break; } + } + return ret; +}; - function filter(arr, iterator, scope) { - if (arr && arrayFilter && arrayFilter === arr.filter) { - return arr.filter(iterator, scope); - } - if (!isArray(arr) || typeof iterator !== "function") { - throw new TypeError(); - } +exports.findNextToken = function (str, startIndex, endIndex) { + return str.charAt(findNextTokenIndex(str, startIndex, endIndex)); +}; +},{"__browserify_process":68,"path":66}],45:[function(require,module,exports){ +"use strict"; +var extd = require("./extended"), + isEmpty = extd.isEmpty, + merge = extd.merge, + forEach = extd.forEach, + declare = extd.declare, + constraintMatcher = require("./constraintMatcher"), + constraint = require("./constraint"), + EqualityConstraint = constraint.EqualityConstraint, + FromConstraint = constraint.FromConstraint; - var t = Object(arr); - var len = t.length >>> 0; - var res = []; - for (var i = 0; i < len; i++) { - if (i in t) { - var val = t[i]; // in case fun mutates this - if (iterator.call(scope, val, i, t)) { - res.push(val); - } - } - } - return res; - } +var id = 0; +var Pattern = declare({}); - function forEach(arr, iterator, scope) { - if (!isArray(arr) || typeof iterator !== "function") { - throw new TypeError(); - } - if (arr && arrayForEach && arrayForEach === arr.forEach) { - arr.forEach(iterator, scope); - return arr; +var ObjectPattern = Pattern.extend({ + instance: { + constructor: function (type, alias, conditions, store, options) { + options = options || {}; + this.id = id++; + this.type = type; + this.alias = alias; + this.conditions = conditions; + this.pattern = options.pattern; + var constraints = [new constraint.ObjectConstraint(type)]; + var constrnts = constraintMatcher.toConstraints(conditions, merge({alias: alias}, options)); + if (constrnts.length) { + constraints = constraints.concat(constrnts); + } else { + var cnstrnt = new constraint.TrueConstraint(); + constraints.push(cnstrnt); } - for (var i = 0, len = arr.length; i < len; ++i) { - iterator.call(scope || arr, arr[i], i, arr); + if (store && !isEmpty(store)) { + var atm = new constraint.HashConstraint(store); + constraints.push(atm); } - return arr; - } + forEach(constraints, function (constraint) { + constraint.set("alias", alias); + }); + this.constraints = constraints; + }, - function every(arr, iterator, scope) { - if (arr && arrayEvery && arrayEvery === arr.every) { - return arr.every(iterator, scope); - } - if (!isArray(arr) || typeof iterator !== "function") { - throw new TypeError(); - } - var t = Object(arr); - var len = t.length >>> 0; - for (var i = 0; i < len; i++) { - if (i in t && !iterator.call(scope, t[i], i, t)) { - return false; + getSpecificity: function () { + var constraints = this.constraints, specificity = 0; + for (var i = 0, l = constraints.length; i < l; i++) { + if (constraints[i] instanceof EqualityConstraint) { + specificity++; } } - return true; - } + return specificity; + }, - function some(arr, iterator, scope) { - if (arr && arraySome && arraySome === arr.some) { - return arr.some(iterator, scope); - } - if (!isArray(arr) || typeof iterator !== "function") { - throw new TypeError(); - } - var t = Object(arr); - var len = t.length >>> 0; - for (var i = 0; i < len; i++) { - if (i in t && iterator.call(scope, t[i], i, t)) { - return true; - } - } - return false; - } + hasConstraint: function (type) { + return extd.some(this.constraints, function (c) { + return c instanceof type; + }); + }, - function map(arr, iterator, scope) { - if (arr && arrayMap && arrayMap === arr.map) { - return arr.map(iterator, scope); - } - if (!isArray(arr) || typeof iterator !== "function") { - throw new TypeError(); - } + hashCode: function () { + return [this.type, this.alias, extd.format("%j", this.conditions)].join(":"); + }, - var t = Object(arr); - var len = t.length >>> 0; - var res = []; - for (var i = 0; i < len; i++) { - if (i in t) { - res.push(iterator.call(scope, t[i], i, t)); - } - } - return res; + toString: function () { + return extd.format("%j", this.constraints); } + } +}).as(exports, "ObjectPattern"); - function reduce(arr, accumulator, curr) { - var initial = arguments.length > 2; - if (arr && arrayReduce && arrayReduce === arr.reduce) { - return initial ? arr.reduce(accumulator, curr) : arr.reduce(accumulator); - } - if (!isArray(arr) || typeof accumulator !== "function") { - throw new TypeError(); - } - var i = 0, l = arr.length >> 0; - if (arguments.length < 3) { - if (l === 0) { - throw new TypeError("Array length is 0 and no second argument"); - } - curr = arr[0]; - i = 1; // start accumulating at the second element - } else { - curr = arguments[2]; - } - while (i < l) { - if (i in arr) { - curr = accumulator.call(undefined, curr, arr[i], i, arr); - } - ++i; - } - return curr; - } +var FromPattern = ObjectPattern.extend({ + instance: { + constructor: function (type, alias, conditions, store, from, options) { + this._super([type, alias, conditions, store, options]); + this.from = new FromConstraint(from, options); + }, - function reduceRight(arr, accumulator, curr) { - var initial = arguments.length > 2; - if (arr && arrayReduceRight && arrayReduceRight === arr.reduceRight) { - return initial ? arr.reduceRight(accumulator, curr) : arr.reduceRight(accumulator); - } - if (!isArray(arr) || typeof accumulator !== "function") { - throw new TypeError(); - } + hasConstraint: function (type) { + return extd.some(this.constraints, function (c) { + return c instanceof type; + }); + }, - var t = Object(arr); - var len = t.length >>> 0; + getSpecificity: function () { + return this._super(arguments) + 1; + }, - // no value to return if no initial value, empty array - if (len === 0 && arguments.length === 2) { - throw new TypeError(); - } + hashCode: function () { + return [this.type, this.alias, extd.format("%j", this.conditions), this.from.from].join(":"); + }, - var k = len - 1; - if (arguments.length >= 3) { - curr = arguments[2]; - } else { - do { - if (k in arr) { - curr = arr[k--]; - break; - } - } - while (true); - } - while (k >= 0) { - if (k in t) { - curr = accumulator.call(undefined, curr, t[k], k, t); - } - k--; - } - return curr; + toString: function () { + return extd.format("%j from %s", this.constraints, this.from.from); } + } +}).as(exports, "FromPattern"); - function toArray(o) { - var ret = []; - if (o !== null) { - var args = argsToArray(arguments); - if (args.length === 1) { - if (isArray(o)) { - ret = o; - } else if (is.isHash(o)) { - for (var i in o) { - if (o.hasOwnProperty(i)) { - ret.push([i, o[i]]); - } - } - } else { - ret.push(o); - } - } else { - forEach(args, function (a) { - ret = ret.concat(toArray(a)); - }); - } - } - return ret; - } - - function sum(array) { - array = array || []; - if (array.length) { - return reduce(array, function (a, b) { - return a + b; - }); - } else { - return 0; - } - } +FromPattern.extend().as(exports, "FromNotPattern"); +ObjectPattern.extend().as(exports, "NotPattern"); +ObjectPattern.extend().as(exports, "ExistsPattern"); +FromPattern.extend().as(exports, "FromExistsPattern"); - function avg(arr) { - arr = arr || []; - if (arr.length) { - var total = sum(arr); - if (is.isNumber(total)) { - return total / arr.length; - } else { - throw new Error("Cannot average an array of non numbers."); - } - } else { - return 0; - } - } +Pattern.extend({ - function sort(arr, cmp) { - return _sort(arr, cmp); - } + instance: { + constructor: function (left, right) { + this.id = id++; + this.leftPattern = left; + this.rightPattern = right; + }, - function min(arr, cmp) { - return _sort(arr, cmp)[0]; - } + hashCode: function () { + return [this.leftPattern.hashCode(), this.rightPattern.hashCode()].join(":"); + }, - function max(arr, cmp) { - return _sort(arr, cmp)[arr.length - 1]; - } + getSpecificity: function () { + return this.rightPattern.getSpecificity() + this.leftPattern.getSpecificity(); + }, - function difference(arr1) { - var ret = arr1, args = flatten(argsToArray(arguments, 1)); - if (isArray(arr1)) { - ret = filter(arr1, function (a) { - return indexOf(args, a) === -1; - }); + getters: { + constraints: function () { + return this.leftPattern.constraints.concat(this.rightPattern.constraints); } - return ret; } + } - function removeDuplicates(arr) { - var ret = [], i = -1, l, retLength = 0; - if (arr) { - l = arr.length; - while (++i < l) { - var item = arr[i]; - if (indexOf(ret, item) === -1) { - ret[retLength++] = item; - } - } - } - return ret; - } +}).as(exports, "CompositePattern"); - function unique(arr) { - return removeDuplicates(arr); +var InitialFact = declare({ + instance: { + constructor: function () { + this.id = id++; + this.recency = 0; } + } +}).as(exports, "InitialFact"); +ObjectPattern.extend({ + instance: { + constructor: function () { + this._super([InitialFact, "__i__", [], {}]); + }, - function rotate(arr, numberOfTimes) { - var ret = arr.slice(); - if (typeof numberOfTimes !== "number") { - numberOfTimes = 1; - } - if (numberOfTimes && isArray(arr)) { - if (numberOfTimes > 0) { - ret.push(ret.shift()); - numberOfTimes--; - } else { - ret.unshift(ret.pop()); - numberOfTimes++; - } - return rotate(ret, numberOfTimes); - } else { - return ret; - } + assert: function () { + return true; } + } +}).as(exports, "InitialFactPattern"); - function permutations(arr, length) { - var ret = []; - if (isArray(arr)) { - var copy = arr.slice(0); - if (typeof length !== "number") { - length = arr.length; - } - if (!length) { - ret = [ - [] - ]; - } else if (length <= arr.length) { - ret = reduce(arr, function (a, b, i) { - var ret; - if (length > 1) { - ret = permute(b, rotate(copy, i).slice(1), length); - } else { - ret = [ - [b] - ]; - } - return a.concat(ret); - }, []); - } - } - return ret; - } - function zip() { - var ret = []; - var arrs = argsToArray(arguments); - if (arrs.length > 1) { - var arr1 = arrs.shift(); - if (isArray(arr1)) { - ret = reduce(arr1, function (a, b, i) { - var curr = [b]; - for (var j = 0; j < arrs.length; j++) { - var currArr = arrs[j]; - if (isArray(currArr) && !is.isUndefined(currArr[i])) { - curr.push(currArr[i]); - } else { - curr.push(null); - } - } - a.push(curr); - return a; - }, []); - } - } - return ret; - } - function transpose(arr) { - var ret = []; - if (isArray(arr) && arr.length) { - var last; - forEach(arr, function (a) { - if (isArray(a) && (!last || a.length === last.length)) { - forEach(a, function (b, i) { - if (!ret[i]) { - ret[i] = []; - } - ret[i].push(b); - }); - last = a; - } - }); - } - return ret; - } - function valuesAt(arr, indexes) { - var ret = []; - indexes = argsToArray(arguments); - arr = indexes.shift(); - if (isArray(arr) && indexes.length) { - for (var i = 0, l = indexes.length; i < l; i++) { - ret.push(arr[indexes[i]] || null); - } - } - return ret; - } +},{"./constraint":8,"./constraintMatcher":9,"./extended":12}],46:[function(require,module,exports){ +"use strict"; +var extd = require("./extended"), + isArray = extd.isArray, + Promise = extd.Promise, + declare = extd.declare, + isHash = extd.isHash, + isString = extd.isString, + format = extd.format, + parser = require("./parser"), + pattern = require("./pattern"), + ObjectPattern = pattern.ObjectPattern, + FromPattern = pattern.FromPattern, + NotPattern = pattern.NotPattern, + ExistsPattern = pattern.ExistsPattern, + FromNotPattern = pattern.FromNotPattern, + FromExistsPattern = pattern.FromExistsPattern, + CompositePattern = pattern.CompositePattern; - function union() { - var ret = []; - var arrs = argsToArray(arguments); - if (arrs.length > 1) { - for (var i = 0, l = arrs.length; i < l; i++) { - ret = ret.concat(arrs[i]); - } - ret = removeDuplicates(ret); - } - return ret; - } +var parseExtra = extd + .switcher() + .isUndefinedOrNull(function () { + return null; + }) + .isLike(/^from +/, function (s) { + return {from: s.replace(/^from +/, "").replace(/^\s*|\s*$/g, "")}; + }) + .def(function (o) { + throw new Error("invalid rule constraint option " + o); + }) + .switcher(); - function intersect() { - var collect = [], sets, i = -1 , l; - if (arguments.length > 1) { - //assume we are intersections all the lists in the array - sets = argsToArray(arguments); - } else { - sets = arguments[0]; - } - if (isArray(sets)) { - collect = sets[0]; - i = 0; - l = sets.length; - while (++i < l) { - collect = intersection(collect, sets[i]); - } - } - return removeDuplicates(collect); +var normailizeConstraint = extd + .switcher() + .isLength(1, function (c) { + throw new Error("invalid rule constraint " + format("%j", [c])); + }) + .isLength(2, function (c) { + c.push("true"); + return c; + }) + //handle case where c[2] is a hash rather than a constraint string + .isLength(3, function (c) { + if (isString(c[2]) && /^from +/.test(c[2])) { + var extra = c[2]; + c.splice(2, 0, "true"); + c[3] = null; + c[4] = parseExtra(extra); + } else if (isHash(c[2])) { + c.splice(2, 0, "true"); } - - function powerSet(arr) { - var ret = []; - if (isArray(arr) && arr.length) { - ret = reduce(arr, function (a, b) { - var ret = map(a, function (c) { - return c.concat(b); - }); - return a.concat(ret); - }, [ - [] - ]); - } - return ret; + return c; + }) + //handle case where c[3] is a from clause rather than a hash for references + .isLength(4, function (c) { + if (isString(c[3])) { + c.splice(3, 0, null); + c[4] = parseExtra(c[4]); } - - function cartesian(a, b) { - var ret = []; - if (isArray(a) && isArray(b) && a.length && b.length) { - ret = cross(a[0], b).concat(cartesian(a.slice(1), b)); - } - return ret; + return c; + }) + .def(function (c) { + if (c.length === 5) { + c[4] = parseExtra(c[4]); } + return c; + }) + .switcher(); - function compact(arr) { - var ret = []; - if (isArray(arr) && arr.length) { - ret = filter(arr, function (item) { - return !is.isUndefinedOrNull(item); - }); - } - return ret; - } - function multiply(arr, times) { - times = is.isNumber(times) ? times : 1; - if (!times) { - //make sure times is greater than zero if it is zero then dont multiply it - times = 1; - } - arr = toArray(arr || []); - var ret = [], i = 0; - while (++i <= times) { - ret = ret.concat(arr); - } - return ret; - } +var getParamTypeSwitch = extd + .switcher() + .isEq("string", function () { + return String; + }) + .isEq("date", function () { + return Date; + }) + .isEq("array", function () { + return Array; + }) + .isEq("boolean", function () { + return Boolean; + }) + .isEq("regexp", function () { + return RegExp; + }) + .isEq("number", function () { + return Number; + }) + .isEq("object", function () { + return Object; + }) + .isEq("hash", function () { + return Object; + }) + .def(function (param) { + throw new TypeError("invalid param type " + param); + }) + .switcher(); - function flatten(arr) { - var set; - var args = argsToArray(arguments); - if (args.length > 1) { - //assume we are intersections all the lists in the array - set = args; - } else { - set = toArray(arr); - } - return reduce(set, function (a, b) { - return a.concat(b); - }, []); - } - function pluck(arr, prop) { - prop = prop.split("."); - var result = arr.slice(0); - forEach(prop, function (prop) { - var exec = prop.match(/(\w+)\(\)$/); - result = map(result, function (item) { - return exec ? item[exec[1]]() : item[prop]; - }); - }); - return result; - } +var getParamType = extd + .switcher() + .isString(function (param) { + return getParamTypeSwitch(param.toLowerCase()); + }) + .isFunction(function (func) { + return func; + }) + .deepEqual([], function () { + return Array; + }) + .def(function (param) { + throw new Error("invalid param type " + param); + }) + .switcher(); - function invoke(arr, func, args) { - args = argsToArray(arguments, 2); - return map(arr, function (item) { - var exec = isString(func) ? item[func] : func; - return exec.apply(item, args); - }); +var parsePattern = extd + .switcher() + .containsAt("or", 0, function (condition) { + condition.shift(); + return extd(condition).map(function (cond) { + cond.scope = condition.scope; + return parsePattern(cond); + }).flatten().value(); + }) + .containsAt("not", 0, function (condition) { + condition.shift(); + condition = normailizeConstraint(condition); + if (condition[4] && condition[4].from) { + return [ + new FromNotPattern( + getParamType(condition[0]), + condition[1] || "m", + parser.parseConstraint(condition[2] || "true"), + condition[3] || {}, + parser.parseConstraint(condition[4].from), + {scope: condition.scope, pattern: condition[2]} + ) + ]; + } else { + return [ + new NotPattern( + getParamType(condition[0]), + condition[1] || "m", + parser.parseConstraint(condition[2] || "true"), + condition[3] || {}, + {scope: condition.scope, pattern: condition[2]} + ) + ]; + } + }) + .containsAt("exists", 0, function (condition) { + condition.shift(); + condition = normailizeConstraint(condition); + if (condition[4] && condition[4].from) { + return [ + new FromExistsPattern( + getParamType(condition[0]), + condition[1] || "m", + parser.parseConstraint(condition[2] || "true"), + condition[3] || {}, + parser.parseConstraint(condition[4].from), + {scope: condition.scope, pattern: condition[2]} + ) + ]; + } else { + return [ + new ExistsPattern( + getParamType(condition[0]), + condition[1] || "m", + parser.parseConstraint(condition[2] || "true"), + condition[3] || {}, + {scope: condition.scope, pattern: condition[2]} + ) + ]; + } + }) + .def(function (condition) { + condition = normailizeConstraint(condition); + if (condition[4] && condition[4].from) { + return [ + new FromPattern( + getParamType(condition[0]), + condition[1] || "m", + parser.parseConstraint(condition[2] || "true"), + condition[3] || {}, + parser.parseConstraint(condition[4].from), + {scope: condition.scope, pattern: condition[2]} + ) + ]; + } else { + return [ + new ObjectPattern( + getParamType(condition[0]), + condition[1] || "m", + parser.parseConstraint(condition[2] || "true"), + condition[3] || {}, + {scope: condition.scope, pattern: condition[2]} + ) + ]; } + }).switcher(); +var Rule = declare({ + instance: { + constructor: function (name, options, pattern, cb) { + this.name = name; + this.pattern = pattern; + this.cb = cb; + if (options.agendaGroup) { + this.agendaGroup = options.agendaGroup; + this.autoFocus = extd.isBoolean(options.autoFocus) ? options.autoFocus : false; + } + this.priority = options.priority || options.salience || 0; + }, - var array = { - toArray: toArray, - sum: sum, - avg: avg, - sort: sort, - min: min, - max: max, - difference: difference, - removeDuplicates: removeDuplicates, - unique: unique, - rotate: rotate, - permutations: permutations, - zip: zip, - transpose: transpose, - valuesAt: valuesAt, - union: union, - intersect: intersect, - powerSet: powerSet, - cartesian: cartesian, - compact: compact, - multiply: multiply, - flatten: flatten, - pluck: pluck, - invoke: invoke, - forEach: forEach, - map: map, - filter: filter, - reduce: reduce, - reduceRight: reduceRight, - some: some, - every: every, - indexOf: indexOf, - lastIndexOf: lastIndexOf - }; + fire: function (flow, match) { + var ret = new Promise(), cb = this.cb; + try { + if (cb.length === 3) { + cb.call(flow, match.factHash, flow, ret.resolve); + } else { + ret = cb.call(flow, match.factHash, flow); + } + } catch (e) { + ret.errback(e); + } + return ret; + } + } +}); - return extended.define(isArray, array).expose(array); +function createRule(name, options, conditions, cb) { + if (isArray(options)) { + cb = conditions; + conditions = options; + } else { + options = options || {}; + } + var isRules = extd.every(conditions, function (cond) { + return isArray(cond); + }); + if (isRules && conditions.length === 1) { + conditions = conditions[0]; + isRules = false; } + var rules = []; + var scope = options.scope || {}; + conditions.scope = scope; + if (isRules) { + var _mergePatterns = function (patt, i) { + if (!patterns[i]) { + patterns[i] = i === 0 ? [] : patterns[i - 1].slice(); + //remove dup + if (i !== 0) { + patterns[i].pop(); + } + patterns[i].push(patt); + } else { + extd(patterns).forEach(function (p) { + p.push(patt); + }); + } + + }; + var l = conditions.length, patterns = [], condition; + for (var i = 0; i < l; i++) { + condition = conditions[i]; + condition.scope = scope; + extd.forEach(parsePattern(condition), _mergePatterns); - if ("undefined" !== typeof exports) { - if ("undefined" !== typeof module && module.exports) { - module.exports = defineArray(require("extended"), require("is-extended"), require("arguments-extended")); } - } else if ("function" === typeof define && define.amd) { - define(["extended", "is-extended", "arguments-extended"], function (extended, is, args) { - return defineArray(extended, is, args); + rules = extd.map(patterns, function (patterns) { + var compPat = null; + for (var i = 0; i < patterns.length; i++) { + if (compPat === null) { + compPat = new CompositePattern(patterns[i++], patterns[i]); + } else { + compPat = new CompositePattern(compPat, patterns[i]); + } + } + return new Rule(name, options, compPat, cb); }); } else { - this.arrayExtended = defineArray(this.extended, this.isExtended, this.argumentsExtended); + rules = extd.map(parsePattern(conditions), function (cond) { + return new Rule(name, options, cond, cb); + }); } + return rules; +} -}).call(this); +exports.createRule = createRule; +},{"./extended":12,"./parser":41,"./pattern":45}],47:[function(require,module,exports){ +"use strict"; +var declare = require("declare.js"), + LinkedList = require("./linkedList"), + id = 0; +var Fact = declare({ + instance: { + constructor: function (obj) { + this.object = obj; + this.recency = 0; + this.id = id++; + }, -},{"arguments-extended":41,"extended":46,"is-extended":56}],43:[function(require,module,exports){ -(function () { - "use strict"; + equals: function (fact) { + return fact === this.object; + }, - function defineDate(extended, is, array) { + hashCode: function () { + return this.id; + } + } - function _pad(string, length, ch, end) { - string = "" + string; //check for numbers - ch = ch || " "; - var strLen = string.length; - while (strLen < length) { - if (end) { - string += ch; - } else { - string = ch + string; +}); + +declare({ + + instance: { + + constructor: function () { + this.recency = 0; + this.facts = new LinkedList(); + }, + + dispose: function () { + this.facts.clear(); + }, + + getFactHandle: function (o) { + var head = {next: this.facts.head}, ret; + while ((head = head.next)) { + var existingFact = head.data; + if (existingFact.equals(o)) { + return existingFact; } - strLen++; } - return string; - } + if (!ret) { + ret = new Fact(o); + ret.recency = this.recency++; + //this.facts.push(ret); + } + return ret; + }, - function _truncate(string, length, end) { - var ret = string; - if (is.isString(ret)) { - if (string.length > length) { - if (end) { - var l = string.length; - ret = string.substring(l - length, l); - } else { - ret = string.substring(0, length); - } + modifyFact: function (fact) { + var head = {next: this.facts.head}; + while ((head = head.next)) { + var existingFact = head.data; + if (existingFact.equals(fact)) { + existingFact.recency = this.recency++; + return existingFact; } - } else { - ret = _truncate("" + ret, length); } + //if we made it here we did not find the fact + throw new Error("the fact to modify does not exist"); + }, + + assertFact: function (fact) { + var ret = new Fact(fact); + ret.recency = this.recency++; + this.facts.push(ret); return ret; - } +// var head = {next: this.facts.head}, ret; +// while ((head = head.next)) { +// var existingFact = head.data; +// if (existingFact.equals(fact)) { +// ret = existingFact; +// break; +// } +// } +// if (!ret) { +// ret = new Fact(fact); +// ret.recency = this.recency++; +// this.facts.push(ret); +// } +// return ret; + }, - function every(arr, iterator, scope) { - if (!is.isArray(arr) || typeof iterator !== "function") { - throw new TypeError(); - } - var t = Object(arr); - var len = t.length >>> 0; - for (var i = 0; i < len; i++) { - if (i in t && !iterator.call(scope, t[i], i, t)) { - return false; + retractFact: function (fact) { + var facts = this.facts, head = {next: facts.head}; + while ((head = head.next)) { + var existingFact = head.data; + if (existingFact.equals(fact)) { + facts.remove(head); + return existingFact; } } - return true; + //if we made it here we did not find the fact + throw new Error("the fact to remove does not exist"); + + } + } +}).as(exports, "WorkingMemory"); - var transforms = (function () { - var floor = Math.floor, round = Math.round; - var addMap = { - day: function addDay(date, amount) { - return [amount, "Date", false]; - }, - weekday: function addWeekday(date, amount) { - // Divide the increment time span into weekspans plus leftover days - // e.g., 8 days is one 5-day weekspan / and two leftover days - // Can't have zero leftover days, so numbers divisible by 5 get - // a days value of 5, and the remaining days make up the number of weeks - var days, weeks, mod = amount % 5, strt = date.getDay(), adj = 0; - if (!mod) { - days = (amount > 0) ? 5 : -5; - weeks = (amount > 0) ? ((amount - 5) / 5) : ((amount + 5) / 5); - } else { - days = mod; - weeks = parseInt(amount / 5, 10); - } - if (strt === 6 && amount > 0) { - adj = 1; - } else if (strt === 0 && amount < 0) { - // Orig date is Sun / negative increment - // Jump back over Sat - adj = -1; - } - // Get weekday val for the new date - var trgt = strt + days; - // New date is on Sat or Sun - if (trgt === 0 || trgt === 6) { - adj = (amount > 0) ? 2 : -2; - } - // Increment by number of weeks plus leftover days plus - // weekend adjustments - return [(7 * weeks) + days + adj, "Date", false]; - }, - year: function addYear(date, amount) { - return [amount, "FullYear", true]; - }, - week: function addWeek(date, amount) { - return [amount * 7, "Date", false]; - }, - quarter: function addYear(date, amount) { - return [amount * 3, "Month", true]; - }, - month: function addYear(date, amount) { - return [amount, "Month", true]; - } - }; +},{"./linkedList":16,"declare.js":52}],48:[function(require,module,exports){ +(function () { + "use strict"; - function addTransform(interval, date, amount) { - interval = interval.replace(/s$/, ""); - if (addMap.hasOwnProperty(interval)) { - return addMap[interval](date, amount); - } - return [amount, "UTC" + interval.charAt(0).toUpperCase() + interval.substring(1) + "s", false]; - } + function defineArgumentsExtended(extended, is) { + var pSlice = Array.prototype.slice, + isArguments = is.isArguments; - var differenceMap = { - "quarter": function quarterDifference(date1, date2, utc) { - var yearDiff = date2.getFullYear() - date1.getFullYear(); - var m1 = date1[utc ? "getUTCMonth" : "getMonth"](); - var m2 = date2[utc ? "getUTCMonth" : "getMonth"](); - // Figure out which quarter the months are in - var q1 = floor(m1 / 3) + 1; - var q2 = floor(m2 / 3) + 1; - // Add quarters for any year difference between the dates - q2 += (yearDiff * 4); - return q2 - q1; - }, + function argsToArray(args, slice) { + var i = -1, j = 0, l = args.length, ret = []; + slice = slice || 0; + i += slice; + while (++i < l) { + ret[j++] = args[i]; + } + return ret; + } - "weekday": function weekdayDifference(date1, date2, utc) { - var days = differenceTransform("day", date1, date2, utc), weeks; - var mod = days % 7; - // Even number of weeks - if (mod === 0) { - days = differenceTransform("week", date1, date2, utc) * 5; - } else { - // Weeks plus spare change (< 7 days) - var adj = 0, aDay = date1[utc ? "getUTCDay" : "getDay"](), bDay = date2[utc ? "getUTCDay" : "getDay"](); - weeks = parseInt(days / 7, 10); - // Mark the date advanced by the number of - // round weeks (may be zero) - var dtMark = new Date(+date1); - dtMark.setDate(dtMark[utc ? "getUTCDate" : "getDate"]() + (weeks * 7)); - var dayMark = dtMark[utc ? "getUTCDay" : "getDay"](); - // Spare change days -- 6 or less - if (days > 0) { - if (aDay === 6 || bDay === 6) { - adj = -1; - } else if (aDay === 0) { - adj = 0; - } else if (bDay === 0 || (dayMark + mod) > 5) { - adj = -2; - } - } else if (days < 0) { - if (aDay === 6) { - adj = 0; - } else if (aDay === 0 || bDay === 0) { - adj = 1; - } else if (bDay === 6 || (dayMark + mod) < 0) { - adj = 2; - } - } - days += adj; - days -= (weeks * 2); - } - return days; - }, - year: function (date1, date2) { - return date2.getFullYear() - date1.getFullYear(); - }, - month: function (date1, date2, utc) { - var m1 = date1[utc ? "getUTCMonth" : "getMonth"](); - var m2 = date2[utc ? "getUTCMonth" : "getMonth"](); - return (m2 - m1) + ((date2.getFullYear() - date1.getFullYear()) * 12); - }, - week: function (date1, date2, utc) { - return round(differenceTransform("day", date1, date2, utc) / 7); - }, - day: function (date1, date2) { - return 1.1574074074074074e-8 * (date2.getTime() - date1.getTime()); - }, - hour: function (date1, date2) { - return 2.7777777777777776e-7 * (date2.getTime() - date1.getTime()); - }, - minute: function (date1, date2) { - return 0.000016666666666666667 * (date2.getTime() - date1.getTime()); - }, - second: function (date1, date2) { - return 0.001 * (date2.getTime() - date1.getTime()); - }, - millisecond: function (date1, date2) { - return date2.getTime() - date1.getTime(); - } - }; + return extended + .define(isArguments, { + toArray: argsToArray + }) + .expose({ + argsToArray: argsToArray + }); + } + if ("undefined" !== typeof exports) { + if ("undefined" !== typeof module && module.exports) { + module.exports = defineArgumentsExtended(require("extended"), require("is-extended")); - function differenceTransform(interval, date1, date2, utc) { - interval = interval.replace(/s$/, ""); - return round(differenceMap[interval](date1, date2, utc)); - } + } + } else if ("function" === typeof define && define.amd) { + define(["extended", "is-extended"], function (extended, is) { + return defineArgumentsExtended(extended, is); + }); + } else { + this.argumentsExtended = defineArgumentsExtended(this.extended, this.isExtended); + } +}).call(this); - return { - addTransform: addTransform, - differenceTransform: differenceTransform - }; - }()), - addTransform = transforms.addTransform, - differenceTransform = transforms.differenceTransform; +},{"extended":53,"is-extended":70}],49:[function(require,module,exports){ +(function () { + "use strict"; + /*global define*/ - /** - * @ignore - * Based on DOJO Date Implementation - * - * Dojo is available under *either* the terms of the modified BSD license *or* the - * Academic Free License version 2.1. As a recipient of Dojo, you may choose which - * license to receive this code under (except as noted in per-module LICENSE - * files). Some modules may not be the copyright of the Dojo Foundation. These - * modules contain explicit declarations of copyright in both the LICENSE files in - * the directories in which they reside and in the code itself. No external - * contributions are allowed under licenses which are fundamentally incompatible - * with the AFL or BSD licenses that Dojo is distributed under. - * - */ + function defineArray(extended, is, args) { - var floor = Math.floor, round = Math.round, min = Math.min, pow = Math.pow, ceil = Math.ceil, abs = Math.abs; - var monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; - var monthAbbr = ["Jan.", "Feb.", "Mar.", "Apr.", "May.", "Jun.", "Jul.", "Aug.", "Sep.", "Oct.", "Nov.", "Dec."]; - var dayNames = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; - var dayAbbr = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; - var eraNames = ["Before Christ", "Anno Domini"]; - var eraAbbr = ["BC", "AD"]; + var isString = is.isString, + isArray = Array.isArray || is.isArray, + isDate = is.isDate, + floor = Math.floor, + abs = Math.abs, + mathMax = Math.max, + mathMin = Math.min, + arrayProto = Array.prototype, + arrayIndexOf = arrayProto.indexOf, + arrayForEach = arrayProto.forEach, + arrayMap = arrayProto.map, + arrayReduce = arrayProto.reduce, + arrayReduceRight = arrayProto.reduceRight, + arrayFilter = arrayProto.filter, + arrayEvery = arrayProto.every, + arraySome = arrayProto.some, + argsToArray = args.argsToArray; - function getDayOfYear(/*Date*/dateObject, utc) { - // summary: gets the day of the year as represented by dateObject - return date.difference(new Date(dateObject.getFullYear(), 0, 1, dateObject.getHours()), dateObject, null, utc) + 1; // Number + function cross(num, cros) { + return reduceRight(cros, function (a, b) { + if (!isArray(b)) { + b = [b]; + } + b.unshift(num); + a.unshift(b); + return a; + }, []); } - function getWeekOfYear(/*Date*/dateObject, /*Number*/firstDayOfWeek, utc) { - firstDayOfWeek = firstDayOfWeek || 0; - var fullYear = dateObject[utc ? "getUTCFullYear" : "getFullYear"](); - var firstDayOfYear = new Date(fullYear, 0, 1).getDay(), - adj = (firstDayOfYear - firstDayOfWeek + 7) % 7, - week = floor((getDayOfYear(dateObject) + adj - 1) / 7); - - // if year starts on the specified day, start counting weeks at 1 - if (firstDayOfYear === firstDayOfWeek) { - week++; + function permute(num, cross, length) { + var ret = []; + for (var i = 0; i < cross.length; i++) { + ret.push([num].concat(rotate(cross, i)).slice(0, length)); } - - return week; // Number + return ret; } - function getTimezoneName(/*Date*/dateObject) { - var str = dateObject.toString(); - var tz = ''; - var pos = str.indexOf('('); - if (pos > -1) { - tz = str.substring(++pos, str.indexOf(')')); + + function intersection(a, b) { + var ret = [], aOne, i = -1, l; + l = a.length; + while (++i < l) { + aOne = a[i]; + if (indexOf(b, aOne) !== -1) { + ret.push(aOne); + } } - return tz; // String + return ret; } - function buildDateEXP(pattern, tokens) { - return pattern.replace(/([a-z])\1*/ig,function (match) { - // Build a simple regexp. Avoid captures, which would ruin the tokens list - var s, - c = match.charAt(0), - l = match.length, - p2 = '0?', - p3 = '0{0,2}'; - if (c === 'y') { - s = '\\d{2,4}'; - } else if (c === "M") { - s = (l > 2) ? '\\S+?' : '1[0-2]|' + p2 + '[1-9]'; - } else if (c === "D") { - s = '[12][0-9][0-9]|3[0-5][0-9]|36[0-6]|' + p3 + '[1-9][0-9]|' + p2 + '[1-9]'; - } else if (c === "d") { - s = '3[01]|[12]\\d|' + p2 + '[1-9]'; - } else if (c === "w") { - s = '[1-4][0-9]|5[0-3]|' + p2 + '[1-9]'; - } else if (c === "E") { - s = '\\S+'; - } else if (c === "h") { - s = '1[0-2]|' + p2 + '[1-9]'; - } else if (c === "K") { - s = '1[01]|' + p2 + '\\d'; - } else if (c === "H") { - s = '1\\d|2[0-3]|' + p2 + '\\d'; - } else if (c === "k") { - s = '1\\d|2[0-4]|' + p2 + '[1-9]'; - } else if (c === "m" || c === "s") { - s = '[0-5]\\d'; - } else if (c === "S") { - s = '\\d{' + l + '}'; - } else if (c === "a") { - var am = 'AM', pm = 'PM'; - s = am + '|' + pm; - if (am !== am.toLowerCase()) { - s += '|' + am.toLowerCase(); - } - if (pm !== pm.toLowerCase()) { - s += '|' + pm.toLowerCase(); - } - s = s.replace(/\./g, "\\."); - } else if (c === 'v' || c === 'z' || c === 'Z' || c === 'G' || c === 'q' || c === 'Q') { - s = ".*"; - } else { - s = c === " " ? "\\s*" : c + "*"; - } - if (tokens) { - tokens.push(match); - } + var _sort = (function () { - return "(" + s + ")"; // add capture - }).replace(/[\xa0 ]/g, "[\\s\\xa0]"); // normalize whitespace. Need explicit handling of \xa0 for IE. - } + var isAll = function (arr, test) { + return every(arr, test); + }; + var defaultCmp = function (a, b) { + return a - b; + }; - /** - * @namespace Utilities for Dates - */ - var date = { + var dateSort = function (a, b) { + return a.getTime() - b.getTime(); + }; - /**@lends date*/ + return function _sort(arr, property) { + var ret = []; + if (isArray(arr)) { + ret = arr.slice(); + if (property) { + if (typeof property === "function") { + ret.sort(property); + } else { + ret.sort(function (a, b) { + var aProp = a[property], bProp = b[property]; + if (isString(aProp) && isString(bProp)) { + return aProp > bProp ? 1 : aProp < bProp ? -1 : 0; + } else if (isDate(aProp) && isDate(bProp)) { + return aProp.getTime() - bProp.getTime(); + } else { + return aProp - bProp; + } + }); + } + } else { + if (isAll(ret, isString)) { + ret.sort(); + } else if (isAll(ret, isDate)) { + ret.sort(dateSort); + } else { + ret.sort(defaultCmp); + } + } + } + return ret; + }; - /** - * Returns the number of days in the month of a date - * - * @example - * - * dateExtender.getDaysInMonth(new Date(2006, 1, 1)); //28 - * dateExtender.getDaysInMonth(new Date(2004, 1, 1)); //29 - * dateExtender.getDaysInMonth(new Date(2006, 2, 1)); //31 - * dateExtender.getDaysInMonth(new Date(2006, 3, 1)); //30 - * dateExtender.getDaysInMonth(new Date(2006, 4, 1)); //31 - * dateExtender.getDaysInMonth(new Date(2006, 5, 1)); //30 - * dateExtender.getDaysInMonth(new Date(2006, 6, 1)); //31 - * @param {Date} dateObject the date containing the month - * @return {Number} the number of days in the month - */ - getDaysInMonth: function (/*Date*/dateObject) { - // summary: - // Returns the number of days in the month used by dateObject - var month = dateObject.getMonth(); - var days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; - if (month === 1 && date.isLeapYear(dateObject)) { - return 29; - } // Number - return days[month]; // Number - }, + })(); - /** - * Determines if a date is a leap year - * - * @example - * - * dateExtender.isLeapYear(new Date(1600, 0, 1)); //true - * dateExtender.isLeapYear(new Date(2004, 0, 1)); //true - * dateExtender.isLeapYear(new Date(2000, 0, 1)); //true - * dateExtender.isLeapYear(new Date(2006, 0, 1)); //false - * dateExtender.isLeapYear(new Date(1900, 0, 1)); //false - * dateExtender.isLeapYear(new Date(1800, 0, 1)); //false - * dateExtender.isLeapYear(new Date(1700, 0, 1)); //false - * - * @param {Date} dateObject - * @returns {Boolean} true if it is a leap year false otherwise - */ - isLeapYear: function (/*Date*/dateObject, utc) { - var year = dateObject[utc ? "getUTCFullYear" : "getFullYear"](); - return (year % 400 === 0) || (year % 4 === 0 && year % 100 !== 0); + function indexOf(arr, searchElement, from) { + var index = (from || 0) - 1, + length = arr.length; + while (++index < length) { + if (arr[index] === searchElement) { + return index; + } + } + return -1; + } - }, + function lastIndexOf(arr, searchElement, from) { + if (!isArray(arr)) { + throw new TypeError(); + } - /** - * Determines if a date is on a weekend - * - * @example - * - * var thursday = new Date(2006, 8, 21); - * var saturday = new Date(2006, 8, 23); - * var sunday = new Date(2006, 8, 24); - * var monday = new Date(2006, 8, 25); - * dateExtender.isWeekend(thursday)); //false - * dateExtender.isWeekend(saturday); //true - * dateExtender.isWeekend(sunday); //true - * dateExtender.isWeekend(monday)); //false - * - * @param {Date} dateObject the date to test - * - * @returns {Boolean} true if the date is a weekend - */ - isWeekend: function (/*Date?*/dateObject, utc) { - // summary: - // Determines if the date falls on a weekend, according to local custom. - var day = (dateObject || new Date())[utc ? "getUTCDay" : "getDay"](); - return day === 0 || day === 6; - }, + var t = Object(arr); + var len = t.length >>> 0; + if (len === 0) { + return -1; + } - /** - * Get the timezone of a date - * - * @example - * //just setting the strLocal to simulate the toString() of a date - * dt.str = 'Sun Sep 17 2006 22:25:51 GMT-0500 (CDT)'; - * //just setting the strLocal to simulate the locale - * dt.strLocale = 'Sun 17 Sep 2006 10:25:51 PM CDT'; - * dateExtender.getTimezoneName(dt); //'CDT' - * dt.str = 'Sun Sep 17 2006 22:57:18 GMT-0500 (CDT)'; - * dt.strLocale = 'Sun Sep 17 22:57:18 2006'; - * dateExtender.getTimezoneName(dt); //'CDT' - * @param dateObject the date to get the timezone from - * - * @returns {String} the timezone of the date - */ - getTimezoneName: getTimezoneName, + var n = len; + if (arguments.length > 2) { + n = Number(arguments[2]); + if (n !== n) { + n = 0; + } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) { + n = (n > 0 || -1) * floor(abs(n)); + } + } - /** - * Compares two dates - * - * @example - * - * var d1 = new Date(); - * d1.setHours(0); - * dateExtender.compare(d1, d1); // 0 - * - * var d1 = new Date(); - * d1.setHours(0); - * var d2 = new Date(); - * d2.setFullYear(2005); - * d2.setHours(12); - * dateExtender.compare(d1, d2, "date"); // 1 - * dateExtender.compare(d1, d2, "datetime"); // 1 - * - * var d1 = new Date(); - * d1.setHours(0); - * var d2 = new Date(); - * d2.setFullYear(2005); - * d2.setHours(12); - * dateExtender.compare(d2, d1, "date"); // -1 - * dateExtender.compare(d1, d2, "time"); //-1 - * - * @param {Date|String} date1 the date to comapare - * @param {Date|String} [date2=new Date()] the date to compare date1 againse - * @param {"date"|"time"|"datetime"} portion compares the portion specified - * - * @returns -1 if date1 is < date2 0 if date1 === date2 1 if date1 > date2 - */ - compare: function (/*Date*/date1, /*Date*/date2, /*String*/portion) { - date1 = new Date(+date1); - date2 = new Date(+(date2 || new Date())); + var k = n >= 0 ? mathMin(n, len - 1) : len - abs(n); - if (portion === "date") { - // Ignore times and compare dates. - date1.setHours(0, 0, 0, 0); - date2.setHours(0, 0, 0, 0); - } else if (portion === "time") { - // Ignore dates and compare times. - date1.setFullYear(0, 0, 0); - date2.setFullYear(0, 0, 0); + for (; k >= 0; k--) { + if (k in t && t[k] === searchElement) { + return k; } - return date1 > date2 ? 1 : date1 < date2 ? -1 : 0; - }, - + } + return -1; + } - /** - * Adds a specified interval and amount to a date - * - * @example - * var dtA = new Date(2005, 11, 27); - * dateExtender.add(dtA, "year", 1); //new Date(2006, 11, 27); - * dateExtender.add(dtA, "years", 1); //new Date(2006, 11, 27); - * - * dtA = new Date(2000, 0, 1); - * dateExtender.add(dtA, "quarter", 1); //new Date(2000, 3, 1); - * dateExtender.add(dtA, "quarters", 1); //new Date(2000, 3, 1); - * - * dtA = new Date(2000, 0, 1); - * dateExtender.add(dtA, "month", 1); //new Date(2000, 1, 1); - * dateExtender.add(dtA, "months", 1); //new Date(2000, 1, 1); - * - * dtA = new Date(2000, 0, 31); - * dateExtender.add(dtA, "month", 1); //new Date(2000, 1, 29); - * dateExtender.add(dtA, "months", 1); //new Date(2000, 1, 29); - * - * dtA = new Date(2000, 0, 1); - * dateExtender.add(dtA, "week", 1); //new Date(2000, 0, 8); - * dateExtender.add(dtA, "weeks", 1); //new Date(2000, 0, 8); - * - * dtA = new Date(2000, 0, 1); - * dateExtender.add(dtA, "day", 1); //new Date(2000, 0, 2); - * - * dtA = new Date(2000, 0, 1); - * dateExtender.add(dtA, "weekday", 1); //new Date(2000, 0, 3); - * - * dtA = new Date(2000, 0, 1, 11); - * dateExtender.add(dtA, "hour", 1); //new Date(2000, 0, 1, 12); - * - * dtA = new Date(2000, 11, 31, 23, 59); - * dateExtender.add(dtA, "minute", 1); //new Date(2001, 0, 1, 0, 0); - * - * dtA = new Date(2000, 11, 31, 23, 59, 59); - * dateExtender.add(dtA, "second", 1); //new Date(2001, 0, 1, 0, 0, 0); - * - * dtA = new Date(2000, 11, 31, 23, 59, 59, 999); - * dateExtender.add(dtA, "millisecond", 1); //new Date(2001, 0, 1, 0, 0, 0, 0); - * - * @param {Date} date - * @param {String} interval the interval to add - *
      - *
    • day | days
    • - *
    • weekday | weekdays
    • - *
    • year | years
    • - *
    • week | weeks
    • - *
    • quarter | quarters
    • - *
    • months | months
    • - *
    • hour | hours
    • - *
    • minute | minutes
    • - *
    • second | seconds
    • - *
    • millisecond | milliseconds
    • - *
    - * @param {Number} [amount=0] the amount to add - */ - add: function (/*Date*/date, /*String*/interval, /*int*/amount) { - var res = addTransform(interval, date, amount || 0); - amount = res[0]; - var property = res[1]; - var sum = new Date(+date); - var fixOvershoot = res[2]; - if (property) { - sum["set" + property](sum["get" + property]() + amount); - } + function filter(arr, iterator, scope) { + if (arr && arrayFilter && arrayFilter === arr.filter) { + return arr.filter(iterator, scope); + } + if (!isArray(arr) || typeof iterator !== "function") { + throw new TypeError(); + } - if (fixOvershoot && (sum.getDate() < date.getDate())) { - sum.setDate(0); + var t = Object(arr); + var len = t.length >>> 0; + var res = []; + for (var i = 0; i < len; i++) { + if (i in t) { + var val = t[i]; // in case fun mutates this + if (iterator.call(scope, val, i, t)) { + res.push(val); + } } + } + return res; + } - return sum; // Date - }, + function forEach(arr, iterator, scope) { + if (!isArray(arr) || typeof iterator !== "function") { + throw new TypeError(); + } + if (arr && arrayForEach && arrayForEach === arr.forEach) { + arr.forEach(iterator, scope); + return arr; + } + for (var i = 0, len = arr.length; i < len; ++i) { + iterator.call(scope || arr, arr[i], i, arr); + } - /** - * Finds the difference between two dates based on the specified interval - * - * @example - * - * var dtA, dtB; - * - * dtA = new Date(2005, 11, 27); - * dtB = new Date(2006, 11, 27); - * dateExtender.difference(dtA, dtB, "year"); //1 - * - * dtA = new Date(2000, 1, 29); - * dtB = new Date(2001, 2, 1); - * dateExtender.difference(dtA, dtB, "quarter"); //4 - * dateExtender.difference(dtA, dtB, "month"); //13 - * - * dtA = new Date(2000, 1, 1); - * dtB = new Date(2000, 1, 8); - * dateExtender.difference(dtA, dtB, "week"); //1 - * - * dtA = new Date(2000, 1, 29); - * dtB = new Date(2000, 2, 1); - * dateExtender.difference(dtA, dtB, "day"); //1 - * - * dtA = new Date(2006, 7, 3); - * dtB = new Date(2006, 7, 11); - * dateExtender.difference(dtA, dtB, "weekday"); //6 - * - * dtA = new Date(2000, 11, 31, 23); - * dtB = new Date(2001, 0, 1, 0); - * dateExtender.difference(dtA, dtB, "hour"); //1 - * - * dtA = new Date(2000, 11, 31, 23, 59); - * dtB = new Date(2001, 0, 1, 0, 0); - * dateExtender.difference(dtA, dtB, "minute"); //1 - * - * dtA = new Date(2000, 11, 31, 23, 59, 59); - * dtB = new Date(2001, 0, 1, 0, 0, 0); - * dateExtender.difference(dtA, dtB, "second"); //1 - * - * dtA = new Date(2000, 11, 31, 23, 59, 59, 999); - * dtB = new Date(2001, 0, 1, 0, 0, 0, 0); - * dateExtender.difference(dtA, dtB, "millisecond"); //1 - * - * - * @param {Date} date1 - * @param {Date} [date2 = new Date()] - * @param {String} [interval = "day"] the intercal to find the difference of. - *
      - *
    • day | days
    • - *
    • weekday | weekdays
    • - *
    • year | years
    • - *
    • week | weeks
    • - *
    • quarter | quarters
    • - *
    • months | months
    • - *
    • hour | hours
    • - *
    • minute | minutes
    • - *
    • second | seconds
    • - *
    • millisecond | milliseconds
    • - *
    - */ - difference: function (/*Date*/date1, /*Date?*/date2, /*String*/interval, utc) { - date2 = date2 || new Date(); - interval = interval || "day"; - return differenceTransform(interval, date1, date2, utc); - }, + return arr; + } - /** - * Formats a date to the specidifed format string - * - * @example - * - * var date = new Date(2006, 7, 11, 0, 55, 12, 345); - * dateExtender.format(date, "EEEE, MMMM dd, yyyy"); //"Friday, August 11, 2006" - * dateExtender.format(date, "M/dd/yy"); //"8/11/06" - * dateExtender.format(date, "E"); //"6" - * dateExtender.format(date, "h:m a"); //"12:55 AM" - * dateExtender.format(date, 'h:m:s'); //"12:55:12" - * dateExtender.format(date, 'h:m:s.SS'); //"12:55:12.35" - * dateExtender.format(date, 'k:m:s.SS'); //"24:55:12.35" - * dateExtender.format(date, 'H:m:s.SS'); //"0:55:12.35" - * dateExtender.format(date, "ddMMyyyy"); //"11082006" - * - * @param date the date to format - * @param {String} format the format of the date composed of the following options - *
      - *
    • G Era designator Text AD
    • - *
    • y Year Year 1996; 96
    • - *
    • M Month in year Month July; Jul; 07
    • - *
    • w Week in year Number 27
    • - *
    • W Week in month Number 2
    • - *
    • D Day in year Number 189
    • - *
    • d Day in month Number 10
    • - *
    • E Day in week Text Tuesday; Tue
    • - *
    • a Am/pm marker Text PM
    • - *
    • H Hour in day (0-23) Number 0
    • - *
    • k Hour in day (1-24) Number 24
    • - *
    • K Hour in am/pm (0-11) Number 0
    • - *
    • h Hour in am/pm (1-12) Number 12
    • - *
    • m Minute in hour Number 30
    • - *
    • s Second in minute Number 55
    • - *
    • S Millisecond Number 978
    • - *
    • z Time zone General time zone Pacific Standard Time; PST; GMT-08:00
    • - *
    • Z Time zone RFC 822 time zone -0800
    • - *
    - */ - format: function (date, format, utc) { - utc = utc || false; - var fullYear, month, day, d, hour, minute, second, millisecond; - if (utc) { - fullYear = date.getUTCFullYear(); - month = date.getUTCMonth(); - day = date.getUTCDay(); - d = date.getUTCDate(); - hour = date.getUTCHours(); - minute = date.getUTCMinutes(); - second = date.getUTCSeconds(); - millisecond = date.getUTCMilliseconds(); - } else { - fullYear = date.getFullYear(); - month = date.getMonth(); - d = date.getDate(); - day = date.getDay(); - hour = date.getHours(); - minute = date.getMinutes(); - second = date.getSeconds(); - millisecond = date.getMilliseconds(); + function every(arr, iterator, scope) { + if (arr && arrayEvery && arrayEvery === arr.every) { + return arr.every(iterator, scope); + } + if (!isArray(arr) || typeof iterator !== "function") { + throw new TypeError(); + } + var t = Object(arr); + var len = t.length >>> 0; + for (var i = 0; i < len; i++) { + if (i in t && !iterator.call(scope, t[i], i, t)) { + return false; } - return format.replace(/([A-Za-z])\1*/g, function (match) { - var s, pad, - c = match.charAt(0), - l = match.length; - if (c === 'd') { - s = "" + d; - pad = true; - } else if (c === "H" && !s) { - s = "" + hour; - pad = true; - } else if (c === 'm' && !s) { - s = "" + minute; - pad = true; - } else if (c === 's') { - if (!s) { - s = "" + second; - } - pad = true; - } else if (c === "G") { - s = ((l < 4) ? eraAbbr : eraNames)[fullYear < 0 ? 0 : 1]; - } else if (c === "y") { - s = fullYear; - if (l > 1) { - if (l === 2) { - s = _truncate("" + s, 2, true); - } else { - pad = true; - } - } - } else if (c.toUpperCase() === "Q") { - s = ceil((month + 1) / 3); - pad = true; - } else if (c === "M") { - if (l < 3) { - s = month + 1; - pad = true; - } else { - s = (l === 3 ? monthAbbr : monthNames)[month]; - } - } else if (c === "w") { - s = getWeekOfYear(date, 0, utc); - pad = true; - } else if (c === "D") { - s = getDayOfYear(date, utc); - pad = true; - } else if (c === "E") { - if (l < 3) { - s = day + 1; - pad = true; - } else { - s = (l === -3 ? dayAbbr : dayNames)[day]; - } - } else if (c === 'a') { - s = (hour < 12) ? 'AM' : 'PM'; - } else if (c === "h") { - s = (hour % 12) || 12; - pad = true; - } else if (c === "K") { - s = (hour % 12); - pad = true; - } else if (c === "k") { - s = hour || 24; - pad = true; - } else if (c === "S") { - s = round(millisecond * pow(10, l - 3)); - pad = true; - } else if (c === "z" || c === "v" || c === "Z") { - s = getTimezoneName(date); - if ((c === "z" || c === "v") && !s) { - l = 4; - } - if (!s || c === "Z") { - var offset = date.getTimezoneOffset(); - var tz = [ - (offset >= 0 ? "-" : "+"), - _pad(floor(abs(offset) / 60), 2, "0"), - _pad(abs(offset) % 60, 2, "0") - ]; - if (l === 4) { - tz.splice(0, 0, "GMT"); - tz.splice(3, 0, ":"); + } + return true; + } + + function some(arr, iterator, scope) { + if (arr && arraySome && arraySome === arr.some) { + return arr.some(iterator, scope); + } + if (!isArray(arr) || typeof iterator !== "function") { + throw new TypeError(); + } + var t = Object(arr); + var len = t.length >>> 0; + for (var i = 0; i < len; i++) { + if (i in t && iterator.call(scope, t[i], i, t)) { + return true; + } + } + return false; + } + + function map(arr, iterator, scope) { + if (arr && arrayMap && arrayMap === arr.map) { + return arr.map(iterator, scope); + } + if (!isArray(arr) || typeof iterator !== "function") { + throw new TypeError(); + } + + var t = Object(arr); + var len = t.length >>> 0; + var res = []; + for (var i = 0; i < len; i++) { + if (i in t) { + res.push(iterator.call(scope, t[i], i, t)); + } + } + return res; + } + + function reduce(arr, accumulator, curr) { + var initial = arguments.length > 2; + if (arr && arrayReduce && arrayReduce === arr.reduce) { + return initial ? arr.reduce(accumulator, curr) : arr.reduce(accumulator); + } + if (!isArray(arr) || typeof accumulator !== "function") { + throw new TypeError(); + } + var i = 0, l = arr.length >> 0; + if (arguments.length < 3) { + if (l === 0) { + throw new TypeError("Array length is 0 and no second argument"); + } + curr = arr[0]; + i = 1; // start accumulating at the second element + } else { + curr = arguments[2]; + } + while (i < l) { + if (i in arr) { + curr = accumulator.call(undefined, curr, arr[i], i, arr); + } + ++i; + } + return curr; + } + + function reduceRight(arr, accumulator, curr) { + var initial = arguments.length > 2; + if (arr && arrayReduceRight && arrayReduceRight === arr.reduceRight) { + return initial ? arr.reduceRight(accumulator, curr) : arr.reduceRight(accumulator); + } + if (!isArray(arr) || typeof accumulator !== "function") { + throw new TypeError(); + } + + var t = Object(arr); + var len = t.length >>> 0; + + // no value to return if no initial value, empty array + if (len === 0 && arguments.length === 2) { + throw new TypeError(); + } + + var k = len - 1; + if (arguments.length >= 3) { + curr = arguments[2]; + } else { + do { + if (k in arr) { + curr = arr[k--]; + break; + } + } + while (true); + } + while (k >= 0) { + if (k in t) { + curr = accumulator.call(undefined, curr, t[k], k, t); + } + k--; + } + return curr; + } + + + function toArray(o) { + var ret = []; + if (o !== null) { + var args = argsToArray(arguments); + if (args.length === 1) { + if (isArray(o)) { + ret = o; + } else if (is.isHash(o)) { + for (var i in o) { + if (o.hasOwnProperty(i)) { + ret.push([i, o[i]]); } - s = tz.join(""); } } else { - s = match; - } - if (pad) { - s = _pad(s, l, '0'); + ret.push(o); } - return s; + } else { + forEach(args, function (a) { + ret = ret.concat(toArray(a)); + }); + } + } + return ret; + } + + function sum(array) { + array = array || []; + if (array.length) { + return reduce(array, function (a, b) { + return a + b; }); + } else { + return 0; } + } - }; + function avg(arr) { + arr = arr || []; + if (arr.length) { + var total = sum(arr); + if (is.isNumber(total)) { + return total / arr.length; + } else { + throw new Error("Cannot average an array of non numbers."); + } + } else { + return 0; + } + } - var numberDate = {}; + function sort(arr, cmp) { + return _sort(arr, cmp); + } - function addInterval(interval) { - numberDate[interval + "sFromNow"] = function (val) { - return date.add(new Date(), interval, val); - }; - numberDate[interval + "sAgo"] = function (val) { - return date.add(new Date(), interval, -val); - }; + function min(arr, cmp) { + return _sort(arr, cmp)[0]; } - var intervals = ["year", "month", "day", "hour", "minute", "second"]; - for (var i = 0, l = intervals.length; i < l; i++) { - addInterval(intervals[i]); + function max(arr, cmp) { + return _sort(arr, cmp)[arr.length - 1]; } - var stringDate = { + function difference(arr1) { + var ret = arr1, args = flatten(argsToArray(arguments, 1)); + if (isArray(arr1)) { + ret = filter(arr1, function (a) { + return indexOf(args, a) === -1; + }); + } + return ret; + } - parseDate: function (dateStr, format) { - if (!format) { - throw new Error('format required when calling dateExtender.parse'); - } - var tokens = [], regexp = buildDateEXP(format, tokens), - re = new RegExp("^" + regexp + "$", "i"), - match = re.exec(dateStr); - if (!match) { - return null; - } // null - var result = [1970, 0, 1, 0, 0, 0, 0], // will get converted to a Date at the end - amPm = "", - valid = every(match, function (v, i) { - if (i) { - var token = tokens[i - 1]; - var l = token.length, type = token.charAt(0); - if (type === 'y') { - if (v < 100) { - v = parseInt(v, 10); - //choose century to apply, according to a sliding window - //of 80 years before and 20 years after present year - var year = '' + new Date().getFullYear(), - century = year.substring(0, 2) * 100, - cutoff = min(year.substring(2, 4) + 20, 99); - result[0] = (v < cutoff) ? century + v : century - 100 + v; - } else { - result[0] = v; - } - } else if (type === "M") { - if (l > 2) { - var months = monthNames, j, k; - if (l === 3) { - months = monthAbbr; - } - //Tolerate abbreviating period in month part - //Case-insensitive comparison - v = v.replace(".", "").toLowerCase(); - var contains = false; - for (j = 0, k = months.length; j < k && !contains; j++) { - var s = months[j].replace(".", "").toLocaleLowerCase(); - if (s === v) { - v = j; - contains = true; - } - } - if (!contains) { - return false; - } - } else { - v--; - } - result[1] = v; - } else if (type === "E" || type === "e") { - var days = dayNames; - if (l === 3) { - days = dayAbbr; - } - //Case-insensitive comparison - v = v.toLowerCase(); - days = array.map(days, function (d) { - return d.toLowerCase(); - }); - var d = array.indexOf(days, v); - if (d === -1) { - v = parseInt(v, 10); - if (isNaN(v) || v > days.length) { - return false; - } - } else { - v = d; - } - } else if (type === 'D' || type === "d") { - if (type === "D") { - result[1] = 0; - } - result[2] = v; - } else if (type === "a") { - var am = "am"; - var pm = "pm"; - var period = /\./g; - v = v.replace(period, '').toLowerCase(); - // we might not have seen the hours field yet, so store the state and apply hour change later - amPm = (v === pm) ? 'p' : (v === am) ? 'a' : ''; - } else if (type === "k" || type === "h" || type === "H" || type === "K") { - if (type === "k" && (+v) === 24) { - v = 0; - } - result[3] = v; - } else if (type === "m") { - result[4] = v; - } else if (type === "s") { - result[5] = v; - } else if (type === "S") { - result[6] = v; - } - } - return true; - }); - if (valid) { - var hours = +result[3]; - //account for am/pm - if (amPm === 'p' && hours < 12) { - result[3] = hours + 12; //e.g., 3pm -> 15 - } else if (amPm === 'a' && hours === 12) { - result[3] = 0; //12am -> 0 - } - var dateObject = new Date(result[0], result[1], result[2], result[3], result[4], result[5], result[6]); // Date - var dateToken = (array.indexOf(tokens, 'd') !== -1), - monthToken = (array.indexOf(tokens, 'M') !== -1), - month = result[1], - day = result[2], - dateMonth = dateObject.getMonth(), - dateDay = dateObject.getDate(); - if ((monthToken && dateMonth > month) || (dateToken && dateDay > day)) { - return null; - } - return dateObject; // Date - } else { - return null; + function removeDuplicates(arr) { + var ret = [], i = -1, l, retLength = 0; + if (arr) { + l = arr.length; + while (++i < l) { + var item = arr[i]; + if (indexOf(ret, item) === -1) { + ret[retLength++] = item; + } } } - }; + return ret; + } - var ret = extended.define(is.isDate, date).define(is.isString, stringDate).define(is.isNumber, numberDate); - for (i in date) { - if (date.hasOwnProperty(i)) { - ret[i] = date[i]; - } + function unique(arr) { + return removeDuplicates(arr); } - for (i in stringDate) { - if (stringDate.hasOwnProperty(i)) { - ret[i] = stringDate[i]; + + function rotate(arr, numberOfTimes) { + var ret = arr.slice(); + if (typeof numberOfTimes !== "number") { + numberOfTimes = 1; } - } - for (i in numberDate) { - if (numberDate.hasOwnProperty(i)) { - ret[i] = numberDate[i]; + if (numberOfTimes && isArray(arr)) { + if (numberOfTimes > 0) { + ret.push(ret.shift()); + numberOfTimes--; + } else { + ret.unshift(ret.pop()); + numberOfTimes++; + } + return rotate(ret, numberOfTimes); + } else { + return ret; } } - return ret; - } - - if ("undefined" !== typeof exports) { - if ("undefined" !== typeof module && module.exports) { - module.exports = defineDate(require("extended"), require("is-extended"), require("array-extended")); + function permutations(arr, length) { + var ret = []; + if (isArray(arr)) { + var copy = arr.slice(0); + if (typeof length !== "number") { + length = arr.length; + } + if (!length) { + ret = [ + [] + ]; + } else if (length <= arr.length) { + ret = reduce(arr, function (a, b, i) { + var ret; + if (length > 1) { + ret = permute(b, rotate(copy, i).slice(1), length); + } else { + ret = [ + [b] + ]; + } + return a.concat(ret); + }, []); + } + } + return ret; } - } else if ("function" === typeof define && define.amd) { - define(["extended", "is-extended", "array-extended"], function (extended, is, arr) { - return defineDate(extended, is, arr); - }); - } else { - this.dateExtended = defineDate(this.extended, this.isExtended, this.arrayExtended); - } - -}).call(this); - - + function zip() { + var ret = []; + var arrs = argsToArray(arguments); + if (arrs.length > 1) { + var arr1 = arrs.shift(); + if (isArray(arr1)) { + ret = reduce(arr1, function (a, b, i) { + var curr = [b]; + for (var j = 0; j < arrs.length; j++) { + var currArr = arrs[j]; + if (isArray(currArr) && !is.isUndefined(currArr[i])) { + curr.push(currArr[i]); + } else { + curr.push(null); + } + } + a.push(curr); + return a; + }, []); + } + } + return ret; + } + function transpose(arr) { + var ret = []; + if (isArray(arr) && arr.length) { + var last; + forEach(arr, function (a) { + if (isArray(a) && (!last || a.length === last.length)) { + forEach(a, function (b, i) { + if (!ret[i]) { + ret[i] = []; + } + ret[i].push(b); + }); + last = a; + } + }); + } + return ret; + } + function valuesAt(arr, indexes) { + var ret = []; + indexes = argsToArray(arguments); + arr = indexes.shift(); + if (isArray(arr) && indexes.length) { + for (var i = 0, l = indexes.length; i < l; i++) { + ret.push(arr[indexes[i]] || null); + } + } + return ret; + } + function union() { + var ret = []; + var arrs = argsToArray(arguments); + if (arrs.length > 1) { + for (var i = 0, l = arrs.length; i < l; i++) { + ret = ret.concat(arrs[i]); + } + ret = removeDuplicates(ret); + } + return ret; + } -},{"array-extended":42,"extended":46,"is-extended":56}],44:[function(require,module,exports){ -(function () { + function intersect() { + var collect = [], sets, i = -1 , l; + if (arguments.length > 1) { + //assume we are intersections all the lists in the array + sets = argsToArray(arguments); + } else { + sets = arguments[0]; + } + if (isArray(sets)) { + collect = sets[0]; + i = 0; + l = sets.length; + while (++i < l) { + collect = intersection(collect, sets[i]); + } + } + return removeDuplicates(collect); + } + + function powerSet(arr) { + var ret = []; + if (isArray(arr) && arr.length) { + ret = reduce(arr, function (a, b) { + var ret = map(a, function (c) { + return c.concat(b); + }); + return a.concat(ret); + }, [ + [] + ]); + } + return ret; + } + + function cartesian(a, b) { + var ret = []; + if (isArray(a) && isArray(b) && a.length && b.length) { + ret = cross(a[0], b).concat(cartesian(a.slice(1), b)); + } + return ret; + } + + function compact(arr) { + var ret = []; + if (isArray(arr) && arr.length) { + ret = filter(arr, function (item) { + return !is.isUndefinedOrNull(item); + }); + } + return ret; + } + + function multiply(arr, times) { + times = is.isNumber(times) ? times : 1; + if (!times) { + //make sure times is greater than zero if it is zero then dont multiply it + times = 1; + } + arr = toArray(arr || []); + var ret = [], i = 0; + while (++i <= times) { + ret = ret.concat(arr); + } + return ret; + } + + function flatten(arr) { + var set; + var args = argsToArray(arguments); + if (args.length > 1) { + //assume we are intersections all the lists in the array + set = args; + } else { + set = toArray(arr); + } + return reduce(set, function (a, b) { + return a.concat(b); + }, []); + } + + function pluck(arr, prop) { + prop = prop.split("."); + var result = arr.slice(0); + forEach(prop, function (prop) { + var exec = prop.match(/(\w+)\(\)$/); + result = map(result, function (item) { + return exec ? item[exec[1]]() : item[prop]; + }); + }); + return result; + } + + function invoke(arr, func, args) { + args = argsToArray(arguments, 2); + return map(arr, function (item) { + var exec = isString(func) ? item[func] : func; + return exec.apply(item, args); + }); + } + + + var array = { + toArray: toArray, + sum: sum, + avg: avg, + sort: sort, + min: min, + max: max, + difference: difference, + removeDuplicates: removeDuplicates, + unique: unique, + rotate: rotate, + permutations: permutations, + zip: zip, + transpose: transpose, + valuesAt: valuesAt, + union: union, + intersect: intersect, + powerSet: powerSet, + cartesian: cartesian, + compact: compact, + multiply: multiply, + flatten: flatten, + pluck: pluck, + invoke: invoke, + forEach: forEach, + map: map, + filter: filter, + reduce: reduce, + reduceRight: reduceRight, + some: some, + every: every, + indexOf: indexOf, + lastIndexOf: lastIndexOf + }; + + return extended.define(isArray, array).expose(array); + } + + if ("undefined" !== typeof exports) { + if ("undefined" !== typeof module && module.exports) { + module.exports = defineArray(require("extended"), require("is-extended"), require("arguments-extended")); + } + } else if ("function" === typeof define && define.amd) { + define(["extended", "is-extended", "arguments-extended"], function (extended, is, args) { + return defineArray(extended, is, args); + }); + } else { + this.arrayExtended = defineArray(this.extended, this.isExtended, this.argumentsExtended); + } + +}).call(this); + + + + + + + +},{"arguments-extended":48,"extended":53,"is-extended":70}],50:[function(require,module,exports){ +(function () { + "use strict"; + + function defineDate(extended, is, array) { + + function _pad(string, length, ch, end) { + string = "" + string; //check for numbers + ch = ch || " "; + var strLen = string.length; + while (strLen < length) { + if (end) { + string += ch; + } else { + string = ch + string; + } + strLen++; + } + return string; + } + + function _truncate(string, length, end) { + var ret = string; + if (is.isString(ret)) { + if (string.length > length) { + if (end) { + var l = string.length; + ret = string.substring(l - length, l); + } else { + ret = string.substring(0, length); + } + } + } else { + ret = _truncate("" + ret, length); + } + return ret; + } + + function every(arr, iterator, scope) { + if (!is.isArray(arr) || typeof iterator !== "function") { + throw new TypeError(); + } + var t = Object(arr); + var len = t.length >>> 0; + for (var i = 0; i < len; i++) { + if (i in t && !iterator.call(scope, t[i], i, t)) { + return false; + } + } + return true; + } + + + var transforms = (function () { + var floor = Math.floor, round = Math.round; + + var addMap = { + day: function addDay(date, amount) { + return [amount, "Date", false]; + }, + weekday: function addWeekday(date, amount) { + // Divide the increment time span into weekspans plus leftover days + // e.g., 8 days is one 5-day weekspan / and two leftover days + // Can't have zero leftover days, so numbers divisible by 5 get + // a days value of 5, and the remaining days make up the number of weeks + var days, weeks, mod = amount % 5, strt = date.getDay(), adj = 0; + if (!mod) { + days = (amount > 0) ? 5 : -5; + weeks = (amount > 0) ? ((amount - 5) / 5) : ((amount + 5) / 5); + } else { + days = mod; + weeks = parseInt(amount / 5, 10); + } + if (strt === 6 && amount > 0) { + adj = 1; + } else if (strt === 0 && amount < 0) { + // Orig date is Sun / negative increment + // Jump back over Sat + adj = -1; + } + // Get weekday val for the new date + var trgt = strt + days; + // New date is on Sat or Sun + if (trgt === 0 || trgt === 6) { + adj = (amount > 0) ? 2 : -2; + } + // Increment by number of weeks plus leftover days plus + // weekend adjustments + return [(7 * weeks) + days + adj, "Date", false]; + }, + year: function addYear(date, amount) { + return [amount, "FullYear", true]; + }, + week: function addWeek(date, amount) { + return [amount * 7, "Date", false]; + }, + quarter: function addYear(date, amount) { + return [amount * 3, "Month", true]; + }, + month: function addYear(date, amount) { + return [amount, "Month", true]; + } + }; + + function addTransform(interval, date, amount) { + interval = interval.replace(/s$/, ""); + if (addMap.hasOwnProperty(interval)) { + return addMap[interval](date, amount); + } + return [amount, "UTC" + interval.charAt(0).toUpperCase() + interval.substring(1) + "s", false]; + } + + + var differenceMap = { + "quarter": function quarterDifference(date1, date2, utc) { + var yearDiff = date2.getFullYear() - date1.getFullYear(); + var m1 = date1[utc ? "getUTCMonth" : "getMonth"](); + var m2 = date2[utc ? "getUTCMonth" : "getMonth"](); + // Figure out which quarter the months are in + var q1 = floor(m1 / 3) + 1; + var q2 = floor(m2 / 3) + 1; + // Add quarters for any year difference between the dates + q2 += (yearDiff * 4); + return q2 - q1; + }, + + "weekday": function weekdayDifference(date1, date2, utc) { + var days = differenceTransform("day", date1, date2, utc), weeks; + var mod = days % 7; + // Even number of weeks + if (mod === 0) { + days = differenceTransform("week", date1, date2, utc) * 5; + } else { + // Weeks plus spare change (< 7 days) + var adj = 0, aDay = date1[utc ? "getUTCDay" : "getDay"](), bDay = date2[utc ? "getUTCDay" : "getDay"](); + weeks = parseInt(days / 7, 10); + // Mark the date advanced by the number of + // round weeks (may be zero) + var dtMark = new Date(+date1); + dtMark.setDate(dtMark[utc ? "getUTCDate" : "getDate"]() + (weeks * 7)); + var dayMark = dtMark[utc ? "getUTCDay" : "getDay"](); + + // Spare change days -- 6 or less + if (days > 0) { + if (aDay === 6 || bDay === 6) { + adj = -1; + } else if (aDay === 0) { + adj = 0; + } else if (bDay === 0 || (dayMark + mod) > 5) { + adj = -2; + } + } else if (days < 0) { + if (aDay === 6) { + adj = 0; + } else if (aDay === 0 || bDay === 0) { + adj = 1; + } else if (bDay === 6 || (dayMark + mod) < 0) { + adj = 2; + } + } + days += adj; + days -= (weeks * 2); + } + return days; + }, + year: function (date1, date2) { + return date2.getFullYear() - date1.getFullYear(); + }, + month: function (date1, date2, utc) { + var m1 = date1[utc ? "getUTCMonth" : "getMonth"](); + var m2 = date2[utc ? "getUTCMonth" : "getMonth"](); + return (m2 - m1) + ((date2.getFullYear() - date1.getFullYear()) * 12); + }, + week: function (date1, date2, utc) { + return round(differenceTransform("day", date1, date2, utc) / 7); + }, + day: function (date1, date2) { + return 1.1574074074074074e-8 * (date2.getTime() - date1.getTime()); + }, + hour: function (date1, date2) { + return 2.7777777777777776e-7 * (date2.getTime() - date1.getTime()); + }, + minute: function (date1, date2) { + return 0.000016666666666666667 * (date2.getTime() - date1.getTime()); + }, + second: function (date1, date2) { + return 0.001 * (date2.getTime() - date1.getTime()); + }, + millisecond: function (date1, date2) { + return date2.getTime() - date1.getTime(); + } + }; + + + function differenceTransform(interval, date1, date2, utc) { + interval = interval.replace(/s$/, ""); + return round(differenceMap[interval](date1, date2, utc)); + } + + + return { + addTransform: addTransform, + differenceTransform: differenceTransform + }; + }()), + addTransform = transforms.addTransform, + differenceTransform = transforms.differenceTransform; + + + /** + * @ignore + * Based on DOJO Date Implementation + * + * Dojo is available under *either* the terms of the modified BSD license *or* the + * Academic Free License version 2.1. As a recipient of Dojo, you may choose which + * license to receive this code under (except as noted in per-module LICENSE + * files). Some modules may not be the copyright of the Dojo Foundation. These + * modules contain explicit declarations of copyright in both the LICENSE files in + * the directories in which they reside and in the code itself. No external + * contributions are allowed under licenses which are fundamentally incompatible + * with the AFL or BSD licenses that Dojo is distributed under. + * + */ + + var floor = Math.floor, round = Math.round, min = Math.min, pow = Math.pow, ceil = Math.ceil, abs = Math.abs; + var monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; + var monthAbbr = ["Jan.", "Feb.", "Mar.", "Apr.", "May.", "Jun.", "Jul.", "Aug.", "Sep.", "Oct.", "Nov.", "Dec."]; + var dayNames = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; + var dayAbbr = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; + var eraNames = ["Before Christ", "Anno Domini"]; + var eraAbbr = ["BC", "AD"]; + + + function getDayOfYear(/*Date*/dateObject, utc) { + // summary: gets the day of the year as represented by dateObject + return date.difference(new Date(dateObject.getFullYear(), 0, 1, dateObject.getHours()), dateObject, null, utc) + 1; // Number + } + + function getWeekOfYear(/*Date*/dateObject, /*Number*/firstDayOfWeek, utc) { + firstDayOfWeek = firstDayOfWeek || 0; + var fullYear = dateObject[utc ? "getUTCFullYear" : "getFullYear"](); + var firstDayOfYear = new Date(fullYear, 0, 1).getDay(), + adj = (firstDayOfYear - firstDayOfWeek + 7) % 7, + week = floor((getDayOfYear(dateObject) + adj - 1) / 7); + + // if year starts on the specified day, start counting weeks at 1 + if (firstDayOfYear === firstDayOfWeek) { + week++; + } + + return week; // Number + } + + function getTimezoneName(/*Date*/dateObject) { + var str = dateObject.toString(); + var tz = ''; + var pos = str.indexOf('('); + if (pos > -1) { + tz = str.substring(++pos, str.indexOf(')')); + } + return tz; // String + } + + + function buildDateEXP(pattern, tokens) { + return pattern.replace(/([a-z])\1*/ig,function (match) { + // Build a simple regexp. Avoid captures, which would ruin the tokens list + var s, + c = match.charAt(0), + l = match.length, + p2 = '0?', + p3 = '0{0,2}'; + if (c === 'y') { + s = '\\d{2,4}'; + } else if (c === "M") { + s = (l > 2) ? '\\S+?' : '1[0-2]|' + p2 + '[1-9]'; + } else if (c === "D") { + s = '[12][0-9][0-9]|3[0-5][0-9]|36[0-6]|' + p3 + '[1-9][0-9]|' + p2 + '[1-9]'; + } else if (c === "d") { + s = '3[01]|[12]\\d|' + p2 + '[1-9]'; + } else if (c === "w") { + s = '[1-4][0-9]|5[0-3]|' + p2 + '[1-9]'; + } else if (c === "E") { + s = '\\S+'; + } else if (c === "h") { + s = '1[0-2]|' + p2 + '[1-9]'; + } else if (c === "K") { + s = '1[01]|' + p2 + '\\d'; + } else if (c === "H") { + s = '1\\d|2[0-3]|' + p2 + '\\d'; + } else if (c === "k") { + s = '1\\d|2[0-4]|' + p2 + '[1-9]'; + } else if (c === "m" || c === "s") { + s = '[0-5]\\d'; + } else if (c === "S") { + s = '\\d{' + l + '}'; + } else if (c === "a") { + var am = 'AM', pm = 'PM'; + s = am + '|' + pm; + if (am !== am.toLowerCase()) { + s += '|' + am.toLowerCase(); + } + if (pm !== pm.toLowerCase()) { + s += '|' + pm.toLowerCase(); + } + s = s.replace(/\./g, "\\."); + } else if (c === 'v' || c === 'z' || c === 'Z' || c === 'G' || c === 'q' || c === 'Q') { + s = ".*"; + } else { + s = c === " " ? "\\s*" : c + "*"; + } + if (tokens) { + tokens.push(match); + } + + return "(" + s + ")"; // add capture + }).replace(/[\xa0 ]/g, "[\\s\\xa0]"); // normalize whitespace. Need explicit handling of \xa0 for IE. + } + + + /** + * @namespace Utilities for Dates + */ + var date = { + + /**@lends date*/ + + /** + * Returns the number of days in the month of a date + * + * @example + * + * dateExtender.getDaysInMonth(new Date(2006, 1, 1)); //28 + * dateExtender.getDaysInMonth(new Date(2004, 1, 1)); //29 + * dateExtender.getDaysInMonth(new Date(2006, 2, 1)); //31 + * dateExtender.getDaysInMonth(new Date(2006, 3, 1)); //30 + * dateExtender.getDaysInMonth(new Date(2006, 4, 1)); //31 + * dateExtender.getDaysInMonth(new Date(2006, 5, 1)); //30 + * dateExtender.getDaysInMonth(new Date(2006, 6, 1)); //31 + * @param {Date} dateObject the date containing the month + * @return {Number} the number of days in the month + */ + getDaysInMonth: function (/*Date*/dateObject) { + // summary: + // Returns the number of days in the month used by dateObject + var month = dateObject.getMonth(); + var days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; + if (month === 1 && date.isLeapYear(dateObject)) { + return 29; + } // Number + return days[month]; // Number + }, + + /** + * Determines if a date is a leap year + * + * @example + * + * dateExtender.isLeapYear(new Date(1600, 0, 1)); //true + * dateExtender.isLeapYear(new Date(2004, 0, 1)); //true + * dateExtender.isLeapYear(new Date(2000, 0, 1)); //true + * dateExtender.isLeapYear(new Date(2006, 0, 1)); //false + * dateExtender.isLeapYear(new Date(1900, 0, 1)); //false + * dateExtender.isLeapYear(new Date(1800, 0, 1)); //false + * dateExtender.isLeapYear(new Date(1700, 0, 1)); //false + * + * @param {Date} dateObject + * @returns {Boolean} true if it is a leap year false otherwise + */ + isLeapYear: function (/*Date*/dateObject, utc) { + var year = dateObject[utc ? "getUTCFullYear" : "getFullYear"](); + return (year % 400 === 0) || (year % 4 === 0 && year % 100 !== 0); + + }, + + /** + * Determines if a date is on a weekend + * + * @example + * + * var thursday = new Date(2006, 8, 21); + * var saturday = new Date(2006, 8, 23); + * var sunday = new Date(2006, 8, 24); + * var monday = new Date(2006, 8, 25); + * dateExtender.isWeekend(thursday)); //false + * dateExtender.isWeekend(saturday); //true + * dateExtender.isWeekend(sunday); //true + * dateExtender.isWeekend(monday)); //false + * + * @param {Date} dateObject the date to test + * + * @returns {Boolean} true if the date is a weekend + */ + isWeekend: function (/*Date?*/dateObject, utc) { + // summary: + // Determines if the date falls on a weekend, according to local custom. + var day = (dateObject || new Date())[utc ? "getUTCDay" : "getDay"](); + return day === 0 || day === 6; + }, + + /** + * Get the timezone of a date + * + * @example + * //just setting the strLocal to simulate the toString() of a date + * dt.str = 'Sun Sep 17 2006 22:25:51 GMT-0500 (CDT)'; + * //just setting the strLocal to simulate the locale + * dt.strLocale = 'Sun 17 Sep 2006 10:25:51 PM CDT'; + * dateExtender.getTimezoneName(dt); //'CDT' + * dt.str = 'Sun Sep 17 2006 22:57:18 GMT-0500 (CDT)'; + * dt.strLocale = 'Sun Sep 17 22:57:18 2006'; + * dateExtender.getTimezoneName(dt); //'CDT' + * @param dateObject the date to get the timezone from + * + * @returns {String} the timezone of the date + */ + getTimezoneName: getTimezoneName, + + /** + * Compares two dates + * + * @example + * + * var d1 = new Date(); + * d1.setHours(0); + * dateExtender.compare(d1, d1); // 0 + * + * var d1 = new Date(); + * d1.setHours(0); + * var d2 = new Date(); + * d2.setFullYear(2005); + * d2.setHours(12); + * dateExtender.compare(d1, d2, "date"); // 1 + * dateExtender.compare(d1, d2, "datetime"); // 1 + * + * var d1 = new Date(); + * d1.setHours(0); + * var d2 = new Date(); + * d2.setFullYear(2005); + * d2.setHours(12); + * dateExtender.compare(d2, d1, "date"); // -1 + * dateExtender.compare(d1, d2, "time"); //-1 + * + * @param {Date|String} date1 the date to comapare + * @param {Date|String} [date2=new Date()] the date to compare date1 againse + * @param {"date"|"time"|"datetime"} portion compares the portion specified + * + * @returns -1 if date1 is < date2 0 if date1 === date2 1 if date1 > date2 + */ + compare: function (/*Date*/date1, /*Date*/date2, /*String*/portion) { + date1 = new Date(+date1); + date2 = new Date(+(date2 || new Date())); + + if (portion === "date") { + // Ignore times and compare dates. + date1.setHours(0, 0, 0, 0); + date2.setHours(0, 0, 0, 0); + } else if (portion === "time") { + // Ignore dates and compare times. + date1.setFullYear(0, 0, 0); + date2.setFullYear(0, 0, 0); + } + return date1 > date2 ? 1 : date1 < date2 ? -1 : 0; + }, + + + /** + * Adds a specified interval and amount to a date + * + * @example + * var dtA = new Date(2005, 11, 27); + * dateExtender.add(dtA, "year", 1); //new Date(2006, 11, 27); + * dateExtender.add(dtA, "years", 1); //new Date(2006, 11, 27); + * + * dtA = new Date(2000, 0, 1); + * dateExtender.add(dtA, "quarter", 1); //new Date(2000, 3, 1); + * dateExtender.add(dtA, "quarters", 1); //new Date(2000, 3, 1); + * + * dtA = new Date(2000, 0, 1); + * dateExtender.add(dtA, "month", 1); //new Date(2000, 1, 1); + * dateExtender.add(dtA, "months", 1); //new Date(2000, 1, 1); + * + * dtA = new Date(2000, 0, 31); + * dateExtender.add(dtA, "month", 1); //new Date(2000, 1, 29); + * dateExtender.add(dtA, "months", 1); //new Date(2000, 1, 29); + * + * dtA = new Date(2000, 0, 1); + * dateExtender.add(dtA, "week", 1); //new Date(2000, 0, 8); + * dateExtender.add(dtA, "weeks", 1); //new Date(2000, 0, 8); + * + * dtA = new Date(2000, 0, 1); + * dateExtender.add(dtA, "day", 1); //new Date(2000, 0, 2); + * + * dtA = new Date(2000, 0, 1); + * dateExtender.add(dtA, "weekday", 1); //new Date(2000, 0, 3); + * + * dtA = new Date(2000, 0, 1, 11); + * dateExtender.add(dtA, "hour", 1); //new Date(2000, 0, 1, 12); + * + * dtA = new Date(2000, 11, 31, 23, 59); + * dateExtender.add(dtA, "minute", 1); //new Date(2001, 0, 1, 0, 0); + * + * dtA = new Date(2000, 11, 31, 23, 59, 59); + * dateExtender.add(dtA, "second", 1); //new Date(2001, 0, 1, 0, 0, 0); + * + * dtA = new Date(2000, 11, 31, 23, 59, 59, 999); + * dateExtender.add(dtA, "millisecond", 1); //new Date(2001, 0, 1, 0, 0, 0, 0); + * + * @param {Date} date + * @param {String} interval the interval to add + *
      + *
    • day | days
    • + *
    • weekday | weekdays
    • + *
    • year | years
    • + *
    • week | weeks
    • + *
    • quarter | quarters
    • + *
    • months | months
    • + *
    • hour | hours
    • + *
    • minute | minutes
    • + *
    • second | seconds
    • + *
    • millisecond | milliseconds
    • + *
    + * @param {Number} [amount=0] the amount to add + */ + add: function (/*Date*/date, /*String*/interval, /*int*/amount) { + var res = addTransform(interval, date, amount || 0); + amount = res[0]; + var property = res[1]; + var sum = new Date(+date); + var fixOvershoot = res[2]; + if (property) { + sum["set" + property](sum["get" + property]() + amount); + } + + if (fixOvershoot && (sum.getDate() < date.getDate())) { + sum.setDate(0); + } + + return sum; // Date + }, + + /** + * Finds the difference between two dates based on the specified interval + * + * @example + * + * var dtA, dtB; + * + * dtA = new Date(2005, 11, 27); + * dtB = new Date(2006, 11, 27); + * dateExtender.difference(dtA, dtB, "year"); //1 + * + * dtA = new Date(2000, 1, 29); + * dtB = new Date(2001, 2, 1); + * dateExtender.difference(dtA, dtB, "quarter"); //4 + * dateExtender.difference(dtA, dtB, "month"); //13 + * + * dtA = new Date(2000, 1, 1); + * dtB = new Date(2000, 1, 8); + * dateExtender.difference(dtA, dtB, "week"); //1 + * + * dtA = new Date(2000, 1, 29); + * dtB = new Date(2000, 2, 1); + * dateExtender.difference(dtA, dtB, "day"); //1 + * + * dtA = new Date(2006, 7, 3); + * dtB = new Date(2006, 7, 11); + * dateExtender.difference(dtA, dtB, "weekday"); //6 + * + * dtA = new Date(2000, 11, 31, 23); + * dtB = new Date(2001, 0, 1, 0); + * dateExtender.difference(dtA, dtB, "hour"); //1 + * + * dtA = new Date(2000, 11, 31, 23, 59); + * dtB = new Date(2001, 0, 1, 0, 0); + * dateExtender.difference(dtA, dtB, "minute"); //1 + * + * dtA = new Date(2000, 11, 31, 23, 59, 59); + * dtB = new Date(2001, 0, 1, 0, 0, 0); + * dateExtender.difference(dtA, dtB, "second"); //1 + * + * dtA = new Date(2000, 11, 31, 23, 59, 59, 999); + * dtB = new Date(2001, 0, 1, 0, 0, 0, 0); + * dateExtender.difference(dtA, dtB, "millisecond"); //1 + * + * + * @param {Date} date1 + * @param {Date} [date2 = new Date()] + * @param {String} [interval = "day"] the intercal to find the difference of. + *
      + *
    • day | days
    • + *
    • weekday | weekdays
    • + *
    • year | years
    • + *
    • week | weeks
    • + *
    • quarter | quarters
    • + *
    • months | months
    • + *
    • hour | hours
    • + *
    • minute | minutes
    • + *
    • second | seconds
    • + *
    • millisecond | milliseconds
    • + *
    + */ + difference: function (/*Date*/date1, /*Date?*/date2, /*String*/interval, utc) { + date2 = date2 || new Date(); + interval = interval || "day"; + return differenceTransform(interval, date1, date2, utc); + }, + + /** + * Formats a date to the specidifed format string + * + * @example + * + * var date = new Date(2006, 7, 11, 0, 55, 12, 345); + * dateExtender.format(date, "EEEE, MMMM dd, yyyy"); //"Friday, August 11, 2006" + * dateExtender.format(date, "M/dd/yy"); //"8/11/06" + * dateExtender.format(date, "E"); //"6" + * dateExtender.format(date, "h:m a"); //"12:55 AM" + * dateExtender.format(date, 'h:m:s'); //"12:55:12" + * dateExtender.format(date, 'h:m:s.SS'); //"12:55:12.35" + * dateExtender.format(date, 'k:m:s.SS'); //"24:55:12.35" + * dateExtender.format(date, 'H:m:s.SS'); //"0:55:12.35" + * dateExtender.format(date, "ddMMyyyy"); //"11082006" + * + * @param date the date to format + * @param {String} format the format of the date composed of the following options + *
      + *
    • G Era designator Text AD
    • + *
    • y Year Year 1996; 96
    • + *
    • M Month in year Month July; Jul; 07
    • + *
    • w Week in year Number 27
    • + *
    • W Week in month Number 2
    • + *
    • D Day in year Number 189
    • + *
    • d Day in month Number 10
    • + *
    • E Day in week Text Tuesday; Tue
    • + *
    • a Am/pm marker Text PM
    • + *
    • H Hour in day (0-23) Number 0
    • + *
    • k Hour in day (1-24) Number 24
    • + *
    • K Hour in am/pm (0-11) Number 0
    • + *
    • h Hour in am/pm (1-12) Number 12
    • + *
    • m Minute in hour Number 30
    • + *
    • s Second in minute Number 55
    • + *
    • S Millisecond Number 978
    • + *
    • z Time zone General time zone Pacific Standard Time; PST; GMT-08:00
    • + *
    • Z Time zone RFC 822 time zone -0800
    • + *
    + */ + format: function (date, format, utc) { + utc = utc || false; + var fullYear, month, day, d, hour, minute, second, millisecond; + if (utc) { + fullYear = date.getUTCFullYear(); + month = date.getUTCMonth(); + day = date.getUTCDay(); + d = date.getUTCDate(); + hour = date.getUTCHours(); + minute = date.getUTCMinutes(); + second = date.getUTCSeconds(); + millisecond = date.getUTCMilliseconds(); + } else { + fullYear = date.getFullYear(); + month = date.getMonth(); + d = date.getDate(); + day = date.getDay(); + hour = date.getHours(); + minute = date.getMinutes(); + second = date.getSeconds(); + millisecond = date.getMilliseconds(); + } + return format.replace(/([A-Za-z])\1*/g, function (match) { + var s, pad, + c = match.charAt(0), + l = match.length; + if (c === 'd') { + s = "" + d; + pad = true; + } else if (c === "H" && !s) { + s = "" + hour; + pad = true; + } else if (c === 'm' && !s) { + s = "" + minute; + pad = true; + } else if (c === 's') { + if (!s) { + s = "" + second; + } + pad = true; + } else if (c === "G") { + s = ((l < 4) ? eraAbbr : eraNames)[fullYear < 0 ? 0 : 1]; + } else if (c === "y") { + s = fullYear; + if (l > 1) { + if (l === 2) { + s = _truncate("" + s, 2, true); + } else { + pad = true; + } + } + } else if (c.toUpperCase() === "Q") { + s = ceil((month + 1) / 3); + pad = true; + } else if (c === "M") { + if (l < 3) { + s = month + 1; + pad = true; + } else { + s = (l === 3 ? monthAbbr : monthNames)[month]; + } + } else if (c === "w") { + s = getWeekOfYear(date, 0, utc); + pad = true; + } else if (c === "D") { + s = getDayOfYear(date, utc); + pad = true; + } else if (c === "E") { + if (l < 3) { + s = day + 1; + pad = true; + } else { + s = (l === -3 ? dayAbbr : dayNames)[day]; + } + } else if (c === 'a') { + s = (hour < 12) ? 'AM' : 'PM'; + } else if (c === "h") { + s = (hour % 12) || 12; + pad = true; + } else if (c === "K") { + s = (hour % 12); + pad = true; + } else if (c === "k") { + s = hour || 24; + pad = true; + } else if (c === "S") { + s = round(millisecond * pow(10, l - 3)); + pad = true; + } else if (c === "z" || c === "v" || c === "Z") { + s = getTimezoneName(date); + if ((c === "z" || c === "v") && !s) { + l = 4; + } + if (!s || c === "Z") { + var offset = date.getTimezoneOffset(); + var tz = [ + (offset >= 0 ? "-" : "+"), + _pad(floor(abs(offset) / 60), 2, "0"), + _pad(abs(offset) % 60, 2, "0") + ]; + if (l === 4) { + tz.splice(0, 0, "GMT"); + tz.splice(3, 0, ":"); + } + s = tz.join(""); + } + } else { + s = match; + } + if (pad) { + s = _pad(s, l, '0'); + } + return s; + }); + } + + }; + + var numberDate = {}; + + function addInterval(interval) { + numberDate[interval + "sFromNow"] = function (val) { + return date.add(new Date(), interval, val); + }; + numberDate[interval + "sAgo"] = function (val) { + return date.add(new Date(), interval, -val); + }; + } + + var intervals = ["year", "month", "day", "hour", "minute", "second"]; + for (var i = 0, l = intervals.length; i < l; i++) { + addInterval(intervals[i]); + } + + var stringDate = { + + parseDate: function (dateStr, format) { + if (!format) { + throw new Error('format required when calling dateExtender.parse'); + } + var tokens = [], regexp = buildDateEXP(format, tokens), + re = new RegExp("^" + regexp + "$", "i"), + match = re.exec(dateStr); + if (!match) { + return null; + } // null + var result = [1970, 0, 1, 0, 0, 0, 0], // will get converted to a Date at the end + amPm = "", + valid = every(match, function (v, i) { + if (i) { + var token = tokens[i - 1]; + var l = token.length, type = token.charAt(0); + if (type === 'y') { + if (v < 100) { + v = parseInt(v, 10); + //choose century to apply, according to a sliding window + //of 80 years before and 20 years after present year + var year = '' + new Date().getFullYear(), + century = year.substring(0, 2) * 100, + cutoff = min(year.substring(2, 4) + 20, 99); + result[0] = (v < cutoff) ? century + v : century - 100 + v; + } else { + result[0] = v; + } + } else if (type === "M") { + if (l > 2) { + var months = monthNames, j, k; + if (l === 3) { + months = monthAbbr; + } + //Tolerate abbreviating period in month part + //Case-insensitive comparison + v = v.replace(".", "").toLowerCase(); + var contains = false; + for (j = 0, k = months.length; j < k && !contains; j++) { + var s = months[j].replace(".", "").toLocaleLowerCase(); + if (s === v) { + v = j; + contains = true; + } + } + if (!contains) { + return false; + } + } else { + v--; + } + result[1] = v; + } else if (type === "E" || type === "e") { + var days = dayNames; + if (l === 3) { + days = dayAbbr; + } + //Case-insensitive comparison + v = v.toLowerCase(); + days = array.map(days, function (d) { + return d.toLowerCase(); + }); + var d = array.indexOf(days, v); + if (d === -1) { + v = parseInt(v, 10); + if (isNaN(v) || v > days.length) { + return false; + } + } else { + v = d; + } + } else if (type === 'D' || type === "d") { + if (type === "D") { + result[1] = 0; + } + result[2] = v; + } else if (type === "a") { + var am = "am"; + var pm = "pm"; + var period = /\./g; + v = v.replace(period, '').toLowerCase(); + // we might not have seen the hours field yet, so store the state and apply hour change later + amPm = (v === pm) ? 'p' : (v === am) ? 'a' : ''; + } else if (type === "k" || type === "h" || type === "H" || type === "K") { + if (type === "k" && (+v) === 24) { + v = 0; + } + result[3] = v; + } else if (type === "m") { + result[4] = v; + } else if (type === "s") { + result[5] = v; + } else if (type === "S") { + result[6] = v; + } + } + return true; + }); + if (valid) { + var hours = +result[3]; + //account for am/pm + if (amPm === 'p' && hours < 12) { + result[3] = hours + 12; //e.g., 3pm -> 15 + } else if (amPm === 'a' && hours === 12) { + result[3] = 0; //12am -> 0 + } + var dateObject = new Date(result[0], result[1], result[2], result[3], result[4], result[5], result[6]); // Date + var dateToken = (array.indexOf(tokens, 'd') !== -1), + monthToken = (array.indexOf(tokens, 'M') !== -1), + month = result[1], + day = result[2], + dateMonth = dateObject.getMonth(), + dateDay = dateObject.getDate(); + if ((monthToken && dateMonth > month) || (dateToken && dateDay > day)) { + return null; + } + return dateObject; // Date + } else { + return null; + } + } + }; + + + var ret = extended.define(is.isDate, date).define(is.isString, stringDate).define(is.isNumber, numberDate); + for (i in date) { + if (date.hasOwnProperty(i)) { + ret[i] = date[i]; + } + } + + for (i in stringDate) { + if (stringDate.hasOwnProperty(i)) { + ret[i] = stringDate[i]; + } + } + for (i in numberDate) { + if (numberDate.hasOwnProperty(i)) { + ret[i] = numberDate[i]; + } + } + return ret; + } + + if ("undefined" !== typeof exports) { + if ("undefined" !== typeof module && module.exports) { + module.exports = defineDate(require("extended"), require("is-extended"), require("array-extended")); + + } + } else if ("function" === typeof define && define.amd) { + define(["extended", "is-extended", "array-extended"], function (extended, is, arr) { + return defineDate(extended, is, arr); + }); + } else { + this.dateExtended = defineDate(this.extended, this.isExtended, this.arrayExtended); + } + +}).call(this); + + + + + + + +},{"array-extended":49,"extended":53,"is-extended":70}],51:[function(require,module,exports){ +(function () { + + /** + * @projectName declare + * @github http://github.com/doug-martin/declare.js + * @header + * + * Declare is a library designed to allow writing object oriented code the same way in both the browser and node.js. + * + * ##Installation + * + * `npm install declare.js` + * + * Or [download the source](https://raw.github.com/doug-martin/declare.js/master/declare.js) ([minified](https://raw.github.com/doug-martin/declare.js/master/declare-min.js)) + * + * ###Requirejs + * + * To use with requirejs place the `declare` source in the root scripts directory + * + * ``` + * + * define(["declare"], function(declare){ + * return declare({ + * instance : { + * hello : function(){ + * return "world"; + * } + * } + * }); + * }); + * + * ``` + * + * + * ##Usage + * + * declare.js provides + * + * Class methods + * + * * `as(module | object, name)` : exports the object to module or the object with the name + * * `mixin(mixin)` : mixes in an object but does not inherit directly from the object. **Note** this does not return a new class but changes the original class. + * * `extend(proto)` : extend a class with the given properties. A shortcut to `declare(Super, {})`; + * + * Instance methods + * + * * `_super(arguments)`: calls the super of the current method, you can pass in either the argments object or an array with arguments you want passed to super + * * `_getSuper()`: returns a this methods direct super. + * * `_static` : use to reference class properties and methods. + * * `get(prop)` : gets a property invoking the getter if it exists otherwise it just returns the named property on the object. + * * `set(prop, val)` : sets a property invoking the setter if it exists otherwise it just sets the named property on the object. + * + * + * ###Declaring a new Class + * + * Creating a new class with declare is easy! + * + * ``` + * + * var Mammal = declare({ + * //define your instance methods and properties + * instance : { + * + * //will be called whenever a new instance is created + * constructor: function(options) { + * options = options || {}; + * this._super(arguments); + * this._type = options.type || "mammal"; + * }, + * + * speak : function() { + * return "A mammal of type " + this._type + " sounds like"; + * }, + * + * //Define your getters + * getters : { + * + * //can be accessed by using the get method. (mammal.get("type")) + * type : function() { + * return this._type; + * } + * }, + * + * //Define your setters + * setters : { + * + * //can be accessed by using the set method. (mammal.set("type", "mammalType")) + * type : function(t) { + * this._type = t; + * } + * } + * }, + * + * //Define your static methods + * static : { + * + * //Mammal.soundOff(); //"Im a mammal!!" + * soundOff : function() { + * return "Im a mammal!!"; + * } + * } + * }); + * + * + * ``` + * + * You can use Mammal just like you would any other class. + * + * ``` + * Mammal.soundOff("Im a mammal!!"); + * + * var myMammal = new Mammal({type : "mymammal"}); + * myMammal.speak(); // "A mammal of type mymammal sounds like" + * myMammal.get("type"); //"mymammal" + * myMammal.set("type", "mammal"); + * myMammal.get("type"); //"mammal" + * + * + * ``` + * + * ###Extending a class + * + * If you want to just extend a single class use the .extend method. + * + * ``` + * + * var Wolf = Mammal.extend({ + * + * //define your instance method + * instance: { + * + * //You can override super constructors just be sure to call `_super` + * constructor: function(options) { + * options = options || {}; + * this._super(arguments); //call our super constructor. + * this._sound = "growl"; + * this._color = options.color || "grey"; + * }, + * + * //override Mammals `speak` method by appending our own data to it. + * speak : function() { + * return this._super(arguments) + " a " + this._sound; + * }, + * + * //add new getters for sound and color + * getters : { + * + * //new Wolf().get("type") + * //notice color is read only as we did not define a setter + * color : function() { + * return this._color; + * }, + * + * //new Wolf().get("sound") + * sound : function() { + * return this._sound; + * } + * }, + * + * setters : { + * + * //new Wolf().set("sound", "howl") + * sound : function(s) { + * this._sound = s; + * } + * } + * + * }, + * + * static : { + * + * //You can override super static methods also! And you can still use _super + * soundOff : function() { + * //You can even call super in your statics!!! + * //should return "I'm a mammal!! that growls" + * return this._super(arguments) + " that growls"; + * } + * } + * }); + * + * Wolf.soundOff(); //Im a mammal!! that growls + * + * var myWolf = new Wolf(); + * myWolf instanceof Mammal //true + * myWolf instanceof Wolf //true + * + * ``` + * + * You can also extend a class by using the declare method and just pass in the super class. + * + * ``` + * //Typical hierarchical inheritance + * // Mammal->Wolf->Dog + * var Dog = declare(Wolf, { + * instance: { + * constructor: function(options) { + * options = options || {}; + * this._super(arguments); + * //override Wolfs initialization of sound to woof. + * this._sound = "woof"; + * + * }, + * + * speak : function() { + * //Should return "A mammal of type mammal sounds like a growl thats domesticated" + * return this._super(arguments) + " thats domesticated"; + * } + * }, + * + * static : { + * soundOff : function() { + * //should return "I'm a mammal!! that growls but now barks" + * return this._super(arguments) + " but now barks"; + * } + * } + * }); + * + * Dog.soundOff(); //Im a mammal!! that growls but now barks + * + * var myDog = new Dog(); + * myDog instanceof Mammal //true + * myDog instanceof Wolf //true + * myDog instanceof Dog //true + * + * + * //Notice you still get the extend method. + * + * // Mammal->Wolf->Dog->Breed + * var Breed = Dog.extend({ + * instance: { + * + * //initialize outside of constructor + * _pitch : "high", + * + * constructor: function(options) { + * options = options || {}; + * this._super(arguments); + * this.breed = options.breed || "lab"; + * }, + * + * speak : function() { + * //Should return "A mammal of type mammal sounds like a + * //growl thats domesticated with a high pitch!" + * return this._super(arguments) + " with a " + this._pitch + " pitch!"; + * }, + * + * getters : { + * pitch : function() { + * return this._pitch; + * } + * } + * }, + * + * static : { + * soundOff : function() { + * //should return "I'M A MAMMAL!! THAT GROWLS BUT NOW BARKS!" + * return this._super(arguments).toUpperCase() + "!"; + * } + * } + * }); + * + * + * Breed.soundOff()//"IM A MAMMAL!! THAT GROWLS BUT NOW BARKS!" + * + * var myBreed = new Breed({color : "gold", type : "lab"}), + * myBreed instanceof Dog //true + * myBreed instanceof Wolf //true + * myBreed instanceof Mammal //true + * myBreed.speak() //"A mammal of type lab sounds like a woof thats domesticated with a high pitch!" + * myBreed.get("type") //"lab" + * myBreed.get("color") //"gold" + * myBreed.get("sound")" //"woof" + * ``` + * + * ###Multiple Inheritance / Mixins + * + * declare also allows the use of multiple super classes. + * This is useful if you have generic classes that provide functionality but shouldnt be used on their own. + * + * Lets declare a mixin that allows us to watch for property changes. + * + * ``` + * //Notice that we set up the functions outside of declare because we can reuse them + * + * function _set(prop, val) { + * //get the old value + * var oldVal = this.get(prop); + * //call super to actually set the property + * var ret = this._super(arguments); + * //call our handlers + * this.__callHandlers(prop, oldVal, val); + * return ret; + * } + * + * function _callHandlers(prop, oldVal, newVal) { + * //get our handlers for the property + * var handlers = this.__watchers[prop], l; + * //if the handlers exist and their length does not equal 0 then we call loop through them + * if (handlers && (l = handlers.length) !== 0) { + * for (var i = 0; i < l; i++) { + * //call the handler + * handlers[i].call(null, prop, oldVal, newVal); + * } + * } + * } + * + * + * //the watch function + * function _watch(prop, handler) { + * if ("function" !== typeof handler) { + * //if its not a function then its an invalid handler + * throw new TypeError("Invalid handler."); + * } + * if (!this.__watchers[prop]) { + * //create the watchers if it doesnt exist + * this.__watchers[prop] = [handler]; + * } else { + * //otherwise just add it to the handlers array + * this.__watchers[prop].push(handler); + * } + * } + * + * function _unwatch(prop, handler) { + * if ("function" !== typeof handler) { + * throw new TypeError("Invalid handler."); + * } + * var handlers = this.__watchers[prop], index; + * if (handlers && (index = handlers.indexOf(handler)) !== -1) { + * //remove the handler if it is found + * handlers.splice(index, 1); + * } + * } + * + * declare({ + * instance:{ + * constructor:function () { + * this._super(arguments); + * //set up our watchers + * this.__watchers = {}; + * }, + * + * //override the default set function so we can watch values + * "set":_set, + * //set up our callhandlers function + * __callHandlers:_callHandlers, + * //add the watch function + * watch:_watch, + * //add the unwatch function + * unwatch:_unwatch + * }, + * + * "static":{ + * + * init:function () { + * this._super(arguments); + * this.__watchers = {}; + * }, + * //override the default set function so we can watch values + * "set":_set, + * //set our callHandlers function + * __callHandlers:_callHandlers, + * //add the watch + * watch:_watch, + * //add the unwatch function + * unwatch:_unwatch + * } + * }) + * + * ``` + * + * Now lets use the mixin + * + * ``` + * var WatchDog = declare([Dog, WatchMixin]); + * + * var watchDog = new WatchDog(); + * //create our handler + * function watch(id, oldVal, newVal) { + * console.log("watchdog's %s was %s, now %s", id, oldVal, newVal); + * } + * + * //watch for property changes + * watchDog.watch("type", watch); + * watchDog.watch("color", watch); + * watchDog.watch("sound", watch); + * + * //now set the properties each handler will be called + * watchDog.set("type", "newDog"); + * watchDog.set("color", "newColor"); + * watchDog.set("sound", "newSound"); + * + * + * //unwatch the property changes + * watchDog.unwatch("type", watch); + * watchDog.unwatch("color", watch); + * watchDog.unwatch("sound", watch); + * + * //no handlers will be called this time + * watchDog.set("type", "newDog"); + * watchDog.set("color", "newColor"); + * watchDog.set("sound", "newSound"); + * + * + * ``` + * + * ###Accessing static methods and properties witin an instance. + * + * To access static properties on an instance use the `_static` property which is a reference to your constructor. + * + * For example if your in your constructor and you want to have configurable default values. + * + * ``` + * consturctor : function constructor(opts){ + * this.opts = opts || {}; + * this._type = opts.type || this._static.DEFAULT_TYPE; + * } + * ``` + * + * + * + * ###Creating a new instance of within an instance. + * + * Often times you want to create a new instance of an object within an instance. If your subclassed however you cannot return a new instance of the parent class as it will not be the right sub class. `declare` provides a way around this by setting the `_static` property on each isntance of the class. + * + * Lets add a reproduce method `Mammal` + * + * ``` + * reproduce : function(options){ + * return new this._static(options); + * } + * ``` + * + * Now in each subclass you can call reproduce and get the proper type. + * + * ``` + * var myDog = new Dog(); + * var myDogsChild = myDog.reproduce(); + * + * myDogsChild instanceof Dog; //true + * ``` + * + * ###Using the `as` + * + * `declare` also provides an `as` method which allows you to add your class to an object or if your using node.js you can pass in `module` and the class will be exported as the module. + * + * ``` + * var animals = {}; + * + * Mammal.as(animals, "Dog"); + * Wolf.as(animals, "Wolf"); + * Dog.as(animals, "Dog"); + * Breed.as(animals, "Breed"); + * + * var myDog = new animals.Dog(); + * + * ``` + * + * Or in node + * + * ``` + * Mammal.as(exports, "Dog"); + * Wolf.as(exports, "Wolf"); + * Dog.as(exports, "Dog"); + * Breed.as(exports, "Breed"); + * + * ``` + * + * To export a class as the `module` in node + * + * ``` + * Mammal.as(module); + * ``` + * + * + */ + function createDeclared() { + var arraySlice = Array.prototype.slice, classCounter = 0, Base, forceNew = new Function(); + + var SUPER_REGEXP = /(super)/g; + + function argsToArray(args, slice) { + slice = slice || 0; + return arraySlice.call(args, slice); + } + + function isArray(obj) { + return Object.prototype.toString.call(obj) === "[object Array]"; + } + + function isObject(obj) { + var undef; + return obj !== null && obj !== undef && typeof obj === "object"; + } + + function isHash(obj) { + var ret = isObject(obj); + return ret && obj.constructor === Object; + } + + var isArguments = function _isArguments(object) { + return Object.prototype.toString.call(object) === '[object Arguments]'; + }; + + if (!isArguments(arguments)) { + isArguments = function _isArguments(obj) { + return !!(obj && obj.hasOwnProperty("callee")); + }; + } + + function indexOf(arr, item) { + if (arr && arr.length) { + for (var i = 0, l = arr.length; i < l; i++) { + if (arr[i] === item) { + return i; + } + } + } + return -1; + } + + function merge(target, source, exclude) { + var name, s; + for (name in source) { + if (source.hasOwnProperty(name) && indexOf(exclude, name) === -1) { + s = source[name]; + if (!(name in target) || (target[name] !== s)) { + target[name] = s; + } + } + } + return target; + } + + function callSuper(args, a) { + var meta = this.__meta, + supers = meta.supers, + l = supers.length, superMeta = meta.superMeta, pos = superMeta.pos; + if (l > pos) { + args = !args ? [] : (!isArguments(args) && !isArray(args)) ? [args] : args; + var name = superMeta.name, f = superMeta.f, m; + do { + m = supers[pos][name]; + if ("function" === typeof m && (m = m._f || m) !== f) { + superMeta.pos = 1 + pos; + return m.apply(this, args); + } + } while (l > ++pos); + } + + return null; + } + + function getSuper() { + var meta = this.__meta, + supers = meta.supers, + l = supers.length, superMeta = meta.superMeta, pos = superMeta.pos; + if (l > pos) { + var name = superMeta.name, f = superMeta.f, m; + do { + m = supers[pos][name]; + if ("function" === typeof m && (m = m._f || m) !== f) { + superMeta.pos = 1 + pos; + return m.bind(this); + } + } while (l > ++pos); + } + return null; + } + + function getter(name) { + var getters = this.__getters__; + if (getters.hasOwnProperty(name)) { + return getters[name].apply(this); + } else { + return this[name]; + } + } + + function setter(name, val) { + var setters = this.__setters__; + if (isHash(name)) { + for (var i in name) { + var prop = name[i]; + if (setters.hasOwnProperty(i)) { + setters[name].call(this, prop); + } else { + this[i] = prop; + } + } + } else { + if (setters.hasOwnProperty(name)) { + return setters[name].apply(this, argsToArray(arguments, 1)); + } else { + return this[name] = val; + } + } + } + + + function defaultFunction() { + var meta = this.__meta || {}, + supers = meta.supers, + l = supers.length, superMeta = meta.superMeta, pos = superMeta.pos; + if (l > pos) { + var name = superMeta.name, f = superMeta.f, m; + do { + m = supers[pos][name]; + if ("function" === typeof m && (m = m._f || m) !== f) { + superMeta.pos = 1 + pos; + return m.apply(this, arguments); + } + } while (l > ++pos); + } + return null; + } + + + function functionWrapper(f, name) { + if (f.toString().match(SUPER_REGEXP)) { + var wrapper = function wrapper() { + var ret, meta = this.__meta || {}; + var orig = meta.superMeta; + meta.superMeta = {f: f, pos: 0, name: name}; + switch (arguments.length) { + case 0: + ret = f.call(this); + break; + case 1: + ret = f.call(this, arguments[0]); + break; + case 2: + ret = f.call(this, arguments[0], arguments[1]); + break; + + case 3: + ret = f.call(this, arguments[0], arguments[1], arguments[2]); + break; + default: + ret = f.apply(this, arguments); + } + meta.superMeta = orig; + return ret; + }; + wrapper._f = f; + return wrapper; + } else { + f._f = f; + return f; + } + } + + function defineMixinProps(child, proto) { + + var operations = proto.setters || {}, __setters = child.__setters__, __getters = child.__getters__; + for (var i in operations) { + if (!__setters.hasOwnProperty(i)) { //make sure that the setter isnt already there + __setters[i] = operations[i]; + } + } + operations = proto.getters || {}; + for (i in operations) { + if (!__getters.hasOwnProperty(i)) { //make sure that the setter isnt already there + __getters[i] = operations[i]; + } + } + for (var j in proto) { + if (j !== "getters" && j !== "setters") { + var p = proto[j]; + if ("function" === typeof p) { + if (!child.hasOwnProperty(j)) { + child[j] = functionWrapper(defaultFunction, j); + } + } else { + child[j] = p; + } + } + } + } + + function mixin() { + var args = argsToArray(arguments), l = args.length; + var child = this.prototype; + var childMeta = child.__meta, thisMeta = this.__meta, bases = child.__meta.bases, staticBases = bases.slice(), + staticSupers = thisMeta.supers || [], supers = childMeta.supers || []; + for (var i = 0; i < l; i++) { + var m = args[i], mProto = m.prototype; + var protoMeta = mProto.__meta, meta = m.__meta; + !protoMeta && (protoMeta = (mProto.__meta = {proto: mProto || {}})); + !meta && (meta = (m.__meta = {proto: m.__proto__ || {}})); + defineMixinProps(child, protoMeta.proto || {}); + defineMixinProps(this, meta.proto || {}); + //copy the bases for static, + + mixinSupers(m.prototype, supers, bases); + mixinSupers(m, staticSupers, staticBases); + } + return this; + } + + function mixinSupers(sup, arr, bases) { + var meta = sup.__meta; + !meta && (meta = (sup.__meta = {})); + var unique = sup.__meta.unique; + !unique && (meta.unique = "declare" + ++classCounter); + //check it we already have this super mixed into our prototype chain + //if true then we have already looped their supers! + if (indexOf(bases, unique) === -1) { + //add their id to our bases + bases.push(unique); + var supers = sup.__meta.supers || [], i = supers.length - 1 || 0; + while (i >= 0) { + mixinSupers(supers[i--], arr, bases); + } + arr.unshift(sup); + } + } + + function defineProps(child, proto) { + var operations = proto.setters, + __setters = child.__setters__, + __getters = child.__getters__; + if (operations) { + for (var i in operations) { + __setters[i] = operations[i]; + } + } + operations = proto.getters || {}; + if (operations) { + for (i in operations) { + __getters[i] = operations[i]; + } + } + for (i in proto) { + if (i != "getters" && i != "setters") { + var f = proto[i]; + if ("function" === typeof f) { + var meta = f.__meta || {}; + if (!meta.isConstructor) { + child[i] = functionWrapper(f, i); + } else { + child[i] = f; + } + } else { + child[i] = f; + } + } + } + + } + + function _export(obj, name) { + if (obj && name) { + obj[name] = this; + } else { + obj.exports = obj = this; + } + return this; + } + + function extend(proto) { + return declare(this, proto); + } + + function getNew(ctor) { + // create object with correct prototype using a do-nothing + // constructor + forceNew.prototype = ctor.prototype; + var t = new forceNew(); + forceNew.prototype = null; // clean up + return t; + } + + + function __declare(child, sup, proto) { + var childProto = {}, supers = []; + var unique = "declare" + ++classCounter, bases = [], staticBases = []; + var instanceSupers = [], staticSupers = []; + var meta = { + supers: instanceSupers, + unique: unique, + bases: bases, + superMeta: { + f: null, + pos: 0, + name: null + } + }; + var childMeta = { + supers: staticSupers, + unique: unique, + bases: staticBases, + isConstructor: true, + superMeta: { + f: null, + pos: 0, + name: null + } + }; + + if (isHash(sup) && !proto) { + proto = sup; + sup = Base; + } + + if ("function" === typeof sup || isArray(sup)) { + supers = isArray(sup) ? sup : [sup]; + sup = supers.shift(); + child.__meta = childMeta; + childProto = getNew(sup); + childProto.__meta = meta; + childProto.__getters__ = merge({}, childProto.__getters__ || {}); + childProto.__setters__ = merge({}, childProto.__setters__ || {}); + child.__getters__ = merge({}, child.__getters__ || {}); + child.__setters__ = merge({}, child.__setters__ || {}); + mixinSupers(sup.prototype, instanceSupers, bases); + mixinSupers(sup, staticSupers, staticBases); + } else { + child.__meta = childMeta; + childProto.__meta = meta; + childProto.__getters__ = childProto.__getters__ || {}; + childProto.__setters__ = childProto.__setters__ || {}; + child.__getters__ = child.__getters__ || {}; + child.__setters__ = child.__setters__ || {}; + } + child.prototype = childProto; + if (proto) { + var instance = meta.proto = proto.instance || {}; + var stat = childMeta.proto = proto.static || {}; + stat.init = stat.init || defaultFunction; + defineProps(childProto, instance); + defineProps(child, stat); + if (!instance.hasOwnProperty("constructor")) { + childProto.constructor = instance.constructor = functionWrapper(defaultFunction, "constructor"); + } else { + childProto.constructor = functionWrapper(instance.constructor, "constructor"); + } + } else { + meta.proto = {}; + childMeta.proto = {}; + child.init = functionWrapper(defaultFunction, "init"); + childProto.constructor = functionWrapper(defaultFunction, "constructor"); + } + if (supers.length) { + mixin.apply(child, supers); + } + if (sup) { + //do this so we mixin our super methods directly but do not ov + merge(child, merge(merge({}, sup), child)); + } + childProto._super = child._super = callSuper; + childProto._getSuper = child._getSuper = getSuper; + childProto._static = child; + } + + function declare(sup, proto) { + function declared() { + switch (arguments.length) { + case 0: + this.constructor.call(this); + break; + case 1: + this.constructor.call(this, arguments[0]); + break; + case 2: + this.constructor.call(this, arguments[0], arguments[1]); + break; + case 3: + this.constructor.call(this, arguments[0], arguments[1], arguments[2]); + break; + default: + this.constructor.apply(this, arguments); + } + } + + __declare(declared, sup, proto); + return declared.init() || declared; + } + + function singleton(sup, proto) { + var retInstance; + + function declaredSingleton() { + if (!retInstance) { + this.constructor.apply(this, arguments); + retInstance = this; + } + return retInstance; + } + + __declare(declaredSingleton, sup, proto); + return declaredSingleton.init() || declaredSingleton; + } + + Base = declare({ + instance: { + "get": getter, + "set": setter + }, + + "static": { + "get": getter, + "set": setter, + mixin: mixin, + extend: extend, + as: _export + } + }); + + declare.singleton = singleton; + return declare; + } + + if ("undefined" !== typeof exports) { + if ("undefined" !== typeof module && module.exports) { + module.exports = createDeclared(); + } + } else if ("function" === typeof define && define.amd) { + define(createDeclared); + } else { + this.declare = createDeclared(); + } +}()); + + + + +},{}],52:[function(require,module,exports){ +module.exports = require("./declare.js"); +},{"./declare.js":51}],53:[function(require,module,exports){ +(function () { + "use strict"; + /*global extender is, dateExtended*/ + + function defineExtended(extender) { + + + var merge = (function merger() { + function _merge(target, source) { + var name, s; + for (name in source) { + if (source.hasOwnProperty(name)) { + s = source[name]; + if (!(name in target) || (target[name] !== s)) { + target[name] = s; + } + } + } + return target; + } + + return function merge(obj) { + if (!obj) { + obj = {}; + } + for (var i = 1, l = arguments.length; i < l; i++) { + _merge(obj, arguments[i]); + } + return obj; // Object + }; + }()); + + function getExtended() { + + var loaded = {}; + + + //getInitial instance; + var extended = extender.define(); + extended.expose({ + register: function register(alias, extendWith) { + if (!extendWith) { + extendWith = alias; + alias = null; + } + var type = typeof extendWith; + if (alias) { + extended[alias] = extendWith; + } else if (extendWith && type === "function") { + extended.extend(extendWith); + } else if (type === "object") { + extended.expose(extendWith); + } else { + throw new TypeError("extended.register must be called with an extender function"); + } + return extended; + }, + + define: function () { + return extender.define.apply(extender, arguments); + } + }); + + return extended; + } + + function extended() { + return getExtended(); + } + + extended.define = function define() { + return extender.define.apply(extender, arguments); + }; + + return extended; + } + + if ("undefined" !== typeof exports) { + if ("undefined" !== typeof module && module.exports) { + module.exports = defineExtended(require("extender")); + + } + } else if ("function" === typeof define && define.amd) { + define(["extender"], function (extender) { + return defineExtended(extender); + }); + } else { + this.extended = defineExtended(this.extender); + } + +}).call(this); + + + + + + + +},{"extender":55}],54:[function(require,module,exports){ +(function () { + /*jshint strict:false*/ + + + /** + * + * @projectName extender + * @github http://github.com/doug-martin/extender + * @header + * [![build status](https://secure.travis-ci.org/doug-martin/extender.png)](http://travis-ci.org/doug-martin/extender) + * # Extender + * + * `extender` is a library that helps in making chainable APIs, by creating a function that accepts different values and returns an object decorated with functions based on the type. + * + * ## Why Is Extender Different? + * + * Extender is different than normal chaining because is does more than return `this`. It decorates your values in a type safe manner. + * + * For example if you return an array from a string based method then the returned value will be decorated with array methods and not the string methods. This allow you as the developer to focus on your API and not worrying about how to properly build and connect your API. + * + * + * ## Installation + * + * ``` + * npm install extender + * ``` + * + * Or [download the source](https://raw.github.com/doug-martin/extender/master/extender.js) ([minified](https://raw.github.com/doug-martin/extender/master/extender-min.js)) + * + * **Note** `extender` depends on [`declare.js`](http://doug-martin.github.com/declare.js/). + * + * ### Requirejs + * + * To use with requirejs place the `extend` source in the root scripts directory + * + * ```javascript + * + * define(["extender"], function(extender){ + * }); + * + * ``` + * + * + * ## Usage + * + * **`extender.define(tester, decorations)`** + * + * To create your own extender call the `extender.define` function. + * + * This function accepts an optional tester which is used to determine a value should be decorated with the specified `decorations` + * + * ```javascript + * function isString(obj) { + * return !isUndefinedOrNull(obj) && (typeof obj === "string" || obj instanceof String); + * } + * + * + * var myExtender = extender.define(isString, { + * multiply: function (str, times) { + * var ret = str; + * for (var i = 1; i < times; i++) { + * ret += str; + * } + * return ret; + * }, + * toArray: function (str, delim) { + * delim = delim || ""; + * return str.split(delim); + * } + * }); + * + * myExtender("hello").multiply(2).value(); //hellohello + * + * ``` + * + * If you do not specify a tester function and just pass in an object of `functions` then all values passed in will be decorated with methods. + * + * ```javascript + * + * function isUndefined(obj) { + * var undef; + * return obj === undef; + * } + * + * function isUndefinedOrNull(obj) { + * var undef; + * return obj === undef || obj === null; + * } + * + * function isArray(obj) { + * return Object.prototype.toString.call(obj) === "[object Array]"; + * } + * + * function isBoolean(obj) { + * var undef, type = typeof obj; + * return !isUndefinedOrNull(obj) && type === "boolean" || type === "Boolean"; + * } + * + * function isString(obj) { + * return !isUndefinedOrNull(obj) && (typeof obj === "string" || obj instanceof String); + * } + * + * var myExtender = extender.define({ + * isUndefined : isUndefined, + * isUndefinedOrNull : isUndefinedOrNull, + * isArray : isArray, + * isBoolean : isBoolean, + * isString : isString + * }); + * + * ``` + * + * To use + * + * ``` + * var undef; + * myExtender("hello").isUndefined().value(); //false + * myExtender(undef).isUndefined().value(); //true + * ``` + * + * You can also chain extenders so that they accept multiple types and decorates accordingly. + * + * ```javascript + * myExtender + * .define(isArray, { + * pluck: function (arr, m) { + * var ret = []; + * for (var i = 0, l = arr.length; i < l; i++) { + * ret.push(arr[i][m]); + * } + * return ret; + * } + * }) + * .define(isBoolean, { + * invert: function (val) { + * return !val; + * } + * }); + * + * myExtender([{a: "a"},{a: "b"},{a: "c"}]).pluck("a").value(); //["a", "b", "c"] + * myExtender("I love javascript!").toArray(/\s+/).pluck("0"); //["I", "l", "j"] + * + * ``` + * + * Notice that we reuse the same extender as defined above. + * + * **Return Values** + * + * When creating an extender if you return a value from one of the decoration functions then that value will also be decorated. If you do not return any values then the extender will be returned. + * + * **Default decoration methods** + * + * By default every value passed into an extender is decorated with the following methods. + * + * * `value` : The value this extender represents. + * * `eq(otherValue)` : Tests strict equality of the currently represented value to the `otherValue` + * * `neq(oterValue)` : Tests strict inequality of the currently represented value. + * * `print` : logs the current value to the console. + * + * **Extender initialization** + * + * When creating an extender you can also specify a constructor which will be invoked with the current value. + * + * ```javascript + * myExtender.define(isString, { + * constructor : function(val){ + * //set our value to the string trimmed + * this._value = val.trimRight().trimLeft(); + * } + * }); + * ``` + * + * **`noWrap`** + * + * `extender` also allows you to specify methods that should not have the value wrapped providing a cleaner exit function other than `value()`. + * + * For example suppose you have an API that allows you to build a validator, rather than forcing the user to invoke the `value` method you could add a method called `validator` which makes more syntactic sense. + * + * ``` + * + * var myValidator = extender.define({ + * //chainable validation methods + * //... + * //end chainable validation methods + * + * noWrap : { + * validator : function(){ + * //return your validator + * } + * } + * }); + * + * myValidator().isNotNull().isEmailAddress().validator(); //now you dont need to call .value() + * + * + * ``` + * **`extender.extend(extendr)`** + * + * You may also compose extenders through the use of `extender.extend(extender)`, which will return an entirely new extender that is the composition of extenders. + * + * Suppose you have the following two extenders. + * + * ```javascript + * var myExtender = extender + * .define({ + * isFunction: is.function, + * isNumber: is.number, + * isString: is.string, + * isDate: is.date, + * isArray: is.array, + * isBoolean: is.boolean, + * isUndefined: is.undefined, + * isDefined: is.defined, + * isUndefinedOrNull: is.undefinedOrNull, + * isNull: is.null, + * isArguments: is.arguments, + * isInstanceOf: is.instanceOf, + * isRegExp: is.regExp + * }); + * var myExtender2 = extender.define(is.array, { + * pluck: function (arr, m) { + * var ret = []; + * for (var i = 0, l = arr.length; i < l; i++) { + * ret.push(arr[i][m]); + * } + * return ret; + * }, + * + * noWrap: { + * pluckPlain: function (arr, m) { + * var ret = []; + * for (var i = 0, l = arr.length; i < l; i++) { + * ret.push(arr[i][m]); + * } + * return ret; + * } + * } + * }); + * + * + * ``` + * + * And you do not want to alter either of them but instead what to create a third that is the union of the two. + * + * + * ```javascript + * var composed = extender.extend(myExtender).extend(myExtender2); + * ``` + * So now you can use the new extender with the joined functionality if `myExtender` and `myExtender2`. + * + * ```javascript + * var extended = composed([ + * {a: "a"}, + * {a: "b"}, + * {a: "c"} + * ]); + * extended.isArray().value(); //true + * extended.pluck("a").value(); // ["a", "b", "c"]); + * + * ``` + * + * **Note** `myExtender` and `myExtender2` will **NOT** be altered. + * + * **`extender.expose(methods)`** + * + * The `expose` method allows you to add methods to your extender that are not wrapped or automatically chained by exposing them on the extender directly. + * + * ``` + * var isMethods = { + * isFunction: is.function, + * isNumber: is.number, + * isString: is.string, + * isDate: is.date, + * isArray: is.array, + * isBoolean: is.boolean, + * isUndefined: is.undefined, + * isDefined: is.defined, + * isUndefinedOrNull: is.undefinedOrNull, + * isNull: is.null, + * isArguments: is.arguments, + * isInstanceOf: is.instanceOf, + * isRegExp: is.regExp + * }; + * + * var myExtender = extender.define(isMethods).expose(isMethods); + * + * myExtender.isArray([]); //true + * myExtender([]).isArray([]).value(); //true + * + * ``` + * + * + * **Using `instanceof`** + * + * When using extenders you can test if a value is an `instanceof` of an extender by using the instanceof operator. + * + * ```javascript + * var str = myExtender("hello"); + * + * str instanceof myExtender; //true + * ``` + * + * ## Examples + * + * To see more examples click [here](https://github.com/doug-martin/extender/tree/master/examples) + */ + function defineExtender(declare) { + + + var slice = Array.prototype.slice, undef; + + function indexOf(arr, item) { + if (arr && arr.length) { + for (var i = 0, l = arr.length; i < l; i++) { + if (arr[i] === item) { + return i; + } + } + } + return -1; + } + + function isArray(obj) { + return Object.prototype.toString.call(obj) === "[object Array]"; + } + + var merge = (function merger() { + function _merge(target, source, exclude) { + var name, s; + for (name in source) { + if (source.hasOwnProperty(name) && indexOf(exclude, name) === -1) { + s = source[name]; + if (!(name in target) || (target[name] !== s)) { + target[name] = s; + } + } + } + return target; + } + + return function merge(obj) { + if (!obj) { + obj = {}; + } + var l = arguments.length; + var exclude = arguments[arguments.length - 1]; + if (isArray(exclude)) { + l--; + } else { + exclude = []; + } + for (var i = 1; i < l; i++) { + _merge(obj, arguments[i], exclude); + } + return obj; // Object + }; + }()); + + + function extender(supers) { + supers = supers || []; + var Base = declare({ + instance: { + constructor: function (value) { + this._value = value; + }, + + value: function () { + return this._value; + }, + + eq: function eq(val) { + return this["__extender__"](this._value === val); + }, + + neq: function neq(other) { + return this["__extender__"](this._value !== other); + }, + print: function () { + console.log(this._value); + return this; + } + } + }), defined = []; + + function addMethod(proto, name, func) { + if ("function" !== typeof func) { + throw new TypeError("when extending type you must provide a function"); + } + var extendedMethod; + if (name === "constructor") { + extendedMethod = function () { + this._super(arguments); + func.apply(this, arguments); + }; + } else { + extendedMethod = function extendedMethod() { + var args = slice.call(arguments); + args.unshift(this._value); + var ret = func.apply(this, args); + return ret !== undef ? this["__extender__"](ret) : this; + }; + } + proto[name] = extendedMethod; + } + + function addNoWrapMethod(proto, name, func) { + if ("function" !== typeof func) { + throw new TypeError("when extending type you must provide a function"); + } + var extendedMethod; + if (name === "constructor") { + extendedMethod = function () { + this._super(arguments); + func.apply(this, arguments); + }; + } else { + extendedMethod = function extendedMethod() { + var args = slice.call(arguments); + args.unshift(this._value); + return func.apply(this, args); + }; + } + proto[name] = extendedMethod; + } + + function decorateProto(proto, decoration, nowrap) { + for (var i in decoration) { + if (decoration.hasOwnProperty(i)) { + if (i !== "getters" && i !== "setters") { + if (i === "noWrap") { + decorateProto(proto, decoration[i], true); + } else if (nowrap) { + addNoWrapMethod(proto, i, decoration[i]); + } else { + addMethod(proto, i, decoration[i]); + } + } else { + proto[i] = decoration[i]; + } + } + } + } + + function _extender(obj) { + var ret = obj, i, l; + if (!(obj instanceof Base)) { + var OurBase = Base; + for (i = 0, l = defined.length; i < l; i++) { + var definer = defined[i]; + if (definer[0](obj)) { + OurBase = OurBase.extend({instance: definer[1]}); + } + } + ret = new OurBase(obj); + ret["__extender__"] = _extender; + } + return ret; + } + + function always() { + return true; + } + + function define(tester, decorate) { + if (arguments.length) { + if (typeof tester === "object") { + decorate = tester; + tester = always; + } + decorate = decorate || {}; + var proto = {}; + decorateProto(proto, decorate); + //handle browsers like which skip over the constructor while looping + if (!proto.hasOwnProperty("constructor")) { + if (decorate.hasOwnProperty("constructor")) { + addMethod(proto, "constructor", decorate.constructor); + } else { + proto.constructor = function () { + this._super(arguments); + }; + } + } + defined.push([tester, proto]); + } + return _extender; + } + + function extend(supr) { + if (supr && supr.hasOwnProperty("__defined__")) { + _extender["__defined__"] = defined = defined.concat(supr["__defined__"]); + } + merge(_extender, supr, ["define", "extend", "expose", "__defined__"]); + return _extender; + } + + _extender.define = define; + _extender.extend = extend; + _extender.expose = function expose() { + var methods; + for (var i = 0, l = arguments.length; i < l; i++) { + methods = arguments[i]; + if (typeof methods === "object") { + merge(_extender, methods, ["define", "extend", "expose", "__defined__"]); + } + } + return _extender; + }; + _extender["__defined__"] = defined; + + + return _extender; + } + + return { + define: function () { + return extender().define.apply(extender, arguments); + }, + + extend: function (supr) { + return extender().define().extend(supr); + } + }; + + } + + if ("undefined" !== typeof exports) { + if ("undefined" !== typeof module && module.exports) { + module.exports = defineExtender(require("declare.js")); + + } + } else if ("function" === typeof define && define.amd) { + define(["declare"], function (declare) { + return defineExtender(declare); + }); + } else { + this.extender = defineExtender(this.declare); + } + +}).call(this); +},{"declare.js":52}],55:[function(require,module,exports){ +module.exports = require("./extender.js"); +},{"./extender.js":54}],56:[function(require,module,exports){ +(function () { + "use strict"; + + function defineFunction(extended, is, args) { + + var isArray = is.isArray, + isObject = is.isObject, + isString = is.isString, + isFunction = is.isFunction, + argsToArray = args.argsToArray; + + function spreadArgs(f, args, scope) { + var ret; + switch ((args || []).length) { + case 0: + ret = f.call(scope); + break; + case 1: + ret = f.call(scope, args[0]); + break; + case 2: + ret = f.call(scope, args[0], args[1]); + break; + case 3: + ret = f.call(scope, args[0], args[1], args[2]); + break; + default: + ret = f.apply(scope, args); + } + return ret; + } + + function hitch(scope, method, args) { + args = argsToArray(arguments, 2); + if ((isString(method) && !(method in scope))) { + throw new Error(method + " property not defined in scope"); + } else if (!isString(method) && !isFunction(method)) { + throw new Error(method + " is not a function"); + } + if (isString(method)) { + return function () { + var func = scope[method]; + if (isFunction(func)) { + var scopeArgs = args.concat(argsToArray(arguments)); + return func.apply(scope, scopeArgs); + } else { + return func; + } + }; + } else { + if (args.length) { + return function () { + var scopeArgs = args.concat(argsToArray(arguments)); + return spreadArgs(method, arguments, scope); + }; + } else { + + return function () { + return spreadArgs(method, arguments, scope); + }; + } + } + } + + + function applyFirst(method, args) { + args = argsToArray(arguments, 1); + if (!isString(method) && !isFunction(method)) { + throw new Error(method + " must be the name of a property or function to execute"); + } + if (isString(method)) { + return function () { + var scopeArgs = argsToArray(arguments), scope = scopeArgs.shift(); + var func = scope[method]; + if (isFunction(func)) { + scopeArgs = args.concat(scopeArgs); + return func.apply(scope, scopeArgs); + } else { + return func; + } + }; + } else { + return function () { + var scopeArgs = argsToArray(arguments), scope = scopeArgs.shift(); + scopeArgs = args.concat(scopeArgs); + return method.apply(scope, scopeArgs); + }; + } + } + + + function hitchIgnore(scope, method, args) { + args = argsToArray(arguments, 2); + if ((isString(method) && !(method in scope))) { + throw new Error(method + " property not defined in scope"); + } else if (!isString(method) && !isFunction(method)) { + throw new Error(method + " is not a function"); + } + if (isString(method)) { + return function () { + var func = scope[method]; + if (isFunction(func)) { + return func.apply(scope, args); + } else { + return func; + } + }; + } else { + return function () { + return method.apply(scope, args); + }; + } + } + + + function hitchAll(scope) { + var funcs = argsToArray(arguments, 1); + if (!isObject(scope) && !isFunction(scope)) { + throw new TypeError("scope must be an object"); + } + if (funcs.length === 1 && isArray(funcs[0])) { + funcs = funcs[0]; + } + if (!funcs.length) { + funcs = []; + for (var k in scope) { + if (scope.hasOwnProperty(k) && isFunction(scope[k])) { + funcs.push(k); + } + } + } + for (var i = 0, l = funcs.length; i < l; i++) { + scope[funcs[i]] = hitch(scope, scope[funcs[i]]); + } + return scope; + } + + + function partial(method, args) { + args = argsToArray(arguments, 1); + if (!isString(method) && !isFunction(method)) { + throw new Error(method + " must be the name of a property or function to execute"); + } + if (isString(method)) { + return function () { + var func = this[method]; + if (isFunction(func)) { + var scopeArgs = args.concat(argsToArray(arguments)); + return func.apply(this, scopeArgs); + } else { + return func; + } + }; + } else { + return function () { + var scopeArgs = args.concat(argsToArray(arguments)); + return method.apply(this, scopeArgs); + }; + } + } + + function curryFunc(f, execute) { + return function () { + var args = argsToArray(arguments); + return execute ? f.apply(this, arguments) : function () { + return f.apply(this, args.concat(argsToArray(arguments))); + }; + }; + } + + + function curry(depth, cb, scope) { + var f; + if (scope) { + f = hitch(scope, cb); + } else { + f = cb; + } + if (depth) { + var len = depth - 1; + for (var i = len; i >= 0; i--) { + f = curryFunc(f, i === len); + } + } + return f; + } + + return extended + .define(isObject, { + bind: hitch, + bindAll: hitchAll, + bindIgnore: hitchIgnore, + curry: function (scope, depth, fn) { + return curry(depth, fn, scope); + } + }) + .define(isFunction, { + bind: function (fn, obj) { + return hitch.apply(this, [obj, fn].concat(argsToArray(arguments, 2))); + }, + bindIgnore: function (fn, obj) { + return hitchIgnore.apply(this, [obj, fn].concat(argsToArray(arguments, 2))); + }, + partial: partial, + applyFirst: applyFirst, + curry: function (fn, num, scope) { + return curry(num, fn, scope); + }, + noWrap: { + f: function () { + return this.value(); + } + } + }) + .define(isString, { + bind: function (str, scope) { + return hitch(scope, str); + }, + bindIgnore: function (str, scope) { + return hitchIgnore(scope, str); + }, + partial: partial, + applyFirst: applyFirst, + curry: function (fn, depth, scope) { + return curry(depth, fn, scope); + } + }) + .expose({ + bind: hitch, + bindAll: hitchAll, + bindIgnore: hitchIgnore, + partial: partial, + applyFirst: applyFirst, + curry: curry + }); - /** - * @projectName declare - * @github http://github.com/doug-martin/declare.js - * @header - * - * Declare is a library designed to allow writing object oriented code the same way in both the browser and node.js. - * - * ##Installation - * - * `npm install declare.js` - * - * Or [download the source](https://raw.github.com/doug-martin/declare.js/master/declare.js) ([minified](https://raw.github.com/doug-martin/declare.js/master/declare-min.js)) - * - * ###Requirejs - * - * To use with requirejs place the `declare` source in the root scripts directory - * - * ``` - * - * define(["declare"], function(declare){ - * return declare({ - * instance : { - * hello : function(){ - * return "world"; - * } - * } - * }); - * }); - * - * ``` - * - * - * ##Usage - * - * declare.js provides - * - * Class methods - * - * * `as(module | object, name)` : exports the object to module or the object with the name - * * `mixin(mixin)` : mixes in an object but does not inherit directly from the object. **Note** this does not return a new class but changes the original class. - * * `extend(proto)` : extend a class with the given properties. A shortcut to `declare(Super, {})`; - * - * Instance methods - * - * * `_super(arguments)`: calls the super of the current method, you can pass in either the argments object or an array with arguments you want passed to super - * * `_getSuper()`: returns a this methods direct super. - * * `_static` : use to reference class properties and methods. - * * `get(prop)` : gets a property invoking the getter if it exists otherwise it just returns the named property on the object. - * * `set(prop, val)` : sets a property invoking the setter if it exists otherwise it just sets the named property on the object. - * - * - * ###Declaring a new Class - * - * Creating a new class with declare is easy! - * - * ``` - * - * var Mammal = declare({ - * //define your instance methods and properties - * instance : { - * - * //will be called whenever a new instance is created - * constructor: function(options) { - * options = options || {}; - * this._super(arguments); - * this._type = options.type || "mammal"; - * }, - * - * speak : function() { - * return "A mammal of type " + this._type + " sounds like"; - * }, - * - * //Define your getters - * getters : { - * - * //can be accessed by using the get method. (mammal.get("type")) - * type : function() { - * return this._type; - * } - * }, - * - * //Define your setters - * setters : { - * - * //can be accessed by using the set method. (mammal.set("type", "mammalType")) - * type : function(t) { - * this._type = t; - * } - * } - * }, - * - * //Define your static methods - * static : { + } + + if ("undefined" !== typeof exports) { + if ("undefined" !== typeof module && module.exports) { + module.exports = defineFunction(require("extended"), require("is-extended"), require("arguments-extended")); + + } + } else if ("function" === typeof define && define.amd) { + define(["extended", "is-extended", "arguments-extended"], function (extended, is, args) { + return defineFunction(extended, is, args); + }); + } else { + this.functionExtended = defineFunction(this.extended, this.isExtended, this.argumentsExtended); + } + +}).call(this); + + + + + + + +},{"arguments-extended":57,"extended":58,"is-extended":63}],57:[function(require,module,exports){ +(function () { + "use strict"; + + function defineArgumentsExtended(extended, is) { + + var pSlice = Array.prototype.slice, + isArguments = is.isArguments; + + function argsToArray(args, slice) { + var i = -1, j = 0, l = args.length, ret = []; + slice = slice || 0; + i += slice; + while (++i < l) { + ret[j++] = args[i]; + } + return ret; + } + + + return extended + .define(isArguments, { + toArray: argsToArray + }) + .expose({ + argsToArray: argsToArray + }); + } + + if ("undefined" !== typeof exports) { + if ("undefined" !== typeof module && module.exports) { + module.exports = defineArgumentsExtended(require("extended"), require("is-extended")); + + } + } else if ("function" === typeof define && define.amd) { + define(["extended", "is-extended"], function (extended, is) { + return defineArgumentsExtended(extended, is); + }); + } else { + this.argumentsExtended = defineArgumentsExtended(this.extended, this.isExtended); + } + +}).call(this); + + +},{"extended":58,"is-extended":63}],58:[function(require,module,exports){ +(function () { + "use strict"; + /*global extender is, dateExtended*/ + + function defineExtended(extender) { + + + var merge = (function merger() { + function _merge(target, source) { + var name, s; + for (name in source) { + if (source.hasOwnProperty(name)) { + s = source[name]; + if (!(name in target) || (target[name] !== s)) { + target[name] = s; + } + } + } + return target; + } + + return function merge(obj) { + if (!obj) { + obj = {}; + } + for (var i = 1, l = arguments.length; i < l; i++) { + _merge(obj, arguments[i]); + } + return obj; // Object + }; + }()); + + function getExtended() { + + var loaded = {}; + + + //getInitial instance; + var extended = extender.define(); + extended.expose({ + register: function register(alias, extendWith) { + if (!extendWith) { + extendWith = alias; + alias = null; + } + var type = typeof extendWith; + if (alias) { + extended[alias] = extendWith; + } else if (extendWith && type === "function") { + extended.extend(extendWith); + } else if (type === "object") { + extended.expose(extendWith); + } else { + throw new TypeError("extended.register must be called with an extender function"); + } + return extended; + }, + + define: function () { + return extender.define.apply(extender, arguments); + } + }); + + return extended; + } + + function extended() { + return getExtended(); + } + + extended.define = function define() { + return extender.define.apply(extender, arguments); + }; + + return extended; + } + + if ("undefined" !== typeof exports) { + if ("undefined" !== typeof module && module.exports) { + module.exports = defineExtended(require("extender")); + + } + } else if ("function" === typeof define && define.amd) { + define(["extender"], function (extender) { + return defineExtended(extender); + }); + } else { + this.extended = defineExtended(this.extender); + } + +}).call(this); + + + + + + + +},{"extender":60}],59:[function(require,module,exports){ +(function () { + /*jshint strict:false*/ + + + /** * - * //Mammal.soundOff(); //"Im a mammal!!" - * soundOff : function() { - * return "Im a mammal!!"; - * } - * } - * }); + * @projectName extender + * @github http://github.com/doug-martin/extender + * @header + * [![build status](https://secure.travis-ci.org/doug-martin/extender.png)](http://travis-ci.org/doug-martin/extender) + * # Extender * + * `extender` is a library that helps in making chainable APIs, by creating a function that accepts different values and returns an object decorated with functions based on the type. * - * ``` + * ## Why Is Extender Different? * - * You can use Mammal just like you would any other class. + * Extender is different than normal chaining because is does more than return `this`. It decorates your values in a type safe manner. * - * ``` - * Mammal.soundOff("Im a mammal!!"); + * For example if you return an array from a string based method then the returned value will be decorated with array methods and not the string methods. This allow you as the developer to focus on your API and not worrying about how to properly build and connect your API. * - * var myMammal = new Mammal({type : "mymammal"}); - * myMammal.speak(); // "A mammal of type mymammal sounds like" - * myMammal.get("type"); //"mymammal" - * myMammal.set("type", "mammal"); - * myMammal.get("type"); //"mammal" * + * ## Installation * * ``` - * - * ###Extending a class - * - * If you want to just extend a single class use the .extend method. - * + * npm install extender * ``` * - * var Wolf = Mammal.extend({ - * - * //define your instance method - * instance: { - * - * //You can override super constructors just be sure to call `_super` - * constructor: function(options) { - * options = options || {}; - * this._super(arguments); //call our super constructor. - * this._sound = "growl"; - * this._color = options.color || "grey"; - * }, - * - * //override Mammals `speak` method by appending our own data to it. - * speak : function() { - * return this._super(arguments) + " a " + this._sound; - * }, - * - * //add new getters for sound and color - * getters : { - * - * //new Wolf().get("type") - * //notice color is read only as we did not define a setter - * color : function() { - * return this._color; - * }, - * - * //new Wolf().get("sound") - * sound : function() { - * return this._sound; - * } - * }, + * Or [download the source](https://raw.github.com/doug-martin/extender/master/extender.js) ([minified](https://raw.github.com/doug-martin/extender/master/extender-min.js)) * - * setters : { + * **Note** `extender` depends on [`declare.js`](http://doug-martin.github.com/declare.js/). * - * //new Wolf().set("sound", "howl") - * sound : function(s) { - * this._sound = s; - * } - * } + * ### Requirejs * - * }, + * To use with requirejs place the `extend` source in the root scripts directory * - * static : { + * ```javascript * - * //You can override super static methods also! And you can still use _super - * soundOff : function() { - * //You can even call super in your statics!!! - * //should return "I'm a mammal!! that growls" - * return this._super(arguments) + " that growls"; - * } - * } + * define(["extender"], function(extender){ * }); * - * Wolf.soundOff(); //Im a mammal!! that growls - * - * var myWolf = new Wolf(); - * myWolf instanceof Mammal //true - * myWolf instanceof Wolf //true - * - * ``` - * - * You can also extend a class by using the declare method and just pass in the super class. - * * ``` - * //Typical hierarchical inheritance - * // Mammal->Wolf->Dog - * var Dog = declare(Wolf, { - * instance: { - * constructor: function(options) { - * options = options || {}; - * this._super(arguments); - * //override Wolfs initialization of sound to woof. - * this._sound = "woof"; - * - * }, - * - * speak : function() { - * //Should return "A mammal of type mammal sounds like a growl thats domesticated" - * return this._super(arguments) + " thats domesticated"; - * } - * }, - * - * static : { - * soundOff : function() { - * //should return "I'm a mammal!! that growls but now barks" - * return this._super(arguments) + " but now barks"; - * } - * } - * }); - * - * Dog.soundOff(); //Im a mammal!! that growls but now barks - * - * var myDog = new Dog(); - * myDog instanceof Mammal //true - * myDog instanceof Wolf //true - * myDog instanceof Dog //true * * - * //Notice you still get the extend method. - * - * // Mammal->Wolf->Dog->Breed - * var Breed = Dog.extend({ - * instance: { + * ## Usage * - * //initialize outside of constructor - * _pitch : "high", + * **`extender.define(tester, decorations)`** * - * constructor: function(options) { - * options = options || {}; - * this._super(arguments); - * this.breed = options.breed || "lab"; - * }, + * To create your own extender call the `extender.define` function. * - * speak : function() { - * //Should return "A mammal of type mammal sounds like a - * //growl thats domesticated with a high pitch!" - * return this._super(arguments) + " with a " + this._pitch + " pitch!"; - * }, + * This function accepts an optional tester which is used to determine a value should be decorated with the specified `decorations` * - * getters : { - * pitch : function() { - * return this._pitch; - * } - * } - * }, + * ```javascript + * function isString(obj) { + * return !isUndefinedOrNull(obj) && (typeof obj === "string" || obj instanceof String); + * } * - * static : { - * soundOff : function() { - * //should return "I'M A MAMMAL!! THAT GROWLS BUT NOW BARKS!" - * return this._super(arguments).toUpperCase() + "!"; - * } - * } - * }); * + * var myExtender = extender.define(isString, { + * multiply: function (str, times) { + * var ret = str; + * for (var i = 1; i < times; i++) { + * ret += str; + * } + * return ret; + * }, + * toArray: function (str, delim) { + * delim = delim || ""; + * return str.split(delim); + * } + * }); * - * Breed.soundOff()//"IM A MAMMAL!! THAT GROWLS BUT NOW BARKS!" + * myExtender("hello").multiply(2).value(); //hellohello * - * var myBreed = new Breed({color : "gold", type : "lab"}), - * myBreed instanceof Dog //true - * myBreed instanceof Wolf //true - * myBreed instanceof Mammal //true - * myBreed.speak() //"A mammal of type lab sounds like a woof thats domesticated with a high pitch!" - * myBreed.get("type") //"lab" - * myBreed.get("color") //"gold" - * myBreed.get("sound")" //"woof" * ``` * - * ###Multiple Inheritance / Mixins - * - * declare also allows the use of multiple super classes. - * This is useful if you have generic classes that provide functionality but shouldnt be used on their own. - * - * Lets declare a mixin that allows us to watch for property changes. + * If you do not specify a tester function and just pass in an object of `functions` then all values passed in will be decorated with methods. * - * ``` - * //Notice that we set up the functions outside of declare because we can reuse them + * ```javascript * - * function _set(prop, val) { - * //get the old value - * var oldVal = this.get(prop); - * //call super to actually set the property - * var ret = this._super(arguments); - * //call our handlers - * this.__callHandlers(prop, oldVal, val); - * return ret; + * function isUndefined(obj) { + * var undef; + * return obj === undef; * } * - * function _callHandlers(prop, oldVal, newVal) { - * //get our handlers for the property - * var handlers = this.__watchers[prop], l; - * //if the handlers exist and their length does not equal 0 then we call loop through them - * if (handlers && (l = handlers.length) !== 0) { - * for (var i = 0; i < l; i++) { - * //call the handler - * handlers[i].call(null, prop, oldVal, newVal); - * } - * } + * function isUndefinedOrNull(obj) { + * var undef; + * return obj === undef || obj === null; * } * - * - * //the watch function - * function _watch(prop, handler) { - * if ("function" !== typeof handler) { - * //if its not a function then its an invalid handler - * throw new TypeError("Invalid handler."); - * } - * if (!this.__watchers[prop]) { - * //create the watchers if it doesnt exist - * this.__watchers[prop] = [handler]; - * } else { - * //otherwise just add it to the handlers array - * this.__watchers[prop].push(handler); - * } + * function isArray(obj) { + * return Object.prototype.toString.call(obj) === "[object Array]"; * } * - * function _unwatch(prop, handler) { - * if ("function" !== typeof handler) { - * throw new TypeError("Invalid handler."); - * } - * var handlers = this.__watchers[prop], index; - * if (handlers && (index = handlers.indexOf(handler)) !== -1) { - * //remove the handler if it is found - * handlers.splice(index, 1); - * } + * function isBoolean(obj) { + * var undef, type = typeof obj; + * return !isUndefinedOrNull(obj) && type === "boolean" || type === "Boolean"; * } * - * declare({ - * instance:{ - * constructor:function () { - * this._super(arguments); - * //set up our watchers - * this.__watchers = {}; - * }, + * function isString(obj) { + * return !isUndefinedOrNull(obj) && (typeof obj === "string" || obj instanceof String); + * } * - * //override the default set function so we can watch values - * "set":_set, - * //set up our callhandlers function - * __callHandlers:_callHandlers, - * //add the watch function - * watch:_watch, - * //add the unwatch function - * unwatch:_unwatch - * }, + * var myExtender = extender.define({ + * isUndefined : isUndefined, + * isUndefinedOrNull : isUndefinedOrNull, + * isArray : isArray, + * isBoolean : isBoolean, + * isString : isString + * }); * - * "static":{ + * ``` * - * init:function () { - * this._super(arguments); - * this.__watchers = {}; - * }, - * //override the default set function so we can watch values - * "set":_set, - * //set our callHandlers function - * __callHandlers:_callHandlers, - * //add the watch - * watch:_watch, - * //add the unwatch function - * unwatch:_unwatch - * } - * }) + * To use * * ``` + * var undef; + * myExtender("hello").isUndefined().value(); //false + * myExtender(undef).isUndefined().value(); //true + * ``` * - * Now lets use the mixin + * You can also chain extenders so that they accept multiple types and decorates accordingly. + * + * ```javascript + * myExtender + * .define(isArray, { + * pluck: function (arr, m) { + * var ret = []; + * for (var i = 0, l = arr.length; i < l; i++) { + * ret.push(arr[i][m]); + * } + * return ret; + * } + * }) + * .define(isBoolean, { + * invert: function (val) { + * return !val; + * } + * }); + * + * myExtender([{a: "a"},{a: "b"},{a: "c"}]).pluck("a").value(); //["a", "b", "c"] + * myExtender("I love javascript!").toArray(/\s+/).pluck("0"); //["I", "l", "j"] * * ``` - * var WatchDog = declare([Dog, WatchMixin]); * - * var watchDog = new WatchDog(); - * //create our handler - * function watch(id, oldVal, newVal) { - * console.log("watchdog's %s was %s, now %s", id, oldVal, newVal); - * } + * Notice that we reuse the same extender as defined above. * - * //watch for property changes - * watchDog.watch("type", watch); - * watchDog.watch("color", watch); - * watchDog.watch("sound", watch); + * **Return Values** * - * //now set the properties each handler will be called - * watchDog.set("type", "newDog"); - * watchDog.set("color", "newColor"); - * watchDog.set("sound", "newSound"); + * When creating an extender if you return a value from one of the decoration functions then that value will also be decorated. If you do not return any values then the extender will be returned. * + * **Default decoration methods** * - * //unwatch the property changes - * watchDog.unwatch("type", watch); - * watchDog.unwatch("color", watch); - * watchDog.unwatch("sound", watch); + * By default every value passed into an extender is decorated with the following methods. * - * //no handlers will be called this time - * watchDog.set("type", "newDog"); - * watchDog.set("color", "newColor"); - * watchDog.set("sound", "newSound"); + * * `value` : The value this extender represents. + * * `eq(otherValue)` : Tests strict equality of the currently represented value to the `otherValue` + * * `neq(oterValue)` : Tests strict inequality of the currently represented value. + * * `print` : logs the current value to the console. + * + * **Extender initialization** * + * When creating an extender you can also specify a constructor which will be invoked with the current value. * + * ```javascript + * myExtender.define(isString, { + * constructor : function(val){ + * //set our value to the string trimmed + * this._value = val.trimRight().trimLeft(); + * } + * }); * ``` * - * ###Accessing static methods and properties witin an instance. + * **`noWrap`** * - * To access static properties on an instance use the `_static` property which is a reference to your constructor. + * `extender` also allows you to specify methods that should not have the value wrapped providing a cleaner exit function other than `value()`. * - * For example if your in your constructor and you want to have configurable default values. + * For example suppose you have an API that allows you to build a validator, rather than forcing the user to invoke the `value` method you could add a method called `validator` which makes more syntactic sense. * * ``` - * consturctor : function constructor(opts){ - * this.opts = opts || {}; - * this._type = opts.type || this._static.DEFAULT_TYPE; - * } + * + * var myValidator = extender.define({ + * //chainable validation methods + * //... + * //end chainable validation methods + * + * noWrap : { + * validator : function(){ + * //return your validator + * } + * } + * }); + * + * myValidator().isNotNull().isEmailAddress().validator(); //now you dont need to call .value() + * + * * ``` + * **`extender.extend(extendr)`** * + * You may also compose extenders through the use of `extender.extend(extender)`, which will return an entirely new extender that is the composition of extenders. * + * Suppose you have the following two extenders. * - * ###Creating a new instance of within an instance. + * ```javascript + * var myExtender = extender + * .define({ + * isFunction: is.function, + * isNumber: is.number, + * isString: is.string, + * isDate: is.date, + * isArray: is.array, + * isBoolean: is.boolean, + * isUndefined: is.undefined, + * isDefined: is.defined, + * isUndefinedOrNull: is.undefinedOrNull, + * isNull: is.null, + * isArguments: is.arguments, + * isInstanceOf: is.instanceOf, + * isRegExp: is.regExp + * }); + * var myExtender2 = extender.define(is.array, { + * pluck: function (arr, m) { + * var ret = []; + * for (var i = 0, l = arr.length; i < l; i++) { + * ret.push(arr[i][m]); + * } + * return ret; + * }, * - * Often times you want to create a new instance of an object within an instance. If your subclassed however you cannot return a new instance of the parent class as it will not be the right sub class. `declare` provides a way around this by setting the `_static` property on each isntance of the class. + * noWrap: { + * pluckPlain: function (arr, m) { + * var ret = []; + * for (var i = 0, l = arr.length; i < l; i++) { + * ret.push(arr[i][m]); + * } + * return ret; + * } + * } + * }); * - * Lets add a reproduce method `Mammal` * * ``` - * reproduce : function(options){ - * return new this._static(options); - * } - * ``` * - * Now in each subclass you can call reproduce and get the proper type. + * And you do not want to alter either of them but instead what to create a third that is the union of the two. * + * + * ```javascript + * var composed = extender.extend(myExtender).extend(myExtender2); * ``` - * var myDog = new Dog(); - * var myDogsChild = myDog.reproduce(); + * So now you can use the new extender with the joined functionality if `myExtender` and `myExtender2`. + * + * ```javascript + * var extended = composed([ + * {a: "a"}, + * {a: "b"}, + * {a: "c"} + * ]); + * extended.isArray().value(); //true + * extended.pluck("a").value(); // ["a", "b", "c"]); * - * myDogsChild instanceof Dog; //true * ``` * - * ###Using the `as` + * **Note** `myExtender` and `myExtender2` will **NOT** be altered. * - * `declare` also provides an `as` method which allows you to add your class to an object or if your using node.js you can pass in `module` and the class will be exported as the module. + * **`extender.expose(methods)`** + * + * The `expose` method allows you to add methods to your extender that are not wrapped or automatically chained by exposing them on the extender directly. * * ``` - * var animals = {}; + * var isMethods = { + * isFunction: is.function, + * isNumber: is.number, + * isString: is.string, + * isDate: is.date, + * isArray: is.array, + * isBoolean: is.boolean, + * isUndefined: is.undefined, + * isDefined: is.defined, + * isUndefinedOrNull: is.undefinedOrNull, + * isNull: is.null, + * isArguments: is.arguments, + * isInstanceOf: is.instanceOf, + * isRegExp: is.regExp + * }; * - * Mammal.as(animals, "Dog"); - * Wolf.as(animals, "Wolf"); - * Dog.as(animals, "Dog"); - * Breed.as(animals, "Breed"); + * var myExtender = extender.define(isMethods).expose(isMethods); * - * var myDog = new animals.Dog(); + * myExtender.isArray([]); //true + * myExtender([]).isArray([]).value(); //true * * ``` * - * Or in node * - * ``` - * Mammal.as(exports, "Dog"); - * Wolf.as(exports, "Wolf"); - * Dog.as(exports, "Dog"); - * Breed.as(exports, "Breed"); + * **Using `instanceof`** * - * ``` + * When using extenders you can test if a value is an `instanceof` of an extender by using the instanceof operator. * - * To export a class as the `module` in node + * ```javascript + * var str = myExtender("hello"); * - * ``` - * Mammal.as(module); + * str instanceof myExtender; //true * ``` * + * ## Examples * + * To see more examples click [here](https://github.com/doug-martin/extender/tree/master/examples) */ - function createDeclared() { - var arraySlice = Array.prototype.slice, classCounter = 0, Base, forceNew = new Function(); - - var SUPER_REGEXP = /(super)/g; - - function argsToArray(args, slice) { - slice = slice || 0; - return arraySlice.call(args, slice); - } - - function isArray(obj) { - return Object.prototype.toString.call(obj) === "[object Array]"; - } - - function isObject(obj) { - var undef; - return obj !== null && obj !== undef && typeof obj === "object"; - } - - function isHash(obj) { - var ret = isObject(obj); - return ret && obj.constructor === Object; - } - - var isArguments = function _isArguments(object) { - return Object.prototype.toString.call(object) === '[object Arguments]'; - }; - - if (!isArguments(arguments)) { - isArguments = function _isArguments(obj) { - return !!(obj && obj.hasOwnProperty("callee")); - }; - } - - function indexOf(arr, item) { - if (arr && arr.length) { - for (var i = 0, l = arr.length; i < l; i++) { - if (arr[i] === item) { - return i; - } - } - } - return -1; - } - - function merge(target, source, exclude) { - var name, s; - for (name in source) { - if (source.hasOwnProperty(name) && indexOf(exclude, name) === -1) { - s = source[name]; - if (!(name in target) || (target[name] !== s)) { - target[name] = s; - } - } - } - return target; - } - - function callSuper(args, a) { - var meta = this.__meta, - supers = meta.supers, - l = supers.length, superMeta = meta.superMeta, pos = superMeta.pos; - if (l > pos) { - args = !args ? [] : (!isArguments(args) && !isArray(args)) ? [args] : args; - var name = superMeta.name, f = superMeta.f, m; - do { - m = supers[pos][name]; - if ("function" === typeof m && (m = m._f || m) !== f) { - superMeta.pos = 1 + pos; - return m.apply(this, args); - } - } while (l > ++pos); - } - - return null; - } - - function getSuper() { - var meta = this.__meta, - supers = meta.supers, - l = supers.length, superMeta = meta.superMeta, pos = superMeta.pos; - if (l > pos) { - var name = superMeta.name, f = superMeta.f, m; - do { - m = supers[pos][name]; - if ("function" === typeof m && (m = m._f || m) !== f) { - superMeta.pos = 1 + pos; - return m.bind(this); - } - } while (l > ++pos); - } - return null; - } - - function getter(name) { - var getters = this.__getters__; - if (getters.hasOwnProperty(name)) { - return getters[name].apply(this); - } else { - return this[name]; - } - } - - function setter(name, val) { - var setters = this.__setters__; - if (isHash(name)) { - for (var i in name) { - var prop = name[i]; - if (setters.hasOwnProperty(i)) { - setters[name].call(this, prop); - } else { - this[i] = prop; - } - } - } else { - if (setters.hasOwnProperty(name)) { - return setters[name].apply(this, argsToArray(arguments, 1)); - } else { - return this[name] = val; - } - } - } - - - function defaultFunction() { - var meta = this.__meta || {}, - supers = meta.supers, - l = supers.length, superMeta = meta.superMeta, pos = superMeta.pos; - if (l > pos) { - var name = superMeta.name, f = superMeta.f, m; - do { - m = supers[pos][name]; - if ("function" === typeof m && (m = m._f || m) !== f) { - superMeta.pos = 1 + pos; - return m.apply(this, arguments); - } - } while (l > ++pos); - } - return null; - } - - - function functionWrapper(f, name) { - if (f.toString().match(SUPER_REGEXP)) { - var wrapper = function wrapper() { - var ret, meta = this.__meta || {}; - var orig = meta.superMeta; - meta.superMeta = {f: f, pos: 0, name: name}; - switch (arguments.length) { - case 0: - ret = f.call(this); - break; - case 1: - ret = f.call(this, arguments[0]); - break; - case 2: - ret = f.call(this, arguments[0], arguments[1]); - break; - - case 3: - ret = f.call(this, arguments[0], arguments[1], arguments[2]); - break; - default: - ret = f.apply(this, arguments); - } - meta.superMeta = orig; - return ret; - }; - wrapper._f = f; - return wrapper; - } else { - f._f = f; - return f; - } - } - - function defineMixinProps(child, proto) { - - var operations = proto.setters || {}, __setters = child.__setters__, __getters = child.__getters__; - for (var i in operations) { - if (!__setters.hasOwnProperty(i)) { //make sure that the setter isnt already there - __setters[i] = operations[i]; - } - } - operations = proto.getters || {}; - for (i in operations) { - if (!__getters.hasOwnProperty(i)) { //make sure that the setter isnt already there - __getters[i] = operations[i]; - } - } - for (var j in proto) { - if (j !== "getters" && j !== "setters") { - var p = proto[j]; - if ("function" === typeof p) { - if (!child.hasOwnProperty(j)) { - child[j] = functionWrapper(defaultFunction, j); - } - } else { - child[j] = p; - } - } - } - } - - function mixin() { - var args = argsToArray(arguments), l = args.length; - var child = this.prototype; - var childMeta = child.__meta, thisMeta = this.__meta, bases = child.__meta.bases, staticBases = bases.slice(), - staticSupers = thisMeta.supers || [], supers = childMeta.supers || []; - for (var i = 0; i < l; i++) { - var m = args[i], mProto = m.prototype; - var protoMeta = mProto.__meta, meta = m.__meta; - !protoMeta && (protoMeta = (mProto.__meta = {proto: mProto || {}})); - !meta && (meta = (m.__meta = {proto: m.__proto__ || {}})); - defineMixinProps(child, protoMeta.proto || {}); - defineMixinProps(this, meta.proto || {}); - //copy the bases for static, - - mixinSupers(m.prototype, supers, bases); - mixinSupers(m, staticSupers, staticBases); - } - return this; - } - - function mixinSupers(sup, arr, bases) { - var meta = sup.__meta; - !meta && (meta = (sup.__meta = {})); - var unique = sup.__meta.unique; - !unique && (meta.unique = "declare" + ++classCounter); - //check it we already have this super mixed into our prototype chain - //if true then we have already looped their supers! - if (indexOf(bases, unique) === -1) { - //add their id to our bases - bases.push(unique); - var supers = sup.__meta.supers || [], i = supers.length - 1 || 0; - while (i >= 0) { - mixinSupers(supers[i--], arr, bases); + function defineExtender(declare) { + + + var slice = Array.prototype.slice, undef; + + function indexOf(arr, item) { + if (arr && arr.length) { + for (var i = 0, l = arr.length; i < l; i++) { + if (arr[i] === item) { + return i; + } } - arr.unshift(sup); } + return -1; } - function defineProps(child, proto) { - var operations = proto.setters, - __setters = child.__setters__, - __getters = child.__getters__; - if (operations) { - for (var i in operations) { - __setters[i] = operations[i]; - } - } - operations = proto.getters || {}; - if (operations) { - for (i in operations) { - __getters[i] = operations[i]; - } - } - for (i in proto) { - if (i != "getters" && i != "setters") { - var f = proto[i]; - if ("function" === typeof f) { - var meta = f.__meta || {}; - if (!meta.isConstructor) { - child[i] = functionWrapper(f, i); - } else { - child[i] = f; + function isArray(obj) { + return Object.prototype.toString.call(obj) === "[object Array]"; + } + + var merge = (function merger() { + function _merge(target, source, exclude) { + var name, s; + for (name in source) { + if (source.hasOwnProperty(name) && indexOf(exclude, name) === -1) { + s = source[name]; + if (!(name in target) || (target[name] !== s)) { + target[name] = s; } - } else { - child[i] = f; } } + return target; } - } + return function merge(obj) { + if (!obj) { + obj = {}; + } + var l = arguments.length; + var exclude = arguments[arguments.length - 1]; + if (isArray(exclude)) { + l--; + } else { + exclude = []; + } + for (var i = 1; i < l; i++) { + _merge(obj, arguments[i], exclude); + } + return obj; // Object + }; + }()); - function _export(obj, name) { - if (obj && name) { - obj[name] = this; - } else { - obj.exports = obj = this; - } - return this; - } - function extend(proto) { - return declare(this, proto); - } + function extender(supers) { + supers = supers || []; + var Base = declare({ + instance: { + constructor: function (value) { + this._value = value; + }, - function getNew(ctor) { - // create object with correct prototype using a do-nothing - // constructor - forceNew.prototype = ctor.prototype; - var t = new forceNew(); - forceNew.prototype = null; // clean up - return t; - } + value: function () { + return this._value; + }, + eq: function eq(val) { + return this["__extender__"](this._value === val); + }, - function __declare(child, sup, proto) { - var childProto = {}, supers = []; - var unique = "declare" + ++classCounter, bases = [], staticBases = []; - var instanceSupers = [], staticSupers = []; - var meta = { - supers: instanceSupers, - unique: unique, - bases: bases, - superMeta: { - f: null, - pos: 0, - name: null - } - }; - var childMeta = { - supers: staticSupers, - unique: unique, - bases: staticBases, - isConstructor: true, - superMeta: { - f: null, - pos: 0, - name: null + neq: function neq(other) { + return this["__extender__"](this._value !== other); + }, + print: function () { + console.log(this._value); + return this; + } } - }; - - if (isHash(sup) && !proto) { - proto = sup; - sup = Base; - } + }), defined = []; - if ("function" === typeof sup || isArray(sup)) { - supers = isArray(sup) ? sup : [sup]; - sup = supers.shift(); - child.__meta = childMeta; - childProto = getNew(sup); - childProto.__meta = meta; - childProto.__getters__ = merge({}, childProto.__getters__ || {}); - childProto.__setters__ = merge({}, childProto.__setters__ || {}); - child.__getters__ = merge({}, child.__getters__ || {}); - child.__setters__ = merge({}, child.__setters__ || {}); - mixinSupers(sup.prototype, instanceSupers, bases); - mixinSupers(sup, staticSupers, staticBases); - } else { - child.__meta = childMeta; - childProto.__meta = meta; - childProto.__getters__ = childProto.__getters__ || {}; - childProto.__setters__ = childProto.__setters__ || {}; - child.__getters__ = child.__getters__ || {}; - child.__setters__ = child.__setters__ || {}; - } - child.prototype = childProto; - if (proto) { - var instance = meta.proto = proto.instance || {}; - var stat = childMeta.proto = proto.static || {}; - stat.init = stat.init || defaultFunction; - defineProps(childProto, instance); - defineProps(child, stat); - if (!instance.hasOwnProperty("constructor")) { - childProto.constructor = instance.constructor = functionWrapper(defaultFunction, "constructor"); + function addMethod(proto, name, func) { + if ("function" !== typeof func) { + throw new TypeError("when extending type you must provide a function"); + } + var extendedMethod; + if (name === "constructor") { + extendedMethod = function () { + this._super(arguments); + func.apply(this, arguments); + }; } else { - childProto.constructor = functionWrapper(instance.constructor, "constructor"); + extendedMethod = function extendedMethod() { + var args = slice.call(arguments); + args.unshift(this._value); + var ret = func.apply(this, args); + return ret !== undef ? this["__extender__"](ret) : this; + }; } - } else { - meta.proto = {}; - childMeta.proto = {}; - child.init = functionWrapper(defaultFunction, "init"); - childProto.constructor = functionWrapper(defaultFunction, "constructor"); - } - if (supers.length) { - mixin.apply(child, supers); - } - if (sup) { - //do this so we mixin our super methods directly but do not ov - merge(child, merge(merge({}, sup), child)); + proto[name] = extendedMethod; } - childProto._super = child._super = callSuper; - childProto._getSuper = child._getSuper = getSuper; - childProto._static = child; - } - function declare(sup, proto) { - function declared() { - switch (arguments.length) { - case 0: - this.constructor.call(this); - break; - case 1: - this.constructor.call(this, arguments[0]); - break; - case 2: - this.constructor.call(this, arguments[0], arguments[1]); - break; - case 3: - this.constructor.call(this, arguments[0], arguments[1], arguments[2]); - break; - default: - this.constructor.apply(this, arguments); + function addNoWrapMethod(proto, name, func) { + if ("function" !== typeof func) { + throw new TypeError("when extending type you must provide a function"); + } + var extendedMethod; + if (name === "constructor") { + extendedMethod = function () { + this._super(arguments); + func.apply(this, arguments); + }; + } else { + extendedMethod = function extendedMethod() { + var args = slice.call(arguments); + args.unshift(this._value); + return func.apply(this, args); + }; } + proto[name] = extendedMethod; } - __declare(declared, sup, proto); - return declared.init() || declared; - } - - function singleton(sup, proto) { - var retInstance; - - function declaredSingleton() { - if (!retInstance) { - this.constructor.apply(this, arguments); - retInstance = this; + function decorateProto(proto, decoration, nowrap) { + for (var i in decoration) { + if (decoration.hasOwnProperty(i)) { + if (i !== "getters" && i !== "setters") { + if (i === "noWrap") { + decorateProto(proto, decoration[i], true); + } else if (nowrap) { + addNoWrapMethod(proto, i, decoration[i]); + } else { + addMethod(proto, i, decoration[i]); + } + } else { + proto[i] = decoration[i]; + } + } } - return retInstance; } - __declare(declaredSingleton, sup, proto); - return declaredSingleton.init() || declaredSingleton; - } - - Base = declare({ - instance: { - "get": getter, - "set": setter - }, - - "static": { - "get": getter, - "set": setter, - mixin: mixin, - extend: extend, - as: _export + function _extender(obj) { + var ret = obj, i, l; + if (!(obj instanceof Base)) { + var OurBase = Base; + for (i = 0, l = defined.length; i < l; i++) { + var definer = defined[i]; + if (definer[0](obj)) { + OurBase = OurBase.extend({instance: definer[1]}); + } + } + ret = new OurBase(obj); + ret["__extender__"] = _extender; + } + return ret; } - }); - - declare.singleton = singleton; - return declare; - } - - if ("undefined" !== typeof exports) { - if ("undefined" !== typeof module && module.exports) { - module.exports = createDeclared(); - } - } else if ("function" === typeof define && define.amd) { - define(createDeclared); - } else { - this.declare = createDeclared(); - } -}()); - - - - -},{}],45:[function(require,module,exports){ -module.exports = require("./declare.js"); -},{"./declare.js":44}],46:[function(require,module,exports){ -(function () { - "use strict"; - /*global extender is, dateExtended*/ - - function defineExtended(extender) { + function always() { + return true; + } - var merge = (function merger() { - function _merge(target, source) { - var name, s; - for (name in source) { - if (source.hasOwnProperty(name)) { - s = source[name]; - if (!(name in target) || (target[name] !== s)) { - target[name] = s; + function define(tester, decorate) { + if (arguments.length) { + if (typeof tester === "object") { + decorate = tester; + tester = always; + } + decorate = decorate || {}; + var proto = {}; + decorateProto(proto, decorate); + //handle browsers like which skip over the constructor while looping + if (!proto.hasOwnProperty("constructor")) { + if (decorate.hasOwnProperty("constructor")) { + addMethod(proto, "constructor", decorate.constructor); + } else { + proto.constructor = function () { + this._super(arguments); + }; } } + defined.push([tester, proto]); } - return target; + return _extender; } - return function merge(obj) { - if (!obj) { - obj = {}; - } - for (var i = 1, l = arguments.length; i < l; i++) { - _merge(obj, arguments[i]); + function extend(supr) { + if (supr && supr.hasOwnProperty("__defined__")) { + _extender["__defined__"] = defined = defined.concat(supr["__defined__"]); } - return obj; // Object - }; - }()); - - function getExtended() { - - var loaded = {}; - + merge(_extender, supr, ["define", "extend", "expose", "__defined__"]); + return _extender; + } - //getInitial instance; - var extended = extender.define(); - extended.expose({ - register: function register(alias, extendWith) { - if (!extendWith) { - extendWith = alias; - alias = null; - } - var type = typeof extendWith; - if (alias) { - extended[alias] = extendWith; - } else if (extendWith && type === "function") { - extended.extend(extendWith); - } else if (type === "object") { - extended.expose(extendWith); - } else { - throw new TypeError("extended.register must be called with an extender function"); + _extender.define = define; + _extender.extend = extend; + _extender.expose = function expose() { + var methods; + for (var i = 0, l = arguments.length; i < l; i++) { + methods = arguments[i]; + if (typeof methods === "object") { + merge(_extender, methods, ["define", "extend", "expose", "__defined__"]); } - return extended; - }, - - define: function () { - return extender.define.apply(extender, arguments); } - }); + return _extender; + }; + _extender["__defined__"] = defined; - return extended; - } - function extended() { - return getExtended(); + return _extender; } - extended.define = function define() { - return extender.define.apply(extender, arguments); + return { + define: function () { + return extender().define.apply(extender, arguments); + }, + + extend: function (supr) { + return extender().define().extend(supr); + } }; - return extended; } if ("undefined" !== typeof exports) { if ("undefined" !== typeof module && module.exports) { - module.exports = defineExtended(require("extender")); + module.exports = defineExtender(require("declare.js")); } } else if ("function" === typeof define && define.amd) { - define(["extender"], function (extender) { - return defineExtended(extender); + define(["declare"], function (declare) { + return defineExtender(declare); }); } else { - this.extended = defineExtended(this.extender); + this.extender = defineExtender(this.declare); } }).call(this); - - - - - - - -},{"extender":48}],47:[function(require,module,exports){ +},{"declare.js":62}],60:[function(require,module,exports){ +module.exports = require("./extender.js"); +},{"./extender.js":59}],61:[function(require,module,exports){ (function () { - /*jshint strict:false*/ - /** + * @projectName declare + * @github http://github.com/doug-martin/declare.js + * @header + * + * Declare is a library designed to allow writing object oriented code the same way in both the browser and node.js. + * + * ##Installation + * + * `npm install declare.js` + * + * Or [download the source](https://raw.github.com/doug-martin/declare.js/master/declare.js) ([minified](https://raw.github.com/doug-martin/declare.js/master/declare-min.js)) + * + * ###Requirejs + * + * To use with requirejs place the `declare` source in the root scripts directory + * + * ``` + * + * define(["declare"], function(declare){ + * return declare({ + * instance : { + * hello : function(){ + * return "world"; + * } + * } + * }); + * }); + * + * ``` + * + * + * ##Usage + * + * declare.js provides + * + * Class methods + * + * * `as(module | object, name)` : exports the object to module or the object with the name + * * `mixin(mixin)` : mixes in an object but does not inherit directly from the object. **Note** this does not return a new class but changes the original class. + * * `extend(proto)` : extend a class with the given properties. A shortcut to `declare(Super, {})`; + * + * Instance methods + * + * * `_super(arguments)`: calls the super of the current method, you can pass in either the argments object or an array with arguments you want passed to super + * * `_getSuper()`: returns a this methods direct super. + * * `_static` : use to reference class properties and methods. + * * `get(prop)` : gets a property invoking the getter if it exists otherwise it just returns the named property on the object. + * * `set(prop, val)` : sets a property invoking the setter if it exists otherwise it just sets the named property on the object. + * + * + * ###Declaring a new Class + * + * Creating a new class with declare is easy! + * + * ``` + * + * var Mammal = declare({ + * //define your instance methods and properties + * instance : { + * + * //will be called whenever a new instance is created + * constructor: function(options) { + * options = options || {}; + * this._super(arguments); + * this._type = options.type || "mammal"; + * }, + * + * speak : function() { + * return "A mammal of type " + this._type + " sounds like"; + * }, + * + * //Define your getters + * getters : { + * + * //can be accessed by using the get method. (mammal.get("type")) + * type : function() { + * return this._type; + * } + * }, * - * @projectName extender - * @github http://github.com/doug-martin/extender - * @header - * [![build status](https://secure.travis-ci.org/doug-martin/extender.png)](http://travis-ci.org/doug-martin/extender) - * # Extender + * //Define your setters + * setters : { * - * `extender` is a library that helps in making chainable APIs, by creating a function that accepts different values and returns an object decorated with functions based on the type. + * //can be accessed by using the set method. (mammal.set("type", "mammalType")) + * type : function(t) { + * this._type = t; + * } + * } + * }, * - * ## Why Is Extender Different? + * //Define your static methods + * static : { * - * Extender is different than normal chaining because is does more than return `this`. It decorates your values in a type safe manner. + * //Mammal.soundOff(); //"Im a mammal!!" + * soundOff : function() { + * return "Im a mammal!!"; + * } + * } + * }); * - * For example if you return an array from a string based method then the returned value will be decorated with array methods and not the string methods. This allow you as the developer to focus on your API and not worrying about how to properly build and connect your API. * + * ``` * - * ## Installation + * You can use Mammal just like you would any other class. * * ``` - * npm install extender + * Mammal.soundOff("Im a mammal!!"); + * + * var myMammal = new Mammal({type : "mymammal"}); + * myMammal.speak(); // "A mammal of type mymammal sounds like" + * myMammal.get("type"); //"mymammal" + * myMammal.set("type", "mammal"); + * myMammal.get("type"); //"mammal" + * + * * ``` * - * Or [download the source](https://raw.github.com/doug-martin/extender/master/extender.js) ([minified](https://raw.github.com/doug-martin/extender/master/extender-min.js)) + * ###Extending a class * - * **Note** `extender` depends on [`declare.js`](http://doug-martin.github.com/declare.js/). + * If you want to just extend a single class use the .extend method. * - * ### Requirejs + * ``` * - * To use with requirejs place the `extend` source in the root scripts directory + * var Wolf = Mammal.extend({ * - * ```javascript + * //define your instance method + * instance: { * - * define(["extender"], function(extender){ + * //You can override super constructors just be sure to call `_super` + * constructor: function(options) { + * options = options || {}; + * this._super(arguments); //call our super constructor. + * this._sound = "growl"; + * this._color = options.color || "grey"; + * }, + * + * //override Mammals `speak` method by appending our own data to it. + * speak : function() { + * return this._super(arguments) + " a " + this._sound; + * }, + * + * //add new getters for sound and color + * getters : { + * + * //new Wolf().get("type") + * //notice color is read only as we did not define a setter + * color : function() { + * return this._color; + * }, + * + * //new Wolf().get("sound") + * sound : function() { + * return this._sound; + * } + * }, + * + * setters : { + * + * //new Wolf().set("sound", "howl") + * sound : function(s) { + * this._sound = s; + * } + * } + * + * }, + * + * static : { + * + * //You can override super static methods also! And you can still use _super + * soundOff : function() { + * //You can even call super in your statics!!! + * //should return "I'm a mammal!! that growls" + * return this._super(arguments) + " that growls"; + * } + * } * }); * + * Wolf.soundOff(); //Im a mammal!! that growls + * + * var myWolf = new Wolf(); + * myWolf instanceof Mammal //true + * myWolf instanceof Wolf //true + * * ``` * + * You can also extend a class by using the declare method and just pass in the super class. * - * ## Usage + * ``` + * //Typical hierarchical inheritance + * // Mammal->Wolf->Dog + * var Dog = declare(Wolf, { + * instance: { + * constructor: function(options) { + * options = options || {}; + * this._super(arguments); + * //override Wolfs initialization of sound to woof. + * this._sound = "woof"; * - * **`extender.define(tester, decorations)`** + * }, * - * To create your own extender call the `extender.define` function. + * speak : function() { + * //Should return "A mammal of type mammal sounds like a growl thats domesticated" + * return this._super(arguments) + " thats domesticated"; + * } + * }, * - * This function accepts an optional tester which is used to determine a value should be decorated with the specified `decorations` + * static : { + * soundOff : function() { + * //should return "I'm a mammal!! that growls but now barks" + * return this._super(arguments) + " but now barks"; + * } + * } + * }); * - * ```javascript - * function isString(obj) { - * return !isUndefinedOrNull(obj) && (typeof obj === "string" || obj instanceof String); - * } + * Dog.soundOff(); //Im a mammal!! that growls but now barks * + * var myDog = new Dog(); + * myDog instanceof Mammal //true + * myDog instanceof Wolf //true + * myDog instanceof Dog //true * - * var myExtender = extender.define(isString, { - * multiply: function (str, times) { - * var ret = str; - * for (var i = 1; i < times; i++) { - * ret += str; - * } - * return ret; - * }, - * toArray: function (str, delim) { - * delim = delim || ""; - * return str.split(delim); - * } - * }); * - * myExtender("hello").multiply(2).value(); //hellohello + * //Notice you still get the extend method. + * + * // Mammal->Wolf->Dog->Breed + * var Breed = Dog.extend({ + * instance: { + * + * //initialize outside of constructor + * _pitch : "high", + * + * constructor: function(options) { + * options = options || {}; + * this._super(arguments); + * this.breed = options.breed || "lab"; + * }, + * + * speak : function() { + * //Should return "A mammal of type mammal sounds like a + * //growl thats domesticated with a high pitch!" + * return this._super(arguments) + " with a " + this._pitch + " pitch!"; + * }, + * + * getters : { + * pitch : function() { + * return this._pitch; + * } + * } + * }, + * + * static : { + * soundOff : function() { + * //should return "I'M A MAMMAL!! THAT GROWLS BUT NOW BARKS!" + * return this._super(arguments).toUpperCase() + "!"; + * } + * } + * }); + * + * + * Breed.soundOff()//"IM A MAMMAL!! THAT GROWLS BUT NOW BARKS!" * + * var myBreed = new Breed({color : "gold", type : "lab"}), + * myBreed instanceof Dog //true + * myBreed instanceof Wolf //true + * myBreed instanceof Mammal //true + * myBreed.speak() //"A mammal of type lab sounds like a woof thats domesticated with a high pitch!" + * myBreed.get("type") //"lab" + * myBreed.get("color") //"gold" + * myBreed.get("sound")" //"woof" * ``` * - * If you do not specify a tester function and just pass in an object of `functions` then all values passed in will be decorated with methods. + * ###Multiple Inheritance / Mixins * - * ```javascript + * declare also allows the use of multiple super classes. + * This is useful if you have generic classes that provide functionality but shouldnt be used on their own. * - * function isUndefined(obj) { - * var undef; - * return obj === undef; - * } + * Lets declare a mixin that allows us to watch for property changes. * - * function isUndefinedOrNull(obj) { - * var undef; - * return obj === undef || obj === null; + * ``` + * //Notice that we set up the functions outside of declare because we can reuse them + * + * function _set(prop, val) { + * //get the old value + * var oldVal = this.get(prop); + * //call super to actually set the property + * var ret = this._super(arguments); + * //call our handlers + * this.__callHandlers(prop, oldVal, val); + * return ret; * } * - * function isArray(obj) { - * return Object.prototype.toString.call(obj) === "[object Array]"; + * function _callHandlers(prop, oldVal, newVal) { + * //get our handlers for the property + * var handlers = this.__watchers[prop], l; + * //if the handlers exist and their length does not equal 0 then we call loop through them + * if (handlers && (l = handlers.length) !== 0) { + * for (var i = 0; i < l; i++) { + * //call the handler + * handlers[i].call(null, prop, oldVal, newVal); + * } + * } * } * - * function isBoolean(obj) { - * var undef, type = typeof obj; - * return !isUndefinedOrNull(obj) && type === "boolean" || type === "Boolean"; + * + * //the watch function + * function _watch(prop, handler) { + * if ("function" !== typeof handler) { + * //if its not a function then its an invalid handler + * throw new TypeError("Invalid handler."); + * } + * if (!this.__watchers[prop]) { + * //create the watchers if it doesnt exist + * this.__watchers[prop] = [handler]; + * } else { + * //otherwise just add it to the handlers array + * this.__watchers[prop].push(handler); + * } * } * - * function isString(obj) { - * return !isUndefinedOrNull(obj) && (typeof obj === "string" || obj instanceof String); + * function _unwatch(prop, handler) { + * if ("function" !== typeof handler) { + * throw new TypeError("Invalid handler."); + * } + * var handlers = this.__watchers[prop], index; + * if (handlers && (index = handlers.indexOf(handler)) !== -1) { + * //remove the handler if it is found + * handlers.splice(index, 1); + * } * } * - * var myExtender = extender.define({ - * isUndefined : isUndefined, - * isUndefinedOrNull : isUndefinedOrNull, - * isArray : isArray, - * isBoolean : isBoolean, - * isString : isString - * }); - * - * ``` + * declare({ + * instance:{ + * constructor:function () { + * this._super(arguments); + * //set up our watchers + * this.__watchers = {}; + * }, * - * To use + * //override the default set function so we can watch values + * "set":_set, + * //set up our callhandlers function + * __callHandlers:_callHandlers, + * //add the watch function + * watch:_watch, + * //add the unwatch function + * unwatch:_unwatch + * }, * - * ``` - * var undef; - * myExtender("hello").isUndefined().value(); //false - * myExtender(undef).isUndefined().value(); //true - * ``` + * "static":{ * - * You can also chain extenders so that they accept multiple types and decorates accordingly. + * init:function () { + * this._super(arguments); + * this.__watchers = {}; + * }, + * //override the default set function so we can watch values + * "set":_set, + * //set our callHandlers function + * __callHandlers:_callHandlers, + * //add the watch + * watch:_watch, + * //add the unwatch function + * unwatch:_unwatch + * } + * }) * - * ```javascript - * myExtender - * .define(isArray, { - * pluck: function (arr, m) { - * var ret = []; - * for (var i = 0, l = arr.length; i < l; i++) { - * ret.push(arr[i][m]); - * } - * return ret; - * } - * }) - * .define(isBoolean, { - * invert: function (val) { - * return !val; - * } - * }); + * ``` * - * myExtender([{a: "a"},{a: "b"},{a: "c"}]).pluck("a").value(); //["a", "b", "c"] - * myExtender("I love javascript!").toArray(/\s+/).pluck("0"); //["I", "l", "j"] + * Now lets use the mixin * * ``` + * var WatchDog = declare([Dog, WatchMixin]); * - * Notice that we reuse the same extender as defined above. - * - * **Return Values** + * var watchDog = new WatchDog(); + * //create our handler + * function watch(id, oldVal, newVal) { + * console.log("watchdog's %s was %s, now %s", id, oldVal, newVal); + * } * - * When creating an extender if you return a value from one of the decoration functions then that value will also be decorated. If you do not return any values then the extender will be returned. + * //watch for property changes + * watchDog.watch("type", watch); + * watchDog.watch("color", watch); + * watchDog.watch("sound", watch); * - * **Default decoration methods** + * //now set the properties each handler will be called + * watchDog.set("type", "newDog"); + * watchDog.set("color", "newColor"); + * watchDog.set("sound", "newSound"); * - * By default every value passed into an extender is decorated with the following methods. * - * * `value` : The value this extender represents. - * * `eq(otherValue)` : Tests strict equality of the currently represented value to the `otherValue` - * * `neq(oterValue)` : Tests strict inequality of the currently represented value. - * * `print` : logs the current value to the console. + * //unwatch the property changes + * watchDog.unwatch("type", watch); + * watchDog.unwatch("color", watch); + * watchDog.unwatch("sound", watch); * - * **Extender initialization** + * //no handlers will be called this time + * watchDog.set("type", "newDog"); + * watchDog.set("color", "newColor"); + * watchDog.set("sound", "newSound"); * - * When creating an extender you can also specify a constructor which will be invoked with the current value. * - * ```javascript - * myExtender.define(isString, { - * constructor : function(val){ - * //set our value to the string trimmed - * this._value = val.trimRight().trimLeft(); - * } - * }); * ``` * - * **`noWrap`** + * ###Accessing static methods and properties witin an instance. * - * `extender` also allows you to specify methods that should not have the value wrapped providing a cleaner exit function other than `value()`. + * To access static properties on an instance use the `_static` property which is a reference to your constructor. * - * For example suppose you have an API that allows you to build a validator, rather than forcing the user to invoke the `value` method you could add a method called `validator` which makes more syntactic sense. + * For example if your in your constructor and you want to have configurable default values. * * ``` - * - * var myValidator = extender.define({ - * //chainable validation methods - * //... - * //end chainable validation methods - * - * noWrap : { - * validator : function(){ - * //return your validator - * } - * } - * }); - * - * myValidator().isNotNull().isEmailAddress().validator(); //now you dont need to call .value() - * - * + * consturctor : function constructor(opts){ + * this.opts = opts || {}; + * this._type = opts.type || this._static.DEFAULT_TYPE; + * } * ``` - * **`extender.extend(extendr)`** * - * You may also compose extenders through the use of `extender.extend(extender)`, which will return an entirely new extender that is the composition of extenders. * - * Suppose you have the following two extenders. * - * ```javascript - * var myExtender = extender - * .define({ - * isFunction: is.function, - * isNumber: is.number, - * isString: is.string, - * isDate: is.date, - * isArray: is.array, - * isBoolean: is.boolean, - * isUndefined: is.undefined, - * isDefined: is.defined, - * isUndefinedOrNull: is.undefinedOrNull, - * isNull: is.null, - * isArguments: is.arguments, - * isInstanceOf: is.instanceOf, - * isRegExp: is.regExp - * }); - * var myExtender2 = extender.define(is.array, { - * pluck: function (arr, m) { - * var ret = []; - * for (var i = 0, l = arr.length; i < l; i++) { - * ret.push(arr[i][m]); - * } - * return ret; - * }, + * ###Creating a new instance of within an instance. * - * noWrap: { - * pluckPlain: function (arr, m) { - * var ret = []; - * for (var i = 0, l = arr.length; i < l; i++) { - * ret.push(arr[i][m]); - * } - * return ret; - * } - * } - * }); + * Often times you want to create a new instance of an object within an instance. If your subclassed however you cannot return a new instance of the parent class as it will not be the right sub class. `declare` provides a way around this by setting the `_static` property on each isntance of the class. * + * Lets add a reproduce method `Mammal` * * ``` - * - * And you do not want to alter either of them but instead what to create a third that is the union of the two. - * - * - * ```javascript - * var composed = extender.extend(myExtender).extend(myExtender2); + * reproduce : function(options){ + * return new this._static(options); + * } * ``` - * So now you can use the new extender with the joined functionality if `myExtender` and `myExtender2`. * - * ```javascript - * var extended = composed([ - * {a: "a"}, - * {a: "b"}, - * {a: "c"} - * ]); - * extended.isArray().value(); //true - * extended.pluck("a").value(); // ["a", "b", "c"]); + * Now in each subclass you can call reproduce and get the proper type. * * ``` + * var myDog = new Dog(); + * var myDogsChild = myDog.reproduce(); * - * **Note** `myExtender` and `myExtender2` will **NOT** be altered. + * myDogsChild instanceof Dog; //true + * ``` * - * **`extender.expose(methods)`** + * ###Using the `as` * - * The `expose` method allows you to add methods to your extender that are not wrapped or automatically chained by exposing them on the extender directly. + * `declare` also provides an `as` method which allows you to add your class to an object or if your using node.js you can pass in `module` and the class will be exported as the module. * * ``` - * var isMethods = { - * isFunction: is.function, - * isNumber: is.number, - * isString: is.string, - * isDate: is.date, - * isArray: is.array, - * isBoolean: is.boolean, - * isUndefined: is.undefined, - * isDefined: is.defined, - * isUndefinedOrNull: is.undefinedOrNull, - * isNull: is.null, - * isArguments: is.arguments, - * isInstanceOf: is.instanceOf, - * isRegExp: is.regExp - * }; + * var animals = {}; * - * var myExtender = extender.define(isMethods).expose(isMethods); + * Mammal.as(animals, "Dog"); + * Wolf.as(animals, "Wolf"); + * Dog.as(animals, "Dog"); + * Breed.as(animals, "Breed"); * - * myExtender.isArray([]); //true - * myExtender([]).isArray([]).value(); //true + * var myDog = new animals.Dog(); * * ``` * + * Or in node * - * **Using `instanceof`** + * ``` + * Mammal.as(exports, "Dog"); + * Wolf.as(exports, "Wolf"); + * Dog.as(exports, "Dog"); + * Breed.as(exports, "Breed"); * - * When using extenders you can test if a value is an `instanceof` of an extender by using the instanceof operator. + * ``` * - * ```javascript - * var str = myExtender("hello"); + * To export a class as the `module` in node * - * str instanceof myExtender; //true + * ``` + * Mammal.as(module); * ``` * - * ## Examples * - * To see more examples click [here](https://github.com/doug-martin/extender/tree/master/examples) */ - function defineExtender(declare) { + function createDeclared() { + var arraySlice = Array.prototype.slice, classCounter = 0, Base, forceNew = new Function(); + + var SUPER_REGEXP = /(super)/g; + + function argsToArray(args, slice) { + slice = slice || 0; + return arraySlice.call(args, slice); + } + + function isArray(obj) { + return Object.prototype.toString.call(obj) === "[object Array]"; + } + + function isObject(obj) { + var undef; + return obj !== null && obj !== undef && typeof obj === "object"; + } + + function isHash(obj) { + var ret = isObject(obj); + return ret && obj.constructor === Object; + } + + var isArguments = function _isArguments(object) { + return Object.prototype.toString.call(object) === '[object Arguments]'; + }; + + if (!isArguments(arguments)) { + isArguments = function _isArguments(obj) { + return !!(obj && obj.hasOwnProperty("callee")); + }; + } + + function indexOf(arr, item) { + if (arr && arr.length) { + for (var i = 0, l = arr.length; i < l; i++) { + if (arr[i] === item) { + return i; + } + } + } + return -1; + } + + function merge(target, source, exclude) { + var name, s; + for (name in source) { + if (source.hasOwnProperty(name) && indexOf(exclude, name) === -1) { + s = source[name]; + if (!(name in target) || (target[name] !== s)) { + target[name] = s; + } + } + } + return target; + } + + function callSuper(args, a) { + var meta = this.__meta, + supers = meta.supers, + l = supers.length, superMeta = meta.superMeta, pos = superMeta.pos; + if (l > pos) { + args = !args ? [] : (!isArguments(args) && !isArray(args)) ? [args] : args; + var name = superMeta.name, f = superMeta.f, m; + do { + m = supers[pos][name]; + if ("function" === typeof m && (m = m._f || m) !== f) { + superMeta.pos = 1 + pos; + return m.apply(this, args); + } + } while (l > ++pos); + } + + return null; + } + + function getSuper() { + var meta = this.__meta, + supers = meta.supers, + l = supers.length, superMeta = meta.superMeta, pos = superMeta.pos; + if (l > pos) { + var name = superMeta.name, f = superMeta.f, m; + do { + m = supers[pos][name]; + if ("function" === typeof m && (m = m._f || m) !== f) { + superMeta.pos = 1 + pos; + return m.bind(this); + } + } while (l > ++pos); + } + return null; + } + + function getter(name) { + var getters = this.__getters__; + if (getters.hasOwnProperty(name)) { + return getters[name].apply(this); + } else { + return this[name]; + } + } + + function setter(name, val) { + var setters = this.__setters__; + if (isHash(name)) { + for (var i in name) { + var prop = name[i]; + if (setters.hasOwnProperty(i)) { + setters[name].call(this, prop); + } else { + this[i] = prop; + } + } + } else { + if (setters.hasOwnProperty(name)) { + return setters[name].apply(this, argsToArray(arguments, 1)); + } else { + return this[name] = val; + } + } + } + + + function defaultFunction() { + var meta = this.__meta || {}, + supers = meta.supers, + l = supers.length, superMeta = meta.superMeta, pos = superMeta.pos; + if (l > pos) { + var name = superMeta.name, f = superMeta.f, m; + do { + m = supers[pos][name]; + if ("function" === typeof m && (m = m._f || m) !== f) { + superMeta.pos = 1 + pos; + return m.apply(this, arguments); + } + } while (l > ++pos); + } + return null; + } + + + function functionWrapper(f, name) { + if (f.toString().match(SUPER_REGEXP)) { + var wrapper = function wrapper() { + var ret, meta = this.__meta || {}; + var orig = meta.superMeta; + meta.superMeta = {f: f, pos: 0, name: name}; + switch (arguments.length) { + case 0: + ret = f.call(this); + break; + case 1: + ret = f.call(this, arguments[0]); + break; + case 2: + ret = f.call(this, arguments[0], arguments[1]); + break; + + case 3: + ret = f.call(this, arguments[0], arguments[1], arguments[2]); + break; + default: + ret = f.apply(this, arguments); + } + meta.superMeta = orig; + return ret; + }; + wrapper._f = f; + return wrapper; + } else { + f._f = f; + return f; + } + } + + function defineMixinProps(child, proto) { + + var operations = proto.setters || {}, __setters = child.__setters__, __getters = child.__getters__; + for (var i in operations) { + if (!__setters.hasOwnProperty(i)) { //make sure that the setter isnt already there + __setters[i] = operations[i]; + } + } + operations = proto.getters || {}; + for (i in operations) { + if (!__getters.hasOwnProperty(i)) { //make sure that the setter isnt already there + __getters[i] = operations[i]; + } + } + for (var j in proto) { + if (j !== "getters" && j !== "setters") { + var p = proto[j]; + if ("function" === typeof p) { + if (!child.hasOwnProperty(j)) { + child[j] = functionWrapper(defaultFunction, j); + } + } else { + child[j] = p; + } + } + } + } + + function mixin() { + var args = argsToArray(arguments), l = args.length; + var child = this.prototype; + var childMeta = child.__meta, thisMeta = this.__meta, bases = child.__meta.bases, staticBases = bases.slice(), + staticSupers = thisMeta.supers || [], supers = childMeta.supers || []; + for (var i = 0; i < l; i++) { + var m = args[i], mProto = m.prototype; + var protoMeta = mProto.__meta, meta = m.__meta; + !protoMeta && (protoMeta = (mProto.__meta = {proto: mProto || {}})); + !meta && (meta = (m.__meta = {proto: m.__proto__ || {}})); + defineMixinProps(child, protoMeta.proto || {}); + defineMixinProps(this, meta.proto || {}); + //copy the bases for static, + + mixinSupers(m.prototype, supers, bases); + mixinSupers(m, staticSupers, staticBases); + } + return this; + } + + function mixinSupers(sup, arr, bases) { + var meta = sup.__meta; + !meta && (meta = (sup.__meta = {})); + var unique = sup.__meta.unique; + !unique && (meta.unique = "declare" + ++classCounter); + //check it we already have this super mixed into our prototype chain + //if true then we have already looped their supers! + if (indexOf(bases, unique) === -1) { + //add their id to our bases + bases.push(unique); + var supers = sup.__meta.supers || [], i = supers.length - 1 || 0; + while (i >= 0) { + mixinSupers(supers[i--], arr, bases); + } + arr.unshift(sup); + } + } + + function defineProps(child, proto) { + var operations = proto.setters, + __setters = child.__setters__, + __getters = child.__getters__; + if (operations) { + for (var i in operations) { + __setters[i] = operations[i]; + } + } + operations = proto.getters || {}; + if (operations) { + for (i in operations) { + __getters[i] = operations[i]; + } + } + for (i in proto) { + if (i != "getters" && i != "setters") { + var f = proto[i]; + if ("function" === typeof f) { + var meta = f.__meta || {}; + if (!meta.isConstructor) { + child[i] = functionWrapper(f, i); + } else { + child[i] = f; + } + } else { + child[i] = f; + } + } + } + } - var slice = Array.prototype.slice, undef; + function _export(obj, name) { + if (obj && name) { + obj[name] = this; + } else { + obj.exports = obj = this; + } + return this; + } - function indexOf(arr, item) { - if (arr && arr.length) { - for (var i = 0, l = arr.length; i < l; i++) { - if (arr[i] === item) { - return i; + function extend(proto) { + return declare(this, proto); + } + + function getNew(ctor) { + // create object with correct prototype using a do-nothing + // constructor + forceNew.prototype = ctor.prototype; + var t = new forceNew(); + forceNew.prototype = null; // clean up + return t; + } + + + function __declare(child, sup, proto) { + var childProto = {}, supers = []; + var unique = "declare" + ++classCounter, bases = [], staticBases = []; + var instanceSupers = [], staticSupers = []; + var meta = { + supers: instanceSupers, + unique: unique, + bases: bases, + superMeta: { + f: null, + pos: 0, + name: null + } + }; + var childMeta = { + supers: staticSupers, + unique: unique, + bases: staticBases, + isConstructor: true, + superMeta: { + f: null, + pos: 0, + name: null + } + }; + + if (isHash(sup) && !proto) { + proto = sup; + sup = Base; + } + + if ("function" === typeof sup || isArray(sup)) { + supers = isArray(sup) ? sup : [sup]; + sup = supers.shift(); + child.__meta = childMeta; + childProto = getNew(sup); + childProto.__meta = meta; + childProto.__getters__ = merge({}, childProto.__getters__ || {}); + childProto.__setters__ = merge({}, childProto.__setters__ || {}); + child.__getters__ = merge({}, child.__getters__ || {}); + child.__setters__ = merge({}, child.__setters__ || {}); + mixinSupers(sup.prototype, instanceSupers, bases); + mixinSupers(sup, staticSupers, staticBases); + } else { + child.__meta = childMeta; + childProto.__meta = meta; + childProto.__getters__ = childProto.__getters__ || {}; + childProto.__setters__ = childProto.__setters__ || {}; + child.__getters__ = child.__getters__ || {}; + child.__setters__ = child.__setters__ || {}; + } + child.prototype = childProto; + if (proto) { + var instance = meta.proto = proto.instance || {}; + var stat = childMeta.proto = proto.static || {}; + stat.init = stat.init || defaultFunction; + defineProps(childProto, instance); + defineProps(child, stat); + if (!instance.hasOwnProperty("constructor")) { + childProto.constructor = instance.constructor = functionWrapper(defaultFunction, "constructor"); + } else { + childProto.constructor = functionWrapper(instance.constructor, "constructor"); + } + } else { + meta.proto = {}; + childMeta.proto = {}; + child.init = functionWrapper(defaultFunction, "init"); + childProto.constructor = functionWrapper(defaultFunction, "constructor"); + } + if (supers.length) { + mixin.apply(child, supers); + } + if (sup) { + //do this so we mixin our super methods directly but do not ov + merge(child, merge(merge({}, sup), child)); + } + childProto._super = child._super = callSuper; + childProto._getSuper = child._getSuper = getSuper; + childProto._static = child; + } + + function declare(sup, proto) { + function declared() { + this.constructor.apply(this, arguments); + } + + __declare(declared, sup, proto); + return declared.init() || declared; + } + + function singleton(sup, proto) { + var retInstance; + + function declaredSingleton() { + if (!retInstance) { + this.constructor.apply(this, arguments); + retInstance = this; + } + return retInstance; + } + + __declare(declaredSingleton, sup, proto); + return declaredSingleton.init() || declaredSingleton; + } + + Base = declare({ + instance: { + "get": getter, + "set": setter + }, + + "static": { + "get": getter, + "set": setter, + mixin: mixin, + extend: extend, + as: _export + } + }); + + declare.singleton = singleton; + return declare; + } + + if ("undefined" !== typeof exports) { + if ("undefined" !== typeof module && module.exports) { + module.exports = createDeclared(); + } + } else if ("function" === typeof define && define.amd) { + define(createDeclared); + } else { + this.declare = createDeclared(); + } +}()); + + + + +},{}],62:[function(require,module,exports){ +module.exports = require("./declare.js"); +},{"./declare.js":61}],63:[function(require,module,exports){ +var Buffer=require("__browserify_Buffer").Buffer;(function () { + "use strict"; + + function defineIsa(extended) { + + var pSlice = Array.prototype.slice; + + var hasOwn = Object.prototype.hasOwnProperty; + var toStr = Object.prototype.toString; + + function argsToArray(args, slice) { + slice = slice || 0; + return pSlice.call(args, slice); + } + + function keys(obj) { + var ret = []; + for (var i in obj) { + if (hasOwn.call(obj, i)) { + ret.push(i); + } + } + return ret; + } + + //taken from node js assert.js + //https://github.com/joyent/node/blob/master/lib/assert.js + function deepEqual(actual, expected) { + // 7.1. All identical values are equivalent, as determined by ===. + if (actual === expected) { + return true; + + } else if (typeof Buffer !== "undefined" && Buffer.isBuffer(actual) && Buffer.isBuffer(expected)) { + if (actual.length !== expected.length) { + return false; + } + for (var i = 0; i < actual.length; i++) { + if (actual[i] !== expected[i]) { + return false; } } + return true; + + // 7.2. If the expected value is a Date object, the actual value is + // equivalent if it is also a Date object that refers to the same time. + } else if (isDate(actual) && isDate(expected)) { + return actual.getTime() === expected.getTime(); + + // 7.3 If the expected value is a RegExp object, the actual value is + // equivalent if it is also a RegExp object with the same source and + // properties (`global`, `multiline`, `lastIndex`, `ignoreCase`). + } else if (isRegExp(actual) && isRegExp(expected)) { + return actual.source === expected.source && + actual.global === expected.global && + actual.multiline === expected.multiline && + actual.lastIndex === expected.lastIndex && + actual.ignoreCase === expected.ignoreCase; + + // 7.4. Other pairs that do not both pass typeof value == 'object', + // equivalence is determined by ==. + } else if (isString(actual) && isString(expected) && actual !== expected) { + return false; + } else if (typeof actual !== 'object' && typeof expected !== 'object') { + return actual === expected; + + // 7.5 For all other Object pairs, including Array objects, equivalence is + // determined by having the same number of owned properties (as verified + // with Object.prototype.hasOwnProperty.call), the same set of keys + // (although not necessarily the same order), equivalent values for every + // corresponding key, and an identical 'prototype' property. Note: this + // accounts for both named and indexed properties on Arrays. + } else { + return objEquiv(actual, expected); } - return -1; } - function isArray(obj) { - return Object.prototype.toString.call(obj) === "[object Array]"; - } - var merge = (function merger() { - function _merge(target, source, exclude) { - var name, s; - for (name in source) { - if (source.hasOwnProperty(name) && indexOf(exclude, name) === -1) { - s = source[name]; - if (!(name in target) || (target[name] !== s)) { - target[name] = s; - } - } + function objEquiv(a, b) { + var key; + if (isUndefinedOrNull(a) || isUndefinedOrNull(b)) { + return false; + } + // an identical 'prototype' property. + if (a.prototype !== b.prototype) { + return false; + } + //~~~I've managed to break Object.keys through screwy arguments passing. + // Converting to array solves the problem. + if (isArguments(a)) { + if (!isArguments(b)) { + return false; } - return target; + a = pSlice.call(a); + b = pSlice.call(b); + return deepEqual(a, b); } - - return function merge(obj) { - if (!obj) { - obj = {}; + try { + var ka = keys(a), + kb = keys(b), + i; + // having the same number of owned properties (keys incorporates + // hasOwnProperty) + if (ka.length !== kb.length) { + return false; } - var l = arguments.length; - var exclude = arguments[arguments.length - 1]; - if (isArray(exclude)) { - l--; - } else { - exclude = []; + //the same set of keys (although not necessarily the same order), + ka.sort(); + kb.sort(); + //~~~cheap key test + for (i = ka.length - 1; i >= 0; i--) { + if (ka[i] !== kb[i]) { + return false; + } } - for (var i = 1; i < l; i++) { - _merge(obj, arguments[i], exclude); + //equivalent values for every corresponding key, and + //~~~possibly expensive deep test + for (i = ka.length - 1; i >= 0; i--) { + key = ka[i]; + if (!deepEqual(a[key], b[key])) { + return false; + } } - return obj; // Object - }; - }()); + } catch (e) {//happens when one is a string literal and the other isn't + return false; + } + return true; + } - function extender(supers) { - supers = supers || []; - var Base = declare({ - instance: { - constructor: function (value) { - this._value = value; - }, + var isFunction = function (obj) { + return toStr.call(obj) === '[object Function]'; + }; - value: function () { - return this._value; - }, + //ie hack + if ("undefined" !== typeof window && !isFunction(window.alert)) { + (function (alert) { + isFunction = function (obj) { + return toStr.call(obj) === '[object Function]' || obj === alert; + }; + }(window.alert)); + } - eq: function eq(val) { - return this["__extender__"](this._value === val); - }, + function isObject(obj) { + var undef; + return obj !== null && typeof obj === "object"; + } - neq: function neq(other) { - return this["__extender__"](this._value !== other); - }, - print: function () { - console.log(this._value); - return this; - } - } - }), defined = []; + function isHash(obj) { + var ret = isObject(obj); + return ret && obj.constructor === Object && !obj.nodeType && !obj.setInterval; + } - function addMethod(proto, name, func) { - if ("function" !== typeof func) { - throw new TypeError("when extending type you must provide a function"); - } - var extendedMethod; - if (name === "constructor") { - extendedMethod = function () { - this._super(arguments); - func.apply(this, arguments); - }; - } else { - extendedMethod = function extendedMethod() { - var args = slice.call(arguments); - args.unshift(this._value); - var ret = func.apply(this, args); - return ret !== undef ? this["__extender__"](ret) : this; - }; - } - proto[name] = extendedMethod; + function isEmpty(object) { + if (isArguments(object)) { + return object.length === 0; + } else if (isObject(object)) { + return keys(object).length === 0; + } else if (isString(object) || isArray(object)) { + return object.length === 0; } + return true; + } - function addNoWrapMethod(proto, name, func) { - if ("function" !== typeof func) { - throw new TypeError("when extending type you must provide a function"); - } - var extendedMethod; - if (name === "constructor") { - extendedMethod = function () { - this._super(arguments); - func.apply(this, arguments); - }; - } else { - extendedMethod = function extendedMethod() { - var args = slice.call(arguments); - args.unshift(this._value); - return func.apply(this, args); - }; - } - proto[name] = extendedMethod; - } + function isBoolean(obj) { + return obj === true || obj === false || toStr.call(obj) === "[object Boolean]"; + } - function decorateProto(proto, decoration, nowrap) { - for (var i in decoration) { - if (decoration.hasOwnProperty(i)) { - if (i !== "getters" && i !== "setters") { - if (i === "noWrap") { - decorateProto(proto, decoration[i], true); - } else if (nowrap) { - addNoWrapMethod(proto, i, decoration[i]); - } else { - addMethod(proto, i, decoration[i]); - } - } else { - proto[i] = decoration[i]; - } - } - } - } + function isUndefined(obj) { + return typeof obj === 'undefined'; + } - function _extender(obj) { - var ret = obj, i, l; - if (!(obj instanceof Base)) { - var OurBase = Base; - for (i = 0, l = defined.length; i < l; i++) { - var definer = defined[i]; - if (definer[0](obj)) { - OurBase = OurBase.extend({instance: definer[1]}); - } - } - ret = new OurBase(obj); - ret["__extender__"] = _extender; - } - return ret; - } + function isDefined(obj) { + return !isUndefined(obj); + } - function always() { - return true; - } + function isUndefinedOrNull(obj) { + return isUndefined(obj) || isNull(obj); + } - function define(tester, decorate) { - if (arguments.length) { - if (typeof tester === "object") { - decorate = tester; - tester = always; - } - decorate = decorate || {}; - var proto = {}; - decorateProto(proto, decorate); - //handle browsers like which skip over the constructor while looping - if (!proto.hasOwnProperty("constructor")) { - if (decorate.hasOwnProperty("constructor")) { - addMethod(proto, "constructor", decorate.constructor); - } else { - proto.constructor = function () { - this._super(arguments); - }; - } - } - defined.push([tester, proto]); - } - return _extender; - } + function isNull(obj) { + return obj === null; + } - function extend(supr) { - if (supr && supr.hasOwnProperty("__defined__")) { - _extender["__defined__"] = defined = defined.concat(supr["__defined__"]); - } - merge(_extender, supr, ["define", "extend", "expose", "__defined__"]); - return _extender; - } - _extender.define = define; - _extender.extend = extend; - _extender.expose = function expose() { - var methods; - for (var i = 0, l = arguments.length; i < l; i++) { - methods = arguments[i]; - if (typeof methods === "object") { - merge(_extender, methods, ["define", "extend", "expose", "__defined__"]); - } - } - return _extender; + var isArguments = function _isArguments(object) { + return toStr.call(object) === '[object Arguments]'; + }; + + if (!isArguments(arguments)) { + isArguments = function _isArguments(obj) { + return !!(obj && hasOwn.call(obj, "callee")); }; - _extender["__defined__"] = defined; + } - return _extender; + function isInstanceOf(obj, clazz) { + if (isFunction(clazz)) { + return obj instanceof clazz; + } else { + return false; + } } - return { - define: function () { - return extender().define.apply(extender, arguments); - }, + function isRegExp(obj) { + return toStr.call(obj) === '[object RegExp]'; + } - extend: function (supr) { - return extender().define().extend(supr); - } + var isArray = Array.isArray || function isArray(obj) { + return toStr.call(obj) === "[object Array]"; }; - } + function isDate(obj) { + return toStr.call(obj) === '[object Date]'; + } - if ("undefined" !== typeof exports) { - if ("undefined" !== typeof module && module.exports) { - module.exports = defineExtender(require("declare.js")); + function isString(obj) { + return toStr.call(obj) === '[object String]'; + } + function isNumber(obj) { + return toStr.call(obj) === '[object Number]'; } - } else if ("function" === typeof define && define.amd) { - define(["declare"], function (declare) { - return defineExtender(declare); - }); - } else { - this.extender = defineExtender(this.declare); - } -}).call(this); -},{"declare.js":45}],48:[function(require,module,exports){ -module.exports = require("./extender.js"); -},{"./extender.js":47}],49:[function(require,module,exports){ -(function () { - "use strict"; + function isTrue(obj) { + return obj === true; + } - function defineFunction(extended, is, args) { + function isFalse(obj) { + return obj === false; + } - var isArray = is.isArray, - isObject = is.isObject, - isString = is.isString, - isFunction = is.isFunction, - argsToArray = args.argsToArray; + function isNotNull(obj) { + return !isNull(obj); + } - function hitch(scope, method, args) { - args = argsToArray(arguments, 2); - if ((isString(method) && !(method in scope))) { - throw new Error(method + " property not defined in scope"); - } else if (!isString(method) && !isFunction(method)) { - throw new Error(method + " is not a function"); - } - if (isString(method)) { - return function () { - var func = scope[method]; - if (isFunction(func)) { - var scopeArgs = args.concat(argsToArray(arguments)); - return func.apply(scope, scopeArgs); - } else { - return func; - } - }; - } else { - if (args.length) { - return function () { - var scopeArgs = args.concat(argsToArray(arguments)); - return method.apply(scope, scopeArgs); - }; - } else { + function isEq(obj, obj2) { + /*jshint eqeqeq:false*/ + return obj == obj2; + } - return function () { - return method.apply(scope, arguments); - }; + function isNeq(obj, obj2) { + /*jshint eqeqeq:false*/ + return obj != obj2; + } + + function isSeq(obj, obj2) { + return obj === obj2; + } + + function isSneq(obj, obj2) { + return obj !== obj2; + } + + function isIn(obj, arr) { + if ((isArray(arr) && Array.prototype.indexOf) || isString(arr)) { + return arr.indexOf(obj) > -1; + } else if (isArray(arr)) { + for (var i = 0, l = arr.length; i < l; i++) { + if (isEq(obj, arr[i])) { + return true; + } } } + return false; } + function isNotIn(obj, arr) { + return !isIn(obj, arr); + } - function applyFirst(method, args) { - args = argsToArray(arguments, 1); - if (!isString(method) && !isFunction(method)) { - throw new Error(method + " must be the name of a property or function to execute"); + function isLt(obj, obj2) { + return obj < obj2; + } + + function isLte(obj, obj2) { + return obj <= obj2; + } + + function isGt(obj, obj2) { + return obj > obj2; + } + + function isGte(obj, obj2) { + return obj >= obj2; + } + + function isLike(obj, reg) { + if (isString(reg)) { + return ("" + obj).match(reg) !== null; + } else if (isRegExp(reg)) { + return reg.test(obj); } - if (isString(method)) { - return function () { - var scopeArgs = argsToArray(arguments), scope = scopeArgs.shift(); - var func = scope[method]; - if (isFunction(func)) { - scopeArgs = args.concat(scopeArgs); - return func.apply(scope, scopeArgs); - } else { - return func; - } - }; - } else { - return function () { - var scopeArgs = argsToArray(arguments), scope = scopeArgs.shift(); - scopeArgs = args.concat(scopeArgs); - return method.apply(scope, scopeArgs); - }; + return false; + } + + function isNotLike(obj, reg) { + return !isLike(obj, reg); + } + + function contains(arr, obj) { + return isIn(obj, arr); + } + + function notContains(arr, obj) { + return !isIn(obj, arr); + } + + function containsAt(arr, obj, index) { + if (isArray(arr) && arr.length > index) { + return isEq(arr[index], obj); } + return false; } + function notContainsAt(arr, obj, index) { + if (isArray(arr)) { + return !isEq(arr[index], obj); + } + return false; + } - function hitchIgnore(scope, method, args) { - args = argsToArray(arguments, 2); - if ((isString(method) && !(method in scope))) { - throw new Error(method + " property not defined in scope"); - } else if (!isString(method) && !isFunction(method)) { - throw new Error(method + " is not a function"); + function has(obj, prop) { + return hasOwn.call(obj, prop); + } + + function notHas(obj, prop) { + return !has(obj, prop); + } + + function length(obj, l) { + if (has(obj, "length")) { + return obj.length === l; } - if (isString(method)) { - return function () { - var func = scope[method]; - if (isFunction(func)) { - return func.apply(scope, args); - } else { - return func; - } - }; - } else { - return function () { - return method.apply(scope, args); - }; + return false; + } + + function notLength(obj, l) { + if (has(obj, "length")) { + return obj.length !== l; } + return false; } + var isa = { + isFunction: isFunction, + isObject: isObject, + isEmpty: isEmpty, + isHash: isHash, + isNumber: isNumber, + isString: isString, + isDate: isDate, + isArray: isArray, + isBoolean: isBoolean, + isUndefined: isUndefined, + isDefined: isDefined, + isUndefinedOrNull: isUndefinedOrNull, + isNull: isNull, + isArguments: isArguments, + instanceOf: isInstanceOf, + isRegExp: isRegExp, + deepEqual: deepEqual, + isTrue: isTrue, + isFalse: isFalse, + isNotNull: isNotNull, + isEq: isEq, + isNeq: isNeq, + isSeq: isSeq, + isSneq: isSneq, + isIn: isIn, + isNotIn: isNotIn, + isLt: isLt, + isLte: isLte, + isGt: isGt, + isGte: isGte, + isLike: isLike, + isNotLike: isNotLike, + contains: contains, + notContains: notContains, + has: has, + notHas: notHas, + isLength: length, + isNotLength: notLength, + containsAt: containsAt, + notContainsAt: notContainsAt + }; + + var tester = { + constructor: function () { + this._testers = []; + }, - function hitchAll(scope) { - var funcs = argsToArray(arguments, 1); - if (!isObject(scope) && !isFunction(scope)) { - throw new TypeError("scope must be an object"); - } - if (funcs.length === 1 && isArray(funcs[0])) { - funcs = funcs[0]; - } - if (!funcs.length) { - funcs = []; - for (var k in scope) { - if (scope.hasOwnProperty(k) && isFunction(scope[k])) { - funcs.push(k); - } + noWrap: { + tester: function () { + var testers = this._testers; + return function tester(value) { + var isa = false; + for (var i = 0, l = testers.length; i < l && !isa; i++) { + isa = testers[i](value); + } + return isa; + }; } } - for (var i = 0, l = funcs.length; i < l; i++) { - scope[funcs[i]] = hitch(scope, scope[funcs[i]]); - } - return scope; - } + }; + var switcher = { + constructor: function () { + this._cases = []; + this.__default = null; + }, - function partial(method, args) { - args = argsToArray(arguments, 1); - if (!isString(method) && !isFunction(method)) { - throw new Error(method + " must be the name of a property or function to execute"); - } - if (isString(method)) { - return function () { - var func = this[method]; - if (isFunction(func)) { - var scopeArgs = args.concat(argsToArray(arguments)); - return func.apply(this, scopeArgs); - } else { - return func; - } - }; - } else { - return function () { - var scopeArgs = args.concat(argsToArray(arguments)); - return method.apply(this, scopeArgs); - }; + def: function (val, fn) { + this.__default = fn; + }, + + noWrap: { + switcher: function () { + var testers = this._cases, __default = this.__default; + return function tester() { + var handled = false, args = argsToArray(arguments), caseRet; + for (var i = 0, l = testers.length; i < l && !handled; i++) { + caseRet = testers[i](args); + if (caseRet.length > 1) { + if (caseRet[1] || caseRet[0]) { + return caseRet[1]; + } + } + } + if (!handled && __default) { + return __default.apply(this, args); + } + }; + } } - } + }; - function curryFunc(f, execute) { - return function () { - var args = argsToArray(arguments); - return execute ? f.apply(this, arguments) : function () { - return f.apply(this, args.concat(argsToArray(arguments))); - }; + function addToTester(func) { + tester[func] = function isaTester() { + this._testers.push(isa[func]); }; } - - function curry(depth, cb, scope) { - var f; - if (scope) { - f = hitch(scope, cb); - } else { - f = cb; - } - if (depth) { - var len = depth - 1; - for (var i = len; i >= 0; i--) { - f = curryFunc(f, i === len); + function addToSwitcher(func) { + switcher[func] = function isaTester() { + var args = argsToArray(arguments, 1), isFunc = isa[func], handler, doBreak = true; + if (args.length <= isFunc.length - 1) { + throw new TypeError("A handler must be defined when calling using switch"); + } else { + handler = args.pop(); + if (isBoolean(handler)) { + doBreak = handler; + handler = args.pop(); + } + } + if (!isFunction(handler)) { + throw new TypeError("handler must be defined"); } + this._cases.push(function (testArgs) { + if (isFunc.apply(isa, testArgs.concat(args))) { + return [doBreak, handler.apply(this, testArgs)]; + } + return [false]; + }); + }; + } + + for (var i in isa) { + if (hasOwn.call(isa, i)) { + addToSwitcher(i); + addToTester(i); } - return f; } - return extended - .define(isObject, { - bind: hitch, - bindAll: hitchAll, - bindIgnore: hitchIgnore, - curry: function (scope, depth, fn) { - return curry(depth, fn, scope); - } - }) - .define(isFunction, { - bind: function (fn, obj) { - return hitch.apply(this, [obj, fn].concat(argsToArray(arguments, 2))); - }, - bindIgnore: function (fn, obj) { - return hitchIgnore.apply(this, [obj, fn].concat(argsToArray(arguments, 2))); - }, - partial: partial, - applyFirst: applyFirst, - curry: function (fn, num, scope) { - return curry(num, fn, scope); - }, - noWrap: { - f: function () { - return this.value(); - } - } - }) - .define(isString, { - bind: function (str, scope) { - return hitch(scope, str); - }, - bindIgnore: function (str, scope) { - return hitchIgnore(scope, str); - }, - partial: partial, - applyFirst: applyFirst, - curry: function (fn, depth, scope) { - return curry(depth, fn, scope); - } - }) - .expose({ - bind: hitch, - bindAll: hitchAll, - bindIgnore: hitchIgnore, - partial: partial, - applyFirst: applyFirst, - curry: curry - }); + var is = extended.define(isa).expose(isa); + is.tester = extended.define(tester); + is.switcher = extended.define(switcher); + return is; } if ("undefined" !== typeof exports) { if ("undefined" !== typeof module && module.exports) { - module.exports = defineFunction(require("extended"), require("is-extended"), require("arguments-extended")); + module.exports = defineIsa(require("extended")); } } else if ("function" === typeof define && define.amd) { - define(["extended", "is-extended", "arguments-extended"], function (extended, is, args) { - return defineFunction(extended, is, args); + define(["extended"], function (extended) { + return defineIsa(extended); }); } else { - this.functionExtended = defineFunction(this.extended, this.isExtended, this.argumentsExtended); + this.isExtended = defineIsa(this.extended); } }).call(this); - - - - - -},{"arguments-extended":41,"extended":46,"is-extended":56}],50:[function(require,module,exports){ +},{"__browserify_Buffer":67,"extended":58}],64:[function(require,module,exports){ var process=require("__browserify_process");if (!process.EventEmitter) process.EventEmitter = function () {}; var EventEmitter = exports.EventEmitter = process.EventEmitter; @@ -9128,10 +12015,10 @@ EventEmitter.listenerCount = function(emitter, type) { return ret; }; -},{"__browserify_process":54}],51:[function(require,module,exports){ +},{"__browserify_process":68}],65:[function(require,module,exports){ // nothing to see here... no file methods for the browser -},{}],52:[function(require,module,exports){ +},{}],66:[function(require,module,exports){ var process=require("__browserify_process");function filter (xs, fn) { var res = []; for (var i = 0; i < xs.length; i++) { @@ -9310,7 +12197,7 @@ exports.relative = function(from, to) { exports.sep = '/'; -},{"__browserify_process":54}],53:[function(require,module,exports){ +},{"__browserify_process":68}],67:[function(require,module,exports){ require=(function(e,t,n,r){function i(r){if(!n[r]){if(!t[r]){if(e)return e(r);throw new Error("Cannot find module '"+r+"'")}var s=n[r]={exports:{}};t[r][0](function(e){var n=t[r][1][e];return i(n?n:e)},s,s.exports)}return n[r].exports}for(var s=0;s 1) { - root = insertAdjustBalance(root, dir); - done.done = true; + var it = root, upd = [], up = [], top = 0, dir; + while (true) { + dir = upd[top] = cmp(data, it.data) === -1 ? "left" : "right"; + up[top++] = it; + if (!it[dir]) { + it[dir] = makeNode(data); + break; + } + it = it[dir]; + } + if (!it[dir]) { + return null; + } + while (--top >= 0) { + up[top].balance += upd[top] === "right" ? -1 : 1; + if (up[top].balance === 0) { + break; + } else if (abs(up[top].balance) > 1) { + up[top] = insertAdjustBalance(up[top], upd[top]); + if (top !== 0) { + up[top - 1][upd[top - 1]] = up[top]; + } else { + tree.__root = up[0]; + } + break; } } } + } - return root; - }; - - var remove = function (root, data, done, compare) { - var dir, cmp, save, b; - if (root) { - //Remove node - cmp = compare(data, root.data); - if (cmp === 0) { - // Unlink and fix parent - var l = root.left, r = root.right; - if (!l || !r) { - dir = !l ? "right" : "left"; - save = root[dir]; - return save; + function remove(tree, data, cmp) { + var root = tree.__root; + if (root !== null && root !== undefined) { + var it = root, top = 0, up = [], upd = [], done = {done: false}, dir, compare; + while (true) { + if (!it) { + return; + } else if ((compare = cmp(data, it.data)) === 0) { + break; } - else { - var heir = l; - while ((r = heir.right) !== null) { - heir = r; - } - root.data = heir.data; - //reset and start searching - data = heir.data; + dir = upd[top] = compare === -1 ? "left" : "right"; + up[top++] = it; + it = it[dir]; + } + var l = it.left, r = it.right; + if (!l || !r) { + dir = !l ? "right" : "left"; + if (top !== 0) { + up[top - 1][upd[top - 1]] = it[dir]; + } else { + tree.__root = it[dir]; + } + } else { + var heir = l; + upd[top] = "left"; + up[top++] = it; + while (heir.right) { + upd[top] = "right"; + up[top++] = heir; + heir = heir.right; } + it.data = heir.data; + up[top - 1][up[top - 1] === it ? "left" : "right"] = heir.left; } - dir = compare(root.data, data) === -1 ? "right" : "left"; - root[dir] = remove(root[dir], data, done, compare); - if (!done.done) { - /* Update balance factors */ - b = (root.balance += (dir === "left" ? 1 : -1)); - /* Terminate or rebalance as necessary */ - var a = abs(b); - if (a === 1) { - done.done = true; - } else if (a > 1) { - root = removeAdjustBalance(root, dir, done); + while (--top >= 0 && !done.done) { + up[top].balance += upd[top] === "left" ? -1 : +1; + if (abs(up[top].balance) === 1) { + break; + } else if (abs(up[top].balance) > 1) { + up[top] = removeAdjustBalance(up[top], upd[top], done); + if (top !== 0) { + up[top - 1][upd[top - 1]] = up[top]; + } else { + tree.__root = up[0]; + } } } } - return root; - }; + } return Tree.extend({ instance: { insert: function (data) { - var done = {done: false}; - this.__root = insert(this.__root, data, done, this.compare); + insert(this, data, this.compare); }, remove: function (data) { - this.__root = remove(this.__root, data, {done: false}, this.compare); + remove(this, data, this.compare); }, __printNode: function (node, level) { @@ -14623,12 +17529,13 @@ var Buffer=require("__browserify_Buffer").Buffer;(function () { instance: { insert: function (data) { if (!this.__root) { - return (this.__root = { + this.__root = { data: data, parent: null, left: null, right: null - }); + }; + return this.__root; } var compare = this.compare; var root = this.__root; @@ -14900,7 +17807,7 @@ var Buffer=require("__browserify_Buffer").Buffer;(function () { -},{"array-extended":42,"declare.js":45,"extended":46,"is-extended":56,"string-extended":60}],58:[function(require,module,exports){ +},{"array-extended":49,"declare.js":52,"extended":53,"is-extended":70,"string-extended":74}],72:[function(require,module,exports){ (function () { "use strict"; /*global extended isExtended*/ @@ -15118,7 +18025,7 @@ var Buffer=require("__browserify_Buffer").Buffer;(function () { -},{"array-extended":42,"extended":46,"is-extended":56}],59:[function(require,module,exports){ +},{"array-extended":49,"extended":53,"is-extended":70}],73:[function(require,module,exports){ var process=require("__browserify_process");(function () { "use strict"; /*global setImmediate, MessageChannel*/ @@ -15623,7 +18530,7 @@ var process=require("__browserify_process");(function () { -},{"__browserify_process":54,"arguments-extended":41,"array-extended":42,"declare.js":45,"extended":46,"function-extended":49,"is-extended":56}],60:[function(require,module,exports){ +},{"__browserify_process":68,"arguments-extended":48,"array-extended":49,"declare.js":52,"extended":53,"function-extended":56,"is-extended":70}],74:[function(require,module,exports){ (function () { "use strict"; @@ -16270,5 +19177,5 @@ var process=require("__browserify_process");(function () { -},{"array-extended":42,"date-extended":43,"extended":46,"is-extended":56}]},{},[1]) +},{"array-extended":49,"date-extended":50,"extended":53,"is-extended":70}]},{},[1]) ; \ No newline at end of file diff --git a/nools.min.js b/nools.min.js index 744d562..f4a6d0d 100644 --- a/nools.min.js +++ b/nools.min.js @@ -1,10 +1,11 @@ -/*! nools - v0.2.1 - 2013-11-08 +/*! nools - v0.2.2 - 2013-11-20 * http://c2fo.github.com/nools * Copyright (c) 2013 Doug Martin (http://c2fo.com); Licensed */ -!function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);throw new Error("Cannot find module '"+g+"'")}var j=c[g]={exports:{}};b[g][0].call(j.exports,function(a){var c=b[g][1][a];return e(c?c:a)},j,j.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;gc&&g>c&&c++;);var h=d[c]-e[c];return h||(h=f-g),h}function g(a,b){return a.recency-b.recency}var h=a("./extended").map,i={salience:d,bucketCounter:e,factRecency:f,activationRecency:g};c.strategies=i,c.strategy=function(a){a=h(a,function(a){return i[a]});var b=a.length;return function(c,d){var e=-1,f=0,g=c===d||c.name===d.name&&c.hashCode===d.hashCode;if(!g){for(;++e0?1:-1}return f}}},{"./extended":12}],8:[function(a,b,c){"use strict";var d,e=a("./extended"),f=e.deepEqual,g=e.merge,h=e.instanceOf,i=e.filter,j=e.declare,k=0,l=j({instance:{constructor:function(b,c){d||(d=a("./constraintMatcher")),this.id=k++,this.type=b,this.constraint=c,e.bindAll(this,["assert"])},assert:function(){throw new Error("not implemented")},equal:function(a){return h(a,this._static)&&this.get("alias")===a.get("alias")&&e.deepEqual(this.constraint,a.constraint)},getters:{variables:function(){return[this.get("alias")]}}}});l.extend({instance:{constructor:function(a){this._super(["object",a])},assert:function(a){return a instanceof this.constraint||a.constructor===this.constraint},equal:function(a){return h(a,this._static)&&this.constraint===a.constraint}}}).as(c,"ObjectConstraint"),l.extend({instance:{constructor:function(a,b){this._super(["equality",a]),b=b||{},this.pattern=b.pattern,this._matcher=d.getMatcher(a,b.scope||{})},assert:function(a){return this._matcher(a)}}}).as(c,"EqualityConstraint"),l.extend({instance:{constructor:function(){this._super(["equality",[!0]])},equal:function(a){return h(a,this._static)&&this.get("alias")===a.get("alias")},assert:function(){return!0}}}).as(c,"TrueConstraint"),l.extend({instance:{constructor:function(a,b){this.cache={},this._super(["reference",a]),b=b||{},this.values=[],this.pattern=b.pattern,this._options=b,this._matcher=d.getMatcher(a,b.scope||{})},assert:function(a){try{return this._matcher(a)}catch(b){throw new Error("Error with evaluating pattern "+this.pattern+" "+b.message)}},merge:function(a){var b=this;return a instanceof this._static&&(b=new this._static([this.constraint,a.constraint,"and"],g({},this._options,this._options)),b._alias=this._alias||a._alias,b.vars=this.vars.concat(a.vars)),b},equal:function(a){return h(a,this._static)&&e.deepEqual(this.constraint,a.constraint)},getters:{variables:function(){return this.vars},alias:function(){return this._alias}},setters:{alias:function(a){this._alias=a,this.vars=i(d.getIdentifiers(this.constraint),function(b){return b!==a})}}}}).as(c,"ReferenceConstraint"),l.extend({instance:{constructor:function(a){this._super(["hash",a])},equal:function(a){return e.instanceOf(a,this._static)&&this.get("alias")===a.get("alias")&&e.deepEqual(this.constraint,a.constraint)},assert:function(){return!0},getters:{variables:function(){return this.constraint}}}}).as(c,"HashConstraint"),l.extend({instance:{constructor:function(a,b){this.type="from",this.constraints=d.getSourceMatcher(a,(b||{}).scope||{}),e.bindAll(this,["assert"])},equal:function(a){return h(a,this._static)&&this.get("alias")===a.get("alias")&&f(this.constraints,a.constraints)},assert:function(a,b){return this.constraints(a,b)},getters:{variables:function(){return this.constraint}}}}).as(c,"FromConstraint")},{"./constraintMatcher":9,"./extended":12}],9:[function(a,b,c){"use strict";var d=a("./extended"),e=d.isArray,f=d.forEach,g=d.some,h=d.map,i=d.indexOf,j=d.isNumber,k=d.removeDuplicates,l=a("./constraint"),m={indexOf:d.indexOf,now:function(){return new Date},Date:function(a,b,c,d,e,f,g){var h=new Date;return j(a)&&h.setYear(a),j(b)&&h.setMonth(b),j(c)&&h.setDate(c),j(d)&&h.setHours(d),j(e)&&h.setMinutes(e),j(f)&&h.setSeconds(f),j(g)&&h.setMilliseconds(g),h},lengthOf:function(a,b){return a.length===b},isTrue:function(a){return a===!0},isFalse:function(a){return a===!1},isNotNull:function(a){return null!==a},dateCmp:function(a,b){return d.compare(a,b)}};f(["years","days","months","hours","minutes","seconds"],function(a){m[a+"FromNow"]=d[a+"FromNow"],m[a+"Ago"]=d[a+"Ago"]}),f(["isArray","isNumber","isHash","isObject","isDate","isBoolean","isString","isRegExp","isNull","isEmpty","isUndefined","isDefined","isUndefinedOrNull","isPromiseLike","isFunction","deepEqual"],function(a){var b=d[a];m[a]=function(){return b.apply(d,arguments)}});var n={equal:function(a,b){var c=!1;return a===b?c=!0:a[2]===b[2]&&(c=-1!==i(["string","number","boolean","regexp","identifier","null"],a[2])?a[0]===b[0]:"unary"===a[2]||"logicalNot"===a[2]?this.equal(a[0],b[0]):this.equal(a[0],b[0])&&this.equal(a[1],b[1])),c},getIdentifiers:function(a){var b=[],c=a[2];if("identifier"===c)return[a[0]];if("function"===c)b=b.concat(this.getIdentifiers(a[0])).concat(this.getIdentifiers(a[1]));else if("string"!==c&&"number"!==c&&"boolean"!==c&&"regexp"!==c&&"unary"!==c&&"unary"!==c)if("prop"===c){if(b=b.concat(this.getIdentifiers(a[0])),a[1])for(var d=a[1];e(d);){if("function"===d[2]){b=b.concat(this.getIdentifiers(d[1]));break}d=d[1]}}else a[0]&&(b=b.concat(this.getIdentifiers(a[0]))),a[1]&&(b=b.concat(this.getIdentifiers(a[1])));return k(b)},toConstraints:function(a,b){var c=[],d=b.alias,e=b.scope||{},f=a[2];return"and"===f?c=c.concat(this.toConstraints(a[0],b)).concat(this.toConstraints(a[1],b)):("composite"===f||"or"===f||"lt"===f||"gt"===f||"lte"===f||"gte"===f||"like"===f||"notLike"===f||"eq"===f||"neq"===f||"in"===f||"notIn"===f||"prop"===f||"propLookup"===f||"function"===f||"logicalNot"===f)&&(g(this.getIdentifiers(a),function(a){return!(a===d||a in m||a in e)})?c.push(new l.ReferenceConstraint(a,b)):c.push(new l.EqualityConstraint(a,b))),c},parse:function(a){return this[a[2]](a[0],a[1])},composite:function(a){return this.parse(a)},and:function(a,b){return["(",this.parse(a),"&&",this.parse(b),")"].join(" ")},or:function(a,b){return["(",this.parse(a),"||",this.parse(b),")"].join(" ")},prop:function(a,b){return"function"===b[2]?[this.parse(a),this.parse(b)].join("."):[this.parse(a),"['",this.parse(b),"']"].join("")},propLookup:function(a,b){return"function"===b[2]?[this.parse(a),this.parse(b)].join("."):[this.parse(a),"[",this.parse(b),"]"].join("")},unary:function(a){return-1*this.parse(a)},plus:function(a,b){return[this.parse(a),"+",this.parse(b)].join(" ")},minus:function(a,b){return[this.parse(a),"-",this.parse(b)].join(" ")},mult:function(a,b){return[this.parse(a),"*",this.parse(b)].join(" ")},div:function(a,b){return[this.parse(a),"/",this.parse(b)].join(" ")},mod:function(a,b){return[this.parse(a),"%",this.parse(b)].join(" ")},lt:function(a,b){return[this.parse(a),"<",this.parse(b)].join(" ")},gt:function(a,b){return[this.parse(a),">",this.parse(b)].join(" ")},lte:function(a,b){return[this.parse(a),"<=",this.parse(b)].join(" ")},gte:function(a,b){return[this.parse(a),">=",this.parse(b)].join(" ")},like:function(a,b){return[this.parse(b),".test(",this.parse(a),")"].join("")},notLike:function(a,b){return["!",this.parse(b),".test(",this.parse(a),")"].join("")},eq:function(a,b){return[this.parse(a),"===",this.parse(b)].join(" ")},neq:function(a,b){return[this.parse(a),"!==",this.parse(b)].join(" ")},"in":function(a,b){return["(indexOf(",this.parse(b),",",this.parse(a),")) != -1"].join("")},notIn:function(a,b){return["(indexOf(",this.parse(b),",",this.parse(a),")) == -1"].join("")},arguments:function(a,b){var c=[];return a&&c.push(this.parse(a)),b&&c.push(this.parse(b)),c.join(",")},array:function(a){var b=[];return a?(b=this.parse(a),e(b)?b:["[",b,"]"].join("")):["[",b.join(","),"]"].join("")},"function":function(a,b){var c=this.parse(b);return[this.parse(a),"(",c,")"].join("")},string:function(a){return"'"+a+"'"},number:function(a){return a},"boolean":function(a){return a},regexp:function(a){return a},identifier:function(a){return a},"null":function(){return"null"},logicalNot:function(a){return["!(",this.parse(a),")"].join("")}},o=c.toJs=function(a,b,c){var d=n.parse(a);b=b||{};var e=n.getIdentifiers(a),f="var indexOf = definedFuncs.indexOf;"+h(e,function(a){var c=["var ",a," = "];return m.hasOwnProperty(a)?c.push("definedFuncs['",a,"']"):b.hasOwnProperty(a)?c.push("scope['",a,"']"):c.push("'",a,"' in fact ? fact['",a,"'] : hash['",a,"']"),c.push(";"),c.join("")}).join("")+" return "+(c?c(d):d),g=new Function("fact, hash, definedFuncs, scope",f);return function(a,c){return g(a,c,m,b)}};c.getMatcher=function(a,b){return o(a,b,function(a){return"!!("+a+")"})},c.getSourceMatcher=function(a,b){return o(a,b,function(a){return a})},c.toConstraints=function(a,b){return n.toConstraints(a,b)},c.equal=function(a,b){return n.equal(a,b)},c.getIdentifiers=function(a){return n.getIdentifiers(a)}},{"./constraint":8,"./extended":12}],10:[function(a,b){"use strict";var c=a("./extended"),d=c.isBoolean,e=c.declare,f=c.merge,g=c.union,h=Array.prototype.slice,i=e({instance:{constructor:function(a){this.isMatch=!0,a instanceof this._static?(this.isMatch=a.isMatch,this.facts=h.call(a.facts),this.factIds=h.call(a.factIds),this.hashCode=this.factIds.join(":"),this.factHash=f({},a.factHash),this.recency=h.call(a.recency)):a?(this.facts=[a],this.factIds=[a.id],this.recency=[a.recency],this.hashCode=a.id+"",this.factHash=a.factHash||{}):(this.facts=[],this.factIds=[],this.factHash={},this.hashCode="")},merge:function(a){var b=new this._static;return b.isMatch=a.isMatch,b.facts=this.facts.concat(a.facts),b.factIds=this.factIds.concat(a.factIds),b.hashCode=b.factIds.join(":"),b.factHash=f({},this.factHash,a.factHash),b.recency=g(this.recency,a.recency),b}}}),j=e({instance:{match:null,factHash:null,fact:null,hashCode:null,paths:null,constructor:function(a,b,c){this.fact=a,this.paths=b||null;var d=this.match=c||new i(a);this.factHash=d.factHash,this.hashCode=d.hashCode,this.factIds=d.factIds},set:function(a,b){return this.factHash[a]=b,this},isMatch:function(a){return d(a)?(this.match.isMatch=a,this):this.match.isMatch},mergeMatch:function(a){var b=this.match=this.match.merge(a);return this.factHash=b.factHash,this.hashCode=b.hashCode,this.factIds=b.factIds,this},clone:function(a,b,c){return new j(a||this.fact,b||this.path,c||this.match)}}}).as(b)},{"./extended":12}],11:[function(a,b){var c=a("./extended"),d=c.Promise,e=a("./nextTick"),f=c.isPromiseLike;d.extend({instance:{looping:!1,constructor:function(a,b){this._super([]),this.flow=a,this.agenda=a.agenda,this.rootNode=a.rootNode,this.matchUntilHalt=!!b,c.bindAll(this,["onAlter","callNext"])},halt:function(){this.__halted=!0,this.looping||this.callback()},onAlter:function(){this.flowAltered=!0,this.looping||!this.matchUntilHalt||this.__halted||this.callNext()},setup:function(){var a=this.flow;this.rootNode.resetCounter(),a.on("assert",this.onAlter),a.on("modify",this.onAlter),a.on("retract",this.onAlter)},tearDown:function(){var a=this.flow;a.removeListener("assert",this.onAlter),a.removeListener("modify",this.onAlter),a.removeListener("retract",this.onAlter)},__handleAsyncNext:function(a){var b=this,c=b.agenda;return a.addCallback(function(){b.looping=!1,c.isEmpty()?(!b.matchUntilHalt||b.__halted)&&b.callback():(b.flowAltered&&(b.rootNode.incrementCounter(),b.flowAltered=!1),b.__halted?b.callback():b.callNext()),b=null}).addErrback(this.errback)},__handleSyncNext:function(a){return this.looping=!1,this.agenda.isEmpty()||this.flowAltered&&(this.rootNode.incrementCounter(),this.flowAltered=!1),a&&!this.__halted?e(this.callNext):(!this.matchUntilHalt||this.__halted)&&this.callback(),a},callback:function(){this.tearDown(),this._super(arguments)},callNext:function(){this.looping=!0;var a=this.agenda.fireNext();return f(a)?this.__handleAsyncNext(a):this.__handleSyncNext(a)},execute:function(){return this.setup(),this.callNext(),this}}}).as(b)},{"./extended":12,"./nextTick":17}],12:[function(a,b){b.exports=a("extended")().register(a("array-extended")).register(a("date-extended")).register(a("object-extended")).register(a("string-extended")).register(a("promise-extended")).register(a("function-extended")).register(a("is-extended")).register("HashTable",a("ht")).register("declare",a("declare.js")).register(a("leafy")).register("LinkedList",a("./linkedList"))},{"./linkedList":16,"array-extended":42,"date-extended":43,"declare.js":45,extended:46,"function-extended":49,ht:55,"is-extended":56,leafy:57,"object-extended":58,"promise-extended":59,"string-extended":60}],13:[function(a,b){"use strict";var c=a("./extended"),d=c.bind,e=c.declare,f=a("./nodes"),g=a("events").EventEmitter,h=a("./workingMemory"),i=h.WorkingMemory,j=a("./executionStrategy"),k=a("./agenda");b.exports=e(g,{instance:{name:null,executionStrategy:null,constructor:function(a,b){this.env=null,this.name=a,this.__rules={},this.conflictResolutionStrategy=b,this.workingMemory=new i,this.agenda=new k(this,b),this.agenda.on("fire",d(this,"emit","fire")),this.agenda.on("focused",d(this,"emit","focused")),this.rootNode=new f.RootNode(this.workingMemory,this.agenda),c.bindAll(this,"halt","assert","retract","modify","focus","emit")},focus:function(a){return this.agenda.setFocus(a),this},halt:function(){var a=this.executionStrategy;return a.matchUntilHalt&&a.halt(),this},dispose:function(){this.workingMemory.dispose(),this.agenda.dispose(),this.rootNode.dispose()},assert:function(a){return this.rootNode.assertFact(this.workingMemory.assertFact(a)),this.emit("assert",a),a},retract:function(a){return this.rootNode.retractFact(this.workingMemory.retractFact(a)),this.emit("retract",a),a},modify:function(a,b){return"function"==typeof b&&b.call(a,a),this.rootNode.modifyFact(this.workingMemory.modifyFact(a)),this.emit("modify",a),a},print:function(){this.rootNode.print()},containsRule:function(a){return this.rootNode.containsRule(a)},rule:function(a){this.rootNode.assertRule(a)},matchUntilHalt:function(a){return(this.executionStrategy=new j(this,!0)).execute().classic(a).promise()},match:function(a){return(this.executionStrategy=new j(this)).execute().classic(a).promise()}}})},{"./agenda":3,"./executionStrategy":11,"./extended":12,"./nodes":23,"./workingMemory":40,events:50}],14:[function(a,b){"use strict";var c=a("./extended"),d=c.instanceOf,e=c.forEach,f=c.declare,g=a("./pattern").InitialFact,h=a("./conflict"),i=h.strategy(["salience","activationRecency"]),j=a("./rule"),k=a("./flow"),l={},m=f({instance:{constructor:function(a,b){if(this.name=a,this.cb=b,this.__rules=[],this.__defined={},this.conflictResolutionStrategy=i,b&&b.call(this,this),l.hasOwnProperty(a))throw new Error("Flow with "+a+" already defined");l[a]=this},conflictResolution:function(a){return this.conflictResolutionStrategy=h.strategy(a),this},getDefined:function(a){var b=this.__defined[a.toLowerCase()];if(!b)throw new Error(a+" flow class is not defined");return b},addDefined:function(a,b){return this.__defined[a.toLowerCase()]=b,b},rule:function(){return this.__rules=this.__rules.concat(j.createRule.apply(j,arguments)),this},getSession:function(){var a=new k(this.name,this.conflictResolutionStrategy);e(this.__rules,function(b){a.rule(b)}),a.assert(new g);for(var b=0,c=arguments.length;c>b;b++)a.assert(arguments[b]);return a},containsRule:function(a){return c.some(this.__rules,function(b){return b.name===a})}},"static":{getFlow:function(a){return l[a]},hasFlow:function(a){return c.has(l,a)},deleteFlow:function(a){return d(a,m)&&(a=a.name),delete l[a],m},deleteFlows:function(){for(var a in l)a in l&&delete l[a];return m},create:function(a,b){return new m(a,b)}}}).as(b)},{"./conflict":7,"./extended":12,"./flow":13,"./pattern":38,"./rule":39}],15:[function(a,b,c){"use strict";function d(a){return/\.nools$/.test(a)}function e(a){var b;return b=d(a)?i.parse(g.readFileSync(a,"utf8"),a):i.parse(a)}var f=a("./extended"),g=a("fs"),h=a("path"),i=a("./compile"),j=a("./flowContainer");c.Flow=j,c.getFlow=j.getFlow,c.hasFlow=j.hasFlow,c.deleteFlow=function(a){return j.deleteFlow(a),this},c.deleteFlows=function(){return j.deleteFlows(),this},c.flow=j.create,c.compile=function(a,b,c){if(f.isFunction(b)?(c=b,b={}):(b=b||{},c=null),f.isString(a)&&(b.name=b.name||(d(a)?h.basename(a,h.extname(a)):null),a=e(a)),!b.name)throw new Error("Name required when compiling nools source");return i.compile(a,b,c,j)},c.transpile=function(a,b){return b=b||{},f.isString(a)&&(b.name=b.name||(d(a)?h.basename(a,h.extname(a)):null),a=e(a)),i.transpile(a,b)},c.parse=e},{"./compile":5,"./extended":12,"./flowContainer":14,fs:51,path:52}],16:[function(a,b){var c=a("declare.js");c({instance:{constructor:function(){this.head=null,this.tail=null,this.length=null},push:function(a){var b=this.tail,c=this.head,d={data:a,prev:b,next:null};return b&&(this.tail.next=d),this.tail=d,c||(this.head=d),this.length++,d},remove:function(a){a.prev?a.prev.next=a.next:this.head=a.next,a.next?a.next.prev=a.prev:this.tail=a.prev,this.length--},forEach:function(a){for(var b={next:this.head};b=b.next;)a(b.data)},clear:function(){this.head=this.tail=null,this.length=0}}}).as(b)},{"declare.js":45}],17:[function(a,b){var c,d=a("__browserify_process"),e=a("./extended");if("function"==typeof setImmediate)c="undefined"!=typeof window?e.bind(window,setImmediate):setImmediate;else if("undefined"!=typeof d)c=d.nextTick;else if("undefined"!=typeof MessageChannel){var f=new MessageChannel,g={},h=g;f.port1.onmessage=function(){g=g.next;var a=g.task;delete g.task,a()},c=function(a){h=h.next={task:a},f.port2.postMessage(0)}}else c=function(a){setTimeout(a,0)};b.exports=c},{"./extended":12,__browserify_process:54}],18:[function(a,b){var c=a("./alphaNode");c.extend({instance:{constructor:function(){this._super(arguments),this.alias=this.constraint.get("alias")},toString:function(){return"AliasNode"+this.__count},assert:function(a){return this.__propagate("assert",a.set(this.alias,a.fact.object))},modify:function(a){return this.__propagate("modify",a.set(this.alias,a.fact.object))},retract:function(a){return this.__propagate("retract",a.set(this.alias,a.fact.object))},equal:function(a){return a instanceof this._static&&this.alias===a.alias}}}).as(b)},{"./alphaNode":19}],19:[function(a,b){"use strict";var c=a("./node");c.extend({instance:{constructor:function(a){this._super([]),this.constraint=a,this.constraintAssert=this.constraint.assert},toString:function(){return"AlphaNode "+this.__count},equal:function(a){return this.constraint.equal(a.constraint)}}}).as(b)},{"./node":27}],20:[function(a,b){function c(a){for(var b=[],c=a.paths,d=-1,e=c.length;++dd;d++)this.__checkMatch(a,c[d],!0);else j(c)&&this.__checkMatch(a,c,!0)},__checkMatch:function(a,b,c){var d;return(d=this.__createMatch(a,b)).isMatch()&&c&&this.__propagate("assert",d.clone()),d},__createMatch:function(a,b){if(this.type(b)){var c,d=this.workingMemory.getFactHandle(b,!0),e=new i(d).set(this.alias,b),f=d.id,g=e.factHash,h=a.factHash;for(var j in h)g[j]=h[j];for(var k=this.__equalityConstraints,l=this.__variables,m=-1,o=k.length;++mc;c++)b=this.__checkMatch(a,l[c],!1),b.isMatch()&&(e=b.fact.id,e in k?this.__propagate("modify",b.clone()):this.__propagate("assert",b.clone()));else j(l)&&(b=this.__checkMatch(a,l,!1),b.isMatch()&&(e=b.fact.id,e in k?this.__propagate("modify",b.clone()):this.__propagate("assert",b.clone())));for(c in k)c in i||(this.removeFromFromMemory(k[c]),this.__propagate("retract",k[c].clone()))}else this.assertLeft(a);f=a.fact,e=f.id;var n=this.fromMemory[e];if(this.fromMemory[e]={},n){var o,p,q,r,s=f.object;for(c in n)p=n[c],o=p[0],q=p[1],r=q.isMatch(),o.hashCode!==a.hashCode&&(b=this.__createMatch(o,s,!1),r&&this.__propagate("retract",q.clone()),b.isMatch()&&this.__propagate(r?"modify":"assert",b.clone()))}},assertLeft:function(a){this.__addToLeftMemory(a),a.fromMatches={},this.__createMatches(a)},assertRight:function(){throw new Error("Shouldnt have gotten here")},toString:function(){return"FromNode"+this.__count}}}).as(b)},{"../constraint":8,"../context":10,"../extended":12,"./joinNode":24}],22:[function(a,b){var c=a("./joinNode"),d=a("../extended"),e=a("../constraint"),f=e.EqualityConstraint,g=e.HashConstraint,h=e.ReferenceConstraint,i=a("../context"),j=d.isDefined,k=d.forEach,l=d.isArray;c.extend({instance:{constructor:function(a,b){this._super(arguments),this.workingMemory=b,this.pattern=a,this.type=a.get("constraints")[0].assert,this.alias=a.get("alias"),this.from=a.from.assert,this.fromMemory={};var c=this.__equalityConstraints=[],d=[];k(this.constraints=this.pattern.get("constraints").slice(1),function(a){a instanceof f||a instanceof h?c.push(a.assert):a instanceof g&&(d=d.concat(a.get("variables")))}),this.__variables=d},retractLeft:function(a){var b=this.removeFromLeftMemory(a);b&&(b=b.data,b.blocked||this.__propagate("retract",b.clone()))},__modify:function(a,b){var c=b.blocked,d=a.factHash,e=this.from(d);if(l(e)){for(var f=0,g=e.length;g>f;f++)if(this.__isMatch(a,e[f],!0)){a.blocked=!0;break}}else j(e)&&(a.blocked=this.__isMatch(a,e,!0));var h=a.blocked;h?c||this.__propagate("retract",b.clone()):c?this.__propagate("assert",a.clone()):this.__propagate("modify",a.clone())},modifyLeft:function(a){var b=this.removeFromLeftMemory(a);if(!b)throw new Error;this.__addToLeftMemory(a),this.__modify(a,b.data);var c=this.fromMemory[a.fact.id];if(this.fromMemory[a.fact.id]={},c)for(var d in c)if(d!==a.hashCode){var e=c[d];b=this.removeFromLeftMemory(e),b&&(e=e.clone(),e.blocked=!1,this.__addToLeftMemory(e),this.__modify(e,b.data))}},__findMatches:function(a){var b=a.factHash,c=this.from(b),d=!1;if(l(c)){for(var e=0,f=c.length;f>e;e++)if(this.__isMatch(a,c[e],!0))return a.blocked=!0,void 0;this.__propagate("assert",a.clone())}else j(c)&&!(a.blocked=this.__isMatch(a,c,!0))&&this.__propagate("assert",a.clone());return d},__isMatch:function(a,b,c){var d=!1;if(this.type(b)){var e=this.workingMemory.getFactHandle(b),f=new i(e,null).mergeMatch(a.match).set(this.alias,b);if(c){var g=this.fromMemory[e.id];g||(g=this.fromMemory[e.id]={}),g[a.hashCode]=a}for(var h=f.factHash,j=this.__equalityConstraints,k=0,l=j.length;l>k;k++){if(!j[k](h)){d=!1;break}d=!0}}return d},removeFromLeftMemory:function(){return this._super(arguments)},assertLeft:function(a){this.__addToLeftMemory(a),this.__findMatches(a)},assertRight:function(){throw new Error("Shouldnt have gotten here")},retractRight:function(){throw new Error("Shouldnt have gotten here")},toString:function(){return"FromNode"+this.__count}}}).as(b)},{"../constraint":8,"../context":10,"../extended":12,"./joinNode":24}],23:[function(a,b,c){"use strict";var d=a("../extended"),e=d.forEach,f=d.some,g=d.declare,h=a("../pattern.js"),i=h.ObjectPattern,j=h.FromPattern,k=h.FromNotPattern,l=h.NotPattern,m=h.CompositePattern,n=h.InitialFactPattern,o=a("../constraint"),p=o.HashConstraint,q=o.ReferenceConstraint,r=a("./aliasNode"),s=a("./equalityNode"),t=a("./joinNode"),u=a("./notNode"),v=a("./fromNode"),w=a("./fromNotNode"),x=a("./leftAdapterNode"),y=a("./rightAdapterNode"),z=a("./typeNode"),A=a("./terminalNode"),B=a("./propertyNode");g({instance:{constructor:function(a,b){this.terminalNodes=[],this.joinNodes=[],this.nodes=[],this.constraints=[],this.typeNodes=[],this.__ruleCount=0,this.bucket={counter:0,recency:0},this.agendaTree=b,this.workingMemory=a},assertRule:function(a){var b=new A(this.bucket,this.__ruleCount++,a,this.agendaTree);this.__addToNetwork(a,a.pattern,b),this.__mergeJoinNodes(),this.terminalNodes.push(b)},resetCounter:function(){this.bucket.counter=0},incrementCounter:function(){this.bucket.counter++},assertFact:function(a){for(var b=this.typeNodes,c=b.length-1;c>=0;c--)b[c].assert(a)},retractFact:function(a){for(var b=this.typeNodes,c=b.length-1;c>=0;c--)b[c].retract(a)},modifyFact:function(a){for(var b=this.typeNodes,c=b.length-1;c>=0;c--)b[c].modify(a)},containsRule:function(a){return f(this.terminalNodes,function(b){return b.rule.name===a})},dispose:function(){for(var a=this.typeNodes,b=a.length-1;b>=0;b--)a[b].dispose()},__mergeJoinNodes:function(){for(var a=this.joinNodes,b=0;b=0;c--){var d=b[c];if(a.equal(d))return d}return b.push(a),a},__createTypeNode:function(a,b){for(var c=new z(b.get("constraints")[0]),d=this.typeNodes,e=d.length-1;e>=0;e--){var f=d[e];if(c.equal(f))return f}return d.push(c),c},__createEqualityNode:function(a,b){return this.__checkEqual(new s(b)).addRule(a)},__createPropertyNode:function(a,b){return this.__checkEqual(new B(b)).addRule(a)},__createAliasNode:function(a,b){return this.__checkEqual(new r(b)).addRule(a)},__createAdapterNode:function(a,b){return("left"===b?new x:new y).addRule(a)},__createJoinNode:function(a,b,c,d){var e;b.rightPattern instanceof l?e=new u:b.rightPattern instanceof k?e=new w(b.rightPattern,this.workingMemory):b.rightPattern instanceof j?e=new v(b.rightPattern,this.workingMemory):(e=new t,this.joinNodes.push(e)),e.__rule__=a;var f=e;if(c instanceof t){var g=this.__createAdapterNode(a,d);f.addOutNode(g,b),f=g}return f.addOutNode(c,b),e.addRule(a)},__addToNetwork:function(a,b,c,d){b instanceof i?!(b instanceof l||b instanceof j||b instanceof k)||d&&"left"!==d?this.__createAlphaNode(a,b,c,d):b instanceof k?this.__createBetaNode(a,new m(new n,b),c,d):this.__createBetaNode(a,new m(new n,b),c,d):b instanceof m&&this.__createBetaNode(a,b,c,d)},__createBetaNode:function(a,b,c,d){var e=this.__createJoinNode(a,b,c,d);return this.__addToNetwork(a,b.rightPattern,e,"right"),this.__addToNetwork(a,b.leftPattern,e,"left"),c.addParentNode(e),e},__createAlphaNode:function(a,b,c,d){var e,f;if(!(b instanceof j)){var g=b.get("constraints");e=this.__createTypeNode(a,b);var h=this.__createAliasNode(a,b);e.addOutNode(h,b),h.addParentNode(e),f=h;for(var i=g.length-1;i>0;i--){var k,l=g[i];if(l instanceof p)k=this.__createPropertyNode(a,l);else{if(l instanceof q){c.constraint.addConstraint(l);continue}k=this.__createEqualityNode(a,l)}f.addOutNode(k,b),k.addParentNode(f),f=k}if(c instanceof t){var m=this.__createAdapterNode(a,d);m.addParentNode(f),f.addOutNode(m,b),f=m}return c.addParentNode(f),f.addOutNode(c,b),e}},print:function(){e(this.terminalNodes,function(a){a.print(" ")})}}}).as(c,"RootNode")},{"../constraint":8,"../extended":12,"../pattern.js":38,"./aliasNode":18,"./equalityNode":20,"./fromNode":21,"./fromNotNode":22,"./joinNode":24,"./leftAdapterNode":26,"./notNode":28,"./propertyNode":29,"./rightAdapterNode":30,"./terminalNode":31,"./typeNode":32}],24:[function(a,b){var c=a("../extended"),d=c.hash.values,e=a("./node"),f=a("./joinReferenceNode"),g=a("../linkedList");e.extend({instance:{constructor:function(){this._super([]),this.constraint=new f,this.leftMemory={},this.rightMemory={},this.leftTuples=new g,this.rightTuples=new g},dispose:function(){this.leftMemory={},this.rightMemory={},this.leftTuples.clear(),this.rightTuples.clear()},disposeLeft:function(a){this.leftMemory={},this.leftTuples.clear(),this.propagateDispose(a)},disposeRight:function(a){this.rightMemory={},this.rightTuples.clear(),this.propagateDispose(a)},hashCode:function(){return"JoinNode "+this.__count},toString:function(){return"JoinNode "+this.__count},retractLeft:function(a){if(a=this.removeFromLeftMemory(a),!a)throw new Error;a=a.data;for(var b=d(a.rightMatches),c=-1,e=b.length;++ce;e++)this.addOutNode(d,c[e]);a.nodes.remove(d)},this);for(var b=a.parentNodes,c=0,d=a.parentNodes.l;d>c;c++){var e=b[c];this.addParentNode(e),e.nodes.remove(a)}return this},resolve:function(a,b){return a.hashCode===b.hashCode},print:function(a){console.log(a+this.toString()),d(this.parentNodes,function(b){b.print(" "+a)})},addOutNode:function(a,b){this.nodes.contains(a)||this.nodes.put(a,[]),this.nodes.get(a).push(b),this.__entrySet=this.nodes.entrySet()},addParentNode:function(a){-1===e(this.parentNodes,a)&&this.parentNodes.push(a)},shareable:function(){return!1},__propagate:function(a,b){for(var c,d,e,g,h=this.__entrySet,j=h.length;--j>-1;)c=h[j],d=c.key,e=c.value,b.paths?(g=f(e,b.paths)).length&&d[a](new i(b.fact,g,b.match)):d[a](b)},dispose:function(a){this.propagateDispose(a)},retract:function(a){this.propagateRetract(a)},propagateDispose:function(a,b){b=b||this.nodes;for(var c=this.__entrySet,d=c.length-1;d>=0;d--){var e=c[d],f=e.key;f.dispose(a)}},propagateAssert:function(a){this.__propagate("assert",a)},propagateRetract:function(a){this.__propagate("retract",a)},assert:function(a){this.propagateAssert(a)},modify:function(a){this.propagateModify(a)},propagateModify:function(a){this.__propagate("modify",a)}}}).as(b)},{"../context":10,"../extended":12}],28:[function(a,b){var c=a("./joinNode"),d=a("../linkedList"),e=a("../context"),f=a("../pattern").InitialFact;c.extend({instance:{constructor:function(){this._super(arguments),this.leftTupleMemory={},this.notMatch=new e(new f).match},toString:function(){return"NotNode "+this.__count},__cloneContext:function(a){return a.clone(null,null,a.match.merge(this.notMatch))},retractRight:function(a){var b=this.removeFromRightMemory(a);if(!b)throw new Error;var c=b.data,d=c.blocking;if(d.length){for(var e,f,g,h=this.rightTuples,i=this.constraint,j={next:d.head},k=h.length;j=j.next;){if(e=j.data,this.removeFromLeftBlockedMemory(e),0!==k){for(i.setLeftContext(e),f=b;f=f.next;)if(i.setRightContext(g=f.data).isMatch()){e.blocker=g,this.addToLeftBlockedMemory(g.blocking.push(e)),e=null;break}i.clearContexts()}e&&(this.__addToLeftMemory(e),this.__propagate("assert",this.__cloneContext(e)))}d.clear()}},retractLeft:function(a){var b=this.removeFromLeftMemory(a);if(b)b=b.data,this.__propagate("retract",this.__cloneContext(b));else if(!this.removeFromLeftBlockedMemory(a))throw new Error},assertLeft:function(a){var b,c,d=this.rightTuples,e=this.constraint;if(d.length){for(b={next:d.head},e.setLeftContext(a);(b=b.next)&&a;)e.setRightContext(c=b.data).isMatch()&&(a.blocker=c,this.addToLeftBlockedMemory(c.blocking.push(a)),a=null);e.clearContexts()}a&&(this.__addToLeftMemory(a),this.__propagate("assert",this.__cloneContext(a)))},assertRight:function(a){this.__addToRightMemory(a),a.blocking=new d;var b,c,e=this.leftTuples,f=this.constraint;if(e.length){for(c={next:e.head},f.setRightContext(a);c=c.next;)b=c.data,f.setLeftContext(b).isMatch()&&(this.__propagate("retract",this.__cloneContext(b)),this.removeFromLeftMemory(b),b.blocker=a,this.addToLeftBlockedMemory(a.blocking.push(b)));f.clearContexts()}},addToLeftBlockedMemory:function(a){var b=a.data,c=b.hashCode,d=this.leftMemory[c];return this.leftTupleMemory[c]=a,d&&this.leftTuples.remove(d),this},removeFromLeftBlockedMemory:function(a){var b=this.leftTupleMemory[a.hashCode]||null;return b&&(delete this.leftTupleMemory[a.hashCode],b.data.blocker.blocking.remove(b)),b},modifyLeft:function(a){var b,c,d,e,f=this.removeFromLeftMemory(a),g=this.constraint,h=this.rightTuples,i=h.length,j=!1;if(f||(f=this.removeFromLeftBlockedMemory(a),j=!0),!f)throw new Error;if(b=f.data,b&&b.blocker&&(e=this.rightMemory[b.blocker.hashCode]),e?(g.setLeftContext(a),g.setRightContext(d=e.data).isMatch()&&(j||this.__propagate("retract",this.__cloneContext(b)),a.blocker=d,this.addToLeftBlockedMemory(d.blocking.push(a)),a=null),a&&(c={next:e.next})):c={next:h.head},a&&i){for(c={next:h.head},g.setLeftContext(a);c=c.next;)if(g.setRightContext(d=c.data).isMatch()){j||this.__propagate("retract",this.__cloneContext(b)),this.addToLeftBlockedMemory(d.blocking.push(a)),a.blocker=d,a=null;break}g.clearContexts()}a&&(this.__addToLeftMemory(a),j?this.__propagate("assert",this.__cloneContext(a)):this.__propagate("modify",this.__cloneContext(a)))},modifyRight:function(a){var b=this.removeFromRightMemory(a);if(!b)throw new Error;var c,e,f=b.data,g=this.leftTuples,h=g.length,i=this.constraint,j=f.blocking;if(this.__addToRightMemory(a),a.blocking=new d,h||j.length){if(j.length){for(var k,l={next:j.head};l=l.next;)if(c=l.data,c.blocker=null,i.setRightContext(a),i.setLeftContext(c),i.isMatch())c.blocker=a,this.addToLeftBlockedMemory(a.blocking.push(c)),c=null;else{for(c.blocker=null,e=b;e=e.next;)if(i.setRightContext(k=e.data).isMatch()){c.blocker=k,this.addToLeftBlockedMemory(k.blocking.push(c)),c=null;break}c&&(this.__addToLeftMemory(c),this.__propagate("assert",this.__cloneContext(c))),i.clearContexts()}i.clearContexts()}if(h)for(i.setRightContext(a),e={next:g.head};e=e.next;)c=e.data,i.setLeftContext(c).isMatch()&&(this.__propagate("retract",this.__cloneContext(c)),this.removeFromLeftMemory(c),this.addToLeftBlockedMemory(a.blocking.push(c)),c.blocker=a)}}}}).as(b)},{"../context":10,"../linkedList":16,"../pattern":38,"./joinNode":24}],29:[function(a,b){var c=a("./alphaNode"),d=a("../context"),e=a("../extended");c.extend({instance:{constructor:function(){this._super(arguments),this.alias=this.constraint.get("alias"),this.varLength=(this.variables=e(this.constraint.get("variables")).toArray().value()).length},assert:function(a){var b,c=new d(a.fact,a.paths),e=this.variables,f=a.fact.object;c.set(this.alias,f);for(var g=0,h=this.varLength;h>g;g++)b=e[g],c.set(b[1],f[b[0]]);this.__propagate("assert",c)},retract:function(a){this.__propagate("retract",new d(a.fact,a.paths))},modify:function(a){var b,c=new d(a.fact,a.paths),e=this.variables,f=a.fact.object;c.set(this.alias,f);for(var g=0,h=this.varLength;h>g;g++)b=e[g],c.set(b[1],f[b[0]]);this.__propagate("modify",c)},toString:function(){return"PropertyNode"+this.__count}}}).as(b)},{"../context":10,"../extended":12,"./alphaNode":19}],30:[function(a,b){var c=a("./node");c.extend({instance:{retractResolve:function(a){this.__propagate("retractResolve",a)},dispose:function(a){this.propagateDispose(a)},propagateAssert:function(a){this.__propagate("assertRight",a)},propagateRetract:function(a){this.__propagate("retractRight",a)},propagateResolve:function(a){this.__propagate("retractResolve",a)},propagateModify:function(a){this.__propagate("modifyRight",a)},toString:function(){return"RightAdapterNode "+this.__count}}}).as(b)},{"./node":27}],31:[function(a,b){var c=a("./node"),d=a("../extended"),e=d.bind,f=d.removeDuplicates;c.extend({instance:{constructor:function(a,b,c,d){this._super([]),this.resolve=e(this,this.resolve),this.rule=c,this.index=b,this.name=this.rule.name,this.agenda=d,this.bucket=a,d.register(this)},__assertModify:function(a){var b=a.match;if(b.recency.sort(function(a,b){return a-b}).reverse(),b.facts=f(b.facts),b.isMatch){var c=this.rule,d=this.bucket;this.agenda.insert(this,{rule:c,hashCode:a.hashCode,index:this.index,name:c.name,recency:d.recency++,match:b,counter:d.counter})}},assert:function(a){this.__assertModify(a)},modify:function(a){this.agenda.retract(this,a),this.__assertModify(a)},retract:function(a){this.agenda.retract(this,a)},retractRight:function(a){this.agenda.retract(this,a)},retractLeft:function(a){this.agenda.retract(this,a)},assertLeft:function(a){this.__assertModify(a)},assertRight:function(a){this.__assertModify(a)},toString:function(){return"TerminalNode "+this.rule.name}}}).as(b)},{"../extended":12,"./node":27}],32:[function(a,b){var c=a("./alphaNode"),d=a("../context");c.extend({instance:{assert:function(a){this.constraintAssert(a.object)&&this.__propagate("assert",a)},modify:function(a){this.constraintAssert(a.object)&&this.__propagate("modify",a)},retract:function(a){this.constraintAssert(a.object)&&this.__propagate("retract",a)},toString:function(){return"TypeNode"+this.__count},dispose:function(){for(var a=this.__entrySet,b=a.length-1;b>=0;b--){var c=a[b],d=c.key,e=c.value;d.dispose({paths:e})}},__propagate:function(a,b){for(var c=this.__entrySet,e=-1,f=c.length;++e":20,"<=":21,">=":22,EQUALITY_EXPRESSION:23,"==":24,"!=":25,"=~":26,"!=~":27,IN_EXPRESSION:28,"in":29,ARRAY_EXPRESSION:30,notIn:31,OBJECT_EXPRESSION:32,AND_EXPRESSION:33,"&&":34,OR_EXPRESSION:35,"||":36,ARGUMENT_LIST:37,",":38,IDENTIFIER_EXPRESSION:39,IDENTIFIER:40,".":41,"[":42,STRING_EXPRESSION:43,"]":44,NUMBER_EXPRESSION:45,"(":46,")":47,STRING:48,NUMBER:49,REGEXP_EXPRESSION:50,REGEXP:51,BOOLEAN_EXPRESSION:52,BOOLEAN:53,NULL_EXPRESSION:54,NULL:55,$accept:0,$end:1},terminals_:{2:"error",5:"EOF",8:"-",9:"!",11:"*",12:"/",13:"%",15:"+",17:"^",19:"<",20:">",21:"<=",22:">=",24:"==",25:"!=",26:"=~",27:"!=~",29:"in",31:"notIn",34:"&&",36:"||",38:",",40:"IDENTIFIER",41:".",42:"[",44:"]",46:"(",47:")",48:"STRING",49:"NUMBER",51:"REGEXP",53:"BOOLEAN",55:"NULL"},productions_:[0,[3,2],[6,1],[6,2],[6,2],[10,1],[10,3],[10,3],[10,3],[14,1],[14,3],[14,3],[16,1],[16,3],[18,1],[18,3],[18,3],[18,3],[18,3],[23,1],[23,3],[23,3],[23,3],[23,3],[28,1],[28,3],[28,3],[28,3],[28,3],[33,1],[33,3],[35,1],[35,3],[37,1],[37,3],[39,1],[32,1],[32,3],[32,4],[32,4],[32,4],[32,3],[32,4],[43,1],[45,1],[50,1],[52,1],[54,1],[30,2],[30,3],[7,1],[7,1],[7,1],[7,1],[7,1],[7,1],[7,1],[7,3],[4,1]],performAction:function(a,b,c,d,e,f){var g=f.length-1;switch(e){case 1:return f[g-1];case 3:this.$=[f[g],null,"unary"];break;case 4:this.$=[f[g],null,"logicalNot"];break;case 6:this.$=[f[g-2],f[g],"mult"];break;case 7:this.$=[f[g-2],f[g],"div"];break;case 8:this.$=[f[g-2],f[g],"mod"];break;case 10:this.$=[f[g-2],f[g],"plus"];break;case 11:this.$=[f[g-2],f[g],"minus"];break;case 13:this.$=[f[g-2],f[g],"pow"];break;case 15:this.$=[f[g-2],f[g],"lt"];break;case 16:this.$=[f[g-2],f[g],"gt"];break;case 17:this.$=[f[g-2],f[g],"lte"];break;case 18:this.$=[f[g-2],f[g],"gte"];break;case 20:this.$=[f[g-2],f[g],"eq"];break;case 21:this.$=[f[g-2],f[g],"neq"];break;case 22:this.$=[f[g-2],f[g],"like"];break;case 23:this.$=[f[g-2],f[g],"notLike"];break;case 25:this.$=[f[g-2],f[g],"in"];break;case 26:this.$=[f[g-2],f[g],"notIn"];break;case 27:this.$=[f[g-2],f[g],"in"];break;case 28:this.$=[f[g-2],f[g],"notIn"];break;case 30:this.$=[f[g-2],f[g],"and"];break;case 32:this.$=[f[g-2],f[g],"or"];break;case 34:this.$=[f[g-2],f[g],"arguments"];break;case 35:this.$=[String(a),null,"identifier"];break;case 37:this.$=[f[g-2],f[g],"prop"];break;case 38:this.$=[f[g-3],f[g-1],"propLookup"];break;case 39:this.$=[f[g-3],f[g-1],"propLookup"];break;case 40:this.$=[f[g-3],f[g-1],"propLookup"];break;case 41:this.$=[f[g-2],[null,null,"arguments"],"function"];break;case 42:this.$=[f[g-3],f[g-1],"function"];break;case 43:this.$=[String(a.replace(/^['|"]|['|"]$/g,"")),null,"string"];break;case 44:this.$=[Number(a),null,"number"];break;case 45:this.$=[a,null,"regexp"];break;case 46:this.$=["true"==a.replace(/^\s+/,""),null,"boolean"];break;case 47:this.$=[null,null,"null"];break;case 48:this.$=[null,null,"array"];break;case 49:this.$=[f[g-1],null,"array"];break;case 57:this.$=[f[g-1],null,"composite"]}},table:[{3:1,4:2,6:28,7:7,8:[1,29],9:[1,30],10:27,14:25,16:17,18:8,23:6,28:5,30:15,32:14,33:4,35:3,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{1:[3]},{5:[1,31]},{5:[2,58],36:[1,32],47:[2,58]},{5:[2,31],34:[1,33],36:[2,31],47:[2,31]},{5:[2,29],34:[2,29],36:[2,29],47:[2,29]},{5:[2,24],24:[1,34],25:[1,35],26:[1,36],27:[1,37],34:[2,24],36:[2,24],47:[2,24]},{5:[2,2],8:[2,2],11:[2,2],12:[2,2],13:[2,2],15:[2,2],17:[2,2],19:[2,2],20:[2,2],21:[2,2],22:[2,2],24:[2,2],25:[2,2],26:[2,2],27:[2,2],29:[1,38],31:[1,39],34:[2,2],36:[2,2],47:[2,2]},{5:[2,19],19:[1,40],20:[1,41],21:[1,42],22:[1,43],24:[2,19],25:[2,19],26:[2,19],27:[2,19],34:[2,19],36:[2,19],47:[2,19]},{5:[2,50],8:[2,50],11:[2,50],12:[2,50],13:[2,50],15:[2,50],17:[2,50],19:[2,50],20:[2,50],21:[2,50],22:[2,50],24:[2,50],25:[2,50],26:[2,50],27:[2,50],29:[2,50],31:[2,50],34:[2,50],36:[2,50],38:[2,50],44:[2,50],47:[2,50]},{5:[2,51],8:[2,51],11:[2,51],12:[2,51],13:[2,51],15:[2,51],17:[2,51],19:[2,51],20:[2,51],21:[2,51],22:[2,51],24:[2,51],25:[2,51],26:[2,51],27:[2,51],29:[2,51],31:[2,51],34:[2,51],36:[2,51],38:[2,51],44:[2,51],47:[2,51]},{5:[2,52],8:[2,52],11:[2,52],12:[2,52],13:[2,52],15:[2,52],17:[2,52],19:[2,52],20:[2,52],21:[2,52],22:[2,52],24:[2,52],25:[2,52],26:[2,52],27:[2,52],29:[2,52],31:[2,52],34:[2,52],36:[2,52],38:[2,52],44:[2,52],47:[2,52]},{5:[2,53],8:[2,53],11:[2,53],12:[2,53],13:[2,53],15:[2,53],17:[2,53],19:[2,53],20:[2,53],21:[2,53],22:[2,53],24:[2,53],25:[2,53],26:[2,53],27:[2,53],29:[2,53],31:[2,53],34:[2,53],36:[2,53],38:[2,53],44:[2,53],47:[2,53]},{5:[2,54],8:[2,54],11:[2,54],12:[2,54],13:[2,54],15:[2,54],17:[2,54],19:[2,54],20:[2,54],21:[2,54],22:[2,54],24:[2,54],25:[2,54],26:[2,54],27:[2,54],29:[2,54],31:[2,54],34:[2,54],36:[2,54],38:[2,54],44:[2,54],47:[2,54]},{5:[2,55],8:[2,55],11:[2,55],12:[2,55],13:[2,55],15:[2,55],17:[2,55],19:[2,55],20:[2,55],21:[2,55],22:[2,55],24:[2,55],25:[2,55],26:[2,55],27:[2,55],29:[2,55],31:[2,55],34:[2,55],36:[2,55],38:[2,55],41:[1,44],42:[1,45],44:[2,55],46:[1,46],47:[2,55]},{5:[2,56],8:[2,56],11:[2,56],12:[2,56],13:[2,56],15:[2,56],17:[2,56],19:[2,56],20:[2,56],21:[2,56],22:[2,56],24:[2,56],25:[2,56],26:[2,56],27:[2,56],29:[2,56],31:[2,56],34:[2,56],36:[2,56],38:[2,56],44:[2,56],47:[2,56]},{4:47,6:28,7:7,8:[1,29],9:[1,30],10:27,14:25,16:17,18:8,23:6,28:5,30:15,32:14,33:4,35:3,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{5:[2,14],17:[1,48],19:[2,14],20:[2,14],21:[2,14],22:[2,14],24:[2,14],25:[2,14],26:[2,14],27:[2,14],34:[2,14],36:[2,14],47:[2,14]},{5:[2,43],8:[2,43],11:[2,43],12:[2,43],13:[2,43],15:[2,43],17:[2,43],19:[2,43],20:[2,43],21:[2,43],22:[2,43],24:[2,43],25:[2,43],26:[2,43],27:[2,43],29:[2,43],31:[2,43],34:[2,43],36:[2,43],38:[2,43],44:[2,43],47:[2,43]},{5:[2,44],8:[2,44],11:[2,44],12:[2,44],13:[2,44],15:[2,44],17:[2,44],19:[2,44],20:[2,44],21:[2,44],22:[2,44],24:[2,44],25:[2,44],26:[2,44],27:[2,44],29:[2,44],31:[2,44],34:[2,44],36:[2,44],38:[2,44],44:[2,44],47:[2,44]},{5:[2,45],8:[2,45],11:[2,45],12:[2,45],13:[2,45],15:[2,45],17:[2,45],19:[2,45],20:[2,45],21:[2,45],22:[2,45],24:[2,45],25:[2,45],26:[2,45],27:[2,45],29:[2,45],31:[2,45],34:[2,45],36:[2,45],38:[2,45],44:[2,45],47:[2,45]},{5:[2,46],8:[2,46],11:[2,46],12:[2,46],13:[2,46],15:[2,46],17:[2,46],19:[2,46],20:[2,46],21:[2,46],22:[2,46],24:[2,46],25:[2,46],26:[2,46],27:[2,46],29:[2,46],31:[2,46],34:[2,46],36:[2,46],38:[2,46],44:[2,46],47:[2,46]},{5:[2,47],8:[2,47],11:[2,47],12:[2,47],13:[2,47],15:[2,47],17:[2,47],19:[2,47],20:[2,47],21:[2,47],22:[2,47],24:[2,47],25:[2,47],26:[2,47],27:[2,47],29:[2,47],31:[2,47],34:[2,47],36:[2,47],38:[2,47],44:[2,47],47:[2,47]},{5:[2,36],8:[2,36],11:[2,36],12:[2,36],13:[2,36],15:[2,36],17:[2,36],19:[2,36],20:[2,36],21:[2,36],22:[2,36],24:[2,36],25:[2,36],26:[2,36],27:[2,36],29:[2,36],31:[2,36],34:[2,36],36:[2,36],38:[2,36],41:[2,36],42:[2,36],44:[2,36],46:[2,36],47:[2,36]},{7:51,30:15,32:14,37:50,39:23,40:[1,26],42:[1,24],43:9,44:[1,49],45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{5:[2,12],8:[1,53],15:[1,52],17:[2,12],19:[2,12],20:[2,12],21:[2,12],22:[2,12],24:[2,12],25:[2,12],26:[2,12],27:[2,12],34:[2,12],36:[2,12],47:[2,12]},{5:[2,35],8:[2,35],11:[2,35],12:[2,35],13:[2,35],15:[2,35],17:[2,35],19:[2,35],20:[2,35],21:[2,35],22:[2,35],24:[2,35],25:[2,35],26:[2,35],27:[2,35],29:[2,35],31:[2,35],34:[2,35],36:[2,35],38:[2,35],41:[2,35],42:[2,35],44:[2,35],46:[2,35],47:[2,35]},{5:[2,9],8:[2,9],11:[1,54],12:[1,55],13:[1,56],15:[2,9],17:[2,9],19:[2,9],20:[2,9],21:[2,9],22:[2,9],24:[2,9],25:[2,9],26:[2,9],27:[2,9],34:[2,9],36:[2,9],47:[2,9]},{5:[2,5],8:[2,5],11:[2,5],12:[2,5],13:[2,5],15:[2,5],17:[2,5],19:[2,5],20:[2,5],21:[2,5],22:[2,5],24:[2,5],25:[2,5],26:[2,5],27:[2,5],34:[2,5],36:[2,5],47:[2,5]},{6:57,7:58,8:[1,29],9:[1,30],30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:59,7:58,8:[1,29],9:[1,30],30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{1:[2,1]},{6:28,7:7,8:[1,29],9:[1,30],10:27,14:25,16:17,18:8,23:6,28:5,30:15,32:14,33:60,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:28,7:7,8:[1,29],9:[1,30],10:27,14:25,16:17,18:8,23:6,28:61,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:28,7:58,8:[1,29],9:[1,30],10:27,14:25,16:17,18:62,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:28,7:58,8:[1,29],9:[1,30],10:27,14:25,16:17,18:63,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:28,7:58,8:[1,29],9:[1,30],10:27,14:25,16:17,18:64,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:28,7:58,8:[1,29],9:[1,30],10:27,14:25,16:17,18:65,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{30:66,32:67,39:23,40:[1,26],42:[1,24]},{30:68,32:69,39:23,40:[1,26],42:[1,24]},{6:28,7:58,8:[1,29],9:[1,30],10:27,14:25,16:70,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:28,7:58,8:[1,29],9:[1,30],10:27,14:25,16:71,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:28,7:58,8:[1,29],9:[1,30],10:27,14:25,16:72,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:28,7:58,8:[1,29],9:[1,30],10:27,14:25,16:73,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{39:74,40:[1,26]},{32:77,39:23,40:[1,26],43:75,45:76,48:[1,18],49:[1,19]},{7:51,30:15,32:14,37:79,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],47:[1,78],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{47:[1,80]},{6:28,7:58,8:[1,29],9:[1,30],10:27,14:81,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{5:[2,48],8:[2,48],11:[2,48],12:[2,48],13:[2,48],15:[2,48],17:[2,48],19:[2,48],20:[2,48],21:[2,48],22:[2,48],24:[2,48],25:[2,48],26:[2,48],27:[2,48],29:[2,48],31:[2,48],34:[2,48],36:[2,48],38:[2,48],44:[2,48],47:[2,48]},{38:[1,83],44:[1,82]},{38:[2,33],44:[2,33],47:[2,33]},{6:28,7:58,8:[1,29],9:[1,30],10:84,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:28,7:58,8:[1,29],9:[1,30],10:85,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:86,7:58,8:[1,29],9:[1,30],30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:87,7:58,8:[1,29],9:[1,30],30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:88,7:58,8:[1,29],9:[1,30],30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{5:[2,3],8:[2,3],11:[2,3],12:[2,3],13:[2,3],15:[2,3],17:[2,3],19:[2,3],20:[2,3],21:[2,3],22:[2,3],24:[2,3],25:[2,3],26:[2,3],27:[2,3],34:[2,3],36:[2,3],47:[2,3]},{5:[2,2],8:[2,2],11:[2,2],12:[2,2],13:[2,2],15:[2,2],17:[2,2],19:[2,2],20:[2,2],21:[2,2],22:[2,2],24:[2,2],25:[2,2],26:[2,2],27:[2,2],34:[2,2],36:[2,2],47:[2,2]},{5:[2,4],8:[2,4],11:[2,4],12:[2,4],13:[2,4],15:[2,4],17:[2,4],19:[2,4],20:[2,4],21:[2,4],22:[2,4],24:[2,4],25:[2,4],26:[2,4],27:[2,4],34:[2,4],36:[2,4],47:[2,4]},{5:[2,32],34:[1,33],36:[2,32],47:[2,32]},{5:[2,30],34:[2,30],36:[2,30],47:[2,30]},{5:[2,20],19:[1,40],20:[1,41],21:[1,42],22:[1,43],24:[2,20],25:[2,20],26:[2,20],27:[2,20],34:[2,20],36:[2,20],47:[2,20]},{5:[2,21],19:[1,40],20:[1,41],21:[1,42],22:[1,43],24:[2,21],25:[2,21],26:[2,21],27:[2,21],34:[2,21],36:[2,21],47:[2,21]},{5:[2,22],19:[1,40],20:[1,41],21:[1,42],22:[1,43],24:[2,22],25:[2,22],26:[2,22],27:[2,22],34:[2,22],36:[2,22],47:[2,22]},{5:[2,23],19:[1,40],20:[1,41],21:[1,42],22:[1,43],24:[2,23],25:[2,23],26:[2,23],27:[2,23],34:[2,23],36:[2,23],47:[2,23]},{5:[2,25],34:[2,25],36:[2,25],47:[2,25]},{5:[2,27],34:[2,27],36:[2,27],41:[1,44],42:[1,45],46:[1,46],47:[2,27]},{5:[2,26],34:[2,26],36:[2,26],47:[2,26]},{5:[2,28],34:[2,28],36:[2,28],41:[1,44],42:[1,45],46:[1,46],47:[2,28]},{5:[2,15],17:[1,48],19:[2,15],20:[2,15],21:[2,15],22:[2,15],24:[2,15],25:[2,15],26:[2,15],27:[2,15],34:[2,15],36:[2,15],47:[2,15]},{5:[2,16],17:[1,48],19:[2,16],20:[2,16],21:[2,16],22:[2,16],24:[2,16],25:[2,16],26:[2,16],27:[2,16],34:[2,16],36:[2,16],47:[2,16]},{5:[2,17],17:[1,48],19:[2,17],20:[2,17],21:[2,17],22:[2,17],24:[2,17],25:[2,17],26:[2,17],27:[2,17],34:[2,17],36:[2,17],47:[2,17]},{5:[2,18],17:[1,48],19:[2,18],20:[2,18],21:[2,18],22:[2,18],24:[2,18],25:[2,18],26:[2,18],27:[2,18],34:[2,18],36:[2,18],47:[2,18]},{5:[2,37],8:[2,37],11:[2,37],12:[2,37],13:[2,37],15:[2,37],17:[2,37],19:[2,37],20:[2,37],21:[2,37],22:[2,37],24:[2,37],25:[2,37],26:[2,37],27:[2,37],29:[2,37],31:[2,37],34:[2,37],36:[2,37],38:[2,37],41:[2,37],42:[2,37],44:[2,37],46:[2,37],47:[2,37]},{44:[1,89]},{44:[1,90]},{41:[1,44],42:[1,45],44:[1,91],46:[1,46]},{5:[2,41],8:[2,41],11:[2,41],12:[2,41],13:[2,41],15:[2,41],17:[2,41],19:[2,41],20:[2,41],21:[2,41],22:[2,41],24:[2,41],25:[2,41],26:[2,41],27:[2,41],29:[2,41],31:[2,41],34:[2,41],36:[2,41],38:[2,41],41:[2,41],42:[2,41],44:[2,41],46:[2,41],47:[2,41]},{38:[1,83],47:[1,92]},{5:[2,57],8:[2,57],11:[2,57],12:[2,57],13:[2,57],15:[2,57],17:[2,57],19:[2,57],20:[2,57],21:[2,57],22:[2,57],24:[2,57],25:[2,57],26:[2,57],27:[2,57],29:[2,57],31:[2,57],34:[2,57],36:[2,57],38:[2,57],44:[2,57],47:[2,57]},{5:[2,13],8:[1,53],15:[1,52],17:[2,13],19:[2,13],20:[2,13],21:[2,13],22:[2,13],24:[2,13],25:[2,13],26:[2,13],27:[2,13],34:[2,13],36:[2,13],47:[2,13]},{5:[2,49],8:[2,49],11:[2,49],12:[2,49],13:[2,49],15:[2,49],17:[2,49],19:[2,49],20:[2,49],21:[2,49],22:[2,49],24:[2,49],25:[2,49],26:[2,49],27:[2,49],29:[2,49],31:[2,49],34:[2,49],36:[2,49],38:[2,49],44:[2,49],47:[2,49]},{7:93,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{5:[2,10],8:[2,10],11:[1,54],12:[1,55],13:[1,56],15:[2,10],17:[2,10],19:[2,10],20:[2,10],21:[2,10],22:[2,10],24:[2,10],25:[2,10],26:[2,10],27:[2,10],34:[2,10],36:[2,10],47:[2,10]},{5:[2,11],8:[2,11],11:[1,54],12:[1,55],13:[1,56],15:[2,11],17:[2,11],19:[2,11],20:[2,11],21:[2,11],22:[2,11],24:[2,11],25:[2,11],26:[2,11],27:[2,11],34:[2,11],36:[2,11],47:[2,11]},{5:[2,6],8:[2,6],11:[2,6],12:[2,6],13:[2,6],15:[2,6],17:[2,6],19:[2,6],20:[2,6],21:[2,6],22:[2,6],24:[2,6],25:[2,6],26:[2,6],27:[2,6],34:[2,6],36:[2,6],47:[2,6]},{5:[2,7],8:[2,7],11:[2,7],12:[2,7],13:[2,7],15:[2,7],17:[2,7],19:[2,7],20:[2,7],21:[2,7],22:[2,7],24:[2,7],25:[2,7],26:[2,7],27:[2,7],34:[2,7],36:[2,7],47:[2,7]},{5:[2,8],8:[2,8],11:[2,8],12:[2,8],13:[2,8],15:[2,8],17:[2,8],19:[2,8],20:[2,8],21:[2,8],22:[2,8],24:[2,8],25:[2,8],26:[2,8],27:[2,8],34:[2,8],36:[2,8],47:[2,8]},{5:[2,38],8:[2,38],11:[2,38],12:[2,38],13:[2,38],15:[2,38],17:[2,38],19:[2,38],20:[2,38],21:[2,38],22:[2,38],24:[2,38],25:[2,38],26:[2,38],27:[2,38],29:[2,38],31:[2,38],34:[2,38],36:[2,38],38:[2,38],41:[2,38],42:[2,38],44:[2,38],46:[2,38],47:[2,38]},{5:[2,39],8:[2,39],11:[2,39],12:[2,39],13:[2,39],15:[2,39],17:[2,39],19:[2,39],20:[2,39],21:[2,39],22:[2,39],24:[2,39],25:[2,39],26:[2,39],27:[2,39],29:[2,39],31:[2,39],34:[2,39],36:[2,39],38:[2,39],41:[2,39],42:[2,39],44:[2,39],46:[2,39],47:[2,39]},{5:[2,40],8:[2,40],11:[2,40],12:[2,40],13:[2,40],15:[2,40],17:[2,40],19:[2,40],20:[2,40],21:[2,40],22:[2,40],24:[2,40],25:[2,40],26:[2,40],27:[2,40],29:[2,40],31:[2,40],34:[2,40],36:[2,40],38:[2,40],41:[2,40],42:[2,40],44:[2,40],46:[2,40],47:[2,40]},{5:[2,42],8:[2,42],11:[2,42],12:[2,42],13:[2,42],15:[2,42],17:[2,42],19:[2,42],20:[2,42],21:[2,42],22:[2,42],24:[2,42],25:[2,42],26:[2,42],27:[2,42],29:[2,42],31:[2,42],34:[2,42],36:[2,42],38:[2,42],41:[2,42],42:[2,42],44:[2,42],46:[2,42],47:[2,42]},{38:[2,34],44:[2,34],47:[2,34]}],defaultActions:{31:[2,1]},parseError:function(a,b){if(!b.recoverable)throw new Error(a); -this.trace(a)},parse:function(a){function b(){var a;return a=c.lexer.lex()||m,"number"!=typeof a&&(a=c.symbols_[a]||a),a}var c=this,d=[0],e=[null],f=[],g=this.table,h="",i=0,j=0,k=0,l=2,m=1;this.lexer.setInput(a),this.lexer.yy=this.yy,this.yy.lexer=this.lexer,this.yy.parser=this,"undefined"==typeof this.lexer.yylloc&&(this.lexer.yylloc={});var n=this.lexer.yylloc;f.push(n);var o=this.lexer.options&&this.lexer.options.ranges;this.parseError="function"==typeof this.yy.parseError?this.yy.parseError:Object.getPrototypeOf(this).parseError;for(var p,q,r,s,t,u,v,w,x,y={};;){if(r=d[d.length-1],this.defaultActions[r]?s=this.defaultActions[r]:((null===p||"undefined"==typeof p)&&(p=b()),s=g[r]&&g[r][p]),"undefined"==typeof s||!s.length||!s[0]){var z="";x=[];for(u in g[r])this.terminals_[u]&&u>l&&x.push("'"+this.terminals_[u]+"'");z=this.lexer.showPosition?"Parse error on line "+(i+1)+":\n"+this.lexer.showPosition()+"\nExpecting "+x.join(", ")+", got '"+(this.terminals_[p]||p)+"'":"Parse error on line "+(i+1)+": Unexpected "+(p==m?"end of input":"'"+(this.terminals_[p]||p)+"'"),this.parseError(z,{text:this.lexer.match,token:this.terminals_[p]||p,line:this.lexer.yylineno,loc:n,expected:x})}if(s[0]instanceof Array&&s.length>1)throw new Error("Parse Error: multiple actions possible at state: "+r+", token: "+p);switch(s[0]){case 1:d.push(p),e.push(this.lexer.yytext),f.push(this.lexer.yylloc),d.push(s[1]),p=null,q?(p=q,q=null):(j=this.lexer.yyleng,h=this.lexer.yytext,i=this.lexer.yylineno,n=this.lexer.yylloc,k>0&&k--);break;case 2:if(v=this.productions_[s[1]][1],y.$=e[e.length-v],y._$={first_line:f[f.length-(v||1)].first_line,last_line:f[f.length-1].last_line,first_column:f[f.length-(v||1)].first_column,last_column:f[f.length-1].last_column},o&&(y._$.range=[f[f.length-(v||1)].range[0],f[f.length-1].range[1]]),t=this.performAction.call(y,h,j,i,this.yy,s[1],e,f),"undefined"!=typeof t)return t;v&&(d=d.slice(0,2*-1*v),e=e.slice(0,-1*v),f=f.slice(0,-1*v)),d.push(this.productions_[s[1]][0]),e.push(y.$),f.push(y._$),w=g[d[d.length-2]][d[d.length-1]],d.push(w);break;case 3:return!0}}return!0}},c=function(){var a={EOF:1,parseError:function(a,b){if(!this.yy.parser)throw new Error(a);this.yy.parser.parseError(a,b)},setInput:function(a){return this._input=a,this._more=this._backtrack=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},input:function(){var a=this._input[0];this.yytext+=a,this.yyleng++,this.offset++,this.match+=a,this.matched+=a;var b=a.match(/(?:\r\n?|\n).*/g);return b?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),a},unput:function(a){var b=a.length,c=a.split(/(?:\r\n?|\n)/g);this._input=a+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-b-1),this.offset-=b;var d=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),c.length-1&&(this.yylineno-=c.length-1);var e=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:c?(c.length===d.length?this.yylloc.first_column:0)+d[d.length-c.length].length-c[0].length:this.yylloc.first_column-b},this.options.ranges&&(this.yylloc.range=[e[0],e[0]+this.yyleng-b]),this.yyleng=this.yytext.length,this},more:function(){return this._more=!0,this},reject:function(){return this.options.backtrack_lexer?(this._backtrack=!0,this):this.parseError("Lexical error on line "+(this.yylineno+1)+". You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},less:function(a){this.unput(this.match.slice(a))},pastInput:function(){var a=this.matched.substr(0,this.matched.length-this.match.length);return(a.length>20?"...":"")+a.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var a=this.match;return a.length<20&&(a+=this._input.substr(0,20-a.length)),(a.substr(0,20)+(a.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var a=this.pastInput(),b=new Array(a.length+1).join("-");return a+this.upcomingInput()+"\n"+b+"^"},test_match:function(a,b){var c,d,e;if(this.options.backtrack_lexer&&(e={yylineno:this.yylineno,yylloc:{first_line:this.yylloc.first_line,last_line:this.last_line,first_column:this.yylloc.first_column,last_column:this.yylloc.last_column},yytext:this.yytext,match:this.match,matches:this.matches,matched:this.matched,yyleng:this.yyleng,offset:this.offset,_more:this._more,_input:this._input,yy:this.yy,conditionStack:this.conditionStack.slice(0),done:this.done},this.options.ranges&&(e.yylloc.range=this.yylloc.range.slice(0))),d=a[0].match(/(?:\r\n?|\n).*/g),d&&(this.yylineno+=d.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:d?d[d.length-1].length-d[d.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+a[0].length},this.yytext+=a[0],this.match+=a[0],this.matches=a,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._backtrack=!1,this._input=this._input.slice(a[0].length),this.matched+=a[0],c=this.performAction.call(this,this.yy,this,b,this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),c)return c;if(this._backtrack){for(var f in e)this[f]=e[f];return!1}return!1},next:function(){if(this.done)return this.EOF;this._input||(this.done=!0);var a,b,c,d;this._more||(this.yytext="",this.match="");for(var e=this._currentRules(),f=0;fb[0].length)){if(b=c,d=f,this.options.backtrack_lexer){if(a=this.test_match(c,e[f]),a!==!1)return a;if(this._backtrack){b=!1;continue}return!1}if(!this.options.flex)break}return b?(a=this.test_match(b,e[d]),a!==!1?a:!1):""===this._input?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+". Unrecognized text.\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){var a=this.next();return a?a:this.lex()},begin:function(a){this.conditionStack.push(a)},popState:function(){var a=this.conditionStack.length-1;return a>0?this.conditionStack.pop():this.conditionStack[0]},_currentRules:function(){return this.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]?this.conditions[this.conditionStack[this.conditionStack.length-1]].rules:this.conditions.INITIAL.rules},topState:function(a){return a=this.conditionStack.length-1-Math.abs(a||0),a>=0?this.conditionStack[a]:"INITIAL"},pushState:function(a){this.begin(a)},stateStackSize:function(){return this.conditionStack.length},options:{},performAction:function(a,b,c,d){switch(c){case 0:return 29;case 1:return 31;case 2:return"from";case 3:return 24;case 4:return 25;case 5:return 21;case 6:return 19;case 7:return 22;case 8:return 20;case 9:return 26;case 10:return 27;case 11:return 34;case 12:return 36;case 13:return 55;case 14:return 53;case 15:break;case 16:return 49;case 17:return 48;case 18:return 48;case 19:return 40;case 20:return 51;case 21:return 41;case 22:return 11;case 23:return 12;case 24:return 13;case 25:return 38;case 26:return 8;case 27:return 26;case 28:return 27;case 29:return 24;case 30:return 24;case 31:return 25;case 32:return 25;case 33:return 21;case 34:return 22;case 35:return 20;case 36:return 19;case 37:return 34;case 38:return 36;case 39:return 15;case 40:return 17;case 41:return 46;case 42:return 44;case 43:return 42;case 44:return 47;case 45:return 9;case 46:return 5}},rules:[/^(?:\s+in\b)/,/^(?:\s+notIn\b)/,/^(?:\s+from\b)/,/^(?:\s+(eq|EQ)\b)/,/^(?:\s+(neq|NEQ)\b)/,/^(?:\s+(lte|LTE)\b)/,/^(?:\s+(lt|LT)\b)/,/^(?:\s+(gte|GTE)\b)/,/^(?:\s+(gt|GT)\b)/,/^(?:\s+(like|LIKE)\b)/,/^(?:\s+(notLike|NOT_LIKE)\b)/,/^(?:\s+(and|AND)\b)/,/^(?:\s+(or|OR)\b)/,/^(?:\s+null\b)/,/^(?:\s+(true|false)\b)/,/^(?:\s+)/,/^(?:-?[0-9]+(?:\.[0-9]+)?\b)/,/^(?:'[^']*')/,/^(?:"[^"]*")/,/^(?:([a-zA-Z_$][0-9a-zA-Z_$]*))/,/^(?:^\/((?![\s=])[^[\/\n\\]*(?:(?:\\[\s\S]|\[[^\]\n\\]*(?:\\[\s\S][^\]\n\\]*)*])[^[\/\n\\]*)*\/[imgy]{0,4})(?!\w))/,/^(?:\.)/,/^(?:\*)/,/^(?:\/)/,/^(?:\%)/,/^(?:,)/,/^(?:-)/,/^(?:=~)/,/^(?:!=~)/,/^(?:==)/,/^(?:===)/,/^(?:!=)/,/^(?:!==)/,/^(?:<=)/,/^(?:>=)/,/^(?:>)/,/^(?:<)/,/^(?:&&)/,/^(?:\|\|)/,/^(?:\+)/,/^(?:\^)/,/^(?:\()/,/^(?:\])/,/^(?:\[)/,/^(?:\))/,/^(?:!)/,/^(?:$)/],conditions:{INITIAL:{rules:[0,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],inclusive:!0}}};return a}();return b.lexer=c,a.prototype=b,b.Parser=a,new a}();"undefined"!=typeof a&&"undefined"!=typeof c&&(c.parser=e,c.Parser=e.Parser,c.parse=function(){return e.parse.apply(e,arguments)},c.main=function(b){b[1]||(console.log("Usage: "+b[0]+" FILE"),d.exit(1));var e=a("fs").readFileSync(a("path").normalize(b[1]),"utf8");return c.parser.parse(e)},"undefined"!=typeof b&&a.main===b&&c.main(d.argv.slice(1)))},{__browserify_process:54,fs:51,path:52}],34:[function(a,b,c){!function(){"use strict";var b=a("./constraint/parser"),d=a("./nools/nool.parser");c.parseConstraint=function(a){try{return b.parse(a)}catch(c){throw new Error("Invalid expression '"+a+"'")}},c.parseRuleSet=function(a,b){return d.parse(a,b)}}()},{"./constraint/parser":33,"./nools/nool.parser":35}],35:[function(a,b,c){"use strict";var d=a("./tokens.js"),e=a("../../extended"),f=e.hash.keys,g=a("./util.js"),h=function(a,b,c){var d=a;a=a.replace(/\/\/(.*)/g,"").replace(/\n|\r|\r\n/g," ");for(var e,i=new RegExp("^("+f(b).join("|")+")");a&&-1!==(e=g.findNextTokenIndex(a));){a=a.substr(e);var j=a.match(i);if(null===j)throw new Error("Error parsing "+a);if(j=j[1],!(j in b))throw new Error("Unknown token"+j);try{a=b[j](a,c,h).replace(/^\s*|\s*$/g,"")}catch(k){throw new Error("Invalid "+j+" definition \n"+k.message+"; \nstarting at : "+d)}}};c.parse=function(a,b){var c={define:[],rules:[],scope:[],loaded:[],file:b};return h(a,d,c),c}},{"../../extended":12,"./tokens.js":36,"./util.js":37}],36:[function(require,module,exports){var process=require("__browserify_process"),utils=require("./util.js"),fs=require("fs"),extd=require("../../extended"),filter=extd.filter,indexOf=extd.indexOf,isWhiteSpace=function(a){return 0===a.replace(/[\s|\n|\r|\t]/g,"").length},joinFunc=function(a,b){return"; "+b},splitRuleLineByPredicateExpressions=function(a){var b=a.replace(/,\s*(\$?\w+\s*:)/g,joinFunc),c=filter(b.split(/ *(not|or) *\(/g),function(a){return""!==a}),d=c.length,e=[];if(!d)return b;for(var f=0;d>f;f++)"not"===c[f]||"or"===c[f]?e.push([c[f],"(",c[++f].replace(/, *$/,"")].join("")):e.push(c[f].replace(/, *$/,""));return e.join(";")},ruleTokens={salience:function(){var a=/^(salience|priority)\s*:\s*(-?\d+)\s*[,;]?/;return function(b,c){if(a.test(b)){var d=b.match(a),e=parseInt(d[2],10);if(isNaN(e))throw new Error("Invalid salience/priority "+d[2]);return c.options.priority=e,b.replace(d[0],"")}throw new Error("invalid format")}}(),agendaGroup:function(){var a=/^(agenda-group|agendaGroup)\s*:\s*([a-zA-Z_$][0-9a-zA-Z_$]*|"[^"]*"|'[^']*')\s*[,;]?/;return function(b,c){if(a.test(b)){var d=b.match(a),e=d[2];if(!e)throw new Error("Invalid agenda-group "+d[2]);return c.options.agendaGroup=e.replace(/^["']|["']$/g,""),b.replace(d[0],"")}throw new Error("invalid format")}}(),autoFocus:function(){var a=/^(auto-focus|autoFocus)\s*:\s*(true|false)\s*[,;]?/;return function(b,c){if(a.test(b)){var d=b.match(a),e=d[2];if(!e)throw new Error("Invalid auto-focus "+d[2]);return c.options.autoFocus="true"===e?!0:!1,b.replace(d[0],"")}throw new Error("invalid format")}}(),"agenda-group":function(){return this.agendaGroup.apply(this,arguments)},"auto-focus":function(){return this.autoFocus.apply(this,arguments)},priority:function(){return this.salience.apply(this,arguments)},when:function(){var ruleRegExp=/^(\$?\w+) *: *(\w+)(.*)/,constraintRegExp=/(\{ *(?:["']?\$?\w+["']?\s*:\s*["']?\$?\w+["']? *(?:, *["']?\$?\w+["']?\s*:\s*["']?\$?\w+["']?)*)+ *\})/,predicateExp=/^(not|or) *\((.*)\)$/m,fromRegExp=/(\bfrom\s+.*)/,parseRules=function(str){for(var rules=[],ruleLines=str.split(";"),l=ruleLines.length,ruleLine,i=0;l>i&&(ruleLine=ruleLines[i].replace(/^\s*|\s*$/g,"").replace(/\n/g,""));i++)if(!isWhiteSpace(ruleLine)){var rule=[];if(predicateExp.test(ruleLine)){var m=ruleLine.match(predicateExp),pred=m[1].replace(/^\s*|\s*$/g,"");if(rule.push(pred),ruleLine=m[2].replace(/^\s*|\s*$/g,""),"or"===pred){rule=rule.concat(parseRules(splitRuleLineByPredicateExpressions(ruleLine))),rules.push(rule);continue}}var parts=ruleLine.match(ruleRegExp);if(!parts||!parts.length)throw new Error("Invalid constraint "+ruleLine);rule.push(parts[2],parts[1]);var constraints=parts[3].replace(/^\s*|\s*$/g,""),hashParts=constraints.match(constraintRegExp),from=null,fromMatch;if(hashParts){var hash=hashParts[1],constraint=constraints.replace(hash,"");fromRegExp.test(constraint)&&(fromMatch=constraint.match(fromRegExp),from=fromMatch[0],constraint=constraint.replace(fromMatch[0],"")),constraint&&rule.push(constraint.replace(/^\s*|\s*$/g,"")),hash&&rule.push(eval("("+hash.replace(/(\$?\w+)\s*:\s*(\$?\w+)/g,'"$1" : "$2"')+")"))}else constraints&&!isWhiteSpace(constraints)&&(fromRegExp.test(constraints)&&(fromMatch=constraints.match(fromRegExp),from=fromMatch[0],constraints=constraints.replace(fromMatch[0],"")),rule.push(constraints));from&&rule.push(from),rules.push(rule)}return rules};return function(a,b){var c=a.replace(/^when\s*/,"").replace(/^\s*|\s*$/g,"");if("{"===utils.findNextToken(c)){var d=utils.getTokensBetween(c,"{","}",!0).join("");return c=c.replace(d,""),b.constraints=parseRules(d.replace(/^\{\s*|\}\s*$/g,"")),c}throw new Error("unexpected token : expected : '{' found : '"+utils.findNextToken(c)+"'")}}(),then:function(){return function(a,b){if(b.action)throw new Error("action already defined for rule"+b.name);var c=a.replace(/^then\s*/,"").replace(/^\s*|\s*$/g,"");if("{"===utils.findNextToken(c)){var d=utils.getTokensBetween(c,"{","}",!0).join("");if(c=c.replace(d,""),b.action||(b.action=d.replace(/^\{\s*|\}\s*$/g,"")),!isWhiteSpace(c))throw new Error("Error parsing then block "+a);return c}throw new Error("unexpected token : expected : '{' found : '"+utils.findNextToken(c)+"'")}}()},topLevelTokens={"/":function(a){return a.match(/^\/\*/)?a.replace(/\/\*.*?\*\//,""):a},define:function(a,b){var c=a.replace(/^define\s*/,""),d=c.match(/^([a-zA-Z_$][0-9a-zA-Z_$]*)/);if(d){if(c=c.replace(d[0],"").replace(/^\s*|\s*$/g,""),"{"===utils.findNextToken(c)){d=d[1];var e=utils.getTokensBetween(c,"{","}",!0).join("");return c=c.replace(e,""),b.define.push({name:d,properties:"("+e+")"}),c}throw new Error("unexpected token : expected : '{' found : '"+utils.findNextToken(c)+"'")}throw new Error("missing name")},"import":function(a,b,c){if("undefined"!=typeof window)throw new Error("import cannot be used in a browser");var d=a.replace(/^import\s*/,"");if("("===utils.findNextToken(d)){var e=utils.getParamList(d);if(d=d.replace(e,"").replace(/^\s*|\s*$/g,""),";"===utils.findNextToken(d)&&(d=d.replace(/\s*;/,"")),e=e.replace(/[\(|\)]/g,"").split(","),1===e.length){if(e=utils.resolve(b.file||process.cwd(),e[0].replace(/["|']/g,"")),-1===indexOf(b.loaded,e)){var f=b.file;b.file=e,c(fs.readFileSync(e,"utf8"),topLevelTokens,b),b.loaded.push(e),b.file=f}return d}throw new Error("import accepts a single file")}throw new Error("unexpected token : expected : '(' found : '"+utils.findNextToken(d)+"'")},global:function(a,b){var c=a.replace(/^global\s*/,""),d=c.match(/^([a-zA-Z_$][0-9a-zA-Z_$]*\s*)/);if(d){if(c=c.replace(d[0],"").replace(/^\s*|\s*$/g,""),"="===utils.findNextToken(c)){d=d[1].replace(/^\s+|\s+$/g,"");var e=utils.getTokensBetween(c,"=",";",!0).join(""),f=e.substring(1,e.length-1);if(f=f.replace(/^\s+|\s+$/g,""),/^require\(/.test(f)){var g=utils.getParamList(f.replace("require")).replace(/[\(|\)]/g,"").split(",");1===g.length&&(g=g[0].replace(/["|']/g,""),f=["require('",utils.resolve(b.file||process.cwd(),g),"')"].join(""))}return b.scope.push({name:d,body:f}),c=c.replace(e,"")}throw new Error("unexpected token : expected : '=' found : '"+utils.findNextToken(c)+"'")}throw new Error("missing name")},"function":function(a,b){var c=a.replace(/^function\s*/,""),d=c.match(/^([a-zA-Z_$][0-9a-zA-Z_$]*)\s*/);if(d){if(c=c.replace(d[0],""),"("===utils.findNextToken(c)){d=d[1];var e=utils.getParamList(c);if(c=c.replace(e,"").replace(/^\s*|\s*$/g,""),"{"===utils.findNextToken(c)){var f=utils.getTokensBetween(c,"{","}",!0).join("");return c=c.replace(f,""),b.scope.push({name:d,body:"function"+e+f}),c}throw new Error("unexpected token : expected : '{' found : '"+utils.findNextToken(c)+"'")}throw new Error("unexpected token : expected : '(' found : '"+utils.findNextToken(c)+"'")}throw new Error("missing name")},rule:function(a,b,c){var d=a.replace(/^rule\s*/,""),e=d.match(/^([a-zA-Z_$][0-9a-zA-Z_$]*|"[^"]*"|'[^']*')/);if(e){if(d=d.replace(e[0],"").replace(/^\s*|\s*$/g,""),"{"===utils.findNextToken(d)){e=e[1].replace(/^["']|["']$/g,"");var f={name:e,options:{},constraints:null,action:null},g=utils.getTokensBetween(d,"{","}",!0).join("");return d=d.replace(g,""),c(g.replace(/^\{\s*|\}\s*$/g,""),ruleTokens,f),b.rules.push(f),d}throw new Error("unexpected token : expected : '{' found : '"+utils.findNextToken(d)+"'")}throw new Error("missing name")}};module.exports=topLevelTokens},{"../../extended":12,"./util.js":37,__browserify_process:54,fs:51}],37:[function(a,b,c){var d=a("__browserify_process"),e=a("path"),f=/[\s|\n|\r|\t]/,g=e.sep||("win32"===d.platform?"\\":"/"),h={"{":"}","}":"{","(":")",")":"(","[":"]"},i=c.getTokensBetween=function(a,b,c,d){var e=0,f=[];b||(b=h[c],e=1),c||(c=h[b]),a=Object(a);for(var g,i=!1,j=0,k=!1;g=a.charAt(j++);)if(g===b)e++,i?f.push(g):(i=!0,d&&f.push(g));else if(g===c&&j){if(e--,0===e){d&&f.push(g),k=!0;break}f.push(g)}else i&&f.push(g);if(!k)throw new Error("Unable to match "+b+" in "+a);return f};c.getParamList=function(a){return i(a,"(",")",!0).join("")},c.resolve=function(a,b){return""!==e.extname(a)&&(a=e.dirname(a)),1===b.split(g).length?b:e.resolve(a,b)};var j=c.findNextTokenIndex=function(a,b,c){b=b||0,c=c||a.length;var d=-1,e=a.length;for((!c||c>e)&&(c=e);c>b;b++){var g=a.charAt(b);if(!f.test(g)){d=b;break}}return d};c.findNextToken=function(a,b,c){return a.charAt(j(a,b,c))}},{__browserify_process:54,path:52}],38:[function(a,b,c){"use strict";var d=a("./extended"),e=d.isEmpty,f=d.merge,g=d.forEach,h=d.declare,i=a("./constraintMatcher"),j=a("./constraint"),k=j.EqualityConstraint,l=j.FromConstraint,m=0,n=h({}),o=n.extend({instance:{constructor:function(a,b,c,d,h){h=h||{},this.id=m++,this.type=a,this.alias=b,this.conditions=c,this.pattern=h.pattern;var k=[new j.ObjectConstraint(a)],l=i.toConstraints(c,f({alias:b},h));if(l.length)k=k.concat(l);else{var n=new j.TrueConstraint;k.push(n)}if(d&&!e(d)){var o=new j.HashConstraint(d);k.push(o)}g(k,function(a){a.set("alias",b)}),this.constraints=k},getSpecificity:function(){for(var a=this.constraints,b=0,c=0,d=a.length;d>c;c++)a[c]instanceof k&&b++;return b},hasConstraint:function(a){return d.some(this.constraints,function(b){return b instanceof a})},hashCode:function(){return[this.type,this.alias,d.format("%j",this.conditions)].join(":")},toString:function(){return d.format("%j",this.constraints)}}}).as(c,"ObjectPattern"),p=o.extend({instance:{constructor:function(a,b,c,d,e,f){this._super([a,b,c,d,f]),this.from=new l(e,f)},hasConstraint:function(a){return d.some(this.constraints,function(b){return b instanceof a})},getSpecificity:function(){return this._super(arguments)+1},hashCode:function(){return[this.type,this.alias,d.format("%j",this.conditions),this.from.from].join(":")},toString:function(){return d.format("%j from %s",this.constraints,this.from.from)}}}).as(c,"FromPattern");p.extend().as(c,"FromNotPattern"),o.extend().as(c,"NotPattern"),n.extend({instance:{constructor:function(a,b){this.id=m++,this.leftPattern=a,this.rightPattern=b},hashCode:function(){return[this.leftPattern.hashCode(),this.rightPattern.hashCode()].join(":")},getSpecificity:function(){return this.rightPattern.getSpecificity()+this.leftPattern.getSpecificity()},getters:{constraints:function(){return this.leftPattern.constraints.concat(this.rightPattern.constraints)}}}}).as(c,"CompositePattern");var q=h({instance:{constructor:function(){this.id=m++,this.recency=0}}}).as(c,"InitialFact");o.extend({instance:{constructor:function(){this._super([q,"i",[],{}])},assert:function(){return!0}}}).as(c,"InitialFactPattern")},{"./constraint":8,"./constraintMatcher":9,"./extended":12}],39:[function(a,b,c){"use strict";function d(a,b,c,d){f(b)?(d=c,c=b):b=b||{};var g=e.every(c,function(a){return f(a)});g&&1===c.length&&(c=c[0],g=!1);var h=[],i=b.scope||{};if(c.scope=i,g){for(var j,k=function(a,b){m[b]?e(m).forEach(function(b){b.push(a)}):(m[b]=0===b?[]:m[b-1].slice(),0!==b&&m[b].pop(),m[b].push(a))},l=c.length,m=[],n=0;l>n;n++)j=c[n],j.scope=i,e.forEach(w(j),k);h=e.map(m,function(c){for(var e=null,f=0;f>>0;if(0===d)return-1;var e=d;arguments.length>2&&(e=Number(arguments[2]),e!==e?e=0:0!==e&&e!==1/0&&e!==-(1/0)&&(e=(e>0||-1)*P(Q(e))));for(var f=e>=0?R(e,d-1):d-Q(e);f>=0;f--)if(f in c&&c[f]===b)return f;return-1}function i(a,b,c){if(a&&X&&X===a.filter)return a.filter(b,c);if(!N(a)||"function"!=typeof b)throw new TypeError;for(var d=Object(a),e=d.length>>>0,f=[],g=0;e>g;g++)if(g in d){var h=d[g];b.call(c,h,g,d)&&f.push(h)}return f}function j(a,b,c){if(!N(a)||"function"!=typeof b)throw new TypeError;if(a&&T&&T===a.forEach)return a.forEach(b,c),a;for(var d=0,e=a.length;e>d;++d)b.call(c||a,a[d],d,a);return a}function k(a,b,c){if(a&&Y&&Y===a.every)return a.every(b,c);if(!N(a)||"function"!=typeof b)throw new TypeError;for(var d=Object(a),e=d.length>>>0,f=0;e>f;f++)if(f in d&&!b.call(c,d[f],f,d))return!1;return!0}function l(a,b,c){if(a&&Z&&Z===a.some)return a.some(b,c);if(!N(a)||"function"!=typeof b)throw new TypeError;for(var d=Object(a),e=d.length>>>0,f=0;e>f;f++)if(f in d&&b.call(c,d[f],f,d))return!0;return!1}function m(a,b,c){if(a&&U&&U===a.map)return a.map(b,c);if(!N(a)||"function"!=typeof b)throw new TypeError;for(var d=Object(a),e=d.length>>>0,f=[],g=0;e>g;g++)g in d&&f.push(b.call(c,d[g],g,d));return f}function n(a,b,c){var d=arguments.length>2;if(a&&V&&V===a.reduce)return d?a.reduce(b,c):a.reduce(b);if(!N(a)||"function"!=typeof b)throw new TypeError;var e=0,f=a.length>>0;if(arguments.length<3){if(0===f)throw new TypeError("Array length is 0 and no second argument");c=a[0],e=1}else c=arguments[2];for(;f>e;)e in a&&(c=b.call(void 0,c,a[e],e,a)),++e;return c}function o(a,b,c){var d=arguments.length>2;if(a&&W&&W===a.reduceRight)return d?a.reduceRight(b,c):a.reduceRight(b);if(!N(a)||"function"!=typeof b)throw new TypeError;var e=Object(a),f=e.length>>>0;if(0===f&&2===arguments.length)throw new TypeError;var g=f-1;if(arguments.length>=3)c=arguments[2];else for(;;)if(g in a){c=a[g--];break}for(;g>=0;)g in e&&(c=b.call(void 0,c,e[g],g,e)),g--;return c}function p(a){var c=[];if(null!==a){var d=$(arguments);if(1===d.length)if(N(a))c=a;else if(b.isHash(a))for(var e in a)a.hasOwnProperty(e)&&c.push([e,a[e]]);else c.push(a);else j(d,function(a){c=c.concat(p(a))})}return c}function q(a){return a=a||[],a.length?n(a,function(a,b){return a+b}):0}function r(a){if(a=a||[],a.length){var c=q(a);if(b.isNumber(c))return c/a.length;throw new Error("Cannot average an array of non numbers.")}return 0}function s(a,b){return _(a,b)}function t(a,b){return _(a,b)[0]}function u(a,b){return _(a,b)[a.length-1]}function v(a){var b=a,c=J($(arguments,1));return N(a)&&(b=i(a,function(a){return-1===g(c,a)})),b}function w(a){var b,c=[],d=-1,e=0;if(a)for(b=a.length;++d0?(c.push(c.shift()),b--):(c.unshift(c.pop()),b++),y(c,b)):c}function z(a,b){var c=[];if(N(a)){var d=a.slice(0);"number"!=typeof b&&(b=a.length),b?b<=a.length&&(c=n(a,function(a,c,f){var g;return g=b>1?e(c,y(d,f).slice(1),b):[[c]],a.concat(g)},[])):c=[[]]}return c}function A(){var a=[],c=$(arguments);if(c.length>1){var d=c.shift();N(d)&&(a=n(d,function(a,d,e){for(var f=[d],g=0;gd;d++)c.push(a[b[d]]||null);return c}function D(){var a=[],b=$(arguments);if(b.length>1){for(var c=0,d=b.length;d>c;c++)a=a.concat(b[c]);a=w(a)}return a}function E(){var a,b,c=[],d=-1;if(a=arguments.length>1?$(arguments):arguments[0],N(a))for(c=a[0],d=0,b=a.length;++d1?c:p(a),n(b,function(a,b){return a.concat(b)},[])}function K(a,b){b=b.split(".");var c=a.slice(0);return j(b,function(a){var b=a.match(/(\w+)\(\)$/);c=m(c,function(c){return b?c[b[1]]():c[a]})}),c}function L(a,b,c){return c=$(arguments,2),m(a,function(a){var d=M(b)?a[b]:b;return d.apply(a,c)})}var M=b.isString,N=Array.isArray||b.isArray,O=b.isDate,P=Math.floor,Q=Math.abs,R=(Math.max,Math.min),S=Array.prototype,T=(S.indexOf,S.forEach),U=S.map,V=S.reduce,W=S.reduceRight,X=S.filter,Y=S.every,Z=S.some,$=c.argsToArray,_=function(){var a=function(a,b){return k(a,b)},b=function(a,b){return a-b},c=function(a,b){return a.getTime()-b.getTime()};return function(d,e){var f=[];return N(d)&&(f=d.slice(),e?"function"==typeof e?f.sort(e):f.sort(function(a,b){var c=a[e],d=b[e];return M(c)&&M(d)?c>d?1:d>c?-1:0:O(c)&&O(d)?c.getTime()-d.getTime():c-d}):a(f,M)?f.sort():a(f,O)?f.sort(c):f.sort(b)),f}}(),ab={toArray:p,sum:q,avg:r,sort:s,min:t,max:u,difference:v,removeDuplicates:w,unique:x,rotate:y,permutations:z,zip:A,transpose:B,valuesAt:C,union:D,intersect:E,powerSet:F,cartesian:G,compact:H,multiply:I,flatten:J,pluck:K,invoke:L,forEach:j,map:m,filter:i,reduce:n,reduceRight:o,some:l,every:k,indexOf:g,lastIndexOf:h};return a.define(N,ab).expose(ab)}"undefined"!=typeof c?"undefined"!=typeof b&&b.exports&&(b.exports=d(a("extended"),a("is-extended"),a("arguments-extended"))):"function"==typeof define&&define.amd?define(["extended","is-extended","arguments-extended"],function(a,b,c){return d(a,b,c) -}):this.arrayExtended=d(this.extended,this.isExtended,this.argumentsExtended)}.call(this)},{"arguments-extended":41,extended:46,"is-extended":56}],43:[function(a,b,c){!function(){"use strict";function d(a,b,c){function d(a,b,c,d){a=""+a,c=c||" ";for(var e=a.length;b>e;)d?a+=c:a=c+a,e++;return a}function e(a,c,d){var f=a;if(b.isString(f)){if(a.length>c)if(d){var g=a.length;f=a.substring(g-c,g)}else f=a.substring(0,c)}else f=e(""+f,c);return f}function f(a,c,d){if(!b.isArray(a)||"function"!=typeof c)throw new TypeError;for(var e=Object(a),f=e.length>>>0,g=0;f>g;g++)if(g in e&&!c.call(d,e[g],g,e))return!1;return!0}function g(a,b){return A.difference(new Date(a.getFullYear(),0,1,a.getHours()),a,null,b)+1}function h(a,b,c){b=b||0;var d=a[c?"getUTCFullYear":"getFullYear"](),e=new Date(d,0,1).getDay(),f=(e-b+7)%7,h=o((g(a)+f-1)/7);return e===b&&h++,h}function i(a){var b=a.toString(),c="",d=b.indexOf("(");return d>-1&&(c=b.substring(++d,b.indexOf(")"))),c}function j(a,b){return a.replace(/([a-z])\1*/gi,function(a){var c,d=a.charAt(0),e=a.length,f="0?",g="0{0,2}";if("y"===d)c="\\d{2,4}";else if("M"===d)c=e>2?"\\S+?":"1[0-2]|"+f+"[1-9]";else if("D"===d)c="[12][0-9][0-9]|3[0-5][0-9]|36[0-6]|"+g+"[1-9][0-9]|"+f+"[1-9]";else if("d"===d)c="3[01]|[12]\\d|"+f+"[1-9]";else if("w"===d)c="[1-4][0-9]|5[0-3]|"+f+"[1-9]";else if("E"===d)c="\\S+";else if("h"===d)c="1[0-2]|"+f+"[1-9]";else if("K"===d)c="1[01]|"+f+"\\d";else if("H"===d)c="1\\d|2[0-3]|"+f+"\\d";else if("k"===d)c="1\\d|2[0-4]|"+f+"[1-9]";else if("m"===d||"s"===d)c="[0-5]\\d";else if("S"===d)c="\\d{"+e+"}";else if("a"===d){var h="AM",i="PM";c=h+"|"+i,h!==h.toLowerCase()&&(c+="|"+h.toLowerCase()),i!==i.toLowerCase()&&(c+="|"+i.toLowerCase()),c=c.replace(/\./g,"\\.")}else c="v"===d||"z"===d||"Z"===d||"G"===d||"q"===d||"Q"===d?".*":" "===d?"\\s*":d+"*";return b&&b.push(a),"("+c+")"}).replace(/[\xa0 ]/g,"[\\s\\xa0]")}function k(a){B[a+"sFromNow"]=function(b){return A.add(new Date,a,b)},B[a+"sAgo"]=function(b){return A.add(new Date,a,-b)}}for(var l=function(){function a(a,b,c){return a=a.replace(/s$/,""),e.hasOwnProperty(a)?e[a](b,c):[c,"UTC"+a.charAt(0).toUpperCase()+a.substring(1)+"s",!1]}function b(a,b,c,e){return a=a.replace(/s$/,""),d(f[a](b,c,e))}var c=Math.floor,d=Math.round,e={day:function(a,b){return[b,"Date",!1]},weekday:function(a,b){var c,d,e=b%5,f=a.getDay(),g=0;e?(c=e,d=parseInt(b/5,10)):(c=b>0?5:-5,d=b>0?(b-5)/5:(b+5)/5),6===f&&b>0?g=1:0===f&&0>b&&(g=-1);var h=f+c;return(0===h||6===h)&&(g=b>0?2:-2),[7*d+c+g,"Date",!1]},year:function(a,b){return[b,"FullYear",!0]},week:function(a,b){return[7*b,"Date",!1]},quarter:function(a,b){return[3*b,"Month",!0]},month:function(a,b){return[b,"Month",!0]}},f={quarter:function(a,b,d){var e=b.getFullYear()-a.getFullYear(),f=a[d?"getUTCMonth":"getMonth"](),g=b[d?"getUTCMonth":"getMonth"](),h=c(f/3)+1,i=c(g/3)+1;return i+=4*e,i-h},weekday:function(a,c,d){var e,f=b("day",a,c,d),g=f%7;if(0===g)f=5*b("week",a,c,d);else{var h=0,i=a[d?"getUTCDay":"getDay"](),j=c[d?"getUTCDay":"getDay"]();e=parseInt(f/7,10);var k=new Date(+a);k.setDate(k[d?"getUTCDate":"getDate"]()+7*e);var l=k[d?"getUTCDay":"getDay"]();f>0?6===i||6===j?h=-1:0===i?h=0:(0===j||l+g>5)&&(h=-2):0>f&&(6===i?h=0:0===i||0===j?h=1:(6===j||0>l+g)&&(h=2)),f+=h,f-=2*e}return f},year:function(a,b){return b.getFullYear()-a.getFullYear()},month:function(a,b,c){var d=a[c?"getUTCMonth":"getMonth"](),e=b[c?"getUTCMonth":"getMonth"]();return e-d+12*(b.getFullYear()-a.getFullYear())},week:function(a,c,e){return d(b("day",a,c,e)/7)},day:function(a,b){return 1.1574074074074074e-8*(b.getTime()-a.getTime())},hour:function(a,b){return 2.7777777777777776e-7*(b.getTime()-a.getTime())},minute:function(a,b){return 16666666666666667e-21*(b.getTime()-a.getTime())},second:function(a,b){return.001*(b.getTime()-a.getTime())},millisecond:function(a,b){return b.getTime()-a.getTime()}};return{addTransform:a,differenceTransform:b}}(),m=l.addTransform,n=l.differenceTransform,o=Math.floor,p=Math.round,q=Math.min,r=Math.pow,s=Math.ceil,t=Math.abs,u=["January","February","March","April","May","June","July","August","September","October","November","December"],v=["Jan.","Feb.","Mar.","Apr.","May.","Jun.","Jul.","Aug.","Sep.","Oct.","Nov.","Dec."],w=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],x=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],y=["Before Christ","Anno Domini"],z=["BC","AD"],A={getDaysInMonth:function(a){var b=a.getMonth(),c=[31,28,31,30,31,30,31,31,30,31,30,31];return 1===b&&A.isLeapYear(a)?29:c[b]},isLeapYear:function(a,b){var c=a[b?"getUTCFullYear":"getFullYear"]();return 0===c%400||0===c%4&&0!==c%100},isWeekend:function(a,b){var c=(a||new Date)[b?"getUTCDay":"getDay"]();return 0===c||6===c},getTimezoneName:i,compare:function(a,b,c){return a=new Date(+a),b=new Date(+(b||new Date)),"date"===c?(a.setHours(0,0,0,0),b.setHours(0,0,0,0)):"time"===c&&(a.setFullYear(0,0,0),b.setFullYear(0,0,0)),a>b?1:b>a?-1:0},add:function(a,b,c){var d=m(b,a,c||0);c=d[0];var e=d[1],f=new Date(+a),g=d[2];return e&&f["set"+e](f["get"+e]()+c),g&&f.getDate()E?z:y)[0>f?0:1];else if("y"===D)B=f,E>1&&(2===E?B=e(""+B,2,!0):C=!0);else if("Q"===D.toUpperCase())B=s((j+1)/3),C=!0;else if("M"===D)3>E?(B=j+1,C=!0):B=(3===E?v:u)[j];else if("w"===D)B=h(a,0,c),C=!0;else if("D"===D)B=g(a,c),C=!0;else if("E"===D)3>E?(B=k+1,C=!0):B=(-3===E?x:w)[k];else if("a"===D)B=12>m?"AM":"PM";else if("h"===D)B=m%12||12,C=!0;else if("K"===D)B=m%12,C=!0;else if("k"===D)B=m||24,C=!0;else if("S"===D)B=p(A*r(10,E-3)),C=!0;else if("z"===D||"v"===D||"Z"===D){if(B=i(a),"z"!==D&&"v"!==D||B||(E=4),!B||"Z"===D){var F=a.getTimezoneOffset(),G=[F>=0?"-":"+",d(o(t(F)/60),2,"0"),d(t(F)%60,2,"0")];4===E&&(G.splice(0,0,"GMT"),G.splice(3,0,":")),B=G.join("")}}else B=b;else B=""+n,C=!0;else B=""+m,C=!0;return C&&(B=d(B,E,"0")),B})}},B={},C=["year","month","day","hour","minute","second"],D=0,E=C.length;E>D;D++)k(C[D]);var F={parseDate:function(a,b){if(!b)throw new Error("format required when calling dateExtender.parse");var d=[],e=j(b,d),g=new RegExp("^"+e+"$","i"),h=g.exec(a);if(!h)return null;var i=[1970,0,1,0,0,0,0],k="",l=f(h,function(a,b){if(b){var e=d[b-1],f=e.length,g=e.charAt(0);if("y"===g)if(100>a){a=parseInt(a,10);var h=""+(new Date).getFullYear(),j=100*h.substring(0,2),l=q(h.substring(2,4)+20,99);i[0]=l>a?j+a:j-100+a}else i[0]=a;else if("M"===g){if(f>2){var m,n,o=u;3===f&&(o=v),a=a.replace(".","").toLowerCase();var p=!1;for(m=0,n=o.length;n>m&&!p;m++){var r=o[m].replace(".","").toLocaleLowerCase();r===a&&(a=m,p=!0)}if(!p)return!1}else a--;i[1]=a}else if("E"===g||"e"===g){var s=w;3===f&&(s=x),a=a.toLowerCase(),s=c.map(s,function(a){return a.toLowerCase()});var t=c.indexOf(s,a);if(-1===t){if(a=parseInt(a,10),isNaN(a)||a>s.length)return!1}else a=t}else if("D"===g||"d"===g)"D"===g&&(i[1]=0),i[2]=a;else if("a"===g){var y="am",z="pm",A=/\./g;a=a.replace(A,"").toLowerCase(),k=a===z?"p":a===y?"a":""}else"k"===g||"h"===g||"H"===g||"K"===g?("k"===g&&24===+a&&(a=0),i[3]=a):"m"===g?i[4]=a:"s"===g?i[5]=a:"S"===g&&(i[6]=a)}return!0});if(l){var m=+i[3];"p"===k&&12>m?i[3]=m+12:"a"===k&&12===m&&(i[3]=0);var n=new Date(i[0],i[1],i[2],i[3],i[4],i[5],i[6]),o=-1!==c.indexOf(d,"d"),p=-1!==c.indexOf(d,"M"),r=i[1],s=i[2],t=n.getMonth(),y=n.getDate();return p&&t>r||o&&y>s?null:n}return null}},G=a.define(b.isDate,A).define(b.isString,F).define(b.isNumber,B);for(D in A)A.hasOwnProperty(D)&&(G[D]=A[D]);for(D in F)F.hasOwnProperty(D)&&(G[D]=F[D]);for(D in B)B.hasOwnProperty(D)&&(G[D]=B[D]);return G}"undefined"!=typeof c?"undefined"!=typeof b&&b.exports&&(b.exports=d(a("extended"),a("is-extended"),a("array-extended"))):"function"==typeof define&&define.amd?define(["extended","is-extended","array-extended"],function(a,b,c){return d(a,b,c)}):this.dateExtended=d(this.extended,this.isExtended,this.arrayExtended)}.call(this)},{"array-extended":42,extended:46,"is-extended":56}],44:[function(a,b,c){!function(){function a(){function a(a,b){return b=b||0,x.call(a,b)}function b(a){return"[object Array]"===Object.prototype.toString.call(a)}function c(a){var b;return null!==a&&a!==b&&"object"==typeof a}function d(a){var b=c(a);return b&&a.constructor===Object}function e(a,b){if(a&&a.length)for(var c=0,d=a.length;d>c;c++)if(a[c]===b)return c;return-1}function f(a,b,c){var d,f;for(d in b)b.hasOwnProperty(d)&&-1===e(c,d)&&(f=b[d],d in a&&a[d]===f||(a[d]=f));return a}function g(a){var c=this.__meta,d=c.supers,e=d.length,f=c.superMeta,g=f.pos;if(e>g){a=a?B(a)||b(a)?a:[a]:[];var h,i=f.name,j=f.f;do if(h=d[g][i],"function"==typeof h&&(h=h._f||h)!==j)return f.pos=1+g,h.apply(this,a);while(e>++g)}return null}function h(){var a=this.__meta,b=a.supers,c=b.length,d=a.superMeta,e=d.pos;if(c>e){var f,g=d.name,h=d.f;do if(f=b[e][g],"function"==typeof f&&(f=f._f||f)!==h)return d.pos=1+e,f.bind(this);while(c>++e)}return null}function i(a){var b=this.__getters__;return b.hasOwnProperty(a)?b[a].apply(this):this[a]}function j(b,c){var e=this.__setters__;if(!d(b))return e.hasOwnProperty(b)?e[b].apply(this,a(arguments,1)):this[b]=c;for(var f in b){var g=b[f];e.hasOwnProperty(f)?e[b].call(this,g):this[f]=g}}function k(){var a=this.__meta||{},b=a.supers,c=b.length,d=a.superMeta,e=d.pos;if(c>e){var f,g=d.name,h=d.f;do if(f=b[e][g],"function"==typeof f&&(f=f._f||f)!==h)return d.pos=1+e,f.apply(this,arguments);while(c>++e)}return null}function l(a,b){if(a.toString().match(A)){var c=function(){var c,d=this.__meta||{},e=d.superMeta;switch(d.superMeta={f:a,pos:0,name:b},arguments.length){case 0:c=a.call(this);break;case 1:c=a.call(this,arguments[0]);break;case 2:c=a.call(this,arguments[0],arguments[1]);break;case 3:c=a.call(this,arguments[0],arguments[1],arguments[2]);break;default:c=a.apply(this,arguments)}return d.superMeta=e,c};return c._f=a,c}return a._f=a,a}function m(a,b){var c=b.setters||{},d=a.__setters__,e=a.__getters__;for(var f in c)d.hasOwnProperty(f)||(d[f]=c[f]);c=b.getters||{};for(f in c)e.hasOwnProperty(f)||(e[f]=c[f]);for(var g in b)if("getters"!==g&&"setters"!==g){var h=b[g];"function"==typeof h?a.hasOwnProperty(g)||(a[g]=l(k,g)):a[g]=h}}function n(){for(var b=a(arguments),c=b.length,d=this.prototype,e=d.__meta,f=this.__meta,g=d.__meta.bases,h=g.slice(),i=f.supers||[],j=e.supers||[],k=0;c>k;k++){var l=b[k],n=l.prototype,p=n.__meta,q=l.__meta;!p&&(p=n.__meta={proto:n||{}}),!q&&(q=l.__meta={proto:l.__proto__||{}}),m(d,p.proto||{}),m(this,q.proto||{}),o(l.prototype,j,g),o(l,i,h)}return this}function o(a,b,c){var d=a.__meta;!d&&(d=a.__meta={});var f=a.__meta.unique;if(!f&&(d.unique="declare"+ ++y),-1===e(c,f)){c.push(f);for(var g=a.__meta.supers||[],h=g.length-1||0;h>=0;)o(g[h--],b,c);b.unshift(a)}}function p(a,b){var c=b.setters,d=a.__setters__,e=a.__getters__;if(c)for(var f in c)d[f]=c[f];if(c=b.getters||{})for(f in c)e[f]=c[f];for(f in b)if("getters"!=f&&"setters"!=f){var g=b[f];if("function"==typeof g){var h=g.__meta||{};a[f]=h.isConstructor?g:l(g,f)}else a[f]=g}}function q(a,b){return a&&b?a[b]=this:a.exports=a=this,this}function r(a){return u(this,a)}function s(a){z.prototype=a.prototype;var b=new z;return z.prototype=null,b}function t(a,c,e){var i={},j=[],m="declare"+ ++y,q=[],r=[],t=[],u=[],v={supers:t,unique:m,bases:q,superMeta:{f:null,pos:0,name:null}},x={supers:u,unique:m,bases:r,isConstructor:!0,superMeta:{f:null,pos:0,name:null}};if(d(c)&&!e&&(e=c,c=w),"function"==typeof c||b(c)?(j=b(c)?c:[c],c=j.shift(),a.__meta=x,i=s(c),i.__meta=v,i.__getters__=f({},i.__getters__||{}),i.__setters__=f({},i.__setters__||{}),a.__getters__=f({},a.__getters__||{}),a.__setters__=f({},a.__setters__||{}),o(c.prototype,t,q),o(c,u,r)):(a.__meta=x,i.__meta=v,i.__getters__=i.__getters__||{},i.__setters__=i.__setters__||{},a.__getters__=a.__getters__||{},a.__setters__=a.__setters__||{}),a.prototype=i,e){var z=v.proto=e.instance||{},A=x.proto=e.static||{};A.init=A.init||k,p(i,z),p(a,A),i.constructor=z.hasOwnProperty("constructor")?l(z.constructor,"constructor"):z.constructor=l(k,"constructor")}else v.proto={},x.proto={},a.init=l(k,"init"),i.constructor=l(k,"constructor");j.length&&n.apply(a,j),c&&f(a,f(f({},c),a)),i._super=a._super=g,i._getSuper=a._getSuper=h,i._static=a}function u(a,b){function c(){switch(arguments.length){case 0:this.constructor.call(this);break;case 1:this.constructor.call(this,arguments[0]);break;case 2:this.constructor.call(this,arguments[0],arguments[1]);break;case 3:this.constructor.call(this,arguments[0],arguments[1],arguments[2]);break;default:this.constructor.apply(this,arguments)}}return t(c,a,b),c.init()||c}function v(a,b){function c(){return d||(this.constructor.apply(this,arguments),d=this),d}var d;return t(c,a,b),c.init()||c}var w,x=Array.prototype.slice,y=0,z=new Function,A=/(super)/g,B=function(a){return"[object Arguments]"===Object.prototype.toString.call(a)};return B(arguments)||(B=function(a){return!(!a||!a.hasOwnProperty("callee"))}),w=u({instance:{get:i,set:j},"static":{get:i,set:j,mixin:n,extend:r,as:q}}),u.singleton=v,u}"undefined"!=typeof c?"undefined"!=typeof b&&b.exports&&(b.exports=a()):"function"==typeof define&&define.amd?define(a):this.declare=a()}()},{}],45:[function(a,b){b.exports=a("./declare.js")},{"./declare.js":44}],46:[function(a,b,c){!function(){"use strict";function d(a){function b(){var b=a.define();return b.expose({register:function(a,c){c||(c=a,a=null);var d=typeof c;if(a)b[a]=c;else if(c&&"function"===d)b.extend(c);else{if("object"!==d)throw new TypeError("extended.register must be called with an extender function");b.expose(c)}return b},define:function(){return a.define.apply(a,arguments)}}),b}function c(){return b()}return function(){function a(a,b){var c,d;for(c in b)b.hasOwnProperty(c)&&(d=b[c],c in a&&a[c]===d||(a[c]=d));return a}return function(b){b||(b={});for(var c=1,d=arguments.length;d>c;c++)a(b,arguments[c]);return b}}(),c.define=function(){return a.define.apply(a,arguments)},c}"undefined"!=typeof c?"undefined"!=typeof b&&b.exports&&(b.exports=d(a("extender"))):"function"==typeof define&&define.amd?define(["extender"],function(a){return d(a)}):this.extended=d(this.extender)}.call(this)},{extender:48}],47:[function(a,b,c){!function(){function d(a){function b(a,b){if(a&&a.length)for(var c=0,d=a.length;d>c;c++)if(a[c]===b)return c;return-1}function c(a){return"[object Array]"===Object.prototype.toString.call(a)}function d(b){function c(a,b,c){if("function"!=typeof c)throw new TypeError("when extending type you must provide a function");var d;d="constructor"===b?function(){this._super(arguments),c.apply(this,arguments)}:function(){var a=f.call(arguments);a.unshift(this._value);var b=c.apply(this,a);return b!==e?this.__extender__(b):this},a[b]=d}function d(a,b,c){if("function"!=typeof c)throw new TypeError("when extending type you must provide a function");var d;d="constructor"===b?function(){this._super(arguments),c.apply(this,arguments)}:function(){var a=f.call(arguments);return a.unshift(this._value),c.apply(this,a)},a[b]=d}function h(a,b,e){for(var f in b)b.hasOwnProperty(f)&&("getters"!==f&&"setters"!==f?"noWrap"===f?h(a,b[f],!0):e?d(a,f,b[f]):c(a,f,b[f]):a[f]=b[f])}function i(a){var b,c,d=a;if(!(a instanceof m)){var e=m;for(b=0,c=n.length;c>b;b++){var f=n[b];f[0](a)&&(e=e.extend({instance:f[1]}))}d=new e(a),d.__extender__=i}return d}function j(){return!0}function k(a,b){if(arguments.length){"object"==typeof a&&(b=a,a=j),b=b||{};var d={};h(d,b),d.hasOwnProperty("constructor")||(b.hasOwnProperty("constructor")?c(d,"constructor",b.constructor):d.constructor=function(){this._super(arguments)}),n.push([a,d])}return i}function l(a){return a&&a.hasOwnProperty("__defined__")&&(i.__defined__=n=n.concat(a.__defined__)),g(i,a,["define","extend","expose","__defined__"]),i}b=b||[];var m=a({instance:{constructor:function(a){this._value=a},value:function(){return this._value},eq:function(a){return this.__extender__(this._value===a)},neq:function(a){return this.__extender__(this._value!==a)},print:function(){return console.log(this._value),this}}}),n=[];return i.define=k,i.extend=l,i.expose=function(){for(var a,b=0,c=arguments.length;c>b;b++)a=arguments[b],"object"==typeof a&&g(i,a,["define","extend","expose","__defined__"]);return i},i.__defined__=n,i}var e,f=Array.prototype.slice,g=function(){function a(a,c,d){var e,f;for(e in c)c.hasOwnProperty(e)&&-1===b(d,e)&&(f=c[e],e in a&&a[e]===f||(a[e]=f));return a}return function(b){b||(b={});var d=arguments.length,e=arguments[arguments.length-1];c(e)?d--:e=[];for(var f=1;d>f;f++)a(b,arguments[f],e);return b}}();return{define:function(){return d().define.apply(d,arguments)},extend:function(a){return d().define().extend(a)}}}"undefined"!=typeof c?"undefined"!=typeof b&&b.exports&&(b.exports=d(a("declare.js"))):"function"==typeof define&&define.amd?define(["declare"],function(a){return d(a)}):this.extender=d(this.declare)}.call(this)},{"declare.js":45}],48:[function(a,b){b.exports=a("./extender.js")},{"./extender.js":47}],49:[function(a,b,c){!function(){"use strict";function d(a,b,c){function d(a,b,c){if(c=o(arguments,2),m(b)&&!(b in a))throw new Error(b+" property not defined in scope");if(!m(b)&&!n(b))throw new Error(b+" is not a function");return m(b)?function(){var d=a[b];if(n(d)){var e=c.concat(o(arguments));return d.apply(a,e)}return d}:c.length?function(){var d=c.concat(o(arguments));return b.apply(a,d)}:function(){return b.apply(a,arguments)}}function e(a,b){if(b=o(arguments,1),!m(a)&&!n(a))throw new Error(a+" must be the name of a property or function to execute");return m(a)?function(){var c=o(arguments),d=c.shift(),e=d[a];return n(e)?(c=b.concat(c),e.apply(d,c)):e}:function(){var c=o(arguments),d=c.shift();return c=b.concat(c),a.apply(d,c)}}function f(a,b,c){if(c=o(arguments,2),m(b)&&!(b in a))throw new Error(b+" property not defined in scope");if(!m(b)&&!n(b))throw new Error(b+" is not a function");return m(b)?function(){var d=a[b];return n(d)?d.apply(a,c):d}:function(){return b.apply(a,c)}}function g(a){var b=o(arguments,1);if(!l(a)&&!n(a))throw new TypeError("scope must be an object");if(1===b.length&&k(b[0])&&(b=b[0]),!b.length){b=[];for(var c in a)a.hasOwnProperty(c)&&n(a[c])&&b.push(c)}for(var e=0,f=b.length;f>e;e++)a[b[e]]=d(a,a[b[e]]);return a}function h(a,b){if(b=o(arguments,1),!m(a)&&!n(a))throw new Error(a+" must be the name of a property or function to execute");return m(a)?function(){var c=this[a];if(n(c)){var d=b.concat(o(arguments));return c.apply(this,d)}return c}:function(){var c=b.concat(o(arguments));return a.apply(this,c)}}function i(a,b){return function(){var c=o(arguments);return b?a.apply(this,arguments):function(){return a.apply(this,c.concat(o(arguments)))}}}function j(a,b,c){var e;if(e=c?d(c,b):b,a)for(var f=a-1,g=f;g>=0;g--)e=i(e,g===f);return e}var k=b.isArray,l=b.isObject,m=b.isString,n=b.isFunction,o=c.argsToArray;return a.define(l,{bind:d,bindAll:g,bindIgnore:f,curry:function(a,b,c){return j(b,c,a)}}).define(n,{bind:function(a,b){return d.apply(this,[b,a].concat(o(arguments,2)))},bindIgnore:function(a,b){return f.apply(this,[b,a].concat(o(arguments,2)))},partial:h,applyFirst:e,curry:function(a,b,c){return j(b,a,c)},noWrap:{f:function(){return this.value()}}}).define(m,{bind:function(a,b){return d(b,a)},bindIgnore:function(a,b){return f(b,a)},partial:h,applyFirst:e,curry:function(a,b,c){return j(b,a,c)}}).expose({bind:d,bindAll:g,bindIgnore:f,partial:h,applyFirst:e,curry:j})}"undefined"!=typeof c?"undefined"!=typeof b&&b.exports&&(b.exports=d(a("extended"),a("is-extended"),a("arguments-extended"))):"function"==typeof define&&define.amd?define(["extended","is-extended","arguments-extended"],function(a,b,c){return d(a,b,c)}):this.functionExtended=d(this.extended,this.isExtended,this.argumentsExtended)}.call(this)},{"arguments-extended":41,extended:46,"is-extended":56}],50:[function(a,b,c){function d(a,b){if(a.indexOf)return a.indexOf(b);for(var c=0;ce;e++)d[e].apply(this,c);return!0}return!1},f.prototype.addListener=function(a,b){if("function"!=typeof b)throw new Error("addListener only takes instances of Function");if(this._events||(this._events={}),this.emit("newListener",a,b),this._events[a])if(g(this._events[a])){if(!this._events[a].warned){var c;c=void 0!==this._events.maxListeners?this._events.maxListeners:h,c&&c>0&&this._events[a].length>c&&(this._events[a].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[a].length),console.trace())}this._events[a].push(b)}else this._events[a]=[this._events[a],b];else this._events[a]=b;return this},f.prototype.on=f.prototype.addListener,f.prototype.once=function(a,b){var c=this;return c.on(a,function d(){c.removeListener(a,d),b.apply(this,arguments)}),this},f.prototype.removeListener=function(a,b){if("function"!=typeof b)throw new Error("removeListener only takes instances of Function");if(!this._events||!this._events[a])return this;var c=this._events[a];if(g(c)){var e=d(c,b);if(0>e)return this;c.splice(e,1),0==c.length&&delete this._events[a]}else this._events[a]===b&&delete this._events[a];return this},f.prototype.removeAllListeners=function(a){return 0===arguments.length?(this._events={},this):(a&&this._events&&this._events[a]&&(this._events[a]=null),this)},f.prototype.listeners=function(a){return this._events||(this._events={}),this._events[a]||(this._events[a]=[]),g(this._events[a])||(this._events[a]=[this._events[a]]),this._events[a]},f.listenerCount=function(a,b){var c;return c=a._events&&a._events[b]?"function"==typeof a._events[b]?1:a._events[b].length:0}},{__browserify_process:54}],51:[function(){},{}],52:[function(a,b,c){function d(a,b){for(var c=[],d=0;d=0;d--){var e=a[d];"."==e?a.splice(d,1):".."===e?(a.splice(d,1),c++):c&&(a.splice(d,1),c--)}if(b)for(;c--;c)a.unshift("..");return a}var f=a("__browserify_process"),g=/^(.+\/(?!$)|\/)?((?:.+?)?(\.[^.]*)?)$/;c.resolve=function(){for(var a="",b=!1,c=arguments.length;c>=-1&&!b;c--){var g=c>=0?arguments[c]:f.cwd();"string"==typeof g&&g&&(a=g+"/"+a,b="/"===g.charAt(0))}return a=e(d(a.split("/"),function(a){return!!a}),!b).join("/"),(b?"/":"")+a||"."},c.normalize=function(a){var b="/"===a.charAt(0),c="/"===a.slice(-1);return a=e(d(a.split("/"),function(a){return!!a}),!b).join("/"),a||b||(a="."),a&&c&&(a+="/"),(b?"/":"")+a},c.join=function(){var a=Array.prototype.slice.call(arguments,0);return c.normalize(d(a,function(a){return a&&"string"==typeof a}).join("/"))},c.dirname=function(a){var b=g.exec(a)[1]||"",c=!1;return b?1===b.length||c&&b.length<=3&&":"===b.charAt(1)?b:b.substring(0,b.length-1):"."},c.basename=function(a,b){var c=g.exec(a)[2]||"";return b&&c.substr(-1*b.length)===b&&(c=c.substr(0,c.length-b.length)),c},c.extname=function(a){return g.exec(a)[3]||""},c.relative=function(a,b){function d(a){for(var b=0;b=0&&""===a[c];c--);return b>c?[]:a.slice(b,c-b+1)}a=c.resolve(a).substr(1),b=c.resolve(b).substr(1);for(var e=d(a.split("/")),f=d(b.split("/")),g=Math.min(e.length,f.length),h=g,i=0;g>i;i++)if(e[i]!==f[i]){h=i;break}for(var j=[],i=h;i=0;e--)if(f[e]!=g[e])return!1;for(e=f.length-1;e>=0;e--)if(d=f[e],!h(a[d],b[d]))return!1;return!0}function l(a,b){return a&&b?b instanceof RegExp?b.test(a):a instanceof b?!0:b.call({},a)===!0?!0:!1:!1}function m(a,b,c,d){var e;"string"==typeof c&&(d=c,c=null);try{b()}catch(g){e=g}if(d=(c&&c.name?" ("+c.name+").":".")+(d?" "+d:"."),a&&!e&&f("Missing expected exception"+d),!a&&l(e,c)&&f("Got unwanted exception"+d),a&&e&&c&&!l(e,c)||!a&&e)throw e}var n=a("util"),o=a("buffer").Buffer,p=Array.prototype.slice,q=b.exports=g;q.AssertionError=function(a){this.name="AssertionError",this.message=a.message,this.actual=a.actual,this.expected=a.expected,this.operator=a.operator;var b=a.stackStartFunction||f;Error.captureStackTrace&&Error.captureStackTrace(this,b)},n.inherits(q.AssertionError,Error),q.AssertionError.prototype.toString=function(){return this.message?[this.name+":",this.message].join(" "):[this.name+":",e(JSON.stringify(this.actual,d),128),this.operator,e(JSON.stringify(this.expected,d),128)].join(" ")},q.AssertionError.__proto__=Error.prototype,q.fail=f,q.ok=g,q.equal=function(a,b,c){a!=b&&f(a,b,c,"==",q.equal)},q.notEqual=function(a,b,c){a==b&&f(a,b,c,"!=",q.notEqual)},q.deepEqual=function(a,b,c){h(a,b)||f(a,b,c,"deepEqual",q.deepEqual)},q.notDeepEqual=function(a,b,c){h(a,b)&&f(a,b,c,"notDeepEqual",q.notDeepEqual)},q.strictEqual=function(a,b,c){a!==b&&f(a,b,c,"===",q.strictEqual)},q.notStrictEqual=function(a,b,c){a===b&&f(a,b,c,"!==",q.notStrictEqual)},q.throws=function(){m.apply(this,[!0].concat(p.call(arguments)))},q.doesNotThrow=function(){m.apply(this,[!1].concat(p.call(arguments)))},q.ifError=function(a){if(a)throw a}},{util:2,buffer:3}],2:[function(a,b,c){function d(a){return a instanceof Array||Array.isArray(a)||a&&a!==Object.prototype&&d(a.__proto__)}function e(a){return a instanceof RegExp||"object"==typeof a&&"[object RegExp]"===Object.prototype.toString.call(a)}function f(a){if(a instanceof Date)return!0;if("object"!=typeof a)return!1;var b=Date.prototype&&h(Date.prototype),c=a.__proto__&&h(a.__proto__);return JSON.stringify(c)===JSON.stringify(b)}a("events"),c.isArray=d,c.isDate=function(a){return"[object Date]"===Object.prototype.toString.call(a)},c.isRegExp=function(a){return"[object RegExp]"===Object.prototype.toString.call(a)},c.print=function(){},c.puts=function(){},c.debug=function(){},c.inspect=function(a,b,i,j){function k(a,i){if(a&&"function"==typeof a.inspect&&a!==c&&(!a.constructor||a.constructor.prototype!==a))return a.inspect(i);switch(typeof a){case"undefined":return m("undefined","undefined");case"string":var j="'"+JSON.stringify(a).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return m(j,"string");case"number":return m(""+a,"number");case"boolean":return m(""+a,"boolean")}if(null===a)return m("null","null");var n=g(a),o=b?h(a):n;if("function"==typeof a&&0===o.length){if(e(a))return m(""+a,"regexp");var p=a.name?": "+a.name:"";return m("[Function"+p+"]","special")}if(f(a)&&0===o.length)return m(a.toUTCString(),"date");var q,r,s;if(d(a)?(r="Array",s=["[","]"]):(r="Object",s=["{","}"]),"function"==typeof a){var t=a.name?": "+a.name:"";q=e(a)?" "+a:" [Function"+t+"]"}else q="";if(f(a)&&(q=" "+a.toUTCString()),0===o.length)return s[0]+q+s[1];if(0>i)return e(a)?m(""+a,"regexp"):m("[Object]","special");l.push(a);var u=o.map(function(b){var c,e;if(a.__lookupGetter__&&(a.__lookupGetter__(b)?e=a.__lookupSetter__(b)?m("[Getter/Setter]","special"):m("[Getter]","special"):a.__lookupSetter__(b)&&(e=m("[Setter]","special"))),n.indexOf(b)<0&&(c="["+b+"]"),e||(l.indexOf(a[b])<0?(e=null===i?k(a[b]):k(a[b],i-1),e.indexOf("\n")>-1&&(e=d(a)?e.split("\n").map(function(a){return" "+a}).join("\n").substr(2):"\n"+e.split("\n").map(function(a){return" "+a}).join("\n"))):e=m("[Circular]","special")),"undefined"==typeof c){if("Array"===r&&b.match(/^\d+$/))return e;c=JSON.stringify(""+b),c.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(c=c.substr(1,c.length-2),c=m(c,"name")):(c=c.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),c=m(c,"string"))}return c+": "+e});l.pop();var v=0,w=u.reduce(function(a,b){return v++,b.indexOf("\n")>=0&&v++,a+b.length+1},0);return u=w>50?s[0]+(""===q?"":q+"\n ")+" "+u.join(",\n ")+" "+s[1]:s[0]+q+" "+u.join(", ")+" "+s[1]}var l=[],m=function(a,b){var c={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]},d={special:"cyan",number:"blue","boolean":"yellow",undefined:"grey","null":"bold",string:"green",date:"magenta",regexp:"red"}[b];return d?"["+c[d][0]+"m"+a+"["+c[d][1]+"m":a};return j||(m=function(a){return a}),k(a,"undefined"==typeof i?2:i)},c.log=function(){},c.pump=null;var g=Object.keys||function(a){var b=[];for(var c in a)b.push(c);return b},h=Object.getOwnPropertyNames||function(a){var b=[];for(var c in a)Object.hasOwnProperty.call(a,c)&&b.push(c);return b},i=Object.create||function(a,b){var c;if(null===a)c={__proto__:null};else{if("object"!=typeof a)throw new TypeError("typeof prototype["+typeof a+"] != 'object'");var d=function(){};d.prototype=a,c=new d,c.__proto__=a}return"undefined"!=typeof b&&Object.defineProperties&&Object.defineProperties(c,b),c};c.inherits=function(a,b){a.super_=b,a.prototype=i(b.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}})};var j=/%[sdj%]/g;c.format=function(a){if("string"!=typeof a){for(var b=[],d=0;d=f)return a;switch(a){case"%s":return String(e[d++]);case"%d":return Number(e[d++]); -case"%j":return JSON.stringify(e[d++]);default:return a}}),h=e[d];f>d;h=e[++d])g+=null===h||"object"!=typeof h?" "+h:" "+c.inspect(h);return g}},{events:4}],5:[function(a,b,c){c.readIEEE754=function(a,b,c,d,e){var f,g,h=8*e-d-1,i=(1<>1,k=-7,l=c?0:e-1,m=c?1:-1,n=a[b+l];for(l+=m,f=n&(1<<-k)-1,n>>=-k,k+=h;k>0;f=256*f+a[b+l],l+=m,k-=8);for(g=f&(1<<-k)-1,f>>=-k,k+=d;k>0;g=256*g+a[b+l],l+=m,k-=8);if(0===f)f=1-j;else{if(f===i)return g?0/0:1/0*(n?-1:1);g+=Math.pow(2,d),f-=j}return(n?-1:1)*g*Math.pow(2,f-d)},c.writeIEEE754=function(a,b,c,d,e,f){var g,h,i,j=8*f-e-1,k=(1<>1,m=23===e?Math.pow(2,-24)-Math.pow(2,-77):0,n=d?f-1:0,o=d?-1:1,p=0>b||0===b&&0>1/b?1:0;for(b=Math.abs(b),isNaN(b)||1/0===b?(h=isNaN(b)?1:0,g=k):(g=Math.floor(Math.log(b)/Math.LN2),b*(i=Math.pow(2,-g))<1&&(g--,i*=2),b+=g+l>=1?m/i:m*Math.pow(2,1-l),b*i>=2&&(g++,i/=2),g+l>=k?(h=0,g=k):g+l>=1?(h=(b*i-1)*Math.pow(2,e),g+=l):(h=b*Math.pow(2,l-1)*Math.pow(2,e),g=0));e>=8;a[c+n]=255&h,n+=o,h/=256,e-=8);for(g=g<0;a[c+n]=255&g,n+=o,g/=256,j-=8);a[c+n-o]|=128*p}},{}],6:[function(a,b){var c=b.exports={};c.nextTick=function(){var a="undefined"!=typeof window&&window.setImmediate,b="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(a)return function(a){return window.setImmediate(a)};if(b){var c=[];return window.addEventListener("message",function(a){if(a.source===window&&"process-tick"===a.data&&(a.stopPropagation(),c.length>0)){var b=c.shift();b()}},!0),function(a){c.push(a),window.postMessage("process-tick","*")}}return function(a){setTimeout(a,0)}}(),c.title="browser",c.browser=!0,c.env={},c.argv=[],c.binding=function(){throw new Error("process.binding is not supported")},c.cwd=function(){return"/"},c.chdir=function(){throw new Error("process.chdir is not supported")}},{}],4:[function(a,b,c){!function(a){function b(a,b){if(a.indexOf)return a.indexOf(b);for(var c=0;cf;f++)d[f].apply(this,c);return!0}return!1},d.prototype.addListener=function(a,b){if("function"!=typeof b)throw new Error("addListener only takes instances of Function");if(this._events||(this._events={}),this.emit("newListener",a,b),this._events[a])if(e(this._events[a])){if(!this._events[a].warned){var c;c=void 0!==this._events.maxListeners?this._events.maxListeners:f,c&&c>0&&this._events[a].length>c&&(this._events[a].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[a].length),console.trace())}this._events[a].push(b)}else this._events[a]=[this._events[a],b];else this._events[a]=b;return this},d.prototype.on=d.prototype.addListener,d.prototype.once=function(a,b){var c=this;return c.on(a,function d(){c.removeListener(a,d),b.apply(this,arguments)}),this},d.prototype.removeListener=function(a,c){if("function"!=typeof c)throw new Error("removeListener only takes instances of Function");if(!this._events||!this._events[a])return this;var d=this._events[a];if(e(d)){var f=b(d,c);if(0>f)return this;d.splice(f,1),0==d.length&&delete this._events[a]}else this._events[a]===c&&delete this._events[a];return this},d.prototype.removeAllListeners=function(a){return 0===arguments.length?(this._events={},this):(a&&this._events&&this._events[a]&&(this._events[a]=null),this)},d.prototype.listeners=function(a){return this._events||(this._events={}),this._events[a]||(this._events[a]=[]),e(this._events[a])||(this._events[a]=[this._events[a]]),this._events[a]}}(a("__browserify_process"))},{__browserify_process:6}],"buffer-browserify":[function(a,b){b.exports=a("q9TxCC")},{}],q9TxCC:[function(a,b,c){function d(a){this.length=a}function e(a){return 16>a?"0"+a.toString(16):a.toString(16)}function f(a){for(var b=[],c=0;ce&&!(e+c>=b.length||e>=a.length);)b[e+c]=a[e],e++;return e}function j(a){try{return decodeURIComponent(a)}catch(b){return String.fromCharCode(65533)}}function k(a){return a=~~Math.ceil(+a),0>a?0:a}function l(a,b,c){if(!(this instanceof l))return new l(a,b,c);var e;if("number"==typeof c)this.length=k(b),this.parent=a,this.offset=c;else{switch(e=typeof a){case"number":this.length=k(a);break;case"string":this.length=l.byteLength(a,b);break;case"object":this.length=k(a.length);break;default:throw new Error("First argument needs to be a number, array or string.")}if(this.length>l.poolSize?(this.parent=new d(this.length),this.offset=0):((!E||E.length-E.used=a.length?0:(c?(e=a.parent[a.offset+b]<<8,b+1=a.length?0:(c?(b+1>>0):(b+2>>0)),e)}function q(a,b,c,d){var e,f;return d||(D.ok("boolean"==typeof c,"missing or invalid endian"),D.ok(void 0!==b&&null!==b,"missing offset"),D.ok(b+1=0,"specified a negative value for writing an unsigned value"),D.ok(b>=a,"value is larger than maximum value for type"),D.ok(Math.floor(a)===a,"value has a fractional component")}function v(a,b,c,d,e){e||(D.ok(void 0!==b&&null!==b,"missing value"),D.ok("boolean"==typeof d,"missing or invalid endian"),D.ok(void 0!==c&&null!==c,"missing offset"),D.ok(c+1>>8*(d?1-f:f)}function w(a,b,c,d,e){e||(D.ok(void 0!==b&&null!==b,"missing value"),D.ok("boolean"==typeof d,"missing or invalid endian"),D.ok(void 0!==c&&null!==c,"missing offset"),D.ok(c+3>>8*(d?3-f:f)}function x(a,b,c){D.ok("number"==typeof a,"cannot write a non-number as a number"),D.ok(b>=a,"value larger than maximum allowed value"),D.ok(a>=c,"value smaller than minimum allowed value"),D.ok(Math.floor(a)===a,"value has a fractional component")}function y(a,b,c){D.ok("number"==typeof a,"cannot write a non-number as a number"),D.ok(b>=a,"value larger than maximum allowed value"),D.ok(a>=c,"value smaller than minimum allowed value")}function z(a,b,c,d,e){e||(D.ok(void 0!==b&&null!==b,"missing value"),D.ok("boolean"==typeof d,"missing or invalid endian"),D.ok(void 0!==c&&null!==c,"missing offset"),D.ok(c+1=0?v(a,b,c,d,e):v(a,65535+b+1,c,d,e)}function A(a,b,c,d,e){e||(D.ok(void 0!==b&&null!==b,"missing value"),D.ok("boolean"==typeof d,"missing or invalid endian"),D.ok(void 0!==c&&null!==c,"missing offset"),D.ok(c+3=0?w(a,b,c,d,e):w(a,4294967295+b+1,c,d,e)}function B(b,c,d,e,f){f||(D.ok(void 0!==c&&null!==c,"missing value"),D.ok("boolean"==typeof e,"missing or invalid endian"),D.ok(void 0!==d&&null!==d,"missing offset"),D.ok(d+3d;d++)if(a[d]=e(this[d]),d==c.INSPECT_MAX_BYTES){a[d+1]="...";break}return""},d.prototype.hexSlice=function(a,b){var c=this.length;(!a||0>a)&&(a=0),(!b||0>b||b>c)&&(b=c);for(var d="",f=a;b>f;f++)d+=e(this[f]);return d},d.prototype.toString=function(a,b,c){if(a=String(a||"utf8").toLowerCase(),b=+b||0,"undefined"==typeof c&&(c=this.length),+c==b)return"";switch(a){case"hex":return this.hexSlice(b,c);case"utf8":case"utf-8":return this.utf8Slice(b,c);case"ascii":return this.asciiSlice(b,c);case"binary":return this.binarySlice(b,c);case"base64":return this.base64Slice(b,c);case"ucs2":case"ucs-2":return this.ucs2Slice(b,c);default:throw new Error("Unknown encoding")}},d.prototype.hexWrite=function(a,b,c){b=+b||0;var e=this.length-b;c?(c=+c,c>e&&(c=e)):c=e;var f=a.length;if(f%2)throw new Error("Invalid hex string");c>f/2&&(c=f/2);for(var g=0;c>g;g++){var h=parseInt(a.substr(2*g,2),16);if(isNaN(h))throw new Error("Invalid hex string");this[b+g]=h}return d._charsWritten=2*g,g},d.prototype.write=function(a,b,c,d){if(isFinite(b))isFinite(c)||(d=c,c=void 0);else{var e=d;d=b,b=c,c=e}b=+b||0;var f=this.length-b;switch(c?(c=+c,c>f&&(c=f)):c=f,d=String(d||"utf8").toLowerCase()){case"hex":return this.hexWrite(a,b,c);case"utf8":case"utf-8":return this.utf8Write(a,b,c);case"ascii":return this.asciiWrite(a,b,c);case"binary":return this.binaryWrite(a,b,c);case"base64":return this.base64Write(a,b,c);case"ucs2":case"ucs-2":return this.ucs2Write(a,b,c);default:throw new Error("Unknown encoding")}},d.prototype.slice=function(a,b){if(void 0===b&&(b=this.length),b>this.length)throw new Error("oob");if(a>b)throw new Error("oob");return new l(this,b-a,+a)},d.prototype.copy=function(a,b,c,d){for(var e=[],f=c;d>f;f++)D.ok("undefined"!=typeof this[f],"copying undefined buffer bytes!"),e.push(this[f]);for(var f=b;fthis.length)throw new Error("oob");if(b>c)throw new Error("oob");for(var d=b;c>d;d++)this[d]=a},c.SlowBuffer=d,c.Buffer=l,l.poolSize=8192;var E;l.isBuffer=function(a){return a instanceof l||a instanceof d},l.concat=function(a,b){if(!Array.isArray(a))throw new Error("Usage: Buffer.concat(list, [totalLength])\n list should be an Array.");if(0===a.length)return new l(0);if(1===a.length)return a[0];if("number"!=typeof b){b=0;for(var c=0;cd;d++)if(a[d]=e(this.parent[d+this.offset]),d==c.INSPECT_MAX_BYTES){a[d+1]="...";break}return""},l.prototype.get=function(a){if(0>a||a>=this.length)throw new Error("oob");return this.parent[this.offset+a]},l.prototype.set=function(a,b){if(0>a||a>=this.length)throw new Error("oob");return this.parent[this.offset+a]=b},l.prototype.write=function(a,b,c,e){if(isFinite(b))isFinite(c)||(e=c,c=void 0);else{var f=e;e=b,b=c,c=f}b=+b||0;var g=this.length-b;c?(c=+c,c>g&&(c=g)):c=g,e=String(e||"utf8").toLowerCase();var h;switch(e){case"hex":h=this.parent.hexWrite(a,this.offset+b,c);break;case"utf8":case"utf-8":h=this.parent.utf8Write(a,this.offset+b,c);break;case"ascii":h=this.parent.asciiWrite(a,this.offset+b,c);break;case"binary":h=this.parent.binaryWrite(a,this.offset+b,c);break;case"base64":h=this.parent.base64Write(a,this.offset+b,c);break;case"ucs2":case"ucs-2":h=this.parent.ucs2Write(a,this.offset+b,c);break;default:throw new Error("Unknown encoding")}return l._charsWritten=d._charsWritten,h},l.prototype.toString=function(a,b,c){switch(a=String(a||"utf8").toLowerCase(),"undefined"==typeof b||0>b?b=0:b>this.length&&(b=this.length),"undefined"==typeof c||c>this.length?c=this.length:0>c&&(c=0),b+=this.offset,c+=this.offset,a){case"hex":return this.parent.hexSlice(b,c);case"utf8":case"utf-8":return this.parent.utf8Slice(b,c);case"ascii":return this.parent.asciiSlice(b,c);case"binary":return this.parent.binarySlice(b,c);case"base64":return this.parent.base64Slice(b,c);case"ucs2":case"ucs-2":return this.parent.ucs2Slice(b,c);default:throw new Error("Unknown encoding")}},l.byteLength=d.byteLength,l.prototype.fill=function(a,b,c){if(a||(a=0),b||(b=0),c||(c=this.length),"string"==typeof a&&(a=a.charCodeAt(0)),"number"!=typeof a||isNaN(a))throw new Error("value is not a number");if(b>c)throw new Error("end < start");if(c===b)return 0;if(0==this.length)return 0;if(0>b||b>=this.length)throw new Error("start out of bounds");if(0>c||c>this.length)throw new Error("end out of bounds");return this.parent.fill(a,b+this.offset,c+this.offset)},l.prototype.copy=function(a,b,c,d){var e=this;if(c||(c=0),d||(d=this.length),b||(b=0),c>d)throw new Error("sourceEnd < sourceStart");if(d===c)return 0;if(0==a.length||0==e.length)return 0;if(0>b||b>=a.length)throw new Error("targetStart out of bounds");if(0>c||c>=e.length)throw new Error("sourceStart out of bounds");if(0>d||d>e.length)throw new Error("sourceEnd out of bounds");return d>this.length&&(d=this.length),a.length-bthis.length)throw new Error("oob");if(a>b)throw new Error("oob");return new l(this.parent,b-a,+a+this.offset)},l.prototype.utf8Slice=function(a,b){return this.toString("utf8",a,b)},l.prototype.binarySlice=function(a,b){return this.toString("binary",a,b)},l.prototype.asciiSlice=function(a,b){return this.toString("ascii",a,b)},l.prototype.utf8Write=function(a,b){return this.write(a,b,"utf8")},l.prototype.binaryWrite=function(a,b){return this.write(a,b,"binary")},l.prototype.asciiWrite=function(a,b){return this.write(a,b,"ascii")},l.prototype.readUInt8=function(a,b){var c=this;return b||(D.ok(void 0!==a&&null!==a,"missing offset"),D.ok(a=c.length?void 0:c.parent[c.offset+a]},l.prototype.readUInt16LE=function(a,b){return o(this,a,!1,b)},l.prototype.readUInt16BE=function(a,b){return o(this,a,!0,b)},l.prototype.readUInt32LE=function(a,b){return p(this,a,!1,b)},l.prototype.readUInt32BE=function(a,b){return p(this,a,!0,b)},l.prototype.readInt8=function(a,b){var c,d=this;return b||(D.ok(void 0!==a&&null!==a,"missing offset"),D.ok(a=d.length?void 0:(c=128&d.parent[d.offset+a],c?-1*(255-d.parent[d.offset+a]+1):d.parent[d.offset+a])},l.prototype.readInt16LE=function(a,b){return q(this,a,!1,b)},l.prototype.readInt16BE=function(a,b){return q(this,a,!0,b)},l.prototype.readInt32LE=function(a,b){return r(this,a,!1,b)},l.prototype.readInt32BE=function(a,b){return r(this,a,!0,b)},l.prototype.readFloatLE=function(a,b){return s(this,a,!1,b)},l.prototype.readFloatBE=function(a,b){return s(this,a,!0,b)},l.prototype.readDoubleLE=function(a,b){return t(this,a,!1,b)},l.prototype.readDoubleBE=function(a,b){return t(this,a,!0,b)},l.prototype.writeUInt8=function(a,b,c){var d=this;c||(D.ok(void 0!==a&&null!==a,"missing value"),D.ok(void 0!==b&&null!==b,"missing offset"),D.ok(b=0?d.writeUInt8(a,b,c):d.writeUInt8(255+a+1,b,c)},l.prototype.writeInt16LE=function(a,b,c){z(this,a,b,!1,c)},l.prototype.writeInt16BE=function(a,b,c){z(this,a,b,!0,c)},l.prototype.writeInt32LE=function(a,b,c){A(this,a,b,!1,c)},l.prototype.writeInt32BE=function(a,b,c){A(this,a,b,!0,c)},l.prototype.writeFloatLE=function(a,b,c){B(this,a,b,!1,c)},l.prototype.writeFloatBE=function(a,b,c){B(this,a,b,!0,c)},l.prototype.writeDoubleLE=function(a,b,c){C(this,a,b,!1,c)},l.prototype.writeDoubleBE=function(a,b,c){C(this,a,b,!0,c)},d.prototype.readUInt8=l.prototype.readUInt8,d.prototype.readUInt16LE=l.prototype.readUInt16LE,d.prototype.readUInt16BE=l.prototype.readUInt16BE,d.prototype.readUInt32LE=l.prototype.readUInt32LE,d.prototype.readUInt32BE=l.prototype.readUInt32BE,d.prototype.readInt8=l.prototype.readInt8,d.prototype.readInt16LE=l.prototype.readInt16LE,d.prototype.readInt16BE=l.prototype.readInt16BE,d.prototype.readInt32LE=l.prototype.readInt32LE,d.prototype.readInt32BE=l.prototype.readInt32BE,d.prototype.readFloatLE=l.prototype.readFloatLE,d.prototype.readFloatBE=l.prototype.readFloatBE,d.prototype.readDoubleLE=l.prototype.readDoubleLE,d.prototype.readDoubleBE=l.prototype.readDoubleBE,d.prototype.writeUInt8=l.prototype.writeUInt8,d.prototype.writeUInt16LE=l.prototype.writeUInt16LE,d.prototype.writeUInt16BE=l.prototype.writeUInt16BE,d.prototype.writeUInt32LE=l.prototype.writeUInt32LE,d.prototype.writeUInt32BE=l.prototype.writeUInt32BE,d.prototype.writeInt8=l.prototype.writeInt8,d.prototype.writeInt16LE=l.prototype.writeInt16LE,d.prototype.writeInt16BE=l.prototype.writeInt16BE,d.prototype.writeInt32LE=l.prototype.writeInt32LE,d.prototype.writeInt32BE=l.prototype.writeInt32BE,d.prototype.writeFloatLE=l.prototype.writeFloatLE,d.prototype.writeFloatBE=l.prototype.writeFloatBE,d.prototype.writeDoubleLE=l.prototype.writeDoubleLE,d.prototype.writeDoubleBE=l.prototype.writeDoubleBE},{assert:1,"./buffer_ieee754":5,"base64-js":7}],7:[function(a,b){!function(){"use strict";function a(a){var b,c,e,f,g,h;if(a.length%4>0)throw"Invalid string. Length must be a multiple of 4";for(g=a.indexOf("="),g=g>0?a.length-g:0,h=[],e=g>0?a.length-4:a.length,b=0,c=0;e>b;b+=4,c+=3)f=d.indexOf(a[b])<<18|d.indexOf(a[b+1])<<12|d.indexOf(a[b+2])<<6|d.indexOf(a[b+3]),h.push((16711680&f)>>16),h.push((65280&f)>>8),h.push(255&f);return 2===g?(f=d.indexOf(a[b])<<2|d.indexOf(a[b+1])>>4,h.push(255&f)):1===g&&(f=d.indexOf(a[b])<<10|d.indexOf(a[b+1])<<4|d.indexOf(a[b+2])>>2,h.push(255&f>>8),h.push(255&f)),h}function c(a){function b(a){return d[63&a>>18]+d[63&a>>12]+d[63&a>>6]+d[63&a]}var c,e,f,g=a.length%3,h="";for(c=0,f=a.length-g;f>c;c+=3)e=(a[c]<<16)+(a[c+1]<<8)+a[c+2],h+=b(e);switch(g){case 1:e=a[a.length-1],h+=d[e>>2],h+=d[63&e<<4],h+="==";break;case 2:e=(a[a.length-2]<<8)+a[a.length-1],h+=d[e>>10],h+=d[63&e>>4],h+=d[63&e<<2],h+="="}return h}var d="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";b.exports.toByteArray=a,b.exports.fromByteArray=c}()},{}],8:[function(a,b,c){c.readIEEE754=function(a,b,c,d,e){var f,g,h=8*e-d-1,i=(1<>1,k=-7,l=c?0:e-1,m=c?1:-1,n=a[b+l];for(l+=m,f=n&(1<<-k)-1,n>>=-k,k+=h;k>0;f=256*f+a[b+l],l+=m,k-=8);for(g=f&(1<<-k)-1,f>>=-k,k+=d;k>0;g=256*g+a[b+l],l+=m,k-=8);if(0===f)f=1-j;else{if(f===i)return g?0/0:1/0*(n?-1:1);g+=Math.pow(2,d),f-=j}return(n?-1:1)*g*Math.pow(2,f-d)},c.writeIEEE754=function(a,b,c,d,e,f){var g,h,i,j=8*f-e-1,k=(1<>1,m=23===e?Math.pow(2,-24)-Math.pow(2,-77):0,n=d?f-1:0,o=d?-1:1,p=0>b||0===b&&0>1/b?1:0;for(b=Math.abs(b),isNaN(b)||1/0===b?(h=isNaN(b)?1:0,g=k):(g=Math.floor(Math.log(b)/Math.LN2),b*(i=Math.pow(2,-g))<1&&(g--,i*=2),b+=g+l>=1?m/i:m*Math.pow(2,1-l),b*i>=2&&(g++,i/=2),g+l>=k?(h=0,g=k):g+l>=1?(h=(b*i-1)*Math.pow(2,e),g+=l):(h=b*Math.pow(2,l-1)*Math.pow(2,e),g=0));e>=8;a[c+n]=255&h,n+=o,h/=256,e-=8);for(g=g<0;a[c+n]=255&g,n+=o,g/=256,j-=8);a[c+n-o]|=128*p}},{}],3:[function(a,b,c){function d(a){this.length=a}function e(a){return 16>a?"0"+a.toString(16):a.toString(16)}function f(a){for(var b=[],c=0;ce&&!(e+c>=b.length||e>=a.length);)b[e+c]=a[e],e++;return e}function j(a){try{return decodeURIComponent(a)}catch(b){return String.fromCharCode(65533)}}function k(a){return a=~~Math.ceil(+a),0>a?0:a}function l(a,b,c){if(!(this instanceof l))return new l(a,b,c);var e;if("number"==typeof c)this.length=k(b),this.parent=a,this.offset=c;else{switch(e=typeof a){case"number":this.length=k(a);break;case"string":this.length=l.byteLength(a,b);break;case"object":this.length=k(a.length);break;default:throw new Error("First argument needs to be a number, array or string.")}if(this.length>l.poolSize?(this.parent=new d(this.length),this.offset=0):((!E||E.length-E.used>>0):(e=a.parent[a.offset+b+2]<<16,e|=a.parent[a.offset+b+1]<<8,e|=a.parent[a.offset+b],e+=a.parent[a.offset+b+3]<<24>>>0),e}function q(a,b,c,d){var e,f;return d||(D.ok("boolean"==typeof c,"missing or invalid endian"),D.ok(void 0!==b&&null!==b,"missing offset"),D.ok(b+1=0,"specified a negative value for writing an unsigned value"),D.ok(b>=a,"value is larger than maximum value for type"),D.ok(Math.floor(a)===a,"value has a fractional component")}function v(a,b,c,d,e){e||(D.ok(void 0!==b&&null!==b,"missing value"),D.ok("boolean"==typeof d,"missing or invalid endian"),D.ok(void 0!==c&&null!==c,"missing offset"),D.ok(c+1>>8,a.parent[a.offset+c+1]=255&b):(a.parent[a.offset+c+1]=(65280&b)>>>8,a.parent[a.offset+c]=255&b)}function w(a,b,c,d,e){e||(D.ok(void 0!==b&&null!==b,"missing value"),D.ok("boolean"==typeof d,"missing or invalid endian"),D.ok(void 0!==c&&null!==c,"missing offset"),D.ok(c+3>>24,a.parent[a.offset+c+1]=255&b>>>16,a.parent[a.offset+c+2]=255&b>>>8,a.parent[a.offset+c+3]=255&b):(a.parent[a.offset+c+3]=255&b>>>24,a.parent[a.offset+c+2]=255&b>>>16,a.parent[a.offset+c+1]=255&b>>>8,a.parent[a.offset+c]=255&b)}function x(a,b,c){D.ok("number"==typeof a,"cannot write a non-number as a number"),D.ok(b>=a,"value larger than maximum allowed value"),D.ok(a>=c,"value smaller than minimum allowed value"),D.ok(Math.floor(a)===a,"value has a fractional component")}function y(a,b,c){D.ok("number"==typeof a,"cannot write a non-number as a number"),D.ok(b>=a,"value larger than maximum allowed value"),D.ok(a>=c,"value smaller than minimum allowed value")}function z(a,b,c,d,e){e||(D.ok(void 0!==b&&null!==b,"missing value"),D.ok("boolean"==typeof d,"missing or invalid endian"),D.ok(void 0!==c&&null!==c,"missing offset"),D.ok(c+1=0?v(a,b,c,d,e):v(a,65535+b+1,c,d,e)}function A(a,b,c,d,e){e||(D.ok(void 0!==b&&null!==b,"missing value"),D.ok("boolean"==typeof d,"missing or invalid endian"),D.ok(void 0!==c&&null!==c,"missing offset"),D.ok(c+3=0?w(a,b,c,d,e):w(a,4294967295+b+1,c,d,e)}function B(b,c,d,e,f){f||(D.ok(void 0!==c&&null!==c,"missing value"),D.ok("boolean"==typeof e,"missing or invalid endian"),D.ok(void 0!==d&&null!==d,"missing offset"),D.ok(d+3d;d++)if(a[d]=e(this[d]),d==c.INSPECT_MAX_BYTES){a[d+1]="...";break}return""},d.prototype.hexSlice=function(a,b){var c=this.length;(!a||0>a)&&(a=0),(!b||0>b||b>c)&&(b=c);for(var d="",f=a;b>f;f++)d+=e(this[f]);return d},d.prototype.toString=function(a,b,c){if(a=String(a||"utf8").toLowerCase(),b=+b||0,"undefined"==typeof c&&(c=this.length),+c==b)return"";switch(a){case"hex":return this.hexSlice(b,c);case"utf8":case"utf-8":return this.utf8Slice(b,c);case"ascii":return this.asciiSlice(b,c);case"binary":return this.binarySlice(b,c);case"base64":return this.base64Slice(b,c);case"ucs2":case"ucs-2":return this.ucs2Slice(b,c);default:throw new Error("Unknown encoding")}},d.prototype.hexWrite=function(a,b,c){b=+b||0;var e=this.length-b;c?(c=+c,c>e&&(c=e)):c=e;var f=a.length;if(f%2)throw new Error("Invalid hex string");c>f/2&&(c=f/2);for(var g=0;c>g;g++){var h=parseInt(a.substr(2*g,2),16);if(isNaN(h))throw new Error("Invalid hex string");this[b+g]=h}return d._charsWritten=2*g,g},d.prototype.write=function(a,b,c,d){if(isFinite(b))isFinite(c)||(d=c,c=void 0);else{var e=d;d=b,b=c,c=e}b=+b||0;var f=this.length-b;switch(c?(c=+c,c>f&&(c=f)):c=f,d=String(d||"utf8").toLowerCase()){case"hex":return this.hexWrite(a,b,c);case"utf8":case"utf-8":return this.utf8Write(a,b,c);case"ascii":return this.asciiWrite(a,b,c);case"binary":return this.binaryWrite(a,b,c);case"base64":return this.base64Write(a,b,c);case"ucs2":case"ucs-2":return this.ucs2Write(a,b,c);default:throw new Error("Unknown encoding")}},d.prototype.slice=function(a,b){if(void 0===b&&(b=this.length),b>this.length)throw new Error("oob");if(a>b)throw new Error("oob");return new l(this,b-a,+a)},d.prototype.copy=function(a,b,c,d){for(var e=[],f=c;d>f;f++)D.ok("undefined"!=typeof this[f],"copying undefined buffer bytes!"),e.push(this[f]);for(var f=b;fd;d++)if(a[d]=e(this.parent[d+this.offset]),d==c.INSPECT_MAX_BYTES){a[d+1]="...";break}return""},l.prototype.get=function(a){if(0>a||a>=this.length)throw new Error("oob");return this.parent[this.offset+a]},l.prototype.set=function(a,b){if(0>a||a>=this.length)throw new Error("oob");return this.parent[this.offset+a]=b},l.prototype.write=function(a,b,c,e){if(isFinite(b))isFinite(c)||(e=c,c=void 0);else{var f=e;e=b,b=c,c=f}b=+b||0;var g=this.length-b;c?(c=+c,c>g&&(c=g)):c=g,e=String(e||"utf8").toLowerCase();var h;switch(e){case"hex":h=this.parent.hexWrite(a,this.offset+b,c);break;case"utf8":case"utf-8":h=this.parent.utf8Write(a,this.offset+b,c);break;case"ascii":h=this.parent.asciiWrite(a,this.offset+b,c);break;case"binary":h=this.parent.binaryWrite(a,this.offset+b,c);break;case"base64":h=this.parent.base64Write(a,this.offset+b,c);break;case"ucs2":case"ucs-2":h=this.parent.ucs2Write(a,this.offset+b,c);break;default:throw new Error("Unknown encoding")}return l._charsWritten=d._charsWritten,h},l.prototype.toString=function(a,b,c){switch(a=String(a||"utf8").toLowerCase(),"undefined"==typeof b||0>b?b=0:b>this.length&&(b=this.length),"undefined"==typeof c||c>this.length?c=this.length:0>c&&(c=0),b+=this.offset,c+=this.offset,a){case"hex":return this.parent.hexSlice(b,c);case"utf8":case"utf-8":return this.parent.utf8Slice(b,c);case"ascii":return this.parent.asciiSlice(b,c);case"binary":return this.parent.binarySlice(b,c);case"base64":return this.parent.base64Slice(b,c);case"ucs2":case"ucs-2":return this.parent.ucs2Slice(b,c);default:throw new Error("Unknown encoding")}},l.byteLength=d.byteLength,l.prototype.fill=function(a,b,c){if(a||(a=0),b||(b=0),c||(c=this.length),"string"==typeof a&&(a=a.charCodeAt(0)),"number"!=typeof a||isNaN(a))throw new Error("value is not a number");if(b>c)throw new Error("end < start");if(c===b)return 0;if(0==this.length)return 0;if(0>b||b>=this.length)throw new Error("start out of bounds");if(0>c||c>this.length)throw new Error("end out of bounds");return this.parent.fill(a,b+this.offset,c+this.offset)},l.prototype.copy=function(a,b,c,d){var e=this;if(c||(c=0),d||(d=this.length),b||(b=0),c>d)throw new Error("sourceEnd < sourceStart");if(d===c)return 0;if(0==a.length||0==e.length)return 0;if(0>b||b>=a.length)throw new Error("targetStart out of bounds");if(0>c||c>=e.length)throw new Error("sourceStart out of bounds");if(0>d||d>e.length)throw new Error("sourceEnd out of bounds");return d>this.length&&(d=this.length),a.length-bthis.length)throw new Error("oob");if(a>b)throw new Error("oob");return new l(this.parent,b-a,+a+this.offset)},l.prototype.utf8Slice=function(a,b){return this.toString("utf8",a,b)},l.prototype.binarySlice=function(a,b){return this.toString("binary",a,b)},l.prototype.asciiSlice=function(a,b){return this.toString("ascii",a,b)},l.prototype.utf8Write=function(a,b){return this.write(a,b,"utf8")},l.prototype.binaryWrite=function(a,b){return this.write(a,b,"binary")},l.prototype.asciiWrite=function(a,b){return this.write(a,b,"ascii")},l.prototype.readUInt8=function(a,b){var c=this;return b||(D.ok(void 0!==a&&null!==a,"missing offset"),D.ok(a=0?d.writeUInt8(a,b,c):d.writeUInt8(255+a+1,b,c)},l.prototype.writeInt16LE=function(a,b,c){z(this,a,b,!1,c)},l.prototype.writeInt16BE=function(a,b,c){z(this,a,b,!0,c)},l.prototype.writeInt32LE=function(a,b,c){A(this,a,b,!1,c)},l.prototype.writeInt32BE=function(a,b,c){A(this,a,b,!0,c)},l.prototype.writeFloatLE=function(a,b,c){B(this,a,b,!1,c)},l.prototype.writeFloatBE=function(a,b,c){B(this,a,b,!0,c)},l.prototype.writeDoubleLE=function(a,b,c){C(this,a,b,!1,c)},l.prototype.writeDoubleBE=function(a,b,c){C(this,a,b,!0,c)},d.prototype.readUInt8=l.prototype.readUInt8,d.prototype.readUInt16LE=l.prototype.readUInt16LE,d.prototype.readUInt16BE=l.prototype.readUInt16BE,d.prototype.readUInt32LE=l.prototype.readUInt32LE,d.prototype.readUInt32BE=l.prototype.readUInt32BE,d.prototype.readInt8=l.prototype.readInt8,d.prototype.readInt16LE=l.prototype.readInt16LE,d.prototype.readInt16BE=l.prototype.readInt16BE,d.prototype.readInt32LE=l.prototype.readInt32LE,d.prototype.readInt32BE=l.prototype.readInt32BE,d.prototype.readFloatLE=l.prototype.readFloatLE,d.prototype.readFloatBE=l.prototype.readFloatBE,d.prototype.readDoubleLE=l.prototype.readDoubleLE,d.prototype.readDoubleBE=l.prototype.readDoubleBE,d.prototype.writeUInt8=l.prototype.writeUInt8,d.prototype.writeUInt16LE=l.prototype.writeUInt16LE,d.prototype.writeUInt16BE=l.prototype.writeUInt16BE,d.prototype.writeUInt32LE=l.prototype.writeUInt32LE,d.prototype.writeUInt32BE=l.prototype.writeUInt32BE,d.prototype.writeInt8=l.prototype.writeInt8,d.prototype.writeInt16LE=l.prototype.writeInt16LE,d.prototype.writeInt16BE=l.prototype.writeInt16BE,d.prototype.writeInt32LE=l.prototype.writeInt32LE,d.prototype.writeInt32BE=l.prototype.writeInt32BE,d.prototype.writeFloatLE=l.prototype.writeFloatLE,d.prototype.writeFloatBE=l.prototype.writeFloatBE,d.prototype.writeDoubleLE=l.prototype.writeDoubleLE,d.prototype.writeDoubleBE=l.prototype.writeDoubleBE},{assert:1,"./buffer_ieee754":8,"base64-js":9}],9:[function(a,b){!function(){"use strict";function a(a){var b,c,e,f,g,h;if(a.length%4>0)throw"Invalid string. Length must be a multiple of 4";for(g=a.indexOf("="),g=g>0?a.length-g:0,h=[],e=g>0?a.length-4:a.length,b=0,c=0;e>b;b+=4,c+=3)f=d.indexOf(a[b])<<18|d.indexOf(a[b+1])<<12|d.indexOf(a[b+2])<<6|d.indexOf(a[b+3]),h.push((16711680&f)>>16),h.push((65280&f)>>8),h.push(255&f);return 2===g?(f=d.indexOf(a[b])<<2|d.indexOf(a[b+1])>>4,h.push(255&f)):1===g&&(f=d.indexOf(a[b])<<10|d.indexOf(a[b+1])<<4|d.indexOf(a[b+2])>>2,h.push(255&f>>8),h.push(255&f)),h}function c(a){function b(a){return d[63&a>>18]+d[63&a>>12]+d[63&a>>6]+d[63&a]}var c,e,f,g=a.length%3,h="";for(c=0,f=a.length-g;f>c;c+=3)e=(a[c]<<16)+(a[c+1]<<8)+a[c+2],h+=b(e);switch(g){case 1:e=a[a.length-1],h+=d[e>>2],h+=d[63&e<<4],h+="==";break;case 2:e=(a[a.length-2]<<8)+a[a.length-1],h+=d[e>>10],h+=d[63&e>>4],h+=d[63&e<<2],h+="="}return h}var d="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";b.exports.toByteArray=a,b.exports.fromByteArray=c}()},{}]},{},[]),b.exports=a("buffer-browserify")},{}],54:[function(a,b){var c=b.exports={};c.nextTick=function(){var a="undefined"!=typeof window&&window.setImmediate,b="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(a)return function(a){return window.setImmediate(a)};if(b){var c=[];return window.addEventListener("message",function(a){if(a.source===window&&"process-tick"===a.data&&(a.stopPropagation(),c.length>0)){var b=c.shift();b()}},!0),function(a){c.push(a),window.postMessage("process-tick","*")}}return function(a){setTimeout(a,0)}}(),c.title="browser",c.browser=!0,c.env={},c.argv=[],c.binding=function(){throw new Error("process.binding is not supported")},c.cwd=function(){return"/"},c.chdir=function(){throw new Error("process.chdir is not supported")}},{}],55:[function(a,b,c){!function(){"use strict";function d(a){var b=function(a){return"string"==typeof a?a:"object"==typeof a?a.hashCode?a.hashCode():""+a:""+a},c=a.declare({instance:{constructor:function(){this.__entries=[],this.__keys=[],this.__values=[]},pushValue:function(a,b){return this.__keys.push(a),this.__values.push(b),this.__entries.push({key:a,value:b}),b},remove:function(a){for(var b,c=null,d=this.__entries,e=this.__keys,f=this.__values,g=d.length-1;g>=0;g--)if((b=d[g])&&b.key===a)return d.splice(g,1),e.splice(g,1),f.splice(g,1),b.value;return c},set:function(a,b){for(var c=null,d=this.__entries,e=this.__values,f=d.length-1;f>=0;f--){var g=d[f];if(g&&a===g.key){e[f]=b,g.value=b,c=b;break}}return c||d.push({key:a,value:b}),c},find:function(a){for(var b,c=null,d=this.__entries,e=d.length-1;e>=0;e--)if(b=d[e],b&&a===b.key){c=b.value;break}return c},getEntrySet:function(){return this.__entries},getKeys:function(){return this.__keys},getValues:function(){return this.__values}}});return a.declare({instance:{constructor:function(){this.__map={}},entrySet:function(){var a=[],b=this.__map;for(var c in b)b.hasOwnProperty(c)&&(a=a.concat(b[c].getEntrySet()));return a},put:function(a,d){var e=b(a),f=null;return(f=this.__map[e])||(f=this.__map[e]=new c),f.pushValue(a,d),d},remove:function(a){var c=b(a),d=null,e=this.__map[c];return e&&(d=e.remove(a)),d},get:function(a){var c,d=b(a),e=null;return(c=this.__map[d])&&(e=c.find(a)),e},set:function(a,d){var e=b(a),f=null,g=null,h=this.__map;return f=(g=h[e])?g.set(a,d):(h[e]=new c).pushValue(a,d)},contains:function(a){var c=b(a),d=!1,e=null;return(e=this.__map[c])&&(d=!!e.find(a)),d},concat:function(a){if(a instanceof this._static){for(var b=new this._static,c=a.entrySet().concat(this.entrySet()),d=c.length-1;d>=0;d--){var e=c[d];b.put(e.key,e.value)}return b}throw new TypeError("When joining hashtables the joining arg must be a HashTable")},filter:function(b,c){var d=this.entrySet(),e=new this._static;d=a.filter(d,b,c);for(var f=d.length-1;f>=0;f--){var g=d[f];e.put(g.key,g.value)}return e},forEach:function(b,c){var d=this.entrySet();a.forEach(d,b,c)},every:function(b,c){var d=this.entrySet();return a.every(d,b,c)},map:function(b,c){var d=this.entrySet();return a.map(d,b,c)},some:function(b,c){var d=this.entrySet();return a.some(d,b,c)},reduce:function(b,c){var d=this.entrySet();return a.reduce(d,b,c)},reduceRight:function(b,c){var d=this.entrySet();return a.reduceRight(d,b,c)},clear:function(){this.__map={}},keys:function(){var a=[],b=this.__map;for(var c in b)a=a.concat(b[c].getKeys());return a},values:function(){var a=[],b=this.__map;for(var c in b)a=a.concat(b[c].getValues());return a},isEmpty:function(){return 0===this.keys().length}}})}"undefined"!=typeof c?"undefined"!=typeof b&&b.exports&&(b.exports=d(a("extended")().register("declare",a("declare.js")).register(a("is-extended")).register(a("array-extended")))):"function"==typeof define?define(["extended","declare","is-extended","array-extended"],function(a,b,c,e){return d(a().register("declare",b).register(c).register(e))}):this.Ht=d(this.extended().register("declare",this.declare).register(this.isExtended).register(this.arrayExtended))}.call(this)},{"array-extended":42,"declare.js":45,extended:46,"is-extended":56}],56:[function(a,b,c){var d=a("__browserify_Buffer").Buffer;!function(){"use strict";function e(a){function b(a,b){var c=-1,d=0,e=a.length,f=[];for(b=b||0,c+=b;++c=0;f--)if(g[f]!==h[f])return!1;for(f=g.length-1;f>=0;f--)if(d=g[f],!e(a[d],b[d]))return!1}catch(i){return!1}return!0}function g(a){return null!==a&&"object"==typeof a}function h(a){var b=g(a);return b&&a.constructor===Object&&!a.nodeType&&!a.setInterval}function i(a){return W(a)?0===a.length:g(a)?0===c(a).length:r(a)||X(a)?0===a.length:!0}function j(a){return a===!0||a===!1||"[object Boolean]"===U.call(a)}function k(a){return"undefined"==typeof a}function l(a){return!k(a)}function m(a){return k(a)||n(a)}function n(a){return null===a}function o(a,b){return V(b)?a instanceof b:!1}function p(a){return"[object RegExp]"===U.call(a)}function q(a){return"[object Date]"===U.call(a)}function r(a){return"[object String]"===U.call(a)}function s(a){return"[object Number]"===U.call(a)}function t(a){return a===!0}function u(a){return a===!1}function v(a){return!n(a)}function w(a,b){return a==b}function x(a,b){return a!=b}function y(a,b){return a===b}function z(a,b){return a!==b}function A(a,b){if(X(b)&&Array.prototype.indexOf||r(b))return b.indexOf(a)>-1;if(X(b))for(var c=0,d=b.length;d>c;c++)if(w(a,b[c]))return!0;return!1}function B(a,b){return!A(a,b)}function C(a,b){return b>a}function D(a,b){return b>=a}function E(a,b){return a>b}function F(a,b){return a>=b}function G(a,b){return r(b)?null!==(""+a).match(b):p(b)?b.test(a):!1}function H(a,b){return!G(a,b)}function I(a,b){return A(b,a)}function J(a,b){return!A(b,a)}function K(a,b,c){return X(a)&&a.length>c?w(a[c],b):!1}function L(a,b,c){return X(a)?!w(a[c],b):!1}function M(a,b){return T.call(a,b)}function N(a,b){return!M(a,b)}function O(a,b){return M(a,"length")?a.length===b:!1}function P(a,b){return M(a,"length")?a.length!==b:!1}function Q(a){Z[a]=function(){this._testers.push(Y[a])}}function R(a){$[a]=function(){var c,d=b(arguments,1),e=Y[a],f=!0;if(d.length<=e.length-1)throw new TypeError("A handler must be defined when calling using switch");if(c=d.pop(),j(c)&&(f=c,c=d.pop()),!V(c))throw new TypeError("handler must be defined");this._cases.push(function(a){return e.apply(Y,a.concat(d))?[f,c.apply(this,a)]:[!1]})}}var S=Array.prototype.slice,T=Object.prototype.hasOwnProperty,U=Object.prototype.toString,V=function(a){return"[object Function]"===U.call(a)};"undefined"==typeof window||V(window.alert)||function(a){V=function(b){return"[object Function]"===U.call(b)||b===a}}(window.alert);var W=function(a){return"[object Arguments]"===U.call(a)};W(arguments)||(W=function(a){return!(!a||!T.call(a,"callee"))});var X=Array.isArray||function(a){return"[object Array]"===U.call(a)},Y={isFunction:V,isObject:g,isEmpty:i,isHash:h,isNumber:s,isString:r,isDate:q,isArray:X,isBoolean:j,isUndefined:k,isDefined:l,isUndefinedOrNull:m,isNull:n,isArguments:W,instanceOf:o,isRegExp:p,deepEqual:e,isTrue:t,isFalse:u,isNotNull:v,isEq:w,isNeq:x,isSeq:y,isSneq:z,isIn:A,isNotIn:B,isLt:C,isLte:D,isGt:E,isGte:F,isLike:G,isNotLike:H,contains:I,notContains:J,has:M,notHas:N,isLength:O,isNotLength:P,containsAt:K,notContainsAt:L},Z={constructor:function(){this._testers=[]},noWrap:{tester:function(){var a=this._testers;return function(b){for(var c=!1,d=0,e=a.length;e>d&&!c;d++)c=a[d](b);return c}}}},$={constructor:function(){this._cases=[],this.__default=null},def:function(a,b){this.__default=b},noWrap:{switcher:function(){var a=this._cases,c=this.__default;return function(){for(var d,e=!1,f=b(arguments),g=0,h=a.length;h>g&&!e;g++)if(d=a[g](f),d.length>1&&(d[1]||d[0]))return d[1];return!e&&c?c.apply(this,f):void 0}}}};for(var _ in Y)T.call(Y,_)&&(R(_),Q(_));var ab=a.define(Y).expose(Y);return ab.tester=a.define(Z),ab.switcher=a.define($),ab}"undefined"!=typeof c?"undefined"!=typeof b&&b.exports&&(b.exports=e(a("extended"))):"function"==typeof define&&define.amd?define(["extended"],function(a){return e(a)}):this.isExtended=e(this.extended)}.call(this)},{__browserify_Buffer:53,extended:46}],57:[function(a,b,c){!function(){"use strict";function d(a){function b(a,b){var c=0;return a>b?1:b>a?-1:b?c:1}var c=a.multiply,d=a.declare({instance:{__printNode:function(b,d){var e=[];a.isUndefinedOrNull(b)?(e.push(c(" ",d)),e.push("~"),console.log(e.join(""))):(this.__printNode(b.right,d+1),e.push(c(" ",d)),e.push(b.data+"\n"),console.log(e.join("")),this.__printNode(b.left,d+1))},constructor:function(a){a=a||{},this.compare=a.compare||b,this.__root=null},insert:function(){throw new Error("Not Implemented")},remove:function(){throw new Error("Not Implemented")},clear:function(){this.__root=null},isEmpty:function(){return!this.__root},traverseWithCondition:function(a,b,c){var e=!0;return a&&(b=b||d.PRE_ORDER,b===d.PRE_ORDER?(e=c(a.data),e&&(e=this.traverseWithCondition(a.left,b,c),e&&(e=this.traverseWithCondition(a.right,b,c)))):b===d.IN_ORDER?(e=this.traverseWithCondition(a.left,b,c),e&&(e=c(a.data),e&&(e=this.traverseWithCondition(a.right,b,c)))):b===d.POST_ORDER?(e=this.traverseWithCondition(a.left,b,c),e&&(e&&(e=this.traverseWithCondition(a.right,b,c)),e&&(e=c(a.data)))):b===d.REVERSE_ORDER&&(e=this.traverseWithCondition(a.right,b,c),e&&(e=c(a.data),e&&(e=this.traverseWithCondition(a.left,b,c))))),e},traverse:function(a,b,c){a&&(b=b||d.PRE_ORDER,b===d.PRE_ORDER?(c(a.data),this.traverse(a.left,b,c),this.traverse(a.right,b,c)):b===d.IN_ORDER?(this.traverse(a.left,b,c),c(a.data),this.traverse(a.right,b,c)):b===d.POST_ORDER?(this.traverse(a.left,b,c),this.traverse(a.right,b,c),c(a.data)):b===d.REVERSE_ORDER&&(this.traverse(a.right,b,c),c(a.data),this.traverse(a.left,b,c)))},forEach:function(a,b,c){if("function"!=typeof a)throw new TypeError;c=c||d.IN_ORDER,b=b||this,this.traverse(this.__root,c,function(c){a.call(b,c,this)})},map:function(a,b,c){if("function"!=typeof a)throw new TypeError;c=c||d.IN_ORDER,b=b||this;var e=new this._static;return this.traverse(this.__root,c,function(c){e.insert(a.call(b,c,this))}),e},filter:function(a,b,c){if("function"!=typeof a)throw new TypeError;c=c||d.IN_ORDER,b=b||this;var e=new this._static;return this.traverse(this.__root,c,function(c){a.call(b,c,this)&&e.insert(c)}),e},reduce:function(b,c,d){var e=this.toArray(d),f=[e,b];return a.isUndefinedOrNull(c)||f.push(c),a.reduce.apply(a,f)},reduceRight:function(b,c,d){var e=this.toArray(d),f=[e,b];return a.isUndefinedOrNull(c)||f.push(c),a.reduceRight.apply(a,f)},every:function(a,b,c){if("function"!=typeof a)throw new TypeError;c=c||d.IN_ORDER,b=b||this;var e=!1;return this.traverseWithCondition(this.__root,c,function(c){return e=a.call(b,c,this)}),e},some:function(a,b,c){if("function"!=typeof a)throw new TypeError;c=c||d.IN_ORDER,b=b||this;var e;return this.traverseWithCondition(this.__root,c,function(c){return e=a.call(b,c,this),!e}),e},toArray:function(a){a=a||d.IN_ORDER;var b=[];return this.traverse(this.__root,a,function(a){b.push(a)}),b},contains:function(a){for(var b=!1,c=this.__root;null!==c;){var d=this.compare(a,c.data);d?c=c[-1===d?"left":"right"]:(b=!0,c=null)}return b},find:function(a){for(var b,c=this.__root;c;){var d=this.compare(a,c.data);if(!d){b=c.data;break}c=c[-1===d?"left":"right"]}return b},findLessThan:function(a,b){var c=[],e=this.compare;return this.traverseWithCondition(this.__root,d.IN_ORDER,function(d){var f=e(a,d);return!b&&0===f||1===f?(c.push(d),!0):!1}),c},findGreaterThan:function(a,b){var c=[],e=this.compare;return this.traverse(this.__root,d.REVERSE_ORDER,function(d){var f=e(a,d);return!b&&0===f||-1===f?(c.push(d),!0):!1}),c},print:function(){this.__printNode(this.__root,0)}},"static":{PRE_ORDER:"pre_order",IN_ORDER:"in_order",POST_ORDER:"post_order",REVERSE_ORDER:"reverse_order"}}),e=function(){var a=Math.abs,b=function(a){return{data:a,balance:0,left:null,right:null}},e=function(a,b,c){var d=a[c];return a[c]=d[b],d[b]=a,d},f=function(a,b,c){return a[c]=e(a[c],c,b),e(a,b,c)},g=function(a,b,c){var d="left"===b?"right":"left",e=a[b],f=e[d];0===f.balance?a.balance=e.balance=0:f.balance===c?(a.balance=-c,e.balance=0):(a.balance=0,e.balance=c),f.balance=0},h=function(a,b){var c="left"===b?"right":"left",d=a[b],h="left"===b?-1:1;return d.balance===h?(a.balance=d.balance=0,a=e(a,c,b)):(g(a,b,h),a=f(a,c,b)),a},i=function(a,b,c){var d="left"===b?"right":"left",h=a[d],i="left"===b?-1:1;return h.balance===-i?(a.balance=h.balance=0,a=e(a,b,d)):h.balance===i?(g(a,d,-i),a=f(a,b,d)):(a.balance=-i,h.balance=i,a=e(a,b,d),c.done=!0),a},j=function(c,d,e,f){if(null===c||void 0===c)c=b(d);else{var g=-1===f(d,c.data)?"left":"right";c[g]=j(c[g],d,e,f),e.done||(c.balance+="left"===g?-1:1,0===c.balance?e.done=!0:a(c.balance)>1&&(c=h(c,g),e.done=!0))}return c},k=function(b,c,d,e){var f,g,h,j;if(b){if(g=e(c,b.data),0===g){var l=b.left,m=b.right;if(!l||!m)return f=l?"left":"right",h=b[f];for(var n=l;null!==(m=n.right);)n=m;b.data=n.data,c=n.data}if(f=-1===e(b.data,c)?"right":"left",b[f]=k(b[f],c,d,e),!d.done){j=b.balance+="left"===f?1:-1;var o=a(j);1===o?d.done=!0:o>1&&(b=i(b,f,d))}}return b};return d.extend({instance:{insert:function(a){var b={done:!1};this.__root=j(this.__root,a,b,this.compare)},remove:function(a){this.__root=k(this.__root,a,{done:!1},this.compare)},__printNode:function(a,b){var d=[];a?(this.__printNode(a.right,b+1),d.push(c(" ",b)),d.push(a.data+":"+a.balance+"\n"),console.log(d.join("")),this.__printNode(a.left,b+1)):(d.push(c(" ",b)),d.push("~"),console.log(d.join("")))}}})}(),f=function(){function a(a,b){return{data:a,level:b,left:g,right:g}}function b(a){if(0!==a.level&&a.left.level===a.level){var b=a.left;a.left=b.right,b.right=a,a=b}return a}function e(a){if(0!==a.level&&a.right.right.level===a.level){var b=a.right;a.right=b.left,b.left=a,a=b,a.level++}return a}function f(c,d,h){if(c===g)c=a(d,1);else{var i=-1===h(d,c.data)?"left":"right";c[i]=f(c[i],d,h),c=b(c),c=e(c)}return c}var g={level:0,data:null},h=function(a,c,d){var f,i;if(a!==g){var j=d(c,a.data);if(0===j)if(f=a.left,i=a.right,f!==g&&i!==g){for(var k=f;k.right!==g;)k=k.right;a.data=k.data,a.left=h(f,k.data,d)}else a=a[f===g?"right":"left"];else{var l=-1===j?"left":"right";a[l]=h(a[l],c,d)}}if(a!==g){var m=a.level,n=a.left.level,o=a.right.level;(m-1>n||m-1>o)&&(o>--a.level&&(a.right.level=a.level),a=b(a),a=e(a))}return a};return d.extend({instance:{isEmpty:function(){return this.__root===g||this._super(arguments)},insert:function(a){this.__root||(this.__root=g),this.__root=f(this.__root,a,this.compare)},remove:function(a){this.__root=h(this.__root,a,this.compare)},traverseWithCondition:function(a){var b=!0;return a!==g?this._super(arguments):b},traverse:function(a){a!==g&&this._super(arguments)},contains:function(){return this.__root!==g?this._super(arguments):!1},__printNode:function(a,b){var d=[];a&&a.data?(this.__printNode(a.right,b+1),d.push(c(" ",b)),d.push(a.data+":"+a.level+"\n"),console.log(d.join("")),this.__printNode(a.left,b+1)):(d.push(c(" ",b)),d.push("~"),console.log(d.join("")))}}})}(),g=d.extend({instance:{insert:function(a){if(!this.__root)return this.__root={data:a,parent:null,left:null,right:null};for(var b=this.compare,c=this.__root;null!==c;){var d=b(a,c.data);if(!d)return;var e=-1===d?"left":"right",f=c[e];if(!f)return c[e]={data:a,parent:c,left:null,right:null};c=f}},remove:function(a){if(null!==this.__root){for(var b,c={right:this.__root},d=c,e=null,f="right";null!==d[f];){b=d,d=d[f];var g=this.compare(a,d.data);g||(e=d),f=-1===g?"left":"right"}null!==e&&(e.data=d.data,b[b.right===d?"right":"left"]=d[null===d.left?"right":"left"]),this.__root=c.right}}}}),h=function(){var a="RED",b="BLACK",e=function(a){return null!==a&&a.red},f=function(a){return{data:a,red:!0,left:null,right:null}},g=function(a,b,c){if(!a)return f(b);var d=c(b,a.data);if(d){var j=-1===d?"left":"right",k="left"===j?"right":"left";a[j]=g(a[j],b,c);var l=a[j];if(e(l)){var m=a[k];e(m)?(a.red=!0,l.red=!1,m.red=!1):e(l[j])?a=h(a,k):e(l[k])&&(a=i(a,k))}}return a},h=function(a,b){var c="left"===b?"right":"left",d=a[c];return a[c]=d[b],d[b]=a,a.red=!0,d.red=!1,d},i=function(a,b){var c="left"===b?"right":"left";return a[c]=h(a[c],c),h(a,b)},j=function(a,b,c,d){if(a){var f;if(0===d(b,a.data)){if(!a.left||!a.right){var g=a[a.left?"left":"right"];return e(a)?c.done=!0:e(g)&&(g.red=!1,c.done=!0),g}for(var h,i=a.right;null!==i.left;)h=i,i=i.left;h&&(h.left=null),a.data=i.data,b=i.data}f=-1===d(b,a.data)?"left":"right",a[f]=j(a[f],b,c,d),c.done||(a=k(a,f,c))}else c.done=!0;return a},k=function(a,b,c){var d="left"===b?"right":"left",f=a,g=f[d];if(e(g)&&(a=h(a,b),g=f[d]),null!==g)if(e(g.left)||e(g.right)){var j=f.red,k=a===f;f=(e(g[d])?h:i)(f,b),f.red=j,f.left.red=f.right.red=0,k?a=f:a[b]=f,c.done=!0}else e(f)&&(c.done=!0),f.red=0,g.red=1;return a};return d.extend({instance:{insert:function(a){this.__root=g(this.__root,a,this.compare),this.__root.red=!1},remove:function(a){var b={done:!1},c=j(this.__root,a,b,this.compare);return null!==c&&(c.red=0),this.__root=c,a},__printNode:function(d,e){var f=[];d?(this.__printNode(d.right,e+1),f.push(c(" ",e)),f.push((d.red?a:b)+":"+d.data+"\n"),console.log(f.join("")),this.__printNode(d.left,e+1)):(f.push(c(" ",e)),f.push("~"),console.log(f.join("")))}}})}();return{Tree:d,AVLTree:e,AnderssonTree:f,BinaryTree:g,RedBlackTree:h,IN_ORDER:d.IN_ORDER,PRE_ORDER:d.PRE_ORDER,POST_ORDER:d.POST_ORDER,REVERSE_ORDER:d.REVERSE_ORDER}}"undefined"!=typeof c?"undefined"!=typeof b&&b.exports&&(b.exports=d(a("extended")().register("declare",a("declare.js")).register(a("is-extended")).register(a("array-extended")).register(a("string-extended")))):"function"==typeof define?define(["extended","declare.js","is-extended","array-extended","string-extended"],function(a,b,c,e,f){return d(a().register("declare",b).register(c).register(e).register(f))}):this.leafy=d(this.extended().register("declare",this.declare).register(this.isExtended).register(this.arrayExtended).register(this.stringExtended))}.call(this)},{"array-extended":42,"declare.js":45,extended:46,"is-extended":56,"string-extended":60}],58:[function(a,b,c){!function(){"use strict";function d(a,b,c){function d(a,b){var c,d;for(c in b)t.call(b,c)&&(d=b[c],c in a&&a[c]===d||(a[c]=d));return a}function e(a,b){var c,d,f;for(c in b)t.call(b,c)&&(d=b[c],f=a[c],p(f,d)||(a[c]=r(f)&&r(d)?e(f,d):r(d)?e({},d):d));return a}function f(a){a||(a={});for(var b=1,c=arguments.length;c>b;b++)d(a,arguments[b]);return a}function g(a){a||(a={});for(var b=1,c=arguments.length;c>b;b++)e(a,arguments[b]);return a}function h(a,b){var c=a.prototype||a;return f(c,b),a}function i(a,b,c){if(!r(a)||!u(b))throw new TypeError;for(var d,e=l(a),f=0,g=e.length;g>f;++f)d=e[f],b.call(c||a,a[d],d,a);return a}function j(a,b,c){if(!r(a)||!u(b))throw new TypeError;for(var d,e,f=l(a),g={},h=0,i=f.length;i>h;++h)d=f[h],e=a[d],b.call(c||a,e,d,a)&&(g[d]=e);return g}function k(a){if(!r(a))throw new TypeError;for(var b=l(a),c=[],d=0,e=b.length;e>d;++d)c.push(a[b[d]]);return c}function l(a){if(!r(a))throw new TypeError;var b=[];for(var c in a)t.call(a,c)&&b.push(c);return b}function m(a){if(!r(a))throw new TypeError;for(var b,c=l(a),d={},e=0,f=c.length;f>e;++e)b=c[e],d[a[b]]=b;return d}function n(a){if(!r(a))throw new TypeError;for(var b,c=l(a),d=[],e=0,f=c.length;f>e;++e)b=c[e],d.push([b,a[b]]);return d}function o(a,b){if(!r(a))throw new TypeError;q(b)&&(b=[b]);for(var c,d=s(l(a),b),e={},f=0,g=d.length;g>f;++f)c=d[f],e[c]=a[c];return e}var p=b.deepEqual,q=b.isString,r=b.isHash,s=c.difference,t=Object.prototype.hasOwnProperty,u=b.isFunction,v={forEach:i,filter:j,invert:m,values:k,toArray:n,keys:l,omit:o},w={extend:h,merge:f,deepMerge:g,omit:o},x=a.define(b.isObject,w).define(r,v).define(b.isFunction,{extend:h}).expose({hash:v}).expose(w),y=x.extend;return x.extend=function(){return 1===arguments.length?y.extend.apply(x,arguments):(h.apply(null,arguments),void 0)},x}"undefined"!=typeof c?"undefined"!=typeof b&&b.exports&&(b.exports=d(a("extended"),a("is-extended"),a("array-extended"))):"function"==typeof define&&define.amd?define(["extended","is-extended","array-extended"],function(a,b,c){return d(a,b,c)}):this.objectExtended=d(this.extended,this.isExtended,this.arrayExtended)}.call(this)},{"array-extended":42,extended:46,"is-extended":56}],59:[function(a,b,c){var d=a("__browserify_process");!function(){"use strict";function e(a,b,c,e,f,g){function h(a,b){return function(){try{l(a.apply(null,arguments)).addCallback(b).addErrback(b)}catch(c){b.errback(c)}}}function i(a,b,c){var d=(new G).callback();return v(a,function(a){d=d.then(c?a:B(null,a)),c||(d=d.then(function(a){return b.push(a),b}))}),d}function j(a){return!w(a)&&y(a.then)}function k(a){var b=new G;return a.then(A(b,"callback"),A(b,"errback")),b.promise()}function l(a){var b;return a=C(arguments),a.length?1===a.length?(a=a.pop(),j(a)?a.addCallback&&a.addErrback?(b=new G,a.addCallback(b.callback),a.addErrback(b.errback)):b=k(a):b=x(a)&&c.every(a,j)?new H(a,!0).promise():(new G).callback(a)):b=new H(c.map(a,function(a){return l(a)}),!0).promise():b=(new G).callback(a).promise(),b}function m(a,b){return function(){var c=new G,d=C(arguments);return d.push(c.resolve),a.apply(b||this,d),c.promise()}}function n(a){if(x(a))return i(a,[],!1);throw new Error("When calling promise.serial the first argument must be an array")}function o(a){if(x(a))return i(a,[],!0);throw new Error("When calling promise.serial the first argument must be an array")}function p(a,b){a=C(arguments);var c=!1;b=a.pop();var d=l(a);return function(){return c?l(b.apply(this,arguments)):(a=arguments,d.then(A(this,function(){return c=!0,b.apply(this,a)})))}}function q(){return new G}function r(a){return new H(a,!0).promise()}function s(a){return q().errback(a)}function t(a){return q().callback(a)}var u,v=c.forEach,w=e.isUndefinedOrNull,x=e.isArray,y=e.isFunction,z=e.isBoolean,A=f.bind,B=f.bindIgnore,C=g.argsToArray;if("function"==typeof setImmediate)u="undefined"!=typeof window?setImmediate.bind(window):setImmediate;else if("undefined"!=typeof d)u=function(a){d.nextTick(a)};else if("undefined"!=typeof MessageChannel){var D=new MessageChannel,E={},F=E;D.port1.onmessage=function(){E=E.next;var a=E.task;delete E.task,a()},u=function(a){F=F.next={task:a},D.port2.postMessage(0)}}else u=function(a){setTimeout(a,0)};var G=a({instance:{__fired:!1,__results:null,__error:null,__errorCbs:null,__cbs:null,constructor:function(){this.__errorCbs=[],this.__cbs=[],f.bindAll(this,["callback","errback","resolve","classic","__resolve","addCallback","addErrback"])},__resolve:function(){if(!this.__fired){this.__fired=!0;var a,b=this.__error?this.__errorCbs:this.__cbs,c=b.length,d=this.__error||this.__results;for(a=0;c>a;a++)this.__callNextTick(b[a],d)}},__callNextTick:function(a,b){u(function(){a.apply(this,b) -})},addCallback:function(a){return a&&(j(a)&&a.callback&&(a=a.callback),this.__fired&&this.__results?this.__callNextTick(a,this.__results):this.__cbs.push(a)),this},addErrback:function(a){return a&&(j(a)&&a.errback&&(a=a.errback),this.__fired&&this.__error?this.__callNextTick(a,this.__error):this.__errorCbs.push(a)),this},callback:function(){return this.__fired||(this.__results=arguments,this.__resolve()),this.promise()},errback:function(){return this.__fired||(this.__error=arguments,this.__resolve()),this.promise()},resolve:function(a){return a?this.errback(a):this.callback.apply(this,C(arguments,1)),this},classic:function(a){return"function"==typeof a&&(this.addErrback(function(b){a(b)}),this.addCallback(function(){a.apply(this,[null].concat(C(arguments)))})),this},then:function(a,b){var c=new G,d=c;return y(b)&&(d=h(b,c)),this.addErrback(d),y(a)?this.addCallback(h(a,c)):this.addCallback(c),c.promise()},both:function(a){return this.then(a,a)},promise:function(){var a={then:A(this,"then"),both:A(this,"both"),promise:function(){return a}};return v(["addCallback","addErrback","classic"],function(b){a[b]=A(this,function(){return this[b].apply(this,arguments),a})},this),a}}}),H=G.extend({instance:{__results:null,__errors:null,__promiseLength:0,__defLength:0,__firedLength:0,normalizeResults:!1,constructor:function(a,b){this.__errors=[],this.__results=[],this.normalizeResults=z(b)?b:!1,this._super(arguments),a&&a.length?(this.__defLength=a.length,v(a,this.__addPromise,this)):this.__resolve()},__addPromise:function(a,b){a.then(A(this,function(){var a=C(arguments);a.unshift(b),this.callback.apply(this,a)}),A(this,function(){var a=C(arguments);a.unshift(b),this.errback.apply(this,a)}))},__resolve:function(){if(!this.__fired){this.__fired=!0;var a,b=this.__errors.length?this.__errorCbs:this.__cbs,c=b.length,d=this.__errors.length?this.__errors:this.__results;for(a=0;c>a;a++)this.__callNextTick(b[a],d)}},__callNextTick:function(a,b){u(function(){a.apply(null,[b])})},addCallback:function(a){return a&&(j(a)&&a.callback&&(a=A(a,"callback")),this.__fired&&!this.__errors.length?this.__callNextTick(a,this.__results):this.__cbs.push(a)),this},addErrback:function(a){return a&&(j(a)&&a.errback&&(a=A(a,"errback")),this.__fired&&this.__errors.length?this.__callNextTick(a,this.__errors):this.__errorCbs.push(a)),this},callback:function(a){if(this.__fired)throw new Error("Already fired!");var b=C(arguments);return this.normalizeResults&&(b=b.slice(1),b=1===b.length?b.pop():b),this.__results[a]=b,this.__firedLength++,this.__firedLength===this.__defLength&&this.__resolve(),this.promise()},errback:function(a){if(this.__fired)throw new Error("Already fired!");var b=C(arguments);return this.normalizeResults&&(b=b.slice(1),b=1===b.length?b.pop():b),this.__errors[a]=b,this.__firedLength++,this.__firedLength===this.__defLength&&this.__resolve(),this.promise()}}});return b.define({isPromiseLike:j}).expose({isPromiseLike:j,when:l,wrap:m,wait:p,serial:n,chain:o,Promise:G,PromiseList:H,promise:q,defer:q,deferredList:r,reject:s,resolve:t})}"undefined"!=typeof c?"undefined"!=typeof b&&b.exports&&(b.exports=e(a("declare.js"),a("extended"),a("array-extended"),a("is-extended"),a("function-extended"),a("arguments-extended"))):"function"==typeof define&&define.amd?define(["declare","extended","array-extended","is-extended","function-extended","arguments-extended"],function(a,b,c,d,f,g){return e(a,b,c,d,f,g)}):this.promiseExtended=e(this.declare,this.extended,this.arrayExtended,this.isExtended,this.functionExtended,this.argumentsExtended)}.call(this)},{__browserify_process:54,"arguments-extended":41,"array-extended":42,"declare.js":45,extended:46,"function-extended":49,"is-extended":56}],60:[function(a,b,c){!function(){"use strict";function d(a,b,c,d){function e(a,b){var c=a;if(x.test(b)){var d=b.match(x),e=d[1],f=d[3],g=d[4];g&&(g=parseInt(g,10),c=c.length0?"+":"")+d),k&&(k=parseInt(k,10),d=d.lengthe;)d?a+=c:a=c+a,e++;return a}function i(a,c,d){var e=a;if(b.isString(e)){if(a.length>c)if(d){var f=a.length;e=a.substring(f-c,f)}else e=a.substring(0,c)}else e=i(""+e,c);return e}function j(a,d){if(d instanceof Array){var h=0,i=d.length;return a.replace(v,function(a,b,j){var k,l;if(!(i>h))return a;if(k=d[h++],"%s"===a||"%d"===a||"%D"===a)l=k+"";else if("%Z"===a)l=k.toUTCString();else if("%j"===a)try{l=s(k)}catch(m){throw new Error("stringExtended.format : Unable to parse json from ",k)}else switch(b=b.replace(/^\[|\]$/g,""),j){case"s":l=e(k,b);break;case"d":l=f(k,b);break;case"j":l=g(k,b);break;case"D":l=c.format(k,b);break;case"Z":l=c.format(k,b,!0)}return l})}if(t(d))return a.replace(w,function(a,h,i){if(i=d[i],!b.isUndefined(i)){if(!h)return""+i;if(b.isString(i))return e(i,h);if(b.isNumber(i))return f(i,h);if(b.isDate(i))return c.format(i,h);if(b.isObject(i))return g(i,h)}return a});var k=u.call(arguments).slice(1);return j(a,k)}function k(a,b){var c=[];return a&&(a.indexOf(b)>0?c=a.replace(/\s+/g,"").split(b):c.push(a)),c}function l(a,b){var c=[];if(b)for(var d=0;b>d;d++)c.push(a);return c.join("")}function m(a,c){var d,e,f;if(c)if(b.isArray(a))for(d=[],e=0,f=a.length;f>e;e++)d.push(m(a[e],c));else if(c instanceof Array)for(d=a,e=0,f=c.length;f>e;e++)d=m(d,c[e]);else c in z&&(d="["+z[c]+"m"+a+"");return d}function n(a,b){return a.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g,function(a){return b&&-1!==d.indexOf(b,a)?a:"\\"+a})}function o(a){return a.replace(/^\s*|\s*$/g,"")}function p(a){return a.replace(/^\s*/,"")}function q(a){return a.replace(/\s*$/,"")}function r(a){return 0===a.length}var s;"undefined"==typeof JSON?function(){function a(a){return 10>a?"0"+a:a}function c(c){return b.isDate(c)?isFinite(c.valueOf())?c.getUTCFullYear()+"-"+a(c.getUTCMonth()+1)+"-"+a(c.getUTCDate())+"T"+a(c.getUTCHours())+":"+a(c.getUTCMinutes())+":"+a(c.getUTCSeconds())+"Z":null:i(c)?c.valueOf():c}function d(a){return j.lastIndex=0,j.test(a)?'"'+a.replace(j,function(a){var b=k[a];return"string"==typeof b?b:"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+a+'"'}function e(a,b){var i,j,k,l,m,n=f,o=b[a];switch(o&&(o=c(o)),"function"==typeof h&&(o=h.call(b,a,o)),typeof o){case"string":return d(o);case"number":return isFinite(o)?String(o):"null";case"boolean":case"null":return String(o);case"object":if(!o)return"null";if(f+=g,m=[],"[object Array]"===Object.prototype.toString.apply(o)){for(l=o.length,i=0;l>i;i+=1)m[i]=e(i,o)||"null";return k=0===m.length?"[]":f?"[\n"+f+m.join(",\n"+f)+"\n"+n+"]":"["+m.join(",")+"]",f=n,k}if(h&&"object"==typeof h)for(l=h.length,i=0;l>i;i+=1)"string"==typeof h[i]&&(j=h[i],k=e(j,o),k&&m.push(d(j)+(f?": ":":")+k));else for(j in o)Object.prototype.hasOwnProperty.call(o,j)&&(k=e(j,o),k&&m.push(d(j)+(f?": ":":")+k));return k=0===m.length?"{}":f?"{\n"+f+m.join(",\n"+f)+"\n"+n+"}":"{"+m.join(",")+"}",f=n,k}}var f,g,h,i=b.tester().isString().isNumber().isBoolean().tester(),j=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,k={"\b":"\\b"," ":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"};s=function(a,b,c){var d;if(f="",g="","number"==typeof c)for(d=0;c>d;d+=1)g+=" ";else"string"==typeof c&&(g=c);if(h=b,b&&"function"!=typeof b&&("object"!=typeof b||"number"!=typeof b.length))throw new Error("JSON.stringify");return e("",{"":a})}}():s=JSON.stringify;var t=b.isHash,u=Array.prototype.slice,v=/%((?:-?\+?.?\d*)?|(?:\[[^\[|\]]*\]))?([sjdDZ])/g,w=/\{(?:\[([^\[|\]]*)\])?(\w+)\}/g,x=/(-?)(\+?)([A-Z|a-z|\W]?)([1-9][0-9]*)?$/,y=/([1-9][0-9]*)$/g,z={bold:1,bright:1,italic:3,underline:4,blink:5,inverse:7,crossedOut:9,red:31,green:32,yellow:33,blue:34,magenta:35,cyan:36,white:37,redBackground:41,greenBackground:42,yellowBackground:43,blueBackground:44,magentaBackground:45,cyanBackground:46,whiteBackground:47,encircled:52,overlined:53,grey:90,black:90},A={SMILEY:"☺",SOLID_SMILEY:"☻",HEART:"♥",DIAMOND:"♦",CLOVE:"♣",SPADE:"♠",DOT:"•",SQUARE_CIRCLE:"◘",CIRCLE:"○",FILLED_SQUARE_CIRCLE:"◙",MALE:"♂",FEMALE:"♀",EIGHT_NOTE:"♪",DOUBLE_EIGHTH_NOTE:"♫",SUN:"☼",PLAY:"►",REWIND:"◄",UP_DOWN:"↕",PILCROW:"¶",SECTION:"§",THICK_MINUS:"▬",SMALL_UP_DOWN:"↨",UP_ARROW:"↑",DOWN_ARROW:"↓",RIGHT_ARROW:"→",LEFT_ARROW:"←",RIGHT_ANGLE:"∟",LEFT_RIGHT_ARROW:"↔",TRIANGLE:"▲",DOWN_TRIANGLE:"▼",HOUSE:"⌂",C_CEDILLA:"Ç",U_UMLAUT:"ü",E_ACCENT:"é",A_LOWER_CIRCUMFLEX:"â",A_LOWER_UMLAUT:"ä",A_LOWER_GRAVE_ACCENT:"à",A_LOWER_CIRCLE_OVER:"å",C_LOWER_CIRCUMFLEX:"ç",E_LOWER_CIRCUMFLEX:"ê",E_LOWER_UMLAUT:"ë",E_LOWER_GRAVE_ACCENT:"è",I_LOWER_UMLAUT:"ï",I_LOWER_CIRCUMFLEX:"î",I_LOWER_GRAVE_ACCENT:"ì",A_UPPER_UMLAUT:"Ä",A_UPPER_CIRCLE:"Å",E_UPPER_ACCENT:"É",A_E_LOWER:"æ",A_E_UPPER:"Æ",O_LOWER_CIRCUMFLEX:"ô",O_LOWER_UMLAUT:"ö",O_LOWER_GRAVE_ACCENT:"ò",U_LOWER_CIRCUMFLEX:"û",U_LOWER_GRAVE_ACCENT:"ù",Y_LOWER_UMLAUT:"ÿ",O_UPPER_UMLAUT:"Ö",U_UPPER_UMLAUT:"Ü",CENTS:"¢",POUND:"£",YEN:"¥",CURRENCY:"¤",PTS:"₧",FUNCTION:"ƒ",A_LOWER_ACCENT:"á",I_LOWER_ACCENT:"í",O_LOWER_ACCENT:"ó",U_LOWER_ACCENT:"ú",N_LOWER_TILDE:"ñ",N_UPPER_TILDE:"Ñ",A_SUPER:"ª",O_SUPER:"º",UPSIDEDOWN_QUESTION:"¿",SIDEWAYS_L:"⌐",NEGATION:"¬",ONE_HALF:"½",ONE_FOURTH:"¼",UPSIDEDOWN_EXCLAMATION:"¡",DOUBLE_LEFT:"«",DOUBLE_RIGHT:"»",LIGHT_SHADED_BOX:"░",MEDIUM_SHADED_BOX:"▒",DARK_SHADED_BOX:"▓",VERTICAL_LINE:"│",MAZE__SINGLE_RIGHT_T:"┤",MAZE_SINGLE_RIGHT_TOP:"┐",MAZE_SINGLE_RIGHT_BOTTOM_SMALL:"┘",MAZE_SINGLE_LEFT_TOP_SMALL:"┌",MAZE_SINGLE_LEFT_BOTTOM_SMALL:"└",MAZE_SINGLE_LEFT_T:"├",MAZE_SINGLE_BOTTOM_T:"┴",MAZE_SINGLE_TOP_T:"┬",MAZE_SINGLE_CENTER:"┼",MAZE_SINGLE_HORIZONTAL_LINE:"─",MAZE_SINGLE_RIGHT_DOUBLECENTER_T:"╡",MAZE_SINGLE_RIGHT_DOUBLE_BL:"╛",MAZE_SINGLE_RIGHT_DOUBLE_T:"╢",MAZE_SINGLE_RIGHT_DOUBLEBOTTOM_TOP:"╖",MAZE_SINGLE_RIGHT_DOUBLELEFT_TOP:"╕",MAZE_SINGLE_LEFT_DOUBLE_T:"╞",MAZE_SINGLE_BOTTOM_DOUBLE_T:"╧",MAZE_SINGLE_TOP_DOUBLE_T:"╤",MAZE_SINGLE_TOP_DOUBLECENTER_T:"╥",MAZE_SINGLE_BOTTOM_DOUBLECENTER_T:"╨",MAZE_SINGLE_LEFT_DOUBLERIGHT_BOTTOM:"╘",MAZE_SINGLE_LEFT_DOUBLERIGHT_TOP:"╒",MAZE_SINGLE_LEFT_DOUBLEBOTTOM_TOP:"╓",MAZE_SINGLE_LEFT_DOUBLETOP_BOTTOM:"╙",MAZE_SINGLE_LEFT_TOP:"Γ",MAZE_SINGLE_RIGHT_BOTTOM:"╜",MAZE_SINGLE_LEFT_CENTER:"╟",MAZE_SINGLE_DOUBLECENTER_CENTER:"╫",MAZE_SINGLE_DOUBLECROSS_CENTER:"╪",MAZE_DOUBLE_LEFT_CENTER:"╣",MAZE_DOUBLE_VERTICAL:"║",MAZE_DOUBLE_RIGHT_TOP:"╗",MAZE_DOUBLE_RIGHT_BOTTOM:"╝",MAZE_DOUBLE_LEFT_BOTTOM:"╚",MAZE_DOUBLE_LEFT_TOP:"╔",MAZE_DOUBLE_BOTTOM_T:"╩",MAZE_DOUBLE_TOP_T:"╦",MAZE_DOUBLE_LEFT_T:"╠",MAZE_DOUBLE_HORIZONTAL:"═",MAZE_DOUBLE_CROSS:"╬",SOLID_RECTANGLE:"█",THICK_LEFT_VERTICAL:"▌",THICK_RIGHT_VERTICAL:"▐",SOLID_SMALL_RECTANGLE_BOTTOM:"▄",SOLID_SMALL_RECTANGLE_TOP:"▀",PHI_UPPER:"Φ",INFINITY:"∞",INTERSECTION:"∩",DEFINITION:"≡",PLUS_MINUS:"±",GT_EQ:"≥",LT_EQ:"≤",THEREFORE:"⌠",SINCE:"∵",DOESNOT_EXIST:"∄",EXISTS:"∃",FOR_ALL:"∀",EXCLUSIVE_OR:"⊕",BECAUSE:"⌡",DIVIDE:"÷",APPROX:"≈",DEGREE:"°",BOLD_DOT:"∙",DOT_SMALL:"·",CHECK:"√",ITALIC_X:"✗",SUPER_N:"ⁿ",SQUARED:"²",CUBED:"³",SOLID_BOX:"■",PERMILE:"‰",REGISTERED_TM:"®",COPYRIGHT:"©",TRADEMARK:"™",BETA:"β",GAMMA:"γ",ZETA:"ζ",ETA:"η",IOTA:"ι",KAPPA:"κ",LAMBDA:"λ",NU:"ν",XI:"ξ",OMICRON:"ο",RHO:"ρ",UPSILON:"υ",CHI_LOWER:"φ",CHI_UPPER:"χ",PSI:"ψ",ALPHA:"α",ESZETT:"ß",PI:"π",SIGMA_UPPER:"Σ",SIGMA_LOWER:"σ",MU:"µ",TAU:"τ",THETA:"Θ",OMEGA:"Ω",DELTA:"δ",PHI_LOWER:"φ",EPSILON:"ε"},B={toArray:k,pad:h,truncate:i,multiply:l,format:j,style:m,escape:n,trim:o,trimLeft:p,trimRight:q,isEmpty:r};return a.define(b.isString,B).define(b.isArray,{style:m}).expose(B).expose({characters:A})}"undefined"!=typeof c?"undefined"!=typeof b&&b.exports&&(b.exports=d(a("extended"),a("is-extended"),a("date-extended"),a("array-extended"))):"function"==typeof define&&define.amd?define(["extended","is-extended","date-extended","array-extended"],function(a,b,c,e){return d(a,b,c,e)}):this.stringExtended=d(this.extended,this.isExtended,this.dateExtended,this.arrayExtended)}.call(this)},{"array-extended":42,"date-extended":43,extended:46,"is-extended":56}]},{},[1]); \ No newline at end of file +!function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);throw new Error("Cannot find module '"+g+"'")}var j=c[g]={exports:{}};b[g][0].call(j.exports,function(a){var c=b[g][1][a];return e(c?c:a)},j,j.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;gc&&g>c&&c++;);var h=d[c]-e[c];return h||(h=f-g),h}function g(a,b){return a.recency-b.recency}var h=a("./extended").map,i={salience:d,bucketCounter:e,factRecency:f,activationRecency:g};c.strategies=i,c.strategy=function(a){a=h(a,function(a){return i[a]});var b=a.length;return function(c,d){var e=-1,f=0,g=c===d||c.name===d.name&&c.hashCode===d.hashCode;if(!g){for(;++e0?1:-1}return f}}},{"./extended":12}],8:[function(a,b,c){"use strict";var d,e=a("./extended"),f=e.deepEqual,g=e.merge,h=e.instanceOf,i=e.filter,j=e.declare,k=0,l=j({type:null,instance:{constructor:function(b){d||(d=a("./constraintMatcher")),this.id=k++,this.constraint=b,e.bindAll(this,["assert"])},assert:function(){throw new Error("not implemented")},getIndexableProperties:function(){return[]},equal:function(a){return h(a,this._static)&&this.get("alias")===a.get("alias")&&e.deepEqual(this.constraint,a.constraint)},getters:{variables:function(){return[this.get("alias")]}}}});l.extend({instance:{type:"object",constructor:function(a){this._super([a])},assert:function(a){return a instanceof this.constraint||a.constructor===this.constraint},equal:function(a){return h(a,this._static)&&this.constraint===a.constraint}}}).as(c,"ObjectConstraint");var m=l.extend({instance:{type:"equality",constructor:function(a,b){this._super([a]),b=b||{},this.pattern=b.pattern,this._matcher=d.getMatcher(a,b,!0)},assert:function(a){return this._matcher(a)}}}).as(c,"EqualityConstraint");m.extend({instance:{type:"inequality"}}).as(c,"InequalityConstraint"),m.extend({instance:{type:"comparison"}}).as(c,"ComparisonConstraint"),l.extend({instance:{type:"equality",constructor:function(){this._super([[!0]])},equal:function(a){return h(a,this._static)&&this.get("alias")===a.get("alias")},assert:function(){return!0}}}).as(c,"TrueConstraint");var n=l.extend({instance:{type:"reference",constructor:function(a,b){this.cache={},this._super([a]),b=b||{},this.values=[],this.pattern=b.pattern,this._options=b,this._matcher=d.getMatcher(a,b,!1)},assert:function(a,b){try{return this._matcher(a,b)}catch(c){throw new Error("Error with evaluating pattern "+this.pattern+" "+c.message)}},merge:function(a){var b=this;return a instanceof n&&(b=new this._static([this.constraint,a.constraint,"and"],g({},this._options,this._options)),b._alias=this._alias||a._alias,b.vars=this.vars.concat(a.vars)),b},equal:function(a){return h(a,this._static)&&e.deepEqual(this.constraint,a.constraint)},getters:{variables:function(){return this.vars},alias:function(){return this._alias}},setters:{alias:function(a){this._alias=a,this.vars=i(d.getIdentifiers(this.constraint),function(b){return b!==a})}}}}).as(c,"ReferenceConstraint");n.extend({instance:{type:"reference_equality",op:"eq",getIndexableProperties:function(){return d.getIndexableProperties(this.constraint)}}}).as(c,"ReferenceEqualityConstraint").extend({instance:{type:"reference_inequality",op:"neq"}}).as(c,"ReferenceInequalityConstraint"),l.extend({instance:{type:"hash",constructor:function(a){this._super([a])},equal:function(a){return e.instanceOf(a,this._static)&&this.get("alias")===a.get("alias")&&e.deepEqual(this.constraint,a.constraint)},assert:function(){return!0},getters:{variables:function(){return this.constraint}}}}).as(c,"HashConstraint"),l.extend({instance:{constructor:function(a,b){this.type="from",this.constraints=d.getSourceMatcher(a,b||{},!0),e.bindAll(this,["assert"])},equal:function(a){return h(a,this._static)&&this.get("alias")===a.get("alias")&&f(this.constraints,a.constraints)},assert:function(a,b){return this.constraints(a,b)},getters:{variables:function(){return this.constraint}}}}).as(c,"FromConstraint")},{"./constraintMatcher":9,"./extended":12}],9:[function(a,b,c){"use strict";function d(a){return e(a).map(function(a){return f(a)?f(a[0])?d(a).value():a.reverse().join("."):a}).flatten().filter(function(a){return!!a})}var e=a("./extended"),f=e.isArray,g=e.forEach,h=e.some,i=e.indexOf,j=e.isNumber,k=e.removeDuplicates,l=a("./constraint"),m={indexOf:e.indexOf,now:function(){return new Date},Date:function(a,b,c,d,e,f,g){var h=new Date;return j(a)&&h.setYear(a),j(b)&&h.setMonth(b),j(c)&&h.setDate(c),j(d)&&h.setHours(d),j(e)&&h.setMinutes(e),j(f)&&h.setSeconds(f),j(g)&&h.setMilliseconds(g),h},lengthOf:function(a,b){return a.length===b},isTrue:function(a){return a===!0},isFalse:function(a){return a===!1},isNotNull:function(a){return null!==a},dateCmp:function(a,b){return e.compare(a,b)}};g(["years","days","months","hours","minutes","seconds"],function(a){m[a+"FromNow"]=e[a+"FromNow"],m[a+"Ago"]=e[a+"Ago"]}),g(["isArray","isNumber","isHash","isObject","isDate","isBoolean","isString","isRegExp","isNull","isEmpty","isUndefined","isDefined","isUndefinedOrNull","isPromiseLike","isFunction","deepEqual"],function(a){var b=e[a];m[a]=function(){return b.apply(e,arguments)}});var n={equal:function(a,b){var c=!1;return a===b?c=!0:a[2]===b[2]&&(c=-1!==i(["string","number","boolean","regexp","identifier","null"],a[2])?a[0]===b[0]:"unary"===a[2]||"logicalNot"===a[2]?this.equal(a[0],b[0]):this.equal(a[0],b[0])&&this.equal(a[1],b[1])),c},__getProperties:function(a){var b=[];if(a){var c=a[2];if(!c)return b;"prop"!==c&&"identifier"!==c&&"string"!==c&&"number"!==c&&"boolean"!==c&&"regexp"!==c&&"unary"!==c&&"unary"!==c?(b[0]=this.__getProperties(a[0]),b[1]=this.__getProperties(a[1])):b="identifier"===c?[a[0]]:n.__getProperties(a[1]).concat(n.__getProperties(a[0]))}return b},getIndexableProperties:function(a){return"composite"===a[2]?this.getIndexableProperties(a[0]):/^(\w+(\['[^']*'])*) *[!=]== (\w+(\['[^']*'])*)$/.test(this.parse(a))?d(this.__getProperties(a)).flatten().value():[]},getIdentifiers:function(a){var b=[],c=a[2];if("identifier"===c)return[a[0]];if("function"===c)b=b.concat(this.getIdentifiers(a[0])).concat(this.getIdentifiers(a[1]));else if("string"!==c&&"number"!==c&&"boolean"!==c&&"regexp"!==c&&"unary"!==c&&"unary"!==c)if("prop"===c){if(b=b.concat(this.getIdentifiers(a[0])),a[1])for(var d=a[1];f(d);){if("function"===d[2]){b=b.concat(this.getIdentifiers(d[1]));break}d=d[1]}}else a[0]&&(b=b.concat(this.getIdentifiers(a[0]))),a[1]&&(b=b.concat(this.getIdentifiers(a[1])));return k(b)},toConstraints:function(a,b){var c=[],d=b.alias,e=b.scope||{},f=a[2];if("and"===f)c=c.concat(this.toConstraints(a[0],b)).concat(this.toConstraints(a[1],b));else if("composite"===f||"or"===f||"lt"===f||"gt"===f||"lte"===f||"gte"===f||"like"===f||"notLike"===f||"eq"===f||"neq"===f||"in"===f||"notIn"===f||"prop"===f||"propLookup"===f||"function"===f||"logicalNot"===f){var g=h(this.getIdentifiers(a),function(a){return!(a===d||a in m||a in e)});"eq"===f?c.push(new l[g?"ReferenceEqualityConstraint":"EqualityConstraint"](a,b)):"neq"===f?c.push(new l[g?"ReferenceInequalityConstraint":"InequalityConstraint"](a,b)):c.push(new l[g?"ReferenceConstraint":"ComparisonConstraint"](a,b))}return c},parse:function(a){return this[a[2]](a[0],a[1])},composite:function(a){return this.parse(a)},and:function(a,b){return["(",this.parse(a),"&&",this.parse(b),")"].join(" ")},or:function(a,b){return["(",this.parse(a),"||",this.parse(b),")"].join(" ")},prop:function(a,b){return"function"===b[2]?[this.parse(a),this.parse(b)].join("."):[this.parse(a),"['",this.parse(b),"']"].join("")},propLookup:function(a,b){return"function"===b[2]?[this.parse(a),this.parse(b)].join("."):[this.parse(a),"[",this.parse(b),"]"].join("")},unary:function(a){return-1*this.parse(a)},plus:function(a,b){return[this.parse(a),"+",this.parse(b)].join(" ")},minus:function(a,b){return[this.parse(a),"-",this.parse(b)].join(" ")},mult:function(a,b){return[this.parse(a),"*",this.parse(b)].join(" ")},div:function(a,b){return[this.parse(a),"/",this.parse(b)].join(" ")},mod:function(a,b){return[this.parse(a),"%",this.parse(b)].join(" ")},lt:function(a,b){return[this.parse(a),"<",this.parse(b)].join(" ")},gt:function(a,b){return[this.parse(a),">",this.parse(b)].join(" ")},lte:function(a,b){return[this.parse(a),"<=",this.parse(b)].join(" ")},gte:function(a,b){return[this.parse(a),">=",this.parse(b)].join(" ")},like:function(a,b){return[this.parse(b),".test(",this.parse(a),")"].join("")},notLike:function(a,b){return["!",this.parse(b),".test(",this.parse(a),")"].join("")},eq:function(a,b){return[this.parse(a),"===",this.parse(b)].join(" ")},neq:function(a,b){return[this.parse(a),"!==",this.parse(b)].join(" ")},"in":function(a,b){return["(indexOf(",this.parse(b),",",this.parse(a),")) != -1"].join("")},notIn:function(a,b){return["(indexOf(",this.parse(b),",",this.parse(a),")) == -1"].join("")},arguments:function(a,b){var c=[];return a&&c.push(this.parse(a)),b&&c.push(this.parse(b)),c.join(",")},array:function(a){var b=[];return a?(b=this.parse(a),f(b)?b:["[",b,"]"].join("")):["[",b.join(","),"]"].join("")},"function":function(a,b){var c=this.parse(b);return[this.parse(a),"(",c,")"].join("")},string:function(a){return"'"+a+"'"},number:function(a){return a},"boolean":function(a){return a},regexp:function(a){return a},identifier:function(a){return a},"null":function(){return"null"},logicalNot:function(a){return["!(",this.parse(a),")"].join("")}},o=0,p=c.toJs=function(a,b,c,d,f){var g=n.parse(a);b=b||{};var h=n.getIdentifiers(a),i=["var indexOf = definedFuncs.indexOf; var hasOwnProperty = Object.prototype.hasOwnProperty;"],j=[];e(h).filter(function(a){var c=["var ",a," = "];if(m.hasOwnProperty(a))c.push("definedFuncs['",a,"']");else{if(!b.hasOwnProperty(a))return!0;c.push("scope['",a,"']")}return c.push(";"),i.push(c.join("")),!1}).forEach(function(a){var b=["var ",a," = "];d||a!==c?b.push("fact."+a):a===c&&b.push("hash.",a,""),b.push(";"),j.push(b.join(""))});var k=i.join("")+"return function matcher"+o++ +(d?"(fact){":"(fact, hash){")+j.join("")+" return "+(f?f(g):g)+";}",l=new Function("definedFuncs, scope",k)(m,b);return l};c.getMatcher=function(a,b,c){return b=b||{},p(a,b.scope,b.alias,c,function(a){return"!!("+a+")"})},c.getSourceMatcher=function(a,b,c){return b=b||{},p(a,b.scope,b.alias,c,function(a){return a})},c.toConstraints=function(a,b){return n.toConstraints(a,b)},c.equal=function(a,b){return n.equal(a,b)},c.getIdentifiers=function(a){return n.getIdentifiers(a)},c.getIndexableProperties=function(a){return n.getIndexableProperties(a)}},{"./constraint":8,"./extended":12}],10:[function(a,b){"use strict";function c(a,b){for(var c=[],d=-1,e=a.length;++di){for(f=a.slice();++gb;b++)a.assert(arguments[b]);return a},containsRule:function(a){return c.some(this.__rules,function(b){return b.name===a})}},"static":{getFlow:function(a){return l[a]},hasFlow:function(a){return c.has(l,a)},deleteFlow:function(a){return d(a,m)&&(a=a.name),delete l[a],m},deleteFlows:function(){for(var a in l)a in l&&delete l[a];return m},create:function(a,b){return new m(a,b)}}}).as(b)},{"./conflict":7,"./extended":12,"./flow":13,"./pattern":45,"./rule":46}],15:[function(a,b,c){"use strict";function d(a){return/\.nools$/.test(a)}function e(a){var b;return b=d(a)?i.parse(g.readFileSync(a,"utf8"),a):i.parse(a)}var f=a("./extended"),g=a("fs"),h=a("path"),i=a("./compile"),j=a("./flowContainer");c.Flow=j,c.getFlow=j.getFlow,c.hasFlow=j.hasFlow,c.deleteFlow=function(a){return j.deleteFlow(a),this},c.deleteFlows=function(){return j.deleteFlows(),this},c.flow=j.create,c.compile=function(a,b,c){if(f.isFunction(b)?(c=b,b={}):(b=b||{},c=null),f.isString(a)&&(b.name=b.name||(d(a)?h.basename(a,h.extname(a)):null),a=e(a)),!b.name)throw new Error("Name required when compiling nools source");return i.compile(a,b,c,j)},c.transpile=function(a,b){return b=b||{},f.isString(a)&&(b.name=b.name||(d(a)?h.basename(a,h.extname(a)):null),a=e(a)),i.transpile(a,b)},c.parse=e},{"./compile":5,"./extended":12,"./flowContainer":14,fs:65,path:66}],16:[function(a,b){var c=a("declare.js");c({instance:{constructor:function(){this.head=null,this.tail=null,this.length=null},push:function(a){var b=this.tail,c=this.head,d={data:a,prev:b,next:null};return b&&(this.tail.next=d),this.tail=d,c||(this.head=d),this.length++,d},remove:function(a){a.prev?a.prev.next=a.next:this.head=a.next,a.next?a.next.prev=a.prev:this.tail=a.prev,this.length--},forEach:function(a){for(var b={next:this.head};b=b.next;)a(b.data)},toArray:function(){for(var a={next:this.head},b=[];a=a.next;)b.push(a);return b},removeByData:function(a){for(var b={next:this.head};b=b.next;)if(b.data===a){this.remove(b);break}},getByData:function(a){for(var b={next:this.head};b=b.next;)if(b.data===a)return b},clear:function(){this.head=this.tail=null,this.length=0}}}).as(b)},{"declare.js":52}],17:[function(a,b){var c,d=a("__browserify_process"),e=a("./extended");if("function"==typeof setImmediate)c="undefined"!=typeof window?e.bind(window,setImmediate):setImmediate;else if("undefined"!=typeof d)c=d.nextTick;else if("undefined"!=typeof MessageChannel){var f=new MessageChannel,g={},h=g;f.port1.onmessage=function(){g=g.next;var a=g.task;delete g.task,a()},c=function(a){h=h.next={task:a},f.port2.postMessage(0)}}else c=function(a){setTimeout(a,0)};b.exports=c},{"./extended":12,__browserify_process:68}],18:[function(a,b){var c=a("./node"),d=a("../extended").intersection,e=a("../context");c.extend({instance:{__propagatePaths:function(a,b){for(var c,f,g,h,i=this.__entrySet,j=i.length;--j>-1;)c=i[j],f=c.key,g=c.value,(h=d(g,b.paths)).length&&f[a](new e(b.fact,h,b.match))},__propagateNoPaths:function(a,b){for(var c=this.__entrySet,d=c.length;--d>-1;)c[d].key[a](b)},__propagate:function(a,b){b.paths?this.__propagatePaths(a,b):this.__propagateNoPaths(a,b)}}}).as(b)},{"../context":10,"../extended":12,"./node":34}],19:[function(a,b){var c=a("./alphaNode");c.extend({instance:{constructor:function(){this._super(arguments),this.alias=this.constraint.get("alias")},toString:function(){return"AliasNode"+this.__count +},assert:function(a){return this.__propagate("assert",a.set(this.alias,a.fact.object))},modify:function(a){return this.__propagate("modify",a.set(this.alias,a.fact.object))},retract:function(a){return this.__propagate("retract",a.set(this.alias,a.fact.object))},equal:function(a){return a instanceof this._static&&this.alias===a.alias}}}).as(b)},{"./alphaNode":20}],20:[function(a,b){"use strict";var c=a("./node");c.extend({instance:{constructor:function(a){this._super([]),this.constraint=a,this.constraintAssert=this.constraint.assert},toString:function(){return"AlphaNode "+this.__count},equal:function(a){return this.constraint.equal(a.constraint)}}}).as(b)},{"./node":34}],21:[function(a,b){var c=a("../extended"),d=c.hash.values,e=c.hash.keys,f=a("./node"),g=a("./misc/leftMemory"),h=a("./misc/rightMemory");f.extend({instance:{nodeType:"BetaNode",constructor:function(){this._super([]),this.leftMemory={},this.rightMemory={},this.leftTuples=new g,this.rightTuples=new h},__propagate:function(a,b){for(var c,d,e=this.__entrySet,f=e.length;--f>-1;)c=e[f],d=c.key,d[a](b)},dispose:function(){this.leftMemory={},this.rightMemory={},this.leftTuples.clear(),this.rightTuples.clear()},disposeLeft:function(a){this.leftMemory={},this.leftTuples.clear(),this.propagateDispose(a)},disposeRight:function(a){this.rightMemory={},this.rightTuples.clear(),this.propagateDispose(a)},hashCode:function(){return this.nodeType+" "+this.__count},toString:function(){return this.nodeType+" "+this.__count},retractLeft:function(a){a=this.removeFromLeftMemory(a).data;for(var b=d(a.rightMatches),c=-1,e=b.length;++ch;h++)if(this.__isMatch(a,e[h],!0)){a.blocked=!0;break}}else f(e)&&(a.blocked=this.__isMatch(a,e,!0));var j=a.blocked;j?c?this.__propagate("modify",a.clone()):this.__propagate("assert",a.clone()):c&&this.__propagate("retract",a.clone())},__findMatches:function(a){var b=a.factHash,c=this.from(b),d=!1;if(g(c)){for(var e=0,h=c.length;h>e;e++)if(this.__isMatch(a,c[e],!0))return a.blocked=!0,this.__propagate("assert",a.clone()),void 0}else f(c)&&this.__isMatch(a,c,!0)&&(a.blocked=!0,this.__propagate("assert",a.clone()));return d},__isMatch:function(a,b,c){var d=!1;if(this.type(b)){var f=this.workingMemory.getFactHandle(b),g=new e(f,null).mergeMatch(a.match).set(this.alias,b);if(c){var h=this.fromMemory[f.id];h||(h=this.fromMemory[f.id]={}),h[a.hashCode]=a}for(var i=g.factHash,j=this.__equalityConstraints,k=0,l=j.length;l>k;k++){if(!j[k](i)){d=!1;break}d=!0}}return d},assertLeft:function(a){this.__addToLeftMemory(a),this.__findMatches(a)}}}).as(b)},{"../context":10,"../extended":12,"./fromNotNode":26}],24:[function(a,b){var c=a("./notNode"),d=a("../linkedList");c.extend({instance:{nodeType:"ExistsNode",blockedContext:function(a,b){a.blocker=b,this.removeFromLeftMemory(a),this.addToLeftBlockedMemory(b.blocking.push(a)),this.__propagate("assert",this.__cloneContext(a))},notBlockedContext:function(a,b){this.__addToLeftMemory(a),b&&this.__propagate("retract",this.__cloneContext(a))},propagateFromLeft:function(a){this.notBlockedContext(a,!1)},retractLeft:function(a){var b;if(!this.removeFromLeftMemory(a)){if(!(b=this.removeFromLeftBlockedMemory(a)))throw new Error;this.__propagate("retract",this.__cloneContext(b.data))}},modifyLeft:function(a){var b,c,d,e,f=this.removeFromLeftMemory(a),g=this.constraint,h=this.rightTuples,i=h.length,j=!1;if(f||(f=this.removeFromLeftBlockedMemory(a),j=!0),!f)throw new Error;if(b=f.data,b&&b.blocker&&(e=this.rightMemory[b.blocker.hashCode]),e?(g.isMatch(a,d=e.data)&&(this.__propagate(j?"modify":"assert",this.__cloneContext(b)),a.blocker=d,this.addToLeftBlockedMemory(d.blocking.push(a)),a=null),a&&(c={next:e.next})):c={next:h.head},a&&i)for(c={next:h.head};c=c.next;)if(g.isMatch(a,d=c.data)){this.__propagate(j?"modify":"assert",this.__cloneContext(b)),this.addToLeftBlockedMemory(d.blocking.push(a)),a.blocker=d,a=null;break}a&&(this.__addToLeftMemory(a),j&&this.__propagate("retract",this.__cloneContext(a)))},modifyRight:function(a){var b=this.removeFromRightMemory(a);if(!b)throw new Error;var c,e,f=b.data,g=this.leftTuples,h=g.length,i=this.constraint,j=f.blocking;if(this.__addToRightMemory(a),a.blocking=new d,h||j.length){if(j.length)for(var k,l={next:j.head};l=l.next;)if(c=l.data,c.blocker=null,i.isMatch(c,a))c.blocker=a,this.addToLeftBlockedMemory(a.blocking.push(c)),this.__propagate("assert",this.__cloneContext(c)),c=null;else{for(c.blocker=null,e=b;e=e.next;)if(i.isMatch(c,k=e.data)){c.blocker=k,this.addToLeftBlockedMemory(k.blocking.push(c)),this.__propagate("assert",this.__cloneContext(c)),c=null;break}c&&this.__addToLeftMemory(c)}if(h)for(e={next:g.head};e=e.next;)c=e.data,i.isMatch(c,a)&&(this.__propagate("assert",this.__cloneContext(c)),this.removeFromLeftMemory(c),this.addToLeftBlockedMemory(a.blocking.push(c)),c.blocker=a)}}}}).as(b)},{"../linkedList":16,"./notNode":35}],25:[function(a,b){var c=a("./joinNode"),d=a("../extended"),e=a("../constraint"),f=e.EqualityConstraint,g=e.HashConstraint,h=e.ReferenceConstraint,i=a("../context"),j=d.isDefined,k=d.isEmpty,l=d.forEach,m=d.isArray,n={isMatch:function(){return!1}};c.extend({instance:{nodeType:"FromNode",constructor:function(a,b){this._super(arguments),this.workingMemory=b,this.fromMemory={},this.pattern=a,this.type=a.get("constraints")[0].assert,this.alias=a.get("alias"),this.from=a.from.assert;var c=this.__equalityConstraints=[],d=[];l(this.constraints=this.pattern.get("constraints").slice(1),function(a){a instanceof f||a instanceof h?c.push(a.assert):a instanceof g&&(d=d.concat(a.get("variables")))}),this.__variables=d},__createMatches:function(a){var b=a.factHash,c=this.from(b);if(m(c))for(var d=0,e=c.length;e>d;d++)this.__checkMatch(a,c[d],!0);else j(c)&&this.__checkMatch(a,c,!0)},__checkMatch:function(a,b,c){var d;return(d=this.__createMatch(a,b)).isMatch()&&c&&this.__propagate("assert",d.clone()),d},__createMatch:function(a,b){if(this.type(b)){var c,d=this.workingMemory.getFactHandle(b,!0),e=new i(d).set(this.alias,b),f=d.id,g=e.factHash,h=a.factHash;for(var j in h)g[j]=h[j];for(var k=this.__equalityConstraints,l=this.__variables,m=-1,o=k.length;++mc;c++)b=this.__checkMatch(a,l[c],!1),b.isMatch()&&(e=b.fact.id,e in k?this.__propagate("modify",b.clone()):this.__propagate("assert",b.clone()));else j(l)&&(b=this.__checkMatch(a,l,!1),b.isMatch()&&(e=b.fact.id,e in k?this.__propagate("modify",b.clone()):this.__propagate("assert",b.clone())));for(c in k)c in i||(this.removeFromFromMemory(k[c]),this.__propagate("retract",k[c].clone()))}else this.assertLeft(a);f=a.fact,e=f.id;var n=this.fromMemory[e];if(this.fromMemory[e]={},n){var o,p,q,r,s=f.object;for(c in n)p=n[c],o=p[0],q=p[1],r=q.isMatch(),o.hashCode!==a.hashCode&&(b=this.__createMatch(o,s,!1),r&&this.__propagate("retract",q.clone()),b.isMatch()&&this.__propagate(r?"modify":"assert",b.clone()))}},assertLeft:function(a){this.__addToLeftMemory(a),a.fromMatches={},this.__createMatches(a)},assertRight:function(){throw new Error("Shouldnt have gotten here")}}}).as(b)},{"../constraint":8,"../context":10,"../extended":12,"./joinNode":28}],26:[function(a,b){var c=a("./joinNode"),d=a("../extended"),e=a("../constraint"),f=e.EqualityConstraint,g=e.HashConstraint,h=e.ReferenceConstraint,i=a("../context"),j=d.isDefined,k=d.forEach,l=d.isArray;c.extend({instance:{nodeType:"FromNotNode",constructor:function(a,b){this._super(arguments),this.workingMemory=b,this.pattern=a,this.type=a.get("constraints")[0].assert,this.alias=a.get("alias"),this.from=a.from.assert,this.fromMemory={};var c=this.__equalityConstraints=[],d=[];k(this.constraints=this.pattern.get("constraints").slice(1),function(a){a instanceof f||a instanceof h?c.push(a.assert):a instanceof g&&(d=d.concat(a.get("variables")))}),this.__variables=d},retractLeft:function(a){var b=this.removeFromLeftMemory(a);b&&(b=b.data,b.blocked||this.__propagate("retract",b.clone()))},__modify:function(a,b){var c=b.blocked,d=a.factHash,e=this.from(d);if(l(e)){for(var f=0,g=e.length;g>f;f++)if(this.__isMatch(a,e[f],!0)){a.blocked=!0;break}}else j(e)&&(a.blocked=this.__isMatch(a,e,!0));var h=a.blocked;h?c||this.__propagate("retract",b.clone()):c?this.__propagate("assert",a.clone()):this.__propagate("modify",a.clone())},modifyLeft:function(a){var b=this.removeFromLeftMemory(a);if(!b)throw new Error;this.__addToLeftMemory(a),this.__modify(a,b.data);var c=this.fromMemory[a.fact.id];if(this.fromMemory[a.fact.id]={},c)for(var d in c)if(d!==a.hashCode){var e=c[d];b=this.removeFromLeftMemory(e),b&&(e=e.clone(),e.blocked=!1,this.__addToLeftMemory(e),this.__modify(e,b.data))}},__findMatches:function(a){var b=a.factHash,c=this.from(b),d=!1;if(l(c)){for(var e=0,f=c.length;f>e;e++)if(this.__isMatch(a,c[e],!0))return a.blocked=!0,void 0;this.__propagate("assert",a.clone())}else j(c)&&!(a.blocked=this.__isMatch(a,c,!0))&&this.__propagate("assert",a.clone());return d},__isMatch:function(a,b,c){var d=!1;if(this.type(b)){var e=this.workingMemory.getFactHandle(b),f=new i(e,null).mergeMatch(a.match).set(this.alias,b);if(c){var g=this.fromMemory[e.id];g||(g=this.fromMemory[e.id]={}),g[a.hashCode]=a}for(var h=f.factHash,j=this.__equalityConstraints,k=0,l=j.length;l>k;k++){if(!j[k](h,h)){d=!1;break}d=!0}}return d},assertLeft:function(a){this.__addToLeftMemory(a),this.__findMatches(a)},assertRight:function(){throw new Error("Shouldnt have gotten here")},retractRight:function(){throw new Error("Shouldnt have gotten here")}}}).as(b)},{"../constraint":8,"../context":10,"../extended":12,"./joinNode":28}],27:[function(a,b,c){"use strict";function d(a){return g(a.constraints||[],function(a){return a instanceof t})}var e=a("../extended"),f=e.forEach,g=e.some,h=e.declare,i=a("../pattern.js"),j=i.ObjectPattern,k=i.FromPattern,l=i.FromNotPattern,m=i.ExistsPattern,n=i.FromExistsPattern,o=i.NotPattern,p=i.CompositePattern,q=i.InitialFactPattern,r=a("../constraint"),s=r.HashConstraint,t=r.ReferenceConstraint,u=a("./aliasNode"),v=a("./equalityNode"),w=a("./joinNode"),x=a("./betaNode"),y=a("./notNode"),z=a("./fromNode"),A=a("./fromNotNode"),B=a("./existsNode"),C=a("./existsFromNode"),D=a("./leftAdapterNode"),E=a("./rightAdapterNode"),F=a("./typeNode"),G=a("./terminalNode"),H=a("./propertyNode");h({instance:{constructor:function(a,b){this.terminalNodes=[],this.joinNodes=[],this.nodes=[],this.constraints=[],this.typeNodes=[],this.__ruleCount=0,this.bucket={counter:0,recency:0},this.agendaTree=b,this.workingMemory=a},assertRule:function(a){var b=new G(this.bucket,this.__ruleCount++,a,this.agendaTree);this.__addToNetwork(a,a.pattern,b),this.__mergeJoinNodes(),this.terminalNodes.push(b)},resetCounter:function(){this.bucket.counter=0},incrementCounter:function(){this.bucket.counter++},assertFact:function(a){for(var b=this.typeNodes,c=b.length-1;c>=0;c--)b[c].assert(a)},retractFact:function(a){for(var b=this.typeNodes,c=b.length-1;c>=0;c--)b[c].retract(a)},modifyFact:function(a){for(var b=this.typeNodes,c=b.length-1;c>=0;c--)b[c].modify(a)},containsRule:function(a){return g(this.terminalNodes,function(b){return b.rule.name===a})},dispose:function(){for(var a=this.typeNodes,b=a.length-1;b>=0;b--)a[b].dispose()},__mergeJoinNodes:function(){for(var a=this.joinNodes,b=0;b=0;c--){var d=b[c];if(a.equal(d))return d}return b.push(a),a},__createTypeNode:function(a,b){for(var c=new F(b.get("constraints")[0]),d=this.typeNodes,e=d.length-1;e>=0;e--){var f=d[e];if(c.equal(f))return f}return d.push(c),c},__createEqualityNode:function(a,b){return this.__checkEqual(new v(b)).addRule(a)},__createPropertyNode:function(a,b){return this.__checkEqual(new H(b)).addRule(a)},__createAliasNode:function(a,b){return this.__checkEqual(new u(b)).addRule(a)},__createAdapterNode:function(a,b){return("left"===b?new D:new E).addRule(a)},__createJoinNode:function(a,b,c,e){var f;b.rightPattern instanceof o?f=new y:b.rightPattern instanceof n?f=new C(b.rightPattern,this.workingMemory):b.rightPattern instanceof m?f=new B:b.rightPattern instanceof l?f=new A(b.rightPattern,this.workingMemory):b.rightPattern instanceof k?f=new z(b.rightPattern,this.workingMemory):b instanceof p&&!d(b.leftPattern)&&!d(b.rightPattern)?(f=new x,this.joinNodes.push(f)):(f=new w,this.joinNodes.push(f)),f.__rule__=a;var g=f;if(c instanceof x){var h=this.__createAdapterNode(a,e);g.addOutNode(h,b),g=h}return g.addOutNode(c,b),f.addRule(a)},__addToNetwork:function(a,b,c,d){b instanceof j?b instanceof q||d&&"left"!==d?this.__createAlphaNode(a,b,c,d):this.__createBetaNode(a,new p(new q,b),c,d):b instanceof p&&this.__createBetaNode(a,b,c,d)},__createBetaNode:function(a,b,c,d){var e=this.__createJoinNode(a,b,c,d);return this.__addToNetwork(a,b.rightPattern,e,"right"),this.__addToNetwork(a,b.leftPattern,e,"left"),c.addParentNode(e),e},__createAlphaNode:function(a,b,c,d){var e,f;if(!(b instanceof k)){var g=b.get("constraints");e=this.__createTypeNode(a,b);var h=this.__createAliasNode(a,b);e.addOutNode(h,b),h.addParentNode(e),f=h;for(var i=g.length-1;i>0;i--){var j,l=g[i];if(l instanceof s)j=this.__createPropertyNode(a,l);else{if(l instanceof t){c.constraint.addConstraint(l);continue}j=this.__createEqualityNode(a,l)}f.addOutNode(j,b),j.addParentNode(f),f=j}if(c instanceof x){var m=this.__createAdapterNode(a,d);m.addParentNode(f),f.addOutNode(m,b),f=m}return c.addParentNode(f),f.addOutNode(c,b),e}},print:function(){f(this.terminalNodes,function(a){a.print(" ")})}}}).as(c,"RootNode")},{"../constraint":8,"../extended":12,"../pattern.js":45,"./aliasNode":19,"./betaNode":21,"./equalityNode":22,"./existsFromNode":23,"./existsNode":24,"./fromNode":25,"./fromNotNode":26,"./joinNode":28,"./leftAdapterNode":30,"./notNode":35,"./propertyNode":36,"./rightAdapterNode":37,"./terminalNode":38,"./typeNode":39}],28:[function(a,b){var c=a("./betaNode"),d=a("./joinReferenceNode");c.extend({instance:{constructor:function(){this._super(arguments),this.constraint=new d(this.leftTuples,this.rightTuples)},nodeType:"JoinNode",propagateFromLeft:function(a,b){var c;return(c=this.constraint.match(a,b)).isMatch&&this.__propagate("assert",this.__addToMemoryMatches(b,a,a.clone(null,null,c))),this},propagateFromRight:function(a,b){var c;return(c=this.constraint.match(b,a)).isMatch&&this.__propagate("assert",this.__addToMemoryMatches(a,b,a.clone(null,null,c))),this},propagateAssertModifyFromLeft:function(a,b,c){var d,e=c.hashCode;if(e in b){d=this.constraint.match(a,c);var f=d.isMatch;f?this.__propagate("modify",this.__addToMemoryMatches(c,a,a.clone(null,null,d))):this.__propagate("retract",b[e].clone())}else this.propagateFromLeft(a,c)},propagateAssertModifyFromRight:function(a,b,c){var d,e=c.hashCode;if(e in b){d=this.constraint.match(c,a);var f=d.isMatch;f?this.__propagate("modify",this.__addToMemoryMatches(a,c,a.clone(null,null,d))):this.__propagate("retract",b[e].clone())}else this.propagateFromRight(a,c)}}}).as(b)},{"./betaNode":21,"./joinReferenceNode":29}],29:[function(a,b){var c=a("./node"),d=a("../constraint"),e=d.ReferenceEqualityConstraint,f={isDefault:!0,assert:function(){return!0},equal:function(){return!1}};c.extend({instance:{constraint:f,constructor:function(a,b){this._super(arguments),this.constraint=f,this.constraintAssert=f.assert,this.rightIndexes=[],this.leftIndexes=[],this.constraintLength=0,this.leftMemory=a,this.rightMemory=b},addConstraint:function(a){if(a instanceof e){var b=a.getIndexableProperties(),c=a.get("alias");if(2===b.length&&c){for(var d,f,g=-1;++g<2;){var h=b[g];null===h.match(new RegExp("^"+c+"(\\.?)"))?d=h:f=h}d&&f&&(this.rightMemory.addIndex(f,d,a.op),this.leftMemory.addIndex(d,f,a.op))}}this.constraint.isDefault?(this.constraint=a,this.isDefault=!1):this.constraint=this.constraint.merge(a),this.constraintAssert=this.constraint.assert},equal:function(a){return this.constraint.equal(a.constraint)},isMatch:function(a,b){return this.constraintAssert(a.factHash,b.factHash)},match:function(a,b){var c={isMatch:!1};return this.constraintAssert(a.factHash,b.factHash)&&(c=a.match.merge(b.match)),c}}}).as(b)},{"../constraint":8,"./node":34}],30:[function(a,b){var c=a("./adapterNode");c.extend({instance:{propagateAssert:function(a){this.__propagate("assertLeft",a)},propagateRetract:function(a){this.__propagate("retractLeft",a)},propagateResolve:function(a){this.__propagate("retractResolve",a)},propagateModify:function(a){this.__propagate("modifyLeft",a)},retractResolve:function(a){this.__propagate("retractResolve",a)},dispose:function(a){this.propagateDispose(a)},toString:function(){return"LeftAdapterNode "+this.__count}}}).as(b)},{"./adapterNode":18}],31:[function(a,b){var c=a("./memory");c.extend({instance:{getLeftMemory:function(a){return this.getMemory(a)}}}).as(b)},{"./memory":32}],32:[function(a,b){var c=a("../../extended"),d=c.indexOf,e=c.plucker,f=c.diffArr,g=Array.prototype.push,h=c.declare,i=c.HashTable;h({instance:{constructor:function(){this.head=null,this.tail=null,this.length=null,this.indexes=[],this.tables={tuples:[],tables:[]}},inequalityThreshold:.5,push:function(a){var b=this.tail,c=this.head,d={data:a,prev:b,next:null};return b&&(this.tail.next=d),this.tail=d,c||(this.head=d),this.length++,this.__index(d),this.tables.tuples.push(d),d},remove:function(a){a.prev?a.prev.next=a.next:this.head=a.next,a.next?a.next.prev=a.prev:this.tail=a.prev;var b=d(this.tables.tuples,a);-1!==b&&this.tables.tuples.splice(b,1),this.__removeFromIndex(a),this.length--},forEach:function(a){for(var b={next:this.head};b=b.next;)a(b.data)},toArray:function(){for(var a={next:this.head},b=[];a=a.next;)b.push(a);return b},clear:function(){this.head=this.tail=null,this.length=0,this.clearIndexes()},clearIndexes:function(){this.tables={},this.indexes.length=0},__index:function(a){for(var b,c,d,e,f,g,h,j=a.data,k=j.factHash,l=this.indexes,m=this.tables,n=-1,o=l.length;++nm&&(k=f(k,n)),k.slice()},__createIndexTree:function(){var a=this.tables.tables={},b=this.indexes;a[b[0][0]]=new i},addIndex:function(a,b,c){this.indexes.push([a,b,e(a),e(b),c||"eq"]),this.indexes.sort(function(a,b){var c=a[4],d=b[4];return c===d?0:c>d?1:-1}),this.__createIndexTree()}}}).as(b)},{"../../extended":12}],33:[function(a,b){var c=a("./memory");c.extend({instance:{getRightMemory:function(a){return this.getMemory(a)}}}).as(b)},{"./memory":32}],34:[function(a,b){var c=a("../extended"),d=c.forEach,e=c.indexOf,f=c.intersection,g=c.declare,h=c.HashTable,i=a("../context"),j=0;g({instance:{constructor:function(){this.nodes=new h,this.rules=[],this.parentNodes=[],this.__count=j++,this.__entrySet=[]},addRule:function(a){return-1===e(this.rules,a)&&this.rules.push(a),this},merge:function(a){a.nodes.forEach(function(b){for(var c=b.value,d=b.key,e=0,f=c.length;f>e;e++)this.addOutNode(d,c[e]);a.nodes.remove(d)},this);for(var b=a.parentNodes,c=0,d=a.parentNodes.l;d>c;c++){var e=b[c];this.addParentNode(e),e.nodes.remove(a)}return this},resolve:function(a,b){return a.hashCode===b.hashCode},print:function(a){console.log(a+this.toString()),d(this.parentNodes,function(b){b.print(" "+a)})},addOutNode:function(a,b){this.nodes.contains(a)||this.nodes.put(a,[]),this.nodes.get(a).push(b),this.__entrySet=this.nodes.entrySet()},addParentNode:function(a){-1===e(this.parentNodes,a)&&this.parentNodes.push(a)},shareable:function(){return!1},__propagate:function(a,b){for(var c,d,e,g,h=this.__entrySet,j=h.length;--j>-1;)c=h[j],d=c.key,e=c.value,(g=f(e,b.paths)).length&&d[a](new i(b.fact,g,b.match))},dispose:function(a){this.propagateDispose(a)},retract:function(a){this.propagateRetract(a)},propagateDispose:function(a,b){b=b||this.nodes;for(var c=this.__entrySet,d=c.length-1;d>=0;d--){var e=c[d],f=e.key;f.dispose(a)}},propagateAssert:function(a){this.__propagate("assert",a)},propagateRetract:function(a){this.__propagate("retract",a)},assert:function(a){this.propagateAssert(a)},modify:function(a){this.propagateModify(a)},propagateModify:function(a){this.__propagate("modify",a)}}}).as(b)},{"../context":10,"../extended":12}],35:[function(a,b){var c=a("./joinNode"),d=a("../linkedList"),e=a("../context"),f=a("../pattern").InitialFact;c.extend({instance:{nodeType:"NotNode",constructor:function(){this._super(arguments),this.leftTupleMemory={},this.notMatch=new e(new f).match},__cloneContext:function(a){return a.clone(null,null,a.match.merge(this.notMatch))},retractRight:function(a){var b=this.removeFromRightMemory(a),c=b.data,d=c.blocking;if(d.length){for(var e,f,g,h=this.rightTuples.getSimilarMemory(c),i=h.length,j=this.constraint,k={next:d.head};k=k.next;){for(f=k.data,e=-1;++eg;g++)b=e[g],c.set(b[1],f[b[0]]);this.__propagate("assert",c)},retract:function(a){this.__propagate("retract",new d(a.fact,a.paths))},modify:function(a){var b,c=new d(a.fact,a.paths),e=this.variables,f=a.fact.object;c.set(this.alias,f);for(var g=0,h=this.varLength;h>g;g++)b=e[g],c.set(b[1],f[b[0]]);this.__propagate("modify",c)},toString:function(){return"PropertyNode"+this.__count}}}).as(b)},{"../context":10,"../extended":12,"./alphaNode":20}],37:[function(a,b){var c=a("./adapterNode");c.extend({instance:{retractResolve:function(a){this.__propagate("retractResolve",a)},dispose:function(a){this.propagateDispose(a)},propagateAssert:function(a){this.__propagate("assertRight",a)},propagateRetract:function(a){this.__propagate("retractRight",a)},propagateResolve:function(a){this.__propagate("retractResolve",a)},propagateModify:function(a){this.__propagate("modifyRight",a)},toString:function(){return"RightAdapterNode "+this.__count}}}).as(b)},{"./adapterNode":18}],38:[function(a,b){var c=a("./node"),d=a("../extended"),e=d.bind;c.extend({instance:{constructor:function(a,b,c,d){this._super([]),this.resolve=e(this,this.resolve),this.rule=c,this.index=b,this.name=this.rule.name,this.agenda=d,this.bucket=a,d.register(this)},__assertModify:function(a){var b=a.match;if(b.isMatch){var c=this.rule,d=this.bucket;this.agenda.insert(this,{rule:c,hashCode:a.hashCode,index:this.index,name:c.name,recency:d.recency++,match:b,counter:d.counter})}},assert:function(a){this.__assertModify(a)},modify:function(a){this.agenda.retract(this,a),this.__assertModify(a)},retract:function(a){this.agenda.retract(this,a)},retractRight:function(a){this.agenda.retract(this,a)},retractLeft:function(a){this.agenda.retract(this,a)},assertLeft:function(a){this.__assertModify(a)},assertRight:function(a){this.__assertModify(a)},toString:function(){return"TerminalNode "+this.rule.name}}}).as(b)},{"../extended":12,"./node":34}],39:[function(a,b){var c=a("./alphaNode"),d=a("../context"); +c.extend({instance:{assert:function(a){this.constraintAssert(a.object)&&this.__propagate("assert",a)},modify:function(a){this.constraintAssert(a.object)&&this.__propagate("modify",a)},retract:function(a){this.constraintAssert(a.object)&&this.__propagate("retract",a)},toString:function(){return"TypeNode"+this.__count},dispose:function(){for(var a=this.__entrySet,b=a.length-1;b>=0;b--){var c=a[b],d=c.key,e=c.value;d.dispose({paths:e})}},__propagate:function(a,b){for(var c=this.__entrySet,e=-1,f=c.length;++e":20,"<=":21,">=":22,EQUALITY_EXPRESSION:23,"==":24,"!=":25,"=~":26,"!=~":27,IN_EXPRESSION:28,"in":29,ARRAY_EXPRESSION:30,notIn:31,OBJECT_EXPRESSION:32,AND_EXPRESSION:33,"&&":34,OR_EXPRESSION:35,"||":36,ARGUMENT_LIST:37,",":38,IDENTIFIER_EXPRESSION:39,IDENTIFIER:40,".":41,"[":42,STRING_EXPRESSION:43,"]":44,NUMBER_EXPRESSION:45,"(":46,")":47,STRING:48,NUMBER:49,REGEXP_EXPRESSION:50,REGEXP:51,BOOLEAN_EXPRESSION:52,BOOLEAN:53,NULL_EXPRESSION:54,NULL:55,$accept:0,$end:1},terminals_:{2:"error",5:"EOF",8:"-",9:"!",11:"*",12:"/",13:"%",15:"+",17:"^",19:"<",20:">",21:"<=",22:">=",24:"==",25:"!=",26:"=~",27:"!=~",29:"in",31:"notIn",34:"&&",36:"||",38:",",40:"IDENTIFIER",41:".",42:"[",44:"]",46:"(",47:")",48:"STRING",49:"NUMBER",51:"REGEXP",53:"BOOLEAN",55:"NULL"},productions_:[0,[3,2],[6,1],[6,2],[6,2],[10,1],[10,3],[10,3],[10,3],[14,1],[14,3],[14,3],[16,1],[16,3],[18,1],[18,3],[18,3],[18,3],[18,3],[23,1],[23,3],[23,3],[23,3],[23,3],[28,1],[28,3],[28,3],[28,3],[28,3],[33,1],[33,3],[35,1],[35,3],[37,1],[37,3],[39,1],[32,1],[32,3],[32,4],[32,4],[32,4],[32,3],[32,4],[43,1],[45,1],[50,1],[52,1],[54,1],[30,2],[30,3],[7,1],[7,1],[7,1],[7,1],[7,1],[7,1],[7,1],[7,3],[4,1]],performAction:function(a,b,c,d,e,f){var g=f.length-1;switch(e){case 1:return f[g-1];case 3:this.$=[f[g],null,"unary"];break;case 4:this.$=[f[g],null,"logicalNot"];break;case 6:this.$=[f[g-2],f[g],"mult"];break;case 7:this.$=[f[g-2],f[g],"div"];break;case 8:this.$=[f[g-2],f[g],"mod"];break;case 10:this.$=[f[g-2],f[g],"plus"];break;case 11:this.$=[f[g-2],f[g],"minus"];break;case 13:this.$=[f[g-2],f[g],"pow"];break;case 15:this.$=[f[g-2],f[g],"lt"];break;case 16:this.$=[f[g-2],f[g],"gt"];break;case 17:this.$=[f[g-2],f[g],"lte"];break;case 18:this.$=[f[g-2],f[g],"gte"];break;case 20:this.$=[f[g-2],f[g],"eq"];break;case 21:this.$=[f[g-2],f[g],"neq"];break;case 22:this.$=[f[g-2],f[g],"like"];break;case 23:this.$=[f[g-2],f[g],"notLike"];break;case 25:this.$=[f[g-2],f[g],"in"];break;case 26:this.$=[f[g-2],f[g],"notIn"];break;case 27:this.$=[f[g-2],f[g],"in"];break;case 28:this.$=[f[g-2],f[g],"notIn"];break;case 30:this.$=[f[g-2],f[g],"and"];break;case 32:this.$=[f[g-2],f[g],"or"];break;case 34:this.$=[f[g-2],f[g],"arguments"];break;case 35:this.$=[String(a),null,"identifier"];break;case 37:this.$=[f[g-2],f[g],"prop"];break;case 38:this.$=[f[g-3],f[g-1],"propLookup"];break;case 39:this.$=[f[g-3],f[g-1],"propLookup"];break;case 40:this.$=[f[g-3],f[g-1],"propLookup"];break;case 41:this.$=[f[g-2],[null,null,"arguments"],"function"];break;case 42:this.$=[f[g-3],f[g-1],"function"];break;case 43:this.$=[String(a.replace(/^['|"]|['|"]$/g,"")),null,"string"];break;case 44:this.$=[Number(a),null,"number"];break;case 45:this.$=[a,null,"regexp"];break;case 46:this.$=["true"==a.replace(/^\s+/,""),null,"boolean"];break;case 47:this.$=[null,null,"null"];break;case 48:this.$=[null,null,"array"];break;case 49:this.$=[f[g-1],null,"array"];break;case 57:this.$=[f[g-1],null,"composite"]}},table:[{3:1,4:2,6:28,7:7,8:[1,29],9:[1,30],10:27,14:25,16:17,18:8,23:6,28:5,30:15,32:14,33:4,35:3,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{1:[3]},{5:[1,31]},{5:[2,58],36:[1,32],47:[2,58]},{5:[2,31],34:[1,33],36:[2,31],47:[2,31]},{5:[2,29],34:[2,29],36:[2,29],47:[2,29]},{5:[2,24],24:[1,34],25:[1,35],26:[1,36],27:[1,37],34:[2,24],36:[2,24],47:[2,24]},{5:[2,2],8:[2,2],11:[2,2],12:[2,2],13:[2,2],15:[2,2],17:[2,2],19:[2,2],20:[2,2],21:[2,2],22:[2,2],24:[2,2],25:[2,2],26:[2,2],27:[2,2],29:[1,38],31:[1,39],34:[2,2],36:[2,2],47:[2,2]},{5:[2,19],19:[1,40],20:[1,41],21:[1,42],22:[1,43],24:[2,19],25:[2,19],26:[2,19],27:[2,19],34:[2,19],36:[2,19],47:[2,19]},{5:[2,50],8:[2,50],11:[2,50],12:[2,50],13:[2,50],15:[2,50],17:[2,50],19:[2,50],20:[2,50],21:[2,50],22:[2,50],24:[2,50],25:[2,50],26:[2,50],27:[2,50],29:[2,50],31:[2,50],34:[2,50],36:[2,50],38:[2,50],44:[2,50],47:[2,50]},{5:[2,51],8:[2,51],11:[2,51],12:[2,51],13:[2,51],15:[2,51],17:[2,51],19:[2,51],20:[2,51],21:[2,51],22:[2,51],24:[2,51],25:[2,51],26:[2,51],27:[2,51],29:[2,51],31:[2,51],34:[2,51],36:[2,51],38:[2,51],44:[2,51],47:[2,51]},{5:[2,52],8:[2,52],11:[2,52],12:[2,52],13:[2,52],15:[2,52],17:[2,52],19:[2,52],20:[2,52],21:[2,52],22:[2,52],24:[2,52],25:[2,52],26:[2,52],27:[2,52],29:[2,52],31:[2,52],34:[2,52],36:[2,52],38:[2,52],44:[2,52],47:[2,52]},{5:[2,53],8:[2,53],11:[2,53],12:[2,53],13:[2,53],15:[2,53],17:[2,53],19:[2,53],20:[2,53],21:[2,53],22:[2,53],24:[2,53],25:[2,53],26:[2,53],27:[2,53],29:[2,53],31:[2,53],34:[2,53],36:[2,53],38:[2,53],44:[2,53],47:[2,53]},{5:[2,54],8:[2,54],11:[2,54],12:[2,54],13:[2,54],15:[2,54],17:[2,54],19:[2,54],20:[2,54],21:[2,54],22:[2,54],24:[2,54],25:[2,54],26:[2,54],27:[2,54],29:[2,54],31:[2,54],34:[2,54],36:[2,54],38:[2,54],44:[2,54],47:[2,54]},{5:[2,55],8:[2,55],11:[2,55],12:[2,55],13:[2,55],15:[2,55],17:[2,55],19:[2,55],20:[2,55],21:[2,55],22:[2,55],24:[2,55],25:[2,55],26:[2,55],27:[2,55],29:[2,55],31:[2,55],34:[2,55],36:[2,55],38:[2,55],41:[1,44],42:[1,45],44:[2,55],46:[1,46],47:[2,55]},{5:[2,56],8:[2,56],11:[2,56],12:[2,56],13:[2,56],15:[2,56],17:[2,56],19:[2,56],20:[2,56],21:[2,56],22:[2,56],24:[2,56],25:[2,56],26:[2,56],27:[2,56],29:[2,56],31:[2,56],34:[2,56],36:[2,56],38:[2,56],44:[2,56],47:[2,56]},{4:47,6:28,7:7,8:[1,29],9:[1,30],10:27,14:25,16:17,18:8,23:6,28:5,30:15,32:14,33:4,35:3,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{5:[2,14],17:[1,48],19:[2,14],20:[2,14],21:[2,14],22:[2,14],24:[2,14],25:[2,14],26:[2,14],27:[2,14],34:[2,14],36:[2,14],47:[2,14]},{5:[2,43],8:[2,43],11:[2,43],12:[2,43],13:[2,43],15:[2,43],17:[2,43],19:[2,43],20:[2,43],21:[2,43],22:[2,43],24:[2,43],25:[2,43],26:[2,43],27:[2,43],29:[2,43],31:[2,43],34:[2,43],36:[2,43],38:[2,43],44:[2,43],47:[2,43]},{5:[2,44],8:[2,44],11:[2,44],12:[2,44],13:[2,44],15:[2,44],17:[2,44],19:[2,44],20:[2,44],21:[2,44],22:[2,44],24:[2,44],25:[2,44],26:[2,44],27:[2,44],29:[2,44],31:[2,44],34:[2,44],36:[2,44],38:[2,44],44:[2,44],47:[2,44]},{5:[2,45],8:[2,45],11:[2,45],12:[2,45],13:[2,45],15:[2,45],17:[2,45],19:[2,45],20:[2,45],21:[2,45],22:[2,45],24:[2,45],25:[2,45],26:[2,45],27:[2,45],29:[2,45],31:[2,45],34:[2,45],36:[2,45],38:[2,45],44:[2,45],47:[2,45]},{5:[2,46],8:[2,46],11:[2,46],12:[2,46],13:[2,46],15:[2,46],17:[2,46],19:[2,46],20:[2,46],21:[2,46],22:[2,46],24:[2,46],25:[2,46],26:[2,46],27:[2,46],29:[2,46],31:[2,46],34:[2,46],36:[2,46],38:[2,46],44:[2,46],47:[2,46]},{5:[2,47],8:[2,47],11:[2,47],12:[2,47],13:[2,47],15:[2,47],17:[2,47],19:[2,47],20:[2,47],21:[2,47],22:[2,47],24:[2,47],25:[2,47],26:[2,47],27:[2,47],29:[2,47],31:[2,47],34:[2,47],36:[2,47],38:[2,47],44:[2,47],47:[2,47]},{5:[2,36],8:[2,36],11:[2,36],12:[2,36],13:[2,36],15:[2,36],17:[2,36],19:[2,36],20:[2,36],21:[2,36],22:[2,36],24:[2,36],25:[2,36],26:[2,36],27:[2,36],29:[2,36],31:[2,36],34:[2,36],36:[2,36],38:[2,36],41:[2,36],42:[2,36],44:[2,36],46:[2,36],47:[2,36]},{7:51,30:15,32:14,37:50,39:23,40:[1,26],42:[1,24],43:9,44:[1,49],45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{5:[2,12],8:[1,53],15:[1,52],17:[2,12],19:[2,12],20:[2,12],21:[2,12],22:[2,12],24:[2,12],25:[2,12],26:[2,12],27:[2,12],34:[2,12],36:[2,12],47:[2,12]},{5:[2,35],8:[2,35],11:[2,35],12:[2,35],13:[2,35],15:[2,35],17:[2,35],19:[2,35],20:[2,35],21:[2,35],22:[2,35],24:[2,35],25:[2,35],26:[2,35],27:[2,35],29:[2,35],31:[2,35],34:[2,35],36:[2,35],38:[2,35],41:[2,35],42:[2,35],44:[2,35],46:[2,35],47:[2,35]},{5:[2,9],8:[2,9],11:[1,54],12:[1,55],13:[1,56],15:[2,9],17:[2,9],19:[2,9],20:[2,9],21:[2,9],22:[2,9],24:[2,9],25:[2,9],26:[2,9],27:[2,9],34:[2,9],36:[2,9],47:[2,9]},{5:[2,5],8:[2,5],11:[2,5],12:[2,5],13:[2,5],15:[2,5],17:[2,5],19:[2,5],20:[2,5],21:[2,5],22:[2,5],24:[2,5],25:[2,5],26:[2,5],27:[2,5],34:[2,5],36:[2,5],47:[2,5]},{6:57,7:58,8:[1,29],9:[1,30],30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:59,7:58,8:[1,29],9:[1,30],30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{1:[2,1]},{6:28,7:7,8:[1,29],9:[1,30],10:27,14:25,16:17,18:8,23:6,28:5,30:15,32:14,33:60,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:28,7:7,8:[1,29],9:[1,30],10:27,14:25,16:17,18:8,23:6,28:61,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:28,7:58,8:[1,29],9:[1,30],10:27,14:25,16:17,18:62,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:28,7:58,8:[1,29],9:[1,30],10:27,14:25,16:17,18:63,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:28,7:58,8:[1,29],9:[1,30],10:27,14:25,16:17,18:64,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:28,7:58,8:[1,29],9:[1,30],10:27,14:25,16:17,18:65,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{30:66,32:67,39:23,40:[1,26],42:[1,24]},{30:68,32:69,39:23,40:[1,26],42:[1,24]},{6:28,7:58,8:[1,29],9:[1,30],10:27,14:25,16:70,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:28,7:58,8:[1,29],9:[1,30],10:27,14:25,16:71,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:28,7:58,8:[1,29],9:[1,30],10:27,14:25,16:72,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:28,7:58,8:[1,29],9:[1,30],10:27,14:25,16:73,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{39:74,40:[1,26]},{32:77,39:23,40:[1,26],43:75,45:76,48:[1,18],49:[1,19]},{7:51,30:15,32:14,37:79,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],47:[1,78],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{47:[1,80]},{6:28,7:58,8:[1,29],9:[1,30],10:27,14:81,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{5:[2,48],8:[2,48],11:[2,48],12:[2,48],13:[2,48],15:[2,48],17:[2,48],19:[2,48],20:[2,48],21:[2,48],22:[2,48],24:[2,48],25:[2,48],26:[2,48],27:[2,48],29:[2,48],31:[2,48],34:[2,48],36:[2,48],38:[2,48],44:[2,48],47:[2,48]},{38:[1,83],44:[1,82]},{38:[2,33],44:[2,33],47:[2,33]},{6:28,7:58,8:[1,29],9:[1,30],10:84,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:28,7:58,8:[1,29],9:[1,30],10:85,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:86,7:58,8:[1,29],9:[1,30],30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:87,7:58,8:[1,29],9:[1,30],30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{6:88,7:58,8:[1,29],9:[1,30],30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{5:[2,3],8:[2,3],11:[2,3],12:[2,3],13:[2,3],15:[2,3],17:[2,3],19:[2,3],20:[2,3],21:[2,3],22:[2,3],24:[2,3],25:[2,3],26:[2,3],27:[2,3],34:[2,3],36:[2,3],47:[2,3]},{5:[2,2],8:[2,2],11:[2,2],12:[2,2],13:[2,2],15:[2,2],17:[2,2],19:[2,2],20:[2,2],21:[2,2],22:[2,2],24:[2,2],25:[2,2],26:[2,2],27:[2,2],34:[2,2],36:[2,2],47:[2,2]},{5:[2,4],8:[2,4],11:[2,4],12:[2,4],13:[2,4],15:[2,4],17:[2,4],19:[2,4],20:[2,4],21:[2,4],22:[2,4],24:[2,4],25:[2,4],26:[2,4],27:[2,4],34:[2,4],36:[2,4],47:[2,4]},{5:[2,32],34:[1,33],36:[2,32],47:[2,32]},{5:[2,30],34:[2,30],36:[2,30],47:[2,30]},{5:[2,20],19:[1,40],20:[1,41],21:[1,42],22:[1,43],24:[2,20],25:[2,20],26:[2,20],27:[2,20],34:[2,20],36:[2,20],47:[2,20]},{5:[2,21],19:[1,40],20:[1,41],21:[1,42],22:[1,43],24:[2,21],25:[2,21],26:[2,21],27:[2,21],34:[2,21],36:[2,21],47:[2,21]},{5:[2,22],19:[1,40],20:[1,41],21:[1,42],22:[1,43],24:[2,22],25:[2,22],26:[2,22],27:[2,22],34:[2,22],36:[2,22],47:[2,22]},{5:[2,23],19:[1,40],20:[1,41],21:[1,42],22:[1,43],24:[2,23],25:[2,23],26:[2,23],27:[2,23],34:[2,23],36:[2,23],47:[2,23]},{5:[2,25],34:[2,25],36:[2,25],47:[2,25]},{5:[2,27],34:[2,27],36:[2,27],41:[1,44],42:[1,45],46:[1,46],47:[2,27]},{5:[2,26],34:[2,26],36:[2,26],47:[2,26]},{5:[2,28],34:[2,28],36:[2,28],41:[1,44],42:[1,45],46:[1,46],47:[2,28]},{5:[2,15],17:[1,48],19:[2,15],20:[2,15],21:[2,15],22:[2,15],24:[2,15],25:[2,15],26:[2,15],27:[2,15],34:[2,15],36:[2,15],47:[2,15]},{5:[2,16],17:[1,48],19:[2,16],20:[2,16],21:[2,16],22:[2,16],24:[2,16],25:[2,16],26:[2,16],27:[2,16],34:[2,16],36:[2,16],47:[2,16]},{5:[2,17],17:[1,48],19:[2,17],20:[2,17],21:[2,17],22:[2,17],24:[2,17],25:[2,17],26:[2,17],27:[2,17],34:[2,17],36:[2,17],47:[2,17]},{5:[2,18],17:[1,48],19:[2,18],20:[2,18],21:[2,18],22:[2,18],24:[2,18],25:[2,18],26:[2,18],27:[2,18],34:[2,18],36:[2,18],47:[2,18]},{5:[2,37],8:[2,37],11:[2,37],12:[2,37],13:[2,37],15:[2,37],17:[2,37],19:[2,37],20:[2,37],21:[2,37],22:[2,37],24:[2,37],25:[2,37],26:[2,37],27:[2,37],29:[2,37],31:[2,37],34:[2,37],36:[2,37],38:[2,37],41:[2,37],42:[2,37],44:[2,37],46:[2,37],47:[2,37]},{44:[1,89]},{44:[1,90]},{41:[1,44],42:[1,45],44:[1,91],46:[1,46]},{5:[2,41],8:[2,41],11:[2,41],12:[2,41],13:[2,41],15:[2,41],17:[2,41],19:[2,41],20:[2,41],21:[2,41],22:[2,41],24:[2,41],25:[2,41],26:[2,41],27:[2,41],29:[2,41],31:[2,41],34:[2,41],36:[2,41],38:[2,41],41:[2,41],42:[2,41],44:[2,41],46:[2,41],47:[2,41]},{38:[1,83],47:[1,92]},{5:[2,57],8:[2,57],11:[2,57],12:[2,57],13:[2,57],15:[2,57],17:[2,57],19:[2,57],20:[2,57],21:[2,57],22:[2,57],24:[2,57],25:[2,57],26:[2,57],27:[2,57],29:[2,57],31:[2,57],34:[2,57],36:[2,57],38:[2,57],44:[2,57],47:[2,57]},{5:[2,13],8:[1,53],15:[1,52],17:[2,13],19:[2,13],20:[2,13],21:[2,13],22:[2,13],24:[2,13],25:[2,13],26:[2,13],27:[2,13],34:[2,13],36:[2,13],47:[2,13]},{5:[2,49],8:[2,49],11:[2,49],12:[2,49],13:[2,49],15:[2,49],17:[2,49],19:[2,49],20:[2,49],21:[2,49],22:[2,49],24:[2,49],25:[2,49],26:[2,49],27:[2,49],29:[2,49],31:[2,49],34:[2,49],36:[2,49],38:[2,49],44:[2,49],47:[2,49]},{7:93,30:15,32:14,39:23,40:[1,26],42:[1,24],43:9,45:10,46:[1,16],48:[1,18],49:[1,19],50:11,51:[1,20],52:12,53:[1,21],54:13,55:[1,22]},{5:[2,10],8:[2,10],11:[1,54],12:[1,55],13:[1,56],15:[2,10],17:[2,10],19:[2,10],20:[2,10],21:[2,10],22:[2,10],24:[2,10],25:[2,10],26:[2,10],27:[2,10],34:[2,10],36:[2,10],47:[2,10]},{5:[2,11],8:[2,11],11:[1,54],12:[1,55],13:[1,56],15:[2,11],17:[2,11],19:[2,11],20:[2,11],21:[2,11],22:[2,11],24:[2,11],25:[2,11],26:[2,11],27:[2,11],34:[2,11],36:[2,11],47:[2,11]},{5:[2,6],8:[2,6],11:[2,6],12:[2,6],13:[2,6],15:[2,6],17:[2,6],19:[2,6],20:[2,6],21:[2,6],22:[2,6],24:[2,6],25:[2,6],26:[2,6],27:[2,6],34:[2,6],36:[2,6],47:[2,6]},{5:[2,7],8:[2,7],11:[2,7],12:[2,7],13:[2,7],15:[2,7],17:[2,7],19:[2,7],20:[2,7],21:[2,7],22:[2,7],24:[2,7],25:[2,7],26:[2,7],27:[2,7],34:[2,7],36:[2,7],47:[2,7]},{5:[2,8],8:[2,8],11:[2,8],12:[2,8],13:[2,8],15:[2,8],17:[2,8],19:[2,8],20:[2,8],21:[2,8],22:[2,8],24:[2,8],25:[2,8],26:[2,8],27:[2,8],34:[2,8],36:[2,8],47:[2,8]},{5:[2,38],8:[2,38],11:[2,38],12:[2,38],13:[2,38],15:[2,38],17:[2,38],19:[2,38],20:[2,38],21:[2,38],22:[2,38],24:[2,38],25:[2,38],26:[2,38],27:[2,38],29:[2,38],31:[2,38],34:[2,38],36:[2,38],38:[2,38],41:[2,38],42:[2,38],44:[2,38],46:[2,38],47:[2,38]},{5:[2,39],8:[2,39],11:[2,39],12:[2,39],13:[2,39],15:[2,39],17:[2,39],19:[2,39],20:[2,39],21:[2,39],22:[2,39],24:[2,39],25:[2,39],26:[2,39],27:[2,39],29:[2,39],31:[2,39],34:[2,39],36:[2,39],38:[2,39],41:[2,39],42:[2,39],44:[2,39],46:[2,39],47:[2,39]},{5:[2,40],8:[2,40],11:[2,40],12:[2,40],13:[2,40],15:[2,40],17:[2,40],19:[2,40],20:[2,40],21:[2,40],22:[2,40],24:[2,40],25:[2,40],26:[2,40],27:[2,40],29:[2,40],31:[2,40],34:[2,40],36:[2,40],38:[2,40],41:[2,40],42:[2,40],44:[2,40],46:[2,40],47:[2,40]},{5:[2,42],8:[2,42],11:[2,42],12:[2,42],13:[2,42],15:[2,42],17:[2,42],19:[2,42],20:[2,42],21:[2,42],22:[2,42],24:[2,42],25:[2,42],26:[2,42],27:[2,42],29:[2,42],31:[2,42],34:[2,42],36:[2,42],38:[2,42],41:[2,42],42:[2,42],44:[2,42],46:[2,42],47:[2,42]},{38:[2,34],44:[2,34],47:[2,34]}],defaultActions:{31:[2,1]},parseError:function(a,b){if(!b.recoverable)throw new Error(a);this.trace(a)},parse:function(a){function b(){var a;return a=c.lexer.lex()||m,"number"!=typeof a&&(a=c.symbols_[a]||a),a}var c=this,d=[0],e=[null],f=[],g=this.table,h="",i=0,j=0,k=0,l=2,m=1;this.lexer.setInput(a),this.lexer.yy=this.yy,this.yy.lexer=this.lexer,this.yy.parser=this,"undefined"==typeof this.lexer.yylloc&&(this.lexer.yylloc={});var n=this.lexer.yylloc;f.push(n);var o=this.lexer.options&&this.lexer.options.ranges;this.parseError="function"==typeof this.yy.parseError?this.yy.parseError:Object.getPrototypeOf(this).parseError;for(var p,q,r,s,t,u,v,w,x,y={};;){if(r=d[d.length-1],this.defaultActions[r]?s=this.defaultActions[r]:((null===p||"undefined"==typeof p)&&(p=b()),s=g[r]&&g[r][p]),"undefined"==typeof s||!s.length||!s[0]){var z="";x=[];for(u in g[r])this.terminals_[u]&&u>l&&x.push("'"+this.terminals_[u]+"'");z=this.lexer.showPosition?"Parse error on line "+(i+1)+":\n"+this.lexer.showPosition()+"\nExpecting "+x.join(", ")+", got '"+(this.terminals_[p]||p)+"'":"Parse error on line "+(i+1)+": Unexpected "+(p==m?"end of input":"'"+(this.terminals_[p]||p)+"'"),this.parseError(z,{text:this.lexer.match,token:this.terminals_[p]||p,line:this.lexer.yylineno,loc:n,expected:x})}if(s[0]instanceof Array&&s.length>1)throw new Error("Parse Error: multiple actions possible at state: "+r+", token: "+p);switch(s[0]){case 1:d.push(p),e.push(this.lexer.yytext),f.push(this.lexer.yylloc),d.push(s[1]),p=null,q?(p=q,q=null):(j=this.lexer.yyleng,h=this.lexer.yytext,i=this.lexer.yylineno,n=this.lexer.yylloc,k>0&&k--);break;case 2:if(v=this.productions_[s[1]][1],y.$=e[e.length-v],y._$={first_line:f[f.length-(v||1)].first_line,last_line:f[f.length-1].last_line,first_column:f[f.length-(v||1)].first_column,last_column:f[f.length-1].last_column},o&&(y._$.range=[f[f.length-(v||1)].range[0],f[f.length-1].range[1]]),t=this.performAction.call(y,h,j,i,this.yy,s[1],e,f),"undefined"!=typeof t)return t;v&&(d=d.slice(0,2*-1*v),e=e.slice(0,-1*v),f=f.slice(0,-1*v)),d.push(this.productions_[s[1]][0]),e.push(y.$),f.push(y._$),w=g[d[d.length-2]][d[d.length-1]],d.push(w);break;case 3:return!0}}return!0}},c=function(){var a={EOF:1,parseError:function(a,b){if(!this.yy.parser)throw new Error(a);this.yy.parser.parseError(a,b)},setInput:function(a){return this._input=a,this._more=this._backtrack=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},input:function(){var a=this._input[0];this.yytext+=a,this.yyleng++,this.offset++,this.match+=a,this.matched+=a;var b=a.match(/(?:\r\n?|\n).*/g);return b?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),a},unput:function(a){var b=a.length,c=a.split(/(?:\r\n?|\n)/g);this._input=a+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-b-1),this.offset-=b;var d=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),c.length-1&&(this.yylineno-=c.length-1);var e=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:c?(c.length===d.length?this.yylloc.first_column:0)+d[d.length-c.length].length-c[0].length:this.yylloc.first_column-b},this.options.ranges&&(this.yylloc.range=[e[0],e[0]+this.yyleng-b]),this.yyleng=this.yytext.length,this},more:function(){return this._more=!0,this},reject:function(){return this.options.backtrack_lexer?(this._backtrack=!0,this):this.parseError("Lexical error on line "+(this.yylineno+1)+". You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},less:function(a){this.unput(this.match.slice(a))},pastInput:function(){var a=this.matched.substr(0,this.matched.length-this.match.length);return(a.length>20?"...":"")+a.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var a=this.match;return a.length<20&&(a+=this._input.substr(0,20-a.length)),(a.substr(0,20)+(a.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var a=this.pastInput(),b=new Array(a.length+1).join("-");return a+this.upcomingInput()+"\n"+b+"^"},test_match:function(a,b){var c,d,e;if(this.options.backtrack_lexer&&(e={yylineno:this.yylineno,yylloc:{first_line:this.yylloc.first_line,last_line:this.last_line,first_column:this.yylloc.first_column,last_column:this.yylloc.last_column},yytext:this.yytext,match:this.match,matches:this.matches,matched:this.matched,yyleng:this.yyleng,offset:this.offset,_more:this._more,_input:this._input,yy:this.yy,conditionStack:this.conditionStack.slice(0),done:this.done},this.options.ranges&&(e.yylloc.range=this.yylloc.range.slice(0))),d=a[0].match(/(?:\r\n?|\n).*/g),d&&(this.yylineno+=d.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:d?d[d.length-1].length-d[d.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+a[0].length},this.yytext+=a[0],this.match+=a[0],this.matches=a,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._backtrack=!1,this._input=this._input.slice(a[0].length),this.matched+=a[0],c=this.performAction.call(this,this.yy,this,b,this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),c)return c;if(this._backtrack){for(var f in e)this[f]=e[f];return!1}return!1},next:function(){if(this.done)return this.EOF;this._input||(this.done=!0);var a,b,c,d;this._more||(this.yytext="",this.match="");for(var e=this._currentRules(),f=0;fb[0].length)){if(b=c,d=f,this.options.backtrack_lexer){if(a=this.test_match(c,e[f]),a!==!1)return a;if(this._backtrack){b=!1;continue}return!1}if(!this.options.flex)break}return b?(a=this.test_match(b,e[d]),a!==!1?a:!1):""===this._input?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+". Unrecognized text.\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){var a=this.next();return a?a:this.lex()},begin:function(a){this.conditionStack.push(a)},popState:function(){var a=this.conditionStack.length-1;return a>0?this.conditionStack.pop():this.conditionStack[0]},_currentRules:function(){return this.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]?this.conditions[this.conditionStack[this.conditionStack.length-1]].rules:this.conditions.INITIAL.rules},topState:function(a){return a=this.conditionStack.length-1-Math.abs(a||0),a>=0?this.conditionStack[a]:"INITIAL"},pushState:function(a){this.begin(a)},stateStackSize:function(){return this.conditionStack.length},options:{},performAction:function(a,b,c,d){switch(c){case 0:return 29;case 1:return 31;case 2:return"from";case 3:return 24;case 4:return 25;case 5:return 21;case 6:return 19;case 7:return 22;case 8:return 20;case 9:return 26;case 10:return 27;case 11:return 34;case 12:return 36;case 13:return 55;case 14:return 53;case 15:break;case 16:return 49;case 17:return 48;case 18:return 48;case 19:return 40;case 20:return 51;case 21:return 41;case 22:return 11;case 23:return 12;case 24:return 13;case 25:return 38;case 26:return 8;case 27:return 26;case 28:return 27;case 29:return 24;case 30:return 24;case 31:return 25;case 32:return 25;case 33:return 21;case 34:return 22;case 35:return 20;case 36:return 19;case 37:return 34;case 38:return 36;case 39:return 15;case 40:return 17;case 41:return 46;case 42:return 44;case 43:return 42;case 44:return 47;case 45:return 9;case 46:return 5}},rules:[/^(?:\s+in\b)/,/^(?:\s+notIn\b)/,/^(?:\s+from\b)/,/^(?:\s+(eq|EQ)\b)/,/^(?:\s+(neq|NEQ)\b)/,/^(?:\s+(lte|LTE)\b)/,/^(?:\s+(lt|LT)\b)/,/^(?:\s+(gte|GTE)\b)/,/^(?:\s+(gt|GT)\b)/,/^(?:\s+(like|LIKE)\b)/,/^(?:\s+(notLike|NOT_LIKE)\b)/,/^(?:\s+(and|AND)\b)/,/^(?:\s+(or|OR)\b)/,/^(?:\s+null\b)/,/^(?:\s+(true|false)\b)/,/^(?:\s+)/,/^(?:-?[0-9]+(?:\.[0-9]+)?\b)/,/^(?:'[^']*')/,/^(?:"[^"]*")/,/^(?:([a-zA-Z_$][0-9a-zA-Z_$]*))/,/^(?:^\/((?![\s=])[^[\/\n\\]*(?:(?:\\[\s\S]|\[[^\]\n\\]*(?:\\[\s\S][^\]\n\\]*)*])[^[\/\n\\]*)*\/[imgy]{0,4})(?!\w))/,/^(?:\.)/,/^(?:\*)/,/^(?:\/)/,/^(?:\%)/,/^(?:,)/,/^(?:-)/,/^(?:=~)/,/^(?:!=~)/,/^(?:==)/,/^(?:===)/,/^(?:!=)/,/^(?:!==)/,/^(?:<=)/,/^(?:>=)/,/^(?:>)/,/^(?:<)/,/^(?:&&)/,/^(?:\|\|)/,/^(?:\+)/,/^(?:\^)/,/^(?:\()/,/^(?:\])/,/^(?:\[)/,/^(?:\))/,/^(?:!)/,/^(?:$)/],conditions:{INITIAL:{rules:[0,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],inclusive:!0}}};return a}();return b.lexer=c,a.prototype=b,b.Parser=a,new a}();"undefined"!=typeof a&&"undefined"!=typeof c&&(c.parser=e,c.Parser=e.Parser,c.parse=function(){return e.parse.apply(e,arguments)},c.main=function(b){b[1]||(console.log("Usage: "+b[0]+" FILE"),d.exit(1));var e=a("fs").readFileSync(a("path").normalize(b[1]),"utf8");return c.parser.parse(e)},"undefined"!=typeof b&&a.main===b&&c.main(d.argv.slice(1)))},{__browserify_process:68,fs:65,path:66}],41:[function(a,b,c){!function(){"use strict";var b=a("./constraint/parser"),d=a("./nools/nool.parser");c.parseConstraint=function(a){try{return b.parse(a)}catch(c){throw new Error("Invalid expression '"+a+"'")}},c.parseRuleSet=function(a,b){return d.parse(a,b)}}()},{"./constraint/parser":40,"./nools/nool.parser":42}],42:[function(a,b,c){"use strict";var d=a("./tokens.js"),e=a("../../extended"),f=e.hash.keys,g=a("./util.js"),h=function(a,b,c){var d=a;a=a.replace(/\/\/(.*)/g,"").replace(/\n|\r|\r\n/g," ");for(var e,i=new RegExp("^("+f(b).join("|")+")");a&&-1!==(e=g.findNextTokenIndex(a));){a=a.substr(e);var j=a.match(i);if(null===j)throw new Error("Error parsing "+a);if(j=j[1],!(j in b))throw new Error("Unknown token"+j);try{a=b[j](a,c,h).replace(/^\s*|\s*$/g,"")}catch(k){throw new Error("Invalid "+j+" definition \n"+k.message+"; \nstarting at : "+d)}}};c.parse=function(a,b){var c={define:[],rules:[],scope:[],loaded:[],file:b};return h(a,d,c),c}},{"../../extended":12,"./tokens.js":43,"./util.js":44}],43:[function(require,module,exports){var process=require("__browserify_process"),utils=require("./util.js"),fs=require("fs"),extd=require("../../extended"),filter=extd.filter,indexOf=extd.indexOf,predicates=["not","or","exists"],predicateRegExp=new RegExp("^("+predicates.join("|")+") *\\((.*)\\)$","m"),predicateBeginExp=new RegExp(" *("+predicates.join("|")+") *\\(","g"),isWhiteSpace=function(a){return 0===a.replace(/[\s|\n|\r|\t]/g,"").length},joinFunc=function(a,b){return"; "+b},splitRuleLineByPredicateExpressions=function(a){var b=a.replace(/,\s*(\$?\w+\s*:)/g,joinFunc),c=filter(b.split(predicateBeginExp),function(a){return""!==a}),d=c.length,e=[];if(!d)return b;for(var f=0;d>f;f++)-1!==indexOf(predicates,c[f])?e.push([c[f],"(",c[++f].replace(/, *$/,"")].join("")):e.push(c[f].replace(/, *$/,""));return e.join(";")},ruleTokens={salience:function(){var a=/^(salience|priority)\s*:\s*(-?\d+)\s*[,;]?/;return function(b,c){if(a.test(b)){var d=b.match(a),e=parseInt(d[2],10);if(isNaN(e))throw new Error("Invalid salience/priority "+d[2]);return c.options.priority=e,b.replace(d[0],"")}throw new Error("invalid format")}}(),agendaGroup:function(){var a=/^(agenda-group|agendaGroup)\s*:\s*([a-zA-Z_$][0-9a-zA-Z_$]*|"[^"]*"|'[^']*')\s*[,;]?/;return function(b,c){if(a.test(b)){var d=b.match(a),e=d[2];if(!e)throw new Error("Invalid agenda-group "+d[2]);return c.options.agendaGroup=e.replace(/^["']|["']$/g,""),b.replace(d[0],"")}throw new Error("invalid format")}}(),autoFocus:function(){var a=/^(auto-focus|autoFocus)\s*:\s*(true|false)\s*[,;]?/;return function(b,c){if(a.test(b)){var d=b.match(a),e=d[2];if(!e)throw new Error("Invalid auto-focus "+d[2]);return c.options.autoFocus="true"===e?!0:!1,b.replace(d[0],"")}throw new Error("invalid format")}}(),"agenda-group":function(){return this.agendaGroup.apply(this,arguments)},"auto-focus":function(){return this.autoFocus.apply(this,arguments)},priority:function(){return this.salience.apply(this,arguments)},when:function(){var ruleRegExp=/^(\$?\w+) *: *(\w+)(.*)/,constraintRegExp=/(\{ *(?:["']?\$?\w+["']?\s*:\s*["']?\$?\w+["']? *(?:, *["']?\$?\w+["']?\s*:\s*["']?\$?\w+["']?)*)+ *\})/,fromRegExp=/(\bfrom\s+.*)/,parseRules=function(str){for(var rules=[],ruleLines=str.split(";"),l=ruleLines.length,ruleLine,i=0;l>i&&(ruleLine=ruleLines[i].replace(/^\s*|\s*$/g,"").replace(/\n/g,""));i++)if(!isWhiteSpace(ruleLine)){var rule=[];if(predicateRegExp.test(ruleLine)){var m=ruleLine.match(predicateRegExp),pred=m[1].replace(/^\s*|\s*$/g,"");if(rule.push(pred),ruleLine=m[2].replace(/^\s*|\s*$/g,""),"or"===pred){rule=rule.concat(parseRules(splitRuleLineByPredicateExpressions(ruleLine))),rules.push(rule);continue}}var parts=ruleLine.match(ruleRegExp);if(!parts||!parts.length)throw new Error("Invalid constraint "+ruleLine);rule.push(parts[2],parts[1]);var constraints=parts[3].replace(/^\s*|\s*$/g,""),hashParts=constraints.match(constraintRegExp),from=null,fromMatch;if(hashParts){var hash=hashParts[1],constraint=constraints.replace(hash,"");fromRegExp.test(constraint)&&(fromMatch=constraint.match(fromRegExp),from=fromMatch[0],constraint=constraint.replace(fromMatch[0],"")),constraint&&rule.push(constraint.replace(/^\s*|\s*$/g,"")),hash&&rule.push(eval("("+hash.replace(/(\$?\w+)\s*:\s*(\$?\w+)/g,'"$1" : "$2"')+")"))}else constraints&&!isWhiteSpace(constraints)&&(fromRegExp.test(constraints)&&(fromMatch=constraints.match(fromRegExp),from=fromMatch[0],constraints=constraints.replace(fromMatch[0],"")),rule.push(constraints));from&&rule.push(from),rules.push(rule)}return rules};return function(a,b){var c=a.replace(/^when\s*/,"").replace(/^\s*|\s*$/g,"");if("{"===utils.findNextToken(c)){var d=utils.getTokensBetween(c,"{","}",!0).join("");return c=c.replace(d,""),b.constraints=parseRules(d.replace(/^\{\s*|\}\s*$/g,"")),c}throw new Error("unexpected token : expected : '{' found : '"+utils.findNextToken(c)+"'")}}(),then:function(){return function(a,b){if(b.action)throw new Error("action already defined for rule"+b.name);var c=a.replace(/^then\s*/,"").replace(/^\s*|\s*$/g,"");if("{"===utils.findNextToken(c)){var d=utils.getTokensBetween(c,"{","}",!0).join(""); +if(c=c.replace(d,""),b.action||(b.action=d.replace(/^\{\s*|\}\s*$/g,"")),!isWhiteSpace(c))throw new Error("Error parsing then block "+a);return c}throw new Error("unexpected token : expected : '{' found : '"+utils.findNextToken(c)+"'")}}()},topLevelTokens={"/":function(a){return a.match(/^\/\*/)?a.replace(/\/\*.*?\*\//,""):a},define:function(a,b){var c=a.replace(/^define\s*/,""),d=c.match(/^([a-zA-Z_$][0-9a-zA-Z_$]*)/);if(d){if(c=c.replace(d[0],"").replace(/^\s*|\s*$/g,""),"{"===utils.findNextToken(c)){d=d[1];var e=utils.getTokensBetween(c,"{","}",!0).join("");return c=c.replace(e,""),b.define.push({name:d,properties:"("+e+")"}),c}throw new Error("unexpected token : expected : '{' found : '"+utils.findNextToken(c)+"'")}throw new Error("missing name")},"import":function(a,b,c){if("undefined"!=typeof window)throw new Error("import cannot be used in a browser");var d=a.replace(/^import\s*/,"");if("("===utils.findNextToken(d)){var e=utils.getParamList(d);if(d=d.replace(e,"").replace(/^\s*|\s*$/g,""),";"===utils.findNextToken(d)&&(d=d.replace(/\s*;/,"")),e=e.replace(/[\(|\)]/g,"").split(","),1===e.length){if(e=utils.resolve(b.file||process.cwd(),e[0].replace(/["|']/g,"")),-1===indexOf(b.loaded,e)){var f=b.file;b.file=e,c(fs.readFileSync(e,"utf8"),topLevelTokens,b),b.loaded.push(e),b.file=f}return d}throw new Error("import accepts a single file")}throw new Error("unexpected token : expected : '(' found : '"+utils.findNextToken(d)+"'")},global:function(a,b){var c=a.replace(/^global\s*/,""),d=c.match(/^([a-zA-Z_$][0-9a-zA-Z_$]*\s*)/);if(d){if(c=c.replace(d[0],"").replace(/^\s*|\s*$/g,""),"="===utils.findNextToken(c)){d=d[1].replace(/^\s+|\s+$/g,"");var e=utils.getTokensBetween(c,"=",";",!0).join(""),f=e.substring(1,e.length-1);if(f=f.replace(/^\s+|\s+$/g,""),/^require\(/.test(f)){var g=utils.getParamList(f.replace("require")).replace(/[\(|\)]/g,"").split(",");1===g.length&&(g=g[0].replace(/["|']/g,""),f=["require('",utils.resolve(b.file||process.cwd(),g),"')"].join(""))}return b.scope.push({name:d,body:f}),c=c.replace(e,"")}throw new Error("unexpected token : expected : '=' found : '"+utils.findNextToken(c)+"'")}throw new Error("missing name")},"function":function(a,b){var c=a.replace(/^function\s*/,""),d=c.match(/^([a-zA-Z_$][0-9a-zA-Z_$]*)\s*/);if(d){if(c=c.replace(d[0],""),"("===utils.findNextToken(c)){d=d[1];var e=utils.getParamList(c);if(c=c.replace(e,"").replace(/^\s*|\s*$/g,""),"{"===utils.findNextToken(c)){var f=utils.getTokensBetween(c,"{","}",!0).join("");return c=c.replace(f,""),b.scope.push({name:d,body:"function"+e+f}),c}throw new Error("unexpected token : expected : '{' found : '"+utils.findNextToken(c)+"'")}throw new Error("unexpected token : expected : '(' found : '"+utils.findNextToken(c)+"'")}throw new Error("missing name")},rule:function(a,b,c){var d=a.replace(/^rule\s*/,""),e=d.match(/^([a-zA-Z_$][0-9a-zA-Z_$]*|"[^"]*"|'[^']*')/);if(e){if(d=d.replace(e[0],"").replace(/^\s*|\s*$/g,""),"{"===utils.findNextToken(d)){e=e[1].replace(/^["']|["']$/g,"");var f={name:e,options:{},constraints:null,action:null},g=utils.getTokensBetween(d,"{","}",!0).join("");return d=d.replace(g,""),c(g.replace(/^\{\s*|\}\s*$/g,""),ruleTokens,f),b.rules.push(f),d}throw new Error("unexpected token : expected : '{' found : '"+utils.findNextToken(d)+"'")}throw new Error("missing name")}};module.exports=topLevelTokens},{"../../extended":12,"./util.js":44,__browserify_process:68,fs:65}],44:[function(a,b,c){var d=a("__browserify_process"),e=a("path"),f=/[\s|\n|\r|\t]/,g=e.sep||("win32"===d.platform?"\\":"/"),h={"{":"}","}":"{","(":")",")":"(","[":"]"},i=c.getTokensBetween=function(a,b,c,d){var e=0,f=[];b||(b=h[c],e=1),c||(c=h[b]),a=Object(a);for(var g,i=!1,j=0,k=!1;g=a.charAt(j++);)if(g===b)e++,i?f.push(g):(i=!0,d&&f.push(g));else if(g===c&&j){if(e--,0===e){d&&f.push(g),k=!0;break}f.push(g)}else i&&f.push(g);if(!k)throw new Error("Unable to match "+b+" in "+a);return f};c.getParamList=function(a){return i(a,"(",")",!0).join("")},c.resolve=function(a,b){return""!==e.extname(a)&&(a=e.dirname(a)),1===b.split(g).length?b:e.resolve(a,b)};var j=c.findNextTokenIndex=function(a,b,c){b=b||0,c=c||a.length;var d=-1,e=a.length;for((!c||c>e)&&(c=e);c>b;b++){var g=a.charAt(b);if(!f.test(g)){d=b;break}}return d};c.findNextToken=function(a,b,c){return a.charAt(j(a,b,c))}},{__browserify_process:68,path:66}],45:[function(a,b,c){"use strict";var d=a("./extended"),e=d.isEmpty,f=d.merge,g=d.forEach,h=d.declare,i=a("./constraintMatcher"),j=a("./constraint"),k=j.EqualityConstraint,l=j.FromConstraint,m=0,n=h({}),o=n.extend({instance:{constructor:function(a,b,c,d,h){h=h||{},this.id=m++,this.type=a,this.alias=b,this.conditions=c,this.pattern=h.pattern;var k=[new j.ObjectConstraint(a)],l=i.toConstraints(c,f({alias:b},h));if(l.length)k=k.concat(l);else{var n=new j.TrueConstraint;k.push(n)}if(d&&!e(d)){var o=new j.HashConstraint(d);k.push(o)}g(k,function(a){a.set("alias",b)}),this.constraints=k},getSpecificity:function(){for(var a=this.constraints,b=0,c=0,d=a.length;d>c;c++)a[c]instanceof k&&b++;return b},hasConstraint:function(a){return d.some(this.constraints,function(b){return b instanceof a})},hashCode:function(){return[this.type,this.alias,d.format("%j",this.conditions)].join(":")},toString:function(){return d.format("%j",this.constraints)}}}).as(c,"ObjectPattern"),p=o.extend({instance:{constructor:function(a,b,c,d,e,f){this._super([a,b,c,d,f]),this.from=new l(e,f)},hasConstraint:function(a){return d.some(this.constraints,function(b){return b instanceof a})},getSpecificity:function(){return this._super(arguments)+1},hashCode:function(){return[this.type,this.alias,d.format("%j",this.conditions),this.from.from].join(":")},toString:function(){return d.format("%j from %s",this.constraints,this.from.from)}}}).as(c,"FromPattern");p.extend().as(c,"FromNotPattern"),o.extend().as(c,"NotPattern"),o.extend().as(c,"ExistsPattern"),p.extend().as(c,"FromExistsPattern"),n.extend({instance:{constructor:function(a,b){this.id=m++,this.leftPattern=a,this.rightPattern=b},hashCode:function(){return[this.leftPattern.hashCode(),this.rightPattern.hashCode()].join(":")},getSpecificity:function(){return this.rightPattern.getSpecificity()+this.leftPattern.getSpecificity()},getters:{constraints:function(){return this.leftPattern.constraints.concat(this.rightPattern.constraints)}}}}).as(c,"CompositePattern");var q=h({instance:{constructor:function(){this.id=m++,this.recency=0}}}).as(c,"InitialFact");o.extend({instance:{constructor:function(){this._super([q,"__i__",[],{}])},assert:function(){return!0}}}).as(c,"InitialFactPattern")},{"./constraint":8,"./constraintMatcher":9,"./extended":12}],46:[function(a,b,c){"use strict";function d(a,b,c,d){f(b)?(d=c,c=b):b=b||{};var g=e.every(c,function(a){return f(a)});g&&1===c.length&&(c=c[0],g=!1);var h=[],i=b.scope||{};if(c.scope=i,g){for(var j,k=function(a,b){m[b]?e(m).forEach(function(b){b.push(a)}):(m[b]=0===b?[]:m[b-1].slice(),0!==b&&m[b].pop(),m[b].push(a))},l=c.length,m=[],n=0;l>n;n++)j=c[n],j.scope=i,e.forEach(y(j),k);h=e.map(m,function(c){for(var e=null,f=0;f>>0;if(0===d)return-1;var e=d;arguments.length>2&&(e=Number(arguments[2]),e!==e?e=0:0!==e&&e!==1/0&&e!==-(1/0)&&(e=(e>0||-1)*P(Q(e))));for(var f=e>=0?R(e,d-1):d-Q(e);f>=0;f--)if(f in c&&c[f]===b)return f;return-1}function i(a,b,c){if(a&&X&&X===a.filter)return a.filter(b,c);if(!N(a)||"function"!=typeof b)throw new TypeError;for(var d=Object(a),e=d.length>>>0,f=[],g=0;e>g;g++)if(g in d){var h=d[g];b.call(c,h,g,d)&&f.push(h)}return f}function j(a,b,c){if(!N(a)||"function"!=typeof b)throw new TypeError;if(a&&T&&T===a.forEach)return a.forEach(b,c),a;for(var d=0,e=a.length;e>d;++d)b.call(c||a,a[d],d,a);return a}function k(a,b,c){if(a&&Y&&Y===a.every)return a.every(b,c);if(!N(a)||"function"!=typeof b)throw new TypeError;for(var d=Object(a),e=d.length>>>0,f=0;e>f;f++)if(f in d&&!b.call(c,d[f],f,d))return!1;return!0}function l(a,b,c){if(a&&Z&&Z===a.some)return a.some(b,c);if(!N(a)||"function"!=typeof b)throw new TypeError;for(var d=Object(a),e=d.length>>>0,f=0;e>f;f++)if(f in d&&b.call(c,d[f],f,d))return!0;return!1}function m(a,b,c){if(a&&U&&U===a.map)return a.map(b,c);if(!N(a)||"function"!=typeof b)throw new TypeError;for(var d=Object(a),e=d.length>>>0,f=[],g=0;e>g;g++)g in d&&f.push(b.call(c,d[g],g,d));return f}function n(a,b,c){var d=arguments.length>2;if(a&&V&&V===a.reduce)return d?a.reduce(b,c):a.reduce(b);if(!N(a)||"function"!=typeof b)throw new TypeError;var e=0,f=a.length>>0;if(arguments.length<3){if(0===f)throw new TypeError("Array length is 0 and no second argument");c=a[0],e=1}else c=arguments[2];for(;f>e;)e in a&&(c=b.call(void 0,c,a[e],e,a)),++e;return c}function o(a,b,c){var d=arguments.length>2;if(a&&W&&W===a.reduceRight)return d?a.reduceRight(b,c):a.reduceRight(b);if(!N(a)||"function"!=typeof b)throw new TypeError;var e=Object(a),f=e.length>>>0;if(0===f&&2===arguments.length)throw new TypeError;var g=f-1;if(arguments.length>=3)c=arguments[2];else for(;;)if(g in a){c=a[g--];break}for(;g>=0;)g in e&&(c=b.call(void 0,c,e[g],g,e)),g--;return c}function p(a){var c=[];if(null!==a){var d=$(arguments);if(1===d.length)if(N(a))c=a;else if(b.isHash(a))for(var e in a)a.hasOwnProperty(e)&&c.push([e,a[e]]);else c.push(a);else j(d,function(a){c=c.concat(p(a))})}return c}function q(a){return a=a||[],a.length?n(a,function(a,b){return a+b}):0}function r(a){if(a=a||[],a.length){var c=q(a);if(b.isNumber(c))return c/a.length;throw new Error("Cannot average an array of non numbers.")}return 0}function s(a,b){return _(a,b)}function t(a,b){return _(a,b)[0]}function u(a,b){return _(a,b)[a.length-1]}function v(a){var b=a,c=J($(arguments,1));return N(a)&&(b=i(a,function(a){return-1===g(c,a)})),b}function w(a){var b,c=[],d=-1,e=0;if(a)for(b=a.length;++d0?(c.push(c.shift()),b--):(c.unshift(c.pop()),b++),y(c,b)):c}function z(a,b){var c=[];if(N(a)){var d=a.slice(0);"number"!=typeof b&&(b=a.length),b?b<=a.length&&(c=n(a,function(a,c,f){var g;return g=b>1?e(c,y(d,f).slice(1),b):[[c]],a.concat(g)},[])):c=[[]]}return c}function A(){var a=[],c=$(arguments);if(c.length>1){var d=c.shift();N(d)&&(a=n(d,function(a,d,e){for(var f=[d],g=0;gd;d++)c.push(a[b[d]]||null);return c}function D(){var a=[],b=$(arguments);if(b.length>1){for(var c=0,d=b.length;d>c;c++)a=a.concat(b[c]);a=w(a)}return a}function E(){var a,b,c=[],d=-1;if(a=arguments.length>1?$(arguments):arguments[0],N(a))for(c=a[0],d=0,b=a.length;++d1?c:p(a),n(b,function(a,b){return a.concat(b)},[])}function K(a,b){b=b.split(".");var c=a.slice(0);return j(b,function(a){var b=a.match(/(\w+)\(\)$/);c=m(c,function(c){return b?c[b[1]]():c[a]})}),c}function L(a,b,c){return c=$(arguments,2),m(a,function(a){var d=M(b)?a[b]:b;return d.apply(a,c)})}var M=b.isString,N=Array.isArray||b.isArray,O=b.isDate,P=Math.floor,Q=Math.abs,R=(Math.max,Math.min),S=Array.prototype,T=(S.indexOf,S.forEach),U=S.map,V=S.reduce,W=S.reduceRight,X=S.filter,Y=S.every,Z=S.some,$=c.argsToArray,_=function(){var a=function(a,b){return k(a,b)},b=function(a,b){return a-b},c=function(a,b){return a.getTime()-b.getTime()};return function(d,e){var f=[];return N(d)&&(f=d.slice(),e?"function"==typeof e?f.sort(e):f.sort(function(a,b){var c=a[e],d=b[e];return M(c)&&M(d)?c>d?1:d>c?-1:0:O(c)&&O(d)?c.getTime()-d.getTime():c-d}):a(f,M)?f.sort():a(f,O)?f.sort(c):f.sort(b)),f}}(),ab={toArray:p,sum:q,avg:r,sort:s,min:t,max:u,difference:v,removeDuplicates:w,unique:x,rotate:y,permutations:z,zip:A,transpose:B,valuesAt:C,union:D,intersect:E,powerSet:F,cartesian:G,compact:H,multiply:I,flatten:J,pluck:K,invoke:L,forEach:j,map:m,filter:i,reduce:n,reduceRight:o,some:l,every:k,indexOf:g,lastIndexOf:h};return a.define(N,ab).expose(ab)}"undefined"!=typeof c?"undefined"!=typeof b&&b.exports&&(b.exports=d(a("extended"),a("is-extended"),a("arguments-extended"))):"function"==typeof define&&define.amd?define(["extended","is-extended","arguments-extended"],function(a,b,c){return d(a,b,c)}):this.arrayExtended=d(this.extended,this.isExtended,this.argumentsExtended)}.call(this)},{"arguments-extended":48,extended:53,"is-extended":70}],50:[function(a,b,c){!function(){"use strict";function d(a,b,c){function d(a,b,c,d){a=""+a,c=c||" ";for(var e=a.length;b>e;)d?a+=c:a=c+a,e++;return a}function e(a,c,d){var f=a;if(b.isString(f)){if(a.length>c)if(d){var g=a.length;f=a.substring(g-c,g)}else f=a.substring(0,c)}else f=e(""+f,c);return f}function f(a,c,d){if(!b.isArray(a)||"function"!=typeof c)throw new TypeError;for(var e=Object(a),f=e.length>>>0,g=0;f>g;g++)if(g in e&&!c.call(d,e[g],g,e))return!1;return!0}function g(a,b){return A.difference(new Date(a.getFullYear(),0,1,a.getHours()),a,null,b)+1}function h(a,b,c){b=b||0;var d=a[c?"getUTCFullYear":"getFullYear"](),e=new Date(d,0,1).getDay(),f=(e-b+7)%7,h=o((g(a)+f-1)/7);return e===b&&h++,h}function i(a){var b=a.toString(),c="",d=b.indexOf("(");return d>-1&&(c=b.substring(++d,b.indexOf(")"))),c}function j(a,b){return a.replace(/([a-z])\1*/gi,function(a){var c,d=a.charAt(0),e=a.length,f="0?",g="0{0,2}";if("y"===d)c="\\d{2,4}";else if("M"===d)c=e>2?"\\S+?":"1[0-2]|"+f+"[1-9]";else if("D"===d)c="[12][0-9][0-9]|3[0-5][0-9]|36[0-6]|"+g+"[1-9][0-9]|"+f+"[1-9]";else if("d"===d)c="3[01]|[12]\\d|"+f+"[1-9]";else if("w"===d)c="[1-4][0-9]|5[0-3]|"+f+"[1-9]";else if("E"===d)c="\\S+";else if("h"===d)c="1[0-2]|"+f+"[1-9]";else if("K"===d)c="1[01]|"+f+"\\d";else if("H"===d)c="1\\d|2[0-3]|"+f+"\\d";else if("k"===d)c="1\\d|2[0-4]|"+f+"[1-9]";else if("m"===d||"s"===d)c="[0-5]\\d";else if("S"===d)c="\\d{"+e+"}";else if("a"===d){var h="AM",i="PM";c=h+"|"+i,h!==h.toLowerCase()&&(c+="|"+h.toLowerCase()),i!==i.toLowerCase()&&(c+="|"+i.toLowerCase()),c=c.replace(/\./g,"\\.")}else c="v"===d||"z"===d||"Z"===d||"G"===d||"q"===d||"Q"===d?".*":" "===d?"\\s*":d+"*";return b&&b.push(a),"("+c+")"}).replace(/[\xa0 ]/g,"[\\s\\xa0]")}function k(a){B[a+"sFromNow"]=function(b){return A.add(new Date,a,b)},B[a+"sAgo"]=function(b){return A.add(new Date,a,-b)}}for(var l=function(){function a(a,b,c){return a=a.replace(/s$/,""),e.hasOwnProperty(a)?e[a](b,c):[c,"UTC"+a.charAt(0).toUpperCase()+a.substring(1)+"s",!1]}function b(a,b,c,e){return a=a.replace(/s$/,""),d(f[a](b,c,e))}var c=Math.floor,d=Math.round,e={day:function(a,b){return[b,"Date",!1]},weekday:function(a,b){var c,d,e=b%5,f=a.getDay(),g=0;e?(c=e,d=parseInt(b/5,10)):(c=b>0?5:-5,d=b>0?(b-5)/5:(b+5)/5),6===f&&b>0?g=1:0===f&&0>b&&(g=-1);var h=f+c;return(0===h||6===h)&&(g=b>0?2:-2),[7*d+c+g,"Date",!1]},year:function(a,b){return[b,"FullYear",!0]},week:function(a,b){return[7*b,"Date",!1]},quarter:function(a,b){return[3*b,"Month",!0]},month:function(a,b){return[b,"Month",!0]}},f={quarter:function(a,b,d){var e=b.getFullYear()-a.getFullYear(),f=a[d?"getUTCMonth":"getMonth"](),g=b[d?"getUTCMonth":"getMonth"](),h=c(f/3)+1,i=c(g/3)+1;return i+=4*e,i-h},weekday:function(a,c,d){var e,f=b("day",a,c,d),g=f%7;if(0===g)f=5*b("week",a,c,d);else{var h=0,i=a[d?"getUTCDay":"getDay"](),j=c[d?"getUTCDay":"getDay"]();e=parseInt(f/7,10);var k=new Date(+a);k.setDate(k[d?"getUTCDate":"getDate"]()+7*e);var l=k[d?"getUTCDay":"getDay"]();f>0?6===i||6===j?h=-1:0===i?h=0:(0===j||l+g>5)&&(h=-2):0>f&&(6===i?h=0:0===i||0===j?h=1:(6===j||0>l+g)&&(h=2)),f+=h,f-=2*e}return f},year:function(a,b){return b.getFullYear()-a.getFullYear()},month:function(a,b,c){var d=a[c?"getUTCMonth":"getMonth"](),e=b[c?"getUTCMonth":"getMonth"]();return e-d+12*(b.getFullYear()-a.getFullYear())},week:function(a,c,e){return d(b("day",a,c,e)/7)},day:function(a,b){return 1.1574074074074074e-8*(b.getTime()-a.getTime())},hour:function(a,b){return 2.7777777777777776e-7*(b.getTime()-a.getTime())},minute:function(a,b){return 16666666666666667e-21*(b.getTime()-a.getTime())},second:function(a,b){return.001*(b.getTime()-a.getTime())},millisecond:function(a,b){return b.getTime()-a.getTime()}};return{addTransform:a,differenceTransform:b}}(),m=l.addTransform,n=l.differenceTransform,o=Math.floor,p=Math.round,q=Math.min,r=Math.pow,s=Math.ceil,t=Math.abs,u=["January","February","March","April","May","June","July","August","September","October","November","December"],v=["Jan.","Feb.","Mar.","Apr.","May.","Jun.","Jul.","Aug.","Sep.","Oct.","Nov.","Dec."],w=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],x=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],y=["Before Christ","Anno Domini"],z=["BC","AD"],A={getDaysInMonth:function(a){var b=a.getMonth(),c=[31,28,31,30,31,30,31,31,30,31,30,31];return 1===b&&A.isLeapYear(a)?29:c[b]},isLeapYear:function(a,b){var c=a[b?"getUTCFullYear":"getFullYear"]();return 0===c%400||0===c%4&&0!==c%100},isWeekend:function(a,b){var c=(a||new Date)[b?"getUTCDay":"getDay"]();return 0===c||6===c},getTimezoneName:i,compare:function(a,b,c){return a=new Date(+a),b=new Date(+(b||new Date)),"date"===c?(a.setHours(0,0,0,0),b.setHours(0,0,0,0)):"time"===c&&(a.setFullYear(0,0,0),b.setFullYear(0,0,0)),a>b?1:b>a?-1:0},add:function(a,b,c){var d=m(b,a,c||0);c=d[0];var e=d[1],f=new Date(+a),g=d[2];return e&&f["set"+e](f["get"+e]()+c),g&&f.getDate()E?z:y)[0>f?0:1];else if("y"===D)B=f,E>1&&(2===E?B=e(""+B,2,!0):C=!0);else if("Q"===D.toUpperCase())B=s((j+1)/3),C=!0;else if("M"===D)3>E?(B=j+1,C=!0):B=(3===E?v:u)[j];else if("w"===D)B=h(a,0,c),C=!0;else if("D"===D)B=g(a,c),C=!0;else if("E"===D)3>E?(B=k+1,C=!0):B=(-3===E?x:w)[k];else if("a"===D)B=12>m?"AM":"PM";else if("h"===D)B=m%12||12,C=!0;else if("K"===D)B=m%12,C=!0;else if("k"===D)B=m||24,C=!0;else if("S"===D)B=p(A*r(10,E-3)),C=!0;else if("z"===D||"v"===D||"Z"===D){if(B=i(a),"z"!==D&&"v"!==D||B||(E=4),!B||"Z"===D){var F=a.getTimezoneOffset(),G=[F>=0?"-":"+",d(o(t(F)/60),2,"0"),d(t(F)%60,2,"0")];4===E&&(G.splice(0,0,"GMT"),G.splice(3,0,":")),B=G.join("")}}else B=b;else B=""+n,C=!0;else B=""+m,C=!0;return C&&(B=d(B,E,"0")),B})}},B={},C=["year","month","day","hour","minute","second"],D=0,E=C.length;E>D;D++)k(C[D]);var F={parseDate:function(a,b){if(!b)throw new Error("format required when calling dateExtender.parse");var d=[],e=j(b,d),g=new RegExp("^"+e+"$","i"),h=g.exec(a);if(!h)return null;var i=[1970,0,1,0,0,0,0],k="",l=f(h,function(a,b){if(b){var e=d[b-1],f=e.length,g=e.charAt(0);if("y"===g)if(100>a){a=parseInt(a,10);var h=""+(new Date).getFullYear(),j=100*h.substring(0,2),l=q(h.substring(2,4)+20,99);i[0]=l>a?j+a:j-100+a}else i[0]=a;else if("M"===g){if(f>2){var m,n,o=u;3===f&&(o=v),a=a.replace(".","").toLowerCase();var p=!1;for(m=0,n=o.length;n>m&&!p;m++){var r=o[m].replace(".","").toLocaleLowerCase();r===a&&(a=m,p=!0)}if(!p)return!1}else a--;i[1]=a}else if("E"===g||"e"===g){var s=w;3===f&&(s=x),a=a.toLowerCase(),s=c.map(s,function(a){return a.toLowerCase()});var t=c.indexOf(s,a);if(-1===t){if(a=parseInt(a,10),isNaN(a)||a>s.length)return!1}else a=t}else if("D"===g||"d"===g)"D"===g&&(i[1]=0),i[2]=a;else if("a"===g){var y="am",z="pm",A=/\./g;a=a.replace(A,"").toLowerCase(),k=a===z?"p":a===y?"a":""}else"k"===g||"h"===g||"H"===g||"K"===g?("k"===g&&24===+a&&(a=0),i[3]=a):"m"===g?i[4]=a:"s"===g?i[5]=a:"S"===g&&(i[6]=a)}return!0});if(l){var m=+i[3];"p"===k&&12>m?i[3]=m+12:"a"===k&&12===m&&(i[3]=0);var n=new Date(i[0],i[1],i[2],i[3],i[4],i[5],i[6]),o=-1!==c.indexOf(d,"d"),p=-1!==c.indexOf(d,"M"),r=i[1],s=i[2],t=n.getMonth(),y=n.getDate();return p&&t>r||o&&y>s?null:n}return null}},G=a.define(b.isDate,A).define(b.isString,F).define(b.isNumber,B);for(D in A)A.hasOwnProperty(D)&&(G[D]=A[D]);for(D in F)F.hasOwnProperty(D)&&(G[D]=F[D]);for(D in B)B.hasOwnProperty(D)&&(G[D]=B[D]);return G}"undefined"!=typeof c?"undefined"!=typeof b&&b.exports&&(b.exports=d(a("extended"),a("is-extended"),a("array-extended"))):"function"==typeof define&&define.amd?define(["extended","is-extended","array-extended"],function(a,b,c){return d(a,b,c)}):this.dateExtended=d(this.extended,this.isExtended,this.arrayExtended)}.call(this)},{"array-extended":49,extended:53,"is-extended":70}],51:[function(a,b,c){!function(){function a(){function a(a,b){return b=b||0,x.call(a,b)}function b(a){return"[object Array]"===Object.prototype.toString.call(a)}function c(a){var b;return null!==a&&a!==b&&"object"==typeof a}function d(a){var b=c(a);return b&&a.constructor===Object}function e(a,b){if(a&&a.length)for(var c=0,d=a.length;d>c;c++)if(a[c]===b)return c;return-1}function f(a,b,c){var d,f;for(d in b)b.hasOwnProperty(d)&&-1===e(c,d)&&(f=b[d],d in a&&a[d]===f||(a[d]=f));return a}function g(a){var c=this.__meta,d=c.supers,e=d.length,f=c.superMeta,g=f.pos;if(e>g){a=a?B(a)||b(a)?a:[a]:[];var h,i=f.name,j=f.f;do if(h=d[g][i],"function"==typeof h&&(h=h._f||h)!==j)return f.pos=1+g,h.apply(this,a);while(e>++g)}return null}function h(){var a=this.__meta,b=a.supers,c=b.length,d=a.superMeta,e=d.pos;if(c>e){var f,g=d.name,h=d.f;do if(f=b[e][g],"function"==typeof f&&(f=f._f||f)!==h)return d.pos=1+e,f.bind(this);while(c>++e)}return null}function i(a){var b=this.__getters__;return b.hasOwnProperty(a)?b[a].apply(this):this[a]}function j(b,c){var e=this.__setters__;if(!d(b))return e.hasOwnProperty(b)?e[b].apply(this,a(arguments,1)):this[b]=c;for(var f in b){var g=b[f];e.hasOwnProperty(f)?e[b].call(this,g):this[f]=g}}function k(){var a=this.__meta||{},b=a.supers,c=b.length,d=a.superMeta,e=d.pos;if(c>e){var f,g=d.name,h=d.f;do if(f=b[e][g],"function"==typeof f&&(f=f._f||f)!==h)return d.pos=1+e,f.apply(this,arguments);while(c>++e)}return null}function l(a,b){if(a.toString().match(A)){var c=function(){var c,d=this.__meta||{},e=d.superMeta;switch(d.superMeta={f:a,pos:0,name:b},arguments.length){case 0:c=a.call(this);break;case 1:c=a.call(this,arguments[0]);break;case 2:c=a.call(this,arguments[0],arguments[1]);break;case 3:c=a.call(this,arguments[0],arguments[1],arguments[2]);break;default:c=a.apply(this,arguments)}return d.superMeta=e,c};return c._f=a,c}return a._f=a,a}function m(a,b){var c=b.setters||{},d=a.__setters__,e=a.__getters__;for(var f in c)d.hasOwnProperty(f)||(d[f]=c[f]);c=b.getters||{};for(f in c)e.hasOwnProperty(f)||(e[f]=c[f]);for(var g in b)if("getters"!==g&&"setters"!==g){var h=b[g];"function"==typeof h?a.hasOwnProperty(g)||(a[g]=l(k,g)):a[g]=h}}function n(){for(var b=a(arguments),c=b.length,d=this.prototype,e=d.__meta,f=this.__meta,g=d.__meta.bases,h=g.slice(),i=f.supers||[],j=e.supers||[],k=0;c>k;k++){var l=b[k],n=l.prototype,p=n.__meta,q=l.__meta;!p&&(p=n.__meta={proto:n||{}}),!q&&(q=l.__meta={proto:l.__proto__||{}}),m(d,p.proto||{}),m(this,q.proto||{}),o(l.prototype,j,g),o(l,i,h)}return this}function o(a,b,c){var d=a.__meta;!d&&(d=a.__meta={});var f=a.__meta.unique;if(!f&&(d.unique="declare"+ ++y),-1===e(c,f)){c.push(f);for(var g=a.__meta.supers||[],h=g.length-1||0;h>=0;)o(g[h--],b,c);b.unshift(a)}}function p(a,b){var c=b.setters,d=a.__setters__,e=a.__getters__;if(c)for(var f in c)d[f]=c[f];if(c=b.getters||{})for(f in c)e[f]=c[f];for(f in b)if("getters"!=f&&"setters"!=f){var g=b[f];if("function"==typeof g){var h=g.__meta||{};a[f]=h.isConstructor?g:l(g,f)}else a[f]=g}}function q(a,b){return a&&b?a[b]=this:a.exports=a=this,this}function r(a){return u(this,a)}function s(a){z.prototype=a.prototype;var b=new z;return z.prototype=null,b}function t(a,c,e){var i={},j=[],m="declare"+ ++y,q=[],r=[],t=[],u=[],v={supers:t,unique:m,bases:q,superMeta:{f:null,pos:0,name:null}},x={supers:u,unique:m,bases:r,isConstructor:!0,superMeta:{f:null,pos:0,name:null}};if(d(c)&&!e&&(e=c,c=w),"function"==typeof c||b(c)?(j=b(c)?c:[c],c=j.shift(),a.__meta=x,i=s(c),i.__meta=v,i.__getters__=f({},i.__getters__||{}),i.__setters__=f({},i.__setters__||{}),a.__getters__=f({},a.__getters__||{}),a.__setters__=f({},a.__setters__||{}),o(c.prototype,t,q),o(c,u,r)):(a.__meta=x,i.__meta=v,i.__getters__=i.__getters__||{},i.__setters__=i.__setters__||{},a.__getters__=a.__getters__||{},a.__setters__=a.__setters__||{}),a.prototype=i,e){var z=v.proto=e.instance||{},A=x.proto=e.static||{};A.init=A.init||k,p(i,z),p(a,A),i.constructor=z.hasOwnProperty("constructor")?l(z.constructor,"constructor"):z.constructor=l(k,"constructor")}else v.proto={},x.proto={},a.init=l(k,"init"),i.constructor=l(k,"constructor");j.length&&n.apply(a,j),c&&f(a,f(f({},c),a)),i._super=a._super=g,i._getSuper=a._getSuper=h,i._static=a}function u(a,b){function c(){switch(arguments.length){case 0:this.constructor.call(this);break;case 1:this.constructor.call(this,arguments[0]);break;case 2:this.constructor.call(this,arguments[0],arguments[1]);break;case 3:this.constructor.call(this,arguments[0],arguments[1],arguments[2]);break;default:this.constructor.apply(this,arguments)}}return t(c,a,b),c.init()||c}function v(a,b){function c(){return d||(this.constructor.apply(this,arguments),d=this),d}var d;return t(c,a,b),c.init()||c}var w,x=Array.prototype.slice,y=0,z=new Function,A=/(super)/g,B=function(a){return"[object Arguments]"===Object.prototype.toString.call(a)};return B(arguments)||(B=function(a){return!(!a||!a.hasOwnProperty("callee"))}),w=u({instance:{get:i,set:j},"static":{get:i,set:j,mixin:n,extend:r,as:q}}),u.singleton=v,u}"undefined"!=typeof c?"undefined"!=typeof b&&b.exports&&(b.exports=a()):"function"==typeof define&&define.amd?define(a):this.declare=a()}()},{}],52:[function(a,b){b.exports=a("./declare.js")},{"./declare.js":51}],53:[function(a,b,c){!function(){"use strict";function d(a){function b(){var b=a.define(); +return b.expose({register:function(a,c){c||(c=a,a=null);var d=typeof c;if(a)b[a]=c;else if(c&&"function"===d)b.extend(c);else{if("object"!==d)throw new TypeError("extended.register must be called with an extender function");b.expose(c)}return b},define:function(){return a.define.apply(a,arguments)}}),b}function c(){return b()}return function(){function a(a,b){var c,d;for(c in b)b.hasOwnProperty(c)&&(d=b[c],c in a&&a[c]===d||(a[c]=d));return a}return function(b){b||(b={});for(var c=1,d=arguments.length;d>c;c++)a(b,arguments[c]);return b}}(),c.define=function(){return a.define.apply(a,arguments)},c}"undefined"!=typeof c?"undefined"!=typeof b&&b.exports&&(b.exports=d(a("extender"))):"function"==typeof define&&define.amd?define(["extender"],function(a){return d(a)}):this.extended=d(this.extender)}.call(this)},{extender:55}],54:[function(a,b,c){!function(){function d(a){function b(a,b){if(a&&a.length)for(var c=0,d=a.length;d>c;c++)if(a[c]===b)return c;return-1}function c(a){return"[object Array]"===Object.prototype.toString.call(a)}function d(b){function c(a,b,c){if("function"!=typeof c)throw new TypeError("when extending type you must provide a function");var d;d="constructor"===b?function(){this._super(arguments),c.apply(this,arguments)}:function(){var a=f.call(arguments);a.unshift(this._value);var b=c.apply(this,a);return b!==e?this.__extender__(b):this},a[b]=d}function d(a,b,c){if("function"!=typeof c)throw new TypeError("when extending type you must provide a function");var d;d="constructor"===b?function(){this._super(arguments),c.apply(this,arguments)}:function(){var a=f.call(arguments);return a.unshift(this._value),c.apply(this,a)},a[b]=d}function h(a,b,e){for(var f in b)b.hasOwnProperty(f)&&("getters"!==f&&"setters"!==f?"noWrap"===f?h(a,b[f],!0):e?d(a,f,b[f]):c(a,f,b[f]):a[f]=b[f])}function i(a){var b,c,d=a;if(!(a instanceof m)){var e=m;for(b=0,c=n.length;c>b;b++){var f=n[b];f[0](a)&&(e=e.extend({instance:f[1]}))}d=new e(a),d.__extender__=i}return d}function j(){return!0}function k(a,b){if(arguments.length){"object"==typeof a&&(b=a,a=j),b=b||{};var d={};h(d,b),d.hasOwnProperty("constructor")||(b.hasOwnProperty("constructor")?c(d,"constructor",b.constructor):d.constructor=function(){this._super(arguments)}),n.push([a,d])}return i}function l(a){return a&&a.hasOwnProperty("__defined__")&&(i.__defined__=n=n.concat(a.__defined__)),g(i,a,["define","extend","expose","__defined__"]),i}b=b||[];var m=a({instance:{constructor:function(a){this._value=a},value:function(){return this._value},eq:function(a){return this.__extender__(this._value===a)},neq:function(a){return this.__extender__(this._value!==a)},print:function(){return console.log(this._value),this}}}),n=[];return i.define=k,i.extend=l,i.expose=function(){for(var a,b=0,c=arguments.length;c>b;b++)a=arguments[b],"object"==typeof a&&g(i,a,["define","extend","expose","__defined__"]);return i},i.__defined__=n,i}var e,f=Array.prototype.slice,g=function(){function a(a,c,d){var e,f;for(e in c)c.hasOwnProperty(e)&&-1===b(d,e)&&(f=c[e],e in a&&a[e]===f||(a[e]=f));return a}return function(b){b||(b={});var d=arguments.length,e=arguments[arguments.length-1];c(e)?d--:e=[];for(var f=1;d>f;f++)a(b,arguments[f],e);return b}}();return{define:function(){return d().define.apply(d,arguments)},extend:function(a){return d().define().extend(a)}}}"undefined"!=typeof c?"undefined"!=typeof b&&b.exports&&(b.exports=d(a("declare.js"))):"function"==typeof define&&define.amd?define(["declare"],function(a){return d(a)}):this.extender=d(this.declare)}.call(this)},{"declare.js":52}],55:[function(a,b){b.exports=a("./extender.js")},{"./extender.js":54}],56:[function(a,b,c){!function(){"use strict";function d(a,b,c){function d(a,b,c){var d;switch((b||[]).length){case 0:d=a.call(c);break;case 1:d=a.call(c,b[0]);break;case 2:d=a.call(c,b[0],b[1]);break;case 3:d=a.call(c,b[0],b[1],b[2]);break;default:d=a.apply(c,b)}return d}function e(a,b,c){if(c=p(arguments,2),n(b)&&!(b in a))throw new Error(b+" property not defined in scope");if(!n(b)&&!o(b))throw new Error(b+" is not a function");return n(b)?function(){var d=a[b];if(o(d)){var e=c.concat(p(arguments));return d.apply(a,e)}return d}:c.length?function(){return c.concat(p(arguments)),d(b,arguments,a)}:function(){return d(b,arguments,a)}}function f(a,b){if(b=p(arguments,1),!n(a)&&!o(a))throw new Error(a+" must be the name of a property or function to execute");return n(a)?function(){var c=p(arguments),d=c.shift(),e=d[a];return o(e)?(c=b.concat(c),e.apply(d,c)):e}:function(){var c=p(arguments),d=c.shift();return c=b.concat(c),a.apply(d,c)}}function g(a,b,c){if(c=p(arguments,2),n(b)&&!(b in a))throw new Error(b+" property not defined in scope");if(!n(b)&&!o(b))throw new Error(b+" is not a function");return n(b)?function(){var d=a[b];return o(d)?d.apply(a,c):d}:function(){return b.apply(a,c)}}function h(a){var b=p(arguments,1);if(!m(a)&&!o(a))throw new TypeError("scope must be an object");if(1===b.length&&l(b[0])&&(b=b[0]),!b.length){b=[];for(var c in a)a.hasOwnProperty(c)&&o(a[c])&&b.push(c)}for(var d=0,f=b.length;f>d;d++)a[b[d]]=e(a,a[b[d]]);return a}function i(a,b){if(b=p(arguments,1),!n(a)&&!o(a))throw new Error(a+" must be the name of a property or function to execute");return n(a)?function(){var c=this[a];if(o(c)){var d=b.concat(p(arguments));return c.apply(this,d)}return c}:function(){var c=b.concat(p(arguments));return a.apply(this,c)}}function j(a,b){return function(){var c=p(arguments);return b?a.apply(this,arguments):function(){return a.apply(this,c.concat(p(arguments)))}}}function k(a,b,c){var d;if(d=c?e(c,b):b,a)for(var f=a-1,g=f;g>=0;g--)d=j(d,g===f);return d}var l=b.isArray,m=b.isObject,n=b.isString,o=b.isFunction,p=c.argsToArray;return a.define(m,{bind:e,bindAll:h,bindIgnore:g,curry:function(a,b,c){return k(b,c,a)}}).define(o,{bind:function(a,b){return e.apply(this,[b,a].concat(p(arguments,2)))},bindIgnore:function(a,b){return g.apply(this,[b,a].concat(p(arguments,2)))},partial:i,applyFirst:f,curry:function(a,b,c){return k(b,a,c)},noWrap:{f:function(){return this.value()}}}).define(n,{bind:function(a,b){return e(b,a)},bindIgnore:function(a,b){return g(b,a)},partial:i,applyFirst:f,curry:function(a,b,c){return k(b,a,c)}}).expose({bind:e,bindAll:h,bindIgnore:g,partial:i,applyFirst:f,curry:k})}"undefined"!=typeof c?"undefined"!=typeof b&&b.exports&&(b.exports=d(a("extended"),a("is-extended"),a("arguments-extended"))):"function"==typeof define&&define.amd?define(["extended","is-extended","arguments-extended"],function(a,b,c){return d(a,b,c)}):this.functionExtended=d(this.extended,this.isExtended,this.argumentsExtended)}.call(this)},{"arguments-extended":57,extended:58,"is-extended":63}],57:[function(a,b,c){!function(){"use strict";function d(a,b){function c(a,b){var c=-1,d=0,e=a.length,f=[];for(b=b||0,c+=b;++cc;c++)a(b,arguments[c]);return b}}(),c.define=function(){return a.define.apply(a,arguments)},c}"undefined"!=typeof c?"undefined"!=typeof b&&b.exports&&(b.exports=d(a("extender"))):"function"==typeof define&&define.amd?define(["extender"],function(a){return d(a)}):this.extended=d(this.extender)}.call(this)},{extender:60}],59:[function(a,b,c){!function(){function d(a){function b(a,b){if(a&&a.length)for(var c=0,d=a.length;d>c;c++)if(a[c]===b)return c;return-1}function c(a){return"[object Array]"===Object.prototype.toString.call(a)}function d(b){function c(a,b,c){if("function"!=typeof c)throw new TypeError("when extending type you must provide a function");var d;d="constructor"===b?function(){this._super(arguments),c.apply(this,arguments)}:function(){var a=f.call(arguments);a.unshift(this._value);var b=c.apply(this,a);return b!==e?this.__extender__(b):this},a[b]=d}function d(a,b,c){if("function"!=typeof c)throw new TypeError("when extending type you must provide a function");var d;d="constructor"===b?function(){this._super(arguments),c.apply(this,arguments)}:function(){var a=f.call(arguments);return a.unshift(this._value),c.apply(this,a)},a[b]=d}function h(a,b,e){for(var f in b)b.hasOwnProperty(f)&&("getters"!==f&&"setters"!==f?"noWrap"===f?h(a,b[f],!0):e?d(a,f,b[f]):c(a,f,b[f]):a[f]=b[f])}function i(a){var b,c,d=a;if(!(a instanceof m)){var e=m;for(b=0,c=n.length;c>b;b++){var f=n[b];f[0](a)&&(e=e.extend({instance:f[1]}))}d=new e(a),d.__extender__=i}return d}function j(){return!0}function k(a,b){if(arguments.length){"object"==typeof a&&(b=a,a=j),b=b||{};var d={};h(d,b),d.hasOwnProperty("constructor")||(b.hasOwnProperty("constructor")?c(d,"constructor",b.constructor):d.constructor=function(){this._super(arguments)}),n.push([a,d])}return i}function l(a){return a&&a.hasOwnProperty("__defined__")&&(i.__defined__=n=n.concat(a.__defined__)),g(i,a,["define","extend","expose","__defined__"]),i}b=b||[];var m=a({instance:{constructor:function(a){this._value=a},value:function(){return this._value},eq:function(a){return this.__extender__(this._value===a)},neq:function(a){return this.__extender__(this._value!==a)},print:function(){return console.log(this._value),this}}}),n=[];return i.define=k,i.extend=l,i.expose=function(){for(var a,b=0,c=arguments.length;c>b;b++)a=arguments[b],"object"==typeof a&&g(i,a,["define","extend","expose","__defined__"]);return i},i.__defined__=n,i}var e,f=Array.prototype.slice,g=function(){function a(a,c,d){var e,f;for(e in c)c.hasOwnProperty(e)&&-1===b(d,e)&&(f=c[e],e in a&&a[e]===f||(a[e]=f));return a}return function(b){b||(b={});var d=arguments.length,e=arguments[arguments.length-1];c(e)?d--:e=[];for(var f=1;d>f;f++)a(b,arguments[f],e);return b}}();return{define:function(){return d().define.apply(d,arguments)},extend:function(a){return d().define().extend(a)}}}"undefined"!=typeof c?"undefined"!=typeof b&&b.exports&&(b.exports=d(a("declare.js"))):"function"==typeof define&&define.amd?define(["declare"],function(a){return d(a)}):this.extender=d(this.declare)}.call(this)},{"declare.js":62}],60:[function(a,b){b.exports=a("./extender.js")},{"./extender.js":59}],61:[function(a,b,c){!function(){function a(){function a(a,b){return b=b||0,x.call(a,b)}function b(a){return"[object Array]"===Object.prototype.toString.call(a)}function c(a){var b;return null!==a&&a!==b&&"object"==typeof a}function d(a){var b=c(a);return b&&a.constructor===Object}function e(a,b){if(a&&a.length)for(var c=0,d=a.length;d>c;c++)if(a[c]===b)return c;return-1}function f(a,b,c){var d,f;for(d in b)b.hasOwnProperty(d)&&-1===e(c,d)&&(f=b[d],d in a&&a[d]===f||(a[d]=f));return a}function g(a){var c=this.__meta,d=c.supers,e=d.length,f=c.superMeta,g=f.pos;if(e>g){a=a?B(a)||b(a)?a:[a]:[];var h,i=f.name,j=f.f;do if(h=d[g][i],"function"==typeof h&&(h=h._f||h)!==j)return f.pos=1+g,h.apply(this,a);while(e>++g)}return null}function h(){var a=this.__meta,b=a.supers,c=b.length,d=a.superMeta,e=d.pos;if(c>e){var f,g=d.name,h=d.f;do if(f=b[e][g],"function"==typeof f&&(f=f._f||f)!==h)return d.pos=1+e,f.bind(this);while(c>++e)}return null}function i(a){var b=this.__getters__;return b.hasOwnProperty(a)?b[a].apply(this):this[a]}function j(b,c){var e=this.__setters__;if(!d(b))return e.hasOwnProperty(b)?e[b].apply(this,a(arguments,1)):this[b]=c;for(var f in b){var g=b[f];e.hasOwnProperty(f)?e[b].call(this,g):this[f]=g}}function k(){var a=this.__meta||{},b=a.supers,c=b.length,d=a.superMeta,e=d.pos;if(c>e){var f,g=d.name,h=d.f;do if(f=b[e][g],"function"==typeof f&&(f=f._f||f)!==h)return d.pos=1+e,f.apply(this,arguments);while(c>++e)}return null}function l(a,b){if(a.toString().match(A)){var c=function(){var c,d=this.__meta||{},e=d.superMeta;switch(d.superMeta={f:a,pos:0,name:b},arguments.length){case 0:c=a.call(this);break;case 1:c=a.call(this,arguments[0]);break;case 2:c=a.call(this,arguments[0],arguments[1]);break;case 3:c=a.call(this,arguments[0],arguments[1],arguments[2]);break;default:c=a.apply(this,arguments)}return d.superMeta=e,c};return c._f=a,c}return a._f=a,a}function m(a,b){var c=b.setters||{},d=a.__setters__,e=a.__getters__;for(var f in c)d.hasOwnProperty(f)||(d[f]=c[f]);c=b.getters||{};for(f in c)e.hasOwnProperty(f)||(e[f]=c[f]);for(var g in b)if("getters"!==g&&"setters"!==g){var h=b[g];"function"==typeof h?a.hasOwnProperty(g)||(a[g]=l(k,g)):a[g]=h}}function n(){for(var b=a(arguments),c=b.length,d=this.prototype,e=d.__meta,f=this.__meta,g=d.__meta.bases,h=g.slice(),i=f.supers||[],j=e.supers||[],k=0;c>k;k++){var l=b[k],n=l.prototype,p=n.__meta,q=l.__meta;!p&&(p=n.__meta={proto:n||{}}),!q&&(q=l.__meta={proto:l.__proto__||{}}),m(d,p.proto||{}),m(this,q.proto||{}),o(l.prototype,j,g),o(l,i,h)}return this}function o(a,b,c){var d=a.__meta;!d&&(d=a.__meta={});var f=a.__meta.unique;if(!f&&(d.unique="declare"+ ++y),-1===e(c,f)){c.push(f);for(var g=a.__meta.supers||[],h=g.length-1||0;h>=0;)o(g[h--],b,c);b.unshift(a)}}function p(a,b){var c=b.setters,d=a.__setters__,e=a.__getters__;if(c)for(var f in c)d[f]=c[f];if(c=b.getters||{})for(f in c)e[f]=c[f];for(f in b)if("getters"!=f&&"setters"!=f){var g=b[f];if("function"==typeof g){var h=g.__meta||{};a[f]=h.isConstructor?g:l(g,f)}else a[f]=g}}function q(a,b){return a&&b?a[b]=this:a.exports=a=this,this}function r(a){return u(this,a)}function s(a){z.prototype=a.prototype;var b=new z;return z.prototype=null,b}function t(a,c,e){var i={},j=[],m="declare"+ ++y,q=[],r=[],t=[],u=[],v={supers:t,unique:m,bases:q,superMeta:{f:null,pos:0,name:null}},x={supers:u,unique:m,bases:r,isConstructor:!0,superMeta:{f:null,pos:0,name:null}};if(d(c)&&!e&&(e=c,c=w),"function"==typeof c||b(c)?(j=b(c)?c:[c],c=j.shift(),a.__meta=x,i=s(c),i.__meta=v,i.__getters__=f({},i.__getters__||{}),i.__setters__=f({},i.__setters__||{}),a.__getters__=f({},a.__getters__||{}),a.__setters__=f({},a.__setters__||{}),o(c.prototype,t,q),o(c,u,r)):(a.__meta=x,i.__meta=v,i.__getters__=i.__getters__||{},i.__setters__=i.__setters__||{},a.__getters__=a.__getters__||{},a.__setters__=a.__setters__||{}),a.prototype=i,e){var z=v.proto=e.instance||{},A=x.proto=e.static||{};A.init=A.init||k,p(i,z),p(a,A),i.constructor=z.hasOwnProperty("constructor")?l(z.constructor,"constructor"):z.constructor=l(k,"constructor")}else v.proto={},x.proto={},a.init=l(k,"init"),i.constructor=l(k,"constructor");j.length&&n.apply(a,j),c&&f(a,f(f({},c),a)),i._super=a._super=g,i._getSuper=a._getSuper=h,i._static=a}function u(a,b){function c(){this.constructor.apply(this,arguments)}return t(c,a,b),c.init()||c}function v(a,b){function c(){return d||(this.constructor.apply(this,arguments),d=this),d}var d;return t(c,a,b),c.init()||c}var w,x=Array.prototype.slice,y=0,z=new Function,A=/(super)/g,B=function(a){return"[object Arguments]"===Object.prototype.toString.call(a)};return B(arguments)||(B=function(a){return!(!a||!a.hasOwnProperty("callee"))}),w=u({instance:{get:i,set:j},"static":{get:i,set:j,mixin:n,extend:r,as:q}}),u.singleton=v,u}"undefined"!=typeof c?"undefined"!=typeof b&&b.exports&&(b.exports=a()):"function"==typeof define&&define.amd?define(a):this.declare=a()}()},{}],62:[function(a,b){b.exports=a("./declare.js")},{"./declare.js":61}],63:[function(a,b,c){var d=a("__browserify_Buffer").Buffer;!function(){"use strict";function e(a){function b(a,b){return b=b||0,S.call(a,b)}function c(a){var b=[];for(var c in a)T.call(a,c)&&b.push(c);return b}function e(a,b){if(a===b)return!0;if("undefined"!=typeof d&&d.isBuffer(a)&&d.isBuffer(b)){if(a.length!==b.length)return!1;for(var c=0;c=0;f--)if(g[f]!==h[f])return!1;for(f=g.length-1;f>=0;f--)if(d=g[f],!e(a[d],b[d]))return!1}catch(i){return!1}return!0}function g(a){return null!==a&&"object"==typeof a}function h(a){var b=g(a);return b&&a.constructor===Object&&!a.nodeType&&!a.setInterval}function i(a){return W(a)?0===a.length:g(a)?0===c(a).length:r(a)||X(a)?0===a.length:!0}function j(a){return a===!0||a===!1||"[object Boolean]"===U.call(a)}function k(a){return"undefined"==typeof a}function l(a){return!k(a)}function m(a){return k(a)||n(a)}function n(a){return null===a}function o(a,b){return V(b)?a instanceof b:!1}function p(a){return"[object RegExp]"===U.call(a)}function q(a){return"[object Date]"===U.call(a)}function r(a){return"[object String]"===U.call(a)}function s(a){return"[object Number]"===U.call(a)}function t(a){return a===!0}function u(a){return a===!1}function v(a){return!n(a)}function w(a,b){return a==b}function x(a,b){return a!=b}function y(a,b){return a===b}function z(a,b){return a!==b}function A(a,b){if(X(b)&&Array.prototype.indexOf||r(b))return b.indexOf(a)>-1;if(X(b))for(var c=0,d=b.length;d>c;c++)if(w(a,b[c]))return!0;return!1}function B(a,b){return!A(a,b)}function C(a,b){return b>a}function D(a,b){return b>=a}function E(a,b){return a>b}function F(a,b){return a>=b}function G(a,b){return r(b)?null!==(""+a).match(b):p(b)?b.test(a):!1}function H(a,b){return!G(a,b)}function I(a,b){return A(b,a)}function J(a,b){return!A(b,a)}function K(a,b,c){return X(a)&&a.length>c?w(a[c],b):!1}function L(a,b,c){return X(a)?!w(a[c],b):!1}function M(a,b){return T.call(a,b)}function N(a,b){return!M(a,b)}function O(a,b){return M(a,"length")?a.length===b:!1}function P(a,b){return M(a,"length")?a.length!==b:!1}function Q(a){Z[a]=function(){this._testers.push(Y[a])}}function R(a){$[a]=function(){var c,d=b(arguments,1),e=Y[a],f=!0;if(d.length<=e.length-1)throw new TypeError("A handler must be defined when calling using switch");if(c=d.pop(),j(c)&&(f=c,c=d.pop()),!V(c))throw new TypeError("handler must be defined");this._cases.push(function(a){return e.apply(Y,a.concat(d))?[f,c.apply(this,a)]:[!1]})}}var S=Array.prototype.slice,T=Object.prototype.hasOwnProperty,U=Object.prototype.toString,V=function(a){return"[object Function]"===U.call(a)};"undefined"==typeof window||V(window.alert)||function(a){V=function(b){return"[object Function]"===U.call(b)||b===a}}(window.alert);var W=function(a){return"[object Arguments]"===U.call(a)};W(arguments)||(W=function(a){return!(!a||!T.call(a,"callee"))});var X=Array.isArray||function(a){return"[object Array]"===U.call(a)},Y={isFunction:V,isObject:g,isEmpty:i,isHash:h,isNumber:s,isString:r,isDate:q,isArray:X,isBoolean:j,isUndefined:k,isDefined:l,isUndefinedOrNull:m,isNull:n,isArguments:W,instanceOf:o,isRegExp:p,deepEqual:e,isTrue:t,isFalse:u,isNotNull:v,isEq:w,isNeq:x,isSeq:y,isSneq:z,isIn:A,isNotIn:B,isLt:C,isLte:D,isGt:E,isGte:F,isLike:G,isNotLike:H,contains:I,notContains:J,has:M,notHas:N,isLength:O,isNotLength:P,containsAt:K,notContainsAt:L},Z={constructor:function(){this._testers=[]},noWrap:{tester:function(){var a=this._testers;return function(b){for(var c=!1,d=0,e=a.length;e>d&&!c;d++)c=a[d](b);return c}}}},$={constructor:function(){this._cases=[],this.__default=null},def:function(a,b){this.__default=b},noWrap:{switcher:function(){var a=this._cases,c=this.__default;return function(){for(var d,e=!1,f=b(arguments),g=0,h=a.length;h>g&&!e;g++)if(d=a[g](f),d.length>1&&(d[1]||d[0]))return d[1];return!e&&c?c.apply(this,f):void 0}}}};for(var _ in Y)T.call(Y,_)&&(R(_),Q(_));var ab=a.define(Y).expose(Y);return ab.tester=a.define(Z),ab.switcher=a.define($),ab}"undefined"!=typeof c?"undefined"!=typeof b&&b.exports&&(b.exports=e(a("extended"))):"function"==typeof define&&define.amd?define(["extended"],function(a){return e(a)}):this.isExtended=e(this.extended)}.call(this)},{__browserify_Buffer:67,extended:58}],64:[function(a,b,c){function d(a,b){if(a.indexOf)return a.indexOf(b);for(var c=0;ce;e++)d[e].apply(this,c);return!0}return!1},f.prototype.addListener=function(a,b){if("function"!=typeof b)throw new Error("addListener only takes instances of Function");if(this._events||(this._events={}),this.emit("newListener",a,b),this._events[a])if(g(this._events[a])){if(!this._events[a].warned){var c;c=void 0!==this._events.maxListeners?this._events.maxListeners:h,c&&c>0&&this._events[a].length>c&&(this._events[a].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[a].length),console.trace())}this._events[a].push(b)}else this._events[a]=[this._events[a],b];else this._events[a]=b;return this},f.prototype.on=f.prototype.addListener,f.prototype.once=function(a,b){var c=this;return c.on(a,function d(){c.removeListener(a,d),b.apply(this,arguments)}),this},f.prototype.removeListener=function(a,b){if("function"!=typeof b)throw new Error("removeListener only takes instances of Function");if(!this._events||!this._events[a])return this;var c=this._events[a];if(g(c)){var e=d(c,b);if(0>e)return this;c.splice(e,1),0==c.length&&delete this._events[a]}else this._events[a]===b&&delete this._events[a];return this},f.prototype.removeAllListeners=function(a){return 0===arguments.length?(this._events={},this):(a&&this._events&&this._events[a]&&(this._events[a]=null),this)},f.prototype.listeners=function(a){return this._events||(this._events={}),this._events[a]||(this._events[a]=[]),g(this._events[a])||(this._events[a]=[this._events[a]]),this._events[a]},f.listenerCount=function(a,b){var c;return c=a._events&&a._events[b]?"function"==typeof a._events[b]?1:a._events[b].length:0}},{__browserify_process:68}],65:[function(){},{}],66:[function(a,b,c){function d(a,b){for(var c=[],d=0;d=0;d--){var e=a[d];"."==e?a.splice(d,1):".."===e?(a.splice(d,1),c++):c&&(a.splice(d,1),c--)}if(b)for(;c--;c)a.unshift("..");return a}var f=a("__browserify_process"),g=/^(.+\/(?!$)|\/)?((?:.+?)?(\.[^.]*)?)$/;c.resolve=function(){for(var a="",b=!1,c=arguments.length;c>=-1&&!b;c--){var g=c>=0?arguments[c]:f.cwd();"string"==typeof g&&g&&(a=g+"/"+a,b="/"===g.charAt(0))}return a=e(d(a.split("/"),function(a){return!!a}),!b).join("/"),(b?"/":"")+a||"."},c.normalize=function(a){var b="/"===a.charAt(0),c="/"===a.slice(-1);return a=e(d(a.split("/"),function(a){return!!a}),!b).join("/"),a||b||(a="."),a&&c&&(a+="/"),(b?"/":"")+a},c.join=function(){var a=Array.prototype.slice.call(arguments,0);return c.normalize(d(a,function(a){return a&&"string"==typeof a}).join("/"))},c.dirname=function(a){var b=g.exec(a)[1]||"",c=!1;return b?1===b.length||c&&b.length<=3&&":"===b.charAt(1)?b:b.substring(0,b.length-1):"."},c.basename=function(a,b){var c=g.exec(a)[2]||"";return b&&c.substr(-1*b.length)===b&&(c=c.substr(0,c.length-b.length)),c},c.extname=function(a){return g.exec(a)[3]||""},c.relative=function(a,b){function d(a){for(var b=0;b=0&&""===a[c];c--);return b>c?[]:a.slice(b,c-b+1)}a=c.resolve(a).substr(1),b=c.resolve(b).substr(1);for(var e=d(a.split("/")),f=d(b.split("/")),g=Math.min(e.length,f.length),h=g,i=0;g>i;i++)if(e[i]!==f[i]){h=i;break}for(var j=[],i=h;i=0;e--)if(f[e]!=g[e])return!1;for(e=f.length-1;e>=0;e--)if(d=f[e],!h(a[d],b[d]))return!1;return!0}function l(a,b){return a&&b?b instanceof RegExp?b.test(a):a instanceof b?!0:b.call({},a)===!0?!0:!1:!1}function m(a,b,c,d){var e;"string"==typeof c&&(d=c,c=null);try{b()}catch(g){e=g}if(d=(c&&c.name?" ("+c.name+").":".")+(d?" "+d:"."),a&&!e&&f("Missing expected exception"+d),!a&&l(e,c)&&f("Got unwanted exception"+d),a&&e&&c&&!l(e,c)||!a&&e)throw e}var n=a("util"),o=a("buffer").Buffer,p=Array.prototype.slice,q=b.exports=g;q.AssertionError=function(a){this.name="AssertionError",this.message=a.message,this.actual=a.actual,this.expected=a.expected,this.operator=a.operator;var b=a.stackStartFunction||f;Error.captureStackTrace&&Error.captureStackTrace(this,b)},n.inherits(q.AssertionError,Error),q.AssertionError.prototype.toString=function(){return this.message?[this.name+":",this.message].join(" "):[this.name+":",e(JSON.stringify(this.actual,d),128),this.operator,e(JSON.stringify(this.expected,d),128)].join(" ")},q.AssertionError.__proto__=Error.prototype,q.fail=f,q.ok=g,q.equal=function(a,b,c){a!=b&&f(a,b,c,"==",q.equal)},q.notEqual=function(a,b,c){a==b&&f(a,b,c,"!=",q.notEqual)},q.deepEqual=function(a,b,c){h(a,b)||f(a,b,c,"deepEqual",q.deepEqual)},q.notDeepEqual=function(a,b,c){h(a,b)&&f(a,b,c,"notDeepEqual",q.notDeepEqual)},q.strictEqual=function(a,b,c){a!==b&&f(a,b,c,"===",q.strictEqual)},q.notStrictEqual=function(a,b,c){a===b&&f(a,b,c,"!==",q.notStrictEqual)},q.throws=function(){m.apply(this,[!0].concat(p.call(arguments)))},q.doesNotThrow=function(){m.apply(this,[!1].concat(p.call(arguments)))},q.ifError=function(a){if(a)throw a}},{util:2,buffer:3}],2:[function(a,b,c){function d(a){return a instanceof Array||Array.isArray(a)||a&&a!==Object.prototype&&d(a.__proto__)}function e(a){return a instanceof RegExp||"object"==typeof a&&"[object RegExp]"===Object.prototype.toString.call(a)}function f(a){if(a instanceof Date)return!0;if("object"!=typeof a)return!1;var b=Date.prototype&&h(Date.prototype),c=a.__proto__&&h(a.__proto__);return JSON.stringify(c)===JSON.stringify(b)}a("events"),c.isArray=d,c.isDate=function(a){return"[object Date]"===Object.prototype.toString.call(a)},c.isRegExp=function(a){return"[object RegExp]"===Object.prototype.toString.call(a)},c.print=function(){},c.puts=function(){},c.debug=function(){},c.inspect=function(a,b,i,j){function k(a,i){if(a&&"function"==typeof a.inspect&&a!==c&&(!a.constructor||a.constructor.prototype!==a))return a.inspect(i);switch(typeof a){case"undefined":return m("undefined","undefined");case"string":var j="'"+JSON.stringify(a).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return m(j,"string");case"number":return m(""+a,"number");case"boolean":return m(""+a,"boolean")}if(null===a)return m("null","null");var n=g(a),o=b?h(a):n;if("function"==typeof a&&0===o.length){if(e(a))return m(""+a,"regexp");var p=a.name?": "+a.name:"";return m("[Function"+p+"]","special")}if(f(a)&&0===o.length)return m(a.toUTCString(),"date");var q,r,s;if(d(a)?(r="Array",s=["[","]"]):(r="Object",s=["{","}"]),"function"==typeof a){var t=a.name?": "+a.name:"";q=e(a)?" "+a:" [Function"+t+"]"}else q="";if(f(a)&&(q=" "+a.toUTCString()),0===o.length)return s[0]+q+s[1];if(0>i)return e(a)?m(""+a,"regexp"):m("[Object]","special");l.push(a);var u=o.map(function(b){var c,e;if(a.__lookupGetter__&&(a.__lookupGetter__(b)?e=a.__lookupSetter__(b)?m("[Getter/Setter]","special"):m("[Getter]","special"):a.__lookupSetter__(b)&&(e=m("[Setter]","special"))),n.indexOf(b)<0&&(c="["+b+"]"),e||(l.indexOf(a[b])<0?(e=null===i?k(a[b]):k(a[b],i-1),e.indexOf("\n")>-1&&(e=d(a)?e.split("\n").map(function(a){return" "+a}).join("\n").substr(2):"\n"+e.split("\n").map(function(a){return" "+a}).join("\n"))):e=m("[Circular]","special")),"undefined"==typeof c){if("Array"===r&&b.match(/^\d+$/))return e;c=JSON.stringify(""+b),c.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(c=c.substr(1,c.length-2),c=m(c,"name")):(c=c.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),c=m(c,"string"))}return c+": "+e});l.pop();var v=0,w=u.reduce(function(a,b){return v++,b.indexOf("\n")>=0&&v++,a+b.length+1},0);return u=w>50?s[0]+(""===q?"":q+"\n ")+" "+u.join(",\n ")+" "+s[1]:s[0]+q+" "+u.join(", ")+" "+s[1]}var l=[],m=function(a,b){var c={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]},d={special:"cyan",number:"blue","boolean":"yellow",undefined:"grey","null":"bold",string:"green",date:"magenta",regexp:"red"}[b];return d?"["+c[d][0]+"m"+a+"["+c[d][1]+"m":a};return j||(m=function(a){return a}),k(a,"undefined"==typeof i?2:i)},c.log=function(){},c.pump=null;var g=Object.keys||function(a){var b=[];for(var c in a)b.push(c);return b},h=Object.getOwnPropertyNames||function(a){var b=[];for(var c in a)Object.hasOwnProperty.call(a,c)&&b.push(c);return b},i=Object.create||function(a,b){var c;if(null===a)c={__proto__:null};else{if("object"!=typeof a)throw new TypeError("typeof prototype["+typeof a+"] != 'object'");var d=function(){};d.prototype=a,c=new d,c.__proto__=a}return"undefined"!=typeof b&&Object.defineProperties&&Object.defineProperties(c,b),c};c.inherits=function(a,b){a.super_=b,a.prototype=i(b.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}}) +};var j=/%[sdj%]/g;c.format=function(a){if("string"!=typeof a){for(var b=[],d=0;d=f)return a;switch(a){case"%s":return String(e[d++]);case"%d":return Number(e[d++]);case"%j":return JSON.stringify(e[d++]);default:return a}}),h=e[d];f>d;h=e[++d])g+=null===h||"object"!=typeof h?" "+h:" "+c.inspect(h);return g}},{events:4}],5:[function(a,b,c){c.readIEEE754=function(a,b,c,d,e){var f,g,h=8*e-d-1,i=(1<>1,k=-7,l=c?0:e-1,m=c?1:-1,n=a[b+l];for(l+=m,f=n&(1<<-k)-1,n>>=-k,k+=h;k>0;f=256*f+a[b+l],l+=m,k-=8);for(g=f&(1<<-k)-1,f>>=-k,k+=d;k>0;g=256*g+a[b+l],l+=m,k-=8);if(0===f)f=1-j;else{if(f===i)return g?0/0:1/0*(n?-1:1);g+=Math.pow(2,d),f-=j}return(n?-1:1)*g*Math.pow(2,f-d)},c.writeIEEE754=function(a,b,c,d,e,f){var g,h,i,j=8*f-e-1,k=(1<>1,m=23===e?Math.pow(2,-24)-Math.pow(2,-77):0,n=d?f-1:0,o=d?-1:1,p=0>b||0===b&&0>1/b?1:0;for(b=Math.abs(b),isNaN(b)||1/0===b?(h=isNaN(b)?1:0,g=k):(g=Math.floor(Math.log(b)/Math.LN2),b*(i=Math.pow(2,-g))<1&&(g--,i*=2),b+=g+l>=1?m/i:m*Math.pow(2,1-l),b*i>=2&&(g++,i/=2),g+l>=k?(h=0,g=k):g+l>=1?(h=(b*i-1)*Math.pow(2,e),g+=l):(h=b*Math.pow(2,l-1)*Math.pow(2,e),g=0));e>=8;a[c+n]=255&h,n+=o,h/=256,e-=8);for(g=g<0;a[c+n]=255&g,n+=o,g/=256,j-=8);a[c+n-o]|=128*p}},{}],6:[function(a,b){var c=b.exports={};c.nextTick=function(){var a="undefined"!=typeof window&&window.setImmediate,b="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(a)return function(a){return window.setImmediate(a)};if(b){var c=[];return window.addEventListener("message",function(a){if(a.source===window&&"process-tick"===a.data&&(a.stopPropagation(),c.length>0)){var b=c.shift();b()}},!0),function(a){c.push(a),window.postMessage("process-tick","*")}}return function(a){setTimeout(a,0)}}(),c.title="browser",c.browser=!0,c.env={},c.argv=[],c.binding=function(){throw new Error("process.binding is not supported")},c.cwd=function(){return"/"},c.chdir=function(){throw new Error("process.chdir is not supported")}},{}],4:[function(a,b,c){!function(a){function b(a,b){if(a.indexOf)return a.indexOf(b);for(var c=0;cf;f++)d[f].apply(this,c);return!0}return!1},d.prototype.addListener=function(a,b){if("function"!=typeof b)throw new Error("addListener only takes instances of Function");if(this._events||(this._events={}),this.emit("newListener",a,b),this._events[a])if(e(this._events[a])){if(!this._events[a].warned){var c;c=void 0!==this._events.maxListeners?this._events.maxListeners:f,c&&c>0&&this._events[a].length>c&&(this._events[a].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[a].length),console.trace())}this._events[a].push(b)}else this._events[a]=[this._events[a],b];else this._events[a]=b;return this},d.prototype.on=d.prototype.addListener,d.prototype.once=function(a,b){var c=this;return c.on(a,function d(){c.removeListener(a,d),b.apply(this,arguments)}),this},d.prototype.removeListener=function(a,c){if("function"!=typeof c)throw new Error("removeListener only takes instances of Function");if(!this._events||!this._events[a])return this;var d=this._events[a];if(e(d)){var f=b(d,c);if(0>f)return this;d.splice(f,1),0==d.length&&delete this._events[a]}else this._events[a]===c&&delete this._events[a];return this},d.prototype.removeAllListeners=function(a){return 0===arguments.length?(this._events={},this):(a&&this._events&&this._events[a]&&(this._events[a]=null),this)},d.prototype.listeners=function(a){return this._events||(this._events={}),this._events[a]||(this._events[a]=[]),e(this._events[a])||(this._events[a]=[this._events[a]]),this._events[a]}}(a("__browserify_process"))},{__browserify_process:6}],"buffer-browserify":[function(a,b){b.exports=a("q9TxCC")},{}],q9TxCC:[function(a,b,c){function d(a){this.length=a}function e(a){return 16>a?"0"+a.toString(16):a.toString(16)}function f(a){for(var b=[],c=0;ce&&!(e+c>=b.length||e>=a.length);)b[e+c]=a[e],e++;return e}function j(a){try{return decodeURIComponent(a)}catch(b){return String.fromCharCode(65533)}}function k(a){return a=~~Math.ceil(+a),0>a?0:a}function l(a,b,c){if(!(this instanceof l))return new l(a,b,c);var e;if("number"==typeof c)this.length=k(b),this.parent=a,this.offset=c;else{switch(e=typeof a){case"number":this.length=k(a);break;case"string":this.length=l.byteLength(a,b);break;case"object":this.length=k(a.length);break;default:throw new Error("First argument needs to be a number, array or string.")}if(this.length>l.poolSize?(this.parent=new d(this.length),this.offset=0):((!E||E.length-E.used=a.length?0:(c?(e=a.parent[a.offset+b]<<8,b+1=a.length?0:(c?(b+1>>0):(b+2>>0)),e)}function q(a,b,c,d){var e,f;return d||(D.ok("boolean"==typeof c,"missing or invalid endian"),D.ok(void 0!==b&&null!==b,"missing offset"),D.ok(b+1=0,"specified a negative value for writing an unsigned value"),D.ok(b>=a,"value is larger than maximum value for type"),D.ok(Math.floor(a)===a,"value has a fractional component")}function v(a,b,c,d,e){e||(D.ok(void 0!==b&&null!==b,"missing value"),D.ok("boolean"==typeof d,"missing or invalid endian"),D.ok(void 0!==c&&null!==c,"missing offset"),D.ok(c+1>>8*(d?1-f:f)}function w(a,b,c,d,e){e||(D.ok(void 0!==b&&null!==b,"missing value"),D.ok("boolean"==typeof d,"missing or invalid endian"),D.ok(void 0!==c&&null!==c,"missing offset"),D.ok(c+3>>8*(d?3-f:f)}function x(a,b,c){D.ok("number"==typeof a,"cannot write a non-number as a number"),D.ok(b>=a,"value larger than maximum allowed value"),D.ok(a>=c,"value smaller than minimum allowed value"),D.ok(Math.floor(a)===a,"value has a fractional component")}function y(a,b,c){D.ok("number"==typeof a,"cannot write a non-number as a number"),D.ok(b>=a,"value larger than maximum allowed value"),D.ok(a>=c,"value smaller than minimum allowed value")}function z(a,b,c,d,e){e||(D.ok(void 0!==b&&null!==b,"missing value"),D.ok("boolean"==typeof d,"missing or invalid endian"),D.ok(void 0!==c&&null!==c,"missing offset"),D.ok(c+1=0?v(a,b,c,d,e):v(a,65535+b+1,c,d,e)}function A(a,b,c,d,e){e||(D.ok(void 0!==b&&null!==b,"missing value"),D.ok("boolean"==typeof d,"missing or invalid endian"),D.ok(void 0!==c&&null!==c,"missing offset"),D.ok(c+3=0?w(a,b,c,d,e):w(a,4294967295+b+1,c,d,e)}function B(b,c,d,e,f){f||(D.ok(void 0!==c&&null!==c,"missing value"),D.ok("boolean"==typeof e,"missing or invalid endian"),D.ok(void 0!==d&&null!==d,"missing offset"),D.ok(d+3d;d++)if(a[d]=e(this[d]),d==c.INSPECT_MAX_BYTES){a[d+1]="...";break}return""},d.prototype.hexSlice=function(a,b){var c=this.length;(!a||0>a)&&(a=0),(!b||0>b||b>c)&&(b=c);for(var d="",f=a;b>f;f++)d+=e(this[f]);return d},d.prototype.toString=function(a,b,c){if(a=String(a||"utf8").toLowerCase(),b=+b||0,"undefined"==typeof c&&(c=this.length),+c==b)return"";switch(a){case"hex":return this.hexSlice(b,c);case"utf8":case"utf-8":return this.utf8Slice(b,c);case"ascii":return this.asciiSlice(b,c);case"binary":return this.binarySlice(b,c);case"base64":return this.base64Slice(b,c);case"ucs2":case"ucs-2":return this.ucs2Slice(b,c);default:throw new Error("Unknown encoding")}},d.prototype.hexWrite=function(a,b,c){b=+b||0;var e=this.length-b;c?(c=+c,c>e&&(c=e)):c=e;var f=a.length;if(f%2)throw new Error("Invalid hex string");c>f/2&&(c=f/2);for(var g=0;c>g;g++){var h=parseInt(a.substr(2*g,2),16);if(isNaN(h))throw new Error("Invalid hex string");this[b+g]=h}return d._charsWritten=2*g,g},d.prototype.write=function(a,b,c,d){if(isFinite(b))isFinite(c)||(d=c,c=void 0);else{var e=d;d=b,b=c,c=e}b=+b||0;var f=this.length-b;switch(c?(c=+c,c>f&&(c=f)):c=f,d=String(d||"utf8").toLowerCase()){case"hex":return this.hexWrite(a,b,c);case"utf8":case"utf-8":return this.utf8Write(a,b,c);case"ascii":return this.asciiWrite(a,b,c);case"binary":return this.binaryWrite(a,b,c);case"base64":return this.base64Write(a,b,c);case"ucs2":case"ucs-2":return this.ucs2Write(a,b,c);default:throw new Error("Unknown encoding")}},d.prototype.slice=function(a,b){if(void 0===b&&(b=this.length),b>this.length)throw new Error("oob");if(a>b)throw new Error("oob");return new l(this,b-a,+a)},d.prototype.copy=function(a,b,c,d){for(var e=[],f=c;d>f;f++)D.ok("undefined"!=typeof this[f],"copying undefined buffer bytes!"),e.push(this[f]);for(var f=b;fthis.length)throw new Error("oob");if(b>c)throw new Error("oob");for(var d=b;c>d;d++)this[d]=a},c.SlowBuffer=d,c.Buffer=l,l.poolSize=8192;var E;l.isBuffer=function(a){return a instanceof l||a instanceof d},l.concat=function(a,b){if(!Array.isArray(a))throw new Error("Usage: Buffer.concat(list, [totalLength])\n list should be an Array.");if(0===a.length)return new l(0);if(1===a.length)return a[0];if("number"!=typeof b){b=0;for(var c=0;cd;d++)if(a[d]=e(this.parent[d+this.offset]),d==c.INSPECT_MAX_BYTES){a[d+1]="...";break}return""},l.prototype.get=function(a){if(0>a||a>=this.length)throw new Error("oob");return this.parent[this.offset+a]},l.prototype.set=function(a,b){if(0>a||a>=this.length)throw new Error("oob");return this.parent[this.offset+a]=b},l.prototype.write=function(a,b,c,e){if(isFinite(b))isFinite(c)||(e=c,c=void 0);else{var f=e;e=b,b=c,c=f}b=+b||0;var g=this.length-b;c?(c=+c,c>g&&(c=g)):c=g,e=String(e||"utf8").toLowerCase();var h;switch(e){case"hex":h=this.parent.hexWrite(a,this.offset+b,c);break;case"utf8":case"utf-8":h=this.parent.utf8Write(a,this.offset+b,c);break;case"ascii":h=this.parent.asciiWrite(a,this.offset+b,c);break;case"binary":h=this.parent.binaryWrite(a,this.offset+b,c);break;case"base64":h=this.parent.base64Write(a,this.offset+b,c);break;case"ucs2":case"ucs-2":h=this.parent.ucs2Write(a,this.offset+b,c);break;default:throw new Error("Unknown encoding")}return l._charsWritten=d._charsWritten,h},l.prototype.toString=function(a,b,c){switch(a=String(a||"utf8").toLowerCase(),"undefined"==typeof b||0>b?b=0:b>this.length&&(b=this.length),"undefined"==typeof c||c>this.length?c=this.length:0>c&&(c=0),b+=this.offset,c+=this.offset,a){case"hex":return this.parent.hexSlice(b,c);case"utf8":case"utf-8":return this.parent.utf8Slice(b,c);case"ascii":return this.parent.asciiSlice(b,c);case"binary":return this.parent.binarySlice(b,c);case"base64":return this.parent.base64Slice(b,c);case"ucs2":case"ucs-2":return this.parent.ucs2Slice(b,c);default:throw new Error("Unknown encoding")}},l.byteLength=d.byteLength,l.prototype.fill=function(a,b,c){if(a||(a=0),b||(b=0),c||(c=this.length),"string"==typeof a&&(a=a.charCodeAt(0)),"number"!=typeof a||isNaN(a))throw new Error("value is not a number");if(b>c)throw new Error("end < start");if(c===b)return 0;if(0==this.length)return 0;if(0>b||b>=this.length)throw new Error("start out of bounds");if(0>c||c>this.length)throw new Error("end out of bounds");return this.parent.fill(a,b+this.offset,c+this.offset)},l.prototype.copy=function(a,b,c,d){var e=this;if(c||(c=0),d||(d=this.length),b||(b=0),c>d)throw new Error("sourceEnd < sourceStart");if(d===c)return 0;if(0==a.length||0==e.length)return 0;if(0>b||b>=a.length)throw new Error("targetStart out of bounds");if(0>c||c>=e.length)throw new Error("sourceStart out of bounds");if(0>d||d>e.length)throw new Error("sourceEnd out of bounds");return d>this.length&&(d=this.length),a.length-bthis.length)throw new Error("oob");if(a>b)throw new Error("oob");return new l(this.parent,b-a,+a+this.offset)},l.prototype.utf8Slice=function(a,b){return this.toString("utf8",a,b)},l.prototype.binarySlice=function(a,b){return this.toString("binary",a,b)},l.prototype.asciiSlice=function(a,b){return this.toString("ascii",a,b)},l.prototype.utf8Write=function(a,b){return this.write(a,b,"utf8")},l.prototype.binaryWrite=function(a,b){return this.write(a,b,"binary")},l.prototype.asciiWrite=function(a,b){return this.write(a,b,"ascii")},l.prototype.readUInt8=function(a,b){var c=this;return b||(D.ok(void 0!==a&&null!==a,"missing offset"),D.ok(a=c.length?void 0:c.parent[c.offset+a]},l.prototype.readUInt16LE=function(a,b){return o(this,a,!1,b)},l.prototype.readUInt16BE=function(a,b){return o(this,a,!0,b)},l.prototype.readUInt32LE=function(a,b){return p(this,a,!1,b)},l.prototype.readUInt32BE=function(a,b){return p(this,a,!0,b)},l.prototype.readInt8=function(a,b){var c,d=this;return b||(D.ok(void 0!==a&&null!==a,"missing offset"),D.ok(a=d.length?void 0:(c=128&d.parent[d.offset+a],c?-1*(255-d.parent[d.offset+a]+1):d.parent[d.offset+a])},l.prototype.readInt16LE=function(a,b){return q(this,a,!1,b)},l.prototype.readInt16BE=function(a,b){return q(this,a,!0,b)},l.prototype.readInt32LE=function(a,b){return r(this,a,!1,b)},l.prototype.readInt32BE=function(a,b){return r(this,a,!0,b)},l.prototype.readFloatLE=function(a,b){return s(this,a,!1,b)},l.prototype.readFloatBE=function(a,b){return s(this,a,!0,b)},l.prototype.readDoubleLE=function(a,b){return t(this,a,!1,b)},l.prototype.readDoubleBE=function(a,b){return t(this,a,!0,b)},l.prototype.writeUInt8=function(a,b,c){var d=this;c||(D.ok(void 0!==a&&null!==a,"missing value"),D.ok(void 0!==b&&null!==b,"missing offset"),D.ok(b=0?d.writeUInt8(a,b,c):d.writeUInt8(255+a+1,b,c)},l.prototype.writeInt16LE=function(a,b,c){z(this,a,b,!1,c)},l.prototype.writeInt16BE=function(a,b,c){z(this,a,b,!0,c)},l.prototype.writeInt32LE=function(a,b,c){A(this,a,b,!1,c)},l.prototype.writeInt32BE=function(a,b,c){A(this,a,b,!0,c)},l.prototype.writeFloatLE=function(a,b,c){B(this,a,b,!1,c)},l.prototype.writeFloatBE=function(a,b,c){B(this,a,b,!0,c)},l.prototype.writeDoubleLE=function(a,b,c){C(this,a,b,!1,c)},l.prototype.writeDoubleBE=function(a,b,c){C(this,a,b,!0,c)},d.prototype.readUInt8=l.prototype.readUInt8,d.prototype.readUInt16LE=l.prototype.readUInt16LE,d.prototype.readUInt16BE=l.prototype.readUInt16BE,d.prototype.readUInt32LE=l.prototype.readUInt32LE,d.prototype.readUInt32BE=l.prototype.readUInt32BE,d.prototype.readInt8=l.prototype.readInt8,d.prototype.readInt16LE=l.prototype.readInt16LE,d.prototype.readInt16BE=l.prototype.readInt16BE,d.prototype.readInt32LE=l.prototype.readInt32LE,d.prototype.readInt32BE=l.prototype.readInt32BE,d.prototype.readFloatLE=l.prototype.readFloatLE,d.prototype.readFloatBE=l.prototype.readFloatBE,d.prototype.readDoubleLE=l.prototype.readDoubleLE,d.prototype.readDoubleBE=l.prototype.readDoubleBE,d.prototype.writeUInt8=l.prototype.writeUInt8,d.prototype.writeUInt16LE=l.prototype.writeUInt16LE,d.prototype.writeUInt16BE=l.prototype.writeUInt16BE,d.prototype.writeUInt32LE=l.prototype.writeUInt32LE,d.prototype.writeUInt32BE=l.prototype.writeUInt32BE,d.prototype.writeInt8=l.prototype.writeInt8,d.prototype.writeInt16LE=l.prototype.writeInt16LE,d.prototype.writeInt16BE=l.prototype.writeInt16BE,d.prototype.writeInt32LE=l.prototype.writeInt32LE,d.prototype.writeInt32BE=l.prototype.writeInt32BE,d.prototype.writeFloatLE=l.prototype.writeFloatLE,d.prototype.writeFloatBE=l.prototype.writeFloatBE,d.prototype.writeDoubleLE=l.prototype.writeDoubleLE,d.prototype.writeDoubleBE=l.prototype.writeDoubleBE},{assert:1,"./buffer_ieee754":5,"base64-js":7}],7:[function(a,b){!function(){"use strict";function a(a){var b,c,e,f,g,h;if(a.length%4>0)throw"Invalid string. Length must be a multiple of 4";for(g=a.indexOf("="),g=g>0?a.length-g:0,h=[],e=g>0?a.length-4:a.length,b=0,c=0;e>b;b+=4,c+=3)f=d.indexOf(a[b])<<18|d.indexOf(a[b+1])<<12|d.indexOf(a[b+2])<<6|d.indexOf(a[b+3]),h.push((16711680&f)>>16),h.push((65280&f)>>8),h.push(255&f);return 2===g?(f=d.indexOf(a[b])<<2|d.indexOf(a[b+1])>>4,h.push(255&f)):1===g&&(f=d.indexOf(a[b])<<10|d.indexOf(a[b+1])<<4|d.indexOf(a[b+2])>>2,h.push(255&f>>8),h.push(255&f)),h}function c(a){function b(a){return d[63&a>>18]+d[63&a>>12]+d[63&a>>6]+d[63&a]}var c,e,f,g=a.length%3,h="";for(c=0,f=a.length-g;f>c;c+=3)e=(a[c]<<16)+(a[c+1]<<8)+a[c+2],h+=b(e);switch(g){case 1:e=a[a.length-1],h+=d[e>>2],h+=d[63&e<<4],h+="==";break;case 2:e=(a[a.length-2]<<8)+a[a.length-1],h+=d[e>>10],h+=d[63&e>>4],h+=d[63&e<<2],h+="="}return h}var d="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";b.exports.toByteArray=a,b.exports.fromByteArray=c}()},{}],8:[function(a,b,c){c.readIEEE754=function(a,b,c,d,e){var f,g,h=8*e-d-1,i=(1<>1,k=-7,l=c?0:e-1,m=c?1:-1,n=a[b+l];for(l+=m,f=n&(1<<-k)-1,n>>=-k,k+=h;k>0;f=256*f+a[b+l],l+=m,k-=8);for(g=f&(1<<-k)-1,f>>=-k,k+=d;k>0;g=256*g+a[b+l],l+=m,k-=8);if(0===f)f=1-j;else{if(f===i)return g?0/0:1/0*(n?-1:1);g+=Math.pow(2,d),f-=j}return(n?-1:1)*g*Math.pow(2,f-d)},c.writeIEEE754=function(a,b,c,d,e,f){var g,h,i,j=8*f-e-1,k=(1<>1,m=23===e?Math.pow(2,-24)-Math.pow(2,-77):0,n=d?f-1:0,o=d?-1:1,p=0>b||0===b&&0>1/b?1:0;for(b=Math.abs(b),isNaN(b)||1/0===b?(h=isNaN(b)?1:0,g=k):(g=Math.floor(Math.log(b)/Math.LN2),b*(i=Math.pow(2,-g))<1&&(g--,i*=2),b+=g+l>=1?m/i:m*Math.pow(2,1-l),b*i>=2&&(g++,i/=2),g+l>=k?(h=0,g=k):g+l>=1?(h=(b*i-1)*Math.pow(2,e),g+=l):(h=b*Math.pow(2,l-1)*Math.pow(2,e),g=0));e>=8;a[c+n]=255&h,n+=o,h/=256,e-=8);for(g=g<0;a[c+n]=255&g,n+=o,g/=256,j-=8);a[c+n-o]|=128*p}},{}],3:[function(a,b,c){function d(a){this.length=a}function e(a){return 16>a?"0"+a.toString(16):a.toString(16)}function f(a){for(var b=[],c=0;ce&&!(e+c>=b.length||e>=a.length);)b[e+c]=a[e],e++;return e}function j(a){try{return decodeURIComponent(a)}catch(b){return String.fromCharCode(65533)}}function k(a){return a=~~Math.ceil(+a),0>a?0:a}function l(a,b,c){if(!(this instanceof l))return new l(a,b,c);var e;if("number"==typeof c)this.length=k(b),this.parent=a,this.offset=c;else{switch(e=typeof a){case"number":this.length=k(a);break;case"string":this.length=l.byteLength(a,b);break;case"object":this.length=k(a.length);break;default:throw new Error("First argument needs to be a number, array or string.")}if(this.length>l.poolSize?(this.parent=new d(this.length),this.offset=0):((!E||E.length-E.used>>0):(e=a.parent[a.offset+b+2]<<16,e|=a.parent[a.offset+b+1]<<8,e|=a.parent[a.offset+b],e+=a.parent[a.offset+b+3]<<24>>>0),e}function q(a,b,c,d){var e,f;return d||(D.ok("boolean"==typeof c,"missing or invalid endian"),D.ok(void 0!==b&&null!==b,"missing offset"),D.ok(b+1=0,"specified a negative value for writing an unsigned value"),D.ok(b>=a,"value is larger than maximum value for type"),D.ok(Math.floor(a)===a,"value has a fractional component")}function v(a,b,c,d,e){e||(D.ok(void 0!==b&&null!==b,"missing value"),D.ok("boolean"==typeof d,"missing or invalid endian"),D.ok(void 0!==c&&null!==c,"missing offset"),D.ok(c+1>>8,a.parent[a.offset+c+1]=255&b):(a.parent[a.offset+c+1]=(65280&b)>>>8,a.parent[a.offset+c]=255&b)}function w(a,b,c,d,e){e||(D.ok(void 0!==b&&null!==b,"missing value"),D.ok("boolean"==typeof d,"missing or invalid endian"),D.ok(void 0!==c&&null!==c,"missing offset"),D.ok(c+3>>24,a.parent[a.offset+c+1]=255&b>>>16,a.parent[a.offset+c+2]=255&b>>>8,a.parent[a.offset+c+3]=255&b):(a.parent[a.offset+c+3]=255&b>>>24,a.parent[a.offset+c+2]=255&b>>>16,a.parent[a.offset+c+1]=255&b>>>8,a.parent[a.offset+c]=255&b)}function x(a,b,c){D.ok("number"==typeof a,"cannot write a non-number as a number"),D.ok(b>=a,"value larger than maximum allowed value"),D.ok(a>=c,"value smaller than minimum allowed value"),D.ok(Math.floor(a)===a,"value has a fractional component")}function y(a,b,c){D.ok("number"==typeof a,"cannot write a non-number as a number"),D.ok(b>=a,"value larger than maximum allowed value"),D.ok(a>=c,"value smaller than minimum allowed value")}function z(a,b,c,d,e){e||(D.ok(void 0!==b&&null!==b,"missing value"),D.ok("boolean"==typeof d,"missing or invalid endian"),D.ok(void 0!==c&&null!==c,"missing offset"),D.ok(c+1=0?v(a,b,c,d,e):v(a,65535+b+1,c,d,e)}function A(a,b,c,d,e){e||(D.ok(void 0!==b&&null!==b,"missing value"),D.ok("boolean"==typeof d,"missing or invalid endian"),D.ok(void 0!==c&&null!==c,"missing offset"),D.ok(c+3=0?w(a,b,c,d,e):w(a,4294967295+b+1,c,d,e)}function B(b,c,d,e,f){f||(D.ok(void 0!==c&&null!==c,"missing value"),D.ok("boolean"==typeof e,"missing or invalid endian"),D.ok(void 0!==d&&null!==d,"missing offset"),D.ok(d+3d;d++)if(a[d]=e(this[d]),d==c.INSPECT_MAX_BYTES){a[d+1]="...";break}return""},d.prototype.hexSlice=function(a,b){var c=this.length;(!a||0>a)&&(a=0),(!b||0>b||b>c)&&(b=c);for(var d="",f=a;b>f;f++)d+=e(this[f]);return d},d.prototype.toString=function(a,b,c){if(a=String(a||"utf8").toLowerCase(),b=+b||0,"undefined"==typeof c&&(c=this.length),+c==b)return"";switch(a){case"hex":return this.hexSlice(b,c);case"utf8":case"utf-8":return this.utf8Slice(b,c);case"ascii":return this.asciiSlice(b,c);case"binary":return this.binarySlice(b,c);case"base64":return this.base64Slice(b,c);case"ucs2":case"ucs-2":return this.ucs2Slice(b,c);default:throw new Error("Unknown encoding")}},d.prototype.hexWrite=function(a,b,c){b=+b||0;var e=this.length-b;c?(c=+c,c>e&&(c=e)):c=e;var f=a.length;if(f%2)throw new Error("Invalid hex string");c>f/2&&(c=f/2);for(var g=0;c>g;g++){var h=parseInt(a.substr(2*g,2),16);if(isNaN(h))throw new Error("Invalid hex string");this[b+g]=h}return d._charsWritten=2*g,g},d.prototype.write=function(a,b,c,d){if(isFinite(b))isFinite(c)||(d=c,c=void 0);else{var e=d;d=b,b=c,c=e}b=+b||0;var f=this.length-b;switch(c?(c=+c,c>f&&(c=f)):c=f,d=String(d||"utf8").toLowerCase()){case"hex":return this.hexWrite(a,b,c);case"utf8":case"utf-8":return this.utf8Write(a,b,c);case"ascii":return this.asciiWrite(a,b,c);case"binary":return this.binaryWrite(a,b,c);case"base64":return this.base64Write(a,b,c);case"ucs2":case"ucs-2":return this.ucs2Write(a,b,c);default:throw new Error("Unknown encoding")}},d.prototype.slice=function(a,b){if(void 0===b&&(b=this.length),b>this.length)throw new Error("oob"); +if(a>b)throw new Error("oob");return new l(this,b-a,+a)},d.prototype.copy=function(a,b,c,d){for(var e=[],f=c;d>f;f++)D.ok("undefined"!=typeof this[f],"copying undefined buffer bytes!"),e.push(this[f]);for(var f=b;fd;d++)if(a[d]=e(this.parent[d+this.offset]),d==c.INSPECT_MAX_BYTES){a[d+1]="...";break}return""},l.prototype.get=function(a){if(0>a||a>=this.length)throw new Error("oob");return this.parent[this.offset+a]},l.prototype.set=function(a,b){if(0>a||a>=this.length)throw new Error("oob");return this.parent[this.offset+a]=b},l.prototype.write=function(a,b,c,e){if(isFinite(b))isFinite(c)||(e=c,c=void 0);else{var f=e;e=b,b=c,c=f}b=+b||0;var g=this.length-b;c?(c=+c,c>g&&(c=g)):c=g,e=String(e||"utf8").toLowerCase();var h;switch(e){case"hex":h=this.parent.hexWrite(a,this.offset+b,c);break;case"utf8":case"utf-8":h=this.parent.utf8Write(a,this.offset+b,c);break;case"ascii":h=this.parent.asciiWrite(a,this.offset+b,c);break;case"binary":h=this.parent.binaryWrite(a,this.offset+b,c);break;case"base64":h=this.parent.base64Write(a,this.offset+b,c);break;case"ucs2":case"ucs-2":h=this.parent.ucs2Write(a,this.offset+b,c);break;default:throw new Error("Unknown encoding")}return l._charsWritten=d._charsWritten,h},l.prototype.toString=function(a,b,c){switch(a=String(a||"utf8").toLowerCase(),"undefined"==typeof b||0>b?b=0:b>this.length&&(b=this.length),"undefined"==typeof c||c>this.length?c=this.length:0>c&&(c=0),b+=this.offset,c+=this.offset,a){case"hex":return this.parent.hexSlice(b,c);case"utf8":case"utf-8":return this.parent.utf8Slice(b,c);case"ascii":return this.parent.asciiSlice(b,c);case"binary":return this.parent.binarySlice(b,c);case"base64":return this.parent.base64Slice(b,c);case"ucs2":case"ucs-2":return this.parent.ucs2Slice(b,c);default:throw new Error("Unknown encoding")}},l.byteLength=d.byteLength,l.prototype.fill=function(a,b,c){if(a||(a=0),b||(b=0),c||(c=this.length),"string"==typeof a&&(a=a.charCodeAt(0)),"number"!=typeof a||isNaN(a))throw new Error("value is not a number");if(b>c)throw new Error("end < start");if(c===b)return 0;if(0==this.length)return 0;if(0>b||b>=this.length)throw new Error("start out of bounds");if(0>c||c>this.length)throw new Error("end out of bounds");return this.parent.fill(a,b+this.offset,c+this.offset)},l.prototype.copy=function(a,b,c,d){var e=this;if(c||(c=0),d||(d=this.length),b||(b=0),c>d)throw new Error("sourceEnd < sourceStart");if(d===c)return 0;if(0==a.length||0==e.length)return 0;if(0>b||b>=a.length)throw new Error("targetStart out of bounds");if(0>c||c>=e.length)throw new Error("sourceStart out of bounds");if(0>d||d>e.length)throw new Error("sourceEnd out of bounds");return d>this.length&&(d=this.length),a.length-bthis.length)throw new Error("oob");if(a>b)throw new Error("oob");return new l(this.parent,b-a,+a+this.offset)},l.prototype.utf8Slice=function(a,b){return this.toString("utf8",a,b)},l.prototype.binarySlice=function(a,b){return this.toString("binary",a,b)},l.prototype.asciiSlice=function(a,b){return this.toString("ascii",a,b)},l.prototype.utf8Write=function(a,b){return this.write(a,b,"utf8")},l.prototype.binaryWrite=function(a,b){return this.write(a,b,"binary")},l.prototype.asciiWrite=function(a,b){return this.write(a,b,"ascii")},l.prototype.readUInt8=function(a,b){var c=this;return b||(D.ok(void 0!==a&&null!==a,"missing offset"),D.ok(a=0?d.writeUInt8(a,b,c):d.writeUInt8(255+a+1,b,c)},l.prototype.writeInt16LE=function(a,b,c){z(this,a,b,!1,c)},l.prototype.writeInt16BE=function(a,b,c){z(this,a,b,!0,c)},l.prototype.writeInt32LE=function(a,b,c){A(this,a,b,!1,c)},l.prototype.writeInt32BE=function(a,b,c){A(this,a,b,!0,c)},l.prototype.writeFloatLE=function(a,b,c){B(this,a,b,!1,c)},l.prototype.writeFloatBE=function(a,b,c){B(this,a,b,!0,c)},l.prototype.writeDoubleLE=function(a,b,c){C(this,a,b,!1,c)},l.prototype.writeDoubleBE=function(a,b,c){C(this,a,b,!0,c)},d.prototype.readUInt8=l.prototype.readUInt8,d.prototype.readUInt16LE=l.prototype.readUInt16LE,d.prototype.readUInt16BE=l.prototype.readUInt16BE,d.prototype.readUInt32LE=l.prototype.readUInt32LE,d.prototype.readUInt32BE=l.prototype.readUInt32BE,d.prototype.readInt8=l.prototype.readInt8,d.prototype.readInt16LE=l.prototype.readInt16LE,d.prototype.readInt16BE=l.prototype.readInt16BE,d.prototype.readInt32LE=l.prototype.readInt32LE,d.prototype.readInt32BE=l.prototype.readInt32BE,d.prototype.readFloatLE=l.prototype.readFloatLE,d.prototype.readFloatBE=l.prototype.readFloatBE,d.prototype.readDoubleLE=l.prototype.readDoubleLE,d.prototype.readDoubleBE=l.prototype.readDoubleBE,d.prototype.writeUInt8=l.prototype.writeUInt8,d.prototype.writeUInt16LE=l.prototype.writeUInt16LE,d.prototype.writeUInt16BE=l.prototype.writeUInt16BE,d.prototype.writeUInt32LE=l.prototype.writeUInt32LE,d.prototype.writeUInt32BE=l.prototype.writeUInt32BE,d.prototype.writeInt8=l.prototype.writeInt8,d.prototype.writeInt16LE=l.prototype.writeInt16LE,d.prototype.writeInt16BE=l.prototype.writeInt16BE,d.prototype.writeInt32LE=l.prototype.writeInt32LE,d.prototype.writeInt32BE=l.prototype.writeInt32BE,d.prototype.writeFloatLE=l.prototype.writeFloatLE,d.prototype.writeFloatBE=l.prototype.writeFloatBE,d.prototype.writeDoubleLE=l.prototype.writeDoubleLE,d.prototype.writeDoubleBE=l.prototype.writeDoubleBE},{assert:1,"./buffer_ieee754":8,"base64-js":9}],9:[function(a,b){!function(){"use strict";function a(a){var b,c,e,f,g,h;if(a.length%4>0)throw"Invalid string. Length must be a multiple of 4";for(g=a.indexOf("="),g=g>0?a.length-g:0,h=[],e=g>0?a.length-4:a.length,b=0,c=0;e>b;b+=4,c+=3)f=d.indexOf(a[b])<<18|d.indexOf(a[b+1])<<12|d.indexOf(a[b+2])<<6|d.indexOf(a[b+3]),h.push((16711680&f)>>16),h.push((65280&f)>>8),h.push(255&f);return 2===g?(f=d.indexOf(a[b])<<2|d.indexOf(a[b+1])>>4,h.push(255&f)):1===g&&(f=d.indexOf(a[b])<<10|d.indexOf(a[b+1])<<4|d.indexOf(a[b+2])>>2,h.push(255&f>>8),h.push(255&f)),h}function c(a){function b(a){return d[63&a>>18]+d[63&a>>12]+d[63&a>>6]+d[63&a]}var c,e,f,g=a.length%3,h="";for(c=0,f=a.length-g;f>c;c+=3)e=(a[c]<<16)+(a[c+1]<<8)+a[c+2],h+=b(e);switch(g){case 1:e=a[a.length-1],h+=d[e>>2],h+=d[63&e<<4],h+="==";break;case 2:e=(a[a.length-2]<<8)+a[a.length-1],h+=d[e>>10],h+=d[63&e>>4],h+=d[63&e<<2],h+="="}return h}var d="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";b.exports.toByteArray=a,b.exports.fromByteArray=c}()},{}]},{},[]),b.exports=a("buffer-browserify")},{}],68:[function(a,b){var c=b.exports={};c.nextTick=function(){var a="undefined"!=typeof window&&window.setImmediate,b="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(a)return function(a){return window.setImmediate(a)};if(b){var c=[];return window.addEventListener("message",function(a){if(a.source===window&&"process-tick"===a.data&&(a.stopPropagation(),c.length>0)){var b=c.shift();b()}},!0),function(a){c.push(a),window.postMessage("process-tick","*")}}return function(a){setTimeout(a,0)}}(),c.title="browser",c.browser=!0,c.env={},c.argv=[],c.binding=function(){throw new Error("process.binding is not supported")},c.cwd=function(){return"/"},c.chdir=function(){throw new Error("process.chdir is not supported")}},{}],69:[function(a,b,c){!function(){"use strict";function d(a){var b=function(a){return"string"==typeof a?a:"object"==typeof a?a.hashCode?a.hashCode():""+a:""+a},c=a.declare({instance:{constructor:function(){this.__entries=[],this.__keys=[],this.__values=[]},pushValue:function(a,b){return this.__keys.push(a),this.__values.push(b),this.__entries.push({key:a,value:b}),b},remove:function(a){for(var b,c=null,d=this.__entries,e=this.__keys,f=this.__values,g=d.length-1;g>=0;g--)if((b=d[g])&&b.key===a)return d.splice(g,1),e.splice(g,1),f.splice(g,1),b.value;return c},set:function(a,b){for(var c=null,d=this.__entries,e=this.__values,f=d.length-1;f>=0;f--){var g=d[f];if(g&&a===g.key){e[f]=b,g.value=b,c=b;break}}return c||d.push({key:a,value:b}),c},find:function(a){for(var b,c=null,d=this.__entries,e=d.length-1;e>=0;e--)if(b=d[e],b&&a===b.key){c=b.value;break}return c},getEntrySet:function(){return this.__entries},getKeys:function(){return this.__keys},getValues:function(){return this.__values}}});return a.declare({instance:{constructor:function(){this.__map={}},entrySet:function(){var a=[],b=this.__map;for(var c in b)b.hasOwnProperty(c)&&(a=a.concat(b[c].getEntrySet()));return a},put:function(a,d){var e=b(a),f=null;return(f=this.__map[e])||(f=this.__map[e]=new c),f.pushValue(a,d),d},remove:function(a){var c=b(a),d=null,e=this.__map[c];return e&&(d=e.remove(a)),d},get:function(a){var c,d=b(a),e=null;return(c=this.__map[d])&&(e=c.find(a)),e},set:function(a,d){var e=b(a),f=null,g=null,h=this.__map;return f=(g=h[e])?g.set(a,d):(h[e]=new c).pushValue(a,d)},contains:function(a){var c=b(a),d=!1,e=null;return(e=this.__map[c])&&(d=!!e.find(a)),d},concat:function(a){if(a instanceof this._static){for(var b=new this._static,c=a.entrySet().concat(this.entrySet()),d=c.length-1;d>=0;d--){var e=c[d];b.put(e.key,e.value)}return b}throw new TypeError("When joining hashtables the joining arg must be a HashTable")},filter:function(b,c){var d=this.entrySet(),e=new this._static;d=a.filter(d,b,c);for(var f=d.length-1;f>=0;f--){var g=d[f];e.put(g.key,g.value)}return e},forEach:function(b,c){var d=this.entrySet();a.forEach(d,b,c)},every:function(b,c){var d=this.entrySet();return a.every(d,b,c)},map:function(b,c){var d=this.entrySet();return a.map(d,b,c)},some:function(b,c){var d=this.entrySet();return a.some(d,b,c)},reduce:function(b,c){var d=this.entrySet();return a.reduce(d,b,c)},reduceRight:function(b,c){var d=this.entrySet();return a.reduceRight(d,b,c)},clear:function(){this.__map={}},keys:function(){var a=[],b=this.__map;for(var c in b)a=a.concat(b[c].getKeys());return a},values:function(){var a=[],b=this.__map;for(var c in b)a=a.concat(b[c].getValues());return a},isEmpty:function(){return 0===this.keys().length}}})}"undefined"!=typeof c?"undefined"!=typeof b&&b.exports&&(b.exports=d(a("extended")().register("declare",a("declare.js")).register(a("is-extended")).register(a("array-extended")))):"function"==typeof define?define(["extended","declare","is-extended","array-extended"],function(a,b,c,e){return d(a().register("declare",b).register(c).register(e))}):this.Ht=d(this.extended().register("declare",this.declare).register(this.isExtended).register(this.arrayExtended))}.call(this)},{"array-extended":49,"declare.js":52,extended:53,"is-extended":70}],70:[function(a,b,c){var d=a("__browserify_Buffer").Buffer;!function(){"use strict";function e(a){function b(a,b){var c=-1,d=0,e=a.length,f=[];for(b=b||0,c+=b;++c=0;f--)if(g[f]!==h[f])return!1;for(f=g.length-1;f>=0;f--)if(d=g[f],!e(a[d],b[d]))return!1}catch(i){return!1}return!0}function g(a){return null!==a&&"object"==typeof a}function h(a){var b=g(a);return b&&a.constructor===Object&&!a.nodeType&&!a.setInterval}function i(a){return W(a)?0===a.length:g(a)?0===c(a).length:r(a)||X(a)?0===a.length:!0}function j(a){return a===!0||a===!1||"[object Boolean]"===U.call(a)}function k(a){return"undefined"==typeof a}function l(a){return!k(a)}function m(a){return k(a)||n(a)}function n(a){return null===a}function o(a,b){return V(b)?a instanceof b:!1}function p(a){return"[object RegExp]"===U.call(a)}function q(a){return"[object Date]"===U.call(a)}function r(a){return"[object String]"===U.call(a)}function s(a){return"[object Number]"===U.call(a)}function t(a){return a===!0}function u(a){return a===!1}function v(a){return!n(a)}function w(a,b){return a==b}function x(a,b){return a!=b}function y(a,b){return a===b}function z(a,b){return a!==b}function A(a,b){if(X(b)&&Array.prototype.indexOf||r(b))return b.indexOf(a)>-1;if(X(b))for(var c=0,d=b.length;d>c;c++)if(w(a,b[c]))return!0;return!1}function B(a,b){return!A(a,b)}function C(a,b){return b>a}function D(a,b){return b>=a}function E(a,b){return a>b}function F(a,b){return a>=b}function G(a,b){return r(b)?null!==(""+a).match(b):p(b)?b.test(a):!1}function H(a,b){return!G(a,b)}function I(a,b){return A(b,a)}function J(a,b){return!A(b,a)}function K(a,b,c){return X(a)&&a.length>c?w(a[c],b):!1}function L(a,b,c){return X(a)?!w(a[c],b):!1}function M(a,b){return T.call(a,b)}function N(a,b){return!M(a,b)}function O(a,b){return M(a,"length")?a.length===b:!1}function P(a,b){return M(a,"length")?a.length!==b:!1}function Q(a){Z[a]=function(){this._testers.push(Y[a])}}function R(a){$[a]=function(){var c,d=b(arguments,1),e=Y[a],f=!0;if(d.length<=e.length-1)throw new TypeError("A handler must be defined when calling using switch");if(c=d.pop(),j(c)&&(f=c,c=d.pop()),!V(c))throw new TypeError("handler must be defined");this._cases.push(function(a){return e.apply(Y,a.concat(d))?[f,c.apply(this,a)]:[!1]})}}var S=Array.prototype.slice,T=Object.prototype.hasOwnProperty,U=Object.prototype.toString,V=function(a){return"[object Function]"===U.call(a)};"undefined"==typeof window||V(window.alert)||function(a){V=function(b){return"[object Function]"===U.call(b)||b===a}}(window.alert);var W=function(a){return"[object Arguments]"===U.call(a)};W(arguments)||(W=function(a){return!(!a||!T.call(a,"callee"))});var X=Array.isArray||function(a){return"[object Array]"===U.call(a)},Y={isFunction:V,isObject:g,isEmpty:i,isHash:h,isNumber:s,isString:r,isDate:q,isArray:X,isBoolean:j,isUndefined:k,isDefined:l,isUndefinedOrNull:m,isNull:n,isArguments:W,instanceOf:o,isRegExp:p,deepEqual:e,isTrue:t,isFalse:u,isNotNull:v,isEq:w,isNeq:x,isSeq:y,isSneq:z,isIn:A,isNotIn:B,isLt:C,isLte:D,isGt:E,isGte:F,isLike:G,isNotLike:H,contains:I,notContains:J,has:M,notHas:N,isLength:O,isNotLength:P,containsAt:K,notContainsAt:L},Z={constructor:function(){this._testers=[]},noWrap:{tester:function(){var a=this._testers;return function(b){for(var c=!1,d=0,e=a.length;e>d&&!c;d++)c=a[d](b);return c}}}},$={constructor:function(){this._cases=[],this.__default=null},def:function(a,b){this.__default=b},noWrap:{switcher:function(){var a=this._cases,c=this.__default;return function(){for(var d,e=!1,f=b(arguments),g=0,h=a.length;h>g&&!e;g++)if(d=a[g](f),d.length>1&&(d[1]||d[0]))return d[1];return!e&&c?c.apply(this,f):void 0}}}};for(var _ in Y)T.call(Y,_)&&(R(_),Q(_));var ab=a.define(Y).expose(Y);return ab.tester=a.define(Z),ab.switcher=a.define($),ab}"undefined"!=typeof c?"undefined"!=typeof b&&b.exports&&(b.exports=e(a("extended"))):"function"==typeof define&&define.amd?define(["extended"],function(a){return e(a)}):this.isExtended=e(this.extended)}.call(this)},{__browserify_Buffer:67,extended:53}],71:[function(a,b,c){!function(){"use strict";function d(a){function b(a,b){var c=0;return a>b?1:b>a?-1:b?c:1}var c=a.multiply,d=a.declare({instance:{__printNode:function(b,d){var e=[];a.isUndefinedOrNull(b)?(e.push(c(" ",d)),e.push("~"),console.log(e.join(""))):(this.__printNode(b.right,d+1),e.push(c(" ",d)),e.push(b.data+"\n"),console.log(e.join("")),this.__printNode(b.left,d+1))},constructor:function(a){a=a||{},this.compare=a.compare||b,this.__root=null},insert:function(){throw new Error("Not Implemented")},remove:function(){throw new Error("Not Implemented")},clear:function(){this.__root=null},isEmpty:function(){return!this.__root},traverseWithCondition:function(a,b,c){var e=!0;return a&&(b=b||d.PRE_ORDER,b===d.PRE_ORDER?(e=c(a.data),e&&(e=this.traverseWithCondition(a.left,b,c),e&&(e=this.traverseWithCondition(a.right,b,c)))):b===d.IN_ORDER?(e=this.traverseWithCondition(a.left,b,c),e&&(e=c(a.data),e&&(e=this.traverseWithCondition(a.right,b,c)))):b===d.POST_ORDER?(e=this.traverseWithCondition(a.left,b,c),e&&(e&&(e=this.traverseWithCondition(a.right,b,c)),e&&(e=c(a.data)))):b===d.REVERSE_ORDER&&(e=this.traverseWithCondition(a.right,b,c),e&&(e=c(a.data),e&&(e=this.traverseWithCondition(a.left,b,c))))),e},traverse:function(a,b,c){a&&(b=b||d.PRE_ORDER,b===d.PRE_ORDER?(c(a.data),this.traverse(a.left,b,c),this.traverse(a.right,b,c)):b===d.IN_ORDER?(this.traverse(a.left,b,c),c(a.data),this.traverse(a.right,b,c)):b===d.POST_ORDER?(this.traverse(a.left,b,c),this.traverse(a.right,b,c),c(a.data)):b===d.REVERSE_ORDER&&(this.traverse(a.right,b,c),c(a.data),this.traverse(a.left,b,c)))},forEach:function(a,b,c){if("function"!=typeof a)throw new TypeError;c=c||d.IN_ORDER,b=b||this,this.traverse(this.__root,c,function(c){a.call(b,c,this)})},map:function(a,b,c){if("function"!=typeof a)throw new TypeError;c=c||d.IN_ORDER,b=b||this;var e=new this._static;return this.traverse(this.__root,c,function(c){e.insert(a.call(b,c,this))}),e},filter:function(a,b,c){if("function"!=typeof a)throw new TypeError;c=c||d.IN_ORDER,b=b||this;var e=new this._static;return this.traverse(this.__root,c,function(c){a.call(b,c,this)&&e.insert(c)}),e},reduce:function(b,c,d){var e=this.toArray(d),f=[e,b];return a.isUndefinedOrNull(c)||f.push(c),a.reduce.apply(a,f)},reduceRight:function(b,c,d){var e=this.toArray(d),f=[e,b];return a.isUndefinedOrNull(c)||f.push(c),a.reduceRight.apply(a,f)},every:function(a,b,c){if("function"!=typeof a)throw new TypeError;c=c||d.IN_ORDER,b=b||this;var e=!1;return this.traverseWithCondition(this.__root,c,function(c){return e=a.call(b,c,this)}),e},some:function(a,b,c){if("function"!=typeof a)throw new TypeError;c=c||d.IN_ORDER,b=b||this;var e;return this.traverseWithCondition(this.__root,c,function(c){return e=a.call(b,c,this),!e}),e},toArray:function(a){a=a||d.IN_ORDER;var b=[];return this.traverse(this.__root,a,function(a){b.push(a)}),b},contains:function(a){for(var b=!1,c=this.__root;null!==c;){var d=this.compare(a,c.data);d?c=c[-1===d?"left":"right"]:(b=!0,c=null)}return b},find:function(a){for(var b,c=this.__root;c;){var d=this.compare(a,c.data);if(!d){b=c.data;break}c=c[-1===d?"left":"right"]}return b},findLessThan:function(a,b){var c=[],e=this.compare;return this.traverseWithCondition(this.__root,d.IN_ORDER,function(d){var f=e(a,d);return!b&&0===f||1===f?(c.push(d),!0):!1}),c},findGreaterThan:function(a,b){var c=[],e=this.compare;return this.traverse(this.__root,d.REVERSE_ORDER,function(d){var f=e(a,d);return!b&&0===f||-1===f?(c.push(d),!0):!1}),c},print:function(){this.__printNode(this.__root,0)}},"static":{PRE_ORDER:"pre_order",IN_ORDER:"in_order",POST_ORDER:"post_order",REVERSE_ORDER:"reverse_order"}}),e=function(){function a(a,b,c){var d=a.__root;if(null===d||void 0===d)a.__root=f(b);else{for(var g,h=d,i=[],k=[],l=0;;){if(g=i[l]=-1===c(b,h.data)?"left":"right",k[l++]=h,!h[g]){h[g]=f(b);break}h=h[g]}if(!h[g])return null;for(;--l>=0&&(k[l].balance+="right"===i[l]?-1:1,0!==k[l].balance);)if(e(k[l].balance)>1){k[l]=j(k[l],i[l]),0!==l?k[l-1][i[l-1]]=k[l]:a.__root=k[0];break}}}function b(a,b,c){var d=a.__root;if(null!==d&&void 0!==d){for(var f,g,h=d,i=0,j=[],l=[],m={done:!1};;){if(!h)return;if(0===(g=c(b,h.data)))break;f=l[i]=-1===g?"left":"right",j[i++]=h,h=h[f]}var n=h.left,o=h.right;if(n&&o){var p=n;for(l[i]="left",j[i++]=h;p.right;)l[i]="right",j[i++]=p,p=p.right;h.data=p.data,j[i-1][j[i-1]===h?"left":"right"]=p.left}else f=n?"left":"right",0!==i?j[i-1][l[i-1]]=h[f]:a.__root=h[f];for(;--i>=0&&!m.done&&(j[i].balance+="left"===l[i]?-1:1,1!==e(j[i].balance));)e(j[i].balance)>1&&(j[i]=k(j[i],l[i],m),0!==i?j[i-1][l[i-1]]=j[i]:a.__root=j[0])}}var e=Math.abs,f=function(a){return{data:a,balance:0,left:null,right:null}},g=function(a,b,c){var d=a[c];return a[c]=d[b],d[b]=a,d},h=function(a,b,c){return a[c]=g(a[c],c,b),g(a,b,c)},i=function(a,b,c){var d="left"===b?"right":"left",e=a[b],f=e[d];0===f.balance?a.balance=e.balance=0:f.balance===c?(a.balance=-c,e.balance=0):(a.balance=0,e.balance=c),f.balance=0},j=function(a,b){var c="left"===b?"right":"left",d=a[b],e="right"===b?-1:1;return d.balance===e?(a.balance=d.balance=0,a=g(a,c,b)):(i(a,b,e),a=h(a,c,b)),a},k=function(a,b,c){var d="left"===b?"right":"left",e=a[d],f="right"===b?-1:1;return e.balance===-f?(a.balance=e.balance=0,a=g(a,b,d)):e.balance===f?(i(a,d,-f),a=h(a,b,d)):(a.balance=-f,e.balance=f,a=g(a,b,d),c.done=!0),a};return d.extend({instance:{insert:function(b){a(this,b,this.compare)},remove:function(a){b(this,a,this.compare)},__printNode:function(a,b){var d=[];a?(this.__printNode(a.right,b+1),d.push(c(" ",b)),d.push(a.data+":"+a.balance+"\n"),console.log(d.join("")),this.__printNode(a.left,b+1)):(d.push(c(" ",b)),d.push("~"),console.log(d.join("")))}}})}(),f=function(){function a(a,b){return{data:a,level:b,left:g,right:g}}function b(a){if(0!==a.level&&a.left.level===a.level){var b=a.left;a.left=b.right,b.right=a,a=b}return a}function e(a){if(0!==a.level&&a.right.right.level===a.level){var b=a.right;a.right=b.left,b.left=a,a=b,a.level++}return a}function f(c,d,h){if(c===g)c=a(d,1);else{var i=-1===h(d,c.data)?"left":"right";c[i]=f(c[i],d,h),c=b(c),c=e(c)}return c}var g={level:0,data:null},h=function(a,c,d){var f,i;if(a!==g){var j=d(c,a.data);if(0===j)if(f=a.left,i=a.right,f!==g&&i!==g){for(var k=f;k.right!==g;)k=k.right;a.data=k.data,a.left=h(f,k.data,d)}else a=a[f===g?"right":"left"];else{var l=-1===j?"left":"right";a[l]=h(a[l],c,d)}}if(a!==g){var m=a.level,n=a.left.level,o=a.right.level;(m-1>n||m-1>o)&&(o>--a.level&&(a.right.level=a.level),a=b(a),a=e(a))}return a};return d.extend({instance:{isEmpty:function(){return this.__root===g||this._super(arguments)},insert:function(a){this.__root||(this.__root=g),this.__root=f(this.__root,a,this.compare)},remove:function(a){this.__root=h(this.__root,a,this.compare)},traverseWithCondition:function(a){var b=!0;return a!==g?this._super(arguments):b},traverse:function(a){a!==g&&this._super(arguments)},contains:function(){return this.__root!==g?this._super(arguments):!1},__printNode:function(a,b){var d=[];a&&a.data?(this.__printNode(a.right,b+1),d.push(c(" ",b)),d.push(a.data+":"+a.level+"\n"),console.log(d.join("")),this.__printNode(a.left,b+1)):(d.push(c(" ",b)),d.push("~"),console.log(d.join("")))}}})}(),g=d.extend({instance:{insert:function(a){if(!this.__root)return this.__root={data:a,parent:null,left:null,right:null},this.__root;for(var b=this.compare,c=this.__root;null!==c;){var d=b(a,c.data);if(!d)return;var e=-1===d?"left":"right",f=c[e];if(!f)return c[e]={data:a,parent:c,left:null,right:null};c=f}},remove:function(a){if(null!==this.__root){for(var b,c={right:this.__root},d=c,e=null,f="right";null!==d[f];){b=d,d=d[f];var g=this.compare(a,d.data);g||(e=d),f=-1===g?"left":"right"}null!==e&&(e.data=d.data,b[b.right===d?"right":"left"]=d[null===d.left?"right":"left"]),this.__root=c.right}}}}),h=function(){var a="RED",b="BLACK",e=function(a){return null!==a&&a.red},f=function(a){return{data:a,red:!0,left:null,right:null}},g=function(a,b,c){if(!a)return f(b);var d=c(b,a.data);if(d){var j=-1===d?"left":"right",k="left"===j?"right":"left";a[j]=g(a[j],b,c);var l=a[j];if(e(l)){var m=a[k];e(m)?(a.red=!0,l.red=!1,m.red=!1):e(l[j])?a=h(a,k):e(l[k])&&(a=i(a,k))}}return a},h=function(a,b){var c="left"===b?"right":"left",d=a[c];return a[c]=d[b],d[b]=a,a.red=!0,d.red=!1,d},i=function(a,b){var c="left"===b?"right":"left";return a[c]=h(a[c],c),h(a,b)},j=function(a,b,c,d){if(a){var f;if(0===d(b,a.data)){if(!a.left||!a.right){var g=a[a.left?"left":"right"];return e(a)?c.done=!0:e(g)&&(g.red=!1,c.done=!0),g}for(var h,i=a.right;null!==i.left;)h=i,i=i.left;h&&(h.left=null),a.data=i.data,b=i.data}f=-1===d(b,a.data)?"left":"right",a[f]=j(a[f],b,c,d),c.done||(a=k(a,f,c))}else c.done=!0;return a},k=function(a,b,c){var d="left"===b?"right":"left",f=a,g=f[d];if(e(g)&&(a=h(a,b),g=f[d]),null!==g)if(e(g.left)||e(g.right)){var j=f.red,k=a===f;f=(e(g[d])?h:i)(f,b),f.red=j,f.left.red=f.right.red=0,k?a=f:a[b]=f,c.done=!0}else e(f)&&(c.done=!0),f.red=0,g.red=1;return a};return d.extend({instance:{insert:function(a){this.__root=g(this.__root,a,this.compare),this.__root.red=!1},remove:function(a){var b={done:!1},c=j(this.__root,a,b,this.compare);return null!==c&&(c.red=0),this.__root=c,a},__printNode:function(d,e){var f=[];d?(this.__printNode(d.right,e+1),f.push(c(" ",e)),f.push((d.red?a:b)+":"+d.data+"\n"),console.log(f.join("")),this.__printNode(d.left,e+1)):(f.push(c(" ",e)),f.push("~"),console.log(f.join("")))}}})}();return{Tree:d,AVLTree:e,AnderssonTree:f,BinaryTree:g,RedBlackTree:h,IN_ORDER:d.IN_ORDER,PRE_ORDER:d.PRE_ORDER,POST_ORDER:d.POST_ORDER,REVERSE_ORDER:d.REVERSE_ORDER}}"undefined"!=typeof c?"undefined"!=typeof b&&b.exports&&(b.exports=d(a("extended")().register("declare",a("declare.js")).register(a("is-extended")).register(a("array-extended")).register(a("string-extended")))):"function"==typeof define?define(["extended","declare.js","is-extended","array-extended","string-extended"],function(a,b,c,e,f){return d(a().register("declare",b).register(c).register(e).register(f))}):this.leafy=d(this.extended().register("declare",this.declare).register(this.isExtended).register(this.arrayExtended).register(this.stringExtended))}.call(this)},{"array-extended":49,"declare.js":52,extended:53,"is-extended":70,"string-extended":74}],72:[function(a,b,c){!function(){"use strict";function d(a,b,c){function d(a,b){var c,d;for(c in b)t.call(b,c)&&(d=b[c],c in a&&a[c]===d||(a[c]=d));return a}function e(a,b){var c,d,f;for(c in b)t.call(b,c)&&(d=b[c],f=a[c],p(f,d)||(a[c]=r(f)&&r(d)?e(f,d):r(d)?e({},d):d));return a}function f(a){a||(a={});for(var b=1,c=arguments.length;c>b;b++)d(a,arguments[b]);return a}function g(a){a||(a={});for(var b=1,c=arguments.length;c>b;b++)e(a,arguments[b]);return a}function h(a,b){var c=a.prototype||a;return f(c,b),a}function i(a,b,c){if(!r(a)||!u(b))throw new TypeError;for(var d,e=l(a),f=0,g=e.length;g>f;++f)d=e[f],b.call(c||a,a[d],d,a);return a}function j(a,b,c){if(!r(a)||!u(b))throw new TypeError;for(var d,e,f=l(a),g={},h=0,i=f.length;i>h;++h)d=f[h],e=a[d],b.call(c||a,e,d,a)&&(g[d]=e);return g}function k(a){if(!r(a))throw new TypeError;for(var b=l(a),c=[],d=0,e=b.length;e>d;++d)c.push(a[b[d]]);return c}function l(a){if(!r(a))throw new TypeError;var b=[];for(var c in a)t.call(a,c)&&b.push(c);return b}function m(a){if(!r(a))throw new TypeError;for(var b,c=l(a),d={},e=0,f=c.length;f>e;++e)b=c[e],d[a[b]]=b;return d}function n(a){if(!r(a))throw new TypeError;for(var b,c=l(a),d=[],e=0,f=c.length;f>e;++e)b=c[e],d.push([b,a[b]]);return d}function o(a,b){if(!r(a))throw new TypeError;q(b)&&(b=[b]);for(var c,d=s(l(a),b),e={},f=0,g=d.length;g>f;++f)c=d[f],e[c]=a[c];return e}var p=b.deepEqual,q=b.isString,r=b.isHash,s=c.difference,t=Object.prototype.hasOwnProperty,u=b.isFunction,v={forEach:i,filter:j,invert:m,values:k,toArray:n,keys:l,omit:o},w={extend:h,merge:f,deepMerge:g,omit:o},x=a.define(b.isObject,w).define(r,v).define(b.isFunction,{extend:h}).expose({hash:v}).expose(w),y=x.extend;return x.extend=function(){return 1===arguments.length?y.extend.apply(x,arguments):(h.apply(null,arguments),void 0)},x}"undefined"!=typeof c?"undefined"!=typeof b&&b.exports&&(b.exports=d(a("extended"),a("is-extended"),a("array-extended"))):"function"==typeof define&&define.amd?define(["extended","is-extended","array-extended"],function(a,b,c){return d(a,b,c)}):this.objectExtended=d(this.extended,this.isExtended,this.arrayExtended)}.call(this)},{"array-extended":49,extended:53,"is-extended":70}],73:[function(a,b,c){var d=a("__browserify_process");!function(){"use strict";function e(a,b,c,e,f,g){function h(a,b){return function(){try{l(a.apply(null,arguments)).addCallback(b).addErrback(b)}catch(c){b.errback(c)}}}function i(a,b,c){var d=(new G).callback();return v(a,function(a){d=d.then(c?a:B(null,a)),c||(d=d.then(function(a){return b.push(a),b}))}),d}function j(a){return!w(a)&&y(a.then)}function k(a){var b=new G;return a.then(A(b,"callback"),A(b,"errback")),b.promise()}function l(a){var b;return a=C(arguments),a.length?1===a.length?(a=a.pop(),j(a)?a.addCallback&&a.addErrback?(b=new G,a.addCallback(b.callback),a.addErrback(b.errback)):b=k(a):b=x(a)&&c.every(a,j)?new H(a,!0).promise():(new G).callback(a)):b=new H(c.map(a,function(a){return l(a)}),!0).promise():b=(new G).callback(a).promise(),b}function m(a,b){return function(){var c=new G,d=C(arguments);return d.push(c.resolve),a.apply(b||this,d),c.promise()}}function n(a){if(x(a))return i(a,[],!1);throw new Error("When calling promise.serial the first argument must be an array")}function o(a){if(x(a))return i(a,[],!0);throw new Error("When calling promise.serial the first argument must be an array")}function p(a,b){a=C(arguments);var c=!1;b=a.pop();var d=l(a);return function(){return c?l(b.apply(this,arguments)):(a=arguments,d.then(A(this,function(){return c=!0,b.apply(this,a)})))}}function q(){return new G}function r(a){return new H(a,!0).promise()}function s(a){return q().errback(a)}function t(a){return q().callback(a)}var u,v=c.forEach,w=e.isUndefinedOrNull,x=e.isArray,y=e.isFunction,z=e.isBoolean,A=f.bind,B=f.bindIgnore,C=g.argsToArray;if("function"==typeof setImmediate)u="undefined"!=typeof window?setImmediate.bind(window):setImmediate;else if("undefined"!=typeof d)u=function(a){d.nextTick(a)};else if("undefined"!=typeof MessageChannel){var D=new MessageChannel,E={},F=E;D.port1.onmessage=function(){E=E.next; +var a=E.task;delete E.task,a()},u=function(a){F=F.next={task:a},D.port2.postMessage(0)}}else u=function(a){setTimeout(a,0)};var G=a({instance:{__fired:!1,__results:null,__error:null,__errorCbs:null,__cbs:null,constructor:function(){this.__errorCbs=[],this.__cbs=[],f.bindAll(this,["callback","errback","resolve","classic","__resolve","addCallback","addErrback"])},__resolve:function(){if(!this.__fired){this.__fired=!0;var a,b=this.__error?this.__errorCbs:this.__cbs,c=b.length,d=this.__error||this.__results;for(a=0;c>a;a++)this.__callNextTick(b[a],d)}},__callNextTick:function(a,b){u(function(){a.apply(this,b)})},addCallback:function(a){return a&&(j(a)&&a.callback&&(a=a.callback),this.__fired&&this.__results?this.__callNextTick(a,this.__results):this.__cbs.push(a)),this},addErrback:function(a){return a&&(j(a)&&a.errback&&(a=a.errback),this.__fired&&this.__error?this.__callNextTick(a,this.__error):this.__errorCbs.push(a)),this},callback:function(){return this.__fired||(this.__results=arguments,this.__resolve()),this.promise()},errback:function(){return this.__fired||(this.__error=arguments,this.__resolve()),this.promise()},resolve:function(a){return a?this.errback(a):this.callback.apply(this,C(arguments,1)),this},classic:function(a){return"function"==typeof a&&(this.addErrback(function(b){a(b)}),this.addCallback(function(){a.apply(this,[null].concat(C(arguments)))})),this},then:function(a,b){var c=new G,d=c;return y(b)&&(d=h(b,c)),this.addErrback(d),y(a)?this.addCallback(h(a,c)):this.addCallback(c),c.promise()},both:function(a){return this.then(a,a)},promise:function(){var a={then:A(this,"then"),both:A(this,"both"),promise:function(){return a}};return v(["addCallback","addErrback","classic"],function(b){a[b]=A(this,function(){return this[b].apply(this,arguments),a})},this),a}}}),H=G.extend({instance:{__results:null,__errors:null,__promiseLength:0,__defLength:0,__firedLength:0,normalizeResults:!1,constructor:function(a,b){this.__errors=[],this.__results=[],this.normalizeResults=z(b)?b:!1,this._super(arguments),a&&a.length?(this.__defLength=a.length,v(a,this.__addPromise,this)):this.__resolve()},__addPromise:function(a,b){a.then(A(this,function(){var a=C(arguments);a.unshift(b),this.callback.apply(this,a)}),A(this,function(){var a=C(arguments);a.unshift(b),this.errback.apply(this,a)}))},__resolve:function(){if(!this.__fired){this.__fired=!0;var a,b=this.__errors.length?this.__errorCbs:this.__cbs,c=b.length,d=this.__errors.length?this.__errors:this.__results;for(a=0;c>a;a++)this.__callNextTick(b[a],d)}},__callNextTick:function(a,b){u(function(){a.apply(null,[b])})},addCallback:function(a){return a&&(j(a)&&a.callback&&(a=A(a,"callback")),this.__fired&&!this.__errors.length?this.__callNextTick(a,this.__results):this.__cbs.push(a)),this},addErrback:function(a){return a&&(j(a)&&a.errback&&(a=A(a,"errback")),this.__fired&&this.__errors.length?this.__callNextTick(a,this.__errors):this.__errorCbs.push(a)),this},callback:function(a){if(this.__fired)throw new Error("Already fired!");var b=C(arguments);return this.normalizeResults&&(b=b.slice(1),b=1===b.length?b.pop():b),this.__results[a]=b,this.__firedLength++,this.__firedLength===this.__defLength&&this.__resolve(),this.promise()},errback:function(a){if(this.__fired)throw new Error("Already fired!");var b=C(arguments);return this.normalizeResults&&(b=b.slice(1),b=1===b.length?b.pop():b),this.__errors[a]=b,this.__firedLength++,this.__firedLength===this.__defLength&&this.__resolve(),this.promise()}}});return b.define({isPromiseLike:j}).expose({isPromiseLike:j,when:l,wrap:m,wait:p,serial:n,chain:o,Promise:G,PromiseList:H,promise:q,defer:q,deferredList:r,reject:s,resolve:t})}"undefined"!=typeof c?"undefined"!=typeof b&&b.exports&&(b.exports=e(a("declare.js"),a("extended"),a("array-extended"),a("is-extended"),a("function-extended"),a("arguments-extended"))):"function"==typeof define&&define.amd?define(["declare","extended","array-extended","is-extended","function-extended","arguments-extended"],function(a,b,c,d,f,g){return e(a,b,c,d,f,g)}):this.promiseExtended=e(this.declare,this.extended,this.arrayExtended,this.isExtended,this.functionExtended,this.argumentsExtended)}.call(this)},{__browserify_process:68,"arguments-extended":48,"array-extended":49,"declare.js":52,extended:53,"function-extended":56,"is-extended":70}],74:[function(a,b,c){!function(){"use strict";function d(a,b,c,d){function e(a,b){var c=a;if(x.test(b)){var d=b.match(x),e=d[1],f=d[3],g=d[4];g&&(g=parseInt(g,10),c=c.length0?"+":"")+d),k&&(k=parseInt(k,10),d=d.lengthe;)d?a+=c:a=c+a,e++;return a}function i(a,c,d){var e=a;if(b.isString(e)){if(a.length>c)if(d){var f=a.length;e=a.substring(f-c,f)}else e=a.substring(0,c)}else e=i(""+e,c);return e}function j(a,d){if(d instanceof Array){var h=0,i=d.length;return a.replace(v,function(a,b,j){var k,l;if(!(i>h))return a;if(k=d[h++],"%s"===a||"%d"===a||"%D"===a)l=k+"";else if("%Z"===a)l=k.toUTCString();else if("%j"===a)try{l=s(k)}catch(m){throw new Error("stringExtended.format : Unable to parse json from ",k)}else switch(b=b.replace(/^\[|\]$/g,""),j){case"s":l=e(k,b);break;case"d":l=f(k,b);break;case"j":l=g(k,b);break;case"D":l=c.format(k,b);break;case"Z":l=c.format(k,b,!0)}return l})}if(t(d))return a.replace(w,function(a,h,i){if(i=d[i],!b.isUndefined(i)){if(!h)return""+i;if(b.isString(i))return e(i,h);if(b.isNumber(i))return f(i,h);if(b.isDate(i))return c.format(i,h);if(b.isObject(i))return g(i,h)}return a});var k=u.call(arguments).slice(1);return j(a,k)}function k(a,b){var c=[];return a&&(a.indexOf(b)>0?c=a.replace(/\s+/g,"").split(b):c.push(a)),c}function l(a,b){var c=[];if(b)for(var d=0;b>d;d++)c.push(a);return c.join("")}function m(a,c){var d,e,f;if(c)if(b.isArray(a))for(d=[],e=0,f=a.length;f>e;e++)d.push(m(a[e],c));else if(c instanceof Array)for(d=a,e=0,f=c.length;f>e;e++)d=m(d,c[e]);else c in z&&(d="["+z[c]+"m"+a+"");return d}function n(a,b){return a.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g,function(a){return b&&-1!==d.indexOf(b,a)?a:"\\"+a})}function o(a){return a.replace(/^\s*|\s*$/g,"")}function p(a){return a.replace(/^\s*/,"")}function q(a){return a.replace(/\s*$/,"")}function r(a){return 0===a.length}var s;"undefined"==typeof JSON?function(){function a(a){return 10>a?"0"+a:a}function c(c){return b.isDate(c)?isFinite(c.valueOf())?c.getUTCFullYear()+"-"+a(c.getUTCMonth()+1)+"-"+a(c.getUTCDate())+"T"+a(c.getUTCHours())+":"+a(c.getUTCMinutes())+":"+a(c.getUTCSeconds())+"Z":null:i(c)?c.valueOf():c}function d(a){return j.lastIndex=0,j.test(a)?'"'+a.replace(j,function(a){var b=k[a];return"string"==typeof b?b:"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+a+'"'}function e(a,b){var i,j,k,l,m,n=f,o=b[a];switch(o&&(o=c(o)),"function"==typeof h&&(o=h.call(b,a,o)),typeof o){case"string":return d(o);case"number":return isFinite(o)?String(o):"null";case"boolean":case"null":return String(o);case"object":if(!o)return"null";if(f+=g,m=[],"[object Array]"===Object.prototype.toString.apply(o)){for(l=o.length,i=0;l>i;i+=1)m[i]=e(i,o)||"null";return k=0===m.length?"[]":f?"[\n"+f+m.join(",\n"+f)+"\n"+n+"]":"["+m.join(",")+"]",f=n,k}if(h&&"object"==typeof h)for(l=h.length,i=0;l>i;i+=1)"string"==typeof h[i]&&(j=h[i],k=e(j,o),k&&m.push(d(j)+(f?": ":":")+k));else for(j in o)Object.prototype.hasOwnProperty.call(o,j)&&(k=e(j,o),k&&m.push(d(j)+(f?": ":":")+k));return k=0===m.length?"{}":f?"{\n"+f+m.join(",\n"+f)+"\n"+n+"}":"{"+m.join(",")+"}",f=n,k}}var f,g,h,i=b.tester().isString().isNumber().isBoolean().tester(),j=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,k={"\b":"\\b"," ":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"};s=function(a,b,c){var d;if(f="",g="","number"==typeof c)for(d=0;c>d;d+=1)g+=" ";else"string"==typeof c&&(g=c);if(h=b,b&&"function"!=typeof b&&("object"!=typeof b||"number"!=typeof b.length))throw new Error("JSON.stringify");return e("",{"":a})}}():s=JSON.stringify;var t=b.isHash,u=Array.prototype.slice,v=/%((?:-?\+?.?\d*)?|(?:\[[^\[|\]]*\]))?([sjdDZ])/g,w=/\{(?:\[([^\[|\]]*)\])?(\w+)\}/g,x=/(-?)(\+?)([A-Z|a-z|\W]?)([1-9][0-9]*)?$/,y=/([1-9][0-9]*)$/g,z={bold:1,bright:1,italic:3,underline:4,blink:5,inverse:7,crossedOut:9,red:31,green:32,yellow:33,blue:34,magenta:35,cyan:36,white:37,redBackground:41,greenBackground:42,yellowBackground:43,blueBackground:44,magentaBackground:45,cyanBackground:46,whiteBackground:47,encircled:52,overlined:53,grey:90,black:90},A={SMILEY:"☺",SOLID_SMILEY:"☻",HEART:"♥",DIAMOND:"♦",CLOVE:"♣",SPADE:"♠",DOT:"•",SQUARE_CIRCLE:"◘",CIRCLE:"○",FILLED_SQUARE_CIRCLE:"◙",MALE:"♂",FEMALE:"♀",EIGHT_NOTE:"♪",DOUBLE_EIGHTH_NOTE:"♫",SUN:"☼",PLAY:"►",REWIND:"◄",UP_DOWN:"↕",PILCROW:"¶",SECTION:"§",THICK_MINUS:"▬",SMALL_UP_DOWN:"↨",UP_ARROW:"↑",DOWN_ARROW:"↓",RIGHT_ARROW:"→",LEFT_ARROW:"←",RIGHT_ANGLE:"∟",LEFT_RIGHT_ARROW:"↔",TRIANGLE:"▲",DOWN_TRIANGLE:"▼",HOUSE:"⌂",C_CEDILLA:"Ç",U_UMLAUT:"ü",E_ACCENT:"é",A_LOWER_CIRCUMFLEX:"â",A_LOWER_UMLAUT:"ä",A_LOWER_GRAVE_ACCENT:"à",A_LOWER_CIRCLE_OVER:"å",C_LOWER_CIRCUMFLEX:"ç",E_LOWER_CIRCUMFLEX:"ê",E_LOWER_UMLAUT:"ë",E_LOWER_GRAVE_ACCENT:"è",I_LOWER_UMLAUT:"ï",I_LOWER_CIRCUMFLEX:"î",I_LOWER_GRAVE_ACCENT:"ì",A_UPPER_UMLAUT:"Ä",A_UPPER_CIRCLE:"Å",E_UPPER_ACCENT:"É",A_E_LOWER:"æ",A_E_UPPER:"Æ",O_LOWER_CIRCUMFLEX:"ô",O_LOWER_UMLAUT:"ö",O_LOWER_GRAVE_ACCENT:"ò",U_LOWER_CIRCUMFLEX:"û",U_LOWER_GRAVE_ACCENT:"ù",Y_LOWER_UMLAUT:"ÿ",O_UPPER_UMLAUT:"Ö",U_UPPER_UMLAUT:"Ü",CENTS:"¢",POUND:"£",YEN:"¥",CURRENCY:"¤",PTS:"₧",FUNCTION:"ƒ",A_LOWER_ACCENT:"á",I_LOWER_ACCENT:"í",O_LOWER_ACCENT:"ó",U_LOWER_ACCENT:"ú",N_LOWER_TILDE:"ñ",N_UPPER_TILDE:"Ñ",A_SUPER:"ª",O_SUPER:"º",UPSIDEDOWN_QUESTION:"¿",SIDEWAYS_L:"⌐",NEGATION:"¬",ONE_HALF:"½",ONE_FOURTH:"¼",UPSIDEDOWN_EXCLAMATION:"¡",DOUBLE_LEFT:"«",DOUBLE_RIGHT:"»",LIGHT_SHADED_BOX:"░",MEDIUM_SHADED_BOX:"▒",DARK_SHADED_BOX:"▓",VERTICAL_LINE:"│",MAZE__SINGLE_RIGHT_T:"┤",MAZE_SINGLE_RIGHT_TOP:"┐",MAZE_SINGLE_RIGHT_BOTTOM_SMALL:"┘",MAZE_SINGLE_LEFT_TOP_SMALL:"┌",MAZE_SINGLE_LEFT_BOTTOM_SMALL:"└",MAZE_SINGLE_LEFT_T:"├",MAZE_SINGLE_BOTTOM_T:"┴",MAZE_SINGLE_TOP_T:"┬",MAZE_SINGLE_CENTER:"┼",MAZE_SINGLE_HORIZONTAL_LINE:"─",MAZE_SINGLE_RIGHT_DOUBLECENTER_T:"╡",MAZE_SINGLE_RIGHT_DOUBLE_BL:"╛",MAZE_SINGLE_RIGHT_DOUBLE_T:"╢",MAZE_SINGLE_RIGHT_DOUBLEBOTTOM_TOP:"╖",MAZE_SINGLE_RIGHT_DOUBLELEFT_TOP:"╕",MAZE_SINGLE_LEFT_DOUBLE_T:"╞",MAZE_SINGLE_BOTTOM_DOUBLE_T:"╧",MAZE_SINGLE_TOP_DOUBLE_T:"╤",MAZE_SINGLE_TOP_DOUBLECENTER_T:"╥",MAZE_SINGLE_BOTTOM_DOUBLECENTER_T:"╨",MAZE_SINGLE_LEFT_DOUBLERIGHT_BOTTOM:"╘",MAZE_SINGLE_LEFT_DOUBLERIGHT_TOP:"╒",MAZE_SINGLE_LEFT_DOUBLEBOTTOM_TOP:"╓",MAZE_SINGLE_LEFT_DOUBLETOP_BOTTOM:"╙",MAZE_SINGLE_LEFT_TOP:"Γ",MAZE_SINGLE_RIGHT_BOTTOM:"╜",MAZE_SINGLE_LEFT_CENTER:"╟",MAZE_SINGLE_DOUBLECENTER_CENTER:"╫",MAZE_SINGLE_DOUBLECROSS_CENTER:"╪",MAZE_DOUBLE_LEFT_CENTER:"╣",MAZE_DOUBLE_VERTICAL:"║",MAZE_DOUBLE_RIGHT_TOP:"╗",MAZE_DOUBLE_RIGHT_BOTTOM:"╝",MAZE_DOUBLE_LEFT_BOTTOM:"╚",MAZE_DOUBLE_LEFT_TOP:"╔",MAZE_DOUBLE_BOTTOM_T:"╩",MAZE_DOUBLE_TOP_T:"╦",MAZE_DOUBLE_LEFT_T:"╠",MAZE_DOUBLE_HORIZONTAL:"═",MAZE_DOUBLE_CROSS:"╬",SOLID_RECTANGLE:"█",THICK_LEFT_VERTICAL:"▌",THICK_RIGHT_VERTICAL:"▐",SOLID_SMALL_RECTANGLE_BOTTOM:"▄",SOLID_SMALL_RECTANGLE_TOP:"▀",PHI_UPPER:"Φ",INFINITY:"∞",INTERSECTION:"∩",DEFINITION:"≡",PLUS_MINUS:"±",GT_EQ:"≥",LT_EQ:"≤",THEREFORE:"⌠",SINCE:"∵",DOESNOT_EXIST:"∄",EXISTS:"∃",FOR_ALL:"∀",EXCLUSIVE_OR:"⊕",BECAUSE:"⌡",DIVIDE:"÷",APPROX:"≈",DEGREE:"°",BOLD_DOT:"∙",DOT_SMALL:"·",CHECK:"√",ITALIC_X:"✗",SUPER_N:"ⁿ",SQUARED:"²",CUBED:"³",SOLID_BOX:"■",PERMILE:"‰",REGISTERED_TM:"®",COPYRIGHT:"©",TRADEMARK:"™",BETA:"β",GAMMA:"γ",ZETA:"ζ",ETA:"η",IOTA:"ι",KAPPA:"κ",LAMBDA:"λ",NU:"ν",XI:"ξ",OMICRON:"ο",RHO:"ρ",UPSILON:"υ",CHI_LOWER:"φ",CHI_UPPER:"χ",PSI:"ψ",ALPHA:"α",ESZETT:"ß",PI:"π",SIGMA_UPPER:"Σ",SIGMA_LOWER:"σ",MU:"µ",TAU:"τ",THETA:"Θ",OMEGA:"Ω",DELTA:"δ",PHI_LOWER:"φ",EPSILON:"ε"},B={toArray:k,pad:h,truncate:i,multiply:l,format:j,style:m,escape:n,trim:o,trimLeft:p,trimRight:q,isEmpty:r};return a.define(b.isString,B).define(b.isArray,{style:m}).expose(B).expose({characters:A})}"undefined"!=typeof c?"undefined"!=typeof b&&b.exports&&(b.exports=d(a("extended"),a("is-extended"),a("date-extended"),a("array-extended"))):"function"==typeof define&&define.amd?define(["extended","is-extended","date-extended","array-extended"],function(a,b,c,e){return d(a,b,c,e)}):this.stringExtended=d(this.extended,this.isExtended,this.dateExtended,this.arrayExtended)}.call(this)},{"array-extended":49,"date-extended":50,extended:53,"is-extended":70}]},{},[1]); \ No newline at end of file diff --git a/package.json b/package.json index ccb9988..8776026 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "nools", "description": "A rules engine for node", - "version": "0.2.1", + "version": "0.2.2", "bin": { "nools": "./bin/nools" }, @@ -29,7 +29,7 @@ "object-extended": "~0.0.3", "promise-extended": "~0.0.3", "arguments-extended": "~0.0.3", - "leafy": "~0.0.2", + "leafy": "~0.0.3", "ht": "~0.0.2", "commander": "~1.1.1", "uglify-js": "~2.3.6" diff --git a/readme.md b/readme.md index da4d8cd..b716374 100644 --- a/readme.md +++ b/readme.md @@ -40,6 +40,7 @@ Or [download the source](https://raw.github.com/C2FO/nools/master/nools.js) ([mi * [Not](#not-constraint) * [Or](#or-constraint) * [From](#from-constraint) + * [Exists](#exists-constraint) * [Actions](#action) * [Globals](#globals) * [Import](#import) @@ -49,6 +50,14 @@ Or [download the source](https://raw.github.com/C2FO/nools/master/nools.js) ([mi ## Resources * [Nools Google group](https://groups.google.com/forum/#!forum/nools) * [Examples](http://c2fo.github.io/nools/examples.html) + * [Conways 2D](http://c2fo.github.io/nools/examples/browser/conways_2d.html) + * [Conways 3D](http://c2fo.github.io/nools/examples/browser/conways_3d.html) + * [Sudoku](http://c2fo.github.io/nools/examples/browser/sudoku.html) + * [Fibonacci](http://c2fo.github.io/nools/examples/browser/fibonacci.html) + * [Miss Manners](http://c2fo.github.io/nools/examples/browser/manners.html) + * [Waltz DB](http://c2fo.github.io/nools/examples/browser/waltzDb.html) + * [Send More Money](http://c2fo.github.io/nools/examples/browser/sendMoreMoney.html) + * [Diagnosis](http://c2fo.github.io/nools/examples/browser/diagnose.html) * [Tests](https://github.com/C2FO/nools/tree/master/test) @@ -1334,6 +1343,42 @@ rule "my rule", { } ``` + + +###Exists Constraint + +`exists` is the logical inversion of a `not` constraint. It checks for the existence of a fact in memory. + + **NOTE** If there are multiple facts that satisfy the constraint the rule will **ONLY** be fired once. + + ```javascript + + [ + ["exists", Number, "n1", "n1 > 1"] + ] + + ``` + + Or using the DSL. + + ``` + + when { + exists(n1: Number n1 > 1); + } + + ``` + + Assuming the above constraint. The following facts would cause the rule to fire once since there is a number that is greater than 1. + + ```javascript + session.assert(1); + session.assert(2); + session.assert(3); + session.assert(4); + session.assert(5); + ``` + ### Action diff --git a/test/browserling.js b/test/browserling.js index 573cea0..ee86ebc 100644 --- a/test/browserling.js +++ b/test/browserling.js @@ -3,7 +3,7 @@ var it = require("it"); it.reporter("tap"); require("./constraintMatcher.test"); -require("./flow.test"); +require("./flow"); require("./flow.compiled.test"); require("./noolsParser.test"); require("./parser.test"); diff --git a/test/constraintMatcher.test.js b/test/constraintMatcher.test.js index 5899f29..3f25984 100644 --- a/test/constraintMatcher.test.js +++ b/test/constraintMatcher.test.js @@ -318,8 +318,24 @@ it.describe("constraint matcher", function (it) { it.should("create for expressions", function () { var atoms = constraintMatcher.toConstraints(parser.parseConstraint("isFalse(a)"), {alias: "a"}); assert.lengthOf(atoms, 1); + assert.equal(atoms[0].type, "comparison"); + + atoms = constraintMatcher.toConstraints(parser.parseConstraint("a == 1"), {alias: "a"}); + assert.lengthOf(atoms, 1); assert.equal(atoms[0].type, "equality"); + atoms = constraintMatcher.toConstraints(parser.parseConstraint("a != 1"), {alias: "a"}); + assert.lengthOf(atoms, 1); + assert.equal(atoms[0].type, "inequality"); + + atoms = constraintMatcher.toConstraints(parser.parseConstraint("a == b"), {alias: "a"}); + assert.lengthOf(atoms, 1); + assert.equal(atoms[0].type, "reference_equality"); + + atoms = constraintMatcher.toConstraints(parser.parseConstraint("a != b"), {alias: "a"}); + assert.lengthOf(atoms, 1); + assert.equal(atoms[0].type, "reference_inequality"); + atoms = constraintMatcher.toConstraints(parser.parseConstraint("isTrue(b)"), {alias: "a"}); assert.lengthOf(atoms, 1); assert.equal(atoms[0].type, "reference"); @@ -327,7 +343,7 @@ it.describe("constraint matcher", function (it) { atoms = constraintMatcher.toConstraints(parser.parseConstraint("isTrue(b) && isFalse(a)"), {alias: "a"}); assert.lengthOf(atoms, 2); assert.equal(atoms[0].type, "reference"); - assert.equal(atoms[1].type, "equality"); + assert.equal(atoms[1].type, "comparison"); atoms = constraintMatcher.toConstraints(parser.parseConstraint("isTrue(b) || isFalse(a)"), {alias: "a"}); assert.lengthOf(atoms, 1); @@ -340,30 +356,30 @@ it.describe("constraint matcher", function (it) { atoms = constraintMatcher.toConstraints(parser.parseConstraint("(isNumber(b) || isFalse(a)) && b == 1"), {alias: "a"}); assert.lengthOf(atoms, 2); assert.equal(atoms[0].type, "reference"); - assert.equal(atoms[1].type, "reference"); + assert.equal(atoms[1].type, "reference_equality"); atoms = constraintMatcher.toConstraints(parser.parseConstraint("a.name == 'bob' && isFalse(a.flag) && b == 1"), {alias: "a"}); assert.lengthOf(atoms, 3); assert.equal(atoms[0].type, "equality"); - assert.equal(atoms[1].type, "equality"); - assert.equal(atoms[2].type, "reference"); + assert.equal(atoms[1].type, "comparison"); + assert.equal(atoms[2].type, "reference_equality"); atoms = constraintMatcher.toConstraints(parser.parseConstraint("a.name == 'bob' && !a.flag && b == 1"), {alias: "a"}); assert.lengthOf(atoms, 3); assert.equal(atoms[0].type, "equality"); - assert.equal(atoms[1].type, "equality"); - assert.equal(atoms[2].type, "reference"); + assert.equal(atoms[1].type, "comparison"); + assert.equal(atoms[2].type, "reference_equality"); atoms = constraintMatcher.toConstraints(parser.parseConstraint("!(a.bool && a.bool2)"), {alias: "a"}); assert.lengthOf(atoms, 1); - assert.equal(atoms[0].type, "equality"); + assert.equal(atoms[0].type, "comparison"); }); it.should("create correct pattern depending on scope", function () { var atoms = constraintMatcher.toConstraints(parser.parseConstraint("isEmail(a)"), {alias: "a", scope: {isEmail: function () { }}}); assert.lengthOf(atoms, 1); - assert.equal(atoms[0].type, "equality"); + assert.equal(atoms[0].type, "comparison"); atoms = constraintMatcher.toConstraints(parser.parseConstraint("isEmail(a)"), {alias: "a"}); assert.lengthOf(atoms, 1); @@ -482,4 +498,45 @@ it.describe("constraint matcher", function (it) { }); }); + it.describe(".getIndexableProperties", function (it) { + + it.should("get properties with no functions", function () { + var props = constraintMatcher.getIndexableProperties(parser.parseConstraint("a == b"), "a"); + assert.deepEqual(props, ["a", "b"]); + props = constraintMatcher.getIndexableProperties(parser.parseConstraint("a.b == b"), "a"); + assert.deepEqual(props, ["a.b", "b"]); + props = constraintMatcher.getIndexableProperties(parser.parseConstraint("a == b.c"), "a"); + assert.deepEqual(props, ["a", "b.c"]); + props = constraintMatcher.getIndexableProperties(parser.parseConstraint("a.b.c.d == b.c.d.e "), "a"); + assert.deepEqual(props, ["a.b.c.d", "b.c.d.e"]); + props = constraintMatcher.getIndexableProperties(parser.parseConstraint("(a == b)"), "a"); + assert.deepEqual(props, ["a", "b"]); + props = constraintMatcher.getIndexableProperties(parser.parseConstraint("a != b"), "a"); + assert.deepEqual(props, ["a", "b"]); + props = constraintMatcher.getIndexableProperties(parser.parseConstraint("a.b != b"), "a"); + assert.deepEqual(props, ["a.b", "b"]); + props = constraintMatcher.getIndexableProperties(parser.parseConstraint("a != b.c"), "a"); + assert.deepEqual(props, ["a", "b.c"]); + props = constraintMatcher.getIndexableProperties(parser.parseConstraint("a.b.c.d != b.c.d.e "), "a"); + assert.deepEqual(props, ["a.b.c.d", "b.c.d.e"]); + props = constraintMatcher.getIndexableProperties(parser.parseConstraint("(a != b)"), "a"); + assert.deepEqual(props, ["a", "b"]); + }); + + it.should("not get non indexable constraints", function () { + var props = constraintMatcher.getIndexableProperties(parser.parseConstraint("a.b.c.d == b.c.d.e || a.b.c == b.c.d "), "a"); + assert.deepEqual(props, []); + + props = constraintMatcher.getIndexableProperties(parser.parseConstraint("a.b.c.d == b.c.d.e || a.b.c == b.c.d && c.d.e == d.e.f "), "a"); + assert.deepEqual(props, []); + props = constraintMatcher.getIndexableProperties(parser.parseConstraint("f3.sequence == s2 + 1")); + assert.deepEqual(props, []); + }); + + it.should("not get properties with functions", function () { + var props = constraintMatcher.getIndexableProperties(parser.parseConstraint("a() == b()"), "a"); + assert.deepEqual(props, []); + }); + }); + }); \ No newline at end of file diff --git a/test/flow.dsl.test.js b/test/flow.dsl.test.js index f751b35..c2eab34 100644 --- a/test/flow.dsl.test.js +++ b/test/flow.dsl.test.js @@ -426,6 +426,4 @@ it.describe("Flow dsl", function (it) { }); }); }); -}); - -//it.run(); \ No newline at end of file +}); \ No newline at end of file diff --git a/test/flow.test.js b/test/flow.test.js index 7fa8ffa..e69de29 100644 --- a/test/flow.test.js +++ b/test/flow.test.js @@ -1,1667 +0,0 @@ -"use strict"; -var it = require("it"), - declare = require("declare.js"), - dateExtended = require("date-extended"), - assert = require("assert"), - nools = require("../index"); - -it.describe("nools", function (it) { - it.describe(".flow", function (it) { - it.should("create a flow", function () { - var flow = nools.flow("nools flow"); - assert.isNotNull(flow); - assert.instanceOf(flow, nools.Flow); - assert.equal("nools flow", flow.name); - assert.equal(nools.getFlow("nools flow"), flow); - }); - }); - - it.describe(".deleteFlow", function (it) { - it.should("delete a flow by name", function () { - var flow = nools.flow("delete nools flow"); - assert.isNotNull(flow); - assert.instanceOf(flow, nools.Flow); - assert.equal("delete nools flow", flow.name); - assert.equal(nools.getFlow("delete nools flow"), flow); - - assert.equal(nools.deleteFlow("delete nools flow"), nools); - assert.isUndefined(nools.getFlow("delete nools flow")); - - }); - - it.should("delete a flow using a Flow instance", function () { - var flow = nools.flow("delete nools flow"); - assert.isNotNull(flow); - assert.instanceOf(flow, nools.Flow); - assert.equal("delete nools flow", flow.name); - assert.equal(nools.getFlow("delete nools flow"), flow); - - assert.equal(nools.deleteFlow(flow), nools); - assert.isUndefined(nools.getFlow("delete nools flow")); - - }); - }); - - it.describe(".hasFlow", function (it) { - - it.should("return true if the flow exists", function () { - var name = "has flow", - flow = nools.flow(name); - assert.isTrue(nools.hasFlow(name)); - }); - - it.should("return false if the flow does not exists", function () { - assert.isFalse(nools.hasFlow(new Date().toString())); - }); - }); - - it.describe(".deleteFlows", function (it) { - - it.should("deleteAllFlows", function () { - var name = "delete nools flows"; - nools.flow(name); - assert.isTrue(nools.hasFlow(name)); - assert.equal(nools.deleteFlows(), nools); - assert.isFalse(nools.hasFlow(name)); - }); - - }); -}); - -it.describe("Flow", function (it) { - - it.describe("#rule", function (it) { - var called = 0; - var flow = nools.flow("test flow"); - it.should("create a rule", function () { - flow.rule("test rule", [String, "s", "s == 'hello'"], function () { - called++; - }); - assert.isTrue(flow.containsRule("test rule")); - }); - - it.should("create a rule with joins properly", function () { - flow.rule("test rule2", [ - [String, "s", "s == 'hello'"], - [String, "s2", "s2 == 'world'"], - [String, "s3", "s3 == 'Hi'"] - ], function () { - called++; - }); - assert.isTrue(flow.containsRule("test rule2")); - }); - - it.should("create a rules that are dependent on eachother properly", function () { - flow.rule("test rule3", [ - [String, "s", "s == 'hello'"], - [String, "s2", "s2 == 'world'"], - [String, "s3", "s3 == 'Hi'"] - ], function () { - called++; - }); - assert.isTrue(flow.containsRule("test rule3")); - - flow.rule("test rule4", [ - [String, "s1"], - [String, "s2", "s2 == 'world' && s1 == 'hello' "], - [String, "s3", "s3 == 'Hi'"], - [String, "s4", "s4 == 'what'"], - [String, "s5", "s5 == 'for'"] - ], function () { - called++; - }); - assert.isTrue(flow.containsRule("test rule4")); - }); - - }); - - it.describe("simple rule", function (it) { - - var called = 0; - var HelloFact = declare({ - instance: { - value: true - } - }); - - var flow = nools.flow("hello world flow", function (flow) { - flow.rule("hello rule", [HelloFact, "h"], function () { - called++; - }); - }); - - it.should("call hello world rule", function () { - var session = flow.getSession(); - session.assert(new HelloFact()); - return session.match().then(function () { - assert.equal(called, 1); - }); - }); - - }); - - it.describe("not rule", function (it) { - - it.describe("with a single fact", function (it) { - var called = 0; - - var flow = nools.flow("notRuleSingleFact", function (flow) { - flow.rule("hello rule", ["not", String, "s", "s == 'hello'"], function (facts) { - assert.isUndefined(facts.s); - called++; - }); - }); - - it.should("call when a string that does not equal 'hello'", function () { - return flow.getSession("world").match().then(function () { - assert.equal(called, 1); - }); - }); - - it.should(" not call when a string that does equal 'hello'", function () { - called = 0; - return flow.getSession("hello").match().then(function () { - assert.equal(called, 0); - }); - }); - - it.should(" not call when a string that does equal 'hello' and one that does not", function () { - called = 0; - return flow.getSession("hello", "world").match().then(function () { - assert.equal(called, 0); - }); - }); - - }); - - it.describe("with multiple facts", function (it) { - var called = 0, arr = []; - var flow1 = nools.flow("notRuleMultiFact", function (flow) { - flow.rule("order rule", [ - [Number, "n1"], - ["not", Number, "n2", "n1 != n2 && n1 > n2"] - ], function (facts, flow) { - arr.push(facts.n1); - flow.retract(facts.n1); - called++; - }); - }); - - var flow2 = nools.flow("notRuleMultiFact2", function (flow) { - flow.rule("order rule reverse", [ - [Number, "n1"], - ["not", Number, "n2", "n1 < n2"] - ], function (facts, flow) { - arr.push(facts.n1); - flow.retract(facts.n1); - called++; - }); - }); - - it.should("fire rules in order", function () { - return flow1.getSession(3, 1, 5, 2, 4).match().then(function () { - assert.deepEqual(arr, [1, 2, 3, 4, 5]); - assert.equal(called, 5); - }).then(function () { - arr = [], called = 0; - return flow2.getSession(4, 2, 5, 1, 3).match().then(function () { - assert.deepEqual(arr, [5, 4, 3, 2, 1]); - assert.equal(called, 5); - }); - }); - }); - }); - - it.describe("modifying facts", function (it) { - var called = 0, arr = []; - - function Num(num) { - this.value = num; - } - - var flow1 = nools.flow("notRuleModifyFact", function (flow) { - flow.rule("not rule", [ - [Num, "n1"], - ["not", Num, "n2", "n1 != n2 && n1.value > n2.value"] - ], function () { - }); - }); - - it.should("handle modifications", function () { - var num1 = new Num(1), - num2 = new Num(2), - num3 = new Num(3), - num4 = new Num(4), - num5 = new Num(5); - var session = flow1.getSession(), - activationTree = session.agenda.rules["not rule"].tree; - - session.assert(num1); - session.assert(num2); - session.assert(num3); - session.assert(num4); - session.assert(num5); - var activations = activationTree.toArray(); - assert.lengthOf(activations, 1); - assert.equal(activations[0].match.factHash.n1, num1); - session.modify(num1, function () { - this.value = 6; - }); - activations = activationTree.toArray() - assert.lengthOf(activations, 1); - assert.equal(activations[0].match.factHash.n1, num2); - session.modify(num2, function () { - this.value = 7; - }); - activations = activationTree.toArray() - assert.lengthOf(activations, 1); - assert.equal(activations[0].match.factHash.n1, num3); - session.modify(num3, function () { - this.value = 8; - }); - activations = activationTree.toArray() - assert.lengthOf(activations, 1); - assert.equal(activations[0].match.factHash.n1, num4); - session.modify(num4, function () { - this.value = 9; - }); - activations = activationTree.toArray() - assert.lengthOf(activations, 1); - assert.equal(activations[0].match.factHash.n1, num5); - session.modify(num5, function () { - this.value = 10; - }); - activations = activationTree.toArray() - assert.lengthOf(activations, 1); - assert.equal(activations[0].match.factHash.n1, num1); - - session.retract(num1); - activations = activationTree.toArray() - assert.lengthOf(activations, 1); - assert.equal(activations[0].match.factHash.n1, num2); - - session.retract(num2); - activations = activationTree.toArray() - assert.lengthOf(activations, 1); - assert.equal(activations[0].match.factHash.n1, num3); - - session.retract(num3); - activations = activationTree.toArray() - assert.lengthOf(activations, 1); - assert.equal(activations[0].match.factHash.n1, num4); - - session.retract(num4); - activations = activationTree.toArray() - assert.lengthOf(activations, 1); - assert.equal(activations[0].match.factHash.n1, num5); - - session.retract(num5); - activations = activationTree.toArray() - assert.lengthOf(activations, 0); - - session.assert(num5); - session.assert(num4); - session.assert(num3); - session.assert(num2); - session.assert(num1); - activations = activationTree.toArray() - assert.lengthOf(activations, 1); - assert.equal(activations[0].match.factHash.n1, num1); - session.retract(num1); - activations = activationTree.toArray() - assert.lengthOf(activations, 1); - assert.equal(activations[0].match.factHash.n1, num2); - session.assert(num1); - activations = activationTree.toArray() - assert.lengthOf(activations, 1); - assert.equal(activations[0].match.factHash.n1, num1); - - }); - }); - - - }); - - it.describe("or rule", function (it) { - - var Count = function () { - this.called = 0; - }, called = new Count(); - - it.describe("or rule with two conditions of the same type", function (it) { - var flow; - it.beforeAll(function () { - flow = nools.flow("or condition", function (flow) { - flow.rule("hello rule", [ - ["or", - [String, "s", "s == 'hello'"], - [String, "s", "s == 'world'"] - ], - [Count, "called", null] - ], function (facts) { - facts.called.called++; - }); - }); - }); - - it.should("should match if one constraints matches", function () { - return flow.getSession("world", called).match().then(function () { - assert.equal(called.called, 1); - called.called = 0; - return flow.getSession("hello", called).match().then(function () { - assert.equal(called.called, 1); - }); - }); - }); - - it.should("not call when a a constraint does not match", function () { - called.called = 0; - return flow.getSession("hello", "world", "test", called).match().then(function () { - assert.equal(called.called, 2); - }); - }); - }); - - it.describe("or rule with three conditions", function (it) { - var flow; - - it.beforeAll(function () { - flow = nools.flow("or condition three constraints", function (flow) { - flow.rule("hello rule", [ - ["or", - [String, "s", "s == 'hello'"], - [String, "s", "s == 'world'"], - [String, "s", "s == 'hello world'"] - ], - [Count, "called", null] - ], function (facts) { - facts.called.called++; - }); - }); - }); - - it.should("should match if one constraints matches", function () { - called.called = 0; - return flow.getSession("world", called).match().then(function () { - assert.equal(called.called, 1); - called.called = 0; - return flow.getSession("hello", called).match().then(function () { - assert.equal(called.called, 1); - called.called = 0; - return flow.getSession("hello world", called).match().then(function () { - assert.equal(called.called, 1); - }); - }); - }); - }); - - it.should("not call when none constraints match", function () { - called.called = 0; - return flow.getSession("hello", "world", "hello world", "test", called).match().then(function () { - assert.equal(called.called, 3); - }); - }); - - }); - - it.describe("or rule with different types", function (it) { - var flow; - - it.beforeAll(function () { - flow = nools.flow("or condition different types", function (flow) { - flow.rule("hello rule", [ - ["or", - [String, "s", "s == 'hello'"], - [String, "s", "s == 'world'"], - [Number, "n", "n == 1"] - ], - [Count, "called", null] - ], function (facts) { - facts.called.called++; - }); - }); - }); - - it.should("should match if one constraints matches", function () { - called.called = 0; - return flow.getSession("world", called).match().then(function () { - assert.equal(called.called, 1); - called.called = 0; - return flow.getSession("hello", called).match().then(function () { - assert.equal(called.called, 1); - called.called = 0; - return flow.getSession(1, called).match().then(function () { - assert.equal(called.called, 1); - }); - }); - }); - }); - - it.should("not call when none constraints match", function () { - called.called = 0; - return flow.getSession("hello", "world", 1, "test", called).match().then(function () { - assert.equal(called.called, 3); - }); - }); - - }); - - it.describe("or with not conditions", function (it) { - var flow; - it.beforeAll(function () { - flow = nools.flow("or condition with not conditions", function (flow) { - flow.rule("hello rule", [ - ["or", - ["not", Number, "n1", "n1 == 1"], - ["not", String, "s1", "s1 == 'hello'"], - ["not", Date, "d1", "d1.getDate() == now().getDate()"] - ], - [Count, "called", null] - ], function (facts) { - facts.called.called++; - }); - }); - }); - - it.should("activate for each fact that does not exist", function () { - var count = new Count(); - return flow.getSession(count).match(2, 'world') - .then(function () { - assert.equal(count.called, 3); - count.called = 0; - return flow.getSession(count, 1).match(); - }) - .then(function () { - assert.equal(count.called, 2); - count.called = 0; - return flow.getSession(count, 'hello').match(); - }) - .then(function () { - assert.equal(count.called, 2); - count.called = 0; - return flow.getSession(count, new Date()).match(); - }) - .then(function () { - assert.equal(count.called, 2); - count.called = 0; - return flow.getSession(count, 1, 'hello', new Date()).match(); - }) - .then(function () { - assert.equal(count.called, 0); - }); - }); - }); - - }); - - it.describe("rule with from", function (it) { - - it.describe("with non array properties", function (it) { - - var called = 0; - var Address = declare({ - instance: { - constructor: function (zip) { - this.zipcode = zip; - } - } - }); - var Person = declare({ - instance: { - constructor: function (first, last, address) { - this.firstName = first; - this.lastName = last; - this.address = address; - } - } - }); - - var flow = nools.flow("from flow", function (flow) { - flow.rule("from rule 1", [ - [Person, "p"], - [Address, "a", "a.zipcode == 88847", "from p.address"], - [String, "first", "first == 'bob'", "from p.firstName"], - [String, "last", "last == 'yukon'", "from p.lastName"] - ], function (facts) { - assert.equal(facts.a, facts.p.address); - assert.equal(facts.a.zipcode, 88847); - assert.equal(facts.first, "bob"); - assert.equal(facts.last, "yukon"); - called++; - }); - - flow.rule("from rule 2", [ - [Person, "p"], - [Address, "a", "a.zipcode == 88845", "from p.address"], - [String, "first", "first == 'bob'", "from p.firstName"], - [String, "last", "last == 'yukon'", "from p.lastName"] - ], function (facts) { - assert.equal(facts.a, facts.p.address); - assert.equal(facts.a.zipcode, 88845); - assert.equal(facts.first, "bob"); - assert.equal(facts.last, "yukon"); - called++; - }); - - flow.rule("from rule 3", [ - [Person, "p"], - [Address, "a", "a.zipcode == 88847", "from p.address"], - [String, "first", "first == 'sally'", "from p.firstName"], - [String, "last", "last == 'yukon'", "from p.lastName"] - ], function (facts) { - assert.equal(facts.a, facts.p.address); - assert.equal(facts.a.zipcode, 88847); - assert.equal(facts.first, "sally"); - assert.equal(facts.last, "yukon"); - called++; - }); - - flow.rule("from rule 4", [ - [Person, "p"], - [Address, "a", "a.zipcode == 88845", "from p.address"], - [String, "first", "first == 'sally'", "from p.firstName"], - [String, "last", "last == 'yukons'", "from p.lastName"] - ], function (facts) { - assert.equal(facts.a, facts.p.address); - assert.equal(facts.a.zipcode, 88845); - assert.equal(facts.first, "sally"); - assert.equal(facts.last, "yukons"); - called++; - }); - }); - - it.should("create the proper match contexts", function () { - var session = flow.getSession(); - session.assert(new Person("bob", "yukon", new Address(88847))); - session.assert(new Person("sally", "yukons", new Address(88847))); - return session.match().then(function () { - assert.equal(called, 1); - }); - }); - - it.should("propagate modified facts properly", function () { - var fired = []; - var session = flow.getSession() - .on("fire", function (name, rule) { - fired.push(name); - }); - var p = new Person("bob", "yukon", new Address(88847)); - session.assert(p); - return session.match().then(function () { - assert.deepEqual(fired, ["from rule 1"]); - fired.length = 0; - session.modify(p, function () { - this.address = new Address(88845) - }); - return session.match().then(function () { - assert.deepEqual(fired, ["from rule 2"]); - fired.length = 0; - session.modify(p, function () { - this.address = new Address(88847); - this.firstName = "sally"; - }); - return session.match().then(function () { - assert.deepEqual(fired, ["from rule 3"]); - fired.length = 0; - session.modify(p, function () { - this.address = new Address(88845); - this.lastName = "yukons" - }); - return session.match().then(function () { - assert.deepEqual(fired, ["from rule 4"]); - fired.length = 0; - }); - }); - }); - }); - }); - - it.should("retract facts properly", function () { - var session = flow.getSession(); - var p = new Person("bob", "yukon", new Address(88847)); - session.assert(p); - assert.equal(session.agenda.peek().name, "from rule 1"); - session.retract(p); - assert.isTrue(session.agenda.isEmpty()); - }); - }); - - it.describe("with js source", function (it) { - - var called = 0; - - function MyValue(n2) { - this.value = n2; - } - - var flow = nools.flow("from flow js source", function (flow) { - flow.rule("from rule 1", [ - [MyValue, "n1"], - [Number, "n2", "n1.value == n2", "from [1,2,3,4,5]"], - ], function (facts) { - assert.equal(facts.n1.value, facts.n2); - assert.isTrue([1, 2, 3, 4, 5].indexOf(facts.n2) !== -1); - called++; - }); - - flow.rule("from rule 2", [ - [MyValue, "n1"], - [String, "n2", "n1.value == n2", "from ['a' ,'b', 'c', 'd', 'e']"] - ], function (facts) { - assert.equal(facts.n1.value, facts.n2); - assert.isTrue(['a' , 'b', 'c', 'd', 'e', 'f'].indexOf(facts.n2) !== -1); - called++; - }); - - flow.rule("from rule 3 with function", [ - [MyValue, "n1", "isDate(n1.value)"], - [Date, "n2", "dateCmp(n1.value, n2)", "from daysFromNow(1)"] - ], function (facts) { - assert.isDate(facts.n1.value); - assert.isDate(facts.n2); - called++; - }); - - flow.rule("from rule 4 with scope function", { - scope: { - myArr: function () { - return ["f", "g", "h", "i", "j"] - } - } - }, [ - [MyValue, "n1"], - [String, "n2", "n1.value == n2", "from myArr()"] - ], function (facts) { - assert.equal(facts.n1.value, facts.n2); - assert.isTrue(["f", "g", "h", "i", "j"].indexOf(facts.n2) !== -1); - called++; - }); - }); - - it.should("create the proper match contexts", function () { - - var session = flow.getSession( - new MyValue(1), - new MyValue(2), - new MyValue(3), - new MyValue(4), - new MyValue(5), - new MyValue('a'), - new MyValue('b'), - new MyValue('c'), - new MyValue('d'), - new MyValue('e'), - new MyValue(dateExtended.daysFromNow(1)), - new MyValue('f'), - new MyValue('g'), - new MyValue('h'), - new MyValue('i'), - new MyValue('j') - - ); - return session.match().then(function () { - assert.equal(called, 16); - }); - }); - - it.should("propagate modified facts properly", function () { - var fired = []; - var session = flow.getSession() - .on("fire", function (name, rule) { - fired.push(name); - }); - var v = new MyValue(1); - session.assert(v); - return session.match().then(function () { - assert.deepEqual(fired, ["from rule 1"]); - fired.length = 0; - debugger; - session.modify(v, function () { - this.value = "a"; - }); - return session.match().then(function () { - assert.deepEqual(fired, ["from rule 2"]); - fired.length = 0; - session.modify(v, function () { - this.value = 1; - }); - }); - }); - }); - }); - - it.describe("with array properties", function (it) { - - var called = 0; - var Person = declare({ - instance: { - constructor: function (first, last, friends) { - this.firstName = first; - this.lastName = last; - this.friends = friends || []; - } - } - }); - - var flow = nools.flow("from flow with arrays", function (flow) { - flow.rule("from rule 1", [ - [Person, "p"], - [Person, "friend", "friend.firstName != p.firstName", "from p.friends"], - [String, "first", "first =~ /^a/", "from friend.firstName"] - ], function (facts) { - assert.isTrue(/^a/.test(facts.first)); - called++; - }); - - flow.rule("from rule 2", [ - [Person, "p"], - [Person, "friend", "friend.firstName != p.firstName", "from p.friends"], - [String, "first", "first =~ /^b/", "from friend.firstName"] - ], function (facts) { - assert.isTrue(/^b/.test(facts.first)); - called++; - }); - }); - - it.should("create all cross product matches", function () { - var fired = [], names = []; - var session = flow.getSession() - .on("fire", function (name, facts) { - if (facts.first.match(/^b/)) { - assert.equal(name, "from rule 2"); - } else { - assert.equal(name, "from rule 1"); - } - names.push([facts.p.firstName, facts.first]); - fired.push(name); - }); - var persons = [ - new Person("bob", "yukon"), - new Person("andy", "yukon"), - new Person("andrew", "yukon"), - new Person("billy", "yukon"), - new Person("sally", "yukon") - ]; - //create graph - for (var i = 0, l = persons.length; i < l; i++) { - var p = persons[i], f; - for (var j = 0, l2 = persons.length; j < l2; j++) { - f = persons[j]; - if (f !== p) { - p.friends.push(f); - } - } - session.assert(p); - } - return session.match().then(function () { - assert.equal(called, 16); - assert.deepEqual(fired, [ - 'from rule 1', - 'from rule 1', - 'from rule 2', - 'from rule 2', - 'from rule 1', - 'from rule 1', - 'from rule 2', - 'from rule 1', - 'from rule 2', - 'from rule 2', - 'from rule 1', - 'from rule 2', - 'from rule 2', - 'from rule 1', - 'from rule 1', - 'from rule 2' - ]); - fired.length = 0; - session.modify(persons[0], function () { - this.firstName = "craig"; - }); - session.modify(persons[1], function () { - this.firstName = "sally"; - }); - session.modify(persons[2], function () { - this.firstName = "thede"; - }); - session.modify(persons[3], function () { - this.firstName = "jake"; - }); - session.modify(persons[4], function () { - this.firstName = "john"; - }); - return session.match().then(function () { - assert.lengthOf(fired, 0); - fired.length = 0; - names.length = 0; - session.modify(persons[0], function () { - this.firstName = "bob"; - }); - session.modify(persons[1], function () { - this.firstName = "bobby"; - }); - session.modify(persons[2], function () { - this.firstName = "billy"; - }); - session.modify(persons[3], function () { - this.firstName = "brian"; - }); - session.modify(persons[4], function () { - this.firstName = "bryan"; - }); - return session.match().then(function () { - names.sort(function (a, b) { - return a[0] === b[0] ? a[1] === b[1] ? 0 : a[1] > b[1] ? 1 : -1 : a[0] > b[0] ? 1 : -1; - }); - assert.deepEqual(names, [ - [ 'billy', 'bob' ], - [ 'billy', 'bobby' ], - [ 'billy', 'brian' ], - [ 'billy', 'bryan' ], - [ 'bob', 'billy' ], - [ 'bob', 'bobby' ], - [ 'bob', 'brian' ], - [ 'bob', 'bryan' ], - - [ 'bobby', 'billy' ], - [ 'bobby', 'bob' ], - [ 'bobby', 'brian' ], - [ 'bobby', 'bryan' ], - - [ 'brian', 'billy' ], - [ 'brian', 'bob' ], - [ 'brian', 'bobby' ], - [ 'brian', 'bryan' ], - - [ 'bryan', 'billy' ], - [ 'bryan', 'bob' ], - [ 'bryan', 'bobby' ], - [ 'bryan', 'brian' ] - ]); - assert.lengthOf(fired, 20); - }) - }) - - }); - }); - - it.should("retract all cross product matches", function () { - var session = flow.getSession(); - var persons = [ - new Person("bob", "yukon"), - new Person("andy", "yukon"), - new Person("andrew", "yukon"), - new Person("billy", "yukon"), - new Person("sally", "yukon") - ]; - //create graph - for (var i = 0, l = persons.length; i < l; i++) { - var p = persons[i], f; - for (var j = 0, l2 = persons.length; j < l2; j++) { - f = persons[j]; - if (f !== p) { - p.friends.push(f); - } - } - session.assert(p); - } - assert.equal(session.agenda.getFocusedAgenda().toArray().length, 16); - for (i = 0, l = persons.length; i < l; i++) { - session.retract(persons[i]); - } - assert.equal(session.agenda.getFocusedAgenda().toArray().length, 0); - }); - }); - - it.describe("with not node", function (it) { - - var called1 = 0, called2 = 0; - var Person = declare({ - instance: { - constructor: function (first, last, friends) { - this.firstName = first; - this.lastName = last; - this.friends = friends || []; - } - } - }); - - var flow = nools.flow("from flow with from and not", function (flow) { - flow.rule("from not rule 1", [ - [Person, "p"], - ["not", Person, "friend", "p != friend && friend.lastName != p.lastName", "from p.friends"] - ], function (facts) { - assert.isUndefined(facts.friend); - called1++; - }); - - flow.rule("from not rule 2", [ - [Person, "p"], - ["not", Person, "friend", "p != friend && friend.lastName == p.lastName", "from p.friends"] - ], function (facts) { - assert.isUndefined(facts.friend); - called2++; - }); - }); - - it.should("only fullfill if all facts evaluate to false", function () { - var session = flow.getSession(); - var persons = [ - new Person("bob", "yukon"), - new Person("andy", "yukon"), - new Person("andrew", "yukon"), - new Person("billy", "yukon"), - new Person("sally", "yukon") - ]; - //create graph - for (var i = 0, l = persons.length; i < l; i++) { - var p = persons[i], f; - for (var j = 0, l2 = persons.length; j < l2; j++) { - f = persons[j]; -// if (f !== p) { - p.friends.push(f); -// } - } - session.assert(p); - } - return session.match().then(function () { - assert.equal(called1, 5); - assert.equal(called2, 0); - called1 = called2 = 0; - session.modify(persons[0], function () { - this.lastName = "yukon"; - }); - session.modify(persons[1], function () { - this.lastName = "yuko"; - }); - session.modify(persons[2], function () { - this.lastName = "yuk"; - }); - session.modify(persons[3], function () { - this.lastName = "yu"; - }); - session.modify(persons[4], function () { - this.lastName = "y"; - }); - - return session.match().then(function () { - assert.equal(called1, 0); - assert.equal(called2, 5); - called1 = called2 = 0; - session.modify(persons[0], function () { - this.lastName = "yukon"; - }); - session.modify(persons[1], function () { - this.lastName = "yukon"; - }); - session.modify(persons[2], function () { - this.lastName = "yukon"; - }); - session.modify(persons[3], function () { - this.lastName = "yukon"; - }); - session.modify(persons[4], function () { - this.lastName = "yukon"; - }); - session.modify(persons[0], function () { - this.lastName = "yukon"; - }); - session.modify(persons[1], function () { - this.lastName = "yuko"; - }); - session.modify(persons[2], function () { - this.lastName = "yuk"; - }); - session.modify(persons[3], function () { - this.lastName = "yu"; - }); - session.modify(persons[4], function () { - this.lastName = "y"; - }); - return session.match().then(function () { - assert.equal(called1, 0); - assert.equal(called2, 5); - }); - }); - }); - }); - - it.should("only fullfill if all facts evaluate to false", function () { - called1 = 0, called2 = 0; - var session = flow.getSession(); - var persons = [ - new Person("bob", "yukon"), - new Person("andy", "yukon"), - new Person("andrew", "yukon"), - new Person("billy", "yukon"), - new Person("sally", "yukon"), - new Person("sally", "yukons") - ]; - //create graph - for (var i = 0, l = persons.length; i < l; i++) { - var p = persons[i], f; - for (var j = 0, l2 = persons.length; j < l2; j++) { - f = persons[j]; - p.friends.push(f); - } - session.assert(p); - } - return session.match().then(function () { - assert.equal(called1, 0); - assert.equal(called2, 1); - }); - }); - }); - - }); - - - it.describe("scope option", function (it) { - - function isEqualTo(str, eq) { - return str === eq; - } - - var Count = function () { - this.called = 0; - }, called = new Count(); - - var flow = nools.flow("scope test", function (flow) { - flow.rule("hello rule", {scope: {isEqualTo: isEqualTo}}, [ - ["or", - [String, "s", "isEqualTo(s, 'hello')"], - [String, "s", "isEqualTo(s, 'world')"] - ], - [Count, "called", null] - ], function (facts) { - facts.called.called++; - }); - }); - - it.should("call when a string equals 'hello'", function () { - return flow.getSession("world", called).match().then(function () { - assert.equal(called.called, 1); - }); - }); - - it.should("call when a string equals 'world'", function () { - called = new Count(); - return flow.getSession("hello", called).match().then(function () { - assert.equal(called.called, 1); - }); - }); - - it.should(" not call when a string that does equal 'hello' or 'world", function () { - called = new Count(); - return flow.getSession("hello", "world", "test", called).match().then(function () { - assert.equal(called.called, 2); - }); - - }); - - }); - - it.describe("events", function (it) { - - it.timeout(1000); - - function Message(m) { - this.message = m; - } - - var session, flow = nools.flow("Simple", function (flow) { - flow.rule("Hello", [Message, "m", "m.message =~ /^hello(\\s*world)?$/"], function (facts) { - this.modify(facts.m, function () { - this.message += " goodbye"; - }); - }); - - flow.rule("Goodbye", [Message, "m", "m.message =~ /.*goodbye$/"], function () { - }); - - }); - - it.beforeEach(function () { - session = flow.getSession(); - }); - - it.should("emit when facts are asserted", function (next) { - var m = new Message("hello"); - session.once("assert", function (fact) { - assert.deepEqual(fact, m); - next(); - }); - session.assert(m); - }); - - it.should("emit when facts are retracted", function (next) { - var m = new Message("hello"); - session.once("retract", function (fact) { - assert.deepEqual(fact, m); - next(); - }); - session.assert(m); - session.retract(m); - }); - - it.should("emit when facts are modified", function (next) { - var m = new Message("hello"); - session.once("modify", function (fact) { - assert.deepEqual(fact, m); - next(); - }); - session.assert(m); - session.modify(m); - }); - - it.should("emit when rules are fired", function (next) { - var m = new Message("hello"); - var fire = [ - ["Hello", "hello"], - ["Goodbye", "hello goodbye"] - ], i = 0; - session.on("fire", function (name, facts) { - assert.equal(name, fire[i][0]); - assert.equal(facts.m.message, fire[i++][1]); - }); - session.assert(m); - session.match(function () { - assert.equal(i, fire.length); - next(); - }); - - }); - - }); - - it.describe("agenda-groups", function (it) { - - function Message(name) { - this.name = name; - } - - var flow = nools.flow("agendGroups", function () { - this.rule("Hello World", {agendaGroup: "ag1"}, [Message, "m", "m.name == 'hello'"], function (facts) { - this.modify(facts.m, function () { - this.name = "goodbye"; - }); - }); - - this.rule("Hello World 2", {agendaGroup: "ag2"}, [Message, "m", "m.name == 'hello'"], function (facts) { - this.modify(facts.m, function () { - this.name = "goodbye"; - }); - }); - - this.rule("GoodBye", {agendaGroup: "ag1"}, [Message, "m", "m.name == 'goodbye'"], function (facts) { - //noop - }); - - this.rule("GoodBye 2", {agendaGroup: "ag2"}, [Message, "m", "m.name == 'goodbye'"], function (facts) { - //noop - }); - }), - session; - - it.beforeEach(function () { - session = flow.getSession(); - }); - - it.should("only fire events in focused group", function () { - var events = []; - session.assert(new Message("hello")); - session.focus("ag1"); - session.on("fire", function (name) { - events.push(name); - }); - return session.match() - .then(function () { - assert.deepEqual(events, ["Hello World", "GoodBye"]); - events = []; - session = flow.getSession(); - session.assert(new Message("hello")); - session.focus("ag2"); - session.on("fire", function (name) { - events.push(name); - }); - return session.match().then(function () { - assert.deepEqual(events, ["Hello World 2", "GoodBye 2"]); - }); - }); - }); - - it.should("should treat focus like a stack", function () { - var events = []; - session.assert(new Message("hello")); - session.focus("ag2"); - session.focus("ag1"); - session.on("fire", function (name) { - events.push(name); - }); - return session.match() - .then(function () { - assert.deepEqual(events, ["Hello World", "GoodBye", "GoodBye 2"]); - events = []; - session = flow.getSession(); - session.assert(new Message("hello")); - session.focus("ag1"); - session.focus("ag2"); - session.on("fire", function (name) { - events.push(name); - }); - return session.match().then(function () { - assert.deepEqual(events, ["Hello World 2", "GoodBye 2", "GoodBye"]); - }); - }); - }); - }); - - it.describe("auto-focus", function (it) { - /*jshint indent*/ - function State(name, state) { - this.name = name; - this.state = state; - } - - var flow = nools.flow("autoFocus", function () { - - this.rule("Bootstrap", [State, "a", "a.name == 'A' && a.state == 'NOT_RUN'"], function (facts) { - this.modify(facts.a, function () { - this.state = 'FINISHED'; - }); - }); - - this.rule("A to B", - [ - [State, "a", "a.name == 'A' && a.state == 'FINISHED'"], - [State, "b", "b.name == 'B' && b.state == 'NOT_RUN'"] - ], - function (facts) { - this.modify(facts.b, function () { - this.state = "FINISHED"; - }); - }); - - this.rule("B to C", - {agendaGroup: "B to C", autoFocus: true}, - [ - [State, "b", "b.name == 'B' && b.state == 'FINISHED'"], - [State, "c", "c.name == 'C' && c.state == 'NOT_RUN'"] - ], - function (facts) { - this.modify(facts.c, function () { - this.state = 'FINISHED'; - }); - this.focus("B to D"); - }); - - this.rule("B to D", - {agendaGroup: "B to D"}, - [ - [State, "b", "b.name == 'B' && b.state == 'FINISHED'"], - [State, "d", "d.name == 'D' && d.state == 'NOT_RUN'"] - ], - function (facts) { - this.modify(facts.d, function () { - this.state = 'FINISHED'; - }); - }); - }), - session; - - it.beforeEach(function () { - session = flow.getSession(); - }); - - it.should("activate agenda groups in proper order", function () { - session.assert(new State("A", "NOT_RUN")); - session.assert(new State("B", "NOT_RUN")); - session.assert(new State("C", "NOT_RUN")); - session.assert(new State("D", "NOT_RUN")); - var fired = []; - session.on("fire", function (name) { - fired.push(name); - }); - return session.match().then(function () { - assert.deepEqual(fired, ["Bootstrap", "A to B", "B to C", "B to D"]); - }); - }); - }); - - it.describe("salience", function (it) { - /*jshint indent*/ - function Message(name) { - this.name = name; - } - - var flow1 = nools.flow("salience1", function () { - - this.rule("Hello4", {salience: 7}, [Message, "m", "m.name == 'Hello'"], function (facts) { - }); - - this.rule("Hello3", {salience: 8}, [Message, "m", "m.name == 'Hello'"], function (facts) { - }); - - this.rule("Hello2", {salience: 9}, [Message, "m", "m.name == 'Hello'"], function (facts) { - }); - - this.rule("Hello1", {salience: 10}, [Message, "m", "m.name == 'Hello'"], function (facts) { - }); - }), - flow2 = nools.flow("salience2", function () { - - this.rule("Hello4", {salience: 10}, [Message, "m", "m.name == 'Hello'"], function (facts) { - }); - - this.rule("Hello3", {salience: 9}, [Message, "m", "m.name == 'Hello'"], function (facts) { - }); - - this.rule("Hello2", {salience: 8}, [Message, "m", "m.name == 'Hello'"], function (facts) { - }); - - this.rule("Hello1", {salience: 7}, [Message, "m", "m.name == 'Hello'"], function (facts) { - }); - }); - - - it.should("activate in the proper order", function () { - var fired1 = [], fired2 = []; - var session1 = flow1.getSession(new Message("Hello")).on("fire", function (name) { - fired1.push(name); - }), - session2 = flow2.getSession(new Message("Hello")).on("fire", function (name) { - fired2.push(name); - }); - return session1.match() - .then(function () { - return session2.match(); - }) - .then(function () { - assert.deepEqual(fired1, ["Hello1", "Hello2", "Hello3", "Hello4"]); - assert.deepEqual(fired2, ["Hello4", "Hello3", "Hello2", "Hello1"]); - }); - }); - }); - - it.describe("async actions", function (it) { - - var flow; - - it.timeout(2000); - - function Message(m) { - this.message = m; - } - - - it.beforeAll(function () { - flow = nools.flow("async flow", function () { - this.rule("Hello", [Message, "m", "m.message == 'hello'"], function (facts, engine, next) { - setTimeout(function () { - next(); - }, 500); - }); - - this.rule("Goodbye", [Message, "m", "m.message == 'hello goodbye'"], function (facts, engine, next) { - setTimeout(function () { - next(); - }, 500); - }); - - }); - }); - - it.should("fire all rules", function () { - var fired = []; - var session = flow.getSession(new Message("hello"), new Message("hello goodbye")) - .on("fire", function (name) { - fired.push(name); - }); - return session.match().then(function () { - assert.deepEqual(fired, ["Goodbye", "Hello"]); - }) - }); - - }); - - it.describe("#matchUntilHalt", function (it) { - function Message(m) { - this.message = m; - } - - function Count(c) { - this.count = c; - } - - var session, flow = nools.flow("Halt Flow", function (flow) { - - flow.rule("Stop", [Count, "c", "c.count == 6"], function () { - this.halt(); - }); - - flow.rule("Hello", [ - [Count, "c"], - [Message, "m", "m.message =~ /^hello(\\s*world)?$/"] - ], function (facts) { - this.modify(facts.m, function () { - this.message += " goodbye"; - }); - this.modify(facts.c, function () { - this.count++; - }); - }); - - flow.rule("Goodbye", [ - [Count, "c"], - [Message, "m", "m.message =~ /.*goodbye$/"] - ], function (facts) { - this.retract(facts.m); - this.modify(facts.c, function () { - this.count++; - }); - }); - - }); - - it.beforeEach(function () { - session = flow.getSession(); - }); - - it.should("match until halt is called", function () { - var count = 0, called = new Count(0); - var interval = setInterval(function () { - if (count++ >= 3) { - clearInterval(interval); - } else { - session.assert(new Message("hello")); - } - }, 50); - session.assert(called); - return session.matchUntilHalt().then(function (err) { - assert.isUndefinedOrNull(err); - assert.equal(called.count, 6); - }); - - }); - }); - - it.describe("fibonacci", function (it) { - - var Fibonacci = declare({ - instance: { - constructor: function (sequence, value) { - this.sequence = sequence; - this.value = value || -1; - } - } - }); - var result = null; - var flow = nools.flow("Fibonacci Flow", function (flow) { - - flow.rule("Recurse", [ - ["not", Fibonacci, "nf", "nf.sequence == 1"], - [Fibonacci, "f", "f.value == -1"] - ], function (facts) { - var f2 = new Fibonacci(facts.f.sequence - 1); - this.assert(f2); - }); - - flow.rule("Bootstrap", [Fibonacci, "f", "f.value == -1 && (f.sequence == 1 || f.sequence == 2)"], function (facts) { - this.modify(facts.f, function () { - this.value = 1; - }); - }); - - flow.rule("Calculate", [ - [Fibonacci, "f1", "f1.value != -1", {sequence: "s1"}], - [Fibonacci, "f2", "f2.value != -1 && f2.sequence == s1 + 1", {sequence: "s2"}], - [Fibonacci, "f3", "f3.value == -1 && f3.sequence == s2 + 1"] - ], function (facts) { - facts.f3.value = facts.f1.value + facts.f2.value; - result = facts.f3.value; - this.modify(facts.f3); - }); - }); - - - it.afterEach(function () { - result = []; - }); - - - it.should("calculate fibonacci 3", function () { - return flow.getSession(new Fibonacci(3)).match() - .then(function () { - assert.equal(result, 2); - }); - }); - - it.should("calculate fibonacci 4", function () { - return flow.getSession(new Fibonacci(4)).match().then(function () { - assert.equal(result, 3); - }); - }); - - it.should("calculate fibonacci 5", function () { - return flow.getSession(new Fibonacci(5)).match() - .then(function () { - assert.equal(result, 5); - }); - }); - - it.should("calculate fibonacci 6", function () { - return flow.getSession(new Fibonacci(6)).match() - .then(function () { - assert.equal(result, 8); - }); - }); - - }); - - it.describe("diagnosis", function (it) { - - var Patient = declare({ - instance: { - constructor: function (name, fever, spots, rash, soreThroat, innoculated) { - this.name = name; - this.fever = fever; - this.spots = spots; - this.rash = rash; - this.soreThroat = soreThroat; - this.innoculated = innoculated; - } - } - }); - - var Diagnosis = declare({ - instance: { - constructor: function (name, diagnosis) { - this.name = name; - this.diagnosis = diagnosis; - } - } - }); - - var Treatment = declare({ - instance: { - constructor: function (name, treatment) { - this.name = name; - this.treatment = treatment; - } - } - }); - - var results = []; - var flow = nools.flow("Diagnosis", function (flow) { - - flow.rule("Measels", [ - [Patient, "p", "p.fever == 'high' && p.spots == true && p.innoculated == true", {name: "n"}], - ["not", Diagnosis, "d", "d.name == n && d.diagnosis == 'allergy'"] - ], - function (facts) { - var name = facts.n; - this.assert(new Diagnosis(name, "measles")); - }); - - flow.rule("Allergy1", [ - [Patient, "p", "p.spots == true", {name: "n"}], - ["not", Diagnosis, "d", "d.name == n && d.diagnosis == 'measles'"] - ], function (facts) { - var name = facts.n; - this.assert(new Diagnosis(name, "allergy")); - }); - - flow.rule("Allergy2", [Patient, "p", "p.rash == true", {name: "n"}], function (facts) { - var name = facts.n; - this.assert(new Diagnosis(name, "allergy")); - }); - - flow.rule("Flu", [Patient, "p", "p.soreThroat == true && p.fever in ['mild', 'high']", {name: "n"}], function (facts) { - var name = facts.n; - this.assert(new Diagnosis(name, "flu")); - }); - - flow.rule("Penicillin", [Diagnosis, "d", "d.diagnosis == 'measles'", {name: "n"}], function (facts) { - var name = facts.n; - this.assert(new Treatment(name, "penicillin")); - }); - - flow.rule("Allergy Pills", [Diagnosis, "d", "d.diagnosis == 'allergy'", {name: "n"}], function (facts) { - var name = facts.n; - this.assert(new Treatment(name, "allegryShot")); - }); - - flow.rule("Bed Rest", [Diagnosis, "d", "d.diagnosis == 'flu'", {name: "n"}], function (facts) { - var name = facts.n; - this.assert(new Treatment(name, "bedRest")); - }); - - flow.rule("Collect", [Treatment, "t"], function (facts) { - results.push(facts.t); - }); - - }); - - it.afterEach(function () { - results = []; - }); - - it.should("treat properly", function () { - var session = flow.getSession(); - session.assert(new Patient("Fred", "none", true, false, false, false)); - session.assert(new Patient("Joe", "high", false, false, true, false)); - session.assert(new Patient("Bob", "high", true, false, false, true)); - session.assert(new Patient("Tom", "none", false, true, false, false)); - return session.match().then(function () { - session.dispose(); - assert.deepEqual(results, [ - {"name": "Tom", "treatment": "allegryShot"}, - {"name": "Bob", "treatment": "penicillin"}, - {"name": "Joe", "treatment": "bedRest"}, - {"name": "Fred", "treatment": "allegryShot"} - ]); - }); - }); - - }); - -}); \ No newline at end of file diff --git a/test/flow/agendaGroups.test.js b/test/flow/agendaGroups.test.js new file mode 100644 index 0000000..10d7e01 --- /dev/null +++ b/test/flow/agendaGroups.test.js @@ -0,0 +1,158 @@ +"use strict"; +var it = require("it"), + assert = require("assert"), + nools = require("../../"); + +it.describe("agenda-groups", function (it) { + + function Message(name) { + this.name = name; + } + + var flow = nools.flow("agendGroups", function () { + this.rule("Hello World", {agendaGroup: "ag1"}, [Message, "m", "m.name == 'hello'"], function (facts) { + this.modify(facts.m, function () { + this.name = "goodbye"; + }); + }); + + this.rule("Hello World 2", {agendaGroup: "ag2"}, [Message, "m", "m.name == 'hello'"], function (facts) { + this.modify(facts.m, function () { + this.name = "goodbye"; + }); + }); + + this.rule("GoodBye", {agendaGroup: "ag1"}, [Message, "m", "m.name == 'goodbye'"], function (facts) { + //noop + }); + + this.rule("GoodBye 2", {agendaGroup: "ag2"}, [Message, "m", "m.name == 'goodbye'"], function (facts) { + //noop + }); + }), + session; + + it.beforeEach(function () { + session = flow.getSession(); + }); + + it.should("only fire events in focused group", function () { + var events = []; + session.assert(new Message("hello")); + session.focus("ag1"); + session.on("fire", function (name) { + events.push(name); + }); + return session.match() + .then(function () { + assert.deepEqual(events, ["Hello World", "GoodBye"]); + events = []; + session = flow.getSession(); + session.assert(new Message("hello")); + session.focus("ag2"); + session.on("fire", function (name) { + events.push(name); + }); + return session.match().then(function () { + assert.deepEqual(events, ["Hello World 2", "GoodBye 2"]); + }); + }); + }); + + it.should("should treat focus like a stack", function () { + var events = []; + session.assert(new Message("hello")); + session.focus("ag2"); + session.focus("ag1"); + session.on("fire", function (name) { + events.push(name); + }); + return session.match() + .then(function () { + assert.deepEqual(events, ["Hello World", "GoodBye", "GoodBye 2"]); + events = []; + session = flow.getSession(); + session.assert(new Message("hello")); + session.focus("ag1"); + session.focus("ag2"); + session.on("fire", function (name) { + events.push(name); + }); + return session.match().then(function () { + assert.deepEqual(events, ["Hello World 2", "GoodBye 2", "GoodBye"]); + }); + }); + }); +}); + +it.describe("auto-focus", function (it) { + /*jshint indent*/ + function State(name, state) { + this.name = name; + this.state = state; + } + + var flow = nools.flow("autoFocus", function () { + + this.rule("Bootstrap", [State, "a", "a.name == 'A' && a.state == 'NOT_RUN'"], function (facts) { + this.modify(facts.a, function () { + this.state = 'FINISHED'; + }); + }); + + this.rule("A to B", + [ + [State, "a", "a.name == 'A' && a.state == 'FINISHED'"], + [State, "b", "b.name == 'B' && b.state == 'NOT_RUN'"] + ], + function (facts) { + this.modify(facts.b, function () { + this.state = "FINISHED"; + }); + }); + + this.rule("B to C", + {agendaGroup: "B to C", autoFocus: true}, + [ + [State, "b", "b.name == 'B' && b.state == 'FINISHED'"], + [State, "c", "c.name == 'C' && c.state == 'NOT_RUN'"] + ], + function (facts) { + this.modify(facts.c, function () { + this.state = 'FINISHED'; + }); + this.focus("B to D"); + }); + + this.rule("B to D", + {agendaGroup: "B to D"}, + [ + [State, "b", "b.name == 'B' && b.state == 'FINISHED'"], + [State, "d", "d.name == 'D' && d.state == 'NOT_RUN'"] + ], + function (facts) { + this.modify(facts.d, function () { + this.state = 'FINISHED'; + }); + }); + }), + session; + + it.beforeEach(function () { + session = flow.getSession(); + }); + + it.should("activate agenda groups in proper order", function () { + session.assert(new State("A", "NOT_RUN")); + session.assert(new State("B", "NOT_RUN")); + session.assert(new State("C", "NOT_RUN")); + session.assert(new State("D", "NOT_RUN")); + var fired = []; + session.on("fire", function (name) { + fired.push(name); + }); + return session.match().then(function () { + assert.deepEqual(fired, ["Bootstrap", "A to B", "B to C", "B to D"]); + }); + }); +}); \ No newline at end of file diff --git a/test/flow/async.test.js b/test/flow/async.test.js new file mode 100644 index 0000000..1d48da0 --- /dev/null +++ b/test/flow/async.test.js @@ -0,0 +1,45 @@ +"use strict"; +var it = require("it"), + nools = require("../../"), + assert = require("assert"); + +it.describe("async actions", function (it) { + + var flow; + + it.timeout(2000); + + function Message(m) { + this.message = m; + } + + + it.beforeAll(function () { + flow = nools.flow("async flow", function () { + this.rule("Hello", [Message, "m", "m.message == 'hello'"], function (facts, engine, next) { + setTimeout(function () { + next(); + }, 500); + }); + + this.rule("Goodbye", [Message, "m", "m.message == 'hello goodbye'"], function (facts, engine, next) { + setTimeout(function () { + next(); + }, 500); + }); + + }); + }); + + it.should("fire all rules", function () { + var fired = []; + var session = flow.getSession(new Message("hello"), new Message("hello goodbye")) + .on("fire", function (name) { + fired.push(name); + }); + return session.match().then(function () { + assert.deepEqual(fired, ["Goodbye", "Hello"]); + }) + }); + +}); \ No newline at end of file diff --git a/test/flow/events.test.js b/test/flow/events.test.js new file mode 100644 index 0000000..93085c3 --- /dev/null +++ b/test/flow/events.test.js @@ -0,0 +1,77 @@ +"use strict"; +var it = require("it"), + assert = require("assert"), + nools = require("../../"); + +it.describe("events", function (it) { + + it.timeout(1000); + + function Message(m) { + this.message = m; + } + + var session, flow = nools.flow("Simple", function (flow) { + flow.rule("Hello", [Message, "m", "m.message =~ /^hello(\\s*world)?$/"], function (facts) { + this.modify(facts.m, function () { + this.message += " goodbye"; + }); + }); + + flow.rule("Goodbye", [Message, "m", "m.message =~ /.*goodbye$/"], function () { + }); + + }); + + it.beforeEach(function () { + session = flow.getSession(); + }); + + it.should("emit when facts are asserted", function (next) { + var m = new Message("hello"); + session.once("assert", function (fact) { + assert.deepEqual(fact, m); + next(); + }); + session.assert(m); + }); + + it.should("emit when facts are retracted", function (next) { + var m = new Message("hello"); + session.once("retract", function (fact) { + assert.deepEqual(fact, m); + next(); + }); + session.assert(m); + session.retract(m); + }); + + it.should("emit when facts are modified", function (next) { + var m = new Message("hello"); + session.once("modify", function (fact) { + assert.deepEqual(fact, m); + next(); + }); + session.assert(m); + session.modify(m); + }); + + it.should("emit when rules are fired", function (next) { + var m = new Message("hello"); + var fire = [ + ["Hello", "hello"], + ["Goodbye", "hello goodbye"] + ], i = 0; + session.on("fire", function (name, facts) { + assert.equal(name, fire[i][0]); + assert.equal(facts.m.message, fire[i++][1]); + }); + session.assert(m); + session.match(function () { + assert.equal(i, fire.length); + next(); + }); + + }); + +}); \ No newline at end of file diff --git a/test/flow/exists.test.js b/test/flow/exists.test.js new file mode 100644 index 0000000..895fecb --- /dev/null +++ b/test/flow/exists.test.js @@ -0,0 +1,291 @@ +"use strict"; +var it = require("it"), + assert = require("assert"), + nools = require("../../"); + +it.describe("exists rule", function (it) { + + var flow; + + var Count = function () { + this.called = 0; + }, called = new Count(); + + it.describe("fact assertion", function (it) { + it.beforeAll(function () { + flow = nools.flow("exists flow", function () { + this.rule("exists 1", [ + ["exists", String, "s1"], + [Count, "c"] + ], function (facts) { + facts.c.called++; + }); + }); + }); + + it.beforeEach(function () { + called.called = 0; + }) + + it.should("only activate once", function () { + return flow.getSession(called, "hello", "world", "hello world").match(function () { + assert.equal(called.called, 1); + }); + }); + + it.should("not activate once if the fact does not exists", function () { + return flow.getSession(called).match(function () { + assert.equal(called.called, 0); + }); + }); + + }); + + it.describe("fact retraction", function (it) { + + function Person(name) { + this.name = name + } + + function Str(val) { + this.val = val; + } + + it.beforeAll(function () { + flow = nools.flow("exists retractions flow", function () { + this.rule("exists 1", [ + [Person, "p"], + ["exists", Str, "s1", "s1.val == p.name"], + [Count, "c"] + ], function (facts) { + facts.c.called++; + } + + ); + }); + }); + + it.beforeEach(function () { + called.called = 0; + }) + + it.should("should handle fact retractions properly", function () { + var session = flow.getSession(called); + var activationTree = session.agenda.rules["exists 1"].tree, + activations, + str1 = new Str("Bob Yuko"), + str2 = new Str("Bob Yukon"), + person = new Person("Bob Yukon"); + session.assert(person); + activations = activationTree.toArray() + assert.lengthOf(activations, 0); + session.assert(str1); + activations = activationTree.toArray() + assert.lengthOf(activations, 0); + session.retract(str1); + activations = activationTree.toArray() + assert.lengthOf(activations, 0); + session.assert(str2); + activations = activationTree.toArray() + assert.lengthOf(activations, 1); + session.retract(str2); + activations = activationTree.toArray() + assert.lengthOf(activations, 0); + session.assert(str2); + activations = activationTree.toArray() + assert.lengthOf(activations, 1); + session.assert(str1); + activations = activationTree.toArray() + assert.lengthOf(activations, 1); + session.retract(str1); + activations = activationTree.toArray() + assert.lengthOf(activations, 1); + session.retract(str2); + activations = activationTree.toArray() + assert.lengthOf(activations, 0); + session.assert(str2); + activations = activationTree.toArray() + assert.lengthOf(activations, 1); + session.retract(person); + activations = activationTree.toArray() + assert.lengthOf(activations, 0); + }); + }); + + it.describe("fact modification", function (it) { + function Person(name) { + this.name = name + } + + function Str(val) { + this.val = val; + } + + it.beforeAll(function () { + flow = nools.flow("exists modification flow", function () { + this.rule("exists 1", [ + [Person, "p"], + ["exists", Str, "s1", "s1.val == p.name"], + [Count, "c"] + ], function (facts) { + facts.c.called++; + } + + ); + }); + }); + + it.beforeEach(function () { + called.called = 0; + }) + + it.should("should handle fact modification properly", function () { + var session = flow.getSession(called); + var activationTree = session.agenda.rules["exists 1"].tree, + activations, + str1 = new Str("Bob Yuko"), + str2 = new Str("Bobby Yukon"), + person = new Person("Bob Yukon"); + session.assert(person); + activations = activationTree.toArray() + assert.lengthOf(activations, 0); + session.assert(str1); + activations = activationTree.toArray() + assert.lengthOf(activations, 0); + session.modify(str1, function () { + this.val = person.name; + }); + activations = activationTree.toArray() + assert.lengthOf(activations, 1); + session.modify(person, function () { + this.name = "Bobby Yukon"; + }); + activations = activationTree.toArray() + assert.lengthOf(activations, 0); + session.assert(str2); + activations = activationTree.toArray() + assert.lengthOf(activations, 1); + }); + }); + + it.describe("with from modifier", function (it) { + function Person(zipcodes) { + this.zipcodes = zipcodes; + } + + it.beforeAll(function () { + flow = nools.flow("exists from flow", function () { + this.rule("exists 1", [ + [Person, "p"], + ["exists", Number, "zip", "zip == 11111", "from p.zipcodes"], + [Count, "c"] + ], function (facts) { + facts.c.called++; + } + + ); + }); + }); + + it.beforeEach(function () { + called.called = 0; + }); + + it.describe("assert", function (it) { + + it.should("should handle fact assertion properly", function () { + var session = flow.getSession(called); + var activationTree = session.agenda.rules["exists 1"].tree, + activations, + person1 = new Person([88888, 99999, 77777]), + person2 = new Person([66666, 55555, 44444]), + person3 = new Person([33333, 22222, 11111]), + person4 = new Person([11111, 11111, 11111]); + session.assert(person1); + activations = activationTree.toArray() + assert.lengthOf(activations, 0); + session.assert(person2); + activations = activationTree.toArray() + assert.lengthOf(activations, 0); + session.assert(person3); + activations = activationTree.toArray() + assert.lengthOf(activations, 1); + session.assert(person4); + activations = activationTree.toArray() + assert.lengthOf(activations, 2); + }); + }); + + it.describe("retract", function (it) { + + it.should("should handle fact retraction properly", function () { + var session = flow.getSession(called); + var activationTree = session.agenda.rules["exists 1"].tree, + activations, + person1 = new Person([88888, 99999, 77777]), + person2 = new Person([66666, 55555, 44444]), + person3 = new Person([33333, 22222, 11111]), + person4 = new Person([11111, 11111, 11111]); + session.assert(person1); + activations = activationTree.toArray(); + assert.lengthOf(activations, 0); + session.assert(person2); + activations = activationTree.toArray(); + assert.lengthOf(activations, 0); + session.assert(person3); + activations = activationTree.toArray(); + assert.lengthOf(activations, 1); + session.assert(person4); + activations = activationTree.toArray(); + assert.lengthOf(activations, 2); + session.retract(person3); + activations = activationTree.toArray(); + assert.lengthOf(activations, 1); + session.retract(person4); + activations = activationTree.toArray(); + assert.lengthOf(activations, 0); + }); + }); + + it.describe("modify", function (it) { + + it.should("should handle fact modification properly", function () { + var session = flow.getSession(called); + var activationTree = session.agenda.rules["exists 1"].tree, + activations, + person1 = new Person([88888, 99999, 77777]), + person2 = new Person([66666, 55555, 44444]), + person3 = new Person([33333, 22222, 11111]), + person4 = new Person([11111, 11111, 11111]); + session.assert(person1); + activations = activationTree.toArray(); + assert.lengthOf(activations, 0); + session.assert(person2); + activations = activationTree.toArray(); + assert.lengthOf(activations, 0); + session.assert(person3); + activations = activationTree.toArray(); + assert.lengthOf(activations, 1); + session.assert(person4); + activations = activationTree.toArray(); + assert.lengthOf(activations, 2); + session.modify(person3, function () { + this.zipcodes = [11111, 11111]; + }); + activations = activationTree.toArray(); + assert.lengthOf(activations, 2); + session.modify(person3, function () { + this.zipcodes = [88888]; + }); + activations = activationTree.toArray(); + assert.lengthOf(activations, 1); + session.modify(person4, function () { + this.zipcodes = [88888]; + }); + activations = activationTree.toArray(); + assert.lengthOf(activations, 0); + + }); + }); + }); +}); \ No newline at end of file diff --git a/test/flow/from.test.js b/test/flow/from.test.js new file mode 100644 index 0000000..355945a --- /dev/null +++ b/test/flow/from.test.js @@ -0,0 +1,565 @@ +"use strict"; +var it = require("it"), + assert = require("assert"), + declare = require("declare.js"), + dateExtended = require("date-extended"), + nools = require("../../"); + +it.describe("from condition", function (it) { + + it.describe("with non array properties", function (it) { + + var called = 0; + var Address = declare({ + instance: { + constructor: function (zip) { + this.zipcode = zip; + } + } + }); + var Person = declare({ + instance: { + constructor: function (first, last, address) { + this.firstName = first; + this.lastName = last; + this.address = address; + } + } + }); + + var flow = nools.flow("from flow", function (flow) { + flow.rule("from rule 1", [ + [Person, "p"], + [Address, "a", "a.zipcode == 88847", "from p.address"], + [String, "first", "first == 'bob'", "from p.firstName"], + [String, "last", "last == 'yukon'", "from p.lastName"] + ], function (facts) { + assert.equal(facts.a, facts.p.address); + assert.equal(facts.a.zipcode, 88847); + assert.equal(facts.first, "bob"); + assert.equal(facts.last, "yukon"); + called++; + }); + + flow.rule("from rule 2", [ + [Person, "p"], + [Address, "a", "a.zipcode == 88845", "from p.address"], + [String, "first", "first == 'bob'", "from p.firstName"], + [String, "last", "last == 'yukon'", "from p.lastName"] + ], function (facts) { + assert.equal(facts.a, facts.p.address); + assert.equal(facts.a.zipcode, 88845); + assert.equal(facts.first, "bob"); + assert.equal(facts.last, "yukon"); + called++; + }); + + flow.rule("from rule 3", [ + [Person, "p"], + [Address, "a", "a.zipcode == 88847", "from p.address"], + [String, "first", "first == 'sally'", "from p.firstName"], + [String, "last", "last == 'yukon'", "from p.lastName"] + ], function (facts) { + assert.equal(facts.a, facts.p.address); + assert.equal(facts.a.zipcode, 88847); + assert.equal(facts.first, "sally"); + assert.equal(facts.last, "yukon"); + called++; + }); + + flow.rule("from rule 4", [ + [Person, "p"], + [Address, "a", "a.zipcode == 88845", "from p.address"], + [String, "first", "first == 'sally'", "from p.firstName"], + [String, "last", "last == 'yukons'", "from p.lastName"] + ], function (facts) { + assert.equal(facts.a, facts.p.address); + assert.equal(facts.a.zipcode, 88845); + assert.equal(facts.first, "sally"); + assert.equal(facts.last, "yukons"); + called++; + }); + }); + + it.should("create the proper match contexts", function () { + var session = flow.getSession(); + session.assert(new Person("bob", "yukon", new Address(88847))); + session.assert(new Person("sally", "yukons", new Address(88847))); + return session.match().then(function () { + assert.equal(called, 1); + }); + }); + + it.should("propagate modified facts properly", function () { + var fired = []; + var session = flow.getSession() + .on("fire", function (name, rule) { + fired.push(name); + }); + var p = new Person("bob", "yukon", new Address(88847)); + session.assert(p); + return session.match().then(function () { + assert.deepEqual(fired, ["from rule 1"]); + fired.length = 0; + session.modify(p, function () { + this.address = new Address(88845) + }); + return session.match().then(function () { + assert.deepEqual(fired, ["from rule 2"]); + fired.length = 0; + session.modify(p, function () { + this.address = new Address(88847); + this.firstName = "sally"; + }); + return session.match().then(function () { + assert.deepEqual(fired, ["from rule 3"]); + fired.length = 0; + session.modify(p, function () { + this.address = new Address(88845); + this.lastName = "yukons" + }); + return session.match().then(function () { + assert.deepEqual(fired, ["from rule 4"]); + fired.length = 0; + }); + }); + }); + }); + }); + + it.should("retract facts properly", function () { + var session = flow.getSession(); + var p = new Person("bob", "yukon", new Address(88847)); + session.assert(p); + assert.equal(session.agenda.peek().name, "from rule 1"); + session.retract(p); + assert.isTrue(session.agenda.isEmpty()); + }); + }); + + it.describe("with js source", function (it) { + + var called = 0; + + function MyValue(n2) { + this.value = n2; + } + + var flow = nools.flow("from flow js source", function (flow) { + flow.rule("from rule 1", [ + [MyValue, "n1"], + [Number, "n2", "n1.value == n2", "from [1,2,3,4,5]"] + ], function (facts) { + assert.equal(facts.n1.value, facts.n2); + assert.isTrue([1, 2, 3, 4, 5].indexOf(facts.n2) !== -1); + called++; + }); + + flow.rule("from rule 2", [ + [MyValue, "n1"], + [String, "n2", "n1.value == n2", "from ['a' ,'b', 'c', 'd', 'e']"] + ], function (facts) { + assert.equal(facts.n1.value, facts.n2); + assert.isTrue(['a' , 'b', 'c', 'd', 'e', 'f'].indexOf(facts.n2) !== -1); + called++; + }); + + flow.rule("from rule 3 with function", [ + [MyValue, "n1", "isDate(n1.value)"], + [Date, "n2", "dateCmp(n1.value, n2)", "from daysFromNow(1)"] + ], function (facts) { + assert.isDate(facts.n1.value); + assert.isDate(facts.n2); + called++; + }); + + flow.rule("from rule 4 with scope function", { + scope: { + myArr: function () { + return ["f", "g", "h", "i", "j"] + } + } + }, [ + [MyValue, "n1"], + [String, "n2", "n1.value == n2", "from myArr()"] + ], function (facts) { + assert.equal(facts.n1.value, facts.n2); + assert.isTrue(["f", "g", "h", "i", "j"].indexOf(facts.n2) !== -1); + called++; + }); + }); + + it.should("create the proper match contexts", function () { + + var session = flow.getSession( + new MyValue(1), + new MyValue(2), + new MyValue(3), + new MyValue(4), + new MyValue(5), + new MyValue('a'), + new MyValue('b'), + new MyValue('c'), + new MyValue('d'), + new MyValue('e'), + new MyValue(dateExtended.daysFromNow(1)), + new MyValue('f'), + new MyValue('g'), + new MyValue('h'), + new MyValue('i'), + new MyValue('j') + + ); + return session.match().then(function () { + assert.equal(called, 16); + }); + }); + + it.should("propagate modified facts properly", function () { + var fired = []; + var session = flow.getSession() + .on("fire", function (name, rule) { + fired.push(name); + }); + var v = new MyValue(1); + session.assert(v); + return session.match().then(function () { + assert.deepEqual(fired, ["from rule 1"]); + fired.length = 0; + session.modify(v, function () { + this.value = "a"; + }); + return session.match().then(function () { + assert.deepEqual(fired, ["from rule 2"]); + fired.length = 0; + session.modify(v, function () { + this.value = 1; + }); + }); + }); + }); + }); + + it.describe("with array properties", function (it) { + + var called = 0; + var Person = declare({ + instance: { + constructor: function (first, last, friends) { + this.firstName = first; + this.lastName = last; + this.friends = friends || []; + } + } + }); + + var flow = nools.flow("from flow with arrays", function (flow) { + flow.rule("from rule 1", [ + [Person, "p"], + [Person, "friend", "friend.firstName != p.firstName", "from p.friends"], + [String, "first", "first =~ /^a/", "from friend.firstName"] + ], function (facts) { + assert.isTrue(/^a/.test(facts.first)); + called++; + }); + + flow.rule("from rule 2", [ + [Person, "p"], + [Person, "friend", "friend.firstName != p.firstName", "from p.friends"], + [String, "first", "first =~ /^b/", "from friend.firstName"] + ], function (facts) { + assert.isTrue(/^b/.test(facts.first)); + called++; + }); + }); + + it.should("create all cross product matches", function () { + var fired = [], names = []; + var session = flow.getSession() + .on("fire", function (name, facts) { + if (facts.first.match(/^b/)) { + assert.equal(name, "from rule 2"); + } else { + assert.equal(name, "from rule 1"); + } + names.push([facts.p.firstName, facts.first]); + fired.push(name); + }); + var persons = [ + new Person("bob", "yukon"), + new Person("andy", "yukon"), + new Person("andrew", "yukon"), + new Person("billy", "yukon"), + new Person("sally", "yukon") + ]; + //create graph + for (var i = 0, l = persons.length; i < l; i++) { + var p = persons[i], f; + for (var j = 0, l2 = persons.length; j < l2; j++) { + f = persons[j]; + if (f !== p) { + p.friends.push(f); + } + } + session.assert(p); + } + return session.match().then(function () { + assert.equal(called, 16); + assert.deepEqual(fired, [ + 'from rule 1', + 'from rule 1', + 'from rule 2', + 'from rule 2', + 'from rule 1', + 'from rule 1', + 'from rule 2', + 'from rule 1', + 'from rule 2', + 'from rule 2', + 'from rule 1', + 'from rule 2', + 'from rule 2', + 'from rule 1', + 'from rule 1', + 'from rule 2' + ]); + fired.length = 0; + session.modify(persons[0], function () { + this.firstName = "craig"; + }); + session.modify(persons[1], function () { + this.firstName = "sally"; + }); + session.modify(persons[2], function () { + this.firstName = "thede"; + }); + session.modify(persons[3], function () { + this.firstName = "jake"; + }); + session.modify(persons[4], function () { + this.firstName = "john"; + }); + return session.match().then(function () { + assert.lengthOf(fired, 0); + fired.length = 0; + names.length = 0; + session.modify(persons[0], function () { + this.firstName = "bob"; + }); + session.modify(persons[1], function () { + this.firstName = "bobby"; + }); + session.modify(persons[2], function () { + this.firstName = "billy"; + }); + session.modify(persons[3], function () { + this.firstName = "brian"; + }); + session.modify(persons[4], function () { + this.firstName = "bryan"; + }); + return session.match().then(function () { + names.sort(function (a, b) { + return a[0] === b[0] ? a[1] === b[1] ? 0 : a[1] > b[1] ? 1 : -1 : a[0] > b[0] ? 1 : -1; + }); + assert.deepEqual(names, [ + [ 'billy', 'bob' ], + [ 'billy', 'bobby' ], + [ 'billy', 'brian' ], + [ 'billy', 'bryan' ], + [ 'bob', 'billy' ], + [ 'bob', 'bobby' ], + [ 'bob', 'brian' ], + [ 'bob', 'bryan' ], + + [ 'bobby', 'billy' ], + [ 'bobby', 'bob' ], + [ 'bobby', 'brian' ], + [ 'bobby', 'bryan' ], + + [ 'brian', 'billy' ], + [ 'brian', 'bob' ], + [ 'brian', 'bobby' ], + [ 'brian', 'bryan' ], + + [ 'bryan', 'billy' ], + [ 'bryan', 'bob' ], + [ 'bryan', 'bobby' ], + [ 'bryan', 'brian' ] + ]); + assert.lengthOf(fired, 20); + }) + }) + + }); + }); + + it.should("retract all cross product matches", function () { + var session = flow.getSession(); + var persons = [ + new Person("bob", "yukon"), + new Person("andy", "yukon"), + new Person("andrew", "yukon"), + new Person("billy", "yukon"), + new Person("sally", "yukon") + ]; + //create graph + for (var i = 0, l = persons.length; i < l; i++) { + var p = persons[i], f; + for (var j = 0, l2 = persons.length; j < l2; j++) { + f = persons[j]; + if (f !== p) { + p.friends.push(f); + } + } + session.assert(p); + } + assert.equal(session.agenda.getFocusedAgenda().toArray().length, 16); + for (i = 0, l = persons.length; i < l; i++) { + session.retract(persons[i]); + } + assert.equal(session.agenda.getFocusedAgenda().toArray().length, 0); + }); + }); + + it.describe("with not node", function (it) { + + var called1 = 0, called2 = 0; + var Person = declare({ + instance: { + constructor: function (first, last, friends) { + this.firstName = first; + this.lastName = last; + this.friends = friends || []; + } + } + }); + + var flow = nools.flow("from flow with from and not", function (flow) { + flow.rule("from not rule 1", [ + [Person, "p"], + ["not", Person, "friend", "p != friend && friend.lastName != p.lastName", "from p.friends"] + ], function (facts) { + assert.isUndefined(facts.friend); + called1++; + }); + + flow.rule("from not rule 2", [ + [Person, "p"], + ["not", Person, "friend", "p != friend && friend.lastName == p.lastName", "from p.friends"] + ], function (facts) { + assert.isUndefined(facts.friend); + called2++; + }); + }); + + it.should("only fullfill if all facts evaluate to false", function () { + var session = flow.getSession(); + var persons = [ + new Person("bob", "yukon"), + new Person("andy", "yukon"), + new Person("andrew", "yukon"), + new Person("billy", "yukon"), + new Person("sally", "yukon") + ]; + //create graph + for (var i = 0, l = persons.length; i < l; i++) { + var p = persons[i], f; + for (var j = 0, l2 = persons.length; j < l2; j++) { + f = persons[j]; +// if (f !== p) { + p.friends.push(f); +// } + } + session.assert(p); + } + return session.match().then(function () { + assert.equal(called1, 5); + assert.equal(called2, 0); + called1 = called2 = 0; + session.modify(persons[0], function () { + this.lastName = "yukon"; + }); + session.modify(persons[1], function () { + this.lastName = "yuko"; + }); + session.modify(persons[2], function () { + this.lastName = "yuk"; + }); + session.modify(persons[3], function () { + this.lastName = "yu"; + }); + session.modify(persons[4], function () { + this.lastName = "y"; + }); + + return session.match().then(function () { + assert.equal(called1, 0); + assert.equal(called2, 5); + called1 = called2 = 0; + session.modify(persons[0], function () { + this.lastName = "yukon"; + }); + session.modify(persons[1], function () { + this.lastName = "yukon"; + }); + session.modify(persons[2], function () { + this.lastName = "yukon"; + }); + session.modify(persons[3], function () { + this.lastName = "yukon"; + }); + session.modify(persons[4], function () { + this.lastName = "yukon"; + }); + session.modify(persons[0], function () { + this.lastName = "yukon"; + }); + session.modify(persons[1], function () { + this.lastName = "yuko"; + }); + session.modify(persons[2], function () { + this.lastName = "yuk"; + }); + session.modify(persons[3], function () { + this.lastName = "yu"; + }); + session.modify(persons[4], function () { + this.lastName = "y"; + }); + return session.match().then(function () { + assert.equal(called1, 0); + assert.equal(called2, 5); + }); + }); + }); + }); + + it.should("only fullfill if all facts evaluate to false", function () { + called1 = 0, called2 = 0; + var session = flow.getSession(); + var persons = [ + new Person("bob", "yukon"), + new Person("andy", "yukon"), + new Person("andrew", "yukon"), + new Person("billy", "yukon"), + new Person("sally", "yukon"), + new Person("sally", "yukons") + ]; + //create graph + for (var i = 0, l = persons.length; i < l; i++) { + var p = persons[i], f; + for (var j = 0, l2 = persons.length; j < l2; j++) { + f = persons[j]; + p.friends.push(f); + } + session.assert(p); + } + return session.match().then(function () { + assert.equal(called1, 0); + assert.equal(called2, 1); + }); + }); + }); + +}); \ No newline at end of file diff --git a/test/flow/index.js b/test/flow/index.js new file mode 100644 index 0000000..883c739 --- /dev/null +++ b/test/flow/index.js @@ -0,0 +1,14 @@ +require("./agendaGroups.test"); +require("./async.test"); +require("./events.test"); +require("./exists.test"); +require("./from.test"); +require("./matchUntil.halt"); +require("./not.test"); +require("./or.test"); +require("./rule.test"); +require("./salience.test"); +require("./scope.test"); +require("./simple.test"); + +//require("it").run(); \ No newline at end of file diff --git a/test/flow/leftMemory.test.js b/test/flow/leftMemory.test.js new file mode 100644 index 0000000..0e4307e --- /dev/null +++ b/test/flow/leftMemory.test.js @@ -0,0 +1,131 @@ +var it = require("it"), + assert = require("assert"), + Context = require("../../lib/context"), + WorkingMemory = require("../../lib/workingMemory").WorkingMemory, + LeftMemory = require("../../lib/nodes/misc/leftMemory"); + +it.describe("BetaNode RightMemory", function (it) { + + it.should("add a context to the memory", function () { + var wm = new WorkingMemory(), + lm = new LeftMemory(), + fact = wm.assertFact("s"), + context = new Context(fact); + lm.push(context); + assert.equal(lm.length, 1); + + }); + + it.should("remove a context from the memory", function () { + var wm = new WorkingMemory(), + lm = new LeftMemory(), + fact = wm.assertFact("s"), + context = new Context(fact); + var node = lm.push(context); + assert.equal(lm.length, 1); + lm.remove(node); + assert.equal(lm.length, 0); + }); + + it.should("addIndexes to the memory", function () { + var lm = new LeftMemory(); + lm.addIndex("s.a", "a.s"); + assert.lengthOf(lm.indexes, 1); + var index = lm.indexes[0]; + assert.equal(index[0], "s.a"); + assert.equal(index[1], "a.s"); + assert.isFunction(index[2]); + assert.isFunction(index[3]); + assert.equal(index[4], "eq"); + assert.deepEqual(index[2]({s: {a: 1}}), 1); + assert.deepEqual(index[3]({a: {s: 1}}), 1); + }); + + it.should("add an index and accept an operator", function () { + var lm = new LeftMemory(); + lm.addIndex("s.a", "a.s", "neq"); + assert.lengthOf(lm.indexes, 1); + var index = lm.indexes[0]; + assert.equal(index[0], "s.a"); + assert.equal(index[1], "a.s"); + assert.isFunction(index[2]); + assert.isFunction(index[3]); + assert.equal(index[4], "neq"); + assert.deepEqual(index[2]({s: {a: 1}}), 1); + assert.deepEqual(index[3]({a: {s: 1}}), 1); + }); + + it.should("add a context and index it", function () { + var wm = new WorkingMemory(), + lm = new LeftMemory(), + leftFact = wm.assertFact({a: 1}), + leftContext = new Context(leftFact); + leftContext.set("s", {a: 1}); + lm.addIndex("s.a", "a.s"); + var node = lm.push(leftContext); + assert.equal(lm.length, 1); + assert.isTrue("s.a" in lm.tables.tables); + assert.isTrue(lm.tables.tables["s.a"].contains(1)); + assert.deepEqual(lm.tables.tables["s.a"].get(1).tuples, [node]); + }); + + it.should("remove a context and unindex it", function () { + var wm = new WorkingMemory(), + rm = new LeftMemory(), + leftFact = wm.assertFact({a: 1}), + leftContext = new Context(leftFact); + leftContext.set("s", {a: 1}); + rm.addIndex("s.a", "a.s"); + var node = rm.push(leftContext); + assert.equal(rm.length, 1); + rm.remove(node); + assert.deepEqual(rm.tables.tables["s.a"].get(1).tuples, []); + }); + + it.describe(".getLeftMemory", function (it) { + it.should("return the correct right memory values", function () { + var wm = new WorkingMemory(), + lm = new LeftMemory(), + rightFact = wm.assertFact({s: 1}), + leftFact = wm.assertFact({a: 1}), + rightContext = new Context(rightFact), + leftContext = new Context(leftFact); + rightContext.set("a", {s: 1}); + leftContext.set("s", {a: 1}); + lm.addIndex("s.a", "a.s"); + var node = lm.push(leftContext); + assert.equal(lm.length, 1); + var nodes = lm.getLeftMemory(rightContext); + assert.lengthOf(nodes, 1); + assert.deepEqual(nodes, [node]); + rightContext.set("a", {s: 2}); + nodes = lm.getLeftMemory(rightContext); + assert.lengthOf(nodes, 0); + }); + + it.should("return the intersection of all indexes", function () { + var wm = new WorkingMemory(), + lm = new LeftMemory(), + rightContext1 = new Context(wm.assertFact({s: 1})), + leftContext1 = new Context(wm.assertFact({a: 1})), + rightContext2 = new Context(wm.assertFact({s: 2})), + leftContext2 = new Context(wm.assertFact({a: 3})); + rightContext1.set("a", {s: 1, b: 2, c: 1}); + leftContext1.set("s", {a: 1, b: 2, c: 2}); + rightContext2.set("a", {s: 1, b: 3, c: 3}); + leftContext2.set("s", {a: 1, b: 4, c: 3}); + debugger; + lm.addIndex("s.c", "a.c", "neq"); + lm.addIndex("s.a", "a.s"); + lm.addIndex("s.b", "a.b"); + var node1 = lm.push(leftContext1); + lm.push(leftContext2); + assert.equal(lm.length, 2); + var nodes = lm.getLeftMemory(rightContext1); + assert.lengthOf(nodes, 1); + assert.deepEqual(nodes, [node1]); + nodes = lm.getLeftMemory(rightContext2); + assert.lengthOf(nodes, 0); + }); + }); +}); \ No newline at end of file diff --git a/test/flow/matchUntil.halt.js b/test/flow/matchUntil.halt.js new file mode 100644 index 0000000..70a23b3 --- /dev/null +++ b/test/flow/matchUntil.halt.js @@ -0,0 +1,65 @@ +"use strict"; +var it = require("it"), + nools = require("../../"), + assert = require("assert"); + +it.describe("#matchUntilHalt", function (it) { + function Message(m) { + this.message = m; + } + + function Count(c) { + this.count = c; + } + + var session, flow = nools.flow("Halt Flow", function (flow) { + + flow.rule("Stop", [Count, "c", "c.count == 6"], function () { + this.halt(); + }); + + flow.rule("Hello", [ + [Count, "c"], + [Message, "m", "m.message =~ /^hello(\\s*world)?$/"] + ], function (facts) { + this.modify(facts.m, function () { + this.message += " goodbye"; + }); + this.modify(facts.c, function () { + this.count++; + }); + }); + + flow.rule("Goodbye", [ + [Count, "c"], + [Message, "m", "m.message =~ /.*goodbye$/"] + ], function (facts) { + this.retract(facts.m); + this.modify(facts.c, function () { + this.count++; + }); + }); + + }); + + it.beforeEach(function () { + session = flow.getSession(); + }); + + it.should("match until halt is called", function () { + var count = 0, called = new Count(0); + var interval = setInterval(function () { + if (count++ >= 3) { + clearInterval(interval); + } else { + session.assert(new Message("hello")); + } + }, 50); + session.assert(called); + return session.matchUntilHalt().then(function (err) { + assert.isUndefinedOrNull(err); + assert.equal(called.count, 6); + }); + + }); +}); \ No newline at end of file diff --git a/test/flow/not.test.js b/test/flow/not.test.js new file mode 100644 index 0000000..c114ea3 --- /dev/null +++ b/test/flow/not.test.js @@ -0,0 +1,185 @@ +"use strict"; +var it = require("it"), + assert = require("assert"), + nools = require("../../"); + +it.describe("not rule", function (it) { + + it.describe("with a single fact", function (it) { + var called = 0; + + var flow = nools.flow("notRuleSingleFact", function (flow) { + flow.rule("hello rule", ["not", String, "s", "s == 'hello'"], function (facts) { + assert.isUndefined(facts.s); + called++; + }); + }); + + it.should("call when a string that does not equal 'hello'", function () { + return flow.getSession("world").match().then(function () { + assert.equal(called, 1); + }); + }); + + it.should(" not call when a string that does equal 'hello'", function () { + called = 0; + return flow.getSession("hello").match().then(function () { + assert.equal(called, 0); + }); + }); + + it.should(" not call when a string that does equal 'hello' and one that does not", function () { + called = 0; + return flow.getSession("hello", "world").match().then(function () { + assert.equal(called, 0); + }); + }); + + }); + + it.describe("with multiple facts", function (it) { + var called = 0, arr = []; + var flow1 = nools.flow("notRuleMultiFact", function (flow) { + flow.rule("order rule", [ + [Number, "n1"], + ["not", Number, "n2", "n1 != n2 && n1 > n2"] + ], function (facts, flow) { + arr.push(facts.n1); + flow.retract(facts.n1); + called++; + }); + }); + + var flow2 = nools.flow("notRuleMultiFact2", function (flow) { + flow.rule("order rule reverse", [ + [Number, "n1"], + ["not", Number, "n2", "n1 < n2"] + ], function (facts, flow) { + arr.push(facts.n1); + flow.retract(facts.n1); + called++; + }); + }); + + it.should("fire rules in order", function () { + return flow1.getSession(3, 1, 5, 2, 4).match().then(function () { + assert.deepEqual(arr, [1, 2, 3, 4, 5]); + assert.equal(called, 5); + }).then(function () { + arr = [], called = 0; + return flow2.getSession(4, 2, 5, 1, 3).match().then(function () { + assert.deepEqual(arr, [5, 4, 3, 2, 1]); + assert.equal(called, 5); + }); + }); + }); + }); + + it.describe("modifying facts", function (it) { + var called = 0, arr = []; + + function Num(num) { + this.value = num; + } + + var flow1 = nools.flow("notRuleModifyFact", function (flow) { + flow.rule("not rule", [ + [Num, "n1"], + ["not", Num, "n2", "n1 != n2 && n1.value > n2.value"] + ], function () { + }); + }); + + it.should("handle modifications", function () { + var num1 = new Num(1), + num2 = new Num(2), + num3 = new Num(3), + num4 = new Num(4), + num5 = new Num(5); + var session = flow1.getSession(), + activationTree = session.agenda.rules["not rule"].tree; + + session.assert(num1); + session.assert(num2); + session.assert(num3); + session.assert(num4); + session.assert(num5); + var activations = activationTree.toArray(); + assert.lengthOf(activations, 1); + assert.equal(activations[0].match.factHash.n1, num1); + session.modify(num1, function () { + this.value = 6; + }); + activations = activationTree.toArray() + assert.lengthOf(activations, 1); + assert.equal(activations[0].match.factHash.n1, num2); + session.modify(num2, function () { + this.value = 7; + }); + activations = activationTree.toArray() + assert.lengthOf(activations, 1); + assert.equal(activations[0].match.factHash.n1, num3); + session.modify(num3, function () { + this.value = 8; + }); + activations = activationTree.toArray() + assert.lengthOf(activations, 1); + assert.equal(activations[0].match.factHash.n1, num4); + session.modify(num4, function () { + this.value = 9; + }); + activations = activationTree.toArray() + assert.lengthOf(activations, 1); + assert.equal(activations[0].match.factHash.n1, num5); + session.modify(num5, function () { + this.value = 10; + }); + activations = activationTree.toArray() + assert.lengthOf(activations, 1); + assert.equal(activations[0].match.factHash.n1, num1); + + session.retract(num1); + activations = activationTree.toArray() + assert.lengthOf(activations, 1); + assert.equal(activations[0].match.factHash.n1, num2); + + session.retract(num2); + activations = activationTree.toArray() + assert.lengthOf(activations, 1); + assert.equal(activations[0].match.factHash.n1, num3); + + session.retract(num3); + activations = activationTree.toArray() + assert.lengthOf(activations, 1); + assert.equal(activations[0].match.factHash.n1, num4); + + session.retract(num4); + activations = activationTree.toArray() + assert.lengthOf(activations, 1); + assert.equal(activations[0].match.factHash.n1, num5); + + session.retract(num5); + activations = activationTree.toArray() + assert.lengthOf(activations, 0); + + session.assert(num5); + session.assert(num4); + session.assert(num3); + session.assert(num2); + session.assert(num1); + activations = activationTree.toArray(); + debugger; + assert.lengthOf(activations, 1); + assert.equal(activations[0].match.factHash.n1, num1); + session.retract(num1); + activations = activationTree.toArray() + assert.lengthOf(activations, 1); + assert.equal(activations[0].match.factHash.n1, num2); + session.assert(num1); + activations = activationTree.toArray() + assert.lengthOf(activations, 1); + assert.equal(activations[0].match.factHash.n1, num1); + + }); + }); +}); diff --git a/test/flow/or.test.js b/test/flow/or.test.js new file mode 100644 index 0000000..16e08f7 --- /dev/null +++ b/test/flow/or.test.js @@ -0,0 +1,176 @@ +"use strict"; +var it = require("it"), + assert = require("assert"), + nools = require("../../"); + +it.describe("or rule", function (it) { + + var Count = function () { + this.called = 0; + }, called = new Count(); + + it.describe("or rule with two conditions of the same type", function (it) { + var flow; + it.beforeAll(function () { + flow = nools.flow("or condition", function (flow) { + flow.rule("hello rule", [ + ["or", + [String, "s", "s == 'hello'"], + [String, "s", "s == 'world'"] + ], + [Count, "called", null] + ], function (facts) { + facts.called.called++; + }); + }); + }); + + it.should("should match if one constraints matches", function () { + return flow.getSession("world", called).match().then(function () { + assert.equal(called.called, 1); + called.called = 0; + return flow.getSession("hello", called).match().then(function () { + assert.equal(called.called, 1); + }); + }); + }); + + it.should("not call when a a constraint does not match", function () { + called.called = 0; + return flow.getSession("hello", "world", "test", called).match().then(function () { + assert.equal(called.called, 2); + }); + }); + }); + + it.describe("or rule with three conditions", function (it) { + var flow; + + it.beforeAll(function () { + flow = nools.flow("or condition three constraints", function (flow) { + flow.rule("hello rule", [ + ["or", + [String, "s", "s == 'hello'"], + [String, "s", "s == 'world'"], + [String, "s", "s == 'hello world'"] + ], + [Count, "called", null] + ], function (facts) { + facts.called.called++; + }); + }); + }); + + it.should("should match if one constraints matches", function () { + called.called = 0; + return flow.getSession("world", called).match().then(function () { + assert.equal(called.called, 1); + called.called = 0; + return flow.getSession("hello", called).match().then(function () { + assert.equal(called.called, 1); + called.called = 0; + return flow.getSession("hello world", called).match().then(function () { + assert.equal(called.called, 1); + }); + }); + }); + }); + + it.should("not call when none constraints match", function () { + called.called = 0; + return flow.getSession("hello", "world", "hello world", "test", called).match().then(function () { + assert.equal(called.called, 3); + }); + }); + + }); + + it.describe("or rule with different types", function (it) { + var flow; + + it.beforeAll(function () { + flow = nools.flow("or condition different types", function (flow) { + flow.rule("hello rule", [ + ["or", + [String, "s", "s == 'hello'"], + [String, "s", "s == 'world'"], + [Number, "n", "n == 1"] + ], + [Count, "called", null] + ], function (facts) { + facts.called.called++; + }); + }); + }); + + it.should("should match if one constraints matches", function () { + called.called = 0; + return flow.getSession("world", called).match().then(function () { + assert.equal(called.called, 1); + called.called = 0; + return flow.getSession("hello", called).match().then(function () { + assert.equal(called.called, 1); + called.called = 0; + return flow.getSession(1, called).match().then(function () { + assert.equal(called.called, 1); + }); + }); + }); + }); + + it.should("not call when none constraints match", function () { + called.called = 0; + return flow.getSession("hello", "world", 1, "test", called).match().then(function () { + assert.equal(called.called, 3); + }); + }); + + }); + + it.describe("or with not conditions", function (it) { + var flow; + it.beforeAll(function () { + flow = nools.flow("or condition with not conditions", function (flow) { + flow.rule("hello rule", [ + ["or", + ["not", Number, "n1", "n1 == 1"], + ["not", String, "s1", "s1 == 'hello'"], + ["not", Date, "d1", "d1.getDate() == now().getDate()"] + ], + [Count, "called", null] + ], function (facts) { + facts.called.called++; + }); + }); + }); + + it.should("activate for each fact that does not exist", function () { + var count = new Count(); + return flow.getSession(count).match(2, 'world') + .then(function () { + assert.equal(count.called, 3); + count.called = 0; + return flow.getSession(count, 1).match(); + }) + .then(function () { + assert.equal(count.called, 2); + count.called = 0; + return flow.getSession(count, 'hello').match(); + }) + .then(function () { + assert.equal(count.called, 2); + count.called = 0; + return flow.getSession(count, new Date()).match(); + }) + .then(function () { + assert.equal(count.called, 2); + count.called = 0; + return flow.getSession(count, 1, 'hello', new Date()).match(); + }) + .then(function () { + assert.equal(count.called, 0); + }); + }); + }); + +}); \ No newline at end of file diff --git a/test/flow/rightMemory.test.js b/test/flow/rightMemory.test.js new file mode 100644 index 0000000..bb0458c --- /dev/null +++ b/test/flow/rightMemory.test.js @@ -0,0 +1,130 @@ +var it = require("it"), + assert = require("assert"), + Context = require("../../lib/context"), + WorkingMemory = require("../../lib/workingMemory").WorkingMemory, + RightMemory = require("../../lib/nodes/misc/rightMemory"); + +it.describe("BetaNode RightMemory", function (it) { + + it.should("add a context to the memory", function () { + var wm = new WorkingMemory(), + rm = new RightMemory(), + fact = wm.assertFact("s"), + context = new Context(fact); + rm.push(context); + assert.equal(rm.length, 1); + + }); + + it.should("remove a context from the memory", function () { + var wm = new WorkingMemory(), + rm = new RightMemory(), + fact = wm.assertFact("s"), + context = new Context(fact); + var node = rm.push(context); + assert.equal(rm.length, 1); + rm.remove(node); + assert.equal(rm.length, 0); + }); + + it.should("addIndexes to the memory", function () { + var rm = new RightMemory(); + rm.addIndex("a.s", "s.a"); + assert.lengthOf(rm.indexes, 1); + var index = rm.indexes[0]; + assert.equal(index[1], "s.a"); + assert.equal(index[0], "a.s"); + assert.isFunction(index[2]); + assert.isFunction(index[3]); + assert.equal(index[4], "eq"); + assert.deepEqual(index[3]({s: {a: 1}}), 1); + assert.deepEqual(index[2]({a: {s: 1}}), 1); + }); + + it.should("add an index and accept an operator", function () { + var rm = new RightMemory(); + rm.addIndex("a.s", "s.a", "neq"); + assert.lengthOf(rm.indexes, 1); + var index = rm.indexes[0]; + assert.equal(index[0], "a.s"); + assert.equal(index[1], "s.a"); + assert.isFunction(index[2]); + assert.isFunction(index[3]); + assert.equal(index[4], "neq"); + assert.deepEqual(index[2]({a: {s: 1}}), 1); + assert.deepEqual(index[3]({s: {a: 1}}), 1); + }); + + it.should("add a context and index it", function () { + var wm = new WorkingMemory(), + rm = new RightMemory(), + rightFact = wm.assertFact({s: 1}), + rightContext = new Context(rightFact); + rightContext.set("a", {s: 1}); + rm.addIndex("a.s", "s.a"); + var node = rm.push(rightContext); + assert.equal(rm.length, 1); + assert.isTrue("a.s" in rm.tables.tables); + assert.isTrue(rm.tables.tables["a.s"].contains(1)); + assert.deepEqual(rm.tables.tables["a.s"].get(1).tuples, [node]); + }); + + it.should("remove a context and unindex it", function () { + var wm = new WorkingMemory(), + rm = new RightMemory(), + rightFact = wm.assertFact({s: 1}), + rightContext = new Context(rightFact); + rightContext.set("a", {s: 1}); + rm.addIndex("a.s", "s.a"); + var node = rm.push(rightContext); + assert.equal(rm.length, 1); + rm.remove(node); + assert.deepEqual(rm.tables.tables["a.s"].get(1).tuples, []); + }); + + it.describe(".getRightMemory", function (it) { + it.should("return the correct right memory values", function () { + var wm = new WorkingMemory(), + rm = new RightMemory(), + rightFact = wm.assertFact({s: 1}), + leftFact = wm.assertFact({a: 1}), + rightContext = new Context(rightFact), + leftContext = new Context(leftFact); + rightContext.set("a", {s: 1}); + leftContext.set("s", {a: 1}); + rm.addIndex("a.s", "s.a"); + var node = rm.push(rightContext); + assert.equal(rm.length, 1); + var nodes = rm.getRightMemory(leftContext); + assert.lengthOf(nodes, 1); + assert.deepEqual(nodes, [node]); + leftContext.set("s", {a: 2}); + nodes = rm.getRightMemory(leftContext); + assert.lengthOf(nodes, 0); + }); + + it.should("return the intersection of all indexes", function () { + var wm = new WorkingMemory(), + rm = new RightMemory(), + rightContext1 = new Context(wm.assertFact({s: 1})), + leftContext1 = new Context(wm.assertFact({a: 1})), + rightContext2 = new Context(wm.assertFact({s: 2})), + leftContext2 = new Context(wm.assertFact({a: 3})); + rightContext1.set("a", {s: 1, b: 2, c: 2}); + leftContext1.set("s", {a: 1, b: 2, c: 1}); + rightContext2.set("a", {s: 1, b: 3, c: 3}); + leftContext2.set("s", {a: 1, b: 4, c: 3}); + rm.addIndex("a.s", "s.a"); + rm.addIndex("a.b", "s.b"); + rm.addIndex("a.c", "s.c", "neq"); + var node1 = rm.push(rightContext1); + rm.push(rightContext2); + assert.equal(rm.length, 2); + var nodes = rm.getRightMemory(leftContext1); + assert.lengthOf(nodes, 1); + assert.deepEqual(nodes, [node1]); + nodes = rm.getRightMemory(leftContext2); + assert.lengthOf(nodes, 0); + }); + }); +}); \ No newline at end of file diff --git a/test/flow/rule.test.js b/test/flow/rule.test.js new file mode 100644 index 0000000..0d98aab --- /dev/null +++ b/test/flow/rule.test.js @@ -0,0 +1,49 @@ +"use strict"; +var it = require("it"), + assert = require("assert"), + nools = require("../../"); + +it.describe("flow#rule", function (it) { + var called = 0; + var flow = nools.flow("test flow"); + it.should("create a rule", function () { + flow.rule("test rule", [String, "s", "s == 'hello'"], function () { + called++; + }); + assert.isTrue(flow.containsRule("test rule")); + }); + + it.should("create a rule with joins properly", function () { + flow.rule("test rule2", [ + [String, "s", "s == 'hello'"], + [String, "s2", "s2 == 'world'"], + [String, "s3", "s3 == 'Hi'"] + ], function () { + called++; + }); + assert.isTrue(flow.containsRule("test rule2")); + }); + + it.should("create a rules that are dependent on eachother properly", function () { + flow.rule("test rule3", [ + [String, "s", "s == 'hello'"], + [String, "s2", "s2 == 'world'"], + [String, "s3", "s3 == 'Hi'"] + ], function () { + called++; + }); + assert.isTrue(flow.containsRule("test rule3")); + + flow.rule("test rule4", [ + [String, "s1"], + [String, "s2", "s2 == 'world' && s1 == 'hello' "], + [String, "s3", "s3 == 'Hi'"], + [String, "s4", "s4 == 'what'"], + [String, "s5", "s5 == 'for'"] + ], function () { + called++; + }); + assert.isTrue(flow.containsRule("test rule4")); + }); + +}); \ No newline at end of file diff --git a/test/flow/salience.test.js b/test/flow/salience.test.js new file mode 100644 index 0000000..6a89ddf --- /dev/null +++ b/test/flow/salience.test.js @@ -0,0 +1,59 @@ +"use strict"; +var it = require("it"), + assert = require("assert"), + nools = require("../../"); + +it.describe("salience", function (it) { + /*jshint indent*/ + function Message(name) { + this.name = name; + } + + var flow1 = nools.flow("salience1", function () { + + this.rule("Hello4", {salience: 7}, [Message, "m", "m.name == 'Hello'"], function (facts) { + }); + + this.rule("Hello3", {salience: 8}, [Message, "m", "m.name == 'Hello'"], function (facts) { + }); + + this.rule("Hello2", {salience: 9}, [Message, "m", "m.name == 'Hello'"], function (facts) { + }); + + this.rule("Hello1", {salience: 10}, [Message, "m", "m.name == 'Hello'"], function (facts) { + }); + }), + flow2 = nools.flow("salience2", function () { + + this.rule("Hello4", {salience: 10}, [Message, "m", "m.name == 'Hello'"], function (facts) { + }); + + this.rule("Hello3", {salience: 9}, [Message, "m", "m.name == 'Hello'"], function (facts) { + }); + + this.rule("Hello2", {salience: 8}, [Message, "m", "m.name == 'Hello'"], function (facts) { + }); + + this.rule("Hello1", {salience: 7}, [Message, "m", "m.name == 'Hello'"], function (facts) { + }); + }); + + + it.should("activate in the proper order", function () { + var fired1 = [], fired2 = []; + var session1 = flow1.getSession(new Message("Hello")).on("fire", function (name) { + fired1.push(name); + }), + session2 = flow2.getSession(new Message("Hello")).on("fire", function (name) { + fired2.push(name); + }); + return session1.match() + .then(function () { + return session2.match(); + }) + .then(function () { + assert.deepEqual(fired1, ["Hello1", "Hello2", "Hello3", "Hello4"]); + assert.deepEqual(fired2, ["Hello4", "Hello3", "Hello2", "Hello1"]); + }); + }); +}); \ No newline at end of file diff --git a/test/flow/scope.test.js b/test/flow/scope.test.js new file mode 100644 index 0000000..b9c93dc --- /dev/null +++ b/test/flow/scope.test.js @@ -0,0 +1,49 @@ +"use strict"; +var it = require("it"), + assert = require("assert"), + nools = require("../../"); + +it.describe("scope option", function (it) { + + function isEqualTo(str, eq) { + return str === eq; + } + + var Count = function () { + this.called = 0; + }, called = new Count(); + + var flow = nools.flow("scope test", function (flow) { + flow.rule("hello rule", {scope: {isEqualTo: isEqualTo}}, [ + ["or", + [String, "s", "isEqualTo(s, 'hello')"], + [String, "s", "isEqualTo(s, 'world')"] + ], + [Count, "called", null] + ], function (facts) { + facts.called.called++; + }); + }); + + it.should("call when a string equals 'hello'", function () { + return flow.getSession("world", called).match().then(function () { + assert.equal(called.called, 1); + }); + }); + + it.should("call when a string equals 'world'", function () { + called = new Count(); + return flow.getSession("hello", called).match().then(function () { + assert.equal(called.called, 1); + }); + }); + + it.should(" not call when a string that does equal 'hello' or 'world", function () { + called = new Count(); + return flow.getSession("hello", "world", "test", called).match().then(function () { + assert.equal(called.called, 2); + }); + + }); + +}); \ No newline at end of file diff --git a/test/flow/simple.test.js b/test/flow/simple.test.js new file mode 100644 index 0000000..ade4ced --- /dev/null +++ b/test/flow/simple.test.js @@ -0,0 +1,29 @@ +"use strict"; +var it = require("it"), + assert = require("assert"), + declare = require("declare.js"), + nools = require("../../"); +it.describe("simple rule", function (it) { + + var called = 0; + var HelloFact = declare({ + instance: { + value: true + } + }); + + var flow = nools.flow("hello world flow", function (flow) { + flow.rule("hello rule", [HelloFact, "h"], function () { + called++; + }); + }); + + it.should("call hello world rule", function () { + var session = flow.getSession(); + session.assert(new HelloFact()); + return session.match().then(function () { + assert.equal(called, 1); + }); + }); + +}); \ No newline at end of file diff --git a/test/nools.test.js b/test/nools.test.js new file mode 100644 index 0000000..2f41f01 --- /dev/null +++ b/test/nools.test.js @@ -0,0 +1,67 @@ +"use strict"; +var it = require("it"), + assert = require("assert"), + nools = require("../"); + +it.describe("nools", function (it) { + it.describe(".flow", function (it) { + it.should("create a flow", function () { + var flow = nools.flow("nools flow"); + assert.isNotNull(flow); + assert.instanceOf(flow, nools.Flow); + assert.equal("nools flow", flow.name); + assert.equal(nools.getFlow("nools flow"), flow); + }); + }); + + it.describe(".deleteFlow", function (it) { + it.should("delete a flow by name", function () { + var flow = nools.flow("delete nools flow"); + assert.isNotNull(flow); + assert.instanceOf(flow, nools.Flow); + assert.equal("delete nools flow", flow.name); + assert.equal(nools.getFlow("delete nools flow"), flow); + + assert.equal(nools.deleteFlow("delete nools flow"), nools); + assert.isUndefined(nools.getFlow("delete nools flow")); + + }); + + it.should("delete a flow using a Flow instance", function () { + var flow = nools.flow("delete nools flow"); + assert.isNotNull(flow); + assert.instanceOf(flow, nools.Flow); + assert.equal("delete nools flow", flow.name); + assert.equal(nools.getFlow("delete nools flow"), flow); + + assert.equal(nools.deleteFlow(flow), nools); + assert.isUndefined(nools.getFlow("delete nools flow")); + + }); + }); + + it.describe(".hasFlow", function (it) { + + it.should("return true if the flow exists", function () { + var name = "has flow"; + nools.flow(name); + assert.isTrue(nools.hasFlow(name)); + }); + + it.should("return false if the flow does not exists", function () { + assert.isFalse(nools.hasFlow(new Date().toString())); + }); + }); + + it.describe(".deleteFlows", function (it) { + + it.should("deleteAllFlows", function () { + var name = "delete nools flows"; + nools.flow(name); + assert.isTrue(nools.hasFlow(name)); + assert.equal(nools.deleteFlows(), nools); + assert.isFalse(nools.hasFlow(name)); + }); + + }); +}); \ No newline at end of file diff --git a/test/noolsParser.test.js b/test/noolsParser.test.js index 2e80ba7..20188ae 100644 --- a/test/noolsParser.test.js +++ b/test/noolsParser.test.js @@ -997,5 +997,25 @@ it.describe("nools dsl parser", function (it) { }); }); + it.should("parse rules with exists clause", function () { + var parsed = noolsParser.parse("rule 'test \"rule\"' { when { exists(c : Clazz c.name eq 'Test' {test : test})} then {console.log($test);}}"); + assert.deepEqual(parsed, { + define: [], + rules: [ + { + name: 'test "rule"', + constraints: [ + ["exists", "Clazz", "c", "c.name eq 'Test'", {test: "test"}] + ], + action: "console.log($test);", + options: {} + } + ], + "scope": [], + "loaded": [], + "file": undefined + }); + }); + }); }); \ No newline at end of file diff --git a/test/rules.test.js b/test/rules.test.js index 2c3f677..c2be248 100644 --- a/test/rules.test.js +++ b/test/rules.test.js @@ -8,7 +8,7 @@ var it = require("it"), var cb = function () { }; -it.describe("Rule",function (it) { +it.describe("Rule", function (it) { it.describe("#createRule", function (it) { it.describe("with strings", function (it) { @@ -603,7 +603,38 @@ it.describe("Rule",function (it) { assert.instanceOf(constrnts[2], constraints.HashConstraint); assert.instanceOf(pattern.rightPattern.from, constraints.FromConstraint); }); + + it.should("should include exists constraints", function () { + var ruleArr = rules.createRule("My Rule", [ + ["exists", "Hash", "h", {name: "name"}], + ["exists", "string", "s2", "s2 == name", {length: "length"}, "from [1,2,3,4]"] + ], cb); + assert.isNotNull(ruleArr); + assert.lengthOf(ruleArr, 1); + + var rule = ruleArr[0]; + assert.equal(rule.name, "My Rule"); + assert.isNotNull(rule.pattern); + var pattern = rule.pattern; + debugger; + assert.instanceOf(pattern, patterns.CompositePattern); + assert.instanceOf(pattern.leftPattern, patterns.ExistsPattern); + assert.instanceOf(pattern.rightPattern, patterns.FromExistsPattern); + assert.equal(pattern.leftPattern.alias, "h"); + assert.equal(pattern.rightPattern.alias, "s2"); + var constrnts = pattern.leftPattern.constraints; + assert.lengthOf(constrnts, 3); + assert.instanceOf(constrnts[0], constraints.ObjectConstraint); + assert.instanceOf(constrnts[1], constraints.TrueConstraint); + assert.instanceOf(constrnts[2], constraints.HashConstraint); + constrnts = pattern.rightPattern.constraints; + assert.lengthOf(constrnts, 3); + assert.instanceOf(constrnts[0], constraints.ObjectConstraint); + assert.instanceOf(constrnts[1], constraints.ReferenceConstraint); + assert.instanceOf(constrnts[2], constraints.HashConstraint); + assert.instanceOf(pattern.rightPattern.from, constraints.FromConstraint); + }); }); -}).as(module); +});