From 0068a698823732705e8567e76547797411f62483 Mon Sep 17 00:00:00 2001 From: Doug Martin Date: Tue, 26 Feb 2013 13:28:04 -0600 Subject: [PATCH] work to support from nodes --- examples/banking/scripts/nools.js | 6 +- examples/browser/manners.html | 6 +- examples/fibonacci.js | 2 +- examples/fibonacci.nools | 1 - examples/sudoku/index.js | 82 +++ examples/sudoku/lib/rules/sudoku.nools | 361 +++++++++++ examples/sudoku/lib/rules/validate.nools | 42 ++ examples/sudoku/lib/sudoku.js | 327 ++++++++++ lib/compile.js | 10 +- lib/constraint.js | 25 + lib/constraintMatcher.js | 13 +- lib/context.js | 22 +- lib/index.js | 16 +- lib/nodes/fromNode.js | 112 ++++ lib/nodes/fromNotNode.js | 80 +++ lib/nodes/index.js | 72 ++- lib/nodes/terminalNode.js | 3 +- lib/parser/nools/tokens.js | 16 +- lib/pattern.js | 197 +++--- lib/rule.js | 117 +++- lib/workingMemory.js | 16 +- nools.js | 747 ++++++++++++++++++----- nools.min.js | 4 +- package.json | 2 +- test/constraintMatcher.test.js | 40 +- test/flow.test.js | 248 +++++++- test/noolsParser.test.js | 58 ++ test/rules.test.js | 66 +- 28 files changed, 2357 insertions(+), 334 deletions(-) create mode 100644 examples/sudoku/index.js create mode 100644 examples/sudoku/lib/rules/sudoku.nools create mode 100644 examples/sudoku/lib/rules/validate.nools create mode 100644 examples/sudoku/lib/sudoku.js create mode 100644 lib/nodes/fromNode.js create mode 100644 lib/nodes/fromNotNode.js diff --git a/examples/banking/scripts/nools.js b/examples/banking/scripts/nools.js index 09422cc..e71b38b 100644 --- a/examples/banking/scripts/nools.js +++ b/examples/banking/scripts/nools.js @@ -14796,7 +14796,7 @@ var Node = declare({ }, assert: function (assertable) { - this.propagateAssert(assertable); + this.__propagate("assert", assertable); }, propagateModify: function (assertable, outNodes) { @@ -14828,7 +14828,7 @@ var TypeNode = AlphaNode.extend({ assert: function (fact) { if (this.constraint.assert(fact.object)) { - this.propagateAssert({fact: fact}); + this.__propagate("assert", {fact: fact}); } }, @@ -15046,7 +15046,7 @@ var BridgeNode = Node.extend({ for (var i in variables) { fh[i] = o[variables[i]]; } - this.propagateAssert({match: mr, fact: fact}); + this.__propagate("assert", {match: mr, fact: fact}); }, retract: function (assertable) { diff --git a/examples/browser/manners.html b/examples/browser/manners.html index 7b12cb6..ce94da1 100644 --- a/examples/browser/manners.html +++ b/examples/browser/manners.html @@ -312,7 +312,7 @@ ]; - var seat = { seat: 16 }; + var seat = { seat: 64 }; var start = { state: 'start' }; var flow = nools.getFlow("manners"), @@ -322,8 +322,8 @@ Count = flow.getDefined("count"), session = flow.getSession(); - for (var i = 0, l = guests16.length; i < l; i++) { - session.assert(new Guest(guests16[i])); + for (var i = 0, l = guests64.length; i < l; i++) { + session.assert(new Guest(guests64[i])); } session.assert(new LastSeat(seat)); session.assert(new Context(start)); diff --git a/examples/fibonacci.js b/examples/fibonacci.js index 7869cf4..62a56bc 100644 --- a/examples/fibonacci.js +++ b/examples/fibonacci.js @@ -14,7 +14,7 @@ var Result = function (result) { var flow = nools.flow("Fibonacci Flow", function (flow) { - flow.rule("Recurse", {priority: 1}, [ + flow.rule("Recurse",[ ["not", Fibonacci, "f", "f.sequence == 1"], [Fibonacci, "f1", "f1.sequence != 1"] ], function (facts) { diff --git a/examples/fibonacci.nools b/examples/fibonacci.nools index 03b7930..9b44f01 100644 --- a/examples/fibonacci.nools +++ b/examples/fibonacci.nools @@ -10,7 +10,6 @@ define Result { } rule Recurse { - priority:1, when { //you can use not or or methods in here not(f : Fibonacci f.sequence == 1); diff --git a/examples/sudoku/index.js b/examples/sudoku/index.js new file mode 100644 index 0000000..8a450ec --- /dev/null +++ b/examples/sudoku/index.js @@ -0,0 +1,82 @@ +var nools = require("../../index.js"), + sudoku = require("./lib/sudoku"); + +var flow = nools.compile(require.resolve("./lib/rules/sudoku.nools"), { + define: { + CellGroup: sudoku.CellGroup, + Cell: sudoku.Cell, + CellCol: sudoku.CellCol, + CellRow: sudoku.CellCol, + CellSqr: sudoku.CellSqr, + Counter: sudoku.Counter, + Setting: sudoku.Setting, + Stepping: sudoku.Stepping + }, + scope: { + explain: true + } +}); + + +var simple = [ + [null, 5, 6, 8, null, 1, 9, 4, null], + [9, null, null, 6, null, 5, null, null, 3], + [7, null, null, 4, 9, 3, null, null, 8], + [8, 9, 7, null, 4, null, 6, 3, 5], + [null, null, 3, 9, null, 6, 8, null, null], + [4, 6, 5, null, 8, null, 2, 9, 1], + [5, null, null, 2, 6, 9, null, null, 7], + [6, null, null, 5, null, 4, null, null, 9], + [null, 4, 9, 7, null, 8, 3, 5, null] +]; + +var medium = [ + [8, 4, 7, null, null, null, 2, 5, 6], + [5, null, null, null, 8, null, null, null, 4], + [2, null, null, null, 7, null, null, null, 8], + [null, null, null, 3, null, 8, null, null, null], + [null, 5, 1, null, null, null, 8, 7, 2], + [null, null, null, 5, null, 7, null, null, null], + [4, null, null, null, 5, null, null, null, 7], + [6, null, null, null, 3, null, null, null, 9], + [1, 3, 2, null, null, null, 4, 8, 5] +]; + +var hard1 = [ + [null, null, null, null, 5, 1, null, 8, null], + [null, 8, null, null, 4, null, null, null, 5], + [null, null, 3, null, null, null, 2, null, null], + [null, null, null, null, 6, null, null, null, 9], + [6, 7, null, 4, null, 9, null, 1, 3], + [8, null, null, null, 3, null, null, null, null], + [null, null, 2, null, null, null, 4, null, null], + [5, null, null, null, 9, null, null, 2, null], + [null, 9, null, 7, 1, null, null, null, null] +]; + +var sud = new sudoku.Sudoku(flow); +var repl = require("repl"); +sud.setCellValues(simple).then(function () { + var sudokuRepl = repl.start("sudoku>>"); + sudokuRepl.context.print = sud.dumpGrid.bind(sud); + sudokuRepl.context.step = function () { + sud.step().classic(function (err) { + if (err) { + console.log(err.stack); + } + }); + }; + sudokuRepl.context.solve = function () { + sud.solve().classic(function (err) { + if (err) { + console.log(err.stack); + } else { + sud.dumpGrid(); + } + }); + }; +}); + + + + diff --git a/examples/sudoku/lib/rules/sudoku.nools b/examples/sudoku/lib/rules/sudoku.nools new file mode 100644 index 0000000..584e733 --- /dev/null +++ b/examples/sudoku/lib/rules/sudoku.nools @@ -0,0 +1,361 @@ + +rule "halt after setup" { + when{ + $ctr: Counter $ctr.count == 0; + } + then{ + console.log("halt after setup"); + halt(); + } +} + +rule "emergency halt" { + when{ + $s: Stepping; + } + then{ + console.log("emergency halt"); + modify($s, function(){ + this.emergency = true; + }); + halt(); + } + +} + +// A Setting object is inserted to define the value of a Cell. +// Rule "set a value" updates the cell and all cell groups containing it. +rule "set a value"{ + + when{ + // a Setting with row and column number, and a value + $s: Setting {rowNo: $rn, colNo: $cn, value: $v}; + + // a matching Cell, with no value set + $c: Cell $c.rowNo == $rn && $c.colNo == $cn && $c.value == null {cellRow: $cr, cellCol: $cc, cellSqr: $cs}; + } + then { + // modify the Cell by setting its value + console.log("set a value"); + modify( $c, function(){ this.blockExcept(); this.value = $v;}); + console.log( "set cell " + $c.toString() ); + modify( $cr, function(){ this.blockValue( $v ) }); + modify( $cc, function(){ this.blockValue( $v ) }); + modify( $cs, function(){ this.blockValue( $v ) }); + } +} + + +// Rule for removing a value from all cells that are siblings +// in one of the three cell groups. +rule "eliminate a value from Cell" { + when{ + // a Setting with row and column number, and a value + $s: Setting {rowNo: $rn, colNo: $cn, value: $v}; + + // the matching Cell, with the value already set + $mc : Cell $mc.rowNo == $rn && $mc.colNo == $cn && $mc.value == $v {exCells: $exCells}; + + // for all Cells that are in cahoots with the updated cell + $c: Cell $v in $c.free from $exCells; + } + then{ + console.log( "clear " + $v + " from cell " + $c.posAsString() + " because of " + $mc.posAsString() ); + // modify a related Cell by blocking the assigned value + modify( $c, function(){ this.blockValue( $v ); }); + } +} + +// Rule for elimination the Setting fact. +rule "retract setting"{ + when { + // a Setting with row and column number, and a value + $s: Setting {rowNo: $rn, colNo: $cn, value: $v}; + + // the matching Cell, with the value already set + $c: Cell $c.rowNo == $rn && $c.colNo == $cn && $c.value == $v; + + // This is the negation of the last pattern in the previous rule. + // Now the Setting fact can be safely retracted. + not( $x: Cell $v in $x.free && $x in $c.exCells); + // count down + $ctr: Counter {count: $count}; + } + then{ + console.log(Object.keys(facts)); + console.log("retracting " + $s.toString()); + // Discard the Setter fact. + retract( $s ); + console.log($count); + modify( $ctr, function(){ this.count = $count - 1;}); + console.log( "done setting cell " + $c.toString() ); + } +} + + +// Detect a set of candidate values with cardinality 1 for some Cell. +// This is the value to be set. +rule "single"{ + when { + // There is currently no setting under way. + not($ns: Setting); + + // One element in the "free" set. + $c: Cell $c.count == 1 {rowNo: $rn, colNo: $cn}; + } + then { + var i = $c.freeValue(); + console.log( "single " + i + " at " + $c.posAsString() ); + // Insert another Setter fact. + assert( new Setting( $rn, $cn, i ) ); + } +} + +// Detect a set of candidate values with a value that is the only one +// in one of its groups. This is the value to be set. +rule "hidden single" { + when{ + // There is currently no setting under way. + not($ns: Setting); + not($nc: Cell $nc.count == 1 ); + + // Some integer. + $i: Number; + + // The "free" set contains this number. + $c: Cell $c.count > 1 && $i in $c.free {rowNo: $rn, colNo: $cn}; + + // We have a cell group containing this cell $c + $cg: CellGroup $c in $cg.cells; + // but no other cell from that group contains $i + not ($nc2: Cell $nc2 != $c && $i in $nc2.free from $cg.cells); + } + then { + console.log( "hidden single " + $i + " at " + $c.posAsString() ); + // Insert another Setter fact. + assert( new Setting( $rn, $cn, $i ) ); + } +} + + +// A "naked pair" is two cells in some cell group with their sets of +// permissible values being equal with cardinality 2. These two values +// can be removed from all other candidate lists in the group. +rule "naked pair" { + when { + // There is currently no setting under way. + not($ns: Setting); + not($nc: Cell $nc.count == 1 ); + + + // One cell with two candidates. + $c1: Cell $c1.count == 2 {free: $f1, cellRow: $r1, rowNo: $rn1, colNo: $cn1, cellSqr: $b1, value: $v}; + + // The containing cell group. + $cg: CellGroup $cg.count > 2 && $c1 in $cg.cells; + + // Another cell with two candidates, not the one we already have. + $c2: Cell( $c2 in $cg.cells && $c2 != $c1 && deepEqual($c2.free, $f1) ); + + // Get one of the "naked pair". + $v: Number from $c1.free; + + // Get some other cell with a candidate equal to one from the pair. + $c3: Cell $c3 != $c1 && $c3 != $c2 && $c3.count > 1 && $v in $c3.free from $cg.cells; + } + then{ + console.log( "remove " + $v + " from " + $c3.posAsString() + " due to naked pair at " + $c1.posAsString() + " and " + $c2.posAsString() ); + // Remove the value. + modify( $c3, function(){ this.blockValue( $v ); }); + } +} + +// If two cells within the same cell group contain candidate sets with more than +// two values, with two values being in both of them but in none of the other +// cells, then we have a "hidden pair". We can remove all other candidates from +// these two cells. +// +rule "hidden pair in row" { + when{ + // There is currently no setting under way. + not($ns: Setting); + not($nc: Cell $nc.count == 1 ); + + // Establish a pair of Integer facts + $i1: Number; + $i2: Number $i2 > $i1; + + // Look for a Cell with these two among its candidates. (The upper bound on + // the number of candidates avoids a lot of useless work during startup.) + $c1: Cell $c1.count > 2 && $c1.count < 9 && $i1 in $c1.free && $i2 in $c1.free {rowNo: $rn1, colNo: $cn1, cellRow: $cellRow}; + + // Get another one from the same row, with the same pair among its candidates, + $c2: Cell $c2 != $c1 && $c2.cellRow == $cellRow && $c2.count > 2 && $i1 in $c2.free && $i12 in $c2.free; + + // Assertain that no other cell in the group has one of these two values. + not($nc2: Cell $nc2 == $c1 && $nc2 == $c2 && ($i1 in $nc2.free || $i2 in $nc2.free ) from $cellRow.cells) + } + then{ + console.log( "hidden pair in row at " + $c1.posAsString() + " and " + $c2.posAsString() ); + // Set the candidate lists of these two Cells to the "hidden pair". + modify( $c1, function(){this.blockExcept([$i1, $i2]) }); + modify( $c2, function(){this.blockExcept([$i1, $i2]) }); + } +} + +rule "hidden pair in column"{ + when{ + not($ns: Setting); + not($nc: Cell $nc.count == 1 ); + + $i1: Number; + $i2: Number $i2 > $i1; + + $c1: Cell $c1.count > 2 && $c1.count < 9 && $i1 in $c1.free && $i2 in $c1.free {rowNo: $rn1, colNo: $cn1, cellCol: $cellCol}; + $c2: Cell $c2 != $c1 && $c2.cellCol == $cellCol && $c2.count > 2 && $i1 in $c2.free && $i2 in $c2.free; + not($nc2: Cell $nc2 == $c1 && $nc2 == $c2 && ($i1 in $nc2.free || $i2 in $nc2.free ) from $cellColl.cells) + } + then{ + console.log( "hidden pair in column at " + $c1.posAsString() + " and " + $c2.posAsString() ); + modify( $c1, function(){this.blockExcept([$i1, $i2]) }); + modify( $c2, function(){this.blockExcept([$i1, $i2]) }); + } +} + +rule "hidden pair in square" { + when{ + not($ns: Setting); + not($nc: Cell $nc.count == 1 ); + + $i1: Number; + $i2: Number $i2 > $i1; + + $c1: Cell $c1.count > 2 && $c1.count < 9 && $i1 in $c1.free && $i2 in $c1.free {rowNo: $rn1, colNo: $cn1, cellSqr: $cellSqr}; + $c2: Cell $c2 != $c1 && $c2.cellSqr == $cellSqr && $c2.count > 2 && $i1 in $c2.free && $i2 in $c2.free; + + not($nc2: Cell $nc2 == $c1 && $nc2 == $c2 && ($i1 in $nc2.free || $i2 in $nc2.free ) from $cellSqr.cells) + } + then{ + console.log( "hidden pair in square " + $c1.posAsString() + " and " + $c2.posAsString() ); + modify( $c1, function(){this.blockExcept([$i1, $i2]) }); + modify( $c2, function(){this.blockExcept([$i1, $i2]) }); + } +} + + +rule "X-wings in rows" { + when{ + not($ns: Setting); + not($nc: Cell $nc.count == 1 ); + + $i: Number; + + $ca1: Cell $ca1.count > 1 && $i in $ca1.free {cellRow: $ra, rowNo: $rano, cellCol: $c1,colNo: $c1no}; + $cb1: Cell $cb1.count > 1 && $i in $cb1.free && $cb1.rowNo > $rano && $cb1.cellCol == $c1 {cellRow: $rb, rowNo: $rbno}; + not($nc2: Cell $nc2 != ca1 && $nc2 != $cb1 && $i in $nc2.free from $c1.cells); + + $ca2: Cell $ca2.count > 1 && $1 in $ca2.free && $ca2.cellRow == $ra && $ca2.colNo > $c1no {cellCol: $c2, colNo: $c2no}; + $cb2: Cell $cb2.count > 1 && $i in $cb2.free && $cb2.cellRow == $rb && $cb2.cellCol == $c2; + not($nc3: Cell $nc3 != $ca2 && $nc3 != $cb2 && $i in $nc3.free from $c2.cells); + + $cx: Cell ($cx.rowNo == $rano || $cx.rowNo == $rbno) && $cx.colNo != $c1no && $cx.colNo != $c2no && $cx.count > 1 && $i in $cx.free; + } + then{ + + console.log( "X-wing with " + $i + " in rows " + + $ca1.posAsString() + " - " + $cb1.posAsString() + + $ca2.posAsString() + " - " + $cb2.posAsString() + ", remove from " + $cx.posAsString() ); + + modify( $cx, function(){ this.blockValue( $i ) }); + } +} + +rule "X-wings in columns"{ + when{ + not($ns: Setting); + not($nc: Cell $nc.count == 1 ); + + $i: Number; + + + $ca1: Cell $ca1.count > 1 && $i in $ca1.free {cellRow: $ra, rowNo: $rano, cellCol: $c1,colNo: $c1no}; + + $ca2: Cell $ca2.count > 1 && $i in $ca2.free && $ca2.colNo > $c1No && $ca2.cellRow == $ra {cellCol: $c2, colNo: $c2no}; + not( $nc2: Cell $nc2 != $ca1 && $nc2 != $ca2 && $i in $nc2.free from $ra.cells); + + $cb1: Cell $cb1.count > 1 && $i in $cb1.free && $cb1.cellCol == $c1 && $cb1.rowNo > $rano {cellRow: $rb, rowNo: $rbno}; + $cb2: Cell $cb2.count > 1 && $i in $cb2.free && $cb2.cellCol == $c2 && $cb2.cellRow == $rb; + not($nc3: Cell $nc3 != $cb1 && $nc3 != $cb2 && $i in $nc3.free from $rb.cells); + + $cx: Cell ($cx.colNo == $c1no || $cx.colNo == $c2no) && $cx.rowNo != $rano && $cx.rowNo != $rbno && $cx.count > 1 && $i in $cx.free; + } + then{ + + console.log( "X-wing with " + $i + " in columns " + + $ca1.posAsString() + " - " + $ca2.posAsString() + + $cb1.posAsString() + " - " + $cb2.posAsString() + ", remove from " + $cx.posAsString() ); + + modify( $cx, function(){this.blockValue( $i ) }); + } +} + +rule "intersection removal column" { + when { + not($ns: Setting); + not($nc: Cell $nc.count == 1 ); + + $i: Number; + + // occurs in a Cell + $c: Cell $i in $c.free {cellSqr: $cs, cellCol: $cc}; + // but not in another cell of the same square and a different column + not($nc2: Cell $nc2 == $c && $i in $nc2.free && $nc2.cellSqr == $cs && $nc2.cellCol != $cc ); + + // but there is a cell in the same column and another sqstuare containing this value + $cx: Cell $cx.count > 1 && $i in $cx.free && $cx.cellCol == $cc && $cx.cellSqr != $cs; + } + then{ + // remove the value from that other cell + //if (explain) { + console.log( "column elimination due to " + $c.posAsString() + + ": remove " + $i + " from " + $cx.posAsString() ); + //} + modify( $cx, function(){this.blockValue( $i ) }); + } +} + +rule "intersection removal row"{ + when{ + not($ns: Setting); + not($nc: Cell $nc.count == 1 ); + + $i: Number; + // occurs in a Cell + $c: Cell $i in $c.free {cellSqr: $cs, cellRow: $cr}; + // but not in another cell of the same square and a different row + not($nc2: Cell $nc2 == $c && $i in $nc2.free && $nc2.cellSqr == $cs && $nc2.cellRow != $cr); + + // but there is a cell in the same row and another square containing this value + $cx: Cell $cx.count > 1 && $i in $cx.free && $cx.cellRow == $cr && $cx.cellSqr != $cs; + } + then { + // remove the value from that other cell + //if (explain) { + console.log( "row elimination due to " + $c.posAsString() + + ": remove " + $i + " from " + $cx.posAsString() ); + //} + modify( $cx, function(){ this.blockValue( $i ) }); + } +} +// +//// Y-wing +//// $c1: Cell( count == 2 ) contains a, b +//// $c2: Cell( count == 2 ) contains a, c +//// $c3: Cell( count == 2 ) contains b, c +//// //g12: CellGroup() contains $c1, $c2 +//// //g1e: CellGroup() contains $c1, $c3 +// +//// $cx: Cell( count > 1 ) contains c +//// // //g12: CellGroup() contains $c1, $c2 +// +// diff --git a/examples/sudoku/lib/rules/validate.nools b/examples/sudoku/lib/rules/validate.nools new file mode 100644 index 0000000..e79a504 --- /dev/null +++ b/examples/sudoku/lib/rules/validate.nools @@ -0,0 +1,42 @@ + +rule "terminate group" { + salience: -100 + when {} + then{ + console.log("Validation complete." ); + halt(); + } +} + +rule "duplicate in cell row" { + when{ + $c: Cell $c.value !== null {$v: value}; + $cr: CellRow $c in $cr.cells; + $e: Cell $e != $c && $e.value == $v && $e.cellRow == $cr; + } + then{ + console.log( "cell " + $c.toString() + " has a duplicate in row " + $cr.getNumber() ); + } +} + +rule "duplicate in cell col" { + when{ + $c: Cell $c.value !== null {$v: value}; + $cc: CellCol $c in $cc.cells; + $e: Cell $e != $c && $e.value == $v && $e.cellCol == $cc; + } + then { + console.log( "cell " + $c.toString() + " has a duplicate in col " + $cc.getNumber() ); + } +} + +rule "duplicate in cell sqr" { + when{ + $c: Cell $c.value !== null {$v: value}; + $cs: CellSqr $c in $cs.cells; + $e: Cell $e != $c && $e.value == $v && $e.cellSqr == $cs + } + then{ + System.out.println( "cell " + $c.toString() + " has duplicate in its square of nine." ); + } +} diff --git a/examples/sudoku/lib/sudoku.js b/examples/sudoku/lib/sudoku.js new file mode 100644 index 0000000..186d66a --- /dev/null +++ b/examples/sudoku/lib/sudoku.js @@ -0,0 +1,327 @@ +var declare = require("declare.js"), + arr = require("array-extended"), + format = require("string-extended").format, + unique = arr.unique; + +var allNine = [1, 2, 3, 4, 5, 6, 7, 8, 9]; + +var SetOfNine = declare({ + instance: { + + free: null, + count: 0, + + constructor: function () { + this.count = (this.free = allNine.slice()).length; + }, + + blockValue: function (value) { + this.free.splice(arr.indexOf(this.free, value), 1); + this.count = this.free.length; + return this; + }, + + blockExcept: function (values) { + this.free = (values || []).splice(); + this.count = this.free.length; + return this; + }, + + freeValue: function () { + return this.free[0]; + } + } +}).as(exports, "SetOfNine"); + +var CellGroup = SetOfNine.extend({ + instance: { + cells: null, + + constructor: function () { + this._super(arguments); + this.cells = []; + }, + + addCell: function (cell) { + this.cells.push(cell); + } + } +}).as(exports, "CellGroup"); + + +var CellFile = CellGroup.extend({ + instance: { + number: null, + + constructor: function (number) { + this._super(arguments); + this.number = number; + }, + + toString: function () { + var ret = [], cells = this.cells; + for (var i = 0, l = cells.length; i < l; i++) { + ret.push(cells[i].toString()); + } + return ret.join(", "); + } + } +}).as(exports, "CellFile"); + +var Cell = SetOfNine.extend({ + instance: { + value: null, + cellRow: null, + cellCol: null, + CellSqr: null, + exCells: null, + + constructor: function () { + this._super(arguments); + this.exCells = []; + }, + + makeReferences: function (cr, col, sqr) { + this.cellRow = cr; + this.cellCol = col; + this.cellSqr = sqr; + this.colNo = col.number; + this.rowNo = cr.number; + this.exCells = unique(this.exCells.concat(cr.cells).concat(col.cells).concat(sqr.cells)); + this.exCells.splice(this.exCells.indexOf(this), 1); + return this; + }, + + toString: function () { + return [this.posAsString(), this.valueAsString()].join(": "); + }, + + valueAsString: function () { + return this.value === null ? " " : this.value; + }, + + posAsString: function () { + return ["[", this.cellRow.number, ",", this.cellCol.number, "]"].join(""); + } + } +}).as(exports, "Cell"); + +var CellCol = CellFile.extend({ + instance: { + toString: function () { + return ["Column ", this.number, ": ", this._super(arguments)]; + } + } +}).as(exports, "CellCol"); + + +var CellRow = CellFile.extend({ + instance: { + toString: function () { + return ["Row ", this.number, ": ", this._super(arguments)]; + } + } +}).as(exports, "CellRow"); + +var CellSqr = CellGroup.extend({ + instance: { + constructor: function (cr1, cr2, cr3, cc1, cc2, cc3) { + this._super(arguments); + for (var i = cr1.number; i <= cr3.number; i++) { + this.addCell(cc1.cells[i]); + this.addCell(cc2.cells[i]); + this.addCell(cc3.cells[i]); + } + + } + } +}).as(exports, "CellSqr"); + +var Counter = declare({ + instance: { + count: 0, + constructor: function (count) { + this.count = count; + } + } +}).as(exports, "Counter"); + + +var Setting = declare({ + instance: { + rowNo: null, + colNo: null, + value: null, + + constructor: function (row, col, value) { + this.rowNo = row; + this.colNo = col; + this.value = value; + }, + + toString: function () { + return "Setting [" + this.rowNo + "," + this.colNo + "] : " + this.value; + } + + } +}).as(exports, "Setting"); + + +var Stepping = declare({ + instance: { + emergency: false + } +}).as(exports, "Stepping"); + +var Sudoku = declare({ + instance: { + + constructor: function (flow) { + this.rows = []; + this.cols = []; + this.sqrs = []; + this.cells = []; + this.flow = flow; + this.session = null; + this.stepping = null; + }, + + 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); + } + }); + }, + + 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); + } + }); + }, + + create: function () { + var rows = this.rows, cols = this.cols, sqrs = [], session = this.session; + for (var i = 0; i < 9; i++) { + session.assert(i + 1); + rows[i] = new CellRow(i); + cols[i] = new CellCol(i); + } + + var cells = this.cells = [], iCol; + for (var iRow = 0; iRow < 9; iRow++) { + cells[iRow] = []; + for (iCol = 0; iCol < 9; iCol++) { + var cell = cells[iRow][iCol] = new Cell(); + rows[iRow].addCell(cell); + cols[iCol].addCell(cell); + } + } + + for (i = 0; i < 3; i++) { + sqrs[i] = []; + for (var j = 0; j < 3; j++) { + sqrs[i][j] = new CellSqr(rows[i * 3], rows[i * 3 + 1], rows[i * 3 + 2], + cols[j * 3], cols[j * 3 + 1], cols[j * 3 + 2]); + } + } + + for (iRow = 0; iRow < 9; iRow++) { + for (iCol = 0; iCol < 9; iCol++) { + session.assert(cells[iRow][iCol].makeReferences(rows[iRow], cols[iCol], sqrs[Math.floor(iRow / 3)][Math.floor(iCol / 3)])); + } + session.assert(rows[iRow]); + session.assert(cols[iRow]); + session.assert(sqrs[Math.floor(iRow / 3)][iRow % 3]); + } + }, + + setCellValues: function (cellValues) { + var session = this.session; + if (session !== null) { + session.dispose(); + } + + var session = (this.session = this.flow.getSession()); + + var s000 = new Setting(0, 0, 0); + this.session.assert(s000); + this.create(); + + var initial = 0; + for (var iRow = 0; iRow < 9; iRow++) { + for (var iCol = 0; iCol < 9; iCol++) { + var value = cellValues[iRow][iCol]; + if (value) { + session.assert(new Setting(iRow, iCol, value)); + initial++; + //console.log(initial); + } + } + } + var counter = this.counter = new Counter(initial); + this.session.assert(counter); + this.session.retract(s000); + return this.session.matchUntilHalt(function (err) { + if (err) { + console.log(err); + } + this.dumpGrid(); + }.bind(this)); + }, + + dumpGrid: function () { + var cells = this.cells; + var print = [" "]; + for (var iCol = 0; iCol < 9; iCol++) { + print.push(format("Col: %d ", iCol)); + } + console.log(print.join("")); + for (var iRow = 0; iRow < 9; iRow++) { + var print = ["Row " + (iRow) + ": "]; + for (iCol = 0; iCol < 9; iCol++) { + if (cells[iRow][iCol].value !== null) { + print.push(format(" --- %d --- ", cells[iRow][iCol].value)); + } else { + var perms = cells[iRow][iCol].free, sb = []; + for (var i = 1; i <= 9; i++) { + if (perms.indexOf(i) !== -1) { + sb.push(i); + } else { + sb.push(' '); + } + } + print.push(format(" %-10s", sb.join(""))); + } + } + console.log(print.join("")); + } + } + + } +}).as(exports, "Sudoku"); + + + + + + + + + + + diff --git a/lib/compile.js b/lib/compile.js index 349a996..a63f6c1 100644 --- a/lib/compile.js +++ b/lib/compile.js @@ -52,10 +52,9 @@ if (/next\(.*\)/.test(action)) { params.push("next"); } - action = declares.join("") + action; - action = ["(function(){ return function _parsedAction(", params.join(","), ")", "{\n\t", action, "\n};}())"].join(""); + action = "with(this){" + declares.join("") + action + "}"; try { - return eval(action); + return bind({defined: defined, scope: scope, bind: bind}, new Function(params.join(","), action)); } catch (e) { throw new Error("Invalid action : " + action + "\n" + e.message); } @@ -149,9 +148,8 @@ declares.push("var " + i + "= scope." + i + ";"); } }); - body = ["((function(){", declares.join(""), "\n\treturn ", body, "\n})())"].join(""); try { - return eval(body); + return bind({scope: scope, defined: defined}, new Function("with(this){" + declares.join("") + "\n\treturn " + body + "\n}")); } catch (e) { throw new Error("Invalid action : " + body + "\n" + e.message); } @@ -160,7 +158,7 @@ var createDefined = (function () { var _createDefined = function (options) { - options = isString(options) ? eval("(function(){ return " + options + "}())") : options; + options = isString(options) ? new Function("return " + options + ";")() : options; var ret = options.hasOwnProperty("constructor") && "function" === typeof options.constructor ? options.constructor : function (opts) { opts = opts || {}; for (var i in opts) { diff --git a/lib/constraint.js b/lib/constraint.js index da3cb77..042a9d5 100644 --- a/lib/constraint.js +++ b/lib/constraint.js @@ -171,5 +171,30 @@ Constraint.extend({ } }).as(exports, "HashConstraint"); +Constraint.extend({ + instance: { + constructor: function (prop, constraints) { + this.type = "from"; + this.prop = prop; + this.constraints = constraints; + }, + + equal: function (constraint) { + return extd.instanceOf(constraint, this._static) && this.get("alias") === constraint.get("alias") && extd.deepEqual(this.constraints, constraint.constraints); + }, + + "assert": function () { + return true; + }, + + getters: { + variables: function () { + return this.constraint; + } + } + + } +}).as(exports, "FromConstraint"); + diff --git a/lib/constraintMatcher.js b/lib/constraintMatcher.js index 7ee7851..2cdaed2 100644 --- a/lib/constraintMatcher.js +++ b/lib/constraintMatcher.js @@ -11,6 +11,7 @@ var extd = require("./extended"), atoms = require("./constraint"); var definedFuncs = { + indexOf: extd.indexOf, now: function () { return new Date(); }, @@ -312,7 +313,7 @@ var toJs = exports.toJs = function (rule, scope) { var js = lang.parse(rule); scope = scope || {}; var vars = lang.getIdentifiers(rule); - return ["(function(){ return function jsMatcher(fact, hash){", map(vars,function (v) { + var body = "var indexOf = definedFuncs.indexOf;" + map(vars,function (v) { var ret = ["var ", v, " = "]; if (definedFuncs.hasOwnProperty(v)) { ret.push("definedFuncs['", v, "']"); @@ -323,12 +324,16 @@ var toJs = exports.toJs = function (rule, scope) { } ret.push(";"); return ret.join(""); - }).join(""), " return !!(", js, ");};})()"].join(""); + }).join("") + " return !!(" + js + ");"; + var f = new Function("fact, hash, definedFuncs, scope", body); + + return function (fact, hash) { + return f(fact, hash, definedFuncs, scope); + }; }; exports.getMatcher = function (rule, scope) { - var js = toJs(rule, scope); - return eval(js); + return toJs(rule, scope); }; exports.toConstraints = function (constraint, options) { diff --git a/lib/context.js b/lib/context.js index d04340e..e7be06c 100644 --- a/lib/context.js +++ b/lib/context.js @@ -1,5 +1,7 @@ "use strict"; var extd = require("./extended"), + isBoolean = extd.isBoolean, + isDefined = extd.isDefined, declare = extd.declare, merge = extd.merge, union = extd.union, @@ -20,7 +22,7 @@ var Match = declare({ if (assertable instanceof this._static) { this.isMatch = assertable.isMatch; this.facts = this.facts.concat(assertable.facts); - this.factIds = this.factIds.concat(assertable.factIds); + this.factIds = this.factIds.concat(assertable.factIds).sort(); this.hashCode = this.factIds.join(":"); this.factHash = merge(this.factHash, assertable.factHash); this.recency = union(this.recency, assertable.recency); @@ -39,7 +41,7 @@ var Match = declare({ var ret = new this._static(); ret.isMatch = mr.isMatch; ret.facts = this.facts.concat(mr.facts); - ret.factIds = this.factIds.concat(mr.factIds); + ret.factIds = this.factIds.concat(mr.factIds).sort(); ret.hashCode = ret.factIds.join(":"); ret.factHash = merge({}, this.factHash, mr.factHash); ret.recency = union(this.recency, mr.recency); @@ -72,12 +74,24 @@ var Context = declare({ }, isMatch: function (isMatch) { - this.match.isMatch = isMatch; + if (isBoolean(isMatch)) { + this.match.isMatch = isMatch; + } else { + return this.match.isMatch; + } + return this; + }, + + mergeMatch: function (merge) { + var match = this.match = this.match.merge(merge); + this.factHash = match.factHash; + this.hashCode = match.hashCode; + this.factIds = match.factIds; return this; }, clone: function (fact, paths, match) { - return new Context(fact || this.fact, paths || this.path, match || this.match); + return new Context(fact || this.fact, null, match || this.match); } } }).as(module); diff --git a/lib/index.js b/lib/index.js index e7775e9..7467f83 100644 --- a/lib/index.js +++ b/lib/index.js @@ -615,7 +615,9 @@ var extd = require("./extended"), rule = require("./rule"), wm = require("./workingMemory"), WorkingMemory = wm.WorkingMemory, - InitialFact = require("./pattern").InitialFact, + pattern = require("./pattern"), + CompositePattern = pattern.CompositePattern, + InitialFact = pattern.InitialFact, Fact = wm.Fact, compile = require("./compile"); @@ -628,9 +630,16 @@ var sortAgenda = function (a, b) { var p1 = a.rule.priority, p2 = b.rule.priority; if (p1 !== p2) { ret = p1 - p2; - } else if (a.counter !== b.counter) { + } + if (a.counter !== b.counter) { ret = a.counter - b.counter; } + if (!ret) { + ret = a.recency - b.recency; + } + if (!ret) { + ret = a.rule.pattern.getSpecificity() - b.rule.pattern.getSpecificity(); + } if (!ret) { var i = 0; @@ -645,8 +654,9 @@ var sortAgenda = function (a, b) { // } } if (!ret) { - ret = a.recency - b.recency; + ret = a.rule.pattern.getSpecificity() - b.rule.pattern.getSpecificity(); } + return ret > 0 ? 1 : -1; }; diff --git a/lib/nodes/fromNode.js b/lib/nodes/fromNode.js new file mode 100644 index 0000000..58f3b74 --- /dev/null +++ b/lib/nodes/fromNode.js @@ -0,0 +1,112 @@ +var Node = require("./joinNode"), + extd = require("../extended"), + constraint = require("../constraint"), + EqualityConstraint = constraint.EqualityConstraint, + HashConstraint = constraint.HashConstraint, + ReferenceConstraint = constraint.ReferenceConstraint, + Context = require("../context"), + pluck = extd.pluck, + forEach = extd.forEach, + isArray = extd.isArray, + indexOf = extd.indexOf; + +var DEFAULT_MATCH = {isMatch: function () { + return false; +}}; +Node.extend({ + instance: { + + constructor: function (pattern, wm) { + this._super(arguments); + this.workingMemory = wm; + this.__fromMemory = {}; + this.pattern = pattern; + this.type = pattern.get("constraints")[0]; + this.alias = pattern.get("alias"); + this.from = pattern.from; + 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); + } else if (c instanceof HashConstraint) { + vars = vars.concat(c.get("variables")); + } + }); + this.__variables = vars; + + }, + + __createMatches: function (context) { + var fh = context.factHash, o = pluck([fh], this.from)[0], newContext; + if (isArray(o)) { + for (var i = 0, l = o.length; i < l; i++) { + if ((newContext = this.__createMatch(context, o[i])).isMatch()) { + this.__propagate("assert", newContext); + } + } + } else if ((newContext = this.__createMatch(context, o)).isMatch()) { + this.__propagate("assert", newContext); + } + }, + + __createMatch: function (lc, o) { + if (this.type.assert(o)) { + var rc = new Context(this.workingMemory.getFactHandle(o)) + .set(this.alias, o); + var fh = rc.factHash, lcFh = lc.factHash; + for (var key in lcFh) { + fh[key] = lcFh[key]; + } + var eqConstraints = this.__equalityConstraints, vars = this.__variables; + for (var i = 0, l = eqConstraints.length; i < l; i++) { + if (!eqConstraints[i].assert(fh)) { + return DEFAULT_MATCH; + } + } + var prop; + for (i = 0, l = vars.length; i < l; i++) { + prop = vars[i]; + fh[prop] = o[prop]; + } + return lc.clone(null, null, lc.match.merge(rc.match)); + } + return DEFAULT_MATCH; + }, + +// retractLeft: function (fact) { +// var contexts = this.leftMemory[fact.id], tuples = this.leftTuples, i, l, found = false; +// if (contexts) { +// found = true; +// for (i = 0, l = contexts.length; i < l; i++) { +// var index = indexOf(tuples, contexts[i]); +// tuples.splice(index, 1); +// //this.propagateRetract(tuple.fac); +// } +// delete this.leftMemory[fact.id]; +// } +// this.propagateRetract(fact); +// }, +// + retractRight: function (fact) { + throw new Error("Shouldnt have gotten here"); + }, + + assertLeft: function (context) { +// this.leftTuples.push(context); + this.__addToLeftMemory(context); + this.__createMatches(context); + + }, + + assertRight: function (context) { + throw new Error("Shouldnt have gotten here"); + }, + + + toString: function () { + return "FromNode" + this.__count; + } + + } +}).as(module); \ No newline at end of file diff --git a/lib/nodes/fromNotNode.js b/lib/nodes/fromNotNode.js new file mode 100644 index 0000000..9f4d6ee --- /dev/null +++ b/lib/nodes/fromNotNode.js @@ -0,0 +1,80 @@ +var Node = require("./joinNode"), + extd = require("../extended"), + constraint = require("../constraint"), + EqualityConstraint = constraint.EqualityConstraint, + HashConstraint = constraint.HashConstraint, + ReferenceConstraint = constraint.ReferenceConstraint, + Context = require("../context"), + pluck = extd.pluck, + forEach = extd.forEach, + isArray = extd.isArray; + +Node.extend({ + instance: { + + constructor: function (pattern) { + this._super(arguments); + this.pattern = pattern; + this.type = pattern.get("constraints")[0]; + this.alias = pattern.get("alias"); + this.from = pattern.from; + 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); + } else if (c instanceof HashConstraint) { + vars = vars.concat(c.get("variables")); + } + }); + this.__variables = vars; + + }, + + __findMatches: function (context) { + var fh = context.factHash, o = pluck([fh], this.from)[0], isMatch = false; + if (isArray(o)) { + for (var i = 0, l = o.length; i < l; i++) { + if (this.__isMatch(context, o[i])) { + return; + } + } + this.__propagate("assert", context.clone()); + } else if (!this.__isMatch(context, o)) { + this.__propagate("assert", context); + } + return isMatch; + }, + + __isMatch: function (oc, o) { + if (this.type.assert(o)) { + var ret = new Context(o, null) + .mergeMatch(oc.match) + .set(this.alias, o); + var fh = ret.factHash; + var eqConstraints = this.__equalityConstraints; + for (var i = 0, l = eqConstraints.length; i < l; i++) { + if (eqConstraints[i].assert(fh)) { + return true; + } + } + } + return false; + }, + + assertLeft: function (context) { + this.__findMatches(context); + + }, + + assertRight: function () { + throw new Error("Shouldnt have gotten here"); + }, + + + toString: function () { + return "FromNode" + this.__count; + } + + } +}).as(module); \ No newline at end of file diff --git a/lib/nodes/index.js b/lib/nodes/index.js index 49ef321..03e6e78 100644 --- a/lib/nodes/index.js +++ b/lib/nodes/index.js @@ -5,6 +5,8 @@ var extd = require("../extended"), 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, @@ -15,6 +17,8 @@ var extd = require("../extended"), EqualityNode = require("./equalityNode"), JoinNode = require("./joinNode"), NotNode = require("./notNode"), + FromNode = require("./fromNode"), + FromNotNode = require("./fromNotNode"), LeftAdapterNode = require("./leftAdapterNode"), RightAdapterNode = require("./rightAdapterNode"), TypeNode = require("./typeNode"), @@ -35,6 +39,7 @@ declare({ recency: 0 }; this.agendaTree = agendaTree; + this.workingMemory = wm; }, assertRule: function (rule) { @@ -136,6 +141,10 @@ declare({ 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); @@ -152,7 +161,7 @@ declare({ __addToNetwork: function (rule, pattern, outNode, side) { if (pattern instanceof ObjectPattern) { - if (pattern instanceof NotPattern && (!side || side === "left")) { + if ((pattern instanceof NotPattern || pattern instanceof FromPattern || pattern instanceof FromNotPattern) && (!side || side === "left")) { return this.__createBetaNode(rule, new CompositePattern(new InitialFactPattern(), pattern), outNode, side); } this.__createAlphaNode(rule, pattern, outNode, side); @@ -171,36 +180,41 @@ declare({ __createAlphaNode: function (rule, pattern, outNode, side) { - var constraints = pattern.get("constraints"); - var typeNode = this.__createTypeNode(rule, pattern); - var aliasNode = this.__createAliasNode(rule, pattern); - typeNode.addOutNode(aliasNode, pattern); - aliasNode.addParentNode(typeNode); - var 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); + 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; } - 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; + + 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; } - outNode.addParentNode(parentNode); - parentNode.addOutNode(outNode, pattern); - return typeNode; }, print: function () { diff --git a/lib/nodes/terminalNode.js b/lib/nodes/terminalNode.js index e0d7608..a65c30c 100644 --- a/lib/nodes/terminalNode.js +++ b/lib/nodes/terminalNode.js @@ -1,5 +1,6 @@ var Node = require("./node"), extd = require("../extended"), + sum = extd.sum, bind = extd.bind, removeDuplicates = extd.removeDuplicates; @@ -29,7 +30,7 @@ Node.extend({ rule: rule, index: this.index, name: rule.name, - recency: bucket.recency++, + recency: sum(match.recency), match: match, counter: bucket.counter }); diff --git a/lib/parser/nools/tokens.js b/lib/parser/nools/tokens.js index 2e30a73..d3e0010 100644 --- a/lib/parser/nools/tokens.js +++ b/lib/parser/nools/tokens.js @@ -39,6 +39,7 @@ var ruleTokens = { }; var constraintRegExp = /(\{(?:["']?\$?\w+["']?\s*:\s*["']?\$?\w+["']? *(?:, *["']?\$?\w+["']?\s*:\s*["']?\$?\w+["']?)*)+\})/; var predicateExp = /^(\w+) *\((.*)\)$/m; + var fromRegExp = /(\bfrom\s+.*)/; var parseRules = function (str) { var rules = []; var ruleLines = str.split(";"), l = ruleLines.length, ruleLine; @@ -61,9 +62,14 @@ var ruleTokens = { if (parts && parts.length) { rule.push(parts[2], parts[1]); var constraints = parts[3].replace(/^\s*|\s*$/g, ""); - var hashParts = constraints.match(constraintRegExp); + 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, "")); } @@ -71,8 +77,16 @@ var ruleTokens = { 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); diff --git a/lib/pattern.js b/lib/pattern.js index 1a98eec..f8f315a 100644 --- a/lib/pattern.js +++ b/lib/pattern.js @@ -1,93 +1,140 @@ -(function () { - "use strict"; - var extd = require("./extended"), - merge = extd.merge, - forEach = extd.forEach, - declare = extd.declare, - constraintMatcher = require("./constraintMatcher"), - constraint = require("./constraint"); - - - var Pattern = declare({}); - - var ObjectPattern = Pattern.extend({ - instance: { - constructor: function (type, alias, conditions, store, options) { - options = options || {}; - this.type = type; - this.alias = alias; - this.conditions = conditions; - this.pattern = options.pattern; - this.constraints = [new constraint.ObjectConstraint(type)]; - var constrnts = constraintMatcher.toConstraints(conditions, merge({alias: alias}, options)); - if (constrnts.length) { - this.constraints = this.constraints.concat(constrnts); - } else { - var cnstrnt = new constraint.TrueConstraint(); - this.constraints.push(cnstrnt); - } - if (store && !extd.isEmpty(store)) { - var atm = new constraint.HashConstraint(store); - this.constraints.push(atm); +"use strict"; +var extd = require("./extended"), + has = extd.has, + isEmpty = extd.isEmpty, + merge = extd.merge, + forEach = extd.forEach, + declare = extd.declare, + constraintMatcher = require("./constraintMatcher"), + constraint = require("./constraint"), + EqualityConstraint = constraint.EqualityConstraint; + + +var Pattern = declare({}); + +var ObjectPattern = Pattern.extend({ + instance: { + constructor: function (type, alias, conditions, store, options) { + options = options || {}; + 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); + } + + forEach(constraints, function (constraint) { + constraint.set("alias", alias); + }); + this.constraints = constraints; + }, + + getSpecificity: function () { + var constraints = this.constraints, specificity = 0; + for (var i = 0, l = constraints.length; i < l; i++) { + if (constraints[i] instanceof EqualityConstraint) { + specificity++; } - forEach(this.constraints, function (constraint) { - constraint.set("alias", alias); - }); - }, - - 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); } + 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"); + } +}).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 = from.from; + }, + + hasConstraint: function (type) { + return extd.some(this.constraints, function (c) { + return c instanceof type; + }); + }, + + getSpecificity: function () { + return this._super(arguments) + 1; + }, + + hashCode: function () { + return [this.type, this.alias, extd.format("%j", this.conditions), this.from.from].join(":"); + }, + + toString: function () { + return extd.format("%j from %s", this.constraints, this.from.from); + } + } +}).as(exports, "FromPattern"); - ObjectPattern.extend().as(exports, "NotPattern"); - Pattern.extend({ +FromPattern.extend().as(exports, "FromNotPattern"); +ObjectPattern.extend().as(exports, "NotPattern"); - instance: { - constructor: function (left, right) { - this.leftPattern = left; - this.rightPattern = right; - }, +Pattern.extend({ - hashCode: function () { - return [this.leftPattern.hashCode(), this.rightPattern.hashCode()].join(":"); - }, + instance: { + constructor: function (left, right) { + this.leftPattern = left; + this.rightPattern = right; + }, - getters: { - constraints: function () { - return this.leftPattern.constraints.concat(this.rightPattern.constraints); - } + 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(exports, "CompositePattern"); +}).as(exports, "CompositePattern"); - var InitialFact = declare({}).as(exports, "InitialFact"); +var InitialFact = declare({}).as(exports, "InitialFact"); - ObjectPattern.extend({ - instance: { - constructor: function () { - this._super([InitialFact, "i", [], {}]); - }, +ObjectPattern.extend({ + instance: { + constructor: function () { + this._super([InitialFact, "i", [], {}]); + }, - assert: function () { - return true; - } + assert: function () { + return true; } - }).as(exports, "InitialFactPattern"); + } +}).as(exports, "InitialFactPattern"); + -})(); diff --git a/lib/rule.js b/lib/rule.js index 55c8409..1fab651 100644 --- a/lib/rule.js +++ b/lib/rule.js @@ -2,15 +2,65 @@ var extd = require("./extended"), isArray = extd.isArray, isString = extd.isString, + isHash = extd.isHash, + format = extd.format, Promise = extd.Promise, when = extd.when, declare = extd.declare, parser = require("./parser"), pattern = require("./pattern"), ObjectPattern = pattern.ObjectPattern, + FromPattern = pattern.FromPattern, NotPattern = pattern.NotPattern, + FromNotPattern = pattern.FromNotPattern, CompositePattern = pattern.CompositePattern; +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 (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 () { @@ -70,29 +120,56 @@ var parsePattern = extd }) .contains("not", function (condition) { condition.shift(); - return [ - new NotPattern( - getParamType(condition[0]), - condition[1] || "m", - parser.parseConstraint(condition[2] || "true"), - condition[3] || {}, - {scope: condition.scope, pattern: condition[2]} - ) - ]; + 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] || {}, + condition[4], + {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) { - return [ - new ObjectPattern( - getParamType(condition[0]), - condition[1] || "m", - parser.parseConstraint(condition[2] || "true"), - condition[3] || {}, - {scope: condition.scope, pattern: condition[2]} - ) - ]; + 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] || {}, + condition[4], + {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) { @@ -119,7 +196,7 @@ var Rule = declare({ }); function createRule(name, options, conditions, cb) { - if (extd.isArray(options)) { + if (isArray(options)) { cb = conditions; conditions = options; } else { diff --git a/lib/workingMemory.js b/lib/workingMemory.js index 8937e24..b019a59 100644 --- a/lib/workingMemory.js +++ b/lib/workingMemory.js @@ -4,7 +4,7 @@ var declare = require("declare.js"); var id = 0; -declare({ +var Fact = declare({ instance: { constructor: function (obj) { @@ -41,6 +41,20 @@ declare({ this.facts.length = 0; }, + getFactHandle: function (o) { + var facts = this.facts, l = facts.length; + for (var i = 0; i < l; i++) { + var existingFact = facts[i]; + if (existingFact.equals(o)) { + return existingFact; + } + } + var ret = new Fact(o); + ret.recency = this.recency++; + facts.push(ret); + return ret; + }, + assertFact: function (fact) { if (fact.object === null) { throw new Error('The fact asserted cannot be null!'); diff --git a/nools.js b/nools.js index f705095..671f7f0 100644 --- a/nools.js +++ b/nools.js @@ -1015,10 +1015,21 @@ var extd = require("./extended"), rule = require("./rule"), wm = require("./workingMemory"), WorkingMemory = wm.WorkingMemory, - InitialFact = require("./pattern").InitialFact, + pattern = require("./pattern"), + CompositePattern = pattern.CompositePattern, + InitialFact = pattern.InitialFact, Fact = wm.Fact, compile = require("./compile"); +function getSpecificity(pattern){ + var specificity = 0; + if(pattern instanceof CompositePattern){ + specificity += getSpecificity(pattern.leftPattern) + getSpecificity(pattern.rightPattern); + }else{ + specificity += pattern.getSpecificity(); + } + return specificity; +} var sortAgenda = function (a, b) { if (a === b) { @@ -1028,9 +1039,13 @@ var sortAgenda = function (a, b) { var p1 = a.rule.priority, p2 = b.rule.priority; if (p1 !== p2) { ret = p1 - p2; - } else if (a.counter !== b.counter) { + } + if (a.counter !== b.counter) { ret = a.counter - b.counter; } + if(!ret){ + ret = a.recency - b.recency; + } if (!ret) { var i = 0; @@ -1044,9 +1059,12 @@ var sortAgenda = function (a, b) { } // } } - if (!ret) { + if(!ret){ ret = a.recency - b.recency; } + if(!ret){ + ret = getSpecificity(a.rule.pattern) - getSpecificity(b.rule.pattern); + } return ret > 0 ? 1 : -1; }; @@ -2999,6 +3017,8 @@ require.define("/node_modules/is-extended/index.js",function(require,module,expo var undef, pSlice = Array.prototype.slice; + var hasOwnProperty = Object.prototype.hasOwnProperty; + function argsToArray(args, slice) { slice = slice || 0; return pSlice.call(args, slice); @@ -3288,6 +3308,42 @@ require.define("/node_modules/is-extended/index.js",function(require,module,expo 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 has(obj, prop) { + return hasOwnProperty.call(obj, prop); + } + + function notHas(obj, prop) { + return !has(obj, prop); + } + + function length(obj, l) { + if (has(obj, "length")) { + return obj.length === l; + } + return false; + } + + function notLength(obj, l) { + if (has(obj, "length")) { + return obj.length !== l; + } + return false; + } + var isa = { isFunction: isFunction, isObject: isObject, @@ -3322,7 +3378,13 @@ require.define("/node_modules/is-extended/index.js",function(require,module,expo isLike: isLike, isNotLike: isNotLike, contains: contains, - notContains: notContains + notContains: notContains, + has: has, + notHas: notHas, + isLength: length, + isNotLength: notLength, + containsAt: containsAt, + notContainsAt: notContainsAt }; var tester = { @@ -3429,7 +3491,7 @@ require.define("/node_modules/is-extended/index.js",function(require,module,expo return defineIsa((require("extended"))); }); } else { - this.is = defineIsa(this.extended); + this.isExtended = defineIsa(this.extended); } }).call(this); @@ -7867,6 +7929,8 @@ var extd = require("../extended"), 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, @@ -7877,6 +7941,8 @@ var extd = require("../extended"), EqualityNode = require("./equalityNode"), JoinNode = require("./joinNode"), NotNode = require("./notNode"), + FromNode = require("./fromNode"), + FromNotNode = require("./fromNotNode"), LeftAdapterNode = require("./leftAdapterNode"), RightAdapterNode = require("./rightAdapterNode"), TypeNode = require("./typeNode"), @@ -7897,6 +7963,7 @@ declare({ recency: 0 }; this.agendaTree = agendaTree; + this.workingMemory = wm; }, assertRule: function (rule) { @@ -7998,6 +8065,10 @@ declare({ 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); @@ -8014,7 +8085,7 @@ declare({ __addToNetwork: function (rule, pattern, outNode, side) { if (pattern instanceof ObjectPattern) { - if (pattern instanceof NotPattern && (!side || side === "left")) { + if ((pattern instanceof NotPattern || pattern instanceof FromPattern || pattern instanceof FromNotPattern) && (!side || side === "left")) { return this.__createBetaNode(rule, new CompositePattern(new InitialFactPattern(), pattern), outNode, side); } this.__createAlphaNode(rule, pattern, outNode, side); @@ -8033,36 +8104,41 @@ declare({ __createAlphaNode: function (rule, pattern, outNode, side) { - var constraints = pattern.get("constraints"); - var typeNode = this.__createTypeNode(rule, pattern); - var aliasNode = this.__createAliasNode(rule, pattern); - typeNode.addOutNode(aliasNode, pattern); - aliasNode.addParentNode(typeNode); - var 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); + 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; } - 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; + + 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; } - outNode.addParentNode(parentNode); - parentNode.addOutNode(outNode, pattern); - return typeNode; }, print: function () { @@ -8080,98 +8156,137 @@ declare({ }); -require.define("/lib/pattern.js",function(require,module,exports,__dirname,__filename,process,global){(function () { - "use strict"; - var extd = require("./extended"), - merge = extd.merge, - forEach = extd.forEach, - declare = extd.declare, - constraintMatcher = require("./constraintMatcher"), - constraint = require("./constraint"); - - - var Pattern = declare({}); - - var ObjectPattern = Pattern.extend({ - instance: { - constructor: function (type, alias, conditions, store, options) { - options = options || {}; - this.type = type; - this.alias = alias; - this.conditions = conditions; - this.pattern = options.pattern; - this.constraints = [new constraint.ObjectConstraint(type)]; - var constrnts = constraintMatcher.toConstraints(conditions, merge({alias: alias}, options)); - if (constrnts.length) { - this.constraints = this.constraints.concat(constrnts); - } else { - var cnstrnt = new constraint.TrueConstraint(); - this.constraints.push(cnstrnt); - } - if (store && !extd.isEmpty(store)) { - var atm = new constraint.HashConstraint(store); - this.constraints.push(atm); - } - forEach(this.constraints, function (constraint) { - constraint.set("alias", alias); - }); - }, +require.define("/lib/pattern.js",function(require,module,exports,__dirname,__filename,process,global){"use strict"; +var extd = require("./extended"), + has = extd.has, + isEmpty = extd.isEmpty, + merge = extd.merge, + forEach = extd.forEach, + declare = extd.declare, + constraintMatcher = require("./constraintMatcher"), + constraint = require("./constraint"), + EqualityConstraint = constraint.EqualityConstraint; - 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(":"); - }, +var Pattern = declare({}); - toString: function () { - return extd.format("%j", this.constraints); +var ObjectPattern = Pattern.extend({ + instance: { + constructor: function (type, alias, conditions, store, options) { + options = options || {}; + 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); + } + + forEach(constraints, function (constraint) { + constraint.set("alias", alias); + }); + this.constraints = constraints; + }, + + 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 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"); + } +}).as(exports, "ObjectPattern"); - ObjectPattern.extend().as(exports, "NotPattern"); +var FromPattern = ObjectPattern.extend({ + instance: { + constructor: function (type, alias, conditions, store, from, options) { + this._super([type, alias, conditions, store, options]); + this.from = from.from; + }, - Pattern.extend({ + hasConstraint: function (type) { + return extd.some(this.constraints, function (c) { + return c instanceof type; + }); + }, - instance: { - constructor: function (left, right) { - this.leftPattern = left; - this.rightPattern = right; - }, + hashCode: function () { + return [this.type, this.alias, extd.format("%j", this.conditions), this.from.from].join(":"); + }, - hashCode: function () { - return [this.leftPattern.hashCode(), this.rightPattern.hashCode()].join(":"); - }, + toString: function () { + return extd.format("%j from %s", this.constraints, this.from.from); + } + } +}).as(exports, "FromPattern"); - getters: { - constraints: function () { - return this.leftPattern.constraints.concat(this.rightPattern.constraints); - } + +FromPattern.extend().as(exports, "FromNotPattern"); +ObjectPattern.extend().as(exports, "NotPattern"); + +Pattern.extend({ + + instance: { + constructor: function (left, right) { + this.leftPattern = left; + this.rightPattern = right; + }, + + hashCode: function () { + return [this.leftPattern.hashCode(), this.rightPattern.hashCode()].join(":"); + }, + + getters: { + constraints: function () { + return this.leftPattern.constraints.concat(this.rightPattern.constraints); } } + } - }).as(exports, "CompositePattern"); +}).as(exports, "CompositePattern"); - var InitialFact = declare({}).as(exports, "InitialFact"); +var InitialFact = declare({}).as(exports, "InitialFact"); - ObjectPattern.extend({ - instance: { - constructor: function () { - this._super([InitialFact, "i", [], {}]); - }, +ObjectPattern.extend({ + instance: { + constructor: function () { + this._super([InitialFact, "i", [], {}]); + }, - assert: function () { - return true; - } + assert: function () { + return true; } - }).as(exports, "InitialFactPattern"); + } +}).as(exports, "InitialFactPattern"); + -})(); }); @@ -8189,6 +8304,7 @@ var extd = require("./extended"), atoms = require("./constraint"); var definedFuncs = { + indexOf: extd.indexOf, now: function () { return new Date(); }, @@ -8490,7 +8606,7 @@ var toJs = exports.toJs = function (rule, scope) { var js = lang.parse(rule); scope = scope || {}; var vars = lang.getIdentifiers(rule); - return ["(function(){ return function jsMatcher(fact, hash){", map(vars,function (v) { + var body = "var indexOf = definedFuncs.indexOf;" + map(vars,function (v) { var ret = ["var ", v, " = "]; if (definedFuncs.hasOwnProperty(v)) { ret.push("definedFuncs['", v, "']"); @@ -8501,12 +8617,16 @@ var toJs = exports.toJs = function (rule, scope) { } ret.push(";"); return ret.join(""); - }).join(""), " return !!(", js, ");};})()"].join(""); + }).join("") + " return !!(" + js + ");"; + var f = new Function("fact, hash, definedFuncs, scope", body); + + return function (fact, hash) { + return f(fact, hash, definedFuncs, scope); + }; }; exports.getMatcher = function (rule, scope) { - var js = toJs(rule, scope); - return eval(js); + return toJs(rule, scope); }; exports.toConstraints = function (constraint, options) { @@ -8699,6 +8819,31 @@ Constraint.extend({ } }).as(exports, "HashConstraint"); +Constraint.extend({ + instance: { + constructor: function (prop, constraints) { + this.type = "from"; + this.prop = prop; + this.constraints = constraints; + }, + + equal: function (constraint) { + return extd.instanceOf(constraint, this._static) && this.get("alias") === constraint.get("alias") && extd.deepEqual(this.constraints, constraint.constraints); + }, + + "assert": function () { + return true; + }, + + getters: { + variables: function () { + return this.constraint; + } + } + + } +}).as(exports, "FromConstraint"); + @@ -8883,6 +9028,8 @@ declare({ require.define("/lib/context.js",function(require,module,exports,__dirname,__filename,process,global){"use strict"; var extd = require("./extended"), + isBoolean = extd.isBoolean, + isDefined = extd.isDefined, declare = extd.declare, merge = extd.merge, union = extd.union, @@ -8903,7 +9050,7 @@ var Match = declare({ if (assertable instanceof this._static) { this.isMatch = assertable.isMatch; this.facts = this.facts.concat(assertable.facts); - this.factIds = this.factIds.concat(assertable.factIds); + this.factIds = this.factIds.concat(assertable.factIds).sort(); this.hashCode = this.factIds.join(":"); this.factHash = merge(this.factHash, assertable.factHash); this.recency = union(this.recency, assertable.recency); @@ -8922,7 +9069,7 @@ var Match = declare({ var ret = new this._static(); ret.isMatch = mr.isMatch; ret.facts = this.facts.concat(mr.facts); - ret.factIds = this.factIds.concat(mr.factIds); + ret.factIds = this.factIds.concat(mr.factIds).sort(); ret.hashCode = ret.factIds.join(":"); ret.factHash = merge({}, this.factHash, mr.factHash); ret.recency = union(this.recency, mr.recency); @@ -8955,12 +9102,24 @@ var Context = declare({ }, isMatch: function (isMatch) { - this.match.isMatch = isMatch; + if (isBoolean(isMatch)) { + this.match.isMatch = isMatch; + } else { + return this.match.isMatch; + } + return this; + }, + + mergeMatch: function (merge) { + var match = this.match = this.match.merge(merge); + this.factHash = match.factHash; + this.hashCode = match.hashCode; + this.factIds = match.factIds; return this; }, clone: function (fact, paths, match) { - return new Context(fact || this.fact, paths || this.path, match || this.match); + return new Context(fact || this.fact, null, match || this.match); } } }).as(module); @@ -9369,6 +9528,202 @@ JoinNode.extend({ }).as(module); }); +require.define("/lib/nodes/fromNode.js",function(require,module,exports,__dirname,__filename,process,global){var Node = require("./joinNode"), + extd = require("../extended"), + constraint = require("../constraint"), + EqualityConstraint = constraint.EqualityConstraint, + HashConstraint = constraint.HashConstraint, + ReferenceConstraint = constraint.ReferenceConstraint, + Context = require("../context"), + pluck = extd.pluck, + forEach = extd.forEach, + isArray = extd.isArray, + indexOf = extd.indexOf; + +var DEFAULT_MATCH = {isMatch: function () { + return false; +}}; +Node.extend({ + instance: { + + constructor: function (pattern, wm) { + this._super(arguments); + this.workingMemory = wm; + this.__fromMemory = {}; + this.pattern = pattern; + this.type = pattern.get("constraints")[0]; + this.alias = pattern.get("alias"); + this.from = pattern.from; + 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); + } else if (c instanceof HashConstraint) { + vars = vars.concat(c.get("variables")); + } + }); + this.__variables = vars; + + }, + + __createMatches: function (context) { + var fh = context.factHash, o = pluck([fh], this.from)[0], newContext; + if (isArray(o)) { + for (var i = 0, l = o.length; i < l; i++) { + if ((newContext = this.__createMatch(context, o[i])).isMatch()) { + this.__propagate("assert", newContext); + } + } + } else if ((newContext = this.__createMatch(context, o)).isMatch()) { + this.__propagate("assert", newContext); + } + }, + + __createMatch: function (lc, o) { + if (this.type.assert(o)) { + var rc = new Context(this.workingMemory.getFactHandle(o)) + .set(this.alias, o); + var fh = rc.factHash, lcFh = lc.factHash; + for (var key in lcFh) { + fh[key] = lcFh[key]; + } + var eqConstraints = this.__equalityConstraints, vars = this.__variables; + for (var i = 0, l = eqConstraints.length; i < l; i++) { + if (!eqConstraints[i].assert(fh)) { + return DEFAULT_MATCH; + } + } + var prop; + for (i = 0, l = vars.length; i < l; i++) { + prop = vars[i]; + fh[prop] = o[prop]; + } + return new Context(rc.fact, null, lc.match.merge(rc.match)); + } + return DEFAULT_MATCH; + }, + + retractLeft: function (fact) { + var contexts = this.leftMemory[fact.id], tuples = this.leftTuples, i, l, found = false; + if (contexts) { + found = true; + for (i = 0, l = contexts.length; i < l; i++) { + var index = indexOf(tuples, contexts[i]); + tuples.splice(index, 1); + //this.propagateRetract(tuple.match); + } + delete this.leftMemory[fact.id]; + } + this.propagateRetract(fact); + }, +// + retractRight: function (fact) { + throw new Error("Shouldnt have gotten here"); + }, + + assertLeft: function (context) { +// this.leftTuples.push(context); + this.__addToLeftMemory(context); + this.__createMatches(context); + + }, + + assertRight: function (context) { + throw new Error("Shouldnt have gotten here"); + }, + + + toString: function () { + return "FromNode" + this.__count; + } + + } +}).as(module); +}); + +require.define("/lib/nodes/fromNotNode.js",function(require,module,exports,__dirname,__filename,process,global){var Node = require("./joinNode"), + extd = require("../extended"), + constraint = require("../constraint"), + EqualityConstraint = constraint.EqualityConstraint, + HashConstraint = constraint.HashConstraint, + ReferenceConstraint = constraint.ReferenceConstraint, + Context = require("../context"), + pluck = extd.pluck, + forEach = extd.forEach, + isArray = extd.isArray; + +Node.extend({ + instance: { + + constructor: function (pattern) { + this._super(arguments); + this.pattern = pattern; + this.type = pattern.get("constraints")[0]; + this.alias = pattern.get("alias"); + this.from = pattern.from; + 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); + } else if (c instanceof HashConstraint) { + vars = vars.concat(c.get("variables")); + } + }); + this.__variables = vars; + + }, + + __findMatches: function (context) { + var fh = context.factHash, o = pluck([fh], this.from)[0], isMatch = false; + if (isArray(o)) { + for (var i = 0, l = o.length; i < l; i++) { + if (this.__isMatch(context, o[i])) { + return; + } + } + this.__propagate("assert", context.clone()); + } else if (!this.__isMatch(context, o)) { + this.__propagate("assert", context); + } + return isMatch; + }, + + __isMatch: function (oc, o) { + if (this.type.assert(o)) { + var ret = new Context(o, null) + .mergeMatch(oc.match) + .set(this.alias, o); + var fh = ret.factHash; + var eqConstraints = this.__equalityConstraints; + for (var i = 0, l = eqConstraints.length; i < l; i++) { + if (eqConstraints[i].assert(fh)) { + return true; + } + } + } + return false; + }, + + assertLeft: function (context) { + this.__findMatches(context); + + }, + + assertRight: function () { + throw new Error("Shouldnt have gotten here"); + }, + + + toString: function () { + return "FromNode" + this.__count; + } + + } +}).as(module); +}); + require.define("/lib/nodes/leftAdapterNode.js",function(require,module,exports,__dirname,__filename,process,global){var Node = require("./node"); Node.extend({ @@ -9484,6 +9839,7 @@ AlphaNode.extend({ require.define("/lib/nodes/terminalNode.js",function(require,module,exports,__dirname,__filename,process,global){var Node = require("./node"), extd = require("../extended"), + sum = extd.sum, bind = extd.bind, removeDuplicates = extd.removeDuplicates; @@ -9513,7 +9869,7 @@ Node.extend({ rule: rule, index: this.index, name: rule.name, - recency: bucket.recency++, + recency: sum(match.recency), match: match, counter: bucket.counter }); @@ -9783,15 +10139,65 @@ require.define("/lib/rule.js",function(require,module,exports,__dirname,__filena var extd = require("./extended"), isArray = extd.isArray, isString = extd.isString, + isHash = extd.isHash, + format = extd.format, Promise = extd.Promise, when = extd.when, declare = extd.declare, parser = require("./parser"), pattern = require("./pattern"), ObjectPattern = pattern.ObjectPattern, + FromPattern = pattern.FromPattern, NotPattern = pattern.NotPattern, + FromNotPattern = pattern.FromNotPattern, CompositePattern = pattern.CompositePattern; +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 (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 () { @@ -9851,29 +10257,56 @@ var parsePattern = extd }) .contains("not", function (condition) { condition.shift(); - return [ - new NotPattern( - getParamType(condition[0]), - condition[1] || "m", - parser.parseConstraint(condition[2] || "true"), - condition[3] || {}, - {scope: condition.scope, pattern: condition[2]} - ) - ]; + 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] || {}, + condition[4], + {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) { - return [ - new ObjectPattern( - getParamType(condition[0]), - condition[1] || "m", - parser.parseConstraint(condition[2] || "true"), - condition[3] || {}, - {scope: condition.scope, pattern: condition[2]} - ) - ]; + 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] || {}, + condition[4], + {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) { @@ -9900,7 +10333,7 @@ var Rule = declare({ }); function createRule(name, options, conditions, cb) { - if (extd.isArray(options)) { + if (isArray(options)) { cb = conditions; conditions = options; } else { @@ -10549,6 +10982,7 @@ var ruleTokens = { }; var constraintRegExp = /(\{(?:["']?\$?\w+["']?\s*:\s*["']?\$?\w+["']? *(?:, *["']?\$?\w+["']?\s*:\s*["']?\$?\w+["']?)*)+\})/; var predicateExp = /^(\w+) *\((.*)\)$/m; + var fromRegExp = /(\bfrom\s+.*)/; var parseRules = function (str) { var rules = []; var ruleLines = str.split(";"), l = ruleLines.length, ruleLine; @@ -10571,9 +11005,14 @@ var ruleTokens = { if (parts && parts.length) { rule.push(parts[2], parts[1]); var constraints = parts[3].replace(/^\s*|\s*$/g, ""); - var hashParts = constraints.match(constraintRegExp); + 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, "")); } @@ -10581,8 +11020,16 @@ var ruleTokens = { 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); @@ -10794,7 +11241,7 @@ var declare = require("declare.js"); var id = 0; -declare({ +var Fact = declare({ instance: { constructor: function (obj) { @@ -10831,6 +11278,20 @@ declare({ this.facts.length = 0; }, + getFactHandle: function (o) { + var facts = this.facts, l = facts.length; + for (var i = 0; i < l; i++) { + var existingFact = facts[i]; + if (existingFact.equals(o)) { + return existingFact; + } + } + var ret = new Fact(o); + ret.recency = this.recency++; + facts.push(ret); + return ret; + }, + assertFact: function (fact) { if (fact.object === null) { throw new Error('The fact asserted cannot be null!'); @@ -10927,10 +11388,9 @@ require.define("/lib/compile.js",function(require,module,exports,__dirname,__fil if (/next\(.*\)/.test(action)) { params.push("next"); } - action = declares.join("") + action; - action = ["(function(){ return function _parsedAction(", params.join(","), ")", "{\n\t", action, "\n};}())"].join(""); + action = "with(this){" + declares.join("") + action + "}"; try { - return eval(action); + return bind({defined: defined, scope: scope, bind: bind}, new Function(params.join(","), action)); } catch (e) { throw new Error("Invalid action : " + action + "\n" + e.message); } @@ -11024,9 +11484,8 @@ require.define("/lib/compile.js",function(require,module,exports,__dirname,__fil declares.push("var " + i + "= scope." + i + ";"); } }); - body = ["((function(){", declares.join(""), "\n\treturn ", body, "\n})())"].join(""); try { - return eval(body); + return bind({scope: scope, defined: defined}, new Function("with(this){" + declares.join("") + "\n\treturn " + body + "\n}")); } catch (e) { throw new Error("Invalid action : " + body + "\n" + e.message); } @@ -11035,7 +11494,7 @@ require.define("/lib/compile.js",function(require,module,exports,__dirname,__fil var createDefined = (function () { var _createDefined = function (options) { - options = isString(options) ? eval("(function(){ return " + options + "}())") : options; + options = isString(options) ? new Function("return " + options + ";")() : options; var ret = options.hasOwnProperty("constructor") && "function" === typeof options.constructor ? options.constructor : function (opts) { opts = opts || {}; for (var i in opts) { diff --git a/nools.min.js b/nools.min.js index 83edc41..5af34b4 100644 --- a/nools.min.js +++ b/nools.min.js @@ -1,4 +1,4 @@ -/*! nools - v0.1.0 - 2013-02-22 +/*! nools - v0.1.0 - 2013-02-26 * http://c2fo.github.com/nools * Copyright (c) 2013 Doug Martin (http://c2fo.com); Licensed */ -(function(){var require=function(e,t){var n=require.resolve(e,t||"/"),r=require.modules[n];if(!r)throw new Error("Failed to resolve module "+e+", tried "+n);var i=require.cache[n],s=i?i.exports:r();return s};require.paths=[],require.modules={},require.cache={},require.extensions=[".js",".coffee",".json"],require._core={assert:!0,events:!0,fs:!0,path:!0,vm:!0},require.resolve=function(){return function(e,t){function o(e){e=n.normalize(e);if(require.modules[e])return e;for(var t=0;t=0;i--){if(t[i]==="node_modules")continue;var s=t.slice(0,i+1).join("/")+"/node_modules";r.push(s)}return r}t||(t="/");if(require._core[e])return e;var n=require.modules.path();t=n.resolve("/",t);var r=t||"/";if(e.match(/^(?:\.\.?\/|\/)/)){var i=o(n.resolve(r,e))||u(n.resolve(r,e));if(i)return i}var s=a(e,r);if(s)return s;throw new Error("Cannot find module '"+e+"'")}}(),require.alias=function(e,t){var n=require.modules.path(),r=null;try{r=require.resolve(e+"/package.json","/")}catch(i){r=require.resolve(e,"/")}var s=n.dirname(r),o=(Object.keys||function(e){var t=[];for(var n in e)t.push(n);return t})(require.modules);for(var u=0;u=0;r--){var i=e[r];i=="."?e.splice(r,1):i===".."?(e.splice(r,1),n++):n&&(e.splice(r,1),n--)}if(t)for(;n--;n)e.unshift("..");return e}var f=/^(.+\/(?!$)|\/)?((?:.+?)?(\.[^.]*)?)$/;n.resolve=function(){var e="",t=!1;for(var n=arguments.length;n>=-1&&!t;n--){var r=n>=0?arguments[n]:s.cwd();if(typeof r!="string"||!r)continue;e=r+"/"+e,t=r.charAt(0)==="/"}return e=a(u(e.split("/"),function(e){return!!e}),!t).join("/"),(t?"/":"")+e||"."},n.normalize=function(e){var t=e.charAt(0)==="/",n=e.slice(-1)==="/";return e=a(u(e.split("/"),function(e){return!!e}),!t).join("/"),!e&&!t&&(e="."),e&&n&&(e+="/"),(t?"/":"")+e},n.join=function(){var e=Array.prototype.slice.call(arguments,0);return n.normalize(u(e,function(e,t){return e&&typeof e=="string"}).join("/"))},n.dirname=function(e){var t=f.exec(e)[1]||"",n=!1;return t?t.length===1||n&&t.length<=3&&t.charAt(1)===":"?t:t.substring(0,t.length-1):"."},n.basename=function(e,t){var n=f.exec(e)[2]||"";return t&&n.substr(-1*t.length)===t&&(n=n.substr(0,n.length-t.length)),n},n.extname=function(e){return f.exec(e)[3]||""}}),require.define("__browserify_process",function(e,t,n,r,i,s,o){var s=t.exports={};s.nextTick=function(){var e=typeof window!="undefined"&&window.setImmediate,t=typeof window!="undefined"&&window.postMessage&&window.addEventListener;if(e)return function(e){return window.setImmediate(e)};if(t){var n=[];return window.addEventListener("message",function(e){if(e.source===window&&e.data==="browserify-tick"){e.stopPropagation();if(n.length>0){var t=n.shift();t()}}},!0),function(t){n.push(t),window.postMessage("browserify-tick","*")}}return function(t){setTimeout(t,0)}}(),s.title="browser",s.browser=!0,s.env={},s.argv=[],s.binding=function(t){if(t==="evals")return e("vm");throw new Error("No such module. (Possibly not yet loaded)")},function(){var t="/",n;s.cwd=function(){return t},s.chdir=function(r){n||(n=e("path")),t=n.resolve(r,t)}}()}),require.define("/package.json",function(e,t,n,r,i,s,o){t.exports={main:"index.js"}}),require.define("/index.js",function(e,t,n,r,i,s,o){t.exports=n=e("./lib")}),require.define("/lib/index.js",function(e,t,n,r,i,s,o){"use strict";function _(e){return/\.nools$/.test(e)}function D(e){var t;return _(e)?t=T.parse(a.readFileSync(e,"utf8")):t=T.parse(e),t}var u=e("./extended"),a=e("fs"),f=e("path"),l=u.bind,c=u.indexOf,h=u.forEach,p=u.declare,d=u.Promise,v=u.when,m=u.AVLTree,g=e("./nodes"),y=e("events").EventEmitter,b=e("./rule"),w=e("./workingMemory"),E=w.WorkingMemory,S=e("./pattern").InitialFact,x=w.Fact,T=e("./compile"),N=function(e,t){if(e===t)return 0;var n,r=e.rule.priority,i=t.rule.priority;r!==i?n=r-i:e.counter!==t.counter&&(n=e.counter-t.counter);if(!n){var s=0,o=e.match.recency,u=t.match.recency,a=o.length-1,f=u.length-1;while(o[s]===u[s]&&s0?1:-1},C=p({instance:{constructor:function(){this.memory=[],this.memoryValues=[]},get:function(e){return this.memoryValues[c(this.memory,e)]},remove:function(e){var t=e.match.facts,n=t.length-1,r=this.memoryValues,i=this.memory;for(;n>=0;n--){var s=c(i,t[n]),o=r[s],u=c(o,e);o.splice(u,1)}},insert:function(e){var t=e.match.facts,n=this.memoryValues,r=this.memory,i=t.length-1;for(;i>=0;i--){var s=t[i],o=c(r,s),u=n[o];u||(u=n[r.push(s)-1]=[]),u.push(e)}}}}),k=m.REVERSE_ORDER,L=p({instance:{constructor:function(){this.masterAgenda=new m({compare:N}),this.rules={}},register:function(e){this.rules[e.name]={tree:new m({compare:N}),factTable:new C}},isEmpty:function(){return this.masterAgenda.isEmpty()},pop:function(){var e=this.masterAgenda,t=e.__root;while(t.right)t=t.right;var n=t.data;e.remove(n);var r=this.rules[n.name];return r.tree.remove(n),r.factTable.remove(n),n},peek:function(){var e=this.masterAgenda,t=e.__root;while(t.right)t=t.right;return t.data},removeByFact:function(e,t){var n=this.rules[e.name],r=n.tree,i=n.factTable,s=this.masterAgenda,o=i.get(t)||[],u=o.length-1;for(;u>=0;u--){var a=o[u];i.remove(a),r.remove(a),s.remove(a)}o.length=0},retract:function(e,t){var n=this.rules[e.name],r=n.tree,i=n.factTable,s=this.masterAgenda;r.traverse(r.__root,k,function(e){t(e)&&(i.remove(e),s.remove(e),r.remove(e))})},insert:function(e,t){var n=this.rules[e.name];n.tree.insert(t),this.masterAgenda.insert(t),n.factTable.insert(t)},dispose:function(){this.masterAgenda.clear();var e=this.rules;for(var t in e)t in e&&e[t].tree.clear();this.rules={}}}}),A=p(y,{instance:{name:null,constructor:function(e){this.env=null,this.name=e,this.__rules={},this.__wmAltered=!1,this.workingMemory=new E,this.agenda=new L,this.rootNode=new g.RootNode(this.workingMemory,this.agenda)},halt:function(){return this.__halted=!0,this},dispose:function(){this.workingMemory.dispose(),this.agenda.dispose(),this.rootNode.dispose()},assert:function(e){return this.__wmAltered=!0,this.__factHelper(e,!0),this.emit("assert",e),e},retract:function(e){return this.__wmAltered=!0,this.__factHelper(e,!1),this.emit("retract",e),e},modify:function(e,t){var n=this.retract(e);return"function"==typeof t&&t.call(e,e),this.emit("modify",e),this.assert(n)},print:function(){this.rootNode.print()},containsRule:function(e){return this.rootNode.containsRule(e)},rule:function(e){this.rootNode.assertRule(e)},__loop:function(e,t){var n=new d,r=this,i=this.rootNode;return i?(i.resetCounter(),function s(){e(n,s)}()):n.callback(),n.classic(t),n},__callNext:function(e){var t=this.agenda.pop(),n=this.rootNode;return t.used=!0,this.emit("fire",t.rule.name,t.match.factHash),v(t.rule.fire(this,t.match)).then(l(this,function(){this.__wmAltered&&(n.incrementCounter(),this.__wmAltered=!1)}))},matchUntilHalt:function(e){return this.__halted=!1,this.__loop(l(this,function(e,t){!this.agenda.isEmpty()&&!this.__halted?this.__callNext(t).then(t,e.errback):this.__halted?e.callback():s.nextTick(t)}),e)},match:function(e){return this.__loop(l(this,function(e,t){this.agenda.isEmpty()?e.callback():this.__callNext(t).then(t,e.errback)}),e)},__factHelper:function(e,t){var n=new x(e);return t?n=this.__assertFact(n):n=this.__retractFact(n),n},__assertFact:function(e){var t=this.workingMemory.assertFact(e);return t&&this.rootNode.assertFact(t),t},__retractFact:function(e){var t=this.workingMemory.retractFact(e);return t&&this.rootNode&&this.rootNode.retractFact(t),t}}}),O={},M=p({instance:{constructor:function(e,t){this.name=e,this.cb=t,this.__rules=[],this.__defined={},t&&t.call(this,this);if(!!O.hasOwnProperty(e))throw new Error("Flow with "+e+" already defined");O[e]=this},getDefined:function(e){var t=this.__defined[e.toLowerCase()];if(!t)throw new Error(e+" flow class is not defined");return t},addDefined:function(e,t){return this.__defined[e.toLowerCase()]=t,t},rule:function(){this.__rules=this.__rules.concat(b.createRule.apply(b,arguments))},getSession:function(){var e=new A(this.name);h(this.__rules,function(t){e.rule(t)}),e.assert(new S);for(var t=0,n=arguments.length;tu){e=e?!a(e)&&!s(e)?[e]:e:[];var f=o.name,l=o.f,c;do{c=r[u][f];if("function"==typeof c&&(c=c._f||c)!==l)return o.pos=1+u,c.apply(this,e)}while(i>++u)}return null}function h(){var e=this.__meta,t=e.supers,n=t.length,r=e.superMeta,i=r.pos;if(n>i){var s=r.name,o=r.f,u;do{u=t[i][s];if("function"==typeof u&&(u=u._f||u)!==o)return r.pos=1+i,u.bind(this)}while(n>++i)}return null}function p(e){var t=this.__getters__;return t.hasOwnProperty(e)?t[e].apply(this):this[e]}function d(e,t){var n=this.__setters__;if(!u(e))return n.hasOwnProperty(e)?n[e].apply(this,i(arguments,1)):this[e]=t;for(var r in e){var s=e[r];n.hasOwnProperty(r)?n[e].call(this,s):this[r]=s}}function v(){var e=this.__meta||{},t=e.supers,n=t.length,r=e.superMeta,i=r.pos;if(n>i){var s=r.name,o=r.f,u;do{u=t[i][s];if("function"==typeof u&&(u=u._f||u)!==o)return r.pos=1+i,u.apply(this,arguments)}while(n>++i)}return null}function m(e,t){var n=function(){var r,i=this.__meta||{},s=i.superMeta;return i.superMeta={f:e,pos:0,name:t},r=e.apply(this,arguments),i.superMeta=s,r};return n._f=e,n}function g(e,t){var n=t.setters||{},r=e.__setters__,i=e.__getters__;for(var s in n)r.hasOwnProperty(s)||(r[s]=n[s]);n=t.getters||{};for(s in n)i.hasOwnProperty(s)||(i[s]=n[s]);for(var o in t)if(o!=="getters"&&o!=="setters"){var u=t[o];"function"==typeof u?e.hasOwnProperty(o)||(e[o]=m(v,o)):e[o]=u}}function y(){var e=i(arguments),t=e.length,n=this.prototype,r=n.__meta,s=this.__meta,o=n.__meta.bases,u=o.slice(),a=s.supers||[],f=r.supers||[];for(var l=0;l=0)b(o[u--],n,r);n.unshift(e)}}function w(e,t){var n=t.setters,r=e.__setters__,i=e.__getters__;if(n)for(var s in n)r[s]=n[s];n=t.getters||{};if(n)for(s in n)i[s]=n[s];for(s in t)if(s!="getters"&&s!="setters"){var o=t[s];if("function"==typeof o){var u=o.__meta||{};u.isConstructor?e[s]=o:e[s]=m(o,s)}else e[s]=o}}function E(e,t){return e&&t?e[t]=this:e.exports=e=this,this}function S(e){return N(this,e)}function x(e){r.prototype=e.prototype;var t=new r;return r.prototype=null,t}function T(e,r,i){var o={},a=[],f="declare"+ ++t,p=[],d=[],g=[],E=[],S={supers:g,unique:f,bases:p,superMeta:{f:null,pos:0,name:null}},T={supers:E,unique:f,bases:d,isConstructor:!0,superMeta:{f:null,pos:0,name:null}};u(r)&&!i&&(i=r,r=n),"function"==typeof r||s(r)?(a=s(r)?r:[r],r=a.shift(),e.__meta=T,o=x(r),o.__meta=S,o.__getters__=l({},o.__getters__||{}),o.__setters__=l({},o.__setters__||{}),e.__getters__=l({},e.__getters__||{}),e.__setters__=l({},e.__setters__||{}),b(r.prototype,g,p),b(r,E,d)):(e.__meta=T,o.__meta=S,o.__getters__=o.__getters__||{},o.__setters__=o.__setters__||{},e.__getters__=e.__getters__||{},e.__setters__=e.__setters__||{}),e.prototype=o;if(i){var N=S.proto=i.instance||{},C=T.proto=i.static||{};C.init=C.init||v,w(o,N),w(e,C),N.hasOwnProperty("constructor")?o.constructor=m(N.constructor,"constructor"):o.constructor=N.constructor=m(v,"constructor")}else S.proto={},T.proto={},e.init=m(v,"init"),o.constructor=m(v,"constructor");a.length&&y.apply(e,a),r&&l(e,l(l({},r),e)),o._super=e._super=c,o._getSuper=e._getSuper=h,o._static=e}function N(e,t){function n(){this.constructor.apply(this,arguments)}return T(n,e,t),n.init()||n}function C(e,t){function r(){return n||(this.constructor.apply(this,arguments),n=this),n}var n;return T(r,e,t),r.init()||r}var e=Array.prototype.slice,t=0,n,r=new Function,a=function(t){return Object.prototype.toString.call(t)==="[object Arguments]"};return a(arguments)||(a=function(t){return!!t&&!!t.hasOwnProperty("callee")}),n=N({instance:{get:p,set:d},"static":{get:p,set:d,mixin:y,extend:S,as:E}}),N.singleton=C,N}"undefined"!=typeof n?"undefined"!=typeof t&&t.exports&&(t.exports=e()):"function"==typeof define?define(e):this.declare=e()})()}),require.define("/node_modules/is-extended/package.json",function(e,t,n,r,i,s,o){t.exports={main:"index.js"}}),require.define("/node_modules/is-extended/index.js",function(e,t,n,r,i,s,o){(function(){"use strict";function r(e){function r(e,t){return t=t||0,n.call(e,t)}function i(e){var t=[];for(var n in e)e.hasOwnProperty(n)&&t.push(n);return t}function s(e,t){if(e===t)return!0;if(typeof Buffer!="undefined"&&Buffer.isBuffer(e)&&Buffer.isBuffer(t)){if(e.length!==t.length)return!1;for(var n=0;n=0;a--)if(o[a]!==u[a])return!1;for(a=o.length-1;a>=0;a--){r=o[a];if(!s(e[r],t[r]))return!1}}catch(f){return!1}return!0}function u(e){return typeof e=="function"}function a(e){var t;return e!==null&&e!==t&&typeof e=="object"}function f(e){var t=a(e);return t&&e.constructor===Object}function l(e){if(a(e)){for(var t in e)if(e.hasOwnProperty(t))return!1}else if(E(e)&&e==="")return!0;return!0}function c(e){return Object.prototype.toString.call(e)==="[object Boolean]"}function h(e){return e!==null&&e===t}function p(e){return!h(e)}function d(e){return h(e)||v(e)}function v(e){return e!==t&&e===null}function g(e,t){return u(t)?e instanceof t:!1}function y(e){return!d(e)&&e instanceof RegExp}function b(e){return Object.prototype.toString.call(e)==="[object Array]"}function w(e){return!d(e)&&typeof e=="object"&&e instanceof Date}function E(e){return!d(e)&&(typeof e=="string"||e instanceof String)}function S(e){return!d(e)&&(typeof e=="number"||e instanceof Number)}function x(e){return e===!0}function T(e){return e===!1}function N(e){return!v(e)}function C(e,t){return e==t}function k(e,t){return e!=t}function L(e,t){return e===t}function A(e,t){return e!==t}function O(e,t){if(b(t))for(var n=0,r=t.length;nt}function H(e,t){return e>=t}function B(e,t){return E(t)&&(t=new RegExp(t)),y(t)?t.test(""+e):!1}function j(e,t){return!B(e,t)}function F(e,t){return O(t,e)}function I(e,t){return!O(t,e)}function z(e){R[e]=function(){this._testers.push(q[e])}}function W(e){U[e]=function(){var n=r(arguments,1),i=q[e],s,o=!0;if(n.length<=i.length-1)throw new TypeError("A handler must be defined when calling using switch");s=n.pop(),c(s)&&(o=s,s=n.pop());if(!u(s))throw new TypeError("handler must be defined");this._cases.push(function(e){return i.apply(q,e.concat(n))?[o,s.apply(this,e)]:[!1]})}}var t,n=Array.prototype.slice,m=function(t){return!d(t)&&Object.prototype.toString.call(t)==="[object Arguments]"};m(arguments)||(m=function(t){return!!t&&!!t.hasOwnProperty("callee")});var q={isFunction:u,isObject:a,isEmpty:l,isHash:f,isNumber:S,isString:E,isDate:w,isArray:b,isBoolean:c,isUndefined:h,isDefined:p,isUndefinedOrNull:d,isNull:v,isArguments:m,instanceOf:g,isRegExp:y,deepEqual:s,isTrue:x,isFalse:T,isNotNull:N,isEq:C,isNeq:k,isSeq:L,isSneq:A,isIn:O,isNotIn:M,isLt:_,isLte:D,isGt:P,isGte:H,isLike:B,isNotLike:j,contains:F,notContains:I},R={constructor:function(){this._testers=[]},noWrap:{tester:function(){var e=this._testers;return function(n){var r=!1;for(var i=0,s=e.length;i1)if(o[1]||o[0])return o[1]}if(!i&&t)return t.apply(this,s)}}}};for(var X in q)q.hasOwnProperty(X)&&(W(X),z(X));var V=e.define(q).expose(q);return V.tester=e.define(R),V.switcher=e.define(U),V}"undefined"!=typeof n?"undefined"!=typeof t&&t.exports&&(t.exports=r(e("extended"))):"function"==typeof define?define(["require"],function(e){return r(e("extended"))}):this.is=r(this.extended)}).call(this)}),require.define("/node_modules/array-extended/package.json",function(e,t,n,r,i,s,o){t.exports={main:"index.js"}}),require.define("/node_modules/array-extended/index.js",function(e,t,n,r,i,s,o){(function(){"use strict";function i(e,t){return t=t||0,r.call(e,t)}function s(e,t){function b(e,t){return M(t,function(t,n){return r(n)||(n=[n]),n.unshift(e),t.unshift(n),t},[])}function w(e,t,n){var r=[];for(var i=0;i>>0;if(s===0)return-1;var f=0;arguments.length>2&&(f=Number(arguments[2]),f!==f?f=0:f!==0&&f!==Infinity&&f!==-Infinity&&(f=(f>0||-1)*o(u(f))));if(f>=s)return-1;var l=f>=0?f:a(s-u(f),0);for(;l>>0;if(s===0)return-1;var a=s;arguments.length>2&&(a=Number(arguments[2]),a!==a?a=0:a!==0&&a!==1/0&&a!==-1/0&&(a=(a>0||-1)*o(u(a))));var l=a>=0?f(a,s-1):s-u(a);for(;l>=0;l--)if(l in i&&i[l]===t)return l;return-1}function N(e,t,n){if(e&&m&&m===e.filter)return e.filter(t,n);if(!r(e)||typeof t!="function")throw new TypeError;var i=Object(e),s=i.length>>>0,o=[];for(var u=0;u>>0;for(var o=0;o>>0;for(var o=0;o>>0,o=[];for(var u=0;u2;if(e&&d&&d===e.reduce)return i?e.reduce(t,n):e.reduce(t);if(!r(e)||typeof t!="function")throw new TypeError;var s=0,o=e.length>>0;if(arguments.length<3){if(o===0)throw new TypeError("Array length is 0 and no second argument");n=e[0],s=1}else n=arguments[2];while(s2;if(e&&v&&v===e.reduceRight)return i?e.reduceRight(t,n):e.reduceRight(t);if(!r(e)||typeof t!="function")throw new TypeError;var s=Object(e),o=s.length>>>0;if(o===0&&arguments.length===2)throw new TypeError;var u=o-1;if(arguments.length>=3)n=arguments[2];else do if(u in e){n=e[u--];break}while(!0);while(u>=0)u in s&&(n=t.call(undefined,n,s[u],u,s)),u--;return n}function _(e){var n=[];if(e!==null){var s=i(arguments);if(s.length===1)if(r(e))n=e;else if(t.isHash(e))for(var o in e)e.hasOwnProperty(o)&&n.push([o,e[o]]);else n.push(e);else C(s,function(e){n=n.concat(_(e))})}return n}function D(e){return e=e||[],e.length?O(e,function(e,t){return e+t}):0}function P(e){e=e||[];if(e.length){var n=D(e);if(t.isNumber(n))return n/e.length;throw new Error("Cannot average an array of non numbers.")}return 0}function H(e,t){return S(e,t)}function B(e,t){return S(e,t)[0]}function j(e,t){return S(e,t)[e.length-1]}function F(e){var t=e,n=Y(i(arguments,1));return r(e)&&(t=N(e,function(e){return x(n,e)===-1})),t}function I(e){var t=[];if(r(e))for(var n=0,i=e.length;n0?(n.push(n.shift()),t--):(n.unshift(n.pop()),t++),R(n,t)):n}function U(e,t){var n=[];if(r(e)){var i=e.slice(0);typeof t!="number"&&(t=e.length),t?t<=e.length&&(n=O(e,function(e,n,r){var s;return t>1?s=w(n,R(i,r).slice(1),t):s=[[n]],e.concat(s)},[])):n=[[]]}return n}function z(){var e=[],n=i(arguments);if(n.length>1){var s=n.shift();r(s)&&(e=O(s,function(e,i,s){var o=[i];for(var u=0;u1){for(var n=0,r=t.length;n1?t=n:t=n[0];if(r(t)){var e=t.shift();for(var s=0,o=t.length;s1?t=n:t=_(e),O(t,function(e,t){return e.concat(t)},[])}function Z(e,t){t=t.split(".");var n=e.slice(0);return C(t,function(e){var t=e.match(/(\w+)\(\)$/);n=A(n,function(n){return t?n[t[1]]():n[e]})}),n}function et(e,t,r){return r=i(arguments,2),A(e,function(e){var i=n(t)?e[t]:t;return i.apply(e,r)})}var n=t.isString,r=Array.isArray||t.isArray,s=t.isDate,o=Math.floor,u=Math.abs,a=Math.max,f=Math.min,l=Array.prototype,c=l.indexOf,h=l.forEach,p=l.map,d=l.reduce,v=l.reduceRight,m=l.filter,g=l.every,y=l.some,S=function(){var e=function(e,t){return k(e,t)},t=function(e,t){return e-t},i=function(e,t){return e.getTime()-t.getTime()};return function(u,a){var f=[];return r(u)&&(f=u.slice(),a?typeof a=="function"?f.sort(a):f.sort(function(e,t){var r=e[a],i=t[a];return n(r)&&n(i)?r>i?1:rn)if(r){var o=e.length;s=e.substring(o-n,o)}else s=e.substring(0,n)}else s=i(""+s,n);return s}function s(e,n,r){if(!t.isArray(e)||typeof n!="function")throw new TypeError;var i=Object(e),s=i.length>>>0;for(var o=0;o-1&&(n=t.substring(++r,t.indexOf(")"))),n}function T(e,t){return e.replace(/([a-z])\1*/ig,function(e){var n,r=e.charAt(0),i=e.length,s="0?",o="0{0,2}";if(r==="y")n="\\d{2,4}";else if(r==="M")n=i>2?"\\S+?":"1[0-2]|"+s+"[1-9]";else if(r==="D")n="[12][0-9][0-9]|3[0-5][0-9]|36[0-6]|"+o+"[1-9][0-9]|"+s+"[1-9]";else if(r==="d")n="3[01]|[12]\\d|"+s+"[1-9]";else if(r==="w")n="[1-4][0-9]|5[0-3]|"+s+"[1-9]";else if(r==="E")n="\\S+";else if(r==="h")n="1[0-2]|"+s+"[1-9]";else if(r==="K")n="1[01]|"+s+"\\d";else if(r==="H")n="1\\d|2[0-3]|"+s+"\\d";else if(r==="k")n="1\\d|2[0-4]|"+s+"[1-9]";else if(r==="m"||r==="s")n="[0-5]\\d";else if(r==="S")n="\\d{"+i+"}";else if(r==="a"){var u="AM",a="PM";n=u+"|"+a,u!==u.toLowerCase()&&(n+="|"+u.toLowerCase()),a!==a.toLowerCase()&&(n+="|"+a.toLowerCase()),n=n.replace(/\./g,"\\.")}else r==="v"||r==="z"||r==="Z"||r==="G"||r==="q"||r==="Q"?n=".*":n=r===" "?"\\s*":r+"*";return t&&t.push(e),"("+n+")"}).replace(/[\xa0 ]/g,"[\\s\\xa0]")}function k(e){C[e+"sFromNow"]=function(t){return N.add(new Date,e,t)},C[e+"sAgo"]=function(t){return N.add(new Date,e,-t)}}var o=function(){function r(e,t,r){return e=e.replace(/s$/,""),n.hasOwnProperty(e)?n[e](t,r):[r,"UTC"+e.charAt(0).toUpperCase()+e.substring(1)+"s",!1]}function s(e,n,r,s){return e=e.replace(/s$/,""),t(i[e](n,r,s))}var e=Math.floor,t=Math.round,n={day:function(t,n){return[n,"Date",!1]},weekday:function(t,n){var r,i,s=n%5,o=t.getDay(),u=0;s?(r=s,i=parseInt(n/5,10)):(r=n>0?5:-5,i=n>0?(n-5)/5:(n+5)/5),o===6&&n>0?u=1:o===0&&n<0&&(u=-1);var a=o+r;if(a===0||a===6)u=n>0?2:-2;return[7*i+r+u,"Date",!1]},year:function(t,n){return[n,"FullYear",!0]},week:function(t,n){return[n*7,"Date",!1]},quarter:function(t,n){return[n*3,"Month",!0]},month:function(t,n){return[n,"Month",!0]}},i={quarter:function(n,r,i){var s=r.getFullYear()-n.getFullYear(),o=n[i?"getUTCMonth":"getMonth"](),u=r[i?"getUTCMonth":"getMonth"](),a=e(o/3)+1,f=e(u/3)+1;return f+=s*4,f-a},weekday:function(t,n,r){var i=s("day",t,n,r),o,u=i%7;if(u===0)i=s("week",t,n,r)*5;else{var a=0,f=t[r?"getUTCDay":"getDay"](),l=n[r?"getUTCDay":"getDay"]();o=parseInt(i/7,10);var c=new Date(+t);c.setDate(c[r?"getUTCDate":"getDate"]()+o*7);var h=c[r?"getUTCDay":"getDay"]();if(i>0){if(f===6||l===6)a=-1;else if(f===0)a=0;else if(l===0||h+u>5)a=-2}else if(i<0)if(f===6)a=0;else if(f===0||l===0)a=1;else if(l===6||h+u<0)a=2;i+=a,i-=o*2}return i},year:function(e,t){return t.getFullYear()-e.getFullYear()},month:function(e,t,n){var r=e[n?"getUTCMonth":"getMonth"](),i=t[n?"getUTCMonth":"getMonth"]();return i-r+(t.getFullYear()-e.getFullYear())*12},week:function(e,n,r){return t(s("day",e,n,r)/7)},day:function(e,t){return 1.1574074074074074e-8*(t.getTime()-e.getTime())},hour:function(e,t){return 2.7777777777777776e-7*(t.getTime()-e.getTime())},minute:function(e,t){return 16666666666666667e-21*(t.getTime()-e.getTime())},second:function(e,t){return.001*(t.getTime()-e.getTime())},millisecond:function(e,t){return t.getTime()-e.getTime()}};return{addTransform:r,differenceTransform:s}}(),u=o.addTransform,a=o.differenceTransform,f=Math.floor,l=Math.round,c=Math.min,h=Math.pow,p=Math.ceil,d=Math.abs,v=["January","February","March","April","May","June","July","August","September","October","November","December"],m=["Jan.","Feb.","Mar.","Apr.","May.","Jun.","Jul.","Aug.","Sep.","Oct.","Nov.","Dec."],g=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],y=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],b=["Before Christ","Anno Domini"],w=["BC","AD"],N={getDaysInMonth:function(e){var t=e.getMonth(),n=[31,28,31,30,31,30,31,31,30,31,30,31];return t===1&&N.isLeapYear(e)?29:n[t]},isLeapYear:function(e,t){var n=e[t?"getUTCFullYear":"getFullYear"]();return n%400===0||n%4===0&&n%100!==0},isWeekend:function(e,t){var n=(e||new Date)[t?"getUTCDay":"getDay"]();return n===0||n===6},getTimezoneName:x,compare:function(e,t,n){return e=new Date(+e),t=new Date(+(t||new Date)),n==="date"?(e.setHours(0,0,0,0),t.setHours(0,0,0,0)):n==="time"&&(e.setFullYear(0,0,0),t.setFullYear(0,0,0)),e>t?1:e1&&(O===2?k=i(""+k,2,!0):L=!0);else if(A.toUpperCase()==="Q")k=p((o+1)/3),L=!0;else if(A==="M")O<3?(k=o+1,L=!0):k=(O===3?m:v)[o];else if(A==="w")k=S(e,0,n),L=!0;else if(A==="D")k=E(e,n),L=!0;else if(A==="E")O<3?(k=u+1,L=!0):k=(O===-3?y:g)[u];else if(A==="a")k=c<12?"AM":"PM";else if(A==="h")k=c%12||12,L=!0;else if(A==="K")k=c%12,L=!0;else if(A==="k")k=c||24,L=!0;else if(A==="S")k=l(C*h(10,O-3)),L=!0;else if(A==="z"||A==="v"||A==="Z"){k=x(e),(A==="z"||A==="v")&&!k&&(O=4);if(!k||A==="Z"){var M=e.getTimezoneOffset(),_=[M>=0?"-":"+",r(f(d(M)/60),2,"0"),r(d(M)%60,2,"0")];O===4&&(_.splice(0,0,"GMT"),_.splice(3,0,":")),k=_.join("")}}else k=t;return L&&(k=r(k,O,"0")),k})}},C={},L=["year","month","day","hour","minute","second"];for(var A=0,O=L.length;A2){var p=v,d,b;s===3&&(p=m),e=e.replace(".","").toLowerCase();var w=!1;for(d=0,b=p.length;dS.length)return!1}else e=x}else if(o==="D"||o==="d")o==="D"&&(a[1]=0),a[2]=e;else if(o==="a"){var T="am",N="pm",C=/\./g;e=e.replace(C,"").toLowerCase(),f=e===N?"p":e===T?"a":""}else o==="k"||o==="h"||o==="H"||o==="K"?(o==="k"&&+e===24&&(e=0),a[3]=e):o==="m"?a[4]=e:o==="s"?a[5]=e:o==="S"&&(a[6]=e)}return!0});if(l){var h=+a[3];f==="p"&&h<12?a[3]=h+12:f==="a"&&h===12&&(a[3]=0);var p=new Date(a[0],a[1],a[2],a[3],a[4],a[5],a[6]),d=n.indexOf(r,"d")!==-1,b=n.indexOf(r,"M")!==-1,w=a[1],E=a[2],S=p.getMonth(),x=p.getDate();return b&&S>w||d&&x>E?null:p}return null}},_=e.define(t.isDate,N).define(t.isString,M).define(t.isNumber,C);for(A in N)N.hasOwnProperty(A)&&(_[A]=N[A]);for(A in M)M.hasOwnProperty(A)&&(_[A]=M[A]);for(A in C)C.hasOwnProperty(A)&&(_[A]=C[A]);return _}"undefined"!=typeof n?"undefined"!=typeof t&&t.exports&&(t.exports=r(e("extended"),e("is-extended"),e("array-extended"))):"function"==typeof define?define(["require"],function(e){return r(e("extended"),e("is-extended"),e("array-extended"))}):this.dateExtended=r(this.extended,this.isExtended,this.arrayExtended)}).call(this)}),require.define("/node_modules/object-extended/package.json",function(e,t,n,r,i,s,o){t.exports={main:"index.js"}}),require.define("/node_modules/object-extended/index.js",function(e,t,n,r,i,s,o){(function(){"use strict";function r(e,t){function i(e,t){var n,r;for(n in t)if(t.hasOwnProperty(n)){r=t[n];if(!(n in e)||e[n]!==r)e[n]=r}return e}function s(e,t){var i,o,u;for(i in t)t.hasOwnProperty(i)&&(o=t[i],u=e[i],n(u,o)||(r(u)&&r(o)?e[i]=s(u,o):r(o)?e[i]=s({},o):e[i]=o));return e}function o(e){e||(e={});for(var t=1,n=arguments.length;t0?"+":"")+r),f&&(f=parseInt(f,10),r.lengthn)if(r){var s=e.length;i=e.substring(s-n,s)}else i=e.substring(0,n)}else i=m(""+i,n);return i}function g(e,a){if(a instanceof Array){var f=0,p=a.length;return e.replace(o,function(e,t,i){var s,o;if(f0?n=e.replace(/\s+/g,"").split(t):n.push(e)),n}function b(e,t){var n=[];if(t)for(var r=0;r=0;s--)r=p(r,s===i)}return r}var n=t.isArray,r=t.isObject,i=t.isString,s=t.isFunction,o=Array.prototype.slice;return e.define(r,{bind:a,bindAll:c,bindIgnore:l,curry:function(e,t,n){return d(t,n,e)}}).define(s,{bind:function(e,t){return a.apply(this,[t,e].concat(u(arguments,2)))},bindIgnore:function(e,t){return l.apply(this,[t,e].concat(u(arguments,2)))},partial:h,applyFirst:f,curry:function(e,t,n){return d(t,e,n)},noWrap:{f:function(){return this.value()}}}).define(i,{bind:function(e,t){return a(t,e)},bindIgnore:function(e,t){return l(t,e)},partial:h,applyFirst:f,curry:function(e,t,n){return d(t,e,n)}}).expose({bind:a,bindAll:c,bindIgnore:l,partial:h,applyFirst:f,curry:d})}"undefined"!=typeof n?"undefined"!=typeof t&&t.exports&&(t.exports=r(e("extended"),e("is-extended"))):"function"==typeof define?define(["require"],function(e){return r(e("extended"),e("is-extended"))}):this.functionExtended=r(this.extended,this.isExtended)}).call(this)}),require.define("/node_modules/ht/package.json",function(e,t,n,r,i,s,o){t.exports={main:"index.js"}}),require.define("/node_modules/ht/index.js",function(e,t,n,r,i,s,o){(function(){"use strict";function r(e){var t=function(e){return typeof e=="string"?e:typeof e=="object"?e.hashCode?e.hashCode():""+e:""+e},n=e.declare({instance:{constructor:function(){this.__entries=[],this.__keys=[],this.__values=[]},pushValue:function(e,t){return this.__keys.push(e),this.__values.push(t),this.__entries.push({key:e,value:t}),t},remove:function(e){var t=null,n=this.__entries,r,i=this.__keys,s=this.__values,o=n.length-1;for(;o>=0;o--)if(!!(r=n[o])&&r.key===e)return n.splice(o,1),i.splice(o,1),s.splice(o,1),r.value;return t},set:function(e,t){var n=null,r=this.__entries,i=this.__values,s=r.length-1;for(;s>=0;s--){var o=r[s];if(o&&e===o.key){i[s]=t,o.value=t,n=t;break}}return n||r.push({key:e,value:t}),n},find:function(e){var t=null,n=this.__entries,r,i=n.length-1;for(;i>=0;i--){r=n[i];if(r&&e===r.key){t=r.value;break}}return t},getEntrySet:function(){return this.__entries},getKeys:function(){return this.__keys},getValues:function(e){return this.__values}}});return e.declare({instance:{constructor:function(){this.__map={}},entrySet:function(){var e=[],t=this.__map;for(var n in t)t.hasOwnProperty(n)&&(e=e.concat(t[n].getEntrySet()));return e},put:function(e,r){var i=t(e),s=null;return(s=this.__map[i])||(s=this.__map[i]=new n),s.pushValue(e,r),r},remove:function(e){var n=t(e),r=null,i=this.__map[n];return i&&(r=i.remove(e)),r},get:function(e){var n=t(e),r=null,i;return!(i=this.__map[n])||(r=i.find(e)),r},set:function(e,r){var i=t(e),s=null,o=null,u=this.__map;return(o=u[i])?s=o.set(e,r):s=(u[i]=new n).pushValue(e,r),s},contains:function(e){var n=t(e),r=!1,i=null;return!(i=this.__map[n])||(r=!!i.find(e)),r},concat:function(e){if(e instanceof this._static){var t=new this._static,n=e.entrySet().concat(this.entrySet());for(var r=n.length-1;r>=0;r--){var i=n[r];t.put(i.key,i.value)}return t}throw new TypeError("When joining hashtables the joining arg must be a HashTable")},filter:function(t,n){var r=this.entrySet(),i=new this._static;r=e.filter(r,t,n);for(var s=r.length-1;s>=0;s--){var o=r[s];i.put(o.key,o.value)}return i},forEach:function(t,n){var r=this.entrySet();e.forEach(r,t,n)},every:function(t,n){var r=this.entrySet();return e.every(r,t,n)},map:function(t,n){var r=this.entrySet();return e.map(r,t,n)},some:function(t,n){var r=this.entrySet();return e.some(r,t,n)},reduce:function(t,n){var r=this.entrySet();return e.reduce(r,t,n)},reduceRight:function(t,n){var r=this.entrySet();return e.reduceRight(r,t,n)},clear:function(){this.__map={}},keys:function(){var e=[],t=this.__map;for(var n in t)e=e.concat(t[n].getKeys());return e},values:function(){var e=[],t=this.__map;for(var n in t)e=e.concat(t[n].getValues());return e},isEmpty:function(){return this.keys().length===0}}})}"undefined"!=typeof n?"undefined"!=typeof t&&t.exports&&(t.exports=r(e("extended")().register("declare",e("declare.js")).register(e("is-extended")).register(e("array-extended")))):"function"==typeof define?define(["extended","declare","is-extended","array-extended"],function(e,t,n,i){return r(e().register("declare",t).register(n).register(i))}):this.Ht=r(this.extended().register("declare",this.declare).register(this.isExtended).register(this.arrayExtended))}).call(this)}),require.define("/node_modules/leafy/package.json",function(e,t,n,r,i,s,o){t.exports={main:"index.js"}}),require.define("/node_modules/leafy/index.js",function(e,t,n,r,i,s,o){(function(){"use strict";function r(e){function t(e,t){var n=0;return e>t?1:e1&&(n=u(n,o),i.done=!0))}return n},l=function(t,n,r,i){var s,o,u,f;if(t){o=i(n,t.data);if(o===0){var c=t.left,h=t.right;if(!c||!h)return s=c?"left":"right",u=t[s],u;var p=c;while((h=p.right)!==null)p=h;t.data=p.data,n=p.data}s=i(t.data,n)===-1?"right":"left",t[s]=l(t[s],n,r,i);if(!r.done){f=t.balance+=s==="left"?1:-1;var d=e(f);d===1?r.done=!0:d>1&&(t=a(t,s,r))}}return t};return r.extend({instance:{insert:function(e){var t={done:!1};this.__root=f(this.__root,e,t,this.compare)},remove:function(e){this.__root=l(this.__root,e,{done:!1},this.compare)},__printNode:function(e,t){var r=[];e?(this.__printNode(e.right,t+1),r.push(n(" ",t)),r.push(e.data+":"+e.balance+"\n"),console.log(r.join("")),this.__printNode(e.left,t+1)):(r.push(n(" ",t)),r.push("~"),console.log(r.join("")))}}})}(),s=function(){function t(t,n){return{data:t,level:n,left:e,right:e}}function i(e){if(e.level!==0&&e.left.level===e.level){var t=e.left;e.left=t.right,t.right=e,e=t}return e}function s(e){if(e.level!==0&&e.right.right.level===e.level){var t=e.right;e.right=t.left,t.left=e,e=t,e.level++}return e}function o(n,r,u){if(n===e)n=t(r,1);else{var a=u(r,n.data)===-1?"left":"right";n[a]=o(n[a],r,u),n=i(n),n=s(n)}return n}var e={level:0,data:null},u=function(t,n,r){var o,a;if(t!==e){var f=r(n,t.data);if(f===0){o=t.left,a=t.right;if(o!==e&&a!==e){var l=o;while(l.right!==e)l=l.right;t.data=l.data,t.left=u(o,l.data,r)}else t=t[o===e?"right":"left"]}else{var c=f===-1?"left":"right";t[c]=u(t[c],n,r)}}if(t!==e){var h=t.level,p=t.left.level,d=t.right.level;if(p--t.level&&(t.right.level=t.level),t=i(t),t=s(t)}return t};return r.extend({instance:{isEmpty:function(){return this.__root===e||this._super(arguments)},insert:function(t){this.__root||(this.__root=e),this.__root=o(this.__root,t,this.compare)},remove:function(e){this.__root=u(this.__root,e,this.compare)},traverseWithCondition:function(t){var n=!0;return t!==e?this._super(arguments):n},traverse:function(t){t!==e&&this._super(arguments)},contains:function(){return this.__root!==e?this._super(arguments):!1},__printNode:function(e,t){var r=[];!e||!e.data?(r.push(n(" ",t)),r.push("~"),console.log(r.join(""))):(this.__printNode(e.right,t+1),r.push(n(" ",t)),r.push(e.data+":"+e.level+"\n"),console.log(r.join("")),this.__printNode(e.left,t+1))}}})}(),o=r.extend({instance:{insert:function(e){if(!this.__root)return this.__root={data:e,parent:null,left:null,right:null};var t=this.compare,n=this.__root;while(n!==null){var r=t(e,n.data);if(!r)return;var i=r===-1?"left":"right",s=n[i];if(!s)return n[i]={data:e,parent:n,left:null,right:null};n=s}},remove:function(e){if(this.__root!==null){var t={right:this.__root},n=t,r,i=null,s="right";while(n[s]!==null){r=n,n=n[s];var o=this.compare(e,n.data);o||(i=n),s=o===-1?"left":"right"}i!==null&&(i.data=n.data,r[r.right===n?"right":"left"]=n[n.left===null?"right":"left"]),this.__root=t.right}}}}),u=function(){var e="RED",t="BLACK",i=function(e){return e!==null&&e.red},s=function(e){return{data:e,red:!0,left:null,right:null}},o=function(e,t,n){if(!e)return s(t);var r=n(t,e.data);if(r){var f=r===-1?"left":"right",l=f==="left"?"right":"left";e[f]=o(e[f],t,n);var c=e[f];if(i(c)){var h=e[l];i(h)?(e.red=!0,c.red=!1,h.red=!1):i(c[f])?e=u(e,l):i(c[l])&&(e=a(e,l))}}return e},u=function(e,t){var n=t==="left"?"right":"left",r=e[n];return e[n]=r[t],r[t]=e,e.red=!0,r.red=!1,r},a=function(e,t){var n=t==="left"?"right":"left";return e[n]=u(e[n],n),u(e,t)},f=function(e,t,n,r){if(!e)n.done=!0;else{var s;if(r(t,e.data)===0){if(!e.left||!e.right){var o=e[e.left?"left":"right"];return i(e)?n.done=!0:i(o)&&(o.red=!1,n.done=!0),o}var u=e.right,a;while(u.left!==null)a=u,u=u.left;a&&(a.left=null),e.data=u.data,t=u.data}s=r(t,e.data)===-1?"left":"right",e[s]=f(e[s],t,n,r),n.done||(e=l(e,s,n))}return e},l=function(e,t,n){var r=t==="left"?"right":"left",s=e,o=s[r];i(o)&&(e=u(e,t),o=s[r]);if(o!==null)if(!i(o.left)&&!i(o.right))i(s)&&(n.done=!0),s.red=0,o.red=1;else{var f=s.red,l=e===s;s=(i(o[r])?u:a)(s,t),s.red=f,s.left.red=s.right.red=0,l?e=s:e[t]=s,n.done=!0}return e};return r.extend({instance:{insert:function(e){this.__root=o(this.__root,e,this.compare),this.__root.red=!1},remove:function(e){var t={done:!1},n=f(this.__root,e,t,this.compare);return n!==null&&(n.red=0),this.__root=n,e},__printNode:function(r,i){var s=[];r?(this.__printNode(r.right,i+1),s.push(n(" ",i)),s.push((r.red?e:t)+":"+r.data+"\n"),console.log(s.join("")),this.__printNode(r.left,i+1)):(s.push(n(" ",i)),s.push("~"),console.log(s.join("")))}}})}();return{Tree:r,AVLTree:i,AnderssonTree:s,BinaryTree:o,RedBlackTree:u,IN_ORDER:r.IN_ORDER,PRE_ORDER:r.PRE_ORDER,POST_ORDER:r.POST_ORDER,REVERSE_ORDER:r.REVERSE_ORDER}}"undefined"!=typeof n?"undefined"!=typeof t&&t.exports&&(t.exports=r(e("extended")().register("declare",e("declare.js")).register(e("is-extended")).register(e("array-extended")).register(e("string-extended")))):"function"==typeof define?define(["extended","declare.js","is-extended","array-extended","string-extended"],function(e,t,n,i,s){return r(e().register("declare",t).register(n).register(i).register(s))}):this.leafy=r(this.extended().register("declare",this.declare).register(this.isExtended).register(this.arrayExtended).register(this.stringExtended))}).call(this)}),require.define("fs",function(e,t,n,r,i,s,o){}),require.define("/lib/nodes/index.js",function(e,t,n,r,i,s,o){"use strict";var u=e("../extended"),a=u.forEach,f=u.some,l=u.declare,c=e("../pattern.js"),h=c.ObjectPattern,p=c.NotPattern,d=c.CompositePattern,v=c.InitialFactPattern,m=e("../constraint"),g=m.HashConstraint,y=m.ReferenceConstraint,b=e("./aliasNode"),w=e("./equalityNode"),E=e("./joinNode"),S=e("./notNode"),x=e("./leftAdapterNode"),T=e("./rightAdapterNode"),N=e("./typeNode"),C=e("./terminalNode"),k=e("./propertyNode");l({instance:{constructor:function(e,t){this.terminalNodes=[],this.joinNodes=[],this.nodes=[],this.constraints=[],this.typeNodes=[],this.__ruleCount=0,this.bucket={counter:0,recency:0},this.agendaTree=t},assertRule:function(e){var t=new C(this.bucket,this.__ruleCount++,e,this.agendaTree);this.__addToNetwork(e,e.pattern,t),this.__mergeJoinNodes(),this.terminalNodes.push(t)},resetCounter:function(){this.bucket.counter=0},incrementCounter:function(){this.bucket.counter++},assertFact:function(e){var t=this.typeNodes,n=t.length-1;for(;n>=0;n--)t[n].assert(e)},retractFact:function(e){var t=this.typeNodes,n=t.length-1;for(;n>=0;n--)t[n].retract(e)},containsRule:function(e){return f(this.terminalNodes,function(t){return t.rule.name===e})},dispose:function(){var e=this.typeNodes,t=e.length-1;for(;t>=0;t--)e[t].dispose()},__mergeJoinNodes:function(){var e=this.joinNodes;for(var t=0;t=0;n--){var r=t[n];if(e.equal(r))return r}return t.push(e),e},__createTypeNode:function(e,t){var n=new N(t.get("constraints")[0]),r=this.typeNodes,i=r.length-1;for(;i>=0;i--){var s=r[i];if(n.equal(s))return s}return r.push(n),n},__createEqualityNode:function(e,t){return this.__checkEqual(new w(t)).addRule(e)},__createPropertyNode:function(e,t){return this.__checkEqual(new k(t)).addRule(e)},__createAliasNode:function(e,t){return this.__checkEqual(new b(t)).addRule(e)},__createAdapterNode:function(e,t){return(t==="left"?new x:new T).addRule(e)},__createJoinNode:function(e,t,n,r){var i;t.rightPattern instanceof p?i=new S:(i=new E,this.joinNodes.push(i));var s=i;if(n instanceof E){var o=this.__createAdapterNode(e,r);s.addOutNode(o,t),s=o}return s.addOutNode(n,t),i.addRule(e)},__addToNetwork:function(e,t,n,r){if(t instanceof h){if(t instanceof p&&(!r||r==="left"))return this.__createBetaNode(e,new d(new v,t),n,r);this.__createAlphaNode(e,t,n,r)}else t instanceof d&&this.__createBetaNode(e,t,n,r)},__createBetaNode:function(e,t,n,r){var i=this.__createJoinNode(e,t,n,r);return this.__addToNetwork(e,t.rightPattern,i,"right"),this.__addToNetwork(e,t.leftPattern,i,"left"),n.addParentNode(i),i},__createAlphaNode:function(e,t,n,r){var i=t.get("constraints"),s=this.__createTypeNode(e,t),o=this.__createAliasNode(e,t);s.addOutNode(o,t),o.addParentNode(s);var u=o,a=i.length-1;for(;a>0;a--){var f=i[a],l;if(f instanceof g)l=this.__createPropertyNode(e,f);else{if(f instanceof y){n.constraint.addConstraint(f);continue}l=this.__createEqualityNode(e,f)}u.addOutNode(l,t),l.addParentNode(u),u=l}if(n instanceof E){var c=this.__createAdapterNode(e,r);c.addParentNode(u),u.addOutNode(c,t),u=c}return n.addParentNode(u),u.addOutNode(n,t),s},print:function(){a(this.terminalNodes,function(e){e.print(" ")})}}}).as(n,"RootNode")}),require.define("/lib/pattern.js",function(e,t,n,r,i,s,o){(function(){"use strict";var t=e("./extended"),r=t.merge,i=t.forEach,s=t.declare,o=e("./constraintMatcher"),u=e("./constraint"),a=s({}),f=a.extend({instance:{constructor:function(e,n,s,a,f){f=f||{},this.type=e,this.alias=n,this.conditions=s,this.pattern=f.pattern,this.constraints=[new u.ObjectConstraint(e)];var l=o.toConstraints(s,r({alias:n},f));if(l.length)this.constraints=this.constraints.concat(l);else{var c=new u.TrueConstraint;this.constraints.push(c)}if(a&&!t.isEmpty(a)){var h=new u.HashConstraint(a);this.constraints.push(h)}i(this.constraints,function(e){e.set("alias",n)})},hasConstraint:function(e){return t.some(this.constraints,function(t){return t instanceof e})},hashCode:function(){return[this.type,this.alias,t.format("%j",this.conditions)].join(":")},toString:function(){return t.format("%j",this.constraints)}}}).as(n,"ObjectPattern");f.extend().as(n,"NotPattern"),a.extend({instance:{constructor:function(e,t){this.leftPattern=e,this.rightPattern=t},hashCode:function(){return[this.leftPattern.hashCode(),this.rightPattern.hashCode()].join(":")},getters:{constraints:function(){return this.leftPattern.constraints.concat(this.rightPattern.constraints)}}}}).as(n,"CompositePattern");var l=s({}).as(n,"InitialFact");f.extend({instance:{constructor:function(){this._super([l,"i",[],{}])},assert:function(){return!0}}}).as(n,"InitialFactPattern")})()}),require.define("/lib/constraintMatcher.js",function(require,module,exports,__dirname,__filename,process,global){"use strict";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"),definedFuncs={now:function(){return new Date},Date:function(e,t,n,r,i,s,o){var u=new Date;return isNumber(e)&&u.setYear(e),isNumber(t)&&u.setMonth(t),isNumber(n)&&u.setDate(n),isNumber(r)&&u.setHours(r),isNumber(i)&&u.setMinutes(i),isNumber(s)&&u.setSeconds(s),isNumber(o)&&u.setMilliseconds(o),u},lengthOf:function(e,t){return e.length===t},isTrue:function(e){return e===!0},isFalse:function(e){return e===!1},isNotNull:function(e){return e!==null},dateCmp:function(e,t){return extd.compare(e,t)}};forEach(["years","days","months","hours","minutes","seconds"],function(e){definedFuncs[e+"FromNow"]=extd[e+"FromNow"],definedFuncs[e+"Ago"]=extd[e+"Ago"]}),forEach(["isArray","isNumber","isHash","isObject","isDate","isBoolean","isString","isRegExp","isNull","isEmpty","isUndefined","isDefined","isUndefinedOrNull","isPromiseLike","isFunction","deepEqual"],function(e){var t=extd[e];definedFuncs[e]=function(){return t.apply(extd,arguments)}});var lang={equal:function(e,t){var n=!1;return e===t?n=!0:e[2]===t[2]&&(indexOf(["string","number","boolean","regexp","identifier","null"],e[2])!==-1?n=e[0]===t[0]:e[2]==="unminus"?n=this.equal(e[0],t[0]):n=this.equal(e[0],t[0])&&this.equal(e[1],t[1])),n},getIdentifiers:function(e){var t=[],n=e[2];if(n==="identifier")return[e[0]];if(n==="function")t.push(e[0]),t=t.concat(this.getIdentifiers(e[1]));else if(n!=="string"&&n!=="number"&&n!=="boolean"&&n!=="regexp"&&n!=="unminus")if(n==="prop"){t=t.concat(this.getIdentifiers(e[0]));if(e[1]){var r=e[1];while(isArray(r)){if(r[2]==="function"){t=t.concat(this.getIdentifiers(r[1]));break}r=r[1]}}}else e[0]&&(t=t.concat(this.getIdentifiers(e[0]))),e[1]&&(t=t.concat(this.getIdentifiers(e[1])));return removeDups(t)},toConstraints:function(e,t){var n=[],r=t.alias,i=t.scope||{},s=e[2];if(s==="and")n=n.concat(this.toConstraints(e[0],t)).concat(this.toConstraints(e[1],t));else if(s==="composite"||s==="or"||s==="lt"||s==="gt"||s==="lte"||s==="gte"||s==="like"||s==="notLike"||s==="eq"||s==="neq"||s==="in"||s==="notIn"||s==="function")some(this.getIdentifiers(e),function(e){return e!==r&&!(e in definedFuncs)&&!(e in i)})?n.push(new atoms.ReferenceConstraint(e,t)):n.push(new atoms.EqualityConstraint(e,t));return n},parse:function(e){return this[e[2]](e[0],e[1])},composite:function(e){return this.parse(e)},and:function(e,t){return[this.parse(e),"&&",this.parse(t)].join(" ")},or:function(e,t){return[this.parse(e),"||",this.parse(t)].join(" ")},prop:function(e,t){return t[2]==="function"?[this.parse(e),this.parse(t)].join("."):[this.parse(e),"['",this.parse(t),"']"].join("")},unminus:function(e){return-1*this.parse(e)},plus:function(e,t){return[this.parse(e),"+",this.parse(t)].join(" ")},minus:function(e,t){return[this.parse(e),"-",this.parse(t)].join(" ")},mult:function(e,t){return[this.parse(e),"*",this.parse(t)].join(" ")},div:function(e,t){return[this.parse(e),"/",this.parse(t)].join(" ")},lt:function(e,t){return[this.parse(e),"<",this.parse(t)].join(" ")},gt:function(e,t){return[this.parse(e),">",this.parse(t)].join(" ")},lte:function(e,t){return[this.parse(e),"<=",this.parse(t)].join(" ")},gte:function(e,t){return[this.parse(e),">=",this.parse(t)].join(" ")},like:function(e,t){return[this.parse(t),".test(",this.parse(e),")"].join("")},notLike:function(e,t){return["!",this.parse(t),".test(",this.parse(e),")"].join("")},eq:function(e,t){return[this.parse(e),"===",this.parse(t)].join(" ")},neq:function(e,t){return[this.parse(e),"!==",this.parse(t)].join(" ")},"in":function(e,t){return["(indexOf(",this.parse(t),",",this.parse(e),")) != -1"].join("")},notIn:function(e,t){return["(indexOf(",this.parse(t),",",this.parse(e),")) == -1"].join("")},arguments:function(e,t){var n=[];return e&&n.push(this.parse(e)),t&&n.push(this.parse(t)),n.join(",")},array:function(e){var t=[];return e?(t=this.parse(e),isArray(t)?t:["[",t,"]"].join("")):["[",t.join(","),"]"].join("")},"function":function(e,t){var n=this.parse(t);return[e,"(",n,")"].join("")},string:function(e){return"'"+e+"'"},number:function(e){return e},"boolean":function(e){return e},regexp:function(e){return e},identifier:function(e){return e},"null":function(){return"null"}},toJs=exports.toJs=function(e,t){var n=lang.parse(e);t=t||{};var r=lang.getIdentifiers(e);return["(function(){ return function jsMatcher(fact, hash){",map(r,function(e){var n=["var ",e," = "];return definedFuncs.hasOwnProperty(e)?n.push("definedFuncs['",e,"']"):t.hasOwnProperty(e)?n.push("scope['",e,"']"):n.push("'",e,"' in fact ? fact['",e,"'] : hash['",e,"']"),n.push(";"),n.join("")}).join("")," return !!(",n,");};})()"].join("")};exports.getMatcher=function(rule,scope){var js=toJs(rule,scope);return eval(js)},exports.toConstraints=function(e,t){return lang.toConstraints(e,t)},exports.equal=function(e,t){return lang.equal(e,t)},exports.getIdentifiers=function(e){return lang.getIdentifiers(e)}}),require.define("/lib/constraint.js",function(e,t,n,r,i,s,o){"use strict";var u=e("./extended"),a=u.hash,f=u.merge,l=a.keys,c=u.forEach,h=u.instanceOf,p=u.filter,d=u.declare,v,m=d({instance:{constructor:function(t,n){v||(v=e("./constraintMatcher")),this.type=t,this.constraint=n},assert:function(){throw new Error("not implemented")},equal:function(e){return h(e,this._static)&&this.get("alias")===e.get("alias")&&u.deepEqual(this.constraint,e.constraint)},getters:{variables:function(){return[this.get("alias")]}}}});m.extend({instance:{constructor:function(e){this._super(["object",e])},assert:function(e){return e instanceof this.constraint||e.constructor===this.constraint},equal:function(e){return h(e,this._static)&&this.constraint===e.constraint}}}).as(n,"ObjectConstraint"),m.extend({instance:{constructor:function(e,t){this._super(["equality",e]),t=t||{},this.pattern=t.pattern,this._matcher=v.getMatcher(e,t.scope||{})},assert:function(e){return this._matcher(e)}}}).as(n,"EqualityConstraint"),m.extend({instance:{constructor:function(){this._super(["equality",[!0]])},equal:function(e){return h(e,this._static)&&this.get("alias")===e.get("alias")},assert:function(){return!0}}}).as(n,"TrueConstraint"),m.extend({instance:{constructor:function(e,t){this.cache={},this._super(["reference",e]),t=t||{},this.values=[],this.pattern=t.pattern,this._options=t,this._matcher=v.getMatcher(e,t.scope||{})},assert:function(e){try{return this._matcher(e)}catch(t){throw new Error("Error with evaluating pattern "+this.pattern+" "+t.message)}},merge:function(e,t){var n=this;return e instanceof this._static&&(n=new this._static([this.constraint,e.constraint,"and"],f({},this._options,this._options)),n._alias=this._alias||e._alias,n.vars=this.vars.concat(e.vars)),n},equal:function(e){return h(e,this._static)&&u.deepEqual(this.constraint,e.constraint)},getters:{variables:function(){return this.vars},alias:function(){return this._alias}},setters:{alias:function(e){this._alias=e,this.vars=p(v.getIdentifiers(this.constraint),function(t){return t!==e})}}}}).as(n,"ReferenceConstraint"),m.extend({instance:{constructor:function(e){this._super(["hash",e])},equal:function(e){return u.instanceOf(e,this._static)&&this.get("alias")===e.get("alias")&&u.deepEqual(this.constraint,e.constraint)},assert:function(){return!0},getters:{variables:function(){return this.constraint}}}}).as(n,"HashConstraint")}),require.define("/lib/nodes/aliasNode.js",function(e,t,n,r,i,s,o){var u=e("./alphaNode");u.extend({instance:{constructor:function(){this._super(arguments),this.alias=this.constraint.get("alias")},toString:function(){return"AliasNode"+this.__count},assert:function(e){return this.__propagate("assert",e.set(this.alias,e.fact.object))},retract:function(e){this.propagateRetract(e.fact)},equal:function(e){return e instanceof this._static&&this.alias===e.alias}}}).as(t)}),require.define("/lib/nodes/alphaNode.js",function(e,t,n,r,i,s,o){"use strict";var u=e("./node");u.extend({instance:{constructor:function(e){this._super([]),this.constraint=e},toString:function(){return"AlphaNode "+this.__count},equal:function(e){return this.constraint.equal(e.constraint)}}}).as(t)}),require.define("/lib/nodes/node.js",function(e,t,n,r,i,s,o){var u=e("../extended"),a=u.forEach,f=u.indexOf,l=u.intersect,c=u.declare,h=u.HashTable,p=e("../context"),d=0;c({instance:{constructor:function(){this.nodes=new h,this.rules=[],this.parentNodes=[],this.__count=d++,this.__entrySet=[]},addRule:function(e){return f(this.rules,e)===-1&&this.rules.push(e),this},merge:function(e){e.nodes.forEach(function(t){var n=t.value,r=t.key;for(var i=0,s=n.length;i=0;i--)s=r[i],o=s.key,u=s.value,t.paths?(a=l(u,t.paths)).length&&o[e](new p(t.fact,a,t.match)):o[e](t)},dispose:function(e){this.propagateDispose(e)},retract:function(e){this.propagateRetract(e)},propagateDispose:function(e,t){t=t||this.nodes;var n=this.__entrySet,r=n.length-1;for(;r>=0;r--){var i=n[r],s=i.key;s.dispose(e)}},propagateAssert:function(e,t){this.__propagate("assert",e,t||this.nodes)},propagateRetract:function(e,t){this.__propagate("retract",e,t||this.nodes)},assert:function(e){this.propagateAssert(e)},propagateModify:function(e,t){this.__propagate("modify",e,t||this.nodes)}}}).as(t)}),require.define("/lib/context.js",function(e,t,n,r,i,s,o){"use strict";var u=e("./extended"),a=u.declare,f=u.merge,l=u.union,c=u.map,h=a({instance:{constructor:function(e){e=e||{},this.variables=[],this.facts=[],this.factIds=[],this.factHash=e.factHash||{},this.recency=[],this.constraints=[],this.isMatch=!0,this.hashCode="";if(e instanceof this._static)this.isMatch=e.isMatch,this.facts=this.facts.concat(e.facts),this.factIds=this.factIds.concat(e.factIds),this.hashCode=this.factIds.join(":"),this.factHash=f(this.factHash,e.factHash),this.recency=l(this.recency,e.recency);else{var t=e;t&&(this.facts.push(t),this.factIds.push(t.id),this.recency.push(t.recency),this.hashCode+=this.factIds.join(":"))}},merge:function(e){var t=new this._static;return t.isMatch=e.isMatch,t.facts=this.facts.concat(e.facts),t.factIds=this.factIds.concat(e.factIds),t.hashCode=t.factIds.join(":"),t.factHash=f({},this.factHash,e.factHash),t.recency=l(this.recency,e.recency),t}}}),p=a({instance:{match:null,factHash:null,fact:null,hashCode:null,paths:null,constructor:function(e,t,n){this.fact=e,this.paths=t||null;var r=this.match=n||new h(e);this.factHash=r.factHash,this.hashCode=r.hashCode,this.factIds=r.factIds},set:function(e,t){return this.factHash[e]=t,this},isMatch:function(e){return this.match.isMatch=e,this},clone:function(e,t,n){return new p(e||this.fact,t||this.path,n||this.match)}}}).as(t)}),require.define("/lib/nodes/equalityNode.js",function(e,t,n,r,i,s,o){var u=e("./alphaNode");u.extend({instance:{constructor:function(){this._super(arguments)},assert:function(e){this.constraint.assert(e.factHash)&&this.__propagate("assert",e)},toString:function(){return"EqualityNode"+this.__count}}}).as(t)}),require.define("/lib/nodes/joinNode.js",function(e,t,n,r,i,s,o){var u=e("../extended"),a=u.hash.values,f=u.indexOf,l=e("./node"),c=e("../context"),h=e("./joinReferenceNode");l.extend({instance:{constructor:function(){this._super([]),this.constraint=new h,this.leftMemory={},this.rightMemory={},this.leftTuples=[],this.rightTuples=[]},dispose:function(){this.leftMemory={},this.rightMemory={}},disposeLeft:function(e){this.leftMemory={},this.propagateDispose(e)},disposeRight:function(e){this.rightMemory={},this.propagateDispose(e)},hashCode:function(){return"JoinNode "+this.__count},toString:function(){return"JoinNode "+this.__count},retractResolve:function(e){var t=a(this.leftMemory),n=t.length-1,r=this.leftTuples;for(;n>=0;n--){var i=t[n],s=i.length-1,o;for(;s>=0;s--){o=i[s];if(this.resolve(o.match,e))return r.splice(f(r,o),1),i.splice(s,1),this._propagateRetractResolve(e)}}this._propagateRetractResolve(e)},retractLeft:function(e){var t=this.leftMemory[e.id],n=this.leftTuples,r,i;if(t){for(r=0,i=t.length;r=0;n--)(i=r.setRightContext(t[n]).match()).isMatch&&this.__propagate("assert",e.clone(null,null,i));r.clearContexts()},assertRight:function(e){var t=e.fact;this.rightMemory[t.id]=e,this.rightTuples.push(e);var n=this.leftTuples,r=n.length-1,i=this.constraint,s;i.setRightContext(e);for(;r>=0;r--)(s=i.setLeftContext(n[r]).match()).isMatch&&this.__propagate("assert",e.clone(null,null,s));i.clearContexts()},_propagateRetractResolve:function(e){this.__propagate("retractResolve",e)},__addToLeftMemory:function(e){var t=e.fact,n=this.leftMemory[t.id];return n||(n=[],this.leftMemory[t.id]=n),this.leftTuples.push(e),n.push(e),this}}}).as(t)}),require.define("/lib/nodes/joinReferenceNode.js",function(e,t,n,r,i,s,o){var u=e("./node");u.extend({instance:{constructor:function(){this._super(arguments),this.__fh={},this.__lc=this.__rc=null,this.__variables=[],this.__varLength=0},setLeftContext:function(e){this.__lc=e;var t=e.match,n=t.factHash,r=this.__fh,i,s=this.__variables;for(var o=0,u=this.__varLength;o=0;n--)r=t[n],i.setLeftContext(r).isMatch()&&(this._propagateRetractResolve(r.match),this.__removeFromLeftMemory(r),r.blocker=e,e.blocking.push(r),this.__addToLeftTupleMemory(r));i.clearContexts()},__removeFromLeftMemory:function(e){var t=this.leftMemory[e.fact.id],n,r=this.leftTuples;for(var i=0,s=t.length;i=0;t--){var n=e[t],r=n.key,i=n.value;r.dispose({paths:i})}},__propagate:function(e,t,n){var r=this.__entrySet,i=r.length-1;for(;i>=0;i--){var s=r[i],o=s.key,u=s.value;o[e](new a(t,u))}}}}).as(t)}),require.define("/lib/nodes/terminalNode.js",function(e,t,n,r,i,s,o){var u=e("./node"),a=e("../extended"),f=a.bind,l=a.removeDuplicates;u.extend({instance:{constructor:function(e,t,n,r){this._super([]),this.resolve=f(this,this.resolve),this.rule=n,this.index=t,this.name=this.rule.name,this.agenda=r,this.bucket=e,r.register(this)},__assertModify:function(e){var t=e.match;t.recency.sort(function(e,t){return e-t}).reverse(),t.facts=l(t.facts);if(t.isMatch){var n=this.rule,r=this.bucket;this.agenda.insert(this,{rule:n,index:this.index,name:n.name,recency:r.recency++,match:t,counter:r.counter})}},assert:function(e){this.__assertModify(e)},modify:function(e){this.__assertModify(e)},retract:function(e){this.agenda.removeByFact(this,e)},retractRight:function(e){this.agenda.removeByFact(this,e)},retractLeft:function(e){this.agenda.removeByFact(this,e)},assertLeft:function(e){this.__assertModify(e)},assertRight:function(e){this.__assertModify(e)},retractResolve:function(e){var t=this.resolve;this.agenda.retract(this,function(n){return t(n.match,e)})},toString:function(){return"TerminalNode "+this.rule.name}}}).as(t)}),require.define("/lib/nodes/propertyNode.js",function(e,t,n,r,i,s,o){var u=e("./alphaNode"),a=e("../context"),f=e("../extended");u.extend({instance:{constructor:function(){this._super(arguments),this.alias=this.constraint.get("alias"),this.varLength=(this.variables=f(this.constraint.get("variables")).toArray().value()).length},assert:function(e){var t=new a(e.fact,e.paths),n=this.variables,r=e.fact.object,i;t.set(this.alias,r);for(var s=0,o=this.varLength;s0&&this._events[e].length>n&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),console.trace())}this._events[e].push(t)}else this._events[e]=[this._events[e],t];return this},u.prototype.on=u.prototype.addListener,u.prototype.once=function(e,t){var n=this;return n.on(e,function r(){n.removeListener(e,r),t.apply(this,arguments)}),this},u.prototype.removeListener=function(e,t){if("function"!=typeof t)throw new Error("removeListener only takes instances of Function");if(!this._events||!this._events[e])return this;var n=this._events[e];if(a(n)){var r=f(n,t);if(r<0)return this;n.splice(r,1),n.length==0&&delete this._events[e]}else this._events[e]===t&&delete this._events[e];return this},u.prototype.removeAllListeners=function(e){return e&&this._events&&this._events[e]&&(this._events[e]=null),this},u.prototype.listeners=function(e){return this._events||(this._events={}),this._events[e]||(this._events[e]=[]),a(this._events[e])||(this._events[e]=[this._events[e]]),this._events[e]}}),require.define("/lib/rule.js",function(e,t,n,r,i,s,o){"use strict";function S(e,t,n,r){u.isArray(t)?(r=n,n=t):t=t||{};var i=u.every(n,function(e){return a(e)});i&&n.length===1&&(n=n[0],i=!1);var s=[],o=t.scope||{};n.scope=o;if(i){var f=function(e,t){c[t]?u(c).forEach(function(t){t.push(e)}):(c[t]=t===0?[]:c[t-1].slice(),t!==0&&c[t].pop(),c[t].push(e))},l=n.length,c=[],h;for(var p=0;p":18,"<=":19,">=":20,EQUALITY_EXPRESSION:21,"==":22,"!=":23,"=~":24,"!=~":25,IN_EXPRESSION:26,"in":27,ARRAY_EXPRESSION:28,notIn:29,OBJECT_EXPRESSION:30,AND_EXPRESSION:31,"&&":32,OR_EXPRESSION:33,"||":34,ARGUMENT_LIST:35,",":36,FUNCTION:37,IDENTIFIER:38,"(":39,")":40,IDENTIFIER_EXPRESSION:41,".":42,STRING_EXPRESSION:43,STRING:44,NUMBER_EXPRESSION:45,NUMBER:46,REGEXP_EXPRESSION:47,REGEXP:48,BOOLEAN_EXPRESSION:49,BOOLEAN:50,NULL_EXPRESSION:51,NULL:52,"[":53,"]":54,$accept:0,$end:1},terminals_:{2:"error",5:"EOF",8:"-",10:"*",11:"/",13:"+",15:"^",17:"<",18:">",19:"<=",20:">=",22:"==",23:"!=",24:"=~",25:"!=~",27:"in",29:"notIn",32:"&&",34:"||",36:",",38:"IDENTIFIER",39:"(",40:")",42:".",44:"STRING",46:"NUMBER",48:"REGEXP",50:"BOOLEAN",52:"NULL",53:"[",54:"]"},productions_:[0,[3,2],[6,1],[6,2],[9,1],[9,3],[9,3],[12,1],[12,3],[12,3],[14,1],[14,3],[16,1],[16,3],[16,3],[16,3],[16,3],[21,1],[21,3],[21,3],[21,3],[21,3],[26,1],[26,3],[26,3],[26,3],[26,3],[31,1],[31,3],[33,1],[33,3],[35,1],[35,3],[37,3],[37,4],[30,1],[30,3],[30,3],[41,1],[43,1],[45,1],[47,1],[49,1],[51,1],[28,2],[28,3],[7,1],[7,1],[7,1],[7,1],[7,1],[7,1],[7,1],[7,1],[7,3],[4,1]],performAction:function(t,n,r,i,s,o,u){var a=o.length-1;switch(s){case 1:return o[a-1];case 3:this.$=[o[a],null,"unminus"];break;case 5:this.$=[o[a-2],o[a],"mult"];break;case 6:this.$=[o[a-2],o[a],"div"];break;case 8:this.$=[o[a-2],o[a],"plus"];break;case 9:this.$=[o[a-2],o[a],"minus"];break;case 11:this.$=[o[a-2],o[a],"pow"];break;case 13:this.$=[o[a-2],o[a],"lt"];break;case 14:this.$=[o[a-2],o[a],"gt"];break;case 15:this.$=[o[a-2],o[a],"lte"];break;case 16:this.$=[o[a-2],o[a],"gte"];break;case 18:this.$=[o[a-2],o[a],"eq"];break;case 19:this.$=[o[a-2],o[a],"neq"];break;case 20:this.$=[o[a-2],o[a],"like"];break;case 21:this.$=[o[a-2],o[a],"notLike"];break;case 23:this.$=[o[a-2],o[a],"in"];break;case 24:this.$=[o[a-2],o[a],"notIn"];break;case 25:this.$=[o[a-2],o[a],"in"];break;case 26:this.$=[o[a-2],o[a],"notIn"];break;case 28:this.$=[o[a-2],o[a],"and"];break;case 30:this.$=[o[a-2],o[a],"or"];break;case 32:this.$=[o[a-2],o[a],"arguments"];break;case 33:this.$=[o[a-2],[null,null,"arguments"],"function"];break;case 34:this.$=[o[a-3],o[a-1],"function"];break;case 36:this.$=[o[a-2],o[a],"prop"];break;case 37:this.$=[o[a-2],o[a],"prop"];break;case 38:this.$=[String(t),null,"identifier"];break;case 39:this.$=[String(t.replace(/^'|'$/g,"")),null,"string"];break;case 40:this.$=[Number(t),null,"number"];break;case 41:this.$=[RegExp(t.replace(/^\/|\/$/g,"")),null,"regexp"];break;case 42:this.$=[t=="true",null,"boolean"];break;case 43:this.$=[null,null,"null"];break;case 44:this.$=[null,null,"array"];break;case 45:this.$=[o[a-1],null,"array"];break;case 54:this.$=[o[a-1],null,"composite"]}},table:[{3:1,4:2,6:29,7:7,8:[1,30],9:28,12:27,14:18,16:8,21:6,26:5,28:15,30:16,31:4,33:3,37:14,38:[1,24],39:[1,17],41:26,43:9,44:[1,19],45:10,46:[1,20],47:11,48:[1,21],49:12,50:[1,22],51:13,52:[1,23],53:[1,25]},{1:[3]},{5:[1,31]},{5:[2,55],34:[1,32],40:[2,55]},{5:[2,29],32:[1,33],34:[2,29],40:[2,29]},{5:[2,27],32:[2,27],34:[2,27],40:[2,27]},{5:[2,22],22:[1,34],23:[1,35],24:[1,36],25:[1,37],32:[2,22],34:[2,22],40:[2,22]},{5:[2,2],8:[2,2],10:[2,2],11:[2,2],13:[2,2],15:[2,2],17:[2,2],18:[2,2],19:[2,2],20:[2,2],22:[2,2],23:[2,2],24:[2,2],25:[2,2],27:[1,38],29:[1,39],32:[2,2],34:[2,2],40:[2,2]},{5:[2,17],17:[1,40],18:[1,41],19:[1,42],20:[1,43],22:[2,17],23:[2,17],24:[2,17],25:[2,17],32:[2,17],34:[2,17],40:[2,17]},{5:[2,46],8:[2,46],10:[2,46],11:[2,46],13:[2,46],15:[2,46],17:[2,46],18:[2,46],19:[2,46],20:[2,46],22:[2,46],23:[2,46],24:[2,46],25:[2,46],27:[2,46],29:[2,46],32:[2,46],34:[2,46],36:[2,46],40:[2,46],54:[2,46]},{5:[2,47],8:[2,47],10:[2,47],11:[2,47],13:[2,47],15:[2,47],17:[2,47],18:[2,47],19:[2,47],20:[2,47],22:[2,47],23:[2,47],24:[2,47],25:[2,47],27:[2,47],29:[2,47],32:[2,47],34:[2,47],36:[2,47],40:[2,47],54:[2,47]},{5:[2,48],8:[2,48],10:[2,48],11:[2,48],13:[2,48],15:[2,48],17:[2,48],18:[2,48],19:[2,48],20:[2,48],22:[2,48],23:[2,48],24:[2,48],25:[2,48],27:[2,48],29:[2,48],32:[2,48],34:[2,48],36:[2,48],40:[2,48],54:[2,48]},{5:[2,49],8:[2,49],10:[2,49],11:[2,49],13:[2,49],15:[2,49],17:[2,49],18:[2,49],19:[2,49],20:[2,49],22:[2,49],23:[2,49],24:[2,49],25:[2,49],27:[2,49],29:[2,49],32:[2,49],34:[2,49],36:[2,49],40:[2,49],54:[2,49]},{5:[2,50],8:[2,50],10:[2,50],11:[2,50],13:[2,50],15:[2,50],17:[2,50],18:[2,50],19:[2,50],20:[2,50],22:[2,50],23:[2,50],24:[2,50],25:[2,50],27:[2,50],29:[2,50],32:[2,50],34:[2,50],36:[2,50],40:[2,50],54:[2,50]},{5:[2,51],8:[2,51],10:[2,51],11:[2,51],13:[2,51],15:[2,51],17:[2,51],18:[2,51],19:[2,51],20:[2,51],22:[2,51],23:[2,51],24:[2,51],25:[2,51],27:[2,51],29:[2,51],32:[2,51],34:[2,51],36:[2,51],40:[2,51],54:[2,51]},{5:[2,52],8:[2,52],10:[2,52],11:[2,52],13:[2,52],15:[2,52],17:[2,52],18:[2,52],19:[2,52],20:[2,52],22:[2,52],23:[2,52],24:[2,52],25:[2,52],27:[2,52],29:[2,52],32:[2,52],34:[2,52],36:[2,52],40:[2,52],54:[2,52]},{5:[2,53],8:[2,53],10:[2,53],11:[2,53],13:[2,53],15:[2,53],17:[2,53],18:[2,53],19:[2,53],20:[2,53],22:[2,53],23:[2,53],24:[2,53],25:[2,53],27:[2,53],29:[2,53],32:[2,53],34:[2,53],36:[2,53],40:[2,53],42:[1,44],54:[2,53]},{4:45,6:29,7:7,8:[1,30],9:28,12:27,14:18,16:8,21:6,26:5,28:15,30:16,31:4,33:3,37:14,38:[1,24],39:[1,17],41:26,43:9,44:[1,19],45:10,46:[1,20],47:11,48:[1,21],49:12,50:[1,22],51:13,52:[1,23],53:[1,25]},{5:[2,12],15:[1,46],17:[2,12],18:[2,12],19:[2,12],20:[2,12],22:[2,12],23:[2,12],24:[2,12],25:[2,12],32:[2,12],34:[2,12],40:[2,12]},{5:[2,39],8:[2,39],10:[2,39],11:[2,39],13:[2,39],15:[2,39],17:[2,39],18:[2,39],19:[2,39],20:[2,39],22:[2,39],23:[2,39],24:[2,39],25:[2,39],27:[2,39],29:[2,39],32:[2,39],34:[2,39],36:[2,39],40:[2,39],54:[2,39]},{5:[2,40],8:[2,40],10:[2,40],11:[2,40],13:[2,40],15:[2,40],17:[2,40],18:[2,40],19:[2,40],20:[2,40],22:[2,40],23:[2,40],24:[2,40],25:[2,40],27:[2,40],29:[2,40],32:[2,40],34:[2,40],36:[2,40],40:[2,40],54:[2,40]},{5:[2,41],8:[2,41],10:[2,41],11:[2,41],13:[2,41],15:[2,41],17:[2,41],18:[2,41],19:[2,41],20:[2,41],22:[2,41],23:[2,41],24:[2,41],25:[2,41],27:[2,41],29:[2,41],32:[2,41],34:[2,41],36:[2,41],40:[2,41],54:[2,41]},{5:[2,42],8:[2,42],10:[2,42],11:[2,42],13:[2,42],15:[2,42],17:[2,42],18:[2,42],19:[2,42],20:[2,42],22:[2,42],23:[2,42],24:[2,42],25:[2,42],27:[2,42],29:[2,42],32:[2,42],34:[2,42],36:[2,42],40:[2,42],54:[2,42]},{5:[2,43],8:[2,43],10:[2,43],11:[2,43],13:[2,43],15:[2,43],17:[2,43],18:[2,43],19:[2,43],20:[2,43],22:[2,43],23:[2,43],24:[2,43],25:[2,43],27:[2,43],29:[2,43],32:[2,43],34:[2,43],36:[2,43],40:[2,43],54:[2,43]},{5:[2,38],8:[2,38],10:[2,38],11:[2,38],13:[2,38],15:[2,38],17:[2,38],18:[2,38],19:[2,38],20:[2,38],22:[2,38],23:[2,38],24:[2,38],25:[2,38],27:[2,38],29:[2,38],32:[2,38],34:[2,38],36:[2,38],39:[1,47],40:[2,38],42:[2,38],54:[2,38]},{7:50,28:15,30:16,35:49,37:14,38:[1,24],39:[1,17],41:26,43:9,44:[1,19],45:10,46:[1,20],47:11,48:[1,21],49:12,50:[1,22],51:13,52:[1,23],53:[1,25],54:[1,48]},{5:[2,35],8:[2,35],10:[2,35],11:[2,35],13:[2,35],15:[2,35],17:[2,35],18:[2,35],19:[2,35],20:[2,35],22:[2,35],23:[2,35],24:[2,35],25:[2,35],27:[2,35],29:[2,35],32:[2,35],34:[2,35],36:[2,35],40:[2,35],42:[2,35],54:[2,35]},{5:[2,10],8:[1,52],13:[1,51],15:[2,10],17:[2,10],18:[2,10],19:[2,10],20:[2,10],22:[2,10],23:[2,10],24:[2,10],25:[2,10],32:[2,10],34:[2,10],40:[2,10]},{5:[2,7],8:[2,7],10:[1,53],11:[1,54],13:[2,7],15:[2,7],17:[2,7],18:[2,7],19:[2,7],20:[2,7],22:[2,7],23:[2,7],24:[2,7],25:[2,7],32:[2,7],34:[2,7],40:[2,7]},{5:[2,4],8:[2,4],10:[2,4],11:[2,4],13:[2,4],15:[2,4],17:[2,4],18:[2,4],19:[2,4],20:[2,4],22:[2,4],23:[2,4],24:[2,4],25:[2,4],32:[2,4],34:[2,4],40:[2,4]},{6:55,7:56,8:[1,30],28:15,30:16,37:14,38:[1,24],39:[1,17],41:26,43:9,44:[1,19],45:10,46:[1,20],47:11,48:[1,21],49:12,50:[1,22],51:13,52:[1,23],53:[1,25]},{1:[2,1]},{6:29,7:7,8:[1,30],9:28,12:27,14:18,16:8,21:6,26:5,28:15,30:16,31:57,37:14,38:[1,24],39:[1,17],41:26,43:9,44:[1,19],45:10,46:[1,20],47:11,48:[1,21],49:12,50:[1,22],51:13,52:[1,23],53:[1,25]},{6:29,7:7,8:[1,30],9:28,12:27,14:18,16:8,21:6,26:58,28:15,30:16,37:14,38:[1,24],39:[1,17],41:26,43:9,44:[1,19],45:10,46:[1,20],47:11,48:[1,21],49:12,50:[1,22],51:13,52:[1,23],53:[1,25]},{6:29,7:56,8:[1,30],9:28,12:27,14:18,16:59,28:15,30:16,37:14,38:[1,24],39:[1,17],41:26,43:9,44:[1,19],45:10,46:[1,20],47:11,48:[1,21],49:12,50:[1,22],51:13,52:[1,23],53:[1,25]},{6:29,7:56,8:[1,30],9:28,12:27,14:18,16:60,28:15,30:16,37:14,38:[1,24],39:[1,17],41:26,43:9,44:[1,19],45:10,46:[1,20],47:11,48:[1,21],49:12,50:[1,22],51:13,52:[1,23],53:[1,25]},{6:29,7:56,8:[1,30],9:28,12:27,14:18,16:61,28:15,30:16,37:14,38:[1,24],39:[1,17],41:26,43:9,44:[1,19],45:10,46:[1,20],47:11,48:[1,21],49:12,50:[1,22],51:13,52:[1,23],53:[1,25]},{6:29,7:56,8:[1,30],9:28,12:27,14:18,16:62,28:15,30:16,37:14,38:[1,24],39:[1,17],41:26,43:9,44:[1,19],45:10,46:[1,20],47:11,48:[1,21],49:12,50:[1,22],51:13,52:[1,23],53:[1,25]},{28:63,30:64,38:[1,65],41:26,53:[1,25]},{28:66,30:67,38:[1,65],41:26,53:[1,25]},{6:29,7:56,8:[1,30],9:28,12:27,14:68,28:15,30:16,37:14,38:[1,24],39:[1,17],41:26,43:9,44:[1,19],45:10,46:[1,20],47:11,48:[1,21],49:12,50:[1,22],51:13,52:[1,23],53:[1,25]},{6:29,7:56,8:[1,30],9:28,12:27,14:69,28:15,30:16,37:14,38:[1,24],39:[1,17],41:26,43:9,44:[1,19],45:10,46:[1,20],47:11,48:[1,21],49:12,50:[1,22],51:13,52:[1,23],53:[1,25]},{6:29,7:56,8:[1,30],9:28,12:27,14:70,28:15,30:16,37:14,38:[1,24],39:[1,17],41:26,43:9,44:[1,19],45:10,46:[1,20],47:11,48:[1,21],49:12,50:[1,22],51:13,52:[1,23],53:[1,25]},{6:29,7:56,8:[1,30],9:28,12:27,14:71,28:15,30:16,37:14,38:[1,24],39:[1,17],41:26,43:9,44:[1,19],45:10,46:[1,20],47:11,48:[1,21],49:12,50:[1,22],51:13,52:[1,23],53:[1,25]},{37:73,38:[1,24],41:72},{40:[1,74]},{6:29,7:56,8:[1,30],9:28,12:75,28:15,30:16,37:14,38:[1,24],39:[1,17],41:26,43:9,44:[1,19],45:10,46:[1,20],47:11,48:[1,21],49:12,50:[1,22],51:13,52:[1,23],53:[1,25]},{7:50,28:15,30:16,35:77,37:14,38:[1,24],39:[1,17],40:[1,76],41:26,43:9,44:[1,19],45:10,46:[1,20],47:11,48:[1,21],49:12,50:[1,22],51:13,52:[1,23],53:[1,25]},{5:[2,44],8:[2,44],10:[2,44],11:[2,44],13:[2,44],15:[2,44],17:[2,44],18:[2,44],19:[2,44],20:[2,44],22:[2,44],23:[2,44],24:[2,44],25:[2,44],27:[2,44],29:[2,44],32:[2,44],34:[2,44],36:[2,44],40:[2,44],54:[2,44]},{36:[1,79],54:[1,78]},{36:[2,31],40:[2,31],54:[2,31]},{6:29,7:56,8:[1,30],9:80,28:15,30:16,37:14,38:[1,24],39:[1,17],41:26,43:9,44:[1,19],45:10,46:[1,20],47:11,48:[1,21],49:12,50:[1,22],51:13,52:[1,23],53:[1,25]},{6:29,7:56,8:[1,30],9:81,28:15,30:16,37:14,38:[1,24],39:[1,17],41:26,43:9,44:[1,19],45:10,46:[1,20],47:11,48:[1,21],49:12,50:[1,22],51:13,52:[1,23],53:[1,25]},{6:82,7:56,8:[1,30],28:15,30:16,37:14,38:[1,24],39:[1,17],41:26,43:9,44:[1,19],45:10,46:[1,20],47:11,48:[1,21],49:12,50:[1,22],51:13,52:[1,23],53:[1,25]},{6:83,7:56,8:[1,30],28:15,30:16,37:14,38:[1,24],39:[1,17],41:26,43:9,44:[1,19],45:10,46:[1,20],47:11,48:[1,21],49:12,50:[1,22],51:13,52:[1,23],53:[1,25]},{5:[2,3],8:[2,3],10:[2,3],11:[2,3],13:[2,3],15:[2,3],17:[2,3],18:[2,3],19:[2,3],20:[2,3],22:[2,3],23:[2,3],24:[2,3],25:[2,3],32:[2,3],34:[2,3],40:[2,3]},{5:[2,2],8:[2,2],10:[2,2],11:[2,2],13:[2,2],15:[2,2],17:[2,2],18:[2,2],19:[2,2],20:[2,2],22:[2,2],23:[2,2],24:[2,2],25:[2,2],32:[2,2],34:[2,2],40:[2,2]},{5:[2,30],32:[1,33],34:[2,30],40:[2,30]},{5:[2,28],32:[2,28],34:[2,28],40:[2,28]},{5:[2,18],17:[1,40],18:[1,41],19:[1,42],20:[1,43],22:[2,18],23:[2,18],24:[2,18],25:[2,18],32:[2,18],34:[2,18],40:[2,18]},{5:[2,19],17:[1,40],18:[1,41],19:[1,42],20:[1,43],22:[2,19],23:[2,19],24:[2,19],25:[2,19],32:[2,19],34:[2,19],40:[2,19]},{5:[2,20],17:[1,40],18:[1,41],19:[1,42],20:[1,43],22:[2,20],23:[2,20],24:[2,20],25:[2,20],32:[2,20],34:[2,20],40:[2,20]},{5:[2,21],17:[1,40],18:[1,41],19:[1,42],20:[1,43],22:[2,21],23:[2,21],24:[2,21],25:[2,21],32:[2,21],34:[2,21],40:[2,21]},{5:[2,23],32:[2,23],34:[2,23],40:[2,23]},{5:[2,25],32:[2,25],34:[2,25],40:[2,25],42:[1,44]},{5:[2,38],32:[2,38],34:[2,38],40:[2,38],42:[2,38]},{5:[2,24],32:[2,24],34:[2,24],40:[2,24]},{5:[2,26],32:[2,26],34:[2,26],40:[2,26],42:[1,44]},{5:[2,13],15:[1,46],17:[2,13],18:[2,13],19:[2,13],20:[2,13],22:[2,13],23:[2,13],24:[2,13],25:[2,13],32:[2,13],34:[2,13],40:[2,13]},{5:[2,14],15:[1,46],17:[2,14],18:[2,14],19:[2,14],20:[2,14],22:[2,14],23:[2,14],24:[2,14],25:[2,14],32:[2,14],34:[2,14],40:[2,14]},{5:[2,15],15:[1,46],17:[2,15],18:[2,15],19:[2,15],20:[2,15],22:[2,15],23:[2,15],24:[2,15],25:[2,15],32:[2,15],34:[2,15],40:[2,15]},{5:[2,16],15:[1,46],17:[2,16],18:[2,16],19:[2,16],20:[2,16],22:[2,16],23:[2,16],24:[2,16],25:[2,16],32:[2,16],34:[2,16],40:[2,16]},{5:[2,36],8:[2,36],10:[2,36],11:[2,36],13:[2,36],15:[2,36],17:[2,36],18:[2,36],19:[2,36],20:[2,36],22:[2,36],23:[2,36],24:[2,36],25:[2,36],27:[2,36],29:[2,36],32:[2,36],34:[2,36],36:[2,36],40:[2,36],42:[2,36],54:[2,36]},{5:[2,37],8:[2,37],10:[2,37],11:[2,37],13:[2,37],15:[2,37],17:[2,37],18:[2,37],19:[2,37],20:[2,37],22:[2,37],23:[2,37],24:[2,37],25:[2,37],27:[2,37],29:[2,37],32:[2,37],34:[2,37],36:[2,37],40:[2,37],42:[2,37],54:[2,37]},{5:[2,54],8:[2,54],10:[2,54],11:[2,54],13:[2,54],15:[2,54],17:[2,54],18:[2,54],19:[2,54],20:[2,54],22:[2,54],23:[2,54],24:[2,54],25:[2,54],27:[2,54],29:[2,54],32:[2,54],34:[2,54],36:[2,54],40:[2,54],54:[2,54]},{5:[2,11],8:[1,52],13:[1,51],15:[2,11],17:[2,11],18:[2,11],19:[2,11],20:[2,11],22:[2,11],23:[2,11],24:[2,11],25:[2,11],32:[2,11],34:[2,11],40:[2,11]},{5:[2,33],8:[2,33],10:[2,33],11:[2,33],13:[2,33],15:[2,33],17:[2,33],18:[2,33],19:[2,33],20:[2,33],22:[2,33],23:[2,33],24:[2,33],25:[2,33],27:[2,33],29:[2,33],32:[2,33],34:[2,33],36:[2,33],40:[2,33],42:[2,33],54:[2,33]},{36:[1,79],40:[1,84]},{5:[2,45],8:[2,45],10:[2,45],11:[2,45],13:[2,45],15:[2,45],17:[2,45],18:[2,45],19:[2,45],20:[2,45],22:[2,45],23:[2,45],24:[2,45],25:[2,45],27:[2,45],29:[2,45],32:[2,45],34:[2,45],36:[2,45],40:[2,45],54:[2,45]},{7:85,28:15,30:16,37:14,38:[1,24],39:[1,17],41:26,43:9,44:[1,19],45:10,46:[1,20],47:11,48:[1,21],49:12,50:[1,22],51:13,52:[1,23],53:[1,25]},{5:[2,8],8:[2,8],10:[1,53],11:[1,54],13:[2,8],15:[2,8],17:[2,8],18:[2,8],19:[2,8],20:[2,8],22:[2,8],23:[2,8],24:[2,8],25:[2,8],32:[2,8],34:[2,8],40:[2,8]},{5:[2,9],8:[2,9],10:[1,53],11:[1,54],13:[2,9],15:[2,9],17:[2,9],18:[2,9],19:[2,9],20:[2,9],22:[2,9],23:[2,9],24:[2,9],25:[2,9],32:[2,9],34:[2,9],40:[2,9]},{5:[2,5],8:[2,5],10:[2,5],11:[2,5],13:[2,5],15:[2,5],17:[2,5],18:[2,5],19:[2,5],20:[2,5],22:[2,5],23:[2,5],24:[2,5],25:[2,5],32:[2,5],34:[2,5],40:[2,5]},{5:[2,6],8:[2,6],10:[2,6],11:[2,6],13:[2,6],15:[2,6],17:[2,6],18:[2,6],19:[2,6],20:[2,6],22:[2,6],23:[2,6],24:[2,6],25:[2,6],32:[2,6],34:[2,6],40:[2,6]},{5:[2,34],8:[2,34],10:[2,34],11:[2,34],13:[2,34],15:[2,34],17:[2,34],18:[2,34],19:[2,34],20:[2,34],22:[2,34],23:[2,34],24:[2,34],25:[2,34],27:[2,34],29:[2,34],32:[2,34],34:[2,34],36:[2,34],40:[2,34],42:[2,34],54:[2,34]},{36:[2,32],40:[2,32],54:[2,32]}],defaultActions:{31:[2,1]},parseError:function(t,n){throw new Error(t)},parse:function(t){function v(e){r.length=r.length-2*e,i.length=i.length-e,s.length=s.length-e}function m(){var e;return e=n.lexer.lex()||1,typeof e!="number"&&(e=n.symbols_[e]||e),e}var n=this,r=[0],i=[null],s=[],o=this.table,u="",a=0,f=0,l=0,c=2,h=1;this.lexer.setInput(t),this.lexer.yy=this.yy,this.yy.lexer=this.lexer,this.yy.parser=this,typeof this.lexer.yylloc=="undefined"&&(this.lexer.yylloc={});var p=this.lexer.yylloc;s.push(p);var d=this.lexer.options&&this.lexer.options.ranges;typeof this.yy.parseError=="function"&&(this.parseError=this.yy.parseError);var g,y,b,w,E,S,x={},T,N,C,k;for(;;){b=r[r.length-1];if(this.defaultActions[b])w=this.defaultActions[b];else{if(g===null||typeof g=="undefined")g=m();w=o[b]&&o[b][g]}if(typeof w=="undefined"||!w.length||!w[0]){var L="";if(!l){k=[];for(T in o[b])this.terminals_[T]&&T>2&&k.push("'"+this.terminals_[T]+"'");this.lexer.showPosition?L="Parse error on line "+(a+1)+":\n"+this.lexer.showPosition()+"\nExpecting "+k.join(", ")+", got '"+(this.terminals_[g]||g)+"'":L="Parse error on line "+(a+1)+": Unexpected "+(g==1?"end of input":"'"+(this.terminals_[g]||g)+"'"),this.parseError(L,{text:this.lexer.match,token:this.terminals_[g]||g,line:this.lexer.yylineno,loc:p,expected:k})}}if(w[0]instanceof Array&&w.length>1)throw new Error("Parse Error: multiple actions possible at state: "+b+", token: "+g);switch(w[0]){case 1:r.push(g),i.push(this.lexer.yytext),s.push(this.lexer.yylloc),r.push(w[1]),g=null,y?(g=y,y=null):(f=this.lexer.yyleng,u=this.lexer.yytext,a=this.lexer.yylineno,p=this.lexer.yylloc,l>0&&l--);break;case 2:N=this.productions_[w[1]][1],x.$=i[i.length-N],x._$={first_line:s[s.length-(N||1)].first_line,last_line:s[s.length-1].last_line,first_column:s[s.length-(N||1)].first_column,last_column:s[s.length-1].last_column},d&&(x._$.range=[s[s.length-(N||1)].range[0],s[s.length-1].range[1]]),S=this.performAction.call(x,u,f,a,this.yy,w[1],i,s);if(typeof S!="undefined")return S;N&&(r=r.slice(0,-1*N*2),i=i.slice(0,-1*N),s=s.slice(0,-1*N)),r.push(this.productions_[w[1]][0]),i.push(x.$),s.push(x._$),C=o[r[r.length-2]][r[r.length-1]],r.push(C);break;case 3:return!0}}return!0}};undefined;var t=function(){var e={EOF:1,parseError:function(t,n){if(!this.yy.parser)throw new Error(t);this.yy.parser.parseError(t,n)},setInput:function(e){return this._input=e,this._more=this._less=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 e=this._input[0];this.yytext+=e,this.yyleng++,this.offset++,this.match+=e,this.matched+=e;var t=e.match(/(?:\r\n?|\n).*/g);return t?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),e},unput:function(e){var t=e.length,n=e.split(/(?:\r\n?|\n)/g);this._input=e+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-t-1),this.offset-=t;var r=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),n.length-1&&(this.yylineno-=n.length-1);var i=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:n?(n.length===r.length?this.yylloc.first_column:0)+r[r.length-n.length].length-n[0].length:this.yylloc.first_column-t},this.options.ranges&&(this.yylloc.range=[i[0],i[0]+this.yyleng-t]),this},more:function(){return this._more=!0,this},less:function(e){this.unput(this.match.slice(e))},pastInput:function(){var e=this.matched.substr(0,this.matched.length-this.match.length);return(e.length>20?"...":"")+e.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var e=this.match;return e.length<20&&(e+=this._input.substr(0,20-e.length)),(e.substr(0,20)+(e.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var e=this.pastInput(),t=(new Array(e.length+1)).join("-");return e+this.upcomingInput()+"\n"+t+"^"},next:function(){if(this.done)return this.EOF;this._input||(this.done=!0);var e,t,n,r,i,s;this._more||(this.yytext="",this.match="");var o=this._currentRules();for(var u=0;ut[0].length)){t=n,r=u;if(!this.options.flex)break}}if(t){s=t[0].match(/(?:\r\n?|\n).*/g),s&&(this.yylineno+=s.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:s?s[s.length-1].length-s[s.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+t[0].length},this.yytext+=t[0],this.match+=t[0],this.matches=t,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._input=this._input.slice(t[0].length),this.matched+=t[0],e=this.performAction.call(this,this.yy,this,o[r],this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1);if(e)return e;return}return 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 t=this.next();return typeof t!="undefined"?t:this.lex()},begin:function(t){this.conditionStack.push(t)},popState:function(){return this.conditionStack.pop()},_currentRules:function(){return this.conditions[this.conditionStack[this.conditionStack.length-1]].rules},topState:function(){return this.conditionStack[this.conditionStack.length-2]},pushState:function(t){this.begin(t)},options:{},performAction:function(t,n,r,i){var s=i;switch(r){case 0:return 27;case 1:return 29;case 2:return"from";case 3:break;case 4:return 46;case 5:return 52;case 6:return 22;case 7:return 23;case 8:return 19;case 9:return 17;case 10:return 20;case 11:return 18;case 12:return 24;case 13:return 25;case 14:return 32;case 15:return 34;case 16:return 50;case 17:return 44;case 18:return 38;case 19:return 48;case 20:return 42;case 21:return 10;case 22:return 11;case 23:return 36;case 24:return 8;case 25:return 24;case 26:return 25;case 27:return 22;case 28:return 22;case 29:return 23;case 30:return 23;case 31:return 19;case 32:return 20;case 33:return 18;case 34:return 17;case 35:return 32;case 36:return 34;case 37:return 13;case 38:return 15;case 39:return 39;case 40:return 54;case 41:return 53;case 42:return 40;case 43:return 5}},rules:[/^(?:\s+in\b)/,/^(?:\s+notIn\b)/,/^(?:\s+from\b)/,/^(?:\s+)/,/^(?:[0-9]+(?:\.[0-9]+)?\b)/,/^(?:null\b)/,/^(?:(eq|EQ))/,/^(?:(neq|NEQ))/,/^(?:(lte|LTE))/,/^(?:(lt|LT))/,/^(?:(gte|GTE))/,/^(?:(gt|GT))/,/^(?:(like|LIKE))/,/^(?:(notLike|NOT_LIKE))/,/^(?:(and|AND))/,/^(?:(or|OR))/,/^(?:(true|false))/,/^(?:'[^']*')/,/^(?:\$?[a-zA-Z0-9]+)/,/^(?:\/(.*)\/)/,/^(?:\.)/,/^(?:\*)/,/^(?:\/)/,/^(?:,)/,/^(?:-)/,/^(?:=~)/,/^(?:!=~)/,/^(?:==)/,/^(?:===)/,/^(?:!=)/,/^(?:!==)/,/^(?:<=)/,/^(?:>=)/,/^(?:>)/,/^(?:<)/,/^(?:&&)/,/^(?:\|\|)/,/^(?:\+)/,/^(?:\^)/,/^(?:\()/,/^(?:\])/,/^(?:\[)/,/^(?:\))/,/^(?:$)/],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],inclusive:!0}}};return e}();return e.lexer=t,n.prototype=e,e.Parser=n,new n}();typeof e!="undefined"&&typeof n!="undefined"&&(n.parser=u,n.Parser=u.Parser,n.parse=function(){return u.parse.apply(u,arguments)},n.main=function(r){r[1]||(console.log("Usage: "+r[0]+" FILE"),s.exit(1));var i=e("fs").readFileSync(e("path").normalize(r[1]),"utf8");return n.parser.parse(i)},typeof t!="undefined"&&e.main===t&&n.main(s.argv.slice(1)))}),require.define("/lib/parser/nools/nool.parser.js",function(e,t,n,r,i,s,o){"use strict";var u=e("./tokens.js"),a=e("../../extended"),f=a.hash.keys,l=e("./util.js"),c=function(e,t,n){var r=e;e=e.replace(/\/\/(.*)[\n|\r|\r\n]/g,"").replace(/\n|\r|\r\n/g," ");var i=new RegExp("^("+f(t).join("|")+")"),s;while(e&&(s=l.findNextTokenIndex(e))!==-1){e=e.substr(s);var o=e.match(i);if(o===null)throw new Error("Error parsing "+e);o=o[1];if(!(o in t))throw new Error("Unknown token"+o);try{e=t[o](e,n,c).replace(/^\s*|\s*$/g,"")}catch(u){throw new Error("Invalid "+o+" definition \n"+u.message+"; \nstarting at : "+r)}}};n.parse=function(e){var t={define:[],rules:[],scope:[]};return c(e,u,t),t}}),require.define("/lib/parser/nools/tokens.js",function(require,module,exports,__dirname,__filename,process,global){"use strict";var utils=require("./util.js"),isWhiteSpace=function(e){return e.replace(/[\s|\n|\r|\t]/g,"").length===0},ruleTokens={salience:function(){var e=/^(salience|priority)\s*:\s*(-?\d+)\s*[,;]?/;return function(t,n){if(e.test(t)){var r=t.match(e),i=parseInt(r[2],10);if(!isNaN(i))return n.options.priority=i,t.replace(r[0],"");throw new Error("Invalid salience/priority "+r[2])}throw new Error("invalid format")}}(),priority:function(){return this.salience.apply(this,arguments)},when:function(){var ruleRegExp=/^(\$?\w+) *: *(\w+)(.*)/,joinFunc=function(e,t){return"; "+t},constraintRegExp=/(\{(?:["']?\$?\w+["']?\s*:\s*["']?\$?\w+["']? *(?:, *["']?\$?\w+["']?\s*:\s*["']?\$?\w+["']?)*)+\})/,predicateExp=/^(\w+) *\((.*)\)$/m,parseRules=function(str){var rules=[],ruleLines=str.split(";"),l=ruleLines.length,ruleLine;for(var i=0;is)r=s;for(;n=0;i--){if(t[i]==="node_modules")continue;var s=t.slice(0,i+1).join("/")+"/node_modules";r.push(s)}return r}t||(t="/");if(require._core[e])return e;var n=require.modules.path();t=n.resolve("/",t);var r=t||"/";if(e.match(/^(?:\.\.?\/|\/)/)){var i=o(n.resolve(r,e))||u(n.resolve(r,e));if(i)return i}var s=a(e,r);if(s)return s;throw new Error("Cannot find module '"+e+"'")}}(),require.alias=function(e,t){var n=require.modules.path(),r=null;try{r=require.resolve(e+"/package.json","/")}catch(i){r=require.resolve(e,"/")}var s=n.dirname(r),o=(Object.keys||function(e){var t=[];for(var n in e)t.push(n);return t})(require.modules);for(var u=0;u=0;r--){var i=e[r];i=="."?e.splice(r,1):i===".."?(e.splice(r,1),n++):n&&(e.splice(r,1),n--)}if(t)for(;n--;n)e.unshift("..");return e}var f=/^(.+\/(?!$)|\/)?((?:.+?)?(\.[^.]*)?)$/;n.resolve=function(){var e="",t=!1;for(var n=arguments.length;n>=-1&&!t;n--){var r=n>=0?arguments[n]:s.cwd();if(typeof r!="string"||!r)continue;e=r+"/"+e,t=r.charAt(0)==="/"}return e=a(u(e.split("/"),function(e){return!!e}),!t).join("/"),(t?"/":"")+e||"."},n.normalize=function(e){var t=e.charAt(0)==="/",n=e.slice(-1)==="/";return e=a(u(e.split("/"),function(e){return!!e}),!t).join("/"),!e&&!t&&(e="."),e&&n&&(e+="/"),(t?"/":"")+e},n.join=function(){var e=Array.prototype.slice.call(arguments,0);return n.normalize(u(e,function(e,t){return e&&typeof e=="string"}).join("/"))},n.dirname=function(e){var t=f.exec(e)[1]||"",n=!1;return t?t.length===1||n&&t.length<=3&&t.charAt(1)===":"?t:t.substring(0,t.length-1):"."},n.basename=function(e,t){var n=f.exec(e)[2]||"";return t&&n.substr(-1*t.length)===t&&(n=n.substr(0,n.length-t.length)),n},n.extname=function(e){return f.exec(e)[3]||""}}),require.define("__browserify_process",function(e,t,n,r,i,s,o){var s=t.exports={};s.nextTick=function(){var e=typeof window!="undefined"&&window.setImmediate,t=typeof window!="undefined"&&window.postMessage&&window.addEventListener;if(e)return function(e){return window.setImmediate(e)};if(t){var n=[];return window.addEventListener("message",function(e){if(e.source===window&&e.data==="browserify-tick"){e.stopPropagation();if(n.length>0){var t=n.shift();t()}}},!0),function(t){n.push(t),window.postMessage("browserify-tick","*")}}return function(t){setTimeout(t,0)}}(),s.title="browser",s.browser=!0,s.env={},s.argv=[],s.binding=function(t){if(t==="evals")return e("vm");throw new Error("No such module. (Possibly not yet loaded)")},function(){var t="/",n;s.cwd=function(){return t},s.chdir=function(r){n||(n=e("path")),t=n.resolve(r,t)}}()}),require.define("/package.json",function(e,t,n,r,i,s,o){t.exports={main:"index.js"}}),require.define("/index.js",function(e,t,n,r,i,s,o){t.exports=n=e("./lib")}),require.define("/lib/index.js",function(e,t,n,r,i,s,o){"use strict";function k(e){var t=0;return e instanceof x?t+=k(e.leftPattern)+k(e.rightPattern):t+=e.getSpecificity(),t}function H(e){return/\.nools$/.test(e)}function B(e){var t;return H(e)?t=C.parse(a.readFileSync(e,"utf8")):t=C.parse(e),t}var u=e("./extended"),a=e("fs"),f=e("path"),l=u.bind,c=u.indexOf,h=u.forEach,p=u.declare,d=u.Promise,v=u.when,m=u.AVLTree,g=e("./nodes"),y=e("events").EventEmitter,b=e("./rule"),w=e("./workingMemory"),E=w.WorkingMemory,S=e("./pattern"),x=S.CompositePattern,T=S.InitialFact,N=w.Fact,C=e("./compile"),L=function(e,t){if(e===t)return 0;var n,r=e.rule.priority,i=t.rule.priority;r!==i&&(n=r-i),e.counter!==t.counter&&(n=e.counter-t.counter),n||(n=e.recency-t.recency);if(!n){var s=0,o=e.match.recency,u=t.match.recency,a=o.length-1,f=u.length-1;while(o[s]===u[s]&&s0?1:-1},A=p({instance:{constructor:function(){this.memory=[],this.memoryValues=[]},get:function(e){return this.memoryValues[c(this.memory,e)]},remove:function(e){var t=e.match.facts,n=t.length-1,r=this.memoryValues,i=this.memory;for(;n>=0;n--){var s=c(i,t[n]),o=r[s],u=c(o,e);o.splice(u,1)}},insert:function(e){var t=e.match.facts,n=this.memoryValues,r=this.memory,i=t.length-1;for(;i>=0;i--){var s=t[i],o=c(r,s),u=n[o];u||(u=n[r.push(s)-1]=[]),u.push(e)}}}}),O=m.REVERSE_ORDER,M=p({instance:{constructor:function(){this.masterAgenda=new m({compare:L}),this.rules={}},register:function(e){this.rules[e.name]={tree:new m({compare:L}),factTable:new A}},isEmpty:function(){return this.masterAgenda.isEmpty()},pop:function(){var e=this.masterAgenda,t=e.__root;while(t.right)t=t.right;var n=t.data;e.remove(n);var r=this.rules[n.name];return r.tree.remove(n),r.factTable.remove(n),n},peek:function(){var e=this.masterAgenda,t=e.__root;while(t.right)t=t.right;return t.data},removeByFact:function(e,t){var n=this.rules[e.name],r=n.tree,i=n.factTable,s=this.masterAgenda,o=i.get(t)||[],u=o.length-1;for(;u>=0;u--){var a=o[u];i.remove(a),r.remove(a),s.remove(a)}o.length=0},retract:function(e,t){var n=this.rules[e.name],r=n.tree,i=n.factTable,s=this.masterAgenda;r.traverse(r.__root,O,function(e){t(e)&&(i.remove(e),s.remove(e),r.remove(e))})},insert:function(e,t){var n=this.rules[e.name];n.tree.insert(t),this.masterAgenda.insert(t),n.factTable.insert(t)},dispose:function(){this.masterAgenda.clear();var e=this.rules;for(var t in e)t in e&&e[t].tree.clear();this.rules={}}}}),_=p(y,{instance:{name:null,constructor:function(e){this.env=null,this.name=e,this.__rules={},this.__wmAltered=!1,this.workingMemory=new E,this.agenda=new M,this.rootNode=new g.RootNode(this.workingMemory,this.agenda)},halt:function(){return this.__halted=!0,this},dispose:function(){this.workingMemory.dispose(),this.agenda.dispose(),this.rootNode.dispose()},assert:function(e){return this.__wmAltered=!0,this.__factHelper(e,!0),this.emit("assert",e),e},retract:function(e){return this.__wmAltered=!0,this.__factHelper(e,!1),this.emit("retract",e),e},modify:function(e,t){var n=this.retract(e);return"function"==typeof t&&t.call(e,e),this.emit("modify",e),this.assert(n)},print:function(){this.rootNode.print()},containsRule:function(e){return this.rootNode.containsRule(e)},rule:function(e){this.rootNode.assertRule(e)},__loop:function(e,t){var n=new d,r=this,i=this.rootNode;return i?(i.resetCounter(),function s(){e(n,s)}()):n.callback(),n.classic(t),n},__callNext:function(e){var t=this.agenda.pop(),n=this.rootNode;return t.used=!0,this.emit("fire",t.rule.name,t.match.factHash),v(t.rule.fire(this,t.match)).then(l(this,function(){this.__wmAltered&&(n.incrementCounter(),this.__wmAltered=!1)}))},matchUntilHalt:function(e){return this.__halted=!1,this.__loop(l(this,function(e,t){!this.agenda.isEmpty()&&!this.__halted?this.__callNext(t).then(t,e.errback):this.__halted?e.callback():s.nextTick(t)}),e)},match:function(e){return this.__loop(l(this,function(e,t){this.agenda.isEmpty()?e.callback():this.__callNext(t).then(t,e.errback)}),e)},__factHelper:function(e,t){var n=new N(e);return t?n=this.__assertFact(n):n=this.__retractFact(n),n},__assertFact:function(e){var t=this.workingMemory.assertFact(e);return t&&this.rootNode.assertFact(t),t},__retractFact:function(e){var t=this.workingMemory.retractFact(e);return t&&this.rootNode&&this.rootNode.retractFact(t),t}}}),D={},P=p({instance:{constructor:function(e,t){this.name=e,this.cb=t,this.__rules=[],this.__defined={},t&&t.call(this,this);if(!!D.hasOwnProperty(e))throw new Error("Flow with "+e+" already defined");D[e]=this},getDefined:function(e){var t=this.__defined[e.toLowerCase()];if(!t)throw new Error(e+" flow class is not defined");return t},addDefined:function(e,t){return this.__defined[e.toLowerCase()]=t,t},rule:function(){this.__rules=this.__rules.concat(b.createRule.apply(b,arguments))},getSession:function(){var e=new _(this.name);h(this.__rules,function(t){e.rule(t)}),e.assert(new T);for(var t=0,n=arguments.length;tu){e=e?!a(e)&&!s(e)?[e]:e:[];var f=o.name,l=o.f,c;do{c=r[u][f];if("function"==typeof c&&(c=c._f||c)!==l)return o.pos=1+u,c.apply(this,e)}while(i>++u)}return null}function h(){var e=this.__meta,t=e.supers,n=t.length,r=e.superMeta,i=r.pos;if(n>i){var s=r.name,o=r.f,u;do{u=t[i][s];if("function"==typeof u&&(u=u._f||u)!==o)return r.pos=1+i,u.bind(this)}while(n>++i)}return null}function p(e){var t=this.__getters__;return t.hasOwnProperty(e)?t[e].apply(this):this[e]}function d(e,t){var n=this.__setters__;if(!u(e))return n.hasOwnProperty(e)?n[e].apply(this,i(arguments,1)):this[e]=t;for(var r in e){var s=e[r];n.hasOwnProperty(r)?n[e].call(this,s):this[r]=s}}function v(){var e=this.__meta||{},t=e.supers,n=t.length,r=e.superMeta,i=r.pos;if(n>i){var s=r.name,o=r.f,u;do{u=t[i][s];if("function"==typeof u&&(u=u._f||u)!==o)return r.pos=1+i,u.apply(this,arguments)}while(n>++i)}return null}function m(e,t){var n=function(){var r,i=this.__meta||{},s=i.superMeta;return i.superMeta={f:e,pos:0,name:t},r=e.apply(this,arguments),i.superMeta=s,r};return n._f=e,n}function g(e,t){var n=t.setters||{},r=e.__setters__,i=e.__getters__;for(var s in n)r.hasOwnProperty(s)||(r[s]=n[s]);n=t.getters||{};for(s in n)i.hasOwnProperty(s)||(i[s]=n[s]);for(var o in t)if(o!=="getters"&&o!=="setters"){var u=t[o];"function"==typeof u?e.hasOwnProperty(o)||(e[o]=m(v,o)):e[o]=u}}function y(){var e=i(arguments),t=e.length,n=this.prototype,r=n.__meta,s=this.__meta,o=n.__meta.bases,u=o.slice(),a=s.supers||[],f=r.supers||[];for(var l=0;l=0)b(o[u--],n,r);n.unshift(e)}}function w(e,t){var n=t.setters,r=e.__setters__,i=e.__getters__;if(n)for(var s in n)r[s]=n[s];n=t.getters||{};if(n)for(s in n)i[s]=n[s];for(s in t)if(s!="getters"&&s!="setters"){var o=t[s];if("function"==typeof o){var u=o.__meta||{};u.isConstructor?e[s]=o:e[s]=m(o,s)}else e[s]=o}}function E(e,t){return e&&t?e[t]=this:e.exports=e=this,this}function S(e){return N(this,e)}function x(e){r.prototype=e.prototype;var t=new r;return r.prototype=null,t}function T(e,r,i){var o={},a=[],f="declare"+ ++t,p=[],d=[],g=[],E=[],S={supers:g,unique:f,bases:p,superMeta:{f:null,pos:0,name:null}},T={supers:E,unique:f,bases:d,isConstructor:!0,superMeta:{f:null,pos:0,name:null}};u(r)&&!i&&(i=r,r=n),"function"==typeof r||s(r)?(a=s(r)?r:[r],r=a.shift(),e.__meta=T,o=x(r),o.__meta=S,o.__getters__=l({},o.__getters__||{}),o.__setters__=l({},o.__setters__||{}),e.__getters__=l({},e.__getters__||{}),e.__setters__=l({},e.__setters__||{}),b(r.prototype,g,p),b(r,E,d)):(e.__meta=T,o.__meta=S,o.__getters__=o.__getters__||{},o.__setters__=o.__setters__||{},e.__getters__=e.__getters__||{},e.__setters__=e.__setters__||{}),e.prototype=o;if(i){var N=S.proto=i.instance||{},C=T.proto=i.static||{};C.init=C.init||v,w(o,N),w(e,C),N.hasOwnProperty("constructor")?o.constructor=m(N.constructor,"constructor"):o.constructor=N.constructor=m(v,"constructor")}else S.proto={},T.proto={},e.init=m(v,"init"),o.constructor=m(v,"constructor");a.length&&y.apply(e,a),r&&l(e,l(l({},r),e)),o._super=e._super=c,o._getSuper=e._getSuper=h,o._static=e}function N(e,t){function n(){this.constructor.apply(this,arguments)}return T(n,e,t),n.init()||n}function C(e,t){function r(){return n||(this.constructor.apply(this,arguments),n=this),n}var n;return T(r,e,t),r.init()||r}var e=Array.prototype.slice,t=0,n,r=new Function,a=function(t){return Object.prototype.toString.call(t)==="[object Arguments]"};return a(arguments)||(a=function(t){return!!t&&!!t.hasOwnProperty("callee")}),n=N({instance:{get:p,set:d},"static":{get:p,set:d,mixin:y,extend:S,as:E}}),N.singleton=C,N}"undefined"!=typeof n?"undefined"!=typeof t&&t.exports&&(t.exports=e()):"function"==typeof define?define(e):this.declare=e()})()}),require.define("/node_modules/is-extended/package.json",function(e,t,n,r,i,s,o){t.exports={main:"index.js"}}),require.define("/node_modules/is-extended/index.js",function(e,t,n,r,i,s,o){(function(){"use strict";function r(e){function i(e,t){return t=t||0,n.call(e,t)}function s(e){var t=[];for(var n in e)e.hasOwnProperty(n)&&t.push(n);return t}function o(e,t){if(e===t)return!0;if(typeof Buffer!="undefined"&&Buffer.isBuffer(e)&&Buffer.isBuffer(t)){if(e.length!==t.length)return!1;for(var n=0;n=0;a--)if(i[a]!==u[a])return!1;for(a=i.length-1;a>=0;a--){r=i[a];if(!o(e[r],t[r]))return!1}}catch(f){return!1}return!0}function a(e){return typeof e=="function"}function f(e){var t;return e!==null&&e!==t&&typeof e=="object"}function l(e){var t=f(e);return t&&e.constructor===Object}function c(e){if(f(e)){for(var t in e)if(e.hasOwnProperty(t))return!1}else if(S(e)&&e==="")return!0;return!0}function h(e){return Object.prototype.toString.call(e)==="[object Boolean]"}function p(e){return e!==null&&e===t}function d(e){return!p(e)}function v(e){return p(e)||m(e)}function m(e){return e!==t&&e===null}function y(e,t){return a(t)?e instanceof t:!1}function b(e){return!v(e)&&e instanceof RegExp}function w(e){return Object.prototype.toString.call(e)==="[object Array]"}function E(e){return!v(e)&&typeof e=="object"&&e instanceof Date}function S(e){return!v(e)&&(typeof e=="string"||e instanceof String)}function x(e){return!v(e)&&(typeof e=="number"||e instanceof Number)}function T(e){return e===!0}function N(e){return e===!1}function C(e){return!m(e)}function k(e,t){return e==t}function L(e,t){return e!=t}function A(e,t){return e===t}function O(e,t){return e!==t}function M(e,t){if(w(t))for(var n=0,r=t.length;nt}function B(e,t){return e>=t}function j(e,t){return S(t)&&(t=new RegExp(t)),b(t)?t.test(""+e):!1}function F(e,t){return!j(e,t)}function I(e,t){return M(t,e)}function q(e,t){return!M(t,e)}function R(e,t,n){return w(e)&&e.length>n?k(e[n],t):!1}function U(e,t,n){return w(e)?!k(e[n],t):!1}function z(e,t){return r.call(e,t)}function W(e,t){return!z(e,t)}function X(e,t){return z(e,"length")?e.length===t:!1}function V(e,t){return z(e,"length")?e.length!==t:!1}function Q(e){J[e]=function(){this._testers.push($[e])}}function G(e){K[e]=function(){var n=i(arguments,1),r=$[e],s,o=!0;if(n.length<=r.length-1)throw new TypeError("A handler must be defined when calling using switch");s=n.pop(),h(s)&&(o=s,s=n.pop());if(!a(s))throw new TypeError("handler must be defined");this._cases.push(function(e){return r.apply($,e.concat(n))?[o,s.apply(this,e)]:[!1]})}}var t,n=Array.prototype.slice,r=Object.prototype.hasOwnProperty,g=function(t){return!v(t)&&Object.prototype.toString.call(t)==="[object Arguments]"};g(arguments)||(g=function(t){return!!t&&!!t.hasOwnProperty("callee")});var $={isFunction:a,isObject:f,isEmpty:c,isHash:l,isNumber:x,isString:S,isDate:E,isArray:w,isBoolean:h,isUndefined:p,isDefined:d,isUndefinedOrNull:v,isNull:m,isArguments:g,instanceOf:y,isRegExp:b,deepEqual:o,isTrue:T,isFalse:N,isNotNull:C,isEq:k,isNeq:L,isSeq:A,isSneq:O,isIn:M,isNotIn:_,isLt:D,isLte:P,isGt:H,isGte:B,isLike:j,isNotLike:F,contains:I,notContains:q,has:z,notHas:W,isLength:X,isNotLength:V,containsAt:R,notContainsAt:U},J={constructor:function(){this._testers=[]},noWrap:{tester:function(){var e=this._testers;return function(n){var r=!1;for(var i=0,s=e.length;i1)if(o[1]||o[0])return o[1]}if(!r&&t)return t.apply(this,s)}}}};for(var Y in $)$.hasOwnProperty(Y)&&(G(Y),Q(Y));var Z=e.define($).expose($);return Z.tester=e.define(J),Z.switcher=e.define(K),Z}"undefined"!=typeof n?"undefined"!=typeof t&&t.exports&&(t.exports=r(e("extended"))):"function"==typeof define?define(["require"],function(e){return r(e("extended"))}):this.isExtended=r(this.extended)}).call(this)}),require.define("/node_modules/array-extended/package.json",function(e,t,n,r,i,s,o){t.exports={main:"index.js"}}),require.define("/node_modules/array-extended/index.js",function(e,t,n,r,i,s,o){(function(){"use strict";function i(e,t){return t=t||0,r.call(e,t)}function s(e,t){function b(e,t){return M(t,function(t,n){return r(n)||(n=[n]),n.unshift(e),t.unshift(n),t},[])}function w(e,t,n){var r=[];for(var i=0;i>>0;if(s===0)return-1;var f=0;arguments.length>2&&(f=Number(arguments[2]),f!==f?f=0:f!==0&&f!==Infinity&&f!==-Infinity&&(f=(f>0||-1)*o(u(f))));if(f>=s)return-1;var l=f>=0?f:a(s-u(f),0);for(;l>>0;if(s===0)return-1;var a=s;arguments.length>2&&(a=Number(arguments[2]),a!==a?a=0:a!==0&&a!==1/0&&a!==-1/0&&(a=(a>0||-1)*o(u(a))));var l=a>=0?f(a,s-1):s-u(a);for(;l>=0;l--)if(l in i&&i[l]===t)return l;return-1}function N(e,t,n){if(e&&m&&m===e.filter)return e.filter(t,n);if(!r(e)||typeof t!="function")throw new TypeError;var i=Object(e),s=i.length>>>0,o=[];for(var u=0;u>>0;for(var o=0;o>>0;for(var o=0;o>>0,o=[];for(var u=0;u2;if(e&&d&&d===e.reduce)return i?e.reduce(t,n):e.reduce(t);if(!r(e)||typeof t!="function")throw new TypeError;var s=0,o=e.length>>0;if(arguments.length<3){if(o===0)throw new TypeError("Array length is 0 and no second argument");n=e[0],s=1}else n=arguments[2];while(s2;if(e&&v&&v===e.reduceRight)return i?e.reduceRight(t,n):e.reduceRight(t);if(!r(e)||typeof t!="function")throw new TypeError;var s=Object(e),o=s.length>>>0;if(o===0&&arguments.length===2)throw new TypeError;var u=o-1;if(arguments.length>=3)n=arguments[2];else do if(u in e){n=e[u--];break}while(!0);while(u>=0)u in s&&(n=t.call(undefined,n,s[u],u,s)),u--;return n}function _(e){var n=[];if(e!==null){var s=i(arguments);if(s.length===1)if(r(e))n=e;else if(t.isHash(e))for(var o in e)e.hasOwnProperty(o)&&n.push([o,e[o]]);else n.push(e);else C(s,function(e){n=n.concat(_(e))})}return n}function D(e){return e=e||[],e.length?O(e,function(e,t){return e+t}):0}function P(e){e=e||[];if(e.length){var n=D(e);if(t.isNumber(n))return n/e.length;throw new Error("Cannot average an array of non numbers.")}return 0}function H(e,t){return S(e,t)}function B(e,t){return S(e,t)[0]}function j(e,t){return S(e,t)[e.length-1]}function F(e){var t=e,n=Y(i(arguments,1));return r(e)&&(t=N(e,function(e){return x(n,e)===-1})),t}function I(e){var t=[];if(r(e))for(var n=0,i=e.length;n0?(n.push(n.shift()),t--):(n.unshift(n.pop()),t++),R(n,t)):n}function U(e,t){var n=[];if(r(e)){var i=e.slice(0);typeof t!="number"&&(t=e.length),t?t<=e.length&&(n=O(e,function(e,n,r){var s;return t>1?s=w(n,R(i,r).slice(1),t):s=[[n]],e.concat(s)},[])):n=[[]]}return n}function z(){var e=[],n=i(arguments);if(n.length>1){var s=n.shift();r(s)&&(e=O(s,function(e,i,s){var o=[i];for(var u=0;u1){for(var n=0,r=t.length;n1?t=n:t=n[0];if(r(t)){var e=t.shift();for(var s=0,o=t.length;s1?t=n:t=_(e),O(t,function(e,t){return e.concat(t)},[])}function Z(e,t){t=t.split(".");var n=e.slice(0);return C(t,function(e){var t=e.match(/(\w+)\(\)$/);n=A(n,function(n){return t?n[t[1]]():n[e]})}),n}function et(e,t,r){return r=i(arguments,2),A(e,function(e){var i=n(t)?e[t]:t;return i.apply(e,r)})}var n=t.isString,r=Array.isArray||t.isArray,s=t.isDate,o=Math.floor,u=Math.abs,a=Math.max,f=Math.min,l=Array.prototype,c=l.indexOf,h=l.forEach,p=l.map,d=l.reduce,v=l.reduceRight,m=l.filter,g=l.every,y=l.some,S=function(){var e=function(e,t){return k(e,t)},t=function(e,t){return e-t},i=function(e,t){return e.getTime()-t.getTime()};return function(u,a){var f=[];return r(u)&&(f=u.slice(),a?typeof a=="function"?f.sort(a):f.sort(function(e,t){var r=e[a],i=t[a];return n(r)&&n(i)?r>i?1:rn)if(r){var o=e.length;s=e.substring(o-n,o)}else s=e.substring(0,n)}else s=i(""+s,n);return s}function s(e,n,r){if(!t.isArray(e)||typeof n!="function")throw new TypeError;var i=Object(e),s=i.length>>>0;for(var o=0;o-1&&(n=t.substring(++r,t.indexOf(")"))),n}function T(e,t){return e.replace(/([a-z])\1*/ig,function(e){var n,r=e.charAt(0),i=e.length,s="0?",o="0{0,2}";if(r==="y")n="\\d{2,4}";else if(r==="M")n=i>2?"\\S+?":"1[0-2]|"+s+"[1-9]";else if(r==="D")n="[12][0-9][0-9]|3[0-5][0-9]|36[0-6]|"+o+"[1-9][0-9]|"+s+"[1-9]";else if(r==="d")n="3[01]|[12]\\d|"+s+"[1-9]";else if(r==="w")n="[1-4][0-9]|5[0-3]|"+s+"[1-9]";else if(r==="E")n="\\S+";else if(r==="h")n="1[0-2]|"+s+"[1-9]";else if(r==="K")n="1[01]|"+s+"\\d";else if(r==="H")n="1\\d|2[0-3]|"+s+"\\d";else if(r==="k")n="1\\d|2[0-4]|"+s+"[1-9]";else if(r==="m"||r==="s")n="[0-5]\\d";else if(r==="S")n="\\d{"+i+"}";else if(r==="a"){var u="AM",a="PM";n=u+"|"+a,u!==u.toLowerCase()&&(n+="|"+u.toLowerCase()),a!==a.toLowerCase()&&(n+="|"+a.toLowerCase()),n=n.replace(/\./g,"\\.")}else r==="v"||r==="z"||r==="Z"||r==="G"||r==="q"||r==="Q"?n=".*":n=r===" "?"\\s*":r+"*";return t&&t.push(e),"("+n+")"}).replace(/[\xa0 ]/g,"[\\s\\xa0]")}function k(e){C[e+"sFromNow"]=function(t){return N.add(new Date,e,t)},C[e+"sAgo"]=function(t){return N.add(new Date,e,-t)}}var o=function(){function r(e,t,r){return e=e.replace(/s$/,""),n.hasOwnProperty(e)?n[e](t,r):[r,"UTC"+e.charAt(0).toUpperCase()+e.substring(1)+"s",!1]}function s(e,n,r,s){return e=e.replace(/s$/,""),t(i[e](n,r,s))}var e=Math.floor,t=Math.round,n={day:function(t,n){return[n,"Date",!1]},weekday:function(t,n){var r,i,s=n%5,o=t.getDay(),u=0;s?(r=s,i=parseInt(n/5,10)):(r=n>0?5:-5,i=n>0?(n-5)/5:(n+5)/5),o===6&&n>0?u=1:o===0&&n<0&&(u=-1);var a=o+r;if(a===0||a===6)u=n>0?2:-2;return[7*i+r+u,"Date",!1]},year:function(t,n){return[n,"FullYear",!0]},week:function(t,n){return[n*7,"Date",!1]},quarter:function(t,n){return[n*3,"Month",!0]},month:function(t,n){return[n,"Month",!0]}},i={quarter:function(n,r,i){var s=r.getFullYear()-n.getFullYear(),o=n[i?"getUTCMonth":"getMonth"](),u=r[i?"getUTCMonth":"getMonth"](),a=e(o/3)+1,f=e(u/3)+1;return f+=s*4,f-a},weekday:function(t,n,r){var i=s("day",t,n,r),o,u=i%7;if(u===0)i=s("week",t,n,r)*5;else{var a=0,f=t[r?"getUTCDay":"getDay"](),l=n[r?"getUTCDay":"getDay"]();o=parseInt(i/7,10);var c=new Date(+t);c.setDate(c[r?"getUTCDate":"getDate"]()+o*7);var h=c[r?"getUTCDay":"getDay"]();if(i>0){if(f===6||l===6)a=-1;else if(f===0)a=0;else if(l===0||h+u>5)a=-2}else if(i<0)if(f===6)a=0;else if(f===0||l===0)a=1;else if(l===6||h+u<0)a=2;i+=a,i-=o*2}return i},year:function(e,t){return t.getFullYear()-e.getFullYear()},month:function(e,t,n){var r=e[n?"getUTCMonth":"getMonth"](),i=t[n?"getUTCMonth":"getMonth"]();return i-r+(t.getFullYear()-e.getFullYear())*12},week:function(e,n,r){return t(s("day",e,n,r)/7)},day:function(e,t){return 1.1574074074074074e-8*(t.getTime()-e.getTime())},hour:function(e,t){return 2.7777777777777776e-7*(t.getTime()-e.getTime())},minute:function(e,t){return 16666666666666667e-21*(t.getTime()-e.getTime())},second:function(e,t){return.001*(t.getTime()-e.getTime())},millisecond:function(e,t){return t.getTime()-e.getTime()}};return{addTransform:r,differenceTransform:s}}(),u=o.addTransform,a=o.differenceTransform,f=Math.floor,l=Math.round,c=Math.min,h=Math.pow,p=Math.ceil,d=Math.abs,v=["January","February","March","April","May","June","July","August","September","October","November","December"],m=["Jan.","Feb.","Mar.","Apr.","May.","Jun.","Jul.","Aug.","Sep.","Oct.","Nov.","Dec."],g=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],y=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],b=["Before Christ","Anno Domini"],w=["BC","AD"],N={getDaysInMonth:function(e){var t=e.getMonth(),n=[31,28,31,30,31,30,31,31,30,31,30,31];return t===1&&N.isLeapYear(e)?29:n[t]},isLeapYear:function(e,t){var n=e[t?"getUTCFullYear":"getFullYear"]();return n%400===0||n%4===0&&n%100!==0},isWeekend:function(e,t){var n=(e||new Date)[t?"getUTCDay":"getDay"]();return n===0||n===6},getTimezoneName:x,compare:function(e,t,n){return e=new Date(+e),t=new Date(+(t||new Date)),n==="date"?(e.setHours(0,0,0,0),t.setHours(0,0,0,0)):n==="time"&&(e.setFullYear(0,0,0),t.setFullYear(0,0,0)),e>t?1:e1&&(O===2?k=i(""+k,2,!0):L=!0);else if(A.toUpperCase()==="Q")k=p((o+1)/3),L=!0;else if(A==="M")O<3?(k=o+1,L=!0):k=(O===3?m:v)[o];else if(A==="w")k=S(e,0,n),L=!0;else if(A==="D")k=E(e,n),L=!0;else if(A==="E")O<3?(k=u+1,L=!0):k=(O===-3?y:g)[u];else if(A==="a")k=c<12?"AM":"PM";else if(A==="h")k=c%12||12,L=!0;else if(A==="K")k=c%12,L=!0;else if(A==="k")k=c||24,L=!0;else if(A==="S")k=l(C*h(10,O-3)),L=!0;else if(A==="z"||A==="v"||A==="Z"){k=x(e),(A==="z"||A==="v")&&!k&&(O=4);if(!k||A==="Z"){var M=e.getTimezoneOffset(),_=[M>=0?"-":"+",r(f(d(M)/60),2,"0"),r(d(M)%60,2,"0")];O===4&&(_.splice(0,0,"GMT"),_.splice(3,0,":")),k=_.join("")}}else k=t;return L&&(k=r(k,O,"0")),k})}},C={},L=["year","month","day","hour","minute","second"];for(var A=0,O=L.length;A2){var p=v,d,b;s===3&&(p=m),e=e.replace(".","").toLowerCase();var w=!1;for(d=0,b=p.length;dS.length)return!1}else e=x}else if(o==="D"||o==="d")o==="D"&&(a[1]=0),a[2]=e;else if(o==="a"){var T="am",N="pm",C=/\./g;e=e.replace(C,"").toLowerCase(),f=e===N?"p":e===T?"a":""}else o==="k"||o==="h"||o==="H"||o==="K"?(o==="k"&&+e===24&&(e=0),a[3]=e):o==="m"?a[4]=e:o==="s"?a[5]=e:o==="S"&&(a[6]=e)}return!0});if(l){var h=+a[3];f==="p"&&h<12?a[3]=h+12:f==="a"&&h===12&&(a[3]=0);var p=new Date(a[0],a[1],a[2],a[3],a[4],a[5],a[6]),d=n.indexOf(r,"d")!==-1,b=n.indexOf(r,"M")!==-1,w=a[1],E=a[2],S=p.getMonth(),x=p.getDate();return b&&S>w||d&&x>E?null:p}return null}},_=e.define(t.isDate,N).define(t.isString,M).define(t.isNumber,C);for(A in N)N.hasOwnProperty(A)&&(_[A]=N[A]);for(A in M)M.hasOwnProperty(A)&&(_[A]=M[A]);for(A in C)C.hasOwnProperty(A)&&(_[A]=C[A]);return _}"undefined"!=typeof n?"undefined"!=typeof t&&t.exports&&(t.exports=r(e("extended"),e("is-extended"),e("array-extended"))):"function"==typeof define?define(["require"],function(e){return r(e("extended"),e("is-extended"),e("array-extended"))}):this.dateExtended=r(this.extended,this.isExtended,this.arrayExtended)}).call(this)}),require.define("/node_modules/object-extended/package.json",function(e,t,n,r,i,s,o){t.exports={main:"index.js"}}),require.define("/node_modules/object-extended/index.js",function(e,t,n,r,i,s,o){(function(){"use strict";function r(e,t){function i(e,t){var n,r;for(n in t)if(t.hasOwnProperty(n)){r=t[n];if(!(n in e)||e[n]!==r)e[n]=r}return e}function s(e,t){var i,o,u;for(i in t)t.hasOwnProperty(i)&&(o=t[i],u=e[i],n(u,o)||(r(u)&&r(o)?e[i]=s(u,o):r(o)?e[i]=s({},o):e[i]=o));return e}function o(e){e||(e={});for(var t=1,n=arguments.length;t0?"+":"")+r),f&&(f=parseInt(f,10),r.lengthn)if(r){var s=e.length;i=e.substring(s-n,s)}else i=e.substring(0,n)}else i=m(""+i,n);return i}function g(e,a){if(a instanceof Array){var f=0,p=a.length;return e.replace(o,function(e,t,i){var s,o;if(f0?n=e.replace(/\s+/g,"").split(t):n.push(e)),n}function b(e,t){var n=[];if(t)for(var r=0;r=0;s--)r=p(r,s===i)}return r}var n=t.isArray,r=t.isObject,i=t.isString,s=t.isFunction,o=Array.prototype.slice;return e.define(r,{bind:a,bindAll:c,bindIgnore:l,curry:function(e,t,n){return d(t,n,e)}}).define(s,{bind:function(e,t){return a.apply(this,[t,e].concat(u(arguments,2)))},bindIgnore:function(e,t){return l.apply(this,[t,e].concat(u(arguments,2)))},partial:h,applyFirst:f,curry:function(e,t,n){return d(t,e,n)},noWrap:{f:function(){return this.value()}}}).define(i,{bind:function(e,t){return a(t,e)},bindIgnore:function(e,t){return l(t,e)},partial:h,applyFirst:f,curry:function(e,t,n){return d(t,e,n)}}).expose({bind:a,bindAll:c,bindIgnore:l,partial:h,applyFirst:f,curry:d})}"undefined"!=typeof n?"undefined"!=typeof t&&t.exports&&(t.exports=r(e("extended"),e("is-extended"))):"function"==typeof define?define(["require"],function(e){return r(e("extended"),e("is-extended"))}):this.functionExtended=r(this.extended,this.isExtended)}).call(this)}),require.define("/node_modules/ht/package.json",function(e,t,n,r,i,s,o){t.exports={main:"index.js"}}),require.define("/node_modules/ht/index.js",function(e,t,n,r,i,s,o){(function(){"use strict";function r(e){var t=function(e){return typeof e=="string"?e:typeof e=="object"?e.hashCode?e.hashCode():""+e:""+e},n=e.declare({instance:{constructor:function(){this.__entries=[],this.__keys=[],this.__values=[]},pushValue:function(e,t){return this.__keys.push(e),this.__values.push(t),this.__entries.push({key:e,value:t}),t},remove:function(e){var t=null,n=this.__entries,r,i=this.__keys,s=this.__values,o=n.length-1;for(;o>=0;o--)if(!!(r=n[o])&&r.key===e)return n.splice(o,1),i.splice(o,1),s.splice(o,1),r.value;return t},set:function(e,t){var n=null,r=this.__entries,i=this.__values,s=r.length-1;for(;s>=0;s--){var o=r[s];if(o&&e===o.key){i[s]=t,o.value=t,n=t;break}}return n||r.push({key:e,value:t}),n},find:function(e){var t=null,n=this.__entries,r,i=n.length-1;for(;i>=0;i--){r=n[i];if(r&&e===r.key){t=r.value;break}}return t},getEntrySet:function(){return this.__entries},getKeys:function(){return this.__keys},getValues:function(e){return this.__values}}});return e.declare({instance:{constructor:function(){this.__map={}},entrySet:function(){var e=[],t=this.__map;for(var n in t)t.hasOwnProperty(n)&&(e=e.concat(t[n].getEntrySet()));return e},put:function(e,r){var i=t(e),s=null;return(s=this.__map[i])||(s=this.__map[i]=new n),s.pushValue(e,r),r},remove:function(e){var n=t(e),r=null,i=this.__map[n];return i&&(r=i.remove(e)),r},get:function(e){var n=t(e),r=null,i;return!(i=this.__map[n])||(r=i.find(e)),r},set:function(e,r){var i=t(e),s=null,o=null,u=this.__map;return(o=u[i])?s=o.set(e,r):s=(u[i]=new n).pushValue(e,r),s},contains:function(e){var n=t(e),r=!1,i=null;return!(i=this.__map[n])||(r=!!i.find(e)),r},concat:function(e){if(e instanceof this._static){var t=new this._static,n=e.entrySet().concat(this.entrySet());for(var r=n.length-1;r>=0;r--){var i=n[r];t.put(i.key,i.value)}return t}throw new TypeError("When joining hashtables the joining arg must be a HashTable")},filter:function(t,n){var r=this.entrySet(),i=new this._static;r=e.filter(r,t,n);for(var s=r.length-1;s>=0;s--){var o=r[s];i.put(o.key,o.value)}return i},forEach:function(t,n){var r=this.entrySet();e.forEach(r,t,n)},every:function(t,n){var r=this.entrySet();return e.every(r,t,n)},map:function(t,n){var r=this.entrySet();return e.map(r,t,n)},some:function(t,n){var r=this.entrySet();return e.some(r,t,n)},reduce:function(t,n){var r=this.entrySet();return e.reduce(r,t,n)},reduceRight:function(t,n){var r=this.entrySet();return e.reduceRight(r,t,n)},clear:function(){this.__map={}},keys:function(){var e=[],t=this.__map;for(var n in t)e=e.concat(t[n].getKeys());return e},values:function(){var e=[],t=this.__map;for(var n in t)e=e.concat(t[n].getValues());return e},isEmpty:function(){return this.keys().length===0}}})}"undefined"!=typeof n?"undefined"!=typeof t&&t.exports&&(t.exports=r(e("extended")().register("declare",e("declare.js")).register(e("is-extended")).register(e("array-extended")))):"function"==typeof define?define(["extended","declare","is-extended","array-extended"],function(e,t,n,i){return r(e().register("declare",t).register(n).register(i))}):this.Ht=r(this.extended().register("declare",this.declare).register(this.isExtended).register(this.arrayExtended))}).call(this)}),require.define("/node_modules/leafy/package.json",function(e,t,n,r,i,s,o){t.exports={main:"index.js"}}),require.define("/node_modules/leafy/index.js",function(e,t,n,r,i,s,o){(function(){"use strict";function r(e){function t(e,t){var n=0;return e>t?1:e1&&(n=u(n,o),i.done=!0))}return n},l=function(t,n,r,i){var s,o,u,f;if(t){o=i(n,t.data);if(o===0){var c=t.left,h=t.right;if(!c||!h)return s=c?"left":"right",u=t[s],u;var p=c;while((h=p.right)!==null)p=h;t.data=p.data,n=p.data}s=i(t.data,n)===-1?"right":"left",t[s]=l(t[s],n,r,i);if(!r.done){f=t.balance+=s==="left"?1:-1;var d=e(f);d===1?r.done=!0:d>1&&(t=a(t,s,r))}}return t};return r.extend({instance:{insert:function(e){var t={done:!1};this.__root=f(this.__root,e,t,this.compare)},remove:function(e){this.__root=l(this.__root,e,{done:!1},this.compare)},__printNode:function(e,t){var r=[];e?(this.__printNode(e.right,t+1),r.push(n(" ",t)),r.push(e.data+":"+e.balance+"\n"),console.log(r.join("")),this.__printNode(e.left,t+1)):(r.push(n(" ",t)),r.push("~"),console.log(r.join("")))}}})}(),s=function(){function t(t,n){return{data:t,level:n,left:e,right:e}}function i(e){if(e.level!==0&&e.left.level===e.level){var t=e.left;e.left=t.right,t.right=e,e=t}return e}function s(e){if(e.level!==0&&e.right.right.level===e.level){var t=e.right;e.right=t.left,t.left=e,e=t,e.level++}return e}function o(n,r,u){if(n===e)n=t(r,1);else{var a=u(r,n.data)===-1?"left":"right";n[a]=o(n[a],r,u),n=i(n),n=s(n)}return n}var e={level:0,data:null},u=function(t,n,r){var o,a;if(t!==e){var f=r(n,t.data);if(f===0){o=t.left,a=t.right;if(o!==e&&a!==e){var l=o;while(l.right!==e)l=l.right;t.data=l.data,t.left=u(o,l.data,r)}else t=t[o===e?"right":"left"]}else{var c=f===-1?"left":"right";t[c]=u(t[c],n,r)}}if(t!==e){var h=t.level,p=t.left.level,d=t.right.level;if(p--t.level&&(t.right.level=t.level),t=i(t),t=s(t)}return t};return r.extend({instance:{isEmpty:function(){return this.__root===e||this._super(arguments)},insert:function(t){this.__root||(this.__root=e),this.__root=o(this.__root,t,this.compare)},remove:function(e){this.__root=u(this.__root,e,this.compare)},traverseWithCondition:function(t){var n=!0;return t!==e?this._super(arguments):n},traverse:function(t){t!==e&&this._super(arguments)},contains:function(){return this.__root!==e?this._super(arguments):!1},__printNode:function(e,t){var r=[];!e||!e.data?(r.push(n(" ",t)),r.push("~"),console.log(r.join(""))):(this.__printNode(e.right,t+1),r.push(n(" ",t)),r.push(e.data+":"+e.level+"\n"),console.log(r.join("")),this.__printNode(e.left,t+1))}}})}(),o=r.extend({instance:{insert:function(e){if(!this.__root)return this.__root={data:e,parent:null,left:null,right:null};var t=this.compare,n=this.__root;while(n!==null){var r=t(e,n.data);if(!r)return;var i=r===-1?"left":"right",s=n[i];if(!s)return n[i]={data:e,parent:n,left:null,right:null};n=s}},remove:function(e){if(this.__root!==null){var t={right:this.__root},n=t,r,i=null,s="right";while(n[s]!==null){r=n,n=n[s];var o=this.compare(e,n.data);o||(i=n),s=o===-1?"left":"right"}i!==null&&(i.data=n.data,r[r.right===n?"right":"left"]=n[n.left===null?"right":"left"]),this.__root=t.right}}}}),u=function(){var e="RED",t="BLACK",i=function(e){return e!==null&&e.red},s=function(e){return{data:e,red:!0,left:null,right:null}},o=function(e,t,n){if(!e)return s(t);var r=n(t,e.data);if(r){var f=r===-1?"left":"right",l=f==="left"?"right":"left";e[f]=o(e[f],t,n);var c=e[f];if(i(c)){var h=e[l];i(h)?(e.red=!0,c.red=!1,h.red=!1):i(c[f])?e=u(e,l):i(c[l])&&(e=a(e,l))}}return e},u=function(e,t){var n=t==="left"?"right":"left",r=e[n];return e[n]=r[t],r[t]=e,e.red=!0,r.red=!1,r},a=function(e,t){var n=t==="left"?"right":"left";return e[n]=u(e[n],n),u(e,t)},f=function(e,t,n,r){if(!e)n.done=!0;else{var s;if(r(t,e.data)===0){if(!e.left||!e.right){var o=e[e.left?"left":"right"];return i(e)?n.done=!0:i(o)&&(o.red=!1,n.done=!0),o}var u=e.right,a;while(u.left!==null)a=u,u=u.left;a&&(a.left=null),e.data=u.data,t=u.data}s=r(t,e.data)===-1?"left":"right",e[s]=f(e[s],t,n,r),n.done||(e=l(e,s,n))}return e},l=function(e,t,n){var r=t==="left"?"right":"left",s=e,o=s[r];i(o)&&(e=u(e,t),o=s[r]);if(o!==null)if(!i(o.left)&&!i(o.right))i(s)&&(n.done=!0),s.red=0,o.red=1;else{var f=s.red,l=e===s;s=(i(o[r])?u:a)(s,t),s.red=f,s.left.red=s.right.red=0,l?e=s:e[t]=s,n.done=!0}return e};return r.extend({instance:{insert:function(e){this.__root=o(this.__root,e,this.compare),this.__root.red=!1},remove:function(e){var t={done:!1},n=f(this.__root,e,t,this.compare);return n!==null&&(n.red=0),this.__root=n,e},__printNode:function(r,i){var s=[];r?(this.__printNode(r.right,i+1),s.push(n(" ",i)),s.push((r.red?e:t)+":"+r.data+"\n"),console.log(s.join("")),this.__printNode(r.left,i+1)):(s.push(n(" ",i)),s.push("~"),console.log(s.join("")))}}})}();return{Tree:r,AVLTree:i,AnderssonTree:s,BinaryTree:o,RedBlackTree:u,IN_ORDER:r.IN_ORDER,PRE_ORDER:r.PRE_ORDER,POST_ORDER:r.POST_ORDER,REVERSE_ORDER:r.REVERSE_ORDER}}"undefined"!=typeof n?"undefined"!=typeof t&&t.exports&&(t.exports=r(e("extended")().register("declare",e("declare.js")).register(e("is-extended")).register(e("array-extended")).register(e("string-extended")))):"function"==typeof define?define(["extended","declare.js","is-extended","array-extended","string-extended"],function(e,t,n,i,s){return r(e().register("declare",t).register(n).register(i).register(s))}):this.leafy=r(this.extended().register("declare",this.declare).register(this.isExtended).register(this.arrayExtended).register(this.stringExtended))}).call(this)}),require.define("fs",function(e,t,n,r,i,s,o){}),require.define("/lib/nodes/index.js",function(e,t,n,r,i,s,o){"use strict";var u=e("../extended"),a=u.forEach,f=u.some,l=u.declare,c=e("../pattern.js"),h=c.ObjectPattern,p=c.FromPattern,d=c.FromNotPattern,v=c.NotPattern,m=c.CompositePattern,g=c.InitialFactPattern,y=e("../constraint"),b=y.HashConstraint,w=y.ReferenceConstraint,E=e("./aliasNode"),S=e("./equalityNode"),x=e("./joinNode"),T=e("./notNode"),N=e("./fromNode"),C=e("./fromNotNode"),k=e("./leftAdapterNode"),L=e("./rightAdapterNode"),A=e("./typeNode"),O=e("./terminalNode"),M=e("./propertyNode");l({instance:{constructor:function(e,t){this.terminalNodes=[],this.joinNodes=[],this.nodes=[],this.constraints=[],this.typeNodes=[],this.__ruleCount=0,this.bucket={counter:0,recency:0},this.agendaTree=t,this.workingMemory=e},assertRule:function(e){var t=new O(this.bucket,this.__ruleCount++,e,this.agendaTree);this.__addToNetwork(e,e.pattern,t),this.__mergeJoinNodes(),this.terminalNodes.push(t)},resetCounter:function(){this.bucket.counter=0},incrementCounter:function(){this.bucket.counter++},assertFact:function(e){var t=this.typeNodes,n=t.length-1;for(;n>=0;n--)t[n].assert(e)},retractFact:function(e){var t=this.typeNodes,n=t.length-1;for(;n>=0;n--)t[n].retract(e)},containsRule:function(e){return f(this.terminalNodes,function(t){return t.rule.name===e})},dispose:function(){var e=this.typeNodes,t=e.length-1;for(;t>=0;t--)e[t].dispose()},__mergeJoinNodes:function(){var e=this.joinNodes;for(var t=0;t=0;n--){var r=t[n];if(e.equal(r))return r}return t.push(e),e},__createTypeNode:function(e,t){var n=new A(t.get("constraints")[0]),r=this.typeNodes,i=r.length-1;for(;i>=0;i--){var s=r[i];if(n.equal(s))return s}return r.push(n),n},__createEqualityNode:function(e,t){return this.__checkEqual(new S(t)).addRule(e)},__createPropertyNode:function(e,t){return this.__checkEqual(new M(t)).addRule(e)},__createAliasNode:function(e,t){return this.__checkEqual(new E(t)).addRule(e)},__createAdapterNode:function(e,t){return(t==="left"?new k:new L).addRule(e)},__createJoinNode:function(e,t,n,r){var i;t.rightPattern instanceof v?i=new T:t.rightPattern instanceof d?i=new C(t.rightPattern,this.workingMemory):t.rightPattern instanceof p?i=new N(t.rightPattern,this.workingMemory):(i=new x,this.joinNodes.push(i));var s=i;if(n instanceof x){var o=this.__createAdapterNode(e,r);s.addOutNode(o,t),s=o}return s.addOutNode(n,t),i.addRule(e)},__addToNetwork:function(e,t,n,r){if(t instanceof h){if((t instanceof v||t instanceof p||t instanceof d)&&(!r||r==="left"))return this.__createBetaNode(e,new m(new g,t),n,r);this.__createAlphaNode(e,t,n,r)}else t instanceof m&&this.__createBetaNode(e,t,n,r)},__createBetaNode:function(e,t,n,r){var i=this.__createJoinNode(e,t,n,r);return this.__addToNetwork(e,t.rightPattern,i,"right"),this.__addToNetwork(e,t.leftPattern,i,"left"),n.addParentNode(i),i},__createAlphaNode:function(e,t,n,r){var i,s;if(!(t instanceof p)){var o=t.get("constraints");i=this.__createTypeNode(e,t);var u=this.__createAliasNode(e,t);i.addOutNode(u,t),u.addParentNode(i),s=u;var a=o.length-1;for(;a>0;a--){var f=o[a],l;if(f instanceof b)l=this.__createPropertyNode(e,f);else{if(f instanceof w){n.constraint.addConstraint(f);continue}l=this.__createEqualityNode(e,f)}s.addOutNode(l,t),l.addParentNode(s),s=l}if(n instanceof x){var c=this.__createAdapterNode(e,r);c.addParentNode(s),s.addOutNode(c,t),s=c}return n.addParentNode(s),s.addOutNode(n,t),i}},print:function(){a(this.terminalNodes,function(e){e.print(" ")})}}}).as(n,"RootNode")}),require.define("/lib/pattern.js",function(e,t,n,r,i,s,o){"use strict";var u=e("./extended"),a=u.has,f=u.isEmpty,l=u.merge,c=u.forEach,h=u.declare,p=e("./constraintMatcher"),d=e("./constraint"),v=d.EqualityConstraint,m=h({}),g=m.extend({instance:{constructor:function(e,t,n,r,i){i=i||{},this.type=e,this.alias=t,this.conditions=n,this.pattern=i.pattern;var s=[new d.ObjectConstraint(e)],o=p.toConstraints(n,l({alias:t},i));if(o.length)s=s.concat(o);else{var u=new d.TrueConstraint;s.push(u)}if(r&&!f(r)){var a=new d.HashConstraint(r);s.push(a)}c(s,function(e){e.set("alias",t)}),this.constraints=s},getSpecificity:function(){var e=this.constraints,t=0;for(var n=0,r=e.length;n",this.parse(t)].join(" ")},lte:function(e,t){return[this.parse(e),"<=",this.parse(t)].join(" ")},gte:function(e,t){return[this.parse(e),">=",this.parse(t)].join(" ")},like:function(e,t){return[this.parse(t),".test(",this.parse(e),")"].join("")},notLike:function(e,t){return["!",this.parse(t),".test(",this.parse(e),")"].join("")},eq:function(e,t){return[this.parse(e),"===",this.parse(t)].join(" ")},neq:function(e,t){return[this.parse(e),"!==",this.parse(t)].join(" ")},"in":function(e,t){return["(indexOf(",this.parse(t),",",this.parse(e),")) != -1"].join("")},notIn:function(e,t){return["(indexOf(",this.parse(t),",",this.parse(e),")) == -1"].join("")},arguments:function(e,t){var n=[];return e&&n.push(this.parse(e)),t&&n.push(this.parse(t)),n.join(",")},array:function(e){var t=[];return e?(t=this.parse(e),a(t)?t:["[",t,"]"].join("")):["[",t.join(","),"]"].join("")},"function":function(e,t){var n=this.parse(t);return[e,"(",n,")"].join("")},string:function(e){return"'"+e+"'"},number:function(e){return e},"boolean":function(e){return e},regexp:function(e){return e},identifier:function(e){return e},"null":function(){return"null"}},y=n.toJs=function(e,t){var n=g.parse(e);t=t||{};var r=g.getIdentifiers(e),i="var indexOf = definedFuncs.indexOf;"+c(r,function(e){var n=["var ",e," = "];return m.hasOwnProperty(e)?n.push("definedFuncs['",e,"']"):t.hasOwnProperty(e)?n.push("scope['",e,"']"):n.push("'",e,"' in fact ? fact['",e,"'] : hash['",e,"']"),n.push(";"),n.join("")}).join("")+" return !!("+n+");",s=new Function("fact, hash, definedFuncs, scope",i);return function(e,n){return s(e,n,m,t)}};n.getMatcher=function(e,t){return y(e,t)},n.toConstraints=function(e,t){return g.toConstraints(e,t)},n.equal=function(e,t){return g.equal(e,t)},n.getIdentifiers=function(e){return g.getIdentifiers(e)}}),require.define("/lib/constraint.js",function(e,t,n,r,i,s,o){"use strict";var u=e("./extended"),a=u.hash,f=u.merge,l=a.keys,c=u.forEach,h=u.instanceOf,p=u.filter,d=u.declare,v,m=d({instance:{constructor:function(t,n){v||(v=e("./constraintMatcher")),this.type=t,this.constraint=n},assert:function(){throw new Error("not implemented")},equal:function(e){return h(e,this._static)&&this.get("alias")===e.get("alias")&&u.deepEqual(this.constraint,e.constraint)},getters:{variables:function(){return[this.get("alias")]}}}});m.extend({instance:{constructor:function(e){this._super(["object",e])},assert:function(e){return e instanceof this.constraint||e.constructor===this.constraint},equal:function(e){return h(e,this._static)&&this.constraint===e.constraint}}}).as(n,"ObjectConstraint"),m.extend({instance:{constructor:function(e,t){this._super(["equality",e]),t=t||{},this.pattern=t.pattern,this._matcher=v.getMatcher(e,t.scope||{})},assert:function(e){return this._matcher(e)}}}).as(n,"EqualityConstraint"),m.extend({instance:{constructor:function(){this._super(["equality",[!0]])},equal:function(e){return h(e,this._static)&&this.get("alias")===e.get("alias")},assert:function(){return!0}}}).as(n,"TrueConstraint"),m.extend({instance:{constructor:function(e,t){this.cache={},this._super(["reference",e]),t=t||{},this.values=[],this.pattern=t.pattern,this._options=t,this._matcher=v.getMatcher(e,t.scope||{})},assert:function(e){try{return this._matcher(e)}catch(t){throw new Error("Error with evaluating pattern "+this.pattern+" "+t.message)}},merge:function(e,t){var n=this;return e instanceof this._static&&(n=new this._static([this.constraint,e.constraint,"and"],f({},this._options,this._options)),n._alias=this._alias||e._alias,n.vars=this.vars.concat(e.vars)),n},equal:function(e){return h(e,this._static)&&u.deepEqual(this.constraint,e.constraint)},getters:{variables:function(){return this.vars},alias:function(){return this._alias}},setters:{alias:function(e){this._alias=e,this.vars=p(v.getIdentifiers(this.constraint),function(t){return t!==e})}}}}).as(n,"ReferenceConstraint"),m.extend({instance:{constructor:function(e){this._super(["hash",e])},equal:function(e){return u.instanceOf(e,this._static)&&this.get("alias")===e.get("alias")&&u.deepEqual(this.constraint,e.constraint)},assert:function(){return!0},getters:{variables:function(){return this.constraint}}}}).as(n,"HashConstraint"),m.extend({instance:{constructor:function(e,t){this.type="from",this.prop=e,this.constraints=t},equal:function(e){return u.instanceOf(e,this._static)&&this.get("alias")===e.get("alias")&&u.deepEqual(this.constraints,e.constraints)},assert:function(){return!0},getters:{variables:function(){return this.constraint}}}}).as(n,"FromConstraint")}),require.define("/lib/nodes/aliasNode.js",function(e,t,n,r,i,s,o){var u=e("./alphaNode");u.extend({instance:{constructor:function(){this._super(arguments),this.alias=this.constraint.get("alias")},toString:function(){return"AliasNode"+this.__count},assert:function(e){return this.__propagate("assert",e.set(this.alias,e.fact.object))},retract:function(e){this.propagateRetract(e.fact)},equal:function(e){return e instanceof this._static&&this.alias===e.alias}}}).as(t)}),require.define("/lib/nodes/alphaNode.js",function(e,t,n,r,i,s,o){"use strict";var u=e("./node");u.extend({instance:{constructor:function(e){this._super([]),this.constraint=e},toString:function(){return"AlphaNode "+this.__count},equal:function(e){return this.constraint.equal(e.constraint)}}}).as(t)}),require.define("/lib/nodes/node.js",function(e,t,n,r,i,s,o){var u=e("../extended"),a=u.forEach,f=u.indexOf,l=u.intersect,c=u.declare,h=u.HashTable,p=e("../context"),d=0;c({instance:{constructor:function(){this.nodes=new h,this.rules=[],this.parentNodes=[],this.__count=d++,this.__entrySet=[]},addRule:function(e){return f(this.rules,e)===-1&&this.rules.push(e),this},merge:function(e){e.nodes.forEach(function(t){var n=t.value,r=t.key;for(var i=0,s=n.length;i=0;i--)s=r[i],o=s.key,u=s.value,t.paths?(a=l(u,t.paths)).length&&o[e](new p(t.fact,a,t.match)):o[e](t)},dispose:function(e){this.propagateDispose(e)},retract:function(e){this.propagateRetract(e)},propagateDispose:function(e,t){t=t||this.nodes;var n=this.__entrySet,r=n.length-1;for(;r>=0;r--){var i=n[r],s=i.key;s.dispose(e)}},propagateAssert:function(e,t){this.__propagate("assert",e,t||this.nodes)},propagateRetract:function(e,t){this.__propagate("retract",e,t||this.nodes)},assert:function(e){this.propagateAssert(e)},propagateModify:function(e,t){this.__propagate("modify",e,t||this.nodes)}}}).as(t)}),require.define("/lib/context.js",function(e,t,n,r,i,s,o){"use strict";var u=e("./extended"),a=u.isBoolean,f=u.isDefined,l=u.declare,c=u.merge,h=u.union,p=u.map,d=l({instance:{constructor:function(e){e=e||{},this.variables=[],this.facts=[],this.factIds=[],this.factHash=e.factHash||{},this.recency=[],this.constraints=[],this.isMatch=!0,this.hashCode="";if(e instanceof this._static)this.isMatch=e.isMatch,this.facts=this.facts.concat(e.facts),this.factIds=this.factIds.concat(e.factIds).sort(),this.hashCode=this.factIds.join(":"),this.factHash=c(this.factHash,e.factHash),this.recency=h(this.recency,e.recency);else{var t=e;t&&(this.facts.push(t),this.factIds.push(t.id),this.recency.push(t.recency),this.hashCode+=this.factIds.join(":"))}},merge:function(e){var t=new this._static;return t.isMatch=e.isMatch,t.facts=this.facts.concat(e.facts),t.factIds=this.factIds.concat(e.factIds).sort(),t.hashCode=t.factIds.join(":"),t.factHash=c({},this.factHash,e.factHash),t.recency=h(this.recency,e.recency),t}}}),v=l({instance:{match:null,factHash:null,fact:null,hashCode:null,paths:null,constructor:function(e,t,n){this.fact=e,this.paths=t||null;var r=this.match=n||new d(e);this.factHash=r.factHash,this.hashCode=r.hashCode,this.factIds=r.factIds},set:function(e,t){return this.factHash[e]=t,this},isMatch:function(e){return a(e)?(this.match.isMatch=e,this):this.match.isMatch},mergeMatch:function(e){var t=this.match=this.match.merge(e);return this.factHash=t.factHash,this.hashCode=t.hashCode,this.factIds=t.factIds,this},clone:function(e,t,n){return new v(e||this.fact,null,n||this.match)}}}).as(t)}),require.define("/lib/nodes/equalityNode.js",function(e,t,n,r,i,s,o){var u=e("./alphaNode");u.extend({instance:{constructor:function(){this._super(arguments)},assert:function(e){this.constraint.assert(e.factHash)&&this.__propagate("assert",e)},toString:function(){return"EqualityNode"+this.__count}}}).as(t)}),require.define("/lib/nodes/joinNode.js",function(e,t,n,r,i,s,o){var u=e("../extended"),a=u.hash.values,f=u.indexOf,l=e("./node"),c=e("../context"),h=e("./joinReferenceNode");l.extend({instance:{constructor:function(){this._super([]),this.constraint=new h,this.leftMemory={},this.rightMemory={},this.leftTuples=[],this.rightTuples=[]},dispose:function(){this.leftMemory={},this.rightMemory={}},disposeLeft:function(e){this.leftMemory={},this.propagateDispose(e)},disposeRight:function(e){this.rightMemory={},this.propagateDispose(e)},hashCode:function(){return"JoinNode "+this.__count},toString:function(){return"JoinNode "+this.__count},retractResolve:function(e){var t=a(this.leftMemory),n=t.length-1,r=this.leftTuples;for(;n>=0;n--){var i=t[n],s=i.length-1,o;for(;s>=0;s--){o=i[s];if(this.resolve(o.match,e))return r.splice(f(r,o),1),i.splice(s,1),this._propagateRetractResolve(e)}}this._propagateRetractResolve(e)},retractLeft:function(e){var t=this.leftMemory[e.id],n=this.leftTuples,r,i;if(t){for(r=0,i=t.length;r=0;n--)(i=r.setRightContext(t[n]).match()).isMatch&&this.__propagate("assert",e.clone(null,null,i));r.clearContexts()},assertRight:function(e){var t=e.fact;this.rightMemory[t.id]=e,this.rightTuples.push(e);var n=this.leftTuples,r=n.length-1,i=this.constraint,s;i.setRightContext(e);for(;r>=0;r--)(s=i.setLeftContext(n[r]).match()).isMatch&&this.__propagate("assert",e.clone(null,null,s));i.clearContexts()},_propagateRetractResolve:function(e){this.__propagate("retractResolve",e)},__addToLeftMemory:function(e){var t=e.fact,n=this.leftMemory[t.id];return n||(n=[],this.leftMemory[t.id]=n),this.leftTuples.push(e),n.push(e),this}}}).as(t)}),require.define("/lib/nodes/joinReferenceNode.js",function(e,t,n,r,i,s,o){var u=e("./node");u.extend({instance:{constructor:function(){this._super(arguments),this.__fh={},this.__lc=this.__rc=null,this.__variables=[],this.__varLength=0},setLeftContext:function(e){this.__lc=e;var t=e.match,n=t.factHash,r=this.__fh,i,s=this.__variables;for(var o=0,u=this.__varLength;o=0;n--)r=t[n],i.setLeftContext(r).isMatch()&&(this._propagateRetractResolve(r.match),this.__removeFromLeftMemory(r),r.blocker=e,e.blocking.push(r),this.__addToLeftTupleMemory(r));i.clearContexts()},__removeFromLeftMemory:function(e){var t=this.leftMemory[e.fact.id],n,r=this.leftTuples;for(var i=0,s=t.length;i=0;t--){var n=e[t],r=n.key,i=n.value;r.dispose({paths:i})}},__propagate:function(e,t,n){var r=this.__entrySet,i=r.length-1;for(;i>=0;i--){var s=r[i],o=s.key,u=s.value;o[e](new a(t,u))}}}}).as(t)}),require.define("/lib/nodes/terminalNode.js",function(e,t,n,r,i,s,o){var u=e("./node"),a=e("../extended"),f=a.sum,l=a.bind,c=a.removeDuplicates;u.extend({instance:{constructor:function(e,t,n,r){this._super([]),this.resolve=l(this,this.resolve),this.rule=n,this.index=t,this.name=this.rule.name,this.agenda=r,this.bucket=e,r.register(this)},__assertModify:function(e){var t=e.match;t.recency.sort(function(e,t){return e-t}).reverse(),t.facts=c(t.facts);if(t.isMatch){var n=this.rule,r=this.bucket;this.agenda.insert(this,{rule:n,index:this.index,name:n.name,recency:f(t.recency),match:t,counter:r.counter})}},assert:function(e){this.__assertModify(e)},modify:function(e){this.__assertModify(e)},retract:function(e){this.agenda.removeByFact(this,e)},retractRight:function(e){this.agenda.removeByFact(this,e)},retractLeft:function(e){this.agenda.removeByFact(this,e)},assertLeft:function(e){this.__assertModify(e)},assertRight:function(e){this.__assertModify(e)},retractResolve:function(e){var t=this.resolve;this.agenda.retract(this,function(n){return t(n.match,e)})},toString:function(){return"TerminalNode "+this.rule.name}}}).as(t)}),require.define("/lib/nodes/propertyNode.js",function(e,t,n,r,i,s,o){var u=e("./alphaNode"),a=e("../context"),f=e("../extended");u.extend({instance:{constructor:function(){this._super(arguments),this.alias=this.constraint.get("alias"),this.varLength=(this.variables=f(this.constraint.get("variables")).toArray().value()).length},assert:function(e){var t=new a(e.fact,e.paths),n=this.variables,r=e.fact.object,i;t.set(this.alias,r);for(var s=0,o=this.varLength;s0&&this._events[e].length>n&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),console.trace())}this._events[e].push(t)}else this._events[e]=[this._events[e],t];return this},u.prototype.on=u.prototype.addListener,u.prototype.once=function(e,t){var n=this;return n.on(e,function r(){n.removeListener(e,r),t.apply(this,arguments)}),this},u.prototype.removeListener=function(e,t){if("function"!=typeof t)throw new Error("removeListener only takes instances of Function");if(!this._events||!this._events[e])return this;var n=this._events[e];if(a(n)){var r=f(n,t);if(r<0)return this;n.splice(r,1),n.length==0&&delete this._events[e]}else this._events[e]===t&&delete this._events[e];return this},u.prototype.removeAllListeners=function(e){return e&&this._events&&this._events[e]&&(this._events[e]=null),this},u.prototype.listeners=function(e){return this._events||(this._events={}),this._events[e]||(this._events[e]=[]),a(this._events[e])||(this._events[e]=[this._events[e]]),this._events[e]}}),require.define("/lib/rule.js",function(e,t,n,r,i,s,o){"use strict";function L(e,t,n,r){a(t)?(r=n,n=t):t=t||{};var i=u.every(n,function(e){return a(e)});i&&n.length===1&&(n=n[0],i=!1);var s=[],o=t.scope||{};n.scope=o;if(i){var f=function(e,t){c[t]?u(c).forEach(function(t){t.push(e)}):(c[t]=t===0?[]:c[t-1].slice(),t!==0&&c[t].pop(),c[t].push(e))},l=n.length,c=[],h;for(var p=0;p":18,"<=":19,">=":20,EQUALITY_EXPRESSION:21,"==":22,"!=":23,"=~":24,"!=~":25,IN_EXPRESSION:26,"in":27,ARRAY_EXPRESSION:28,notIn:29,OBJECT_EXPRESSION:30,AND_EXPRESSION:31,"&&":32,OR_EXPRESSION:33,"||":34,ARGUMENT_LIST:35,",":36,FUNCTION:37,IDENTIFIER:38,"(":39,")":40,IDENTIFIER_EXPRESSION:41,".":42,STRING_EXPRESSION:43,STRING:44,NUMBER_EXPRESSION:45,NUMBER:46,REGEXP_EXPRESSION:47,REGEXP:48,BOOLEAN_EXPRESSION:49,BOOLEAN:50,NULL_EXPRESSION:51,NULL:52,"[":53,"]":54,$accept:0,$end:1},terminals_:{2:"error",5:"EOF",8:"-",10:"*",11:"/",13:"+",15:"^",17:"<",18:">",19:"<=",20:">=",22:"==",23:"!=",24:"=~",25:"!=~",27:"in",29:"notIn",32:"&&",34:"||",36:",",38:"IDENTIFIER",39:"(",40:")",42:".",44:"STRING",46:"NUMBER",48:"REGEXP",50:"BOOLEAN",52:"NULL",53:"[",54:"]"},productions_:[0,[3,2],[6,1],[6,2],[9,1],[9,3],[9,3],[12,1],[12,3],[12,3],[14,1],[14,3],[16,1],[16,3],[16,3],[16,3],[16,3],[21,1],[21,3],[21,3],[21,3],[21,3],[26,1],[26,3],[26,3],[26,3],[26,3],[31,1],[31,3],[33,1],[33,3],[35,1],[35,3],[37,3],[37,4],[30,1],[30,3],[30,3],[41,1],[43,1],[45,1],[47,1],[49,1],[51,1],[28,2],[28,3],[7,1],[7,1],[7,1],[7,1],[7,1],[7,1],[7,1],[7,1],[7,3],[4,1]],performAction:function(t,n,r,i,s,o,u){var a=o.length-1;switch(s){case 1:return o[a-1];case 3:this.$=[o[a],null,"unminus"];break;case 5:this.$=[o[a-2],o[a],"mult"];break;case 6:this.$=[o[a-2],o[a],"div"];break;case 8:this.$=[o[a-2],o[a],"plus"];break;case 9:this.$=[o[a-2],o[a],"minus"];break;case 11:this.$=[o[a-2],o[a],"pow"];break;case 13:this.$=[o[a-2],o[a],"lt"];break;case 14:this.$=[o[a-2],o[a],"gt"];break;case 15:this.$=[o[a-2],o[a],"lte"];break;case 16:this.$=[o[a-2],o[a],"gte"];break;case 18:this.$=[o[a-2],o[a],"eq"];break;case 19:this.$=[o[a-2],o[a],"neq"];break;case 20:this.$=[o[a-2],o[a],"like"];break;case 21:this.$=[o[a-2],o[a],"notLike"];break;case 23:this.$=[o[a-2],o[a],"in"];break;case 24:this.$=[o[a-2],o[a],"notIn"];break;case 25:this.$=[o[a-2],o[a],"in"];break;case 26:this.$=[o[a-2],o[a],"notIn"];break;case 28:this.$=[o[a-2],o[a],"and"];break;case 30:this.$=[o[a-2],o[a],"or"];break;case 32:this.$=[o[a-2],o[a],"arguments"];break;case 33:this.$=[o[a-2],[null,null,"arguments"],"function"];break;case 34:this.$=[o[a-3],o[a-1],"function"];break;case 36:this.$=[o[a-2],o[a],"prop"];break;case 37:this.$=[o[a-2],o[a],"prop"];break;case 38:this.$=[String(t),null,"identifier"];break;case 39:this.$=[String(t.replace(/^'|'$/g,"")),null,"string"];break;case 40:this.$=[Number(t),null,"number"];break;case 41:this.$=[RegExp(t.replace(/^\/|\/$/g,"")),null,"regexp"];break;case 42:this.$=[t=="true",null,"boolean"];break;case 43:this.$=[null,null,"null"];break;case 44:this.$=[null,null,"array"];break;case 45:this.$=[o[a-1],null,"array"];break;case 54:this.$=[o[a-1],null,"composite"]}},table:[{3:1,4:2,6:29,7:7,8:[1,30],9:28,12:27,14:18,16:8,21:6,26:5,28:15,30:16,31:4,33:3,37:14,38:[1,24],39:[1,17],41:26,43:9,44:[1,19],45:10,46:[1,20],47:11,48:[1,21],49:12,50:[1,22],51:13,52:[1,23],53:[1,25]},{1:[3]},{5:[1,31]},{5:[2,55],34:[1,32],40:[2,55]},{5:[2,29],32:[1,33],34:[2,29],40:[2,29]},{5:[2,27],32:[2,27],34:[2,27],40:[2,27]},{5:[2,22],22:[1,34],23:[1,35],24:[1,36],25:[1,37],32:[2,22],34:[2,22],40:[2,22]},{5:[2,2],8:[2,2],10:[2,2],11:[2,2],13:[2,2],15:[2,2],17:[2,2],18:[2,2],19:[2,2],20:[2,2],22:[2,2],23:[2,2],24:[2,2],25:[2,2],27:[1,38],29:[1,39],32:[2,2],34:[2,2],40:[2,2]},{5:[2,17],17:[1,40],18:[1,41],19:[1,42],20:[1,43],22:[2,17],23:[2,17],24:[2,17],25:[2,17],32:[2,17],34:[2,17],40:[2,17]},{5:[2,46],8:[2,46],10:[2,46],11:[2,46],13:[2,46],15:[2,46],17:[2,46],18:[2,46],19:[2,46],20:[2,46],22:[2,46],23:[2,46],24:[2,46],25:[2,46],27:[2,46],29:[2,46],32:[2,46],34:[2,46],36:[2,46],40:[2,46],54:[2,46]},{5:[2,47],8:[2,47],10:[2,47],11:[2,47],13:[2,47],15:[2,47],17:[2,47],18:[2,47],19:[2,47],20:[2,47],22:[2,47],23:[2,47],24:[2,47],25:[2,47],27:[2,47],29:[2,47],32:[2,47],34:[2,47],36:[2,47],40:[2,47],54:[2,47]},{5:[2,48],8:[2,48],10:[2,48],11:[2,48],13:[2,48],15:[2,48],17:[2,48],18:[2,48],19:[2,48],20:[2,48],22:[2,48],23:[2,48],24:[2,48],25:[2,48],27:[2,48],29:[2,48],32:[2,48],34:[2,48],36:[2,48],40:[2,48],54:[2,48]},{5:[2,49],8:[2,49],10:[2,49],11:[2,49],13:[2,49],15:[2,49],17:[2,49],18:[2,49],19:[2,49],20:[2,49],22:[2,49],23:[2,49],24:[2,49],25:[2,49],27:[2,49],29:[2,49],32:[2,49],34:[2,49],36:[2,49],40:[2,49],54:[2,49]},{5:[2,50],8:[2,50],10:[2,50],11:[2,50],13:[2,50],15:[2,50],17:[2,50],18:[2,50],19:[2,50],20:[2,50],22:[2,50],23:[2,50],24:[2,50],25:[2,50],27:[2,50],29:[2,50],32:[2,50],34:[2,50],36:[2,50],40:[2,50],54:[2,50]},{5:[2,51],8:[2,51],10:[2,51],11:[2,51],13:[2,51],15:[2,51],17:[2,51],18:[2,51],19:[2,51],20:[2,51],22:[2,51],23:[2,51],24:[2,51],25:[2,51],27:[2,51],29:[2,51],32:[2,51],34:[2,51],36:[2,51],40:[2,51],54:[2,51]},{5:[2,52],8:[2,52],10:[2,52],11:[2,52],13:[2,52],15:[2,52],17:[2,52],18:[2,52],19:[2,52],20:[2,52],22:[2,52],23:[2,52],24:[2,52],25:[2,52],27:[2,52],29:[2,52],32:[2,52],34:[2,52],36:[2,52],40:[2,52],54:[2,52]},{5:[2,53],8:[2,53],10:[2,53],11:[2,53],13:[2,53],15:[2,53],17:[2,53],18:[2,53],19:[2,53],20:[2,53],22:[2,53],23:[2,53],24:[2,53],25:[2,53],27:[2,53],29:[2,53],32:[2,53],34:[2,53],36:[2,53],40:[2,53],42:[1,44],54:[2,53]},{4:45,6:29,7:7,8:[1,30],9:28,12:27,14:18,16:8,21:6,26:5,28:15,30:16,31:4,33:3,37:14,38:[1,24],39:[1,17],41:26,43:9,44:[1,19],45:10,46:[1,20],47:11,48:[1,21],49:12,50:[1,22],51:13,52:[1,23],53:[1,25]},{5:[2,12],15:[1,46],17:[2,12],18:[2,12],19:[2,12],20:[2,12],22:[2,12],23:[2,12],24:[2,12],25:[2,12],32:[2,12],34:[2,12],40:[2,12]},{5:[2,39],8:[2,39],10:[2,39],11:[2,39],13:[2,39],15:[2,39],17:[2,39],18:[2,39],19:[2,39],20:[2,39],22:[2,39],23:[2,39],24:[2,39],25:[2,39],27:[2,39],29:[2,39],32:[2,39],34:[2,39],36:[2,39],40:[2,39],54:[2,39]},{5:[2,40],8:[2,40],10:[2,40],11:[2,40],13:[2,40],15:[2,40],17:[2,40],18:[2,40],19:[2,40],20:[2,40],22:[2,40],23:[2,40],24:[2,40],25:[2,40],27:[2,40],29:[2,40],32:[2,40],34:[2,40],36:[2,40],40:[2,40],54:[2,40]},{5:[2,41],8:[2,41],10:[2,41],11:[2,41],13:[2,41],15:[2,41],17:[2,41],18:[2,41],19:[2,41],20:[2,41],22:[2,41],23:[2,41],24:[2,41],25:[2,41],27:[2,41],29:[2,41],32:[2,41],34:[2,41],36:[2,41],40:[2,41],54:[2,41]},{5:[2,42],8:[2,42],10:[2,42],11:[2,42],13:[2,42],15:[2,42],17:[2,42],18:[2,42],19:[2,42],20:[2,42],22:[2,42],23:[2,42],24:[2,42],25:[2,42],27:[2,42],29:[2,42],32:[2,42],34:[2,42],36:[2,42],40:[2,42],54:[2,42]},{5:[2,43],8:[2,43],10:[2,43],11:[2,43],13:[2,43],15:[2,43],17:[2,43],18:[2,43],19:[2,43],20:[2,43],22:[2,43],23:[2,43],24:[2,43],25:[2,43],27:[2,43],29:[2,43],32:[2,43],34:[2,43],36:[2,43],40:[2,43],54:[2,43]},{5:[2,38],8:[2,38],10:[2,38],11:[2,38],13:[2,38],15:[2,38],17:[2,38],18:[2,38],19:[2,38],20:[2,38],22:[2,38],23:[2,38],24:[2,38],25:[2,38],27:[2,38],29:[2,38],32:[2,38],34:[2,38],36:[2,38],39:[1,47],40:[2,38],42:[2,38],54:[2,38]},{7:50,28:15,30:16,35:49,37:14,38:[1,24],39:[1,17],41:26,43:9,44:[1,19],45:10,46:[1,20],47:11,48:[1,21],49:12,50:[1,22],51:13,52:[1,23],53:[1,25],54:[1,48]},{5:[2,35],8:[2,35],10:[2,35],11:[2,35],13:[2,35],15:[2,35],17:[2,35],18:[2,35],19:[2,35],20:[2,35],22:[2,35],23:[2,35],24:[2,35],25:[2,35],27:[2,35],29:[2,35],32:[2,35],34:[2,35],36:[2,35],40:[2,35],42:[2,35],54:[2,35]},{5:[2,10],8:[1,52],13:[1,51],15:[2,10],17:[2,10],18:[2,10],19:[2,10],20:[2,10],22:[2,10],23:[2,10],24:[2,10],25:[2,10],32:[2,10],34:[2,10],40:[2,10]},{5:[2,7],8:[2,7],10:[1,53],11:[1,54],13:[2,7],15:[2,7],17:[2,7],18:[2,7],19:[2,7],20:[2,7],22:[2,7],23:[2,7],24:[2,7],25:[2,7],32:[2,7],34:[2,7],40:[2,7]},{5:[2,4],8:[2,4],10:[2,4],11:[2,4],13:[2,4],15:[2,4],17:[2,4],18:[2,4],19:[2,4],20:[2,4],22:[2,4],23:[2,4],24:[2,4],25:[2,4],32:[2,4],34:[2,4],40:[2,4]},{6:55,7:56,8:[1,30],28:15,30:16,37:14,38:[1,24],39:[1,17],41:26,43:9,44:[1,19],45:10,46:[1,20],47:11,48:[1,21],49:12,50:[1,22],51:13,52:[1,23],53:[1,25]},{1:[2,1]},{6:29,7:7,8:[1,30],9:28,12:27,14:18,16:8,21:6,26:5,28:15,30:16,31:57,37:14,38:[1,24],39:[1,17],41:26,43:9,44:[1,19],45:10,46:[1,20],47:11,48:[1,21],49:12,50:[1,22],51:13,52:[1,23],53:[1,25]},{6:29,7:7,8:[1,30],9:28,12:27,14:18,16:8,21:6,26:58,28:15,30:16,37:14,38:[1,24],39:[1,17],41:26,43:9,44:[1,19],45:10,46:[1,20],47:11,48:[1,21],49:12,50:[1,22],51:13,52:[1,23],53:[1,25]},{6:29,7:56,8:[1,30],9:28,12:27,14:18,16:59,28:15,30:16,37:14,38:[1,24],39:[1,17],41:26,43:9,44:[1,19],45:10,46:[1,20],47:11,48:[1,21],49:12,50:[1,22],51:13,52:[1,23],53:[1,25]},{6:29,7:56,8:[1,30],9:28,12:27,14:18,16:60,28:15,30:16,37:14,38:[1,24],39:[1,17],41:26,43:9,44:[1,19],45:10,46:[1,20],47:11,48:[1,21],49:12,50:[1,22],51:13,52:[1,23],53:[1,25]},{6:29,7:56,8:[1,30],9:28,12:27,14:18,16:61,28:15,30:16,37:14,38:[1,24],39:[1,17],41:26,43:9,44:[1,19],45:10,46:[1,20],47:11,48:[1,21],49:12,50:[1,22],51:13,52:[1,23],53:[1,25]},{6:29,7:56,8:[1,30],9:28,12:27,14:18,16:62,28:15,30:16,37:14,38:[1,24],39:[1,17],41:26,43:9,44:[1,19],45:10,46:[1,20],47:11,48:[1,21],49:12,50:[1,22],51:13,52:[1,23],53:[1,25]},{28:63,30:64,38:[1,65],41:26,53:[1,25]},{28:66,30:67,38:[1,65],41:26,53:[1,25]},{6:29,7:56,8:[1,30],9:28,12:27,14:68,28:15,30:16,37:14,38:[1,24],39:[1,17],41:26,43:9,44:[1,19],45:10,46:[1,20],47:11,48:[1,21],49:12,50:[1,22],51:13,52:[1,23],53:[1,25]},{6:29,7:56,8:[1,30],9:28,12:27,14:69,28:15,30:16,37:14,38:[1,24],39:[1,17],41:26,43:9,44:[1,19],45:10,46:[1,20],47:11,48:[1,21],49:12,50:[1,22],51:13,52:[1,23],53:[1,25]},{6:29,7:56,8:[1,30],9:28,12:27,14:70,28:15,30:16,37:14,38:[1,24],39:[1,17],41:26,43:9,44:[1,19],45:10,46:[1,20],47:11,48:[1,21],49:12,50:[1,22],51:13,52:[1,23],53:[1,25]},{6:29,7:56,8:[1,30],9:28,12:27,14:71,28:15,30:16,37:14,38:[1,24],39:[1,17],41:26,43:9,44:[1,19],45:10,46:[1,20],47:11,48:[1,21],49:12,50:[1,22],51:13,52:[1,23],53:[1,25]},{37:73,38:[1,24],41:72},{40:[1,74]},{6:29,7:56,8:[1,30],9:28,12:75,28:15,30:16,37:14,38:[1,24],39:[1,17],41:26,43:9,44:[1,19],45:10,46:[1,20],47:11,48:[1,21],49:12,50:[1,22],51:13,52:[1,23],53:[1,25]},{7:50,28:15,30:16,35:77,37:14,38:[1,24],39:[1,17],40:[1,76],41:26,43:9,44:[1,19],45:10,46:[1,20],47:11,48:[1,21],49:12,50:[1,22],51:13,52:[1,23],53:[1,25]},{5:[2,44],8:[2,44],10:[2,44],11:[2,44],13:[2,44],15:[2,44],17:[2,44],18:[2,44],19:[2,44],20:[2,44],22:[2,44],23:[2,44],24:[2,44],25:[2,44],27:[2,44],29:[2,44],32:[2,44],34:[2,44],36:[2,44],40:[2,44],54:[2,44]},{36:[1,79],54:[1,78]},{36:[2,31],40:[2,31],54:[2,31]},{6:29,7:56,8:[1,30],9:80,28:15,30:16,37:14,38:[1,24],39:[1,17],41:26,43:9,44:[1,19],45:10,46:[1,20],47:11,48:[1,21],49:12,50:[1,22],51:13,52:[1,23],53:[1,25]},{6:29,7:56,8:[1,30],9:81,28:15,30:16,37:14,38:[1,24],39:[1,17],41:26,43:9,44:[1,19],45:10,46:[1,20],47:11,48:[1,21],49:12,50:[1,22],51:13,52:[1,23],53:[1,25]},{6:82,7:56,8:[1,30],28:15,30:16,37:14,38:[1,24],39:[1,17],41:26,43:9,44:[1,19],45:10,46:[1,20],47:11,48:[1,21],49:12,50:[1,22],51:13,52:[1,23],53:[1,25]},{6:83,7:56,8:[1,30],28:15,30:16,37:14,38:[1,24],39:[1,17],41:26,43:9,44:[1,19],45:10,46:[1,20],47:11,48:[1,21],49:12,50:[1,22],51:13,52:[1,23],53:[1,25]},{5:[2,3],8:[2,3],10:[2,3],11:[2,3],13:[2,3],15:[2,3],17:[2,3],18:[2,3],19:[2,3],20:[2,3],22:[2,3],23:[2,3],24:[2,3],25:[2,3],32:[2,3],34:[2,3],40:[2,3]},{5:[2,2],8:[2,2],10:[2,2],11:[2,2],13:[2,2],15:[2,2],17:[2,2],18:[2,2],19:[2,2],20:[2,2],22:[2,2],23:[2,2],24:[2,2],25:[2,2],32:[2,2],34:[2,2],40:[2,2]},{5:[2,30],32:[1,33],34:[2,30],40:[2,30]},{5:[2,28],32:[2,28],34:[2,28],40:[2,28]},{5:[2,18],17:[1,40],18:[1,41],19:[1,42],20:[1,43],22:[2,18],23:[2,18],24:[2,18],25:[2,18],32:[2,18],34:[2,18],40:[2,18]},{5:[2,19],17:[1,40],18:[1,41],19:[1,42],20:[1,43],22:[2,19],23:[2,19],24:[2,19],25:[2,19],32:[2,19],34:[2,19],40:[2,19]},{5:[2,20],17:[1,40],18:[1,41],19:[1,42],20:[1,43],22:[2,20],23:[2,20],24:[2,20],25:[2,20],32:[2,20],34:[2,20],40:[2,20]},{5:[2,21],17:[1,40],18:[1,41],19:[1,42],20:[1,43],22:[2,21],23:[2,21],24:[2,21],25:[2,21],32:[2,21],34:[2,21],40:[2,21]},{5:[2,23],32:[2,23],34:[2,23],40:[2,23]},{5:[2,25],32:[2,25],34:[2,25],40:[2,25],42:[1,44]},{5:[2,38],32:[2,38],34:[2,38],40:[2,38],42:[2,38]},{5:[2,24],32:[2,24],34:[2,24],40:[2,24]},{5:[2,26],32:[2,26],34:[2,26],40:[2,26],42:[1,44]},{5:[2,13],15:[1,46],17:[2,13],18:[2,13],19:[2,13],20:[2,13],22:[2,13],23:[2,13],24:[2,13],25:[2,13],32:[2,13],34:[2,13],40:[2,13]},{5:[2,14],15:[1,46],17:[2,14],18:[2,14],19:[2,14],20:[2,14],22:[2,14],23:[2,14],24:[2,14],25:[2,14],32:[2,14],34:[2,14],40:[2,14]},{5:[2,15],15:[1,46],17:[2,15],18:[2,15],19:[2,15],20:[2,15],22:[2,15],23:[2,15],24:[2,15],25:[2,15],32:[2,15],34:[2,15],40:[2,15]},{5:[2,16],15:[1,46],17:[2,16],18:[2,16],19:[2,16],20:[2,16],22:[2,16],23:[2,16],24:[2,16],25:[2,16],32:[2,16],34:[2,16],40:[2,16]},{5:[2,36],8:[2,36],10:[2,36],11:[2,36],13:[2,36],15:[2,36],17:[2,36],18:[2,36],19:[2,36],20:[2,36],22:[2,36],23:[2,36],24:[2,36],25:[2,36],27:[2,36],29:[2,36],32:[2,36],34:[2,36],36:[2,36],40:[2,36],42:[2,36],54:[2,36]},{5:[2,37],8:[2,37],10:[2,37],11:[2,37],13:[2,37],15:[2,37],17:[2,37],18:[2,37],19:[2,37],20:[2,37],22:[2,37],23:[2,37],24:[2,37],25:[2,37],27:[2,37],29:[2,37],32:[2,37],34:[2,37],36:[2,37],40:[2,37],42:[2,37],54:[2,37]},{5:[2,54],8:[2,54],10:[2,54],11:[2,54],13:[2,54],15:[2,54],17:[2,54],18:[2,54],19:[2,54],20:[2,54],22:[2,54],23:[2,54],24:[2,54],25:[2,54],27:[2,54],29:[2,54],32:[2,54],34:[2,54],36:[2,54],40:[2,54],54:[2,54]},{5:[2,11],8:[1,52],13:[1,51],15:[2,11],17:[2,11],18:[2,11],19:[2,11],20:[2,11],22:[2,11],23:[2,11],24:[2,11],25:[2,11],32:[2,11],34:[2,11],40:[2,11]},{5:[2,33],8:[2,33],10:[2,33],11:[2,33],13:[2,33],15:[2,33],17:[2,33],18:[2,33],19:[2,33],20:[2,33],22:[2,33],23:[2,33],24:[2,33],25:[2,33],27:[2,33],29:[2,33],32:[2,33],34:[2,33],36:[2,33],40:[2,33],42:[2,33],54:[2,33]},{36:[1,79],40:[1,84]},{5:[2,45],8:[2,45],10:[2,45],11:[2,45],13:[2,45],15:[2,45],17:[2,45],18:[2,45],19:[2,45],20:[2,45],22:[2,45],23:[2,45],24:[2,45],25:[2,45],27:[2,45],29:[2,45],32:[2,45],34:[2,45],36:[2,45],40:[2,45],54:[2,45]},{7:85,28:15,30:16,37:14,38:[1,24],39:[1,17],41:26,43:9,44:[1,19],45:10,46:[1,20],47:11,48:[1,21],49:12,50:[1,22],51:13,52:[1,23],53:[1,25]},{5:[2,8],8:[2,8],10:[1,53],11:[1,54],13:[2,8],15:[2,8],17:[2,8],18:[2,8],19:[2,8],20:[2,8],22:[2,8],23:[2,8],24:[2,8],25:[2,8],32:[2,8],34:[2,8],40:[2,8]},{5:[2,9],8:[2,9],10:[1,53],11:[1,54],13:[2,9],15:[2,9],17:[2,9],18:[2,9],19:[2,9],20:[2,9],22:[2,9],23:[2,9],24:[2,9],25:[2,9],32:[2,9],34:[2,9],40:[2,9]},{5:[2,5],8:[2,5],10:[2,5],11:[2,5],13:[2,5],15:[2,5],17:[2,5],18:[2,5],19:[2,5],20:[2,5],22:[2,5],23:[2,5],24:[2,5],25:[2,5],32:[2,5],34:[2,5],40:[2,5]},{5:[2,6],8:[2,6],10:[2,6],11:[2,6],13:[2,6],15:[2,6],17:[2,6],18:[2,6],19:[2,6],20:[2,6],22:[2,6],23:[2,6],24:[2,6],25:[2,6],32:[2,6],34:[2,6],40:[2,6]},{5:[2,34],8:[2,34],10:[2,34],11:[2,34],13:[2,34],15:[2,34],17:[2,34],18:[2,34],19:[2,34],20:[2,34],22:[2,34],23:[2,34],24:[2,34],25:[2,34],27:[2,34],29:[2,34],32:[2,34],34:[2,34],36:[2,34],40:[2,34],42:[2,34],54:[2,34]},{36:[2,32],40:[2,32],54:[2,32]}],defaultActions:{31:[2,1]},parseError:function(t,n){throw new Error(t)},parse:function(t){function v(e){r.length=r.length-2*e,i.length=i.length-e,s.length=s.length-e}function m(){var e;return e=n.lexer.lex()||1,typeof e!="number"&&(e=n.symbols_[e]||e),e}var n=this,r=[0],i=[null],s=[],o=this.table,u="",a=0,f=0,l=0,c=2,h=1;this.lexer.setInput(t),this.lexer.yy=this.yy,this.yy.lexer=this.lexer,this.yy.parser=this,typeof this.lexer.yylloc=="undefined"&&(this.lexer.yylloc={});var p=this.lexer.yylloc;s.push(p);var d=this.lexer.options&&this.lexer.options.ranges;typeof this.yy.parseError=="function"&&(this.parseError=this.yy.parseError);var g,y,b,w,E,S,x={},T,N,C,k;for(;;){b=r[r.length-1];if(this.defaultActions[b])w=this.defaultActions[b];else{if(g===null||typeof g=="undefined")g=m();w=o[b]&&o[b][g]}if(typeof w=="undefined"||!w.length||!w[0]){var L="";if(!l){k=[];for(T in o[b])this.terminals_[T]&&T>2&&k.push("'"+this.terminals_[T]+"'");this.lexer.showPosition?L="Parse error on line "+(a+1)+":\n"+this.lexer.showPosition()+"\nExpecting "+k.join(", ")+", got '"+(this.terminals_[g]||g)+"'":L="Parse error on line "+(a+1)+": Unexpected "+(g==1?"end of input":"'"+(this.terminals_[g]||g)+"'"),this.parseError(L,{text:this.lexer.match,token:this.terminals_[g]||g,line:this.lexer.yylineno,loc:p,expected:k})}}if(w[0]instanceof Array&&w.length>1)throw new Error("Parse Error: multiple actions possible at state: "+b+", token: "+g);switch(w[0]){case 1:r.push(g),i.push(this.lexer.yytext),s.push(this.lexer.yylloc),r.push(w[1]),g=null,y?(g=y,y=null):(f=this.lexer.yyleng,u=this.lexer.yytext,a=this.lexer.yylineno,p=this.lexer.yylloc,l>0&&l--);break;case 2:N=this.productions_[w[1]][1],x.$=i[i.length-N],x._$={first_line:s[s.length-(N||1)].first_line,last_line:s[s.length-1].last_line,first_column:s[s.length-(N||1)].first_column,last_column:s[s.length-1].last_column},d&&(x._$.range=[s[s.length-(N||1)].range[0],s[s.length-1].range[1]]),S=this.performAction.call(x,u,f,a,this.yy,w[1],i,s);if(typeof S!="undefined")return S;N&&(r=r.slice(0,-1*N*2),i=i.slice(0,-1*N),s=s.slice(0,-1*N)),r.push(this.productions_[w[1]][0]),i.push(x.$),s.push(x._$),C=o[r[r.length-2]][r[r.length-1]],r.push(C);break;case 3:return!0}}return!0}};undefined;var t=function(){var e={EOF:1,parseError:function(t,n){if(!this.yy.parser)throw new Error(t);this.yy.parser.parseError(t,n)},setInput:function(e){return this._input=e,this._more=this._less=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 e=this._input[0];this.yytext+=e,this.yyleng++,this.offset++,this.match+=e,this.matched+=e;var t=e.match(/(?:\r\n?|\n).*/g);return t?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),e},unput:function(e){var t=e.length,n=e.split(/(?:\r\n?|\n)/g);this._input=e+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-t-1),this.offset-=t;var r=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),n.length-1&&(this.yylineno-=n.length-1);var i=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:n?(n.length===r.length?this.yylloc.first_column:0)+r[r.length-n.length].length-n[0].length:this.yylloc.first_column-t},this.options.ranges&&(this.yylloc.range=[i[0],i[0]+this.yyleng-t]),this},more:function(){return this._more=!0,this},less:function(e){this.unput(this.match.slice(e))},pastInput:function(){var e=this.matched.substr(0,this.matched.length-this.match.length);return(e.length>20?"...":"")+e.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var e=this.match;return e.length<20&&(e+=this._input.substr(0,20-e.length)),(e.substr(0,20)+(e.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var e=this.pastInput(),t=(new Array(e.length+1)).join("-");return e+this.upcomingInput()+"\n"+t+"^"},next:function(){if(this.done)return this.EOF;this._input||(this.done=!0);var e,t,n,r,i,s;this._more||(this.yytext="",this.match="");var o=this._currentRules();for(var u=0;ut[0].length)){t=n,r=u;if(!this.options.flex)break}}if(t){s=t[0].match(/(?:\r\n?|\n).*/g),s&&(this.yylineno+=s.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:s?s[s.length-1].length-s[s.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+t[0].length},this.yytext+=t[0],this.match+=t[0],this.matches=t,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._input=this._input.slice(t[0].length),this.matched+=t[0],e=this.performAction.call(this,this.yy,this,o[r],this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1);if(e)return e;return}return 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 t=this.next();return typeof t!="undefined"?t:this.lex()},begin:function(t){this.conditionStack.push(t)},popState:function(){return this.conditionStack.pop()},_currentRules:function(){return this.conditions[this.conditionStack[this.conditionStack.length-1]].rules},topState:function(){return this.conditionStack[this.conditionStack.length-2]},pushState:function(t){this.begin(t)},options:{},performAction:function(t,n,r,i){var s=i;switch(r){case 0:return 27;case 1:return 29;case 2:return"from";case 3:break;case 4:return 46;case 5:return 52;case 6:return 22;case 7:return 23;case 8:return 19;case 9:return 17;case 10:return 20;case 11:return 18;case 12:return 24;case 13:return 25;case 14:return 32;case 15:return 34;case 16:return 50;case 17:return 44;case 18:return 38;case 19:return 48;case 20:return 42;case 21:return 10;case 22:return 11;case 23:return 36;case 24:return 8;case 25:return 24;case 26:return 25;case 27:return 22;case 28:return 22;case 29:return 23;case 30:return 23;case 31:return 19;case 32:return 20;case 33:return 18;case 34:return 17;case 35:return 32;case 36:return 34;case 37:return 13;case 38:return 15;case 39:return 39;case 40:return 54;case 41:return 53;case 42:return 40;case 43:return 5}},rules:[/^(?:\s+in\b)/,/^(?:\s+notIn\b)/,/^(?:\s+from\b)/,/^(?:\s+)/,/^(?:[0-9]+(?:\.[0-9]+)?\b)/,/^(?:null\b)/,/^(?:(eq|EQ))/,/^(?:(neq|NEQ))/,/^(?:(lte|LTE))/,/^(?:(lt|LT))/,/^(?:(gte|GTE))/,/^(?:(gt|GT))/,/^(?:(like|LIKE))/,/^(?:(notLike|NOT_LIKE))/,/^(?:(and|AND))/,/^(?:(or|OR))/,/^(?:(true|false))/,/^(?:'[^']*')/,/^(?:\$?[a-zA-Z0-9]+)/,/^(?:\/(.*)\/)/,/^(?:\.)/,/^(?:\*)/,/^(?:\/)/,/^(?:,)/,/^(?:-)/,/^(?:=~)/,/^(?:!=~)/,/^(?:==)/,/^(?:===)/,/^(?:!=)/,/^(?:!==)/,/^(?:<=)/,/^(?:>=)/,/^(?:>)/,/^(?:<)/,/^(?:&&)/,/^(?:\|\|)/,/^(?:\+)/,/^(?:\^)/,/^(?:\()/,/^(?:\])/,/^(?:\[)/,/^(?:\))/,/^(?:$)/],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],inclusive:!0}}};return e}();return e.lexer=t,n.prototype=e,e.Parser=n,new n}();typeof e!="undefined"&&typeof n!="undefined"&&(n.parser=u,n.Parser=u.Parser,n.parse=function(){return u.parse.apply(u,arguments)},n.main=function(r){r[1]||(console.log("Usage: "+r[0]+" FILE"),s.exit(1));var i=e("fs").readFileSync(e("path").normalize(r[1]),"utf8");return n.parser.parse(i)},typeof t!="undefined"&&e.main===t&&n.main(s.argv.slice(1)))}),require.define("/lib/parser/nools/nool.parser.js",function(e,t,n,r,i,s,o){"use strict";var u=e("./tokens.js"),a=e("../../extended"),f=a.hash.keys,l=e("./util.js"),c=function(e,t,n){var r=e;e=e.replace(/\/\/(.*)[\n|\r|\r\n]/g,"").replace(/\n|\r|\r\n/g," ");var i=new RegExp("^("+f(t).join("|")+")"),s;while(e&&(s=l.findNextTokenIndex(e))!==-1){e=e.substr(s);var o=e.match(i);if(o===null)throw new Error("Error parsing "+e);o=o[1];if(!(o in t))throw new Error("Unknown token"+o);try{e=t[o](e,n,c).replace(/^\s*|\s*$/g,"")}catch(u){throw new Error("Invalid "+o+" definition \n"+u.message+"; \nstarting at : "+r)}}};n.parse=function(e){var t={define:[],rules:[],scope:[]};return c(e,u,t),t}}),require.define("/lib/parser/nools/tokens.js",function(require,module,exports,__dirname,__filename,process,global){"use strict";var utils=require("./util.js"),isWhiteSpace=function(e){return e.replace(/[\s|\n|\r|\t]/g,"").length===0},ruleTokens={salience:function(){var e=/^(salience|priority)\s*:\s*(-?\d+)\s*[,;]?/;return function(t,n){if(e.test(t)){var r=t.match(e),i=parseInt(r[2],10);if(!isNaN(i))return n.options.priority=i,t.replace(r[0],"");throw new Error("Invalid salience/priority "+r[2])}throw new Error("invalid format")}}(),priority:function(){return this.salience.apply(this,arguments)},when:function(){var ruleRegExp=/^(\$?\w+) *: *(\w+)(.*)/,joinFunc=function(e,t){return"; "+t},constraintRegExp=/(\{(?:["']?\$?\w+["']?\s*:\s*["']?\$?\w+["']? *(?:, *["']?\$?\w+["']?\s*:\s*["']?\$?\w+["']?)*)+\})/,predicateExp=/^(\w+) *\((.*)\)$/m,fromRegExp=/(\bfrom\s+.*)/,parseRules=function(str){var rules=[],ruleLines=str.split(";"),l=ruleLines.length,ruleLine;for(var i=0;is)r=s;for(;n