<commit_before>require=function t(e,r,n){function a(i,s){if(!r[i]){if(!e[i]){var p="function"==typeof require&&require;if(!s&&p)return p(i,!0);if(o)return o(i,!0);var u=new Error("Cannot find module '"+i+"'");throw u.code="MODULE_NOT_FOUND",u}var c=r[i]={exports:{}};e[i][0].call(c.exports,function(t){var r=e[i][1][t];return a(r?r:t)},c,c.exports,t,e,r,n)}return r[i].exports}for(var o="function"==typeof require&&require,i=0;i<n.length;i++)a(n[i]);return a}({1:[function(t,e){function r(t){this._grammar=t}var n=/^-?(?:(?:[0-9]*\.[0-9]+)|[0-9]+)$/,a=/^[a-zA-Z_\$][a-zA-Z0-9_\$]*$/,o=/\\\\/,i=["'(?:(?:\\\\')?[^'])*'",'"(?:(?:\\\\")?[^"])*"',"\\s+","\\btrue\\b","\\bfalse\\b"],s=["\\b[a-zA-Z_\\$][a-zA-Z0-9_\\$]*\\b","(?:(?:[0-9]*\\.[0-9]+)|[0-9]+)"],p=["binaryOp","unaryOp","openParen","openBracket","question","colon","semicolon","shove","push","lambdaExpression"];r.prototype.getElements=function(t){var e=this._getSplitRegex();return t.split(e).filter(function(t){return t})},r.prototype.getTokens=function(t){for(var e=[],r=!1,n=0;n<t.length;n++)this._isWhitespace(t[n])?e.length&&(e[e.length-1].raw+=t[n]):"-"===t[n]&&this._isNegative(e)?r=!0:(r&&(t[n]="-"+t[n],r=!1),e.push(this._createToken(t[n])));return r&&e.push(this._createToken("-")),e},r.prototype.tokenize=function(t){var e=this.getElements(t);return this.getTokens(e)},r.prototype._createToken=function(t){var e={type:"literal",value:t,raw:t};if('"'==t[0]||"'"==t[0])e.value=this._unquote(t);else if(t.match(n))e.value=parseFloat(t);else if("true"===t||"false"===t)e.value="true"===t;else if(this._grammar[t])e.type=this._grammar[t].type;else{if(!t.match(a))throw new Error("Invalid expression token: "+t);e.type="identifier"}return e},r.prototype._escapeRegExp=function(t){return t=t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),t.match(a)&&(t="\\b"+t+"\\b"),t},r.prototype._getSplitRegex=function(){if(!this._splitRegex){var t=Object.keys(this._grammar);t=t.sort(function(t,e){return e.length-t.length}).map(function(t){return this._escapeRegExp(t)},this),this._splitRegex=new RegExp("("+[i.join("|"),t.join("|"),s.join("|")].join("|")+")")}return this._splitRegex},r.prototype._isNegative=function(t){return t.length?p.some(function(e){return e===t[t.length-1].type}):!0},r.prototype._isWhitespace=function(t){for(var e=0;e<t.length;e++)if(" "!=t[e])return!1;return!0},r.prototype._unquote=function(t){var e=t[0],r=new RegExp("\\\\"+e,"g");return t.substr(1,t.length-2).replace(r,e).replace(o,"\\")},e.exports=r},{}],2:[function(t,e){var r=t("./handlers"),n=function(t,e,r,n){this._grammar=t,this._transforms=e||{},this._context=r||{},this._relContext=n||this._context};n.prototype.eval=function(t){var e=this;return Promise.resolve().then(function(){return r[t.type].call(e,t)})},n.prototype.evalArray=function(t){return Promise.all(t.map(function(t){return this.eval(t)},this))},n.prototype.evalMap=function(t){var e=Object.keys(t),r={},n=e.map(function(e){return this.eval(t[e])},this);return Promise.all(n).then(function(t){return t.forEach(function(t,n){r[e[n]]=t}),r})},n.prototype._filterRelative=function(t,e){var r=[];return Array.isArray(t)||(t=[t]),t.forEach(function(t){var a=new n(this._grammar,this._transforms,this._context,t);r.push(a.eval(e))},this),Promise.all(r).then(function(e){var r=[];return e.forEach(function(e,n){e&&r.push(t[n])}),r})},n.prototype._filterStatic=function(t,e){return this.eval(e).then(function(e){return"boolean"==typeof e?e?t:void 0:t[e]})},e.exports=n},{"./handlers":3}],3:[function(t,e,r){r.ArrayLiteral=function(t){return this.evalArray(t.value)},r.BinaryExpression=function(t){var e=this;return Promise.all([this.eval(t.left),this.eval(t.right)]).then(function(r){return e._grammar[t.operator].eval(r[0],r[1])})},r.ConditionalExpression=function(t){var e=this;return this.eval(t.test).then(function(r){return r?t.consequent?e.eval(t.consequent):r:e.eval(t.alternate)})},r.AssignmentExpression=function(t){var e=this;return this.eval(t.subject).then(function(r){return e._context[t.name]=r,t.right?e.eval(t.right):void 0})},r.LambdaExpression=function(t){return t.lambda.bind(this)},r.FilterExpression=function(t){var e=this;return this.eval(t.subject).then(function(r){return t.relative?e._filterRelative(r,t.expr):e._filterStatic(r,t.expr)})},r.ShoveContextAssignment=function(t){var e=this;return this.eval(t.subject).then(function(r){e._context[t.name]=r})},r.PassContext=function(t){var e=this;return this.eval(t.subject).then(function(){return e.eval(t.right)})},r.Identifier=function(t){return t.from?this.eval(t.from).then(function(e){return void 0===e?void 0:(Array.isArray(e)&&(e=e[0]),e?e[t.value]:void 0)}):t.relative?this._relContext[t.value]:this._context[t.value]},r.Literal=function(t){return t.value},r.ObjectLiteral=function(t){return this.evalMap(t.value)},r.Transform=function(t){var e=this._transforms[t.name];if(!e)throw new Error("Transform '"+t.name+"' is not defined.");return Promise.all([this.eval(t.subject),this.evalArray(t.args||[])]).then(function(t){return e.apply(null,[t[0]].concat(t[1]))}).then(function(t){return Array.isArray(t)?Promise.all(t):Promise.resolve(t)})},r.UnaryExpression=function(t){var e=this;return this.eval(t.right).then(function(r){return e._grammar[t.operator].eval(r)})}},{}],4:[function(t,e,r){r.elements={".":{type:"dot"},"[":{type:"openBracket"},"]":{type:"closeBracket"},"|":{type:"pipe"},"{":{type:"openCurl"},"}":{type:"closeCurl"},":":{type:"colon"},",":{type:"comma"},"(":{type:"openParen"},")":{type:"closeParen"},"?":{type:"question"},"=":{type:"assign"},"->":{type:"rightArrow"},";":{type:"semicolon"},"=<<":{type:"pull"},">>":{type:"export"},"+":{type:"binaryOp",precedence:30,eval:function(t,e){return t+e}},"-":{type:"binaryOp",precedence:30,eval:function(t,e){return t-e}},"*":{type:"binaryOp",precedence:40,eval:function(t,e){return t*e}},"/":{type:"binaryOp",precedence:40,eval:function(t,e){return t/e}},"//":{type:"binaryOp",precedence:40,eval:function(t,e){return Math.floor(t/e)}},"%":{type:"binaryOp",precedence:50,eval:function(t,e){return t%e}},"^":{type:"binaryOp",precedence:50,eval:function(t,e){return Math.pow(t,e)}},"==":{type:"binaryOp",precedence:20,eval:function(t,e){return t==e}},"!=":{type:"binaryOp",precedence:20,eval:function(t,e){return t!=e}},">":{type:"binaryOp",precedence:20,eval:function(t,e){return t>e}},">=":{type:"binaryOp",precedence:20,eval:function(t,e){return t>=e}},"<":{type:"binaryOp",precedence:20,eval:function(t,e){return e>t}},"<=":{type:"binaryOp",precedence:20,eval:function(t,e){return e>=t}},"&&":{type:"binaryOp",precedence:10,eval:function(t,e){return t&&e}},"||":{type:"binaryOp",precedence:10,eval:function(t,e){return t||e}},$:{type:"binaryOp",precedence:20,eval:function(t,e){return"string"==typeof e?-1!==e.indexOf(t):Array.isArray(e)?e.some(function(e){return e==t}):!1}},"!":{type:"unaryOp",precedence:1/0,eval:function(t){return!t}}}},{}],5:[function(t,e){function r(t,e,r){this._grammar=t,this._state="expectOperand",this._tree=null,this._exprStr=e||"",this._relative=!1,this._stopMap=r||{}}var n=t("./handlers"),a=t("./states").states;r.prototype.addToken=function(t){if("complete"==this._state)throw new Error("Cannot add a new token to a completed Parser");var e=a[this._state],r=this._exprStr;if(this._exprStr+=t.raw,e.subHandler){this._subParser||this._startSubExpression(r);var o=this._subParser.addToken(t);if(o){if(this._endSubExpression(),this._parentStop)return o;this._state=o}}else{if(!e.tokenTypes[t.type]){if(this._stopMap[t.type])return this._stopMap[t.type];throw new Error("Token "+t.raw+" ("+t.type+") unexpected in expression: "+this._exprStr)}var i=e.tokenTypes[t.type],s=n[t.type];i.handler&&(s=i.handler),s&&s.call(this,t),i.toState&&(this._state=i.toState)}return!1},r.prototype.addTokens=function(t){t.forEach(this.addToken,this)},r.prototype.complete=function(){if(this._cursor&&!a[this._state].completable)throw new Error("Unexpected end of expression: "+this._exprStr);return this._subParser&&this._endSubExpression(),this._state="complete",this._cursor?this._tree:null},r.prototype.isRelative=function(){return this._relative},r.prototype._endSubExpression=function(){a[this._state].subHandler.call(this,this._subParser.complete()),this._subParser=null},r.prototype._placeAtCursor=function(t){this._cursor?(this._cursor.right=t,this._setParent(t,this._cursor)):this._tree=t,this._cursor=t},r.prototype._placeBeforeCursor=function(t){this._cursor=this._cursor._parent,this._placeAtCursor(t)},r.prototype._setParent=function(t,e){Object.defineProperty(t,"_parent",{value:e,writable:!0})},r.prototype._startSubExpression=function(t){var e=a[this._state].endStates;e||(this._parentStop=!0,e=this._stopMap),this._subParser=new r(this._grammar,t,e)},e.exports=r},{"./handlers":6,"./states":7}],6:[function(t,e,r){r.argVal=function(t){this._cursor.args.push(t)},r.arrayStart=function(){this._placeAtCursor({type:"ArrayLiteral",value:[]})},r.arrayVal=function(t){t&&this._cursor.value.push(t)},r.binaryOp=function(t){for(var e=this._grammar[t.value].precedence||0,r=this._cursor._parent;r&&r.operator&&this._grammar[r.operator].precedence>=e;)this._cursor=r,r=r._parent;var n={type:"BinaryExpression",operator:t.value,left:this._cursor};this._setParent(this._cursor,n),this._cursor=r,this._placeAtCursor(n)},r.dot=function(){this._nextIdentEncapsulate=this._cursor&&("BinaryExpression"!=this._cursor.type||"BinaryExpression"==this._cursor.type&&this._cursor.right)&&"UnaryExpression"!=this._cursor.type,this._nextIdentRelative=!this._cursor||this._cursor&&!this._nextIdentEncapsulate,this._nextIdentRelative&&(this._relative=!0)},r.filter=function(t){this._placeBeforeCursor({type:"FilterExpression",expr:t,relative:this._subParser.isRelative(),subject:this._cursor})},r.identifier=function(t){var e={type:"Identifier",value:t.value};this._nextIdentEncapsulate?(e.from=this._cursor,this._placeBeforeCursor(e)):(this._nextIdentRelative&&(e.relative=!0),this._placeAtCursor(e))},r.literal=function(t){this._placeAtCursor({type:"Literal",value:t.value})},r.objKey=function(t){this._curObjKey=t.value},r.objStart=function(){this._placeAtCursor({type:"ObjectLiteral",value:{}})},r.objVal=function(t){this._cursor.value[this._curObjKey]=t},r.subExpression=function(t){this._placeAtCursor(t)},r.ternaryEnd=function(t){this._cursor.alternate=t},r.ternaryMid=function(t){this._cursor.consequent=t},r.ternaryStart=function(){this._tree={type:"ConditionalExpression",test:this._tree},this._cursor=this._tree},r.passContext=function(){this._placeBeforeCursor({type:"PassContext",subject:this._cursor})},r.assignmentStart=function(){this._tree={type:"AssignmentExpression",name:this._tree.value},this._cursor=this._tree},r.assignmentEnd=function(t){this._cursor.subject=t},r.lambdaExpressionStart=function(){var t,e=[];if(null!==this._tree)for(t=this._tree;;){if(e.push(t.value),!t.right)break;t=t.right}this._tree={type:"LambdaExpression",argNames:e},this._cursor=this._tree},r.lambdaExpressionEnd=function(e){var r=t("../evaluator/Evaluator"),n=this._cursor.argNames;delete this._cursor.argNames,this._cursor.lambda=function(){var t,a=this._context,o=Array.prototype.slice.call(arguments),i={};for(t=0;t<n.length;t++)i[n[t]]=o[t];Object.keys(a).forEach(function(t){!t in i&&(i[t]=a[t])});var s=new r(this._grammar,this._transforms,i);return Promise.resolve().then(function(){return s.eval(e)})}},r.transform=function(t){this._placeBeforeCursor({type:"Transform",name:t.value,args:[],subject:this._cursor})},r.unaryOp=function(t){this._placeAtCursor({type:"UnaryExpression",operator:t.value})}},{"../evaluator/Evaluator":2}],7:[function(t,e,r){var n=t("./handlers");r.states={expectOperand:{tokenTypes:{literal:{toState:"expectBinOp"},identifier:{toState:"identifier"},unaryOp:{},openParen:{toState:"subExpression"},openCurl:{toState:"expectObjKey",handler:n.objStart},dot:{toState:"traverse"},rightArrow:{toState:"lambdaExpressionEnd",handler:n.lambdaExpressionStart},openBracket:{toState:"arrayVal",handler:n.arrayStart}}},potentialOperand:{tokenTypes:{literal:{toState:"expectBinOp"},identifier:{toState:"identifier"},unaryOp:{},openParen:{toState:"subExpression"},openCurl:{toState:"expectObjKey",handler:n.objStart},dot:{toState:"traverse"},rightArrow:{toState:"lambdaExpressionEnd",handler:n.lambdaExpressionStart},openBracket:{toState:"arrayVal",handler:n.arrayStart}},completable:!0},lambdaExpressionEnd:{subHandler:n.lambdaExpressionEnd,completable:!0},expectBinOp:{tokenTypes:{binaryOp:{toState:"expectOperand"},pipe:{toState:"expectTransform"},dot:{toState:"traverse"},rightArrow:{toState:"lambdaExpressionEnd",handler:n.lambdaExpressionStart},question:{toState:"ternaryMid",handler:n.ternaryStart}},completable:!0},expectTransform:{tokenTypes:{identifier:{toState:"postTransform",handler:n.transform}}},expectObjKey:{tokenTypes:{identifier:{toState:"expectKeyValSep",handler:n.objKey},closeCurl:{toState:"expectBinOp"}}},expectKeyValSep:{tokenTypes:{colon:{toState:"objVal"}}},postTransform:{tokenTypes:{openParen:{toState:"argVal"},binaryOp:{toState:"expectOperand"},dot:{toState:"traverse"},openBracket:{toState:"filter"},pipe:{toState:"expectTransform"}},completable:!0},postTransformArgs:{tokenTypes:{binaryOp:{toState:"expectOperand"},dot:{toState:"traverse"},openBracket:{toState:"filter"},pipe:{toState:"expectTransform"}},completable:!0},identifier:{tokenTypes:{binaryOp:{toState:"expectOperand"},comma:{toState:"expectOperand"},dot:{toState:"traverse"},openBracket:{toState:"filter"},assign:{toState:"assignmentEnd",handler:n.assignmentStart},pipe:{toState:"expectTransform"},question:{toState:"ternaryMid",handler:n.ternaryStart}},completable:!0},traverse:{tokenTypes:{identifier:{toState:"identifier"}}},filter:{subHandler:n.filter,endStates:{closeBracket:"identifier"}},assignmentEnd:{subHandler:n.assignmentEnd,endStates:{semicolon:"potentialOperand"},completable:!0},subExpression:{subHandler:n.subExpression,endStates:{closeParen:"expectBinOp"}},argVal:{subHandler:n.argVal,endStates:{comma:"argVal",closeParen:"postTransformArgs"}},objVal:{subHandler:n.objVal,endStates:{comma:"expectObjKey",closeCurl:"expectBinOp"}},arrayVal:{subHandler:n.arrayVal,endStates:{comma:"arrayVal",closeBracket:"expectBinOp"}},ternaryMid:{subHandler:n.ternaryMid,endStates:{colon:"ternaryEnd"}},ternaryEnd:{subHandler:n.ternaryEnd,completable:!0}}},{"./handlers":6}],Jexl:[function(t,e){function r(){this._customGrammar=null,this._lexer=null,this._transforms={}}var n=t("./evaluator/Evaluator"),a=t("./Lexer"),o=t("./parser/Parser"),i=t("./grammar").elements;r.prototype.addBinaryOp=function(t,e,r){this._addGrammarElement(t,{type:"binaryOp",precedence:e,eval:r})},r.prototype.addUnaryOp=function(t,e){this._addGrammarElement(t,{type:"unaryOp",weight:1/0,eval:e})},r.prototype.addTransform=function(t,e){this._transforms[t]=e},r.prototype.addTransforms=function(t){for(var e in t)t.hasOwnProperty(e)&&(this._transforms[e]=t[e])},r.prototype.getTransform=function(t){return this._transforms[t]},r.prototype.eval=function(t,e,r){t=t.trim(),"function"==typeof e?(r=e,e={}):e||(e={});var n=this._eval(t,e);if(r){var a=!1;return n.then(function(t){a=!0,setTimeout(r.bind(null,null,t),0)})["catch"](function(t){a||setTimeout(r.bind(null,t),0)})}return n},r.prototype.removeOp=function(t){var e=this._getCustomGrammar();!e[t]||"binaryOp"!=e[t].type&&"unaryOp"!=e[t].type||(delete e[t],this._lexer=null)},r.prototype._addGrammarElement=function(t,e){var r=this._getCustomGrammar();r[t]=e,this._lexer=null},r.prototype._eval=function(t,e){var r=this,a=this._getGrammar(),i=new o(a),s=new n(a,this._transforms,e);return Promise.resolve().then(function(){return i.addTokens(r._getLexer().tokenize(t)),s.eval(i.complete())})},r.prototype._getCustomGrammar=function(){if(!this._customGrammar){this._customGrammar={};for(var t in i)i.hasOwnProperty(t)&&(this._customGrammar[t]=i[t])}return this._customGrammar},r.prototype._getGrammar=function(){return this._customGrammar||i},r.prototype._getLexer=function(){return this._lexer||(this._lexer=new a(this._getGrammar())),this._lexer},e.exports=new r,e.exports.Jexl=r},{"./Lexer":1,"./evaluator/Evaluator":2,"./grammar":4,"./parser/Parser":5}]},{},[]);<commit_msg>resolve merge conflicts<commit_after>require=function e(t,r,n){function a(i,s){if(!r[i]){if(!t[i]){var p="function"==typeof require&&require;if(!s&&p)return p(i,!0);if(o)return o(i,!0);var u=new Error("Cannot find module '"+i+"'");throw u.code="MODULE_NOT_FOUND",u}var c=r[i]={exports:{}};t[i][0].call(c.exports,function(e){var r=t[i][1][e];return a(r?r:e)},c,c.exports,e,t,r,n)}return r[i].exports}for(var o="function"==typeof require&&require,i=0;i<n.length;i++)a(n[i]);return a}({1:[function(e,t){function r(e){this._grammar=e}var n=/^-?(?:(?:[0-9]*\.[0-9]+)|[0-9]+)$/,a=/^[a-zA-Z_\$][a-zA-Z0-9_\$]*$/,o=/\\\\/,i=["'(?:(?:\\\\')?[^'])*'",'"(?:(?:\\\\")?[^"])*"',"\\s+","\\btrue\\b","\\bfalse\\b"],s=["\\b[a-zA-Z_\\$][a-zA-Z0-9_\\$]*\\b","(?:(?:[0-9]*\\.[0-9]+)|[0-9]+)"],p=["binaryOp","unaryOp","openParen","openBracket","question","colon","rightArrow","equals"];r.prototype.getElements=function(e){var t=this._getSplitRegex();return e.split(t).filter(function(e){return e})},r.prototype.getTokenizedLines=function(e){for(var t,r=[],n=[],a=!1,o=0;o<e.length;o++)this._isWhitespace(e[o])?n.length&&(n[n.length-1].raw+=e[o]):"-"===e[o]&&this._isNegative(n)?a=!0:(a&&(e[o]="-"+e[o],a=!1),t=this._createToken(e[o]),"semicolon"!==t.type?n.push(t):n.length&&(r.push(n),n=[]));return a&&n.push(this._createToken("-")),n.length&&r.push(n),r},r.prototype.tokenizeLines=function(e){var t=this.getElements(e);return this.getTokenizedLines(t)},r.prototype._createToken=function(e){var t={type:"literal",value:e,raw:e};if('"'==e[0]||"'"==e[0])t.value=this._unquote(e);else if(e.match(n))t.value=parseFloat(e);else if("true"===e||"false"===e)t.value="true"===e;else if(this._grammar[e])t.type=this._grammar[e].type;else{if(!e.match(a))throw new Error("Invalid expression token: "+e);t.type="identifier"}return t},r.prototype._escapeRegExp=function(e){return e=e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),e.match(a)&&(e="\\b"+e+"\\b"),e},r.prototype._getSplitRegex=function(){if(!this._splitRegex){var e=Object.keys(this._grammar);e=e.sort(function(e,t){return t.length-e.length}).map(function(e){return this._escapeRegExp(e)},this),this._splitRegex=new RegExp("("+[i.join("|"),e.join("|"),s.join("|")].join("|")+")")}return this._splitRegex},r.prototype._isNegative=function(e){return e.length?p.some(function(t){return t===e[e.length-1].type}):!0},r.prototype._isWhitespace=function(e){return!/\S/.test(e)},r.prototype._unquote=function(e){var t=e[0],r=new RegExp("\\\\"+t,"g");return e.substr(1,e.length-2).replace(r,t).replace(o,"\\")},t.exports=r},{}],2:[function(e,t){var r=e("./handlers"),n=function(e,t,r,n){this._grammar=e,this._transforms=t||{},this._context=r||{},this._relContext=n||this._context};n.prototype.eval=function(e){var t=this;return Promise.resolve().then(function(){return r[e.type].call(t,e)})},n.prototype.evalArray=function(e){return Promise.all(e.map(function(e){return this.eval(e)},this))},n.prototype.evalMap=function(e){var t=Object.keys(e),r={},n=t.map(function(t){return this.eval(e[t])},this);return Promise.all(n).then(function(e){return e.forEach(function(e,n){r[t[n]]=e}),r})},n.prototype._filterRelative=function(e,t){var r=[];return Array.isArray(e)||(e=[e]),e.forEach(function(e){var a=new n(this._grammar,this._transforms,this._context,e);r.push(a.eval(t))},this),Promise.all(r).then(function(t){var r=[];return t.forEach(function(t,n){t&&r.push(e[n])}),r})},n.prototype._filterStatic=function(e,t){return this.eval(t).then(function(t){return"boolean"==typeof t?t?e:void 0:e[t]})},t.exports=n},{"./handlers":3}],3:[function(e,t,r){r.ArrayLiteral=function(e){return this.evalArray(e.value)},r.AssignmentExpression=function(e){var t=this._context,r={};Object.keys(t).forEach(function(n){n!==e.name&&(r[n]=t[n])}),this._context=r,this._context[e.name]=this.eval(e.subject)},r.BinaryExpression=function(e){var t=this;return Promise.all([this.eval(e.left),this.eval(e.right)]).then(function(r){return t._grammar[e.operator].eval(r[0],r[1])})},r.ConditionalExpression=function(e){var t=this;return this.eval(e.test).then(function(r){return r?e.consequent?t.eval(e.consequent):r:t.eval(e.alternate)})},r.FilterExpression=function(e){var t=this;return this.eval(e.subject).then(function(r){return e.relative?t._filterRelative(r,e.expr):t._filterStatic(r,e.expr)})},r.Identifier=function(e){return e.from?this.eval(e.from).then(function(t){return void 0===t?void 0:(Array.isArray(t)&&(t=t[0]),t?t[e.value]:void 0)}):e.relative?this._relContext[e.value]:this._context[e.value]},r.LambdaExpression=function(e){return e.lambda.bind(this)},r.Literal=function(e){return e.value},r.ObjectLiteral=function(e){return this.evalMap(e.value)},r.Transform=function(e){var t=this._transforms[e.name];if(!t)throw new Error("Transform '"+e.name+"' is not defined.");return Promise.all([this.eval(e.subject),this.evalArray(e.args||[])]).then(function(e){return t.apply(null,[e[0]].concat(e[1]))}).then(function(e){return Array.isArray(e)?Promise.all(e):Promise.resolve(e)})},r.UnaryExpression=function(e){var t=this;return this.eval(e.right).then(function(r){return t._grammar[e.operator].eval(r)})}},{}],4:[function(e,t,r){r.elements={".":{type:"dot"},"[":{type:"openBracket"},"]":{type:"closeBracket"},"|":{type:"pipe"},"{":{type:"openCurl"},"}":{type:"closeCurl"},":":{type:"colon"},",":{type:"comma"},"(":{type:"openParen"},")":{type:"closeParen"},"?":{type:"question"},";":{type:"semicolon"},"=":{type:"equals"},"->":{type:"rightArrow"},"+":{type:"binaryOp",precedence:30,eval:function(e,t){return e+t}},"-":{type:"binaryOp",precedence:30,eval:function(e,t){return e-t}},"*":{type:"binaryOp",precedence:40,eval:function(e,t){return e*t}},"/":{type:"binaryOp",precedence:40,eval:function(e,t){return e/t}},"//":{type:"binaryOp",precedence:40,eval:function(e,t){return Math.floor(e/t)}},"%":{type:"binaryOp",precedence:50,eval:function(e,t){return e%t}},"^":{type:"binaryOp",precedence:50,eval:function(e,t){return Math.pow(e,t)}},"==":{type:"binaryOp",precedence:20,eval:function(e,t){return e==t}},"!=":{type:"binaryOp",precedence:20,eval:function(e,t){return e!=t}},">":{type:"binaryOp",precedence:20,eval:function(e,t){return e>t}},">=":{type:"binaryOp",precedence:20,eval:function(e,t){return e>=t}},"<":{type:"binaryOp",precedence:20,eval:function(e,t){return t>e}},"<=":{type:"binaryOp",precedence:20,eval:function(e,t){return t>=e}},"&&":{type:"binaryOp",precedence:10,eval:function(e,t){return e&&t}},"||":{type:"binaryOp",precedence:10,eval:function(e,t){return e||t}},"in":{type:"binaryOp",precedence:20,eval:function(e,t){return"string"==typeof t?-1!==t.indexOf(e):Array.isArray(t)?t.some(function(t){return t==e}):!1}},"!":{type:"unaryOp",precedence:1/0,eval:function(e){return!e}}}},{}],5:[function(e,t){function r(e,t,r,n){this._grammar=e,this._state=t||"expectFirstOperand",this._tree=null,this._exprStr=r||"",this._relative=!1,this._stopMap=n||{}}var n=e("./handlers"),a=e("./states").states;r.prototype.addToken=function(e){if("complete"==this._state)throw new Error("Cannot add a new token to a completed Parser");var t=a[this._state],r=this._exprStr;if(this._exprStr+=e.raw,t.subHandler){this._subParser||this._startSubExpression(r);var o=this._subParser.addToken(e);if(o){if(this._endSubExpression(),this._parentStop)return o;this._state=o}}else{if(!t.tokenTypes[e.type]){if(this._stopMap[e.type])return this._stopMap[e.type];throw new Error("Token "+e.raw+" ("+e.type+") unexpected in expression: "+this._exprStr)}var i=t.tokenTypes[e.type],s=n[e.type];i.handler&&(s=i.handler),s&&s.call(this,e),i.toState&&(this._state=i.toState)}return!1},r.prototype.addTokens=function(e){e.forEach(this.addToken,this)},r.prototype.complete=function(){if(this._cursor&&!a[this._state].completable)throw new Error("Unexpected end of expression: "+this._exprStr);return this._subParser&&this._endSubExpression(),this._state="complete",this._cursor?this._tree:null},r.prototype.isRelative=function(){return this._relative},r.prototype._endSubExpression=function(){a[this._state].subHandler.call(this,this._subParser.complete()),this._subParser=null},r.prototype._placeAtCursor=function(e){this._cursor?(this._cursor.right=e,this._setParent(e,this._cursor)):this._tree=e,this._cursor=e},r.prototype._placeBeforeCursor=function(e){this._cursor=this._cursor._parent,this._placeAtCursor(e)},r.prototype._setParent=function(e,t){Object.defineProperty(e,"_parent",{value:t,writable:!0})},r.prototype._startSubExpression=function(e){var t=a[this._state].endStates;t||(this._parentStop=!0,t=this._stopMap),this._subParser=new r(this._grammar,"expectOperand",e,t)},t.exports=r},{"./handlers":6,"./states":7}],6:[function(e,t,r){r.argVal=function(e){this._cursor.args.push(e)},r.arrayStart=function(){this._placeAtCursor({type:"ArrayLiteral",value:[]})},r.arrayVal=function(e){e&&this._cursor.value.push(e)},r.assignmentEnd=function(e){this._tree={type:"AssignmentExpression",name:this._tree.value,subject:e},this._cursor.subject=this._tree},r.binaryOp=function(e){for(var t=this._grammar[e.value].precedence||0,r=this._cursor._parent;r&&r.operator&&this._grammar[r.operator].precedence>=t;)this._cursor=r,r=r._parent;var n={type:"BinaryExpression",operator:e.value,left:this._cursor};this._setParent(this._cursor,n),this._cursor=r,this._placeAtCursor(n)},r.dot=function(){this._nextIdentEncapsulate=this._cursor&&("BinaryExpression"!=this._cursor.type||"BinaryExpression"==this._cursor.type&&this._cursor.right)&&"UnaryExpression"!=this._cursor.type,this._nextIdentRelative=!this._cursor||this._cursor&&!this._nextIdentEncapsulate,this._nextIdentRelative&&(this._relative=!0)},r.filter=function(e){this._placeBeforeCursor({type:"FilterExpression",expr:e,relative:this._subParser.isRelative(),subject:this._cursor})},r.identifier=function(e){var t={type:"Identifier",value:e.value};this._nextIdentEncapsulate?(t.from=this._cursor,this._placeBeforeCursor(t)):(this._nextIdentRelative&&(t.relative=!0),this._placeAtCursor(t))},r.lambdaExpressionEnd=function(t){var r=e("../evaluator/Evaluator"),n=this._cursor.argNames;this._cursor.lambda=function(){var e=arguments,a={},o=this._context;n.forEach(function(t,r){a[t]=e[r]}),Object.keys(o).forEach(function(e){e in a||(a[e]=o[e])});var i=new r(this._grammar,this._transforms,a);return i.eval(t)}},r.lambdaExpressionStart=function(){for(var e=[],t=this._tree;t&&t.value;)e.push(t.value),t=t.right;this._tree={type:"LambdaExpression",argNames:e},this._cursor=this._tree},r.literal=function(e){this._placeAtCursor({type:"Literal",value:e.value})},r.objKey=function(e){this._curObjKey=e.value},r.objStart=function(){this._placeAtCursor({type:"ObjectLiteral",value:{}})},r.objVal=function(e){this._cursor.value[this._curObjKey]=e},r.subExpression=function(e){this._placeAtCursor(e)},r.ternaryEnd=function(e){this._cursor.alternate=e},r.ternaryMid=function(e){this._cursor.consequent=e},r.ternaryStart=function(){this._tree={type:"ConditionalExpression",test:this._tree},this._cursor=this._tree},r.transform=function(e){this._placeBeforeCursor({type:"Transform",name:e.value,args:[],subject:this._cursor})},r.unaryOp=function(e){this._placeAtCursor({type:"UnaryExpression",operator:e.value})}},{"../evaluator/Evaluator":2}],7:[function(e,t,r){var n=e("./handlers");r.states={expectFirstOperand:{tokenTypes:{literal:{toState:"expectBinOp"},identifier:{toState:"firstIdentifier"},unaryOp:{},openParen:{toState:"subExpression"},openCurl:{toState:"expectObjKey",handler:n.objStart},dot:{toState:"traverse"},rightArrow:{toState:"lambdaExpressionEnd",handler:n.lambdaExpressionStart},openBracket:{toState:"arrayVal",handler:n.arrayStart}}},expectOperand:{tokenTypes:{literal:{toState:"expectBinOp"},identifier:{toState:"identifier"},unaryOp:{},openParen:{toState:"subExpression"},openCurl:{toState:"expectObjKey",handler:n.objStart},dot:{toState:"traverse"},rightArrow:{toState:"lambdaExpressionEnd",handler:n.lambdaExpressionStart},openBracket:{toState:"arrayVal",handler:n.arrayStart}}},expectBinOp:{tokenTypes:{binaryOp:{toState:"expectOperand"},pipe:{toState:"expectTransform"},dot:{toState:"traverse"},rightArrow:{toState:"lambdaExpressionEnd",handler:n.lambdaExpressionStart},question:{toState:"ternaryMid",handler:n.ternaryStart}},completable:!0},expectIdentifier:{tokenTypes:{identifier:{toState:"argName"}}},expectTransform:{tokenTypes:{identifier:{toState:"postTransform",handler:n.transform}}},expectObjKey:{tokenTypes:{identifier:{toState:"expectKeyValSep",handler:n.objKey},closeCurl:{toState:"expectBinOp"}}},expectKeyValSep:{tokenTypes:{colon:{toState:"objVal"}}},postTransform:{tokenTypes:{openParen:{toState:"argVal"},binaryOp:{toState:"expectOperand"},dot:{toState:"traverse"},openBracket:{toState:"filter"},pipe:{toState:"expectTransform"}},completable:!0},postTransformArgs:{tokenTypes:{binaryOp:{toState:"expectOperand"},dot:{toState:"traverse"},openBracket:{toState:"filter"},pipe:{toState:"expectTransform"}},completable:!0},firstIdentifier:{tokenTypes:{binaryOp:{toState:"expectOperand"},comma:{toState:"expectIdentifier"},dot:{toState:"traverse"},openBracket:{toState:"filter"},equals:{toState:"assignmentEnd"},pipe:{toState:"expectTransform"},question:{toState:"ternaryMid",handler:n.ternaryStart}},completable:!0},identifier:{tokenTypes:{binaryOp:{toState:"expectOperand"},dot:{toState:"traverse"},openBracket:{toState:"filter"},pipe:{toState:"expectTransform"},question:{toState:"ternaryMid",handler:n.ternaryStart}},completable:!0},traverse:{tokenTypes:{identifier:{toState:"identifier"}}},filter:{subHandler:n.filter,endStates:{closeBracket:"identifier"}},assignmentEnd:{subHandler:n.assignmentEnd,completable:!0},lambdaExpressionEnd:{subHandler:n.lambdaExpressionEnd,completable:!0},subExpression:{subHandler:n.subExpression,endStates:{closeParen:"expectBinOp"}},argName:{tokenTypes:{comma:{toState:"expectIdentifier"}},completable:!0},argVal:{subHandler:n.argVal,endStates:{comma:"argVal",closeParen:"postTransformArgs"}},objVal:{subHandler:n.objVal,endStates:{comma:"expectObjKey",closeCurl:"expectBinOp"}},arrayVal:{subHandler:n.arrayVal,endStates:{comma:"arrayVal",closeBracket:"expectBinOp"}},ternaryMid:{subHandler:n.ternaryMid,endStates:{colon:"ternaryEnd"}},ternaryEnd:{subHandler:n.ternaryEnd,completable:!0}}},{"./handlers":6}],Jexl:[function(e,t){function r(){this._customGrammar=null,this._lexer=null,this._transforms={}}var n=e("./evaluator/Evaluator"),a=e("./Lexer"),o=e("./parser/Parser"),i=e("./grammar").elements;r.prototype.addBinaryOp=function(e,t,r){this._addGrammarElement(e,{type:"binaryOp",precedence:t,eval:r})},r.prototype.addUnaryOp=function(e,t){this._addGrammarElement(e,{type:"unaryOp",weight:1/0,eval:t})},r.prototype.addTransform=function(e,t){this._transforms[e]=t},r.prototype.addTransforms=function(e){for(var t in e)e.hasOwnProperty(t)&&(this._transforms[t]=e[t])},r.prototype.getTransform=function(e){return this._transforms[e]},r.prototype.eval=function(e,t,r){e=e.trim(),"function"==typeof t?(r=t,t={}):t||(t={});var n=this._eval(e,t);if(r){var a=!1;return n.then(function(e){a=!0,setTimeout(r.bind(null,null,e),0)})["catch"](function(e){a||setTimeout(r.bind(null,e),0)})}return n},r.prototype.removeOp=function(e){var t=this._getCustomGrammar();!t[e]||"binaryOp"!=t[e].type&&"unaryOp"!=t[e].type||(delete t[e],this._lexer=null)},r.prototype._addGrammarElement=function(e,t){var r=this._getCustomGrammar();r[e]=t,this._lexer=null},r.prototype._eval=function(e,t){var r=this,a=this._getGrammar(),i=new n(a,this._transforms,t);return Promise.resolve().then(function(){var t=r._getLexer().tokenizeLines(e);return Promise.all(t.map(function(e){var t=new o(a);return t.addTokens(e),i.eval(t.complete())})).then(function(e){return e[e.length-1]})})},r.prototype._getCustomGrammar=function(){if(!this._customGrammar){this._customGrammar={};for(var e in i)i.hasOwnProperty(e)&&(this._customGrammar[e]=i[e])}return this._customGrammar},r.prototype._getGrammar=function(){return this._customGrammar||i},r.prototype._getLexer=function(){return this._lexer||(this._lexer=new a(this._getGrammar())),this._lexer},t.exports=new r,t.exports.Jexl=r},{"./Lexer":1,"./evaluator/Evaluator":2,"./grammar":4,"./parser/Parser":5}]},{},[]);
{'fraction_non_alphanumeric': 0.2568241673121611, 'fraction_numerical': 0.007343144848954299, 'mean_word_length': 17.528128587830082, 'pattern_counts': {'":': 83, '<': 15, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '716051', 'n_tokens_mistral': 12002, 'n_tokens_neox': 11809, 'n_words': 401}