PHP Classes

File: src/js/Xpresion.min.js

Recommend this page to a friend!
  Classes of Nikos M.   Xpresion PHP Parser Engine   src/js/Xpresion.min.js   Download  
File: src/js/Xpresion.min.js
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: Xpresion PHP Parser Engine
Parse expressions that may contain variables
Author: By
Last change:
Date: 4 years ago
Size: 31,113 bytes
 

Contents

Class file image Download
/** * * Xpresion * Simple eXpression parser engine with variables and custom functions support for PHP, Python, Node.js and Browser * @version: 1.0.1 * * https://github.com/foo123/Xpresion * **/ !function(t,n,i){"use strict";"undefined"!=typeof Components&&"object"==typeof Components.classes&&"object"==typeof Components.classesByID&&Components.utils&&"function"==typeof Components.utils.import?(t.$deps=t.$deps||{})&&(t.EXPORTED_SYMBOLS=[n])&&(t[n]=t.$deps[n]=i.call(t)):"object"==typeof module&&module.exports?(module.$deps=module.$deps||{})&&(module.exports=module.$deps[n]=i.call(t)):"undefined"!=typeof System&&"function"==typeof System.register&&"function"==typeof System.import?System.register(n,[],function(e){e(n,i.call(t))}):"function"==typeof define&&define.amd&&"function"==typeof require&&"function"==typeof require.specified&&require.specified(n)?define(n,["module"],function(n){return i.moduleUri=n.uri,i.call(t)}):n in t||(t[n]=i.call(t)||1)&&"function"==typeof define&&define.amd&&define(function(){return t[n]})}("undefined"!=typeof self?self:this,"Xpresion",function(t){"use strict";var n,i="prototype",e=Object[i].hasOwnProperty,l=Object[i].toString,r=JSON.stringify,o=Object.keys,u=Object.create,s=Math.floor,a=Math.round,p=Math.abs,h=Math.max,f={meridian:{am:"am",pm:"pm",AM:"AM",PM:"PM"},ordinal:{ord:{1:"st",2:"nd",3:"rd"},nth:"th"},timezone:["UTC","EST","MDT"],timezone_short:["UTC","EST","MDT"],day:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],day_short:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],month:["January","February","March","April","May","June","July","August","September","October","November","December"],month_short:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]},c="charAt",y=/^\s+|\s+$/g,d=String[i].trim?function(t){return t.trim()}:function(t){return t.replace(y,"")},g=!1;function _(t,n){return t&&e.call(t,n)?1:0}function v(t,n,i,e){var l=String(t);if(i=i||"0",e)for(;l.length<n;)l+=i;else for(;l.length<n;)l=i+l;return l}function m(){return m.GUID+=1,v((new Date).getTime().toString(16),12)+"--"+v(m.GUID.toString(16),4)}function T(t){return t instanceof Array||"[object Array]"===l.call(t)}function b(t,n,i){for(var e,l="";n<i&&(" "===(e=t[c](n))||"\r"===e||"\t"===e||"\v"===e||"\0"===e);)l+=e,n+=1;return l}function S(t,n){var i,e,l,r=t.length;if(r&&n.length)for(i="",l=0;l<r;l++)i+=e=t[c](l),"\n"===e&&(i+=n);else i=t;return i}function E(t,n,i,e){var l,r,o,u,s=0;if(n)for(l=t,r=n.length,o=0,s=1;o<r;){if(u=n[o++],null==l||null==l[u]){s=0;break}l=l[u]}if(!s&&i)for(l=t,r=i.length,o=0,s=1;o<r;){if(u=i[o++],null==l||null==l[u]){s=0;break}l=l[u]}if(!s&&null!=e&&e!==t){if(n)for(l=e,r=n.length,o=0,s=1;o<r;){if(u=n[o++],null==l||null==l[u]){s=0;break}l=l[u]}if(!s&&i)for(l=e,r=i.length,o=0,s=1;o<r;){if(u=i[o++],null==l||null==l[u]){s=0;break}l=l[u]}}return s?l:null}function O(t,n){this.prev=t||null,this.value=n||null}function $(t,n){n&&(n.next=this),this.node=t||null,this.prev=n||null,this.next=null}function x(t,n,i,e,l,r,o){var u,s,a,p,h,f,c,y,d=null,g="";if(-1===n.type){if((u=n.opt_args)&&u.value[5])for(;u;){if(a=E(t,(s=u.value)[1],[String(s[0])],s[6]?null:o),null===d&&n.name===s[0]&&(d=a),0===s[2]&&null==a||1===s[2]&&null!=a)return"";u=u.prev}}else d=E(t,n.key,[String(n.name)],n.loc?null:o);if(y=(p=T(d))?d.length:-1,p&&y>n.start)for(h=n.start,f=-1===n.end?y-1:Math.min(n.end,y-1),c=h;c<=f;c++)g+=P(t,n.tpl,i,e,c,r,o);else p||n.start!==n.end||(g=P(t,n.tpl,i,e,null,r,o));return g}function R(t,n,i,e,l,r,o){var u,s,a,p,h="";if(n.stpl&&(_(i,n.stpl)||_(D.subGlobal,n.stpl)||_(e,n.stpl)||_(e,"*")||_(D.fnGlobal,n.stpl)||_(D.fnGlobal,"*")))if(u=E(t,n.key,[String(n.name)],n.loc?null:o),_(i,n.stpl)||_(D.subGlobal,n.stpl))null==l||0===l&&n.start===n.end&&n.opt||!T(u)||(u=l<u.length?u[l]:null),null==u&&null!==n.dval?h=n.dval:(a=_(i,n.stpl)?i[n.stpl].node:D.subGlobal[n.stpl].node,s={},null!=u&&(T(u)?s[a.name]=u:s=u),h=x(s,a,i,e,0,n.algn?r:"",null==o?t:o));else{if(p=null,_(e,n.stpl)?p=e[n.stpl]:_(e,"*")?p=e["*"]:_(D.fnGlobal,n.stpl)?p=D.fnGlobal[n.stpl]:D.fnGlobal["*"]&&(p=D.fnGlobal["*"]),T(u)&&(u=(l=null!=l?l:n.start)<u.length?u[l]:null),"function"==typeof p)u=p(u,{symbol:n,index:l,currentArguments:t,originalArguments:o,alignment:r});else u=String(p);h=null==u&&null!==n.dval?n.dval:String(u),n.algn&&(h=S(h,r))}else n.opt&&null!==n.dval?h=n.dval:(T(u=E(t,n.key,[String(n.name)],n.loc?null:o))&&(u=(l=null!=l?l:n.start)<u.length?u[l]:null),h=null==u&&null!==n.dval?n.dval:String(u),n.algn&&(h=S(h,r)));return h}function P(t,n,i,e,l,r,o){for(var u,s=r=r||"",a="";n;)-1===(u=n.node.type)?a+=x(t,n.node,i,e,0,n.node.algn?s:r,o):1===u?a+=R(t,n.node,i,e,l,n.node.algn?s:r,o):0===u?(s+=n.node.algn,a+=n.node.val):100===u&&(s=r,a+="\n"+r),n=n.next;return a}function D(t,n,i){if(!(this instanceof D))return new D(t,n,i);this.id=null,this.tpl=null,this.fn={},this._args=[t||"",n||D.defaultDelimiters,i||!1]}function w(t,n){return new Function(t,n)}function N(t){return t instanceof String||"[object String]"===l.call(t)}function F(t){return"[object Object]"===l.call(t)}function M(t,n,i){var e=t.toString(),l=n-e.length;return l>0?new Array(l+1).join(i||" ")+e:e}function A(){return s((new Date).getTime()/1e3)}function C(t,n){if(!arguments.length)return"";var i,l,r,o,u,h,c=f,y={},d=(u=n instanceof Date?new Date(n):"number"==typeof n?new Date(1e3*n):new Date).getTimezoneOffset(),g=p(d),_=u.getMonth();for(y.G=u.getHours(),y.j=u.getDate(),h=y.j%10,y.n=_+1,y.Y=u.getFullYear(),y.w=u.getDay(),y.N=y.w||7,y.d=M(y.j,2,"0"),y.D=c.day_short[y.w],y.l=c.day[y.w],y.S=c.ordinal.ord[y.j]?c.ordinal.ord[y.j]:c.ordinal.ord[h]?c.ordinal.ord[h]:c.ordinal.nth,y.z=a((new Date(y.Y,_,y.j)-new Date(y.Y,0,1))/864e5),y.W=M(1+a((new Date(y.Y,_,y.j-y.N+3)-new Date(y.Y,0,4))/864e5/7),2,"0"),y.F=c.month[_],y.m=M(y.n,2,"0"),y.M=c.month_short[_],y.t=new Date(y.Y,_+1,0).getDate(),y.L=y.Y%4==0&y.Y%100!=0|y.Y%400==0,y.o=y.Y+(11===_&&y.W<9?1:0===_&&y.W>9?-1:0),y.y=y.Y.toString().slice(-2),y.a=y.G>11?c.meridian.pm:c.meridian.am,y.A=y.G>11?c.meridian.PM:c.meridian.AM,y.B=M(s((3600*u.getUTCHours()+60*u.getUTCMinutes()+u.getUTCSeconds()+3600)/86.4)%1e3,3,"0"),y.g=y.G%12||12,y.h=M(y.g,2,"0"),y.H=M(y.G,2,"0"),y.i=M(u.getMinutes(),2,"0"),y.s=M(u.getSeconds(),2,"0"),y.u=M(1e3*u.getMilliseconds(),6,"0"),y.e="",y.I=new Date(y.Y,0)-Date.UTC(y.Y,0)!=new Date(y.Y,6)-Date.UTC(y.Y,6)?1:0,y.O=(d>0?"-":"+")+M(100*s(g/60)+g%60,4,"0"),y.P=y.O.substr(0,3)+":"+y.O.substr(3,2),y.T="UTC",y.Z=60*-d,y.U=u/1e3|0,y.c=[y.Y,"-",y.m,"-",y.d,"\\",y.T,y.H,":",y.i,":",y.s,y.P].join(""),y.r=[y.D,", ",y.d," ",y.M," ",y.Y," ",y.H,":",y.i,":",y.s," ",y.O].join(""),i="",r=0,o=t.length;r<o;r++)l=t.charAt(r),i+=e.call(y,l)?y[l]:l;return i}function k(){return null}function j(t){if(!(this instanceof j))return new j(t);this.RE={},this.BLOCKS={},this.RESERVED={},this.OPERATORS={},this.FUNCTIONS={},this.FN={INF:1/0,NAN:NaN},"object"==typeof t&&(t.re&&this.defRE(t.re),t.blocks&&this.defBlock(t.blocks),t.reserved&&this.defReserved(t.reserved),t.operators&&this.defOp(t.operators),t.functions&&this.defFunc(t.functions),t.runtime&&this.defRuntimeFunc(t.runtime))}function I(t,n){if(!(this instanceof I))return new I(t,n);n&&n instanceof j||(n=I.defaultConfiguration()),this.source=String(null==t?"":t),this.dummy_evaluator=k,I.parse(this,n)}m.GUID=0,D.VERSION="3.0.0",D.defaultDelimiters=["<",">","[","]"],D.fnGlobal={},D.subGlobal={},D.guid=m,D.multisplit=function(t,n,i){var e,l,r,o,u,s,a,p,h,f,y,g,v,T,S,E,x,R,P,D,w,N,F,M,A,C,k=n[0],j=n[1],I=n[2],Y=n[3],U=k.length,G=j.length,V=I.length,L=Y.length,z="#"+Y,K=null,X=0,B=0,q=0,J=0,H=t.length,W=[k,U,j,G],Z=[I,V,Y,L],Q=[null,0,null,0,null,0,null,0];for(i=!0===i,P={type:1,name:null,key:null,stpl:null,dval:null,opt:0,neg:0,algn:0,loc:0,start:0,end:0},w=h=new $({type:0,val:"",algn:""}),N=null,D=null,S={},x=null,E={},R=null,W[1]<W[3]&&(y=W[0],W[2]=W[0],W[0]=y,g=W[1],W[3]=W[1],W[1]=g),Z[1]<Z[3]&&(y=Z[0],Z[2]=Z[0],Z[0]=y,g=Z[1],Z[3]=Z[1],Z[1]=g),l=0,r=0,g=0;4>l&&4>r;)W[l+1]<Z[r+1]?(Q[g]=Z[r],Q[g+1]=Z[r+1],r+=2):(Q[g]=W[l],Q[g+1]=W[l+1],l+=2),g+=2;for(;4>l;)Q[g]=W[l],Q[g+1]=W[l+1],l+=2,g+=2;for(;4>r;)Q[g]=Z[r],Q[g+1]=Z[r+1],r+=2,g+=2;for(a=null,y="",g=0;g<H;)if("\\"!==(p=t[c](g)))if(C=null,Q[0]===t.substr(g,Q[1])?C=Q[0]:Q[2]===t.substr(g,Q[3])?C=Q[2]:Q[4]===t.substr(g,Q[5])?C=Q[4]:Q[6]===t.substr(g,Q[7])&&(C=Q[6]),k===C)g+=U,y.length&&(0===h.node.type?h.node.val+=y:h=new $({type:0,val:y,algn:""},h)),y="";else if(j===C){if(g+=G,u=y,y="",-1<(s=u.indexOf("|"))?(K=u.slice(s+1),u=u.slice(0,s)):K=null,"?"===(p=i?g<H?t[c](g):"":u[c](0))||"*"===p)B=1,"*"===p?(l=1,r=-1):(l=0,r=0),i?(g+=1)<H&&"!"===t[c](g)?(X=1,g+=1):X=0:"!"===u[c](1)?(X=1,u=u.slice(2)):(X=0,u=u.slice(1));else if("{"===p){if(i){for(y="",v=g+1,T=H;v<T&&"}"!==t[c](v);)y+=t[c](v++);g=v+1}else{for(y="",v=1,T=u.length;v<T&&"}"!==u[c](v);)y+=u[c](v++);u=u.slice(v+1)}(y=y.split(",")).length>1?(l=(l=d(y[0])).length?0|+l:0,r=(r=d(y[1])).length?0|+r:-1,B=1):(r=l=(l=d(y[0])).length?0|+l:0,B=0),y="",X=0}else B=0,X=0,l=0,r=0;if(X&&null===K&&(K=""),"@"===(p=u[c](0))?(q=1,u=u.slice(1)):q=0,"."===(p=u[c](0))?(J=1,u=u.slice(1)):J=0,u=(o=-1<u.indexOf(":")?u.split(":"):[u,null])[0],o=o[1],e=-1<u.indexOf(".")?u.split("."):null,x&&!_(E,x)&&(E[x]={}),":="+I===t.substr(g,2+V)&&(g+=2,R=o=o&&o.length?o:"grtpl--"+m(),x&&u.length&&(E[x][u]=o)),!u.length)continue;null==o&&x&&_(E,x)&&_(E[x],u)&&(o=E[x][u]),B&&!P.opt?(P.name=u,P.key=e,P.stpl=o,P.dval=K,P.opt=B,P.neg=X,P.algn=q,P.loc=J,P.start=l,P.end=r,D=new O(null,[u,e,X,l,r,B,J])):B?(l!==r&&P.start===P.end&&(P.name=u,P.key=e,P.stpl=o,P.dval=K,P.opt=B,P.neg=X,P.algn=q,P.loc=J,P.start=l,P.end=r),D=new O(D,[u,e,X,l,r,B,J])):B||null!==P.name||(P.name=u,P.key=e,P.stpl=o,P.dval=K,P.opt=0,P.neg=X,P.algn=q,P.loc=J,P.start=l,P.end=r,D=new O(null,[u,e,X,l,r,0,J])),0===h.node.type&&(h.node.algn=b(h.node.val,0,h.node.val.length)),h=new $({type:1,name:u,key:e,stpl:o,dval:K,opt:B,algn:q,loc:J,start:l,end:r},h)}else if(I===C){if(g+=V,y.length&&(0===h.node.type?h.node.val+=y:h=new $({type:0,val:y,algn:""},h)),y="","#"===t[c](g)){for(v=g+1,T=H;v<T&&z!==t.substr(v,L+1);)y+=t[c](v++);g=v+L+1,0===h.node.type&&(h.node.algn=b(h.node.val,0,h.node.val.length)),h=new $({type:-100,val:y},h),y="";continue}a=new O(a,[h,N,P,D,x,R]),R&&(x=R),R=null,P={type:1,name:null,key:null,stpl:null,dval:null,opt:0,neg:0,algn:0,loc:0,start:0,end:0},D=null,N=h=new $({type:0,val:"",algn:""})}else Y===C?(g+=L,f=h,F=N,M=P,A=D,a?(h=a.value[0],N=a.value[1],P=a.value[2],D=a.value[3],x=a.value[4],R=a.value[5],a=a.prev):h=null,y.length&&(0===f.node.type?f.node.val+=y:f=new $({type:0,val:y,algn:""},f)),y="",R?(S[R]=new $({type:2,name:M.name,key:M.key,loc:M.loc,algn:M.algn,start:M.start,end:M.end,opt_args:null,tpl:F}),R=null):(0===h.node.type&&(h.node.algn=b(h.node.val,0,h.node.val.length)),h=new $({type:-1,name:M.name,key:M.key,loc:M.loc,algn:M.algn,start:M.start,end:M.end,opt_args:A,tpl:F},h))):"\n"===(p=t[c](g++))?(y.length&&(0===h.node.type?h.node.val+=y:h=new $({type:0,val:y,algn:""},h)),y="",0===h.node.type&&(h.node.algn=b(h.node.val,0,h.node.val.length)),h=new $({type:100,val:"\n"},h)):y+=p;else y+=g+1<H?t[c](g+1):"",g+=2;return y.length&&(0===h.node.type?h.node.val+=y:h=new $({type:0,val:y,algn:""},h)),0===h.node.type&&(h.node.algn=b(h.node.val,0,h.node.val.length)),[w,S]},D.align=S,D.main=P,D[i]={constructor:D,id:null,tpl:null,fn:null,_args:null,dispose:function(){return this.id=null,this.tpl=null,this.fn=null,this._args=null,this},parse:function(){return null===this.tpl&&null!==this._args&&(this.tpl=D.multisplit(this._args[0],this._args[1],this._args[2]),this._args=null),this},render:function(t){return null===this.tpl&&this.parse(),D.main(null==t?{}:t,this.tpl[0],this.tpl[1],this.fn)}},j[i]={constructor:j,RE:null,BLOCKS:null,RESERVED:null,OPERATORS:null,FUNCTIONS:null,FN:null,dispose:function(){return this.RE=null,this.BLOCKS=null,this.RESERVED=null,this.OPERATORS=null,this.FUNCTIONS=null,this.FN=null,this},defRE:function(t){if("object"==typeof t)for(var n in t)e.call(t,n)&&(this.RE[n]=t[n]);return this},defBlock:function(t){if("object"==typeof t)for(var n in t)e.call(t,n)&&(this.BLOCKS[n]=t[n]);return this},defReserved:function(t){if("object"==typeof t)for(var n in t)e.call(t,n)&&(this.RESERVED[n]=t[n]);return this},defOp:function(t){var n,i;if("object"==typeof t)for(n in t)e.call(t,n)&&t[n]&&((i=t[n])instanceof st||i instanceof ht?this.OPERATORS[n]=i:i.polymorphic?this.OPERATORS[n]=ht().Polymorphic(i.polymorphic.map(function(t){var n,i;return F(t)?(n=t.check,i=t.op):(n=t[0],i=t[1]),[n,i=i instanceof ht?i:new ht(i.input,i.output,i.otype,i.fixity,i.associativity,i.priority,i.ofixity)]})):this.OPERATORS[n]=new ht(i.input,i.output,i.otype,i.fixity,i.associativity,i.priority,i.ofixity));return this},defFunc:function(t){var n,i;if("object"==typeof t)for(n in t)e.call(t,n)&&t[n]&&(i=t[n],this.FUNCTIONS[n]=i instanceof st||i instanceof ft?i:new ft(i.input,i.output,i.otype,i.priority,i.arity,i.associativity,i.ofixity));return this},defRuntimeFunc:function(t){if("object"==typeof t)for(var n in t)e.call(t,n)&&(this.FN[n]=t[n]);return this}},I.VERSION="1.0.1",I.Configuration=j,I.CONF=null,I.defaultConfiguration=function(t){return arguments.length&&(I.CONF=t),I.CONF};I.COMMA=",",I.LPAREN="(",I.RPAREN=")";var Y=I.NONE=0,U=I.DEFAULT=1,G=I.LEFT=-2,V=I.RIGHT=2,L=I.PREFIX=2,z=I.INFIX=4,K=I.POSTFIX=8,X=I.T_DUM=0,B=I.T_MIX=1,q=I.T_DFT=B,J=I.T_IDE=16,H=I.T_VAR=17,W=I.T_LIT=32,Z=I.T_NUM=33,Q=I.T_STR=34,tt=I.T_REX=35,nt=I.T_BOL=36,it=(I.T_DTM=37,I.T_ARY=38),et=I.T_OP=128,lt=I.T_N_OP=129,rt=I.T_POLY_OP=130,ot=I.T_FUN=131,ut=I.T_EMPTY=1024;function st(t){if(!(this instanceof st))return new st(t);this.alias=t}function at(t,n,i,e,l){if(!(this instanceof at))return new at(t,n,i,e,l);this.type=t,this.arity=n,this.node=i,this.children=e||null,this.pos=l||0}function pt(t,n,i,e){if(!(this instanceof pt))return new pt(t,n,i,e);this.type=t,this.input=n,this.output=i,this.value=e||null,this.priority=1e3,this.parity=0,this.arity=0,this.arity_min=0,this.arity_max=0,this.associativity=U,this.fixity=z,this.parenthesize=!1,this.revert=!1}function ht(t,n,i,e,l,r,o){if(!(this instanceof ht))return new ht(t,n,i,e,l,r,o);t=null==t?"":t,n=null==n?"":n;var u=ht.parse_definition(t);this.type=u[0],this.opdef=u[1],this.parts=u[2],n instanceof D||(n=new D(String(n))),pt.call(this,this.type,this.parts[0],n),this.fixity=null!=e?e:L,this.associativity=null!=l?l:U,this.priority=null!=r?r:1e3,this.arity=u[3],this.arity_min=u[4],this.arity_max=u[5],this.otype=null!=i?i:B,this.ofixity=null!=o?o:this.fixity,this.parenthesize=!1,this.revert=!1,this.morphes=null}function ft(t,n,i,e,l,r,o){if(!(this instanceof ft))return new ft(t,n,i,e,l,r,o);t=null==t?"":t,n=null==n?"":n,ht.call(this,N(t)?[t,null!=l?l:1]:t,n,null!=i?i:B,L,null!=r?r:V,null!=e?e:1,null!=o?o:L),this.type=ot}return I.TYPES={0:"T_DUM",1:"T_MIX",16:"T_IDE",17:"T_VAR",32:"T_LIT",33:"T_NUM",34:"T_STR",35:"T_REX",36:"T_BOL",37:"T_DTM",38:"T_ARY",128:"T_OP",129:"T_N_OP",130:"T_POLY_OP",131:"T_FUN",1024:"T_EMPTY"},I.Tpl=D,I.Alias=st,st.get_entry=function(t,n){if(n&&t&&e.call(t,n)){for(var i=t[n];i instanceof st&&e.call(t,i.alias);){if(i===t[n=i.alias])return!1;i=t[n]}return i}return!1},I.Node=at,at[i]={constructor:at,type:null,arity:null,node:null,children:null,pos:null,op_parts:null,op_def:null,op_index:null,op_next:function(t,n,i,e){var l=0,r=0===this.op_parts.indexOf(t.input);return r&&0===this.op_def[0][0]&&(!1===(l=ht.match_args(this.op_def[0][2],n-1,i,e))?r=!1:(this.arity=l,this.op_def.shift())),r&&(this.op_def.shift(),this.op_parts.shift()),r},op_complete:function(){return!this.op_parts.length},dispose:function(){var t,n,i=this.children;if(i&&(t=i.length))for(n=0;n<t;n++)i[n]&&i[n].dispose();return this.type=null,this.arity=null,this.pos=null,this.node=null,this.op_parts=null,this.op_def=null,this.op_index=null,i=this.children=null,this},toString:function(){var t,n=[],i=this.node,e=this.children?this.children:[],l=e.length;for(t=0;t<l;t++)n.push(e[t].toString());return["Node("+i.type+","+i.arity+"): "+(i.parts?i.parts.join(" "):i.input),"Childs: [",""+n.join("\n"),"]"].join("\n")+"\n"}},at.DFT=function(t,n,i){i=!1!==i,n=n||I.render;for(var e,l,r,o,u=[t],s=[];u.length;)(e=u[0]).children&&e.children.length?(u=e.children.concat(u),e.children=null):(u.shift(),r=(l=e.node).arity,et&l.type&&0===r?r=1:r>s.length&&l.arity_min<=l.arity&&(r=l.arity_min),o=n(l,r?s.splice(s.length-r,r):[]),s.push(o),i&&e.dispose());return u=null,s[0]},I.reduce=function(t,i,e,l,r,o){var u,s,a,p,h,f,c,y=null,d=0;if(l)if(rt===(p=l).type&&(p=p.morph([r,t,i])),lt===p.type){if(!1===(f=p.validate(r,i,t))[0])return o.err=!0,o.msg=f[1],!1;(a=p.node(null,r,i,t)).arity=f[0],e.unshift(a),i.unshift(a)}else{if(e.length&&(d=(y=e[0]).op_index),y&&y.op_next(p,r,i,t)){for(;i.length>d;)c=(s=(u=i.shift()).node).arity,et&s.type&&0===c?c=1:c>t.length&&s.arity_min<=s.arity&&(c=s.arity_min),a=s.node(c?t.splice(t.length-c,c):[],u.pos),t.push(a);if(!y.op_complete())return;e.shift(),i.shift(),p=y.node,y.dispose(),d=e.length?e[0].op_index:0}else if(!1===(f=p.validate(r,i,t))[0])return o.err=!0,o.msg=f[1],!1;if(h=p.fixity,K===h)(c=p.arity)>t.length&&p.arity_min<=t.length&&(c=p.arity_min),a=p.node(c?t.splice(t.length-c,c):[],r),t.push(a);else if(L===h)i.unshift(at(p.otype,p.arity,p,null,r)),et&p.type&&0===p.arity&&t.push(n.node(null,r+1));else{for(;i.length>d;){if(!((s=(u=i.shift()).node).priority<p.priority||s.priority===p.priority&&(s.associativity<p.associativity||s.associativity===p.associativity&&s.associativity<0))){i.unshift(u);break}c=s.arity,et&s.type&&0===c?c=1:c>t.length&&s.arity_min<=s.arity&&(c=s.arity_min),a=s.node(c?t.splice(t.length-c,c):[],u.pos),t.push(a)}i.unshift(at(p.otype,p.arity,p,null,r))}}else for(;i.length;)c=(s=(u=i.shift()).node).arity,et&s.type&&0===c?c=1:c>t.length&&s.arity_min<=s.arity&&(c=s.arity_min),a=s.node(c?t.splice(t.length-c,c):[],u.pos),t.push(a)},I.parse_delimited_block=function(t,n,i,e,l){5>arguments.length&&(l=!0);var r=e,o=!1,u="";for(l=!1!==l,n+=1;n<i&&(r+=u=t.charAt(n++),e!==u||o);)o=!!l&&(!o&&"\\"===u);return r},I.parse_re_flags=function(t,n,i){for(var e,l="",r=!1,o=!1,u=!1,s=0,a=n+s,p=!0;a<i&&p;)"i"!=(e=t.charAt(a++))||r||(l+="i",r=!0),"m"!=e||u||(l+="m",u=!0),"g"!=e||o||(l+="g",o=!0),((s+=1)>=3||!r&&!o&&!u)&&(p=!1);return l},I.parse=function(t,n){var i,l,r,u,s,a,p,h,f,c,y,d,g,_,v,m,T=I.reduce,b=st.get_entry,S=!e.call(n.RE,"t_var"),E=0,O={err:!1,msg:""};for(l=(i=String(t.source)).length,a=0,t._cnt=0,t._symbol_table={},t._cache={},t.variables={},f=[],c=[],y=[],d=0,E=0;a<l;)if(u=i.charAt(a),(g=b(n.BLOCKS,u))&&!1!==(s=g.parse(i,a,l,u))&&(a+=s.length,"function"==typeof g.rest&&(v=g.rest(i,a,l))||(v=""),a+=v.length,!1!==(h=t.t_block(n,s,g.type,v))))d+=1,f.push(h.node(null,d));else if(p=(r=i.slice(a)).match(n.RE.t_spc))a+=p[0].length;else if((p=r.match(n.RE.t_num))&&!1!==(h=t.t_liter(n,p[1],Z)))d+=1,f.push(h.node(null,d)),a+=p[0].length;else{if(p=r.match(n.RE.t_ident)){if(!1!==(h=t.t_liter(n,p[1],J))){d+=1,f.push(h.node(null,d)),a+=p[0].length;continue}if(!1!==(h=t.t_op(n,p[1]))){if(T(f,c,y,h,d+=1,O),O.err){E=1,m=O.msg;break}a+=p[0].length;continue}if(S&&!1!==(h=t.t_var(n,p[1]))){d+=1,f.push(h.node(null,d)),a+=p[0].length;continue}}if(p=r.match(n.RE.t_special)){for(s=p[1],h=!1;s.length>0&&!1===(h=t.t_op(n,s));)s=s.slice(0,-1);if(!1!==h){if(T(f,c,y,h,d+=1,O),O.err){E=1,m=O.msg;break}a+=s.length;continue}}if(S||!(p=r.match(n.RE.t_var))||!1===(h=t.t_var(n,p[1]))){if(p=r.match(n.RE.t_nonspc)){if(!1!==(h=t.t_liter(n,p[1],W))){d+=1,f.push(h.node(null,d)),a+=p[0].length;continue}if(!1!==(h=t.t_op(n,p[1]))){if(T(f,c,y,h,d+=1,O),O.err){E=1,m=O.msg;break}a+=p[0].length;continue}E=1,m='Unknown token "'+p[0]+'"';break}}else d+=1,f.push(h.node(null,d)),a+=p[0].length}if(E||(T(f,c,y),(1!==f.length||c.length>0)&&(E=1,m="Parse Error, Mismatched Parentheses or Operators")),!E)try{_=t.compile(f[0],n)}catch(r){E=1,m="Compilation Error, "+r.toString()}if(y=null,c=null,f=null,t._symbol_table=null,E)throw _=null,t.variables=[],t._cnt=0,t._cache={},t.evaluatorString="",t.evaluator=t.dummy_evaluator,new Error("Xpresion Error: "+m+' at "'+i+'"');return t.variables=o(t.variables),t.evaluatorString=_[0],t.evaluator=_[1],t},I.render=function(t,n){return t.render(n)},I.GET=function(t,n){if(!n||!n.length)return t;for(var i,e=0,l=n.length,r=t;e<l&&(i=n[e++],r)&&null!=r[i];)r=r[i];return e===l?r:null},I.Tok=pt,pt.render=function(t,n){return t instanceof pt?t.render(n||[]):String(t)},pt[i]={constructor:pt,type:null,input:null,output:null,value:null,priority:1e3,parity:0,arity:0,arity_min:0,arity_max:0,associativity:U,fixity:z,parenthesize:!1,revert:!1,dispose:function(){return this.type=null,this.input=null,this.output=null,this.value=null,this.priority=null,this.parity=null,this.arity=null,this.arity_min=null,this.arity_max=null,this.associativity=null,this.fixity=null,this.parenthesize=null,this.revert=null,this},setType:function(t){return this.type=t,this},setParenthesize:function(t){return this.parenthesize=!!t,this},setReverse:function(t){return this.revert=!!t,this},render:function(t){var n=this.output,i=this.parenthesize,e=i?I.LPAREN:"",l=i?I.RPAREN:"";return t||(t=[]),t.unshift(this.input),e+(n instanceof D?n.render({$:t}):String(n))+l},node:function(t,n){return at(this.type,this.arity,this,t||null,n||0)},toString:function(){return String(this.output)}},n=I.EMPTY_TOKEN=pt(ut,"",""),I.Op=ht,ht.Condition=function(t){if(N(t[0]))try{t[0]=w("curr,Xpresion","return "+t[0]+";")}catch(n){t[0]=null}return["function"==typeof t[0]?t[0]:null,t[1]]},ht.parse_definition=function(t){var n,i,e,l,r=[],o=[],u=0,s=0,a=0;for(e=0,l=(t=N(t)?[1,t,1]:[].concat(t)).length;e<l;e++)N(t[e])?(r.push(t[e]),o.push([1,e,t[e]])):(o.push([0,e,t[e]]),u+=n=p(t[e]),a+=n,s+=t[e]);return 1===r.length&&1===o.length?(o=[[0,0,1],[1,1,r[0]],[0,2,1]],s=a=u=2,i=et):i=r.length>1?lt:et,[i,o,r,u,h(0,s),a]},ht.match_args=function(t,n,i,e){for(var l=e.length-1,r=0,o=p(t);(r<o||l>=0)&&n===(l>=0?e[l].pos:-10);)r++,n--,l--;return r>=o?o:t<=0&&0},ht[i]=u(pt[i]),ht[i].otype=null,ht[i].ofixity=null,ht[i].opdef=null,ht[i].parts=null,ht[i].morphes=null,ht[i].dispose=function(){return this.otype=null,this.ofixity=null,this.opdef=null,this.parts=null,this.morphes=null,pt[i].dispose.call(this),this},ht[i].Polymorphic=function(t){return this.type=rt,this.morphes=(t||[]).map(ht.Condition),this},ht[i].morph=function(t){var n,i,e,l,r,o=this.morphes,u=o.length,s=0,a=o[0][1],p=!1;if(t.length<7){for(t.push(!!t[1].length&&t[1][t[1].length-1]),t.push(!!t[2].length&&t[2][0]),t.push(!!t[4]&&t[4].pos+1===t[0]),e=0,l=t[1].length-1,r=0;!e;)if(l>=0&&r<t[2].length&&r+1<t[2].length&&t[2][r+1].node instanceof I.Func)e=t[1][l--].type;else if(r<t[2].length)e=t[2][r++].type;else{if(!(l>=0))break;e=t[1][l--].type}t.push(e)}for(i={POS:t[0],TOKS:t[1],OPS:t[2],TOK:t[3],OP:t[4],PREV_IS_OP:t[5],DEDUCED_TYPE:t[6]};s<u;){if(n=o[s++],!0===Boolean(n[0](i,I))){n=n[1],p=!0;break}n[1].priority>=a.priority&&(a=n[1])}for(p||(n=a);rt===n.type;)n=n.morph(t);return n},ht[i].render=function(t){t&&t.length||(t=["",""]);var n,i=this.otype,e=this.output,l=this.parenthesize,r=l?I.LPAREN:"",o=l?I.RPAREN:"",u=I.COMMA,s=this.ofixity;t.length;return pt(i,n=e instanceof D?r+e.render({$:t})+o:z===s?r+t.join(e)+o:K===s?r+t.join(u)+o+e:e+r+t.join(u)+o,n)},ht[i].validate=function(t,n,i){var e=this.opdef,l="",r=0;return 0===e[0][0]&&!1===(r=ht.match_args(e[0][2],t-1,n,i))&&(l='Operator "'+this.input+'" expecting '+e[0][2]+" prior argument(s)"),[r,l]},ht[i].node=function(t,n,i,e){t=t||[],n=n||0;var l,r=this.otype;return this.revert&&t.reverse(),X===r&&t.length?r=t[0].type:t.length&&(t[0].type=r),l=new at(r,this.arity,this,t,n),lt===this.type&&arguments.length>2&&(l.op_parts=this.parts.slice(1),l.op_def=this.opdef.slice(0===this.opdef[0][0]?2:1),l.op_index=arguments[2].length+1),l},I.Func=ft,ft[i]=u(ht[i]),I[i]={constructor:I,source:null,variables:null,evaluatorString:null,evaluator:null,_cnt:0,_cache:null,_symbol_table:null,dummy_evaluator:null,dispose:function(){return this.dummy_evaluator=null,this.source=null,this.variables=null,this.evaluatorString=null,this.evaluator=null,this._cnt=null,this._symbol_table=null,this._cache=null,this},compile:function(t,n){n||(n=I.defaultConfiguration());var i=at.DFT(t,I.render,!0);return[i,function(t,n,i){return w("Fn,Cache,Xpresion",["return function evaluator(Var){",' "use strict";'," return "+t+";","};"].join("\n"))(n,i,I)}(i,n.FN,this._cache)]},evaluate:function(t){return 1>arguments.length&&(t={}),"function"==typeof this.evaluator?this.evaluator(t):null},debug:function(t){var n=["Expression: "+this.source,"Variables : ["+this.variables.join(",")+"]","Evaluator : "+this.evaluatorString];return arguments.length&&(n.push("Data : "+r(t,null,4)),n.push("Result : "+r(this.evaluate(t)))),n.join("\n")},toString:function(){return"[Xpresion source]: "+String(this.source)},t_liter:function(t,n,i){return Z===i?pt(Z,n,n):st.get_entry(t.RESERVED,n.toLowerCase())},t_block:function(t,n,i,l){if(l=l||"",Q===i)return pt(Q,n,n);if(tt===i){var r,o,u="re_"+n+l;return e.call(this._symbol_table,u)?r=this._symbol_table[u]:(r="re_"+ ++this._cnt,o=n.slice(1,-1),this._cache[r]=new RegExp(o,l||""),this._symbol_table[u]=r),pt(tt,n,"Cache."+r)}return!1},t_var:function(t,n){var i,l=n.split("."),r=l[0];return e.call(this.variables,r)||(this.variables[r]=r),1<l.length?(i='["'+l.slice(1).join('","')+'"]',pt(H,r,'Xpresion.GET(Var["'+r+'"],'+i+")")):pt(H,r,'Var["'+r+'"]')},t_op:function(t,n){var i=!1;return!1===(i=st.get_entry(t.FUNCTIONS,n))&&(i=st.get_entry(t.OPERATORS,n)),i},t_tok:function(t,n){return pt(B,n,n)}},I.init=function(){g||(g=!0,I.defaultConfiguration(j({re:{t_spc:/^(\s+)/,t_nonspc:/^(\S+)/,t_special:/^([*.\\\-+\/\^\$\(\)\[\]|?<:>&~%!#@=_,;{}]+)/,t_num:/^(\d+(\.\d+)?)/,t_ident:/^([a-zA-Z_][a-zA-Z0-9_]*)\b/,t_var:/^\$([a-zA-Z0-9_][a-zA-Z0-9_.]*)\b/},blocks:{"'":{type:Q,parse:I.parse_delimited_block},'"':st("'"),"`":{type:tt,parse:I.parse_delimited_block,rest:I.parse_re_flags}},reserved:{null:pt(J,"null","null"),false:pt(nt,"false","false"),true:pt(nt,"true","true"),infinity:pt(Z,"Infinity","Infinity"),nan:pt(Z,"NaN","NaN"),none:st("null"),inf:st("infinity")},operators:{"(":{input:["(",-1,")"],output:"<$.0>",otype:X,fixity:K,associativity:V,priority:0},")":{input:[-1,")"]},"[":{input:["[",-1,"]"],output:"\\[<$.0>\\]",otype:it,fixity:K,associativity:V,priority:2},"]":{input:[-1,"]"]},",":{input:[1,",",1],output:"<$.0>,<$.1>",otype:q,fixity:z,associativity:G,priority:103},"?":{input:[1,"?",1,":",1],output:"(<$.0>?<$.1>:<$.2>)",otype:B,fixity:z,associativity:V,priority:100},":":{input:[1,":",1]},"!":{input:["!",1],output:"!<$.0>",otype:nt,fixity:L,associativity:V,priority:10},"~":{input:["~",1],output:"~<$.0>",otype:Z,fixity:L,associativity:V,priority:10},"^":{input:[1,"^",1],output:"Math.pow(<$.0>,<$.1>)",otype:Z,fixity:z,associativity:V,priority:11},"*":{input:[1,"*",1],output:"(<$.0>*<$.1>)",otype:Z,fixity:z,associativity:G,priority:20},"/":{input:[1,"/",1],output:"(<$.0>/<$.1>)",otype:Z,fixity:z,associativity:G,priority:20},"%":{input:[1,"%",1],output:"(<$.0>%<$.1>)",otype:Z,fixity:z,associativity:G,priority:20},"+":{polymorphic:[[function(t,n){return t.TOK&&!t.PREV_IS_OP&&t.DEDUCED_TYPE===n.T_ARY},{input:[1,"+",1],output:"Fn.ary_merge(<$.0>,<$.1>)",otype:it,fixity:z,associativity:G,priority:25}],[function(t,n){return t.TOK&&!t.PREV_IS_OP&&t.DEDUCED_TYPE===n.T_STR},{input:[1,"+",1],output:"(<$.0>+String(<$.1>))",otype:Q,fixity:z,associativity:G,priority:25}],[function(t,n){return t.TOK&&!t.PREV_IS_OP},{input:[1,"+",1],output:"(<$.0>+<$.1>)",otype:Z,fixity:z,associativity:G,priority:25}],[function(t,n){return!t.TOK||t.PREV_IS_OP},{input:["+",1],output:"<$.0>",otype:Z,fixity:L,associativity:V,priority:4}]]},"-":{polymorphic:[[function(t,n){return t.TOK&&!t.PREV_IS_OP},{input:[1,"-",1],output:"(<$.0>-<$.1>)",otype:Z,fixity:z,associativity:G,priority:25}],[function(t,n){return!t.TOK||t.PREV_IS_OP},{input:["-",1],output:"(-<$.0>)",otype:Z,fixity:L,associativity:V,priority:4}]]},">>":{input:[1,">>",1],output:"(<$.0>\\>\\><$.1>)",otype:Z,fixity:z,associativity:G,priority:30},"<<":{input:[1,"<<",1],output:"(<$.0>\\<\\<<$.1>)",otype:Z,fixity:z,associativity:G,priority:30},">":{input:[1,">",1],output:"(<$.0>\\><$.1>)",otype:nt,fixity:z,associativity:G,priority:35},"<":{input:[1,"<",1],output:"(<$.0>\\<<$.1>)",otype:nt,fixity:z,associativity:G,priority:35},">=":{input:[1,">=",1],output:"(<$.0>\\>=<$.1>)",otype:nt,fixity:z,associativity:G,priority:35},"<=":{input:[1,"<=",1],output:"(<$.0>\\<=<$.1>)",otype:nt,fixity:z,associativity:G,priority:35},"==":{polymorphic:[[function(t,n){return t.DEDUCED_TYPE===n.T_ARY},{input:[1,"==",1],output:"Fn.ary_eq(<$.0>,<$.1>)",otype:nt,fixity:z,associativity:G,priority:40}],[function(t,n){return!0},{input:[1,"==",1],output:"(<$.0>==<$.1>)",otype:nt,fixity:z,associativity:G,priority:40}]]},"!=":{input:[1,"!=",1],output:"(<$.0>!=<$.1>)",otype:nt,fixity:z,associativity:G,priority:40},is:{input:[1,"is",1],output:"(<$.0>===<$.1>)",otype:nt,fixity:z,associativity:G,priority:40},matches:{input:[1,"matches",1],output:"Fn.match(<$.1>,<$.0>)",otype:nt,fixity:z,associativity:Y,priority:40},in:{input:[1,"in",1],output:"Fn.contains(<$.1>,<$.0>)",otype:nt,fixity:z,associativity:Y,priority:40},"&":{input:[1,"&",1],output:"(<$.0>&<$.1>)",otype:Z,fixity:z,associativity:G,priority:45},"|":{input:[1,"|",1],output:"(<$.0>|<$.1>)",otype:Z,fixity:z,associativity:G,priority:46},"&&":{input:[1,"&&",1],output:"(<$.0>&&<$.1>)",otype:nt,fixity:z,associativity:G,priority:47},"||":{input:[1,"||",1],output:"(<$.0>||<$.1>)",otype:nt,fixity:z,associativity:G,priority:48},or:st("||"),and:st("&&"),not:st("!")},functions:{min:{input:"min",output:"Math.min(<$.0>)",otype:Z},max:{input:"max",output:"Math.max(<$.0>)",otype:Z},pow:{input:"pow",output:"Math.pow(<$.0>)",otype:Z},sqrt:{input:"sqrt",output:"Math.sqrt(<$.0>)",otype:Z},len:{input:"len",output:"Fn.len(<$.0>)",otype:Z},int:{input:"int",output:"parseInt(<$.0>)",otype:Z},float:{input:"float",output:"parseFloat(<$.0>)",otype:Z},str:{input:"str",output:"String(<$.0>)",otype:Q},array:{input:"array",output:"Fn.ary(<$.0>)",otype:it},clamp:{input:"clamp",output:"Fn.clamp(<$.0>)",otype:Z},sum:{input:"sum",output:"Fn.sum(<$.0>)",otype:Z},avg:{input:"avg",output:"Fn.avg(<$.0>)",otype:Z},time:{input:"avg",output:"Fn.time()",otype:Z,arity:0},date:{input:"date",output:"Fn.date(<$.0>)",otype:Q}},runtime:{clamp:function(t,n,i){return n>i?t>n?n:t<i?i:t:t>i?i:t<n?n:t},len:function(t){return t?T(t)||N(t)?t.length:F(t)?o(t).length:1:0},sum:function(){var t,n,i=arguments,e=0;if(i[0]&&T(i[0])&&(i=i[0]),(n=i.length)>0)for(t=0;t<n;t++)e+=i[t];return e},avg:function(){var t,n,i=arguments,e=0;if(i[0]&&T(i[0])&&(i=i[0]),(n=i.length)>0){for(t=0;t<n;t++)e+=i[t];e/=n}return e},ary:function(t){return T(t)?t:[t]},ary_eq:function(t,n){var i,e=t.length;if(e!==n.length)return!1;for(i=0;i<e;i++)if(t[i]!=n[i])return!1;return!0},ary_merge:function(t,n){return[].concat(t).concat(n)},match:function(t,n){return n.test(t)},contains:function(t,n){return T(t)||N(t)?-1<t.indexOf(n):e.call(t,n)},time:A,date:C}})))},I.init(),I});