Comparing version 1.3.1 to 1.3.2
/* | ||
Crox v1.3.1 | ||
Crox v1.3.2 | ||
https://github.com/thx/crox | ||
Released under the MIT license | ||
md5: 8da2a66f77bf4c724bc022772a8cc33d | ||
md5: 1bd1fba7c18a787e720243fe9b83d7d5 | ||
*/ | ||
(function(C){var A=function(){function A(a,g){this.row=a;this.col=g}function F(a,g){var f=a.substring(0,g),e=f.match(/\r\n?|\n/g),d=1;e&&(d+=e.length);f=1+/[^\r\n]*$/.exec(f)[0].length;return new A(d,f)}function C(a){return'"'+a.replace(/[\x00-\x1f"\\\u2028\u2029]/g,function(g){switch(g){case '"':return'\\"';case "\\":return"\\\\";case "\b":return"\\b";case "\f":return"\\f";case "\n":return"\\n";case "\r":return"\\r";case "\t":return"\\t"}return"\\u"+("000"+g.charCodeAt(0).toString(16)).slice(-4)})+ | ||
'"'}function G(a){return eval(a)}function t(a){return a.replace(/^_+/,"$&$&")}function J(a){function g(b,c,h,g){this.tag=b;this.text=c;this.index=h;this.subMatches=g}function f(){}function e(b){for(var c=1,h=[],g=[1],a=[],e=0;e<b.length;++e)g.push(c+=RegExp("|"+b[e][0].source).exec("").length),a.push(b[e][1]||f),h.push("("+b[e][0].source+")");return[RegExp(h.join("|")+"|","g"),g,a]}g.prototype.toString=function(){return this.text};var d=a.$||"$",b={},h;for(h in a)"$"!=h.charAt(0)&&(b[h]=e(a[h])); | ||
return function(h){var c=h.length,l=0,a=[""],e={text:"",index:0,source:h,pushState:function(b){a.push(b)},popState:function(){a.pop()},retract:function(b){l-=b}};return{scan:function(){do{var f;a:{var r=b[a[a.length-1]],k=r[0];k.lastIndex=l;f=k.exec(h);if(""==f[0]){if(l<c)throw Error("lexer error: "+F(h,l)+"\n"+h.slice(l,l+50));f=new g(d,"",l)}else{e.index=l;l=k.lastIndex;for(var k=r[1],q=0;q<k.length;++q)if(f[k[q]]){r=r[2][q].apply(e,f.slice(k[q],k[q+1]));f=new g(r,f[0],e.index,f.slice(k[q]+1,k[q+ | ||
1]));break a}f=void 0}}}while(null==f.tag);return f},getPos:function(b){return F(h,b)}}}}function w(a){var g;a:{switch(a){case "id":case "lit":g=!0;break a}g=!1}return g||"."==a||"[]"==a}function m(a){return w(a)||"!"==a||"u-"==a}function x(a){if(m(a))return!0;switch(a){case "*":case "/":case "%":return!0}return!1}function y(a){if(x(a))return!0;switch(a){case "+":case "-":return!0}return!1}function z(a){if(y(a))return!0;switch(a){case "<":case ">":case "<=":case ">=":return!0}return!1}function B(a){if(z(a))return!0; | ||
switch(a){case "eq":case "ne":return!0}return!1}function D(a){return B(a)||"&&"==a}function H(a){return D(a)||"||"==a}function K(a,g,f){function e(b){c+=b}function d(b){for(var c=0;c<b.length;++c){var a=b[c];switch(a[0]){case "if":e("if("+h(a[1])+"){");d(a[2]);e("}");a[3]&&(e("else{"),d(a[3]),e("}"));break;case "each":var p=a[3]?t(a[3]):"_"+s++,r=h(a[1]);if(/^\w+$/.test(r))var k=r;else k="_"+s++,e("var "+k+" = "+r+";");a[5]?e("for(var "+p+"=0;"+p+"<"+k+".length;"+p+"++){"):e("for(var "+p+" in "+k+ | ||
") {");e("var "+a[4]+" = "+k+"["+p+"];");d(a[2]);e("}");break;case "set":e("var "+t(a[1])+"="+h(a[2])+";");break;case "eval":p=h(a[1]);/^\w+$/.test(p)?r=p:(r="_t",e("_t = "+p+";"));e("if("+r+" !=null)_s += "+((f?!a[2]:a[2])?g+"("+r+")":r)+";");break;case "text":e("_s += "+C(a[1])+";");break;case "inc":break;default:throw Error("unknown stmt: "+a[0]);}}}function b(b,c){var a=h(b);c&&!c(b[0])&&(a="("+a+")");return a}function h(c){switch(c[0]){case "id":return t(c[1]);case "lit":return"string"==typeof c[1]? | ||
C(c[1]):String(c[1]);case ".":return b(c[1],w)+"."+c[2];case "[]":return b(c[1],w)+"["+h(c[2])+"]";case "()":var a=[];if(c[2])for(var g=0;g<c[2].length;++g)a.push(h(c[2][g]));return b(c[1],w)+"("+a.join(",")+")";case "!":return"!"+b(c[1],m);case "u-":return"- "+b(c[1],m);case "*":case "/":case "%":return b(c[1],x)+c[0]+b(c[2],m);case "+":case "-":return b(c[1],y)+c[0]+" "+b(c[2],x);case "<":case ">":case "<=":case ">=":return b(c[1],z)+c[0]+b(c[2],y);case "==":case "!=":case "===":case "!==":return b(c[1], | ||
B)+c[0]+b(c[2],z);case "&&":return b(c[1],D)+"&&"+b(c[2],B);case "||":return b(c[1],H)+"||"+b(c[2],D);default:throw Error("unknown expr: "+c[0]);}}var s=0,c="";d(a[1]);return c}function E(a){return L(M(a))}function I(a,g){var f=E(a),e;g&&(e=g.htmlEncode);a=K(f,e||"_htmlEncode",!0);f="";e||(f="var _obj = { '<': '<', '>': '>', '&': '&', '\"': '"' };\tfunction _htmlEncode(s) {\t\treturn String(s).replace(/[<>&\"]/g, function(c) {\t\t\treturn _obj[c];\t\t});\t}");return Function("root", | ||
f+("var _t,_s = '';"+a+"return _s;"))}function N(a,g){function f(a){for(var e=0;e<a.length;++e){var c=a[e];switch(c[0]){case "if":var l="if("+d(c[1])+"){";b+=l;f(c[2]);b+="}";c[3]&&(b+="else{",f(c[3]),b+="}");break;case "each":l="foreach("+d(c[1])+" as "+(c[3]?"$crox_"+t(c[3])+"=>":"")+("$crox_"+t(c[4]))+")";b+=l;b+="{";f(c[2]);b+="}";break;case "set":c="$crox_"+t(c[1])+" = "+d(c[2])+";";b+=c;break;case "eval":l=d(c[1]);b+="crox_echo("+l+", "+(g?!c[2]:c[2])+");";break;case "text":l=c[1];/<\?(?:php)?|\?>/.test(l)? | ||
(c="echo "+("'"+String(c[1]).replace(/['\\]/g,"\\$&")+"'")+";",b+=c):b+="?>"+l+"<?php ";break;case "inc":c="include '"+c[1].replace(/\.\w+$/,".php")+"';";b+=c;break;default:throw Error("unknown stmt: "+c[0]);}}}function e(b,a){var c=d(b);a&&!a(b[0])&&(c="("+c+")");return c}function d(b){switch(b[0]){case "id":return"$crox_"+t(b[1]);case "lit":return"string"==typeof b[1]?"'"+String(b[1]).replace(/['\\]/g,"\\$&")+"'":String(b[1]);case ".":return e(b[1],w)+"->"+b[2];case "[]":return e(b[1],w)+"["+d(b[2])+ | ||
"]";case "!":return"!crox_ToBoolean("+e(b[1],m)+")";case "u-":return"- "+e(b[1],m);case "*":case "/":case "%":return e(b[1],x)+b[0]+e(b[2],m);case "+":return"crox_plus("+e(b[1],null)+", "+e(b[2],null)+")";case "-":return e(b[1],y)+"- "+e(b[2],x);case "<":case ">":case "<=":case ">=":return e(b[1],z)+b[0]+e(b[2],y);case "==":case "!=":case "===":case "!==":return e(b[1],B)+b[0]+e(b[2],z);case "&&":return"crox_logical_and("+e(b[1],null)+", "+e(b[2],null)+")";case "||":return"crox_logical_or("+e(b[1], | ||
null)+", "+e(b[2],null)+")";default:throw Error("unknown expr: "+b[0]);}}var b="";f(a[1]);b="?>"==b.slice(0,2)?b.slice(2):"<?php "+b;return b="<?php "==b.slice(-6)?b.slice(0,-6):b+"?>"}function O(a){function g(b){return"$crox_"+t(b)}function f(b){s+=b}function e(c){for(var a=0;a<c.length;++a){var d=c[a];switch(d[0]){case "if":f("#if("+b(d[1])+")");e(d[2]);d[3]&&(f("#{else}"),e(d[3]));f("#{end}");break;case "each":++h;var s=b(d[1]);if(/^$\w+$/.test(s))var p=s;else p="$list"+(1==h?"":h),f("#set ("+ | ||
p+" = "+s+")");d[5]?(f("#foreach("+g(d[4])+" in "+p+")"),d[3]&&f("#set("+g(d[3])+" = $velocityCount - 1)")):d[3]?(f("#foreach("+g(d[3])+" in "+p+".keySet())"),f("#set("+g(d[4])+" ="+p+".get("+g(d[3])+"))")):f("#foreach("+g(d[4])+" in "+p+")");e(d[2]);f("#{end}");--h;break;case "set":f("#set ("+g(d[1])+"="+b(d[2])+")");break;case "eval":d=b(d[1]);/^$\w+$/.test(d)?f("$!{"+d.slice(1)+"}"):f("#set($t = "+d+")$!{t}");break;case "text":f(d[1].replace(/\$/g,"$${dollar}").replace(/#/g,"$${sharp}"));break; | ||
case "inc":f("#parse('"+d[1].replace(/\.\w+$/,".vm")+"')");break;default:throw Error("unknown stmt: "+d[0]);}}}function d(c,a){var g=b(c);a&&!a(c[0])&&(g="("+g+")");return g}function b(c){switch(c[0]){case "id":return g(c[1]);case "lit":return"string"==typeof c[1]?(c=c[1],c=-1==c.indexOf("'")?"'"+c+"'":"('"+c.split("'").join("'+\"'\"+'")+"')",c):String(c[1]);case ".":return d(c[1],w)+"."+c[2];case "[]":return d(c[1],w)+"["+b(c[2])+"]";case "!":return"!"+d(c[1],m);case "u-":if("u-"==c[1][0])throw Error("\u7981\u6b62\u4e24\u4e2a\u8d1f\u53f7\u8fde\u7528"); | ||
return"-"+d(c[1],m);case "*":case "/":case "%":return d(c[1],x)+c[0]+d(c[2],m);case "+":case "-":return d(c[1],y)+c[0]+" "+d(c[2],x);case "<":case ">":case "<=":case ">=":return d(c[1],z)+c[0]+d(c[2],y);case "==":case "!=":case "===":case "!==":return d(c[1],B)+c[0].slice(0,2)+d(c[2],z);case "&&":return d(c[1],D)+"&&"+d(c[2],B);case "||":return d(c[1],H)+"||"+d(c[2],D);default:throw Error("unknown expr: "+c[0]);}}var h=0,s="#set($dollar='$')#set($sharp='#')";e(a[1]);return s}A.prototype.toString= | ||
function(){return"("+this.row+","+this.col+")"};var M=function(){var a=[[/\s+/],[/\/\/[^\r\n]*|\/\*[\s\S]*?\*\//],[/[A-Za-z_]\w*/,function(a){switch(a){case "true":case "false":return"boolean";case "set":case "include":return a;default:if(-1!=" abstract boolean break byte case catch char class const continue debugger default delete do double else enum export extends final finally float for function goto if implements import in instanceof int interface let long native new package private protected public return short static super switch synchronized this throw throws transient try typeof var void volatile while with yield ".indexOf(" "+ | ||
a+" ")||"null"==a)throw Error("Reserved: "+a+" "+F(this.source,this.index));return"realId"}}],[/"(?:[^"\\]|\\[\s\S])*"|'(?:[^'\\]|\\[\s\S])*'/,function(a){return"string"}],[/\d+(?:\.\d+)?(?:e-?\d+)?/,function(a){return"number"}],[function(a){a.sort().reverse();for(var f=0;f<a.length;++f)a[f]=a[f].replace(/[()*+?.[\]|]/g,"\\$&");return RegExp(a.join("|"))}("! % && ( ) * + - . / < <= = > >= [ ] || === !== == != ,".split(" ")),function(a){return/[*/%]/.test(a)?"mul":/[<>]/.test(a)?"rel":/[!=]=/.test(a)? | ||
"eq":a}]];return J({"":[[/(?:(?!{{)[\s\S])+/,function(a){return"text"}],[/{{{/,function(a){this.pushState(a);return a}],[/{{(?:\/if|else|\/each|\/forin|\/raw)}}/,function(a){return a}],[/{{#raw}}/,function(a){this.pushState("raw");return a}],[/{{(?:#(?:if|each|forin)(?=\s))?/,function(a){this.pushState("{{");return a}]],raw:[[/(?:(?!{{\/raw}})[\s\S])+/,function(a){this.popState();return"rawtext"}]],"{{":a.concat([[/}}/,function(a){this.popState();return a}]]),"{{{":a.concat([[/}}}/,function(a){this.popState(); | ||
return a}]])})}(),L=function(){return function(a){function g(b,a){return h[b][a]}for(var f=a.nStart,e=a.tSymbols,d={},b=0;b<e.length;++b)d[e[b]]=b;var h=a.tAction,s=a.tGoto,c=a.tRules,l=a.tFuncs,m=a.actionIndex;m&&(g=function(b,a){var c=h[m[b]];return c[a]||c._});return function(b,a){function h(a){throw Error("Syntax error: "+b.getPos(m.index)+(a?"\n"+a:""));}var k=0,q=[0],m=b.scan(),u=[],t={get:function(b){return u[u.length+b]},set:function(b,a){u[u.length+b]=a}};if(a)for(var n in a)t[n]=a[n];for(;;)if(n= | ||
g(k,d[m.tag]))if(0<n)q.push(k=n),u.push(m),m=b.scan();else if(0>n&&-32768<n){n=-n;var k=c[n],v=k.length-1;q.length-=v;k=s[q[q.length-1]][k[0]-f];q.push(k);l[n]?(n=l[n].apply(t,u.splice(u.length-v,v)),u.push(n)):1!=v&&u.splice(u.length-v,v,null)}else return m.tag!=e[0]&&h(),u[0];else{n=[];for(v=0;v<f;++v)g(k,v)&&n.push(e[v]);h("find "+m.tag+"\nexpect "+n.join(" "))}}}({nStart:37,tSymbols:"$ ! && ( ) + , - . = [ ] boolean eq include mul number rawtext realId rel set string text {{ {{#each {{#forin {{#if {{#raw}} {{/each}} {{/forin}} {{/if}} {{/raw}} {{else}} {{{ || }} }}} AdditiveExpression EqualityExpression LogicalAndExpression LogicalOrExpression MemberExpression MultiplicativeExpression PrimaryExpression RelationalExpression UnaryExpression _text args epsilon expr id name program statement statements texts".split(" "), | ||
tAction:[{_:-2},{_:-32768},{22:3,23:4,24:5,25:6,26:7,27:8,33:9,_:-1},{_:-19},{1:13,3:14,7:15,12:16,14:17,16:18,18:19,20:20,21:21,_:0},{1:13,3:14,7:15,12:16,14:33,16:18,18:19,20:34,21:21,_:0},{17:38,_:0},{_:-17},{_:-3},{22:3,27:8,_:-13},{_:-26},{21:44,_:-23},{_:-25},{_:-21},{14:33,18:19,20:34,_:-22},{_:-24},{5:46,7:47,_:-44},{13:48,_:-48},{2:49,_:-50},{34:50,_:-52},{3:51,8:52,10:53,_:-36},{15:54,_:-41},{_:-29},{19:55,_:-46},{_:-39},{35:56,_:0},{_:-27},{_:-23},{_:-22},{14:33,18:19,20:34,21:57,_:0}, | ||
{35:61,_:0},{31:62,_:0},{36:63,_:0},{_:-18},{_:-37},{4:64,_:0},{_:-38},{35:65,_:0},{9:66,_:0},{1:13,3:14,7:15,12:16,14:33,16:18,18:19,20:34,21:21,_:-53},{14:33,18:19,20:34,_:0},{_:-11},{_:-15},{_:-16},{14:33,18:19,20:34,21:57,_:-53},{_:-20},{_:-12},{_:-28},{_:-14},{15:54,_:-42},{15:54,_:-43},{19:55,_:-47},{13:48,_:-49},{2:49,_:-51},{4:85,6:86,_:0},{4:87,_:0},{_:-34},{_:-30},{11:88,_:0},{_:-40},{5:46,7:47,_:-45},{35:89,_:0},{35:90,_:0},{35:91,_:0},{35:92,_:0},{22:3,23:4,24:5,25:6,26:7,27:8,30:93,32:94, | ||
33:9,_:0},{35:95,_:0},{_:-33},{_:-32},{_:-31},{_:-4},{_:-10},{_:-35},{22:3,23:4,24:5,25:6,26:7,27:8,28:102,33:9,_:0},{22:3,23:4,24:5,25:6,26:7,27:8,28:103,33:9,_:0},{22:3,23:4,24:5,25:6,26:7,27:8,29:104,33:9,_:0},{22:3,23:4,24:5,25:6,26:7,27:8,29:105,33:9,_:0},{22:3,23:4,24:5,25:6,26:7,27:8,30:106,33:9,_:0},{_:-6},{_:-7},{_:-8},{_:-9},{_:-5}],actionIndex:[0,1,2,3,4,5,5,5,6,5,7,8,9,5,5,5,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,29,30,31,32,33,34,35,36,37,38,5,5,5,5,5,39,40,5,5,5, | ||
41,42,43,44,44,0,45,46,47,48,5,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,5,68,69,0,0,0,0,70,0,71,72,73,74,75,76,77,78,79,80,81,82],tGoto:[{15:1,17:2},,{9:10,16:11,18:12},,{0:22,1:23,2:24,3:25,4:26,5:27,6:28,7:29,8:30,12:31,13:32},{0:22,1:23,2:24,3:25,4:26,5:27,6:28,7:29,8:30,12:35,13:32},{0:22,1:23,2:24,3:25,4:26,5:27,6:28,7:29,8:30,12:36,13:32},{0:22,1:23,2:24,3:25,4:26,5:27,6:28,7:29,8:30,12:37,13:32},,{0:22,1:23,2:24,3:25,4:26,5:27,6:28,7:29,8:30,12:39,13:32},,,{9:40},{4:26,6:28, | ||
8:41,13:32},{0:22,1:23,2:24,3:25,4:26,5:27,6:28,7:29,8:30,12:42,13:32},{4:26,6:28,8:43,13:32},,,,,{13:45},,,,,,,,,,,,,,,{13:58,14:59},{13:58,14:60},,,,,,,,,,{4:26,5:67,6:28,8:30,13:32},{4:26,5:68,6:28,8:30,13:32},{0:22,4:26,5:27,6:28,7:69,8:30,13:32},{0:22,1:70,4:26,5:27,6:28,7:29,8:30,13:32},{0:22,1:23,2:71,4:26,5:27,6:28,7:29,8:30,13:32},{0:22,1:23,2:24,3:25,4:26,5:27,6:28,7:29,8:30,10:72,11:73,12:74,13:32},{13:75},{0:22,1:23,2:24,3:25,4:26,5:27,6:28,7:29,8:30,12:76,13:32},{4:26,6:28,8:77,13:32}, | ||
{0:78,4:26,5:27,6:28,8:30,13:32},,,,{11:79,13:58,14:80},{11:81,13:58,14:82},{17:83},,,,,{0:22,1:23,2:24,3:25,4:26,5:27,6:28,7:29,8:30,12:84,13:32},,,,,,,,,,,,,,,,,{9:10,16:11,18:12},,,{0:22,1:23,2:24,3:25,4:26,5:27,6:28,7:29,8:30,12:96,13:32},,,{17:97},{17:98},{17:99},{17:100},,{17:101},,,{9:10,16:11,18:12},{9:10,16:11,18:12},{9:10,16:11,18:12},{9:10,16:11,18:12},{9:10,16:11,18:12}],tRules:[[56,52],[52,54],[54],[54,54,53],[53,26,49,35,54,30],[53,26,49,35,54,32,54,30],[53,24,49,51,48,35,54,28],[53, | ||
24,49,51,51,35,54,28],[53,25,49,51,48,35,54,29],[53,25,49,51,51,35,54,29],[53,23,20,50,9,49,35],[53,23,49,35],[53,33,49,36],[53,55],[53,23,14,21,35],[51,21],[51,50],[55,46],[55,55,46],[46,22],[46,27,17,31],[50,18],[50,20],[50,14],[43,21],[43,16],[43,12],[43,50],[43,3,49,4],[41,43],[41,41,8,50],[41,41,10,49,11],[41,41,3,48,4],[41,41,3,47,4],[47,49],[47,47,6,49],[45,41],[45,1,45],[45,7,45],[42,45],[42,42,15,45],[37,42],[37,37,5,42],[37,37,7,42],[44,37],[44,44,19,37],[38,44],[38,38,13,44],[39,38],[39, | ||
39,2,38],[40,39],[40,40,34,39],[49,40],[48]],tFuncs:function(){function a(b,a,d,c,e,f,g){return["each",a,f,c,d,!0]}function g(b,a,d,c,e,f,g){return["each",a,f,c,d,!1]}function f(b){return b.text}function e(b,a,d,c){return["()",b,d]}function d(b,a,d){return[a.text,b,d]}return[,function(b){return["prog",b]},function(){return[]},function(b,a){b.push(a);return b},function(b,a,d,c,e){return["if",a,c]},function(b,a,d,c,e,f,g){return["if",a,c,f]},a,a,g,g,function(b,a,d,c,e,f){return["set",d.text,e]},function(b, | ||
a,d){return["eval",a,!1]},function(b,a,d){return["eval",a,!0]},function(a){return["text",a]},function(a,d,e,c){return["inc",G(e.text)]},function(a){return G(a.text)},f,function(a){return a},function(a,d){return a+d},f,function(a,d,e){return d.text},,,,function(a){return["lit",G(a.text)]},function(a){return["lit",+a.text]},function(a){return["lit","true"==a.text]},function(a){return["id",a.text]},function(a,d,e){return d},,function(a,d,e){return[".",a,e.text]},function(a,d,e,c){return["[]",a,e]},e, | ||
e,function(a){return[a]},function(a,d,e){a.push(e);return a},,function(a,d){return["!",d]},function(a,d){return["u-",d]},,d,,d,d,,d,,d,,d,,d]}()})}();return{parse:E,compile:I,render:function(a,g){return I(a)(g)},compileToPhp:function(a){return N(E(a),!0)},compileToVM:function(a,g){return O(E(a))},version:"1.3.1"}}();"object"==typeof module&&module&&"object"==typeof module.exports?module.exports=A:"function"==typeof define&&(define.amd||define.cmd)?define(function(){return A}):"undefined"!=typeof KISSY&& | ||
KISSY.add(function(){return A});C&&(C.Crox=A)})(this); | ||
(function(C){var x=function(){function x(a,f){this.row=a;this.col=f}function C(a,f){var d=a.substring(0,f),b=d.match(/\r\n?|\n/g),h=1;b&&(h+=b.length);d=1+/[^\r\n]*$/.exec(d)[0].length;return new x(h,d)}function M(a){return'"'+a.replace(/[\x00-\x1f"\\\u2028\u2029]/g,function(a){switch(a){case '"':return'\\"';case "\\":return"\\\\";case "\b":return"\\b";case "\f":return"\\f";case "\n":return"\\n";case "\r":return"\\r";case "\t":return"\\t"}return"\\u"+("000"+a.charCodeAt(0).toString(16)).slice(-4)})+ | ||
'"'}function L(a){return eval(a)}function r(a){return a.replace(/^_+/,"$&$&")}function P(a){function f(a,c,f,b,p,e){this.tag=a;this.text=c;this.index=f;this.subMatches=b;this.end=p;this.pos=e}function d(){}function b(a){for(var c=1,f=[],b=[1],p=[],e=0;e<a.length;++e)b.push(c+=RegExp("|"+a[e][0].source).exec("").length),p.push(a[e][1]||d),f.push("("+a[e][0].source+")");return[RegExp(f.join("|")+"|","g"),b,p]}f.prototype.toString=function(){return this.text};var h=a.$||"$",e={},p;for(p in a)"$"!=p.charAt(0)&& | ||
(e[p]=b(a[p]));return function(a){var c=a.length,b=0,p=[""],d={text:"",index:0,source:a,pushState:function(c){p.push(c)},popState:function(){p.pop()},retract:function(c){b-=c}},v=new x(1,1),y=/\r\n?|\n/g,m=/[^\r\n\u2028\u2029]*$/;return{scan:function(){do{var t;a:{var A=e[p[p.length-1]],l=A[0];l.lastIndex=b;t=l.exec(a);if(""==t[0]){if(b<c)throw Error("lexer error: "+v+"\n"+a.slice(b,b+50));t=new f(h,"",b,null,b,v)}else{d.index=b;b=l.lastIndex;for(var l=A[1],u=0;u<l.length;++u)if(t[l[u]]){A=A[2][u].apply(d, | ||
t.slice(l[u],l[u+1]));t=null==A?null:new f(A,t[0],d.index,t.slice(l[u]+1,l[u+1]),b,v);break a}t=void 0}}if(null!=t)return A=v.row,l=v.col,u=(u=t.text.match(y))?u.length:0,A+=u,l=0==u?l+t.text.length:m.exec(t.text)[0].length+1,v=new x(A,l),t}while(1)},GetCurrentPosition:function(){return v},getPos:function(c){return C(a,c)}}}}function w(a){var f;a:{switch(a){case "id":case "lit":f=!0;break a}f=!1}return f||"."==a||"[]"==a}function y(a){return w(a)||"!"==a||"u-"==a}function E(a){if(y(a))return!0;switch(a){case "*":case "/":case "%":return!0}return!1} | ||
function G(a){if(E(a))return!0;switch(a){case "+":case "-":return!0}return!1}function H(a){if(G(a))return!0;switch(a){case "<":case ">":case "<=":case ">=":return!0}return!1}function I(a){if(H(a))return!0;switch(a){case "eq":case "ne":return!0}return!1}function J(a){return I(a)||"&&"==a}function N(a){return J(a)||"||"==a}function Q(a,f,d){function b(c){v.push(c)}function h(c,a){c.pos=a;return c}function e(a){for(var k=0;k<a.length;++k){var l=a[k];switch(l[0]){case "if":b("if(");b(c(l[1]));b("){"); | ||
e(l[2]);b("}");l[3]&&(b("else{"),e(l[3]),b("}"));break;case "each":var g=l[3]?r(l[3]):"_"+x++,m=c(l[1]),n=p(m);/^\w+$/.test(n)||(n="_"+x++,b("var "+n+" = "),b(m),b(";"));l[5]?(b("for(var "+g+"=0;"+g+"<"),b(c([".",h(["t",n],l[1].pos),"length"])),b(";"+g+"++){")):b("for(var "+g+" in "+n+") {");b("var "+l[4]+" = ");b(c(["[]",h(["t",n],l[1].pos),["t",g]]));b(";");e(l[2]);b("}");break;case "set":b("var "+r(l[1])+"=");b(c(l[2]));b(";");break;case "eval":m=c(l[1]);n=p(m);/^\w+$/.test(n)?g=n:(g="_t",b("_t = "), | ||
b(m),b(";"));b("if("+g+" !=null)_s += "+((d?!l[2]:l[2])?f+"("+g+")":g)+";");break;case "text":b("_s += "+M(l[1])+";");break;case "inc":break;default:throw Error("unknown stmt: "+l[0]);}}}function p(c){if("string"==typeof c)return c;if(c instanceof Array){for(var a=[],b=0;b<c.length;++b)a.push(p(c[b]));return a.join("")}throw Error("unknown type");}function k(a,b){var f=c(a);b&&!b(a[0])&&(f=["(",f,")"]);return f}function c(c){return h(n(c),c.pos)}function n(a){switch(a[0]){case "t":return a[1];case "id":return r(a[1]); | ||
case "lit":return"string"==typeof a[1]?M(a[1]):String(a[1]);case ".":return[k(a[1],w),".",a[2]];case "[]":return[k(a[1],w),"[",c(a[2])+"]"];case "()":var b=[k(a[1],w),"("];if(a[2])for(var f=0;f<a[2].length;++f)0<f&&b.push(","),b.push(c(a[2][f]));b.push(")");return b;case "!":return["!",k(a[1],y)];case "u-":return["- ",k(a[1],y)];case "*":case "/":case "%":return[k(a[1],E),a[0],k(a[2],y)];case "+":case "-":return[k(a[1],G),a[0]," ",k(a[2],E)];case "<":case ">":case "<=":case ">=":return[k(a[1],H), | ||
a[0],k(a[2],G)];case "==":case "!=":case "===":case "!==":return[k(a[1],I),a[0],k(a[2],H)];case "&&":return[k(a[1],J),"&&",k(a[2],I)];case "||":return[k(a[1],N),"||",k(a[2],J)];default:throw Error("unknown expr: "+a[0]);}}function g(a){"string"==typeof a&&(m+=a);if(a instanceof Array){a.pos&&C.push([m.length,a.pos]);for(var c=0;c<a.length;++c)g(a[c])}}var x=0,v=[];e(a[1]);var C=[],m="";g(v);a=new String(m);a.posLog=C;return a}function K(a){return R(S(a))}function O(a,f){var d=K(a),b;f&&(b=f.htmlEncode); | ||
a=Q(d,b||"_htmlEncode",!0);d="";b||(d="var _obj = { '<': '<', '>': '>', '&': '&', '\"': '"' };\r\n\tfunction _htmlEncode(s) {\r\n\t\treturn String(s).replace(/[<>&\"]/g, function(c) {\r\n\t\t\treturn _obj[c];\r\n\t\t});\r\n\t}");d+="var _t,_s = '';";f&&f.debug?(b=a.posLog,d=d+"try{\n"+("eval("+JSON.stringify(a)+");"),d+="}catch(_e){throw "+function(a,b){for(var f=a.stack,d=f.split(/\r\n?|\n/),d=+/:(\d+):(\d+)\)$/m.exec(d[1])[2],c=null,n=0;n<b.length;++n)if(b[n][0]+1>=d){c=b[n][1];break}d= | ||
c.pos;return Error("CroxError: "+("("+d.row+","+d.col+")")+"\n"+f)}+"(_e,"+JSON.stringify(b)+");}"):d+=a;d+="return _s;";return Function("root",d)}function T(a,f){function d(a){for(var b=0;b<a.length;++b){var c=a[b];switch(c[0]){case "if":var n="if("+h(c[1])+"){";e+=n;d(c[2]);e+="}";c[3]&&(e+="else{",d(c[3]),e+="}");break;case "each":n="foreach("+h(c[1])+" as "+(c[3]?"$crox_"+r(c[3])+"=>":"")+("$crox_"+r(c[4]))+")";e+=n;e+="{";d(c[2]);e+="}";break;case "set":c="$crox_"+r(c[1])+" = "+h(c[2])+";";e+= | ||
c;break;case "eval":n=h(c[1]);e+="crox_echo("+n+", "+(f?!c[2]:c[2])+");";break;case "text":n=c[1];/<\?(?:php)?|\?>/.test(n)?(c="echo "+("'"+String(c[1]).replace(/['\\]/g,"\\$&")+"'")+";",e+=c):e+="?>"+n+"<?php ";break;case "inc":c="include '"+c[1].replace(/\.\w+$/,".php")+"';";e+=c;break;default:throw Error("unknown stmt: "+c[0]);}}}function b(a,b){var c=h(a);b&&!b(a[0])&&(c="("+c+")");return c}function h(a){switch(a[0]){case "id":return"$crox_"+r(a[1]);case "lit":return"string"==typeof a[1]?"'"+ | ||
String(a[1]).replace(/['\\]/g,"\\$&")+"'":String(a[1]);case ".":return b(a[1],w)+"->"+a[2];case "[]":return b(a[1],w)+"["+h(a[2])+"]";case "!":return"!crox_ToBoolean("+b(a[1],y)+")";case "u-":return"- "+b(a[1],y);case "*":case "/":case "%":return b(a[1],E)+a[0]+b(a[2],y);case "+":return"crox_plus("+b(a[1],null)+", "+b(a[2],null)+")";case "-":return b(a[1],G)+"- "+b(a[2],E);case "<":case ">":case "<=":case ">=":return b(a[1],H)+a[0]+b(a[2],G);case "==":case "!=":case "===":case "!==":return b(a[1], | ||
I)+a[0]+b(a[2],H);case "&&":return"crox_logical_and("+b(a[1],null)+", "+b(a[2],null)+")";case "||":return"crox_logical_or("+b(a[1],null)+", "+b(a[2],null)+")";default:throw Error("unknown expr: "+a[0]);}}var e="";d(a[1]);e="?>"==e.slice(0,2)?e.slice(2):"<?php "+e;return e="<?php "==e.slice(-6)?e.slice(0,-6):e+"?>"}function U(a){function f(a){return"$crox_"+r(a)}function d(a){k+=a}function b(a){for(var n=0;n<a.length;++n){var g=a[n];switch(g[0]){case "if":d("#if("+e(g[1])+")");b(g[2]);g[3]&&(d("#{else}"), | ||
b(g[3]));d("#{end}");break;case "each":++p;var h=e(g[1]);if(/^$\w+$/.test(h))var k=h;else k="$list"+(1==p?"":p),d("#set ("+k+" = "+h+")");g[5]?(d("#foreach("+f(g[4])+" in "+k+")"),g[3]&&d("#set("+f(g[3])+" = $velocityCount - 1)")):g[3]?(d("#foreach("+f(g[3])+" in "+k+".keySet())"),d("#set("+f(g[4])+" ="+k+".get("+f(g[3])+"))")):d("#foreach("+f(g[4])+" in "+k+")");b(g[2]);d("#{end}");--p;break;case "set":d("#set ("+f(g[1])+"="+e(g[2])+")");break;case "eval":g=e(g[1]);/^$\w+$/.test(g)?d("$!{"+g.slice(1)+ | ||
"}"):d("#set($t = "+g+")$!{t}");break;case "text":d(g[1].replace(/\$/g,"$${dollar}").replace(/#/g,"$${sharp}"));break;case "inc":d("#parse('"+g[1].replace(/\.\w+$/,".vm")+"')");break;default:throw Error("unknown stmt: "+g[0]);}}}function h(a,b){var f=e(a);b&&!b(a[0])&&(f="("+f+")");return f}function e(a){switch(a[0]){case "id":return f(a[1]);case "lit":return"string"==typeof a[1]?(a=a[1],a=-1==a.indexOf("'")?"'"+a+"'":"('"+a.split("'").join("'+\"'\"+'")+"')",a):String(a[1]);case ".":return h(a[1], | ||
w)+"."+a[2];case "[]":return h(a[1],w)+"["+e(a[2])+"]";case "!":return"!"+h(a[1],y);case "u-":if("u-"==a[1][0])throw Error("\u7981\u6b62\u4e24\u4e2a\u8d1f\u53f7\u8fde\u7528");return"-"+h(a[1],y);case "*":case "/":case "%":return h(a[1],E)+a[0]+h(a[2],y);case "+":case "-":return h(a[1],G)+a[0]+" "+h(a[2],E);case "<":case ">":case "<=":case ">=":return h(a[1],H)+a[0]+h(a[2],G);case "==":case "!=":case "===":case "!==":return h(a[1],I)+a[0].slice(0,2)+h(a[2],H);case "&&":return h(a[1],J)+"&&"+h(a[2], | ||
I);case "||":return h(a[1],N)+"||"+h(a[2],J);default:throw Error("unknown expr: "+a[0]);}}var p=0,k="#set($dollar='$')#set($sharp='#')";b(a[1]);return k}x.prototype.toString=function(){return"("+this.row+","+this.col+")"};var S=function(){var a=[[/\s+/],[/\/\/[^\r\n]*|\/\*[\s\S]*?\*\//],[/[A-Za-z_]\w*/,function(a){switch(a){case "true":case "false":return"boolean";case "set":case "include":return a;default:if(-1!=" abstract boolean break byte case catch char class const continue debugger default delete do double else enum export extends final finally float for function goto if implements import in instanceof int interface let long native new package private protected public return short static super switch synchronized this throw throws transient try typeof var void volatile while with yield ".indexOf(" "+ | ||
a+" ")||"null"==a)throw Error("Reserved: "+a+" "+C(this.source,this.index));return"realId"}}],[/"(?:[^"\\]|\\[\s\S])*"|'(?:[^'\\]|\\[\s\S])*'/,function(a){return"string"}],[/\d+(?:\.\d+)?(?:e-?\d+)?/,function(a){return"number"}],[function(a){a.sort().reverse();for(var d=0;d<a.length;++d)a[d]=a[d].replace(/[()*+?.[\]|]/g,"\\$&");return RegExp(a.join("|"))}("! % && ( ) * + - . / < <= = > >= [ ] || === !== == != ,".split(" ")),function(a){return/[*/%]/.test(a)?"mul":/[<>]/.test(a)?"rel":/[!=]=/.test(a)? | ||
"eq":a}]];return P({"":[[/(?:(?!{{)[\s\S])+/,function(a){return"text"}],[/{{{/,function(a){this.pushState(a);return a}],[/{{(?:\/if|else|\/each|\/forin|\/raw)}}/,function(a){return a}],[/{{#raw}}/,function(a){this.pushState("raw");return a}],[/{{(?:#(?:if|each|forin)(?=\s))?/,function(a){this.pushState("{{");return a}]],raw:[[/(?:(?!{{\/raw}})[\s\S])+/,function(a){this.popState();return"rawtext"}]],"{{":a.concat([[/}}/,function(a){this.popState();return a}]]),"{{{":a.concat([[/}}}/,function(a){this.popState(); | ||
return a}]])})}(),R=function(){var a={nStart:37,tSymbols:"$ ! && ( ) + , - . = [ ] boolean eq include mul number rawtext realId rel set string text {{ {{#each {{#forin {{#if {{#raw}} {{/each}} {{/forin}} {{/if}} {{/raw}} {{else}} {{{ || }} }}} AdditiveExpression EqualityExpression LogicalAndExpression LogicalOrExpression MemberExpression MultiplicativeExpression PrimaryExpression RelationalExpression UnaryExpression _text args empty expr id name program statement statements texts program'".split(" "), | ||
actionList:[{_:-2},{_:-32768},{22:11,23:9,24:7,25:8,26:6,27:12,33:10,_:-1},{_:-3},{22:11,27:12,_:-13},{_:-17},{1:32,3:31,7:33,12:30,14:26,16:29,18:28,20:25,21:27,_:0},{1:32,3:31,7:33,12:30,14:38,16:29,18:28,20:37,21:27,_:0},{_:-19},{17:40,_:0},{_:-18},{_:-27},{_:-29},{3:41,8:42,10:43,_:-36},{_:-39},{15:44,_:-41},{5:46,7:45,_:-44},{19:47,_:-46},{13:48,_:-48},{2:49,_:-50},{34:50,_:-52},{35:51,_:0},{_:-22},{_:-23},{_:-24},{_:-21},{_:-25},{_:-26},{14:26,18:28,20:25,21:57,_:0},{35:59,_:0},{14:26,18:28, | ||
20:25,_:-22},{21:61,_:-23},{36:62,_:0},{31:63,_:0},{1:32,3:31,7:33,12:30,14:26,16:29,18:28,20:25,21:27,_:-53},{14:26,18:28,20:25,_:0},{_:-2},{4:77,_:0},{_:-37},{_:-38},{14:26,18:28,20:25,21:57,_:-53},{_:-16},{_:-15},{_:-11},{9:82,_:0},{35:83,_:0},{_:-12},{_:-20},{4:84,6:85,_:0},{_:-34},{4:86,_:0},{_:-30},{11:87,_:0},{_:-40},{15:44,_:-43},{15:44,_:-42},{5:46,7:45,_:-45},{19:47,_:-47},{13:48,_:-49},{2:49,_:-51},{22:11,23:9,24:7,25:8,26:6,27:12,30:88,32:89,33:10,_:0},{_:-28},{35:90,_:0},{35:91,_:0}, | ||
{35:92,_:0},{35:93,_:0},{_:-14},{_:-32},{_:-33},{_:-31},{_:-4},{_:-2},{_:-2},{_:-2},{35:101,_:0},{_:-35},{22:11,23:9,24:7,25:8,26:6,27:12,30:102,33:10,_:0},{22:11,23:9,24:7,25:8,26:6,27:12,28:103,33:10,_:0},{22:11,23:9,24:7,25:8,26:6,27:12,28:104,33:10,_:0},{22:11,23:9,24:7,25:8,26:6,27:12,29:105,33:10,_:0},{22:11,23:9,24:7,25:8,26:6,27:12,29:106,33:10,_:0},{_:-10},{_:-5},{_:-6},{_:-7},{_:-8},{_:-9}],actionIndex:[0,1,2,3,4,5,6,6,6,7,6,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,6,6, | ||
6,28,28,29,30,31,32,33,34,35,6,6,6,6,6,6,6,6,36,37,38,39,40,41,42,40,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,6,66,67,6,68,69,70,71,72,72,73,73,74,75,76,77,78,79,80,81,82,83,84,85,86],tGoto:[{52:1,54:2},{},{53:3,55:4,46:5},{},{46:13},{},{50:14,43:15,41:16,45:17,42:18,37:19,44:20,38:21,39:22,40:23,49:24},{50:14,43:15,41:16,45:17,42:18,37:19,44:20,38:21,39:22,40:23,49:34},{50:14,43:15,41:16,45:17,42:18,37:19,44:20,38:21,39:22,40:23,49:35},{50:14,43:15,41:16,45:17,42:18,37:19, | ||
44:20,38:21,39:22,40:23,49:36},{50:14,43:15,41:16,45:17,42:18,37:19,44:20,38:21,39:22,40:23,49:39},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{50:14,43:15,41:16,45:17,42:18,37:19,44:20,38:21,39:22,40:23,49:52},{50:14,43:15,41:16,45:53},{50:14,43:15,41:16,45:54},{51:55,50:56},{51:58,50:56},{},{50:60},{},{},{},{50:14,43:15,41:16,47:64,45:17,42:18,37:19,44:20,38:21,39:22,40:23,49:65,48:66},{50:67},{50:14,43:15,41:16,45:17,42:18,37:19,44:20,38:21,39:22,40:23,49:68},{50:14,43:15,41:16, | ||
45:69},{50:14,43:15,41:16,45:17,42:70},{50:14,43:15,41:16,45:17,42:71},{50:14,43:15,41:16,45:17,42:18,37:72},{50:14,43:15,41:16,45:17,42:18,37:19,44:73},{50:14,43:15,41:16,45:17,42:18,37:19,44:20,38:74},{50:14,43:15,41:16,45:17,42:18,37:19,44:20,38:21,39:75},{54:76},{},{},{},{51:78,50:56,48:79},{},{},{51:80,50:56,48:81},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{53:3,55:4,46:5},{},{},{},{},{},{50:14,43:15,41:16,45:17,42:18,37:19,44:20,38:21,39:22,40:23,49:94},{},{},{50:14,43:15,41:16,45:17, | ||
42:18,37:19,44:20,38:21,39:22,40:23,49:95},{},{},{},{54:96},{54:97},{54:98},{54:99},{54:100},{},{},{53:3,55:4,46:5},{53:3,55:4,46:5},{53:3,55:4,46:5},{53:3,55:4,46:5},{53:3,55:4,46:5},{},{},{},{},{},{}],tRules:[[56,52],[52,54],[54],[54,54,53],[53,26,49,35,54,30],[53,26,49,35,54,32,54,30],[53,24,49,51,51,35,54,28],[53,24,49,51,48,35,54,28],[53,25,49,51,51,35,54,29],[53,25,49,51,48,35,54,29],[53,23,20,50,9,49,35],[53,23,49,35],[53,33,49,36],[53,55],[53,23,14,21,35],[51,21],[51,50],[55,46],[55,55,46], | ||
[46,22],[46,27,17,31],[50,18],[50,20],[50,14],[43,21],[43,16],[43,12],[43,50],[43,3,49,4],[41,43],[41,41,8,50],[41,41,10,49,11],[41,41,3,47,4],[41,41,3,48,4],[47,49],[47,47,6,49],[45,41],[45,1,45],[45,7,45],[42,45],[42,42,15,45],[37,42],[37,37,5,42],[37,37,7,42],[44,37],[44,44,19,37],[38,44],[38,38,13,44],[39,38],[39,39,2,38],[40,39],[40,40,34,39],[49,40],[48]],objCharset:null};return function(f,d){function b(a,b,c,d,e,f,g){return["each",b,f,d,c,!0]}function h(a,b,c,d,f,e,g){return["each",b,e,d,c, | ||
!1]}function e(a){return a.text}function p(a,b,c,d){return["()",a,c]}function k(a,b,c){return[b.text,a,c]}function c(a,b){return t[a][b]}function n(a,b,c){this.start=a;this.end=b;this.pos=c}function g(a){throw Error("Syntax error: "+f.getPos(B.index)+(a?"\n"+a:""));}for(var y=a.nStart,v=a.tSymbols,x={},m=0;m<v.length;++m)x[v[m]]=m;var t=a.tAction||a.actionList,A=a.tGoto,l=a.tRules,u=a.actionIndex,C=[,function(a){return["prog",a]},function(){return[]},function(a,b){a.push(b);return a},function(a,b, | ||
c,d,e){return["if",b,d]},function(a,b,c,d,e,f,g){return["if",b,d,f]},b,b,h,h,function(a,b,c,d,e,f){return["set",c.text,e]},function(a,b,c){return["eval",b,!1]},function(a,b,c){return["eval",b,!0]},function(a){return["text",a]},function(a,b,c,d){return["inc",L(c.text)]},function(a){return L(a.text)},e,function(a){return a},function(a,b){return a+b},e,function(a,b,c){return b.text},,,,function(a){return["lit",L(a.text)]},function(a){return["lit",+a.text]},function(a){return["lit","true"==a.text]},function(a){return["id", | ||
a.text]},function(a,b,c){return b},,function(a,b,c){return[".",a,c.text]},function(a,b,c,d){return["[]",a,c]},p,p,function(a){return[a]},function(a,b,c){a.push(c);return a},,function(a,b){return["!",b]},function(a,b){return["u-",b]},,k,,k,k,,k,,k,,k,,k];u&&(c=function(a,b){var c=t[u[a]];return c[b]||c._});var r=0,w=[0],B=f.scan(),D=[],E={get:function(a){return D[D.length+a]},set:function(a,b){D[D.length+a]=b}};if(d)for(m in d)E[m]=d[m];m=[];for(n.prototype.toString=function(){return JSON.stringify({start:this.start, | ||
end:this.end,pos:this.pos.toString()})};;){var q=c(r,x[B.tag]);if(q)if(0<q)w.push(r=q),D.push(B),m.push(new n(B.index,B.end,B.pos)),B=f.scan();else if(0>q&&-32768<q){var z=-q,r=l[z],q=r.length-1;w.length-=q;r=A[w[w.length-1]][r[0]];w.push(r);var F=null;C[z]?(F=D.splice(D.length-q,q),F=C[z].apply(E,F),D.push(F)):1!=q&&D.splice(D.length-q,q,null);z=0<m.length?m[m.length-1]:null;0==q?m.push(z=new n(B.index,B.index,B.pos)):1!=q&&(z=new n(m[m.length-q].start,m[m.length-1].end,m[m.length-q].pos),m.splice(m.length- | ||
q,q),m.push(z));F&&F instanceof Array&&0<F.length&&"string"==typeof F[0]&&(F.pos=z)}else return B.tag!=v[0]&&g(),D[0];else{q=[];for(z=0;z<y;++z)c(r,z)&&q.push(v[z]);g("find "+B.tag+"\nexpect "+q.join(" "))}}}}();return{parse:K,compile:O,render:function(a,f){return O(a)(f)},compileToPhp:function(a){return T(K(a),!0)},compileToVM:function(a,f){return U(K(a))},version:"1.3.2"}}();"object"==typeof module&&module&&"object"==typeof module.exports?module.exports=x:"function"==typeof define&&(define.amd|| | ||
define.cmd)?define(function(){return x}):"undefined"!=typeof KISSY&&KISSY.add(function(){return x});C&&(C.Crox=x)})(this); |
/** | ||
* @preserve Crox v1.3.1 | ||
* @preserve Crox v1.3.2 | ||
* https://github.com/thx/crox | ||
* | ||
* Released under the MIT license | ||
* md5: 8da2a66f77bf4c724bc022772a8cc33d | ||
* md5: 1bd1fba7c18a787e720243fe9b83d7d5 | ||
*/ | ||
@@ -149,3 +149,3 @@ (function(root) {var Crox = (function() { | ||
function Token(tag, text, index, subMatches) { | ||
function Token(tag, text, index, subMatches, end, pos) { | ||
this.tag = tag; | ||
@@ -155,2 +155,4 @@ this.text = text; | ||
this.subMatches = subMatches; | ||
this.end = end; | ||
this.pos = pos; | ||
} | ||
@@ -204,2 +206,3 @@ Token.prototype.toString = function() { | ||
}; | ||
var currentPos = new Position(1, 1); | ||
@@ -214,6 +217,6 @@ function scan() { | ||
if (i < Length) { | ||
throw Error('lexer error: ' + getPos(s, i) + | ||
throw Error('lexer error: ' + currentPos + | ||
'\n' + s.slice(i, i + 50)); | ||
} | ||
return new Token(endTag, '', i); | ||
return new Token(endTag, '', i, null, i, currentPos); | ||
} | ||
@@ -226,6 +229,9 @@ obj.index = i; | ||
var tag = rule[2][j].apply(obj, t.slice(idx[j], idx[j + 1])); | ||
return new Token(tag, t[0], obj.index, t.slice(idx[j] + 1, idx[j + 1])); | ||
if (tag == null) return null; | ||
return new Token(tag, t[0], obj.index, t.slice(idx[j] + 1, idx[j + 1]), i, currentPos); | ||
} | ||
} | ||
var re_newLine = /\r\n?|\n/g; | ||
var re_lastLine = /[^\r\n\u2028\u2029]*$/; | ||
return { | ||
@@ -235,5 +241,18 @@ scan: function() { | ||
var t = scan(); | ||
} while (t.tag == null); | ||
return t; | ||
if (t != null) { | ||
var _row = currentPos.row; | ||
var _col = currentPos.col; | ||
var ms = t.text.match(re_newLine); | ||
var h = ms ? ms.length : 0; | ||
_row += h; | ||
if (h == 0) _col += t.text.length; | ||
else _col = re_lastLine.exec(t.text)[0].length + 1; | ||
currentPos = new Position(_row, _col); | ||
return t; | ||
} | ||
} while (true); | ||
}, | ||
GetCurrentPosition: function() { | ||
return currentPos; | ||
}, | ||
getPos: function(i) { | ||
@@ -332,90 +351,146 @@ return getPos(s, i); | ||
var parse = function() { | ||
var table = {/* state num: 107 */ | ||
nStart: 37, | ||
tSymbols: ["$", "!", "&&", "(", ")", "+", ",", "-", ".", "=", "[", "]", "boolean", "eq", "include", "mul", "number", "rawtext", "realId", "rel", "set", "string", "text", "{{", "{{#each", "{{#forin", "{{#if", "{{#raw}}", "{{/each}}", "{{/forin}}", "{{/if}}", "{{/raw}}", "{{else}}", "{{{", "||", "}}", "}}}", "AdditiveExpression", "EqualityExpression", "LogicalAndExpression", "LogicalOrExpression", "MemberExpression", "MultiplicativeExpression", "PrimaryExpression", "RelationalExpression", "UnaryExpression", "_text", "args", "epsilon", "expr", "id", "name", "program", "statement", "statements", "texts"], | ||
tAction: [{ _: -2 }, { _: -32768 }, { 22: 3, 23: 4, 24: 5, 25: 6, 26: 7, 27: 8, 33: 9, _: -1 }, { _: -19 }, { 1: 13, 3: 14, 7: 15, 12: 16, 14: 17, 16: 18, 18: 19, 20: 20, 21: 21, _: 0 }, { 1: 13, 3: 14, 7: 15, 12: 16, 14: 33, 16: 18, 18: 19, 20: 34, 21: 21, _: 0 }, { 17: 38, _: 0 }, { _: -17 }, { _: -3 }, { 22: 3, 27: 8, _: -13 }, { _: -26 }, { 21: 44, _: -23 }, { _: -25 }, { _: -21 }, { 14: 33, 18: 19, 20: 34, _: -22 }, { _: -24 }, { 5: 46, 7: 47, _: -44 }, { 13: 48, _: -48 }, { 2: 49, _: -50 }, { 34: 50, _: -52 }, { 3: 51, 8: 52, 10: 53, _: -36 }, { 15: 54, _: -41 }, { _: -29 }, { 19: 55, _: -46 }, { _: -39 }, { 35: 56, _: 0 }, { _: -27 }, { _: -23 }, { _: -22 }, { 14: 33, 18: 19, 20: 34, 21: 57, _: 0 }, { 35: 61, _: 0 }, { 31: 62, _: 0 }, { 36: 63, _: 0 }, { _: -18 }, { _: -37 }, { 4: 64, _: 0 }, { _: -38 }, { 35: 65, _: 0 }, { 9: 66, _: 0 }, { 1: 13, 3: 14, 7: 15, 12: 16, 14: 33, 16: 18, 18: 19, 20: 34, 21: 21, _: -53 }, { 14: 33, 18: 19, 20: 34, _: 0 }, { _: -11 }, { _: -15 }, { _: -16 }, { 14: 33, 18: 19, 20: 34, 21: 57, _: -53 }, { _: -20 }, { _: -12 }, { _: -28 }, { _: -14 }, { 15: 54, _: -42 }, { 15: 54, _: -43 }, { 19: 55, _: -47 }, { 13: 48, _: -49 }, { 2: 49, _: -51 }, { 4: 85, 6: 86, _: 0 }, { 4: 87, _: 0 }, { _: -34 }, { _: -30 }, { 11: 88, _: 0 }, { _: -40 }, { 5: 46, 7: 47, _: -45 }, { 35: 89, _: 0 }, { 35: 90, _: 0 }, { 35: 91, _: 0 }, { 35: 92, _: 0 }, { 22: 3, 23: 4, 24: 5, 25: 6, 26: 7, 27: 8, 30: 93, 32: 94, 33: 9, _: 0 }, { 35: 95, _: 0 }, { _: -33 }, { _: -32 }, { _: -31 }, { _: -4 }, { _: -10 }, { _: -35 }, { 22: 3, 23: 4, 24: 5, 25: 6, 26: 7, 27: 8, 28: 102, 33: 9, _: 0 }, { 22: 3, 23: 4, 24: 5, 25: 6, 26: 7, 27: 8, 28: 103, 33: 9, _: 0 }, { 22: 3, 23: 4, 24: 5, 25: 6, 26: 7, 27: 8, 29: 104, 33: 9, _: 0 }, { 22: 3, 23: 4, 24: 5, 25: 6, 26: 7, 27: 8, 29: 105, 33: 9, _: 0 }, { 22: 3, 23: 4, 24: 5, 25: 6, 26: 7, 27: 8, 30: 106, 33: 9, _: 0 }, { _: -6 }, { _: -7 }, { _: -8 }, { _: -9 }, { _: -5 }], | ||
actionIndex: [0, 1, 2, 3, 4, 5, 5, 5, 6, 5, 7, 8, 9, 5, 5, 5, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 5, 5, 5, 5, 5, 39, 40, 5, 5, 5, 41, 42, 43, 44, 44, 0, 45, 46, 47, 48, 5, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 5, 68, 69, 0, 0, 0, 0, 70, 0, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82], | ||
tGoto: [{ 15: 1, 17: 2 }, , { 9: 10, 16: 11, 18: 12 }, , { 0: 22, 1: 23, 2: 24, 3: 25, 4: 26, 5: 27, 6: 28, 7: 29, 8: 30, 12: 31, 13: 32 }, { 0: 22, 1: 23, 2: 24, 3: 25, 4: 26, 5: 27, 6: 28, 7: 29, 8: 30, 12: 35, 13: 32 }, { 0: 22, 1: 23, 2: 24, 3: 25, 4: 26, 5: 27, 6: 28, 7: 29, 8: 30, 12: 36, 13: 32 }, { 0: 22, 1: 23, 2: 24, 3: 25, 4: 26, 5: 27, 6: 28, 7: 29, 8: 30, 12: 37, 13: 32 }, , { 0: 22, 1: 23, 2: 24, 3: 25, 4: 26, 5: 27, 6: 28, 7: 29, 8: 30, 12: 39, 13: 32 }, , , { 9: 40 }, { 4: 26, 6: 28, 8: 41, 13: 32 }, { 0: 22, 1: 23, 2: 24, 3: 25, 4: 26, 5: 27, 6: 28, 7: 29, 8: 30, 12: 42, 13: 32 }, { 4: 26, 6: 28, 8: 43, 13: 32 }, , , , , { 13: 45 }, , , , , , , , , , , , , , , { 13: 58, 14: 59 }, { 13: 58, 14: 60 }, , , , , , , , , , { 4: 26, 5: 67, 6: 28, 8: 30, 13: 32 }, { 4: 26, 5: 68, 6: 28, 8: 30, 13: 32 }, { 0: 22, 4: 26, 5: 27, 6: 28, 7: 69, 8: 30, 13: 32 }, { 0: 22, 1: 70, 4: 26, 5: 27, 6: 28, 7: 29, 8: 30, 13: 32 }, { 0: 22, 1: 23, 2: 71, 4: 26, 5: 27, 6: 28, 7: 29, 8: 30, 13: 32 }, { 0: 22, 1: 23, 2: 24, 3: 25, 4: 26, 5: 27, 6: 28, 7: 29, 8: 30, 10: 72, 11: 73, 12: 74, 13: 32 }, { 13: 75 }, { 0: 22, 1: 23, 2: 24, 3: 25, 4: 26, 5: 27, 6: 28, 7: 29, 8: 30, 12: 76, 13: 32 }, { 4: 26, 6: 28, 8: 77, 13: 32 }, { 0: 78, 4: 26, 5: 27, 6: 28, 8: 30, 13: 32 }, , , , { 11: 79, 13: 58, 14: 80 }, { 11: 81, 13: 58, 14: 82 }, { 17: 83 }, , , , , { 0: 22, 1: 23, 2: 24, 3: 25, 4: 26, 5: 27, 6: 28, 7: 29, 8: 30, 12: 84, 13: 32 }, , , , , , , , , , , , , , , , , { 9: 10, 16: 11, 18: 12 }, , , { 0: 22, 1: 23, 2: 24, 3: 25, 4: 26, 5: 27, 6: 28, 7: 29, 8: 30, 12: 96, 13: 32 }, , , { 17: 97 }, { 17: 98 }, { 17: 99 }, { 17: 100 }, , { 17: 101 }, , , { 9: 10, 16: 11, 18: 12 }, { 9: 10, 16: 11, 18: 12 }, { 9: 10, 16: 11, 18: 12 }, { 9: 10, 16: 11, 18: 12 }, { 9: 10, 16: 11, 18: 12 }], | ||
tRules: [[56, 52], [52, 54], [54], [54, 54, 53], [53, 26, 49, 35, 54, 30], [53, 26, 49, 35, 54, 32, 54, 30], [53, 24, 49, 51, 48, 35, 54, 28], [53, 24, 49, 51, 51, 35, 54, 28], [53, 25, 49, 51, 48, 35, 54, 29], [53, 25, 49, 51, 51, 35, 54, 29], [53, 23, 20, 50, 9, 49, 35], [53, 23, 49, 35], [53, 33, 49, 36], [53, 55], [53, 23, 14, 21, 35], [51, 21], [51, 50], [55, 46], [55, 55, 46], [46, 22], [46, 27, 17, 31], [50, 18], [50, 20], [50, 14], [43, 21], [43, 16], [43, 12], [43, 50], [43, 3, 49, 4], [41, 43], [41, 41, 8, 50], [41, 41, 10, 49, 11], [41, 41, 3, 48, 4], [41, 41, 3, 47, 4], [47, 49], [47, 47, 6, 49], [45, 41], [45, 1, 45], [45, 7, 45], [42, 45], [42, 42, 15, 45], [37, 42], [37, 37, 5, 42], [37, 37, 7, 42], [44, 37], [44, 44, 19, 37], [38, 44], [38, 38, 13, 44], [39, 38], [39, 39, 2, 38], [40, 39], [40, 40, 34, 39], [49, 40], [48]], | ||
tFuncs: function() { | ||
function $f0($1, $2, $3, $4, $5, $6, $7) { | ||
var $$; $$ = ['each', $2, $6, $4, $3, true]; return $$; | ||
var table = {//conflicts: 2 | ||
"nStart": 37, | ||
"tSymbols": /*57*/["$", "!", "\u0026\u0026", "(", ")", "+", ",", "-", ".", "=", "[", "]", "boolean", "eq", "include", "mul", "number", "rawtext", "realId", "rel", "set", "string", "text", "{{", "{{#each", "{{#forin", "{{#if", "{{#raw}}", "{{/each}}", "{{/forin}}", "{{/if}}", "{{/raw}}", "{{else}}", "{{{", "||", "}}", "}}}", "AdditiveExpression", "EqualityExpression", "LogicalAndExpression", "LogicalOrExpression", "MemberExpression", "MultiplicativeExpression", "PrimaryExpression", "RelationalExpression", "UnaryExpression", "_text", "args", "empty", "expr", "id", "name", "program", "statement", "statements", "texts", "program\u0027"], | ||
actionList: [{ "_": -2 }, { "_": -32768 }, { "22": 11, "23": 9, "24": 7, "25": 8, "26": 6, "27": 12, "33": 10, "_": -1 }, { "_": -3 }, { "22": 11, "27": 12, "_": -13 }, { "_": -17 }, { "1": 32, "3": 31, "7": 33, "12": 30, "14": 26, "16": 29, "18": 28, "20": 25, "21": 27, "_": 0 }, { "1": 32, "3": 31, "7": 33, "12": 30, "14": 38, "16": 29, "18": 28, "20": 37, "21": 27, "_": 0 }, { "_": -19 }, { "17": 40, "_": 0 }, { "_": -18 }, { "_": -27 }, { "_": -29 }, { "3": 41, "8": 42, "10": 43, "_": -36 }, { "_": -39 }, { "15": 44, "_": -41 }, { "5": 46, "7": 45, "_": -44 }, { "19": 47, "_": -46 }, { "13": 48, "_": -48 }, { "2": 49, "_": -50 }, { "34": 50, "_": -52 }, { "35": 51, "_": 0 }, { "_": -22 }, { "_": -23 }, { "_": -24 }, { "_": -21 }, { "_": -25 }, { "_": -26 }, { "14": 26, "18": 28, "20": 25, "21": 57, "_": 0 }, { "35": 59, "_": 0 }, { "14": 26, "18": 28, "20": 25, "_": -22 }, { "21": 61, "_": -23 }, { "36": 62, "_": 0 }, { "31": 63, "_": 0 }, { "1": 32, "3": 31, "7": 33, "12": 30, "14": 26, "16": 29, "18": 28, "20": 25, "21": 27, "_": -53 }, { "14": 26, "18": 28, "20": 25, "_": 0 }, { "_": -2 }, { "4": 77, "_": 0 }, { "_": -37 }, { "_": -38 }, { "14": 26, "18": 28, "20": 25, "21": 57, "_": -53 }, { "_": -16 }, { "_": -15 }, { "_": -11 }, { "9": 82, "_": 0 }, { "35": 83, "_": 0 }, { "_": -12 }, { "_": -20 }, { "4": 84, "6": 85, "_": 0 }, { "_": -34 }, { "4": 86, "_": 0 }, { "_": -30 }, { "11": 87, "_": 0 }, { "_": -40 }, { "15": 44, "_": -43 }, { "15": 44, "_": -42 }, { "5": 46, "7": 45, "_": -45 }, { "19": 47, "_": -47 }, { "13": 48, "_": -49 }, { "2": 49, "_": -51 }, { "22": 11, "23": 9, "24": 7, "25": 8, "26": 6, "27": 12, "30": 88, "32": 89, "33": 10, "_": 0 }, { "_": -28 }, { "35": 90, "_": 0 }, { "35": 91, "_": 0 }, { "35": 92, "_": 0 }, { "35": 93, "_": 0 }, { "_": -14 }, { "_": -32 }, { "_": -33 }, { "_": -31 }, { "_": -4 }, { "_": -2 }, { "_": -2 }, { "_": -2 }, { "35": 101, "_": 0 }, { "_": -35 }, { "22": 11, "23": 9, "24": 7, "25": 8, "26": 6, "27": 12, "30": 102, "33": 10, "_": 0 }, { "22": 11, "23": 9, "24": 7, "25": 8, "26": 6, "27": 12, "28": 103, "33": 10, "_": 0 }, { "22": 11, "23": 9, "24": 7, "25": 8, "26": 6, "27": 12, "28": 104, "33": 10, "_": 0 }, { "22": 11, "23": 9, "24": 7, "25": 8, "26": 6, "27": 12, "29": 105, "33": 10, "_": 0 }, { "22": 11, "23": 9, "24": 7, "25": 8, "26": 6, "27": 12, "29": 106, "33": 10, "_": 0 }, { "_": -10 }, { "_": -5 }, { "_": -6 }, { "_": -7 }, { "_": -8 }, { "_": -9 }], | ||
actionIndex: [0, 1, 2, 3, 4, 5, 6, 6, 6, 7, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 6, 6, 6, 28, 28, 29, 30, 31, 32, 33, 34, 35, 6, 6, 6, 6, 6, 6, 6, 6, 36, 37, 38, 39, 40, 41, 42, 40, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 6, 66, 67, 6, 68, 69, 70, 71, 72, 72, 73, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86], | ||
"tGoto": /*107*/[{ "52": 1, "54": 2 }, {}, { "53": 3, "55": 4, "46": 5 }, {}, { "46": 13 }, {}, { "50": 14, "43": 15, "41": 16, "45": 17, "42": 18, "37": 19, "44": 20, "38": 21, "39": 22, "40": 23, "49": 24 }, { "50": 14, "43": 15, "41": 16, "45": 17, "42": 18, "37": 19, "44": 20, "38": 21, "39": 22, "40": 23, "49": 34 }, { "50": 14, "43": 15, "41": 16, "45": 17, "42": 18, "37": 19, "44": 20, "38": 21, "39": 22, "40": 23, "49": 35 }, { "50": 14, "43": 15, "41": 16, "45": 17, "42": 18, "37": 19, "44": 20, "38": 21, "39": 22, "40": 23, "49": 36 }, { "50": 14, "43": 15, "41": 16, "45": 17, "42": 18, "37": 19, "44": 20, "38": 21, "39": 22, "40": 23, "49": 39 }, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, { "50": 14, "43": 15, "41": 16, "45": 17, "42": 18, "37": 19, "44": 20, "38": 21, "39": 22, "40": 23, "49": 52 }, { "50": 14, "43": 15, "41": 16, "45": 53 }, { "50": 14, "43": 15, "41": 16, "45": 54 }, { "51": 55, "50": 56 }, { "51": 58, "50": 56 }, {}, { "50": 60 }, {}, {}, {}, { "50": 14, "43": 15, "41": 16, "47": 64, "45": 17, "42": 18, "37": 19, "44": 20, "38": 21, "39": 22, "40": 23, "49": 65, "48": 66 }, { "50": 67 }, { "50": 14, "43": 15, "41": 16, "45": 17, "42": 18, "37": 19, "44": 20, "38": 21, "39": 22, "40": 23, "49": 68 }, { "50": 14, "43": 15, "41": 16, "45": 69 }, { "50": 14, "43": 15, "41": 16, "45": 17, "42": 70 }, { "50": 14, "43": 15, "41": 16, "45": 17, "42": 71 }, { "50": 14, "43": 15, "41": 16, "45": 17, "42": 18, "37": 72 }, { "50": 14, "43": 15, "41": 16, "45": 17, "42": 18, "37": 19, "44": 73 }, { "50": 14, "43": 15, "41": 16, "45": 17, "42": 18, "37": 19, "44": 20, "38": 74 }, { "50": 14, "43": 15, "41": 16, "45": 17, "42": 18, "37": 19, "44": 20, "38": 21, "39": 75 }, { "54": 76 }, {}, {}, {}, { "51": 78, "50": 56, "48": 79 }, {}, {}, { "51": 80, "50": 56, "48": 81 }, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, { "53": 3, "55": 4, "46": 5 }, {}, {}, {}, {}, {}, { "50": 14, "43": 15, "41": 16, "45": 17, "42": 18, "37": 19, "44": 20, "38": 21, "39": 22, "40": 23, "49": 94 }, {}, {}, { "50": 14, "43": 15, "41": 16, "45": 17, "42": 18, "37": 19, "44": 20, "38": 21, "39": 22, "40": 23, "49": 95 }, {}, {}, {}, { "54": 96 }, { "54": 97 }, { "54": 98 }, { "54": 99 }, { "54": 100 }, {}, {}, { "53": 3, "55": 4, "46": 5 }, { "53": 3, "55": 4, "46": 5 }, { "53": 3, "55": 4, "46": 5 }, { "53": 3, "55": 4, "46": 5 }, { "53": 3, "55": 4, "46": 5 }, {}, {}, {}, {}, {}, {}], | ||
"tRules": /*54*/[[56, 52], [52, 54], [54], [54, 54, 53], [53, 26, 49, 35, 54, 30], [53, 26, 49, 35, 54, 32, 54, 30], [53, 24, 49, 51, 51, 35, 54, 28], [53, 24, 49, 51, 48, 35, 54, 28], [53, 25, 49, 51, 51, 35, 54, 29], [53, 25, 49, 51, 48, 35, 54, 29], [53, 23, 20, 50, 9, 49, 35], [53, 23, 49, 35], [53, 33, 49, 36], [53, 55], [53, 23, 14, 21, 35], [51, 21], [51, 50], [55, 46], [55, 55, 46], [46, 22], [46, 27, 17, 31], [50, 18], [50, 20], [50, 14], [43, 21], [43, 16], [43, 12], [43, 50], [43, 3, 49, 4], [41, 43], [41, 41, 8, 50], [41, 41, 10, 49, 11], [41, 41, 3, 47, 4], [41, 41, 3, 48, 4], [47, 49], [47, 47, 6, 49], [45, 41], [45, 1, 45], [45, 7, 45], [42, 45], [42, 42, 15, 45], [37, 42], [37, 37, 5, 42], [37, 37, 7, 42], [44, 37], [44, 44, 19, 37], [38, 44], [38, 38, 13, 44], [39, 38], [39, 39, 2, 38], [40, 39], [40, 40, 34, 39], [49, 40], [48]], | ||
"objCharset": null | ||
} | ||
; | ||
function parse(lexer, others) { | ||
var nStart = table.nStart; | ||
var tSymbols = table.tSymbols; | ||
var tSymbolIndex = {}; | ||
for (var i = 0; i < tSymbols.length; ++i) | ||
tSymbolIndex[tSymbols[i]] = i; | ||
var tAction = table.tAction || table.actionList; | ||
var tGoto = table.tGoto; | ||
var tRules = table.tRules; | ||
var tCodes = table.tCodes; | ||
var actionIndex = table.actionIndex; | ||
function $f0($1, $2, $3, $4, $5, $6, $7) { var $$; { $$ = ['each', $2, $6, $4, $3, true]; } return $$; } | ||
function $f1($1, $2, $3, $4, $5, $6, $7) { var $$; { $$ = ['each', $2, $6, $4, $3, false]; } return $$; } | ||
function $f2($1) { var $$; { $$ = $1.text; } return $$; } | ||
function $f3($1, $2, $3, $4) { var $$; { $$ = ['()', $1, $3]; } return $$; } | ||
function $f4($1, $2, $3) { var $$; { $$ = [$2.text, $1, $3]; } return $$; } var tFuncs = [, function($1) { var $$; { $$ = ['prog', $1]; } return $$; }, function() { var $$; { $$ = []; } return $$; }, function($1, $2) { var $$; { $1.push($2); $$ = $1; } return $$; }, function($1, $2, $3, $4, $5) { var $$; { $$ = ['if', $2, $4]; } return $$; }, function($1, $2, $3, $4, $5, $6, $7) { var $$; { $$ = ['if', $2, $4, $6]; } return $$; }, $f0, $f0, $f1, $f1, function($1, $2, $3, $4, $5, $6) { var $$; { $$ = ['set', $3.text, $5]; } return $$; }, function($1, $2, $3) { var $$; { $$ = ['eval', $2, false]; } return $$; }, function($1, $2, $3) { var $$; { $$ = ['eval', $2, true]; } return $$; }, function($1) { var $$; { $$ = ['text', $1]; } return $$; }, function($1, $2, $3, $4) { var $$; { $$ = ['inc', evalStr($3.text)]; } return $$; }, function($1) { var $$; { $$ = evalStr($1.text); } return $$; }, $f2, function($1) { var $$; { $$ = $1; } return $$; }, function($1, $2) { var $$; { $$ = $1 + $2; } return $$; }, $f2, function($1, $2, $3) { var $$; { $$ = $2.text; } return $$; }, , , , function($1) { var $$; { $$ = ['lit', evalStr($1.text)]; } return $$; }, function($1) { var $$; { $$ = ['lit', evalNum($1.text)]; } return $$; }, function($1) { var $$; { $$ = ['lit', $1.text == 'true']; } return $$; }, function($1) { var $$; { $$ = ['id', $1.text]; } return $$; }, function($1, $2, $3) { var $$; { $$ = $2; } return $$; }, , function($1, $2, $3) { var $$; { $$ = ['.', $1, $3.text]; } return $$; }, function($1, $2, $3, $4) { var $$; { $$ = ['[]', $1, $3]; } return $$; }, $f3, $f3, function($1) { var $$; { $$ = [$1]; } return $$; }, function($1, $2, $3) { var $$; { ($$ = $1).push($3); } return $$; }, , function($1, $2) { var $$; { $$ = ['!', $2]; } return $$; }, function($1, $2) { var $$; { $$ = ['u-', $2]; } return $$; }, , $f4, , $f4, $f4, , $f4, , $f4, , $f4, , $f4]; | ||
function getAction(x, y) { | ||
return tAction[x][y]; | ||
} | ||
var stateNum = tAction.length; | ||
if (actionIndex) { | ||
getAction = function(x, y) { | ||
var list = tAction[actionIndex[x]]; | ||
return list[y] || list._; | ||
}; | ||
stateNum = actionIndex.length; | ||
} | ||
function getToken() { | ||
var t = lexer.scan(); | ||
return t; | ||
} | ||
var s = 0; | ||
var stateStack = [0]; | ||
var a = getToken(); | ||
var valueStack = []; | ||
var obj = { | ||
get: function(i) { | ||
return valueStack[valueStack.length + i]; | ||
}, | ||
set: function(i, v) { | ||
valueStack[valueStack.length + i] = v; | ||
} | ||
function $f1($1, $2, $3, $4, $5, $6, $7) { | ||
var $$; $$ = ['each', $2, $6, $4, $3, false]; return $$; | ||
}; | ||
if (others) for (var i in others) | ||
obj[i] = others[i]; | ||
var $smb = valueStack; | ||
var ctxStack = []; | ||
function Context(index, end, pos) { | ||
this.start = index; | ||
this.end = end; | ||
this.pos = pos; | ||
} | ||
Context.prototype.toString = function() { | ||
return JSON.stringify({ | ||
start: this.start, | ||
end: this.end, | ||
pos: this.pos.toString() | ||
}) | ||
}; | ||
function isAstNode(t) { | ||
return !!t && t instanceof Array && t.length > 0 && typeof t[0] == 'string'; | ||
} | ||
function setPos(node, pos) { | ||
node.pos = pos; | ||
} | ||
while (1) { | ||
var $top = $smb.length - 1; | ||
var t = getAction(s, tSymbolIndex[a.tag]); | ||
if (!t) { | ||
var okTokens = []; | ||
for (var j = 0; j < nStart; ++j) { | ||
if (getAction(s, j)) | ||
okTokens.push(tSymbols[j]); | ||
} | ||
err('find ' + a.tag + '\nexpect ' + okTokens.join(' ')); | ||
} | ||
function $f2($1) { | ||
var $$; $$ = $1.text; return $$; | ||
else if (t > 0) { | ||
stateStack.push(s = t); | ||
valueStack.push(a); | ||
ctxStack.push(new Context(a.index, a.end, a.pos)); | ||
a = getToken(); | ||
} | ||
function $f3($1, $2, $3, $4) { | ||
var $$; $$ = ['()', $1, $3]; return $$; | ||
else if (t < 0 && t > -32768) { | ||
var idx = -t; | ||
var p = tRules[idx]; | ||
var num = p.length - 1; | ||
stateStack.length -= num; | ||
s = tGoto[stateStack[stateStack.length - 1]][p[0]]; | ||
stateStack.push(s); | ||
var val = null; | ||
if (tFuncs[idx]) { | ||
var popped = valueStack.splice(valueStack.length - num, num); | ||
val = tFuncs[idx].apply(obj, popped); | ||
valueStack.push(val); | ||
} | ||
else if (num != 1) { | ||
valueStack.splice(valueStack.length - num, num, null); | ||
} | ||
var ctx = ctxStack.length > 0 ? ctxStack[ctxStack.length - 1] : null; | ||
if (num == 0) { | ||
ctxStack.push(ctx = new Context(a.index, a.index, a.pos)); | ||
} | ||
else if (num != 1) { | ||
ctx = new Context( | ||
ctxStack[ctxStack.length - num].start, | ||
ctxStack[ctxStack.length - 1].end, | ||
ctxStack[ctxStack.length - num].pos | ||
); | ||
ctxStack.splice(ctxStack.length - num, num); | ||
ctxStack.push(ctx); | ||
} | ||
if (isAstNode(val)) { | ||
setPos(val, ctx); | ||
} | ||
} | ||
function $f4($1, $2, $3) { | ||
var $$; $$ = [$2.text, $1, $3]; return $$; | ||
else { | ||
if (a.tag != tSymbols[0]) err(); | ||
return valueStack[0]; | ||
} | ||
return [, function($1) { | ||
var $$; $$ = ['prog', $1]; return $$; | ||
}, function() { | ||
var $$; $$ = []; return $$; | ||
}, function($1, $2) { | ||
var $$; $1.push($2); $$ = $1; return $$; | ||
}, function($1, $2, $3, $4, $5) { | ||
var $$; $$ = ['if', $2, $4]; return $$; | ||
}, function($1, $2, $3, $4, $5, $6, $7) { | ||
var $$; $$ = ['if', $2, $4, $6]; return $$; | ||
}, $f0, $f0, $f1, $f1, function($1, $2, $3, $4, $5, $6) { | ||
var $$; $$ = ['set', $3.text, $5]; return $$; | ||
}, function($1, $2, $3) { | ||
var $$; $$ = ['eval', $2, false]; return $$; | ||
}, function($1, $2, $3) { | ||
var $$; $$ = ['eval', $2, true]; return $$; | ||
}, function($1) { | ||
var $$; $$ = ['text', $1]; return $$; | ||
}, function($1, $2, $3, $4) { | ||
var $$; $$ = ['inc', evalStr($3.text)]; return $$; | ||
}, function($1) { | ||
var $$; $$ = evalStr($1.text); return $$; | ||
}, $f2, function($1) { | ||
var $$; $$ = $1; return $$; | ||
}, function($1, $2) { | ||
var $$; $$ = $1 + $2; return $$; | ||
}, $f2, function($1, $2, $3) { | ||
var $$; $$ = $2.text; return $$; | ||
}, , , , function($1) { | ||
var $$; $$ = ['lit', evalStr($1.text)]; return $$; | ||
}, function($1) { | ||
var $$; $$ = ['lit', evalNum($1.text)]; return $$; | ||
}, function($1) { | ||
var $$; $$ = ['lit', $1.text == 'true']; return $$; | ||
}, function($1) { | ||
var $$; $$ = ['id', $1.text]; return $$; | ||
}, function($1, $2, $3) { | ||
var $$; $$ = $2; return $$; | ||
}, , function($1, $2, $3) { | ||
var $$; $$ = ['.', $1, $3.text]; return $$; | ||
}, function($1, $2, $3, $4) { | ||
var $$; $$ = ['[]', $1, $3]; return $$; | ||
}, $f3, $f3, function($1) { | ||
var $$; $$ = [$1]; return $$; | ||
}, function($1, $2, $3) { | ||
var $$; ($$ = $1).push($3); return $$; | ||
}, , function($1, $2) { | ||
var $$; $$ = ['!', $2]; return $$; | ||
}, function($1, $2) { | ||
var $$; $$ = ['u-', $2]; return $$; | ||
}, , $f4, , $f4, $f4, , $f4, , $f4, , $f4, , $f4]; | ||
}() | ||
}; | ||
return function(a) { | ||
function c(a, b) { return g[a][b] } for (var d = a.nStart, f = a.tSymbols, b = {}, e = 0; e < f.length; ++e) b[f[e]] = e; var g = a.tAction, p = a.tGoto, h = a.tRules, n = a.tFuncs, | ||
m = a.actionIndex; m && (c = function(a, b) { var c = g[m[a]]; return c[b] || c._ }); return function(a, e) { | ||
function g(b) { throw Error("Syntax error: " + a.getPos(l.index) + (b ? "\n" + b : "")); } var m = 0, B = [0], l = a.scan(), v = [], r = { get: function(a) { return v[v.length + a] }, set: function(a, b) { v[v.length + a] = b } }; if (e) for (var y in e) r[y] = e[y]; for (; ;) if (y = c(m, b[l.tag])) if (0 < y) B.push(m = y), v.push(l), l = a.scan(); else if (0 > y && -32768 < y) { | ||
y = -y; var m = h[y], t = m.length - 1; B.length -= t; m = p[B[B.length - 1]][m[0] - d]; B.push(m); n[y] ? (y = n[y].apply(r, v.splice(v.length - | ||
t, t)), v.push(y)) : 1 != t && v.splice(v.length - t, t, null) | ||
} else return l.tag != f[0] && g(), v[0]; else { y = []; for (t = 0; t < d; ++t) c(m, t) && y.push(f[t]); g("find " + l.tag + "\nexpect " + y.join(" ")) } | ||
} | ||
}(table); | ||
function err(msg) { | ||
throw Error('Syntax error: ' + lexer.getPos(a.index) + (msg ? '\n' + msg : '')); | ||
} | ||
} | ||
return parse; | ||
}(); | ||
function isAtom(op) { | ||
@@ -492,4 +567,8 @@ switch (op) { | ||
function emit(s) { | ||
body += s; | ||
body.push(s); | ||
} | ||
function nodeWithPos(node, pos) { | ||
node.pos = pos; | ||
return node; | ||
} | ||
@@ -499,3 +578,5 @@ function stmtGen(a) { | ||
case 'if': | ||
emit('if(' + exprGen(a[1]) + '){'); | ||
emit('if('); | ||
emit(exprGen(a[1])); | ||
emit('){'); | ||
stmtsGen(a[2]); | ||
@@ -511,13 +592,24 @@ emit('}'); | ||
var keyName = a[3] ? encodeCommonName(a[3]) : TMake(); | ||
var sExpr = exprGen(a[1]); | ||
if (/^\w+$/.test(sExpr)) { | ||
var listName = sExpr; | ||
var tmpExpr = exprGen(a[1]); | ||
var tmpStr = joinCode(tmpExpr); | ||
if (/^\w+$/.test(tmpStr)) { | ||
var listName = tmpStr; | ||
} | ||
else { | ||
listName = TMake(); | ||
emit('var ' + listName + ' = ' + sExpr + ';'); | ||
emit('var ' + listName + ' = '); | ||
emit(tmpExpr); | ||
emit(';'); | ||
} | ||
if (a[5]) emit('for(var ' + keyName + '=0;' + keyName + '<' + listName + '.length;' + keyName + '++){'); | ||
if (a[5]) { | ||
emit('for(var ' + keyName + '=0;' + keyName + '<'); | ||
//listName + '.length' | ||
emit(exprGen(['.', nodeWithPos(['t', listName], a[1].pos), 'length'])); | ||
emit(';' + keyName + '++){'); | ||
} | ||
else emit('for(var ' + keyName + ' in ' + listName + ') {'); | ||
emit('var ' + a[4] + ' = ' + listName + '[' + keyName + '];'); | ||
emit('var ' + a[4] + ' = '); | ||
//listName + '[' + keyName + ']' | ||
emit(exprGen(['[]', nodeWithPos(['t', listName], a[1].pos), ['t', keyName]])); | ||
emit(';'); | ||
stmtsGen(a[2]); | ||
@@ -527,11 +619,16 @@ emit('}'); | ||
case 'set': | ||
emit('var ' + encodeCommonName(a[1]) + '=' + exprGen(a[2]) + ';'); | ||
emit('var ' + encodeCommonName(a[1]) + '='); | ||
emit(exprGen(a[2])); | ||
emit(';'); | ||
break; | ||
case 'eval': | ||
var s = exprGen(a[1]); | ||
if (/^\w+$/.test(s)) | ||
var tName = s; | ||
var tmpExpr = exprGen(a[1]); | ||
var tmpStr = joinCode(tmpExpr); | ||
if (/^\w+$/.test(tmpStr)) | ||
var tName = tmpStr; | ||
else { | ||
tName = '_t'; | ||
emit('_t = ' + s + ';'); | ||
emit('_t = '); | ||
emit(tmpExpr); | ||
emit(';'); | ||
} | ||
@@ -555,36 +652,56 @@ emit('if(' + tName + ' !=null)_s += ' + ((defaultEncode ? !a[2] : a[2]) ? encodeName + '(' + tName + ')' : tName) + ';'); | ||
function joinCode(a) { | ||
if (typeof a == 'string') | ||
return a; | ||
if (a instanceof Array) { | ||
var r = []; | ||
for (var i = 0; i < a.length; ++i) { | ||
r.push(joinCode(a[i])); | ||
} | ||
return r.join(''); | ||
} | ||
throw new Error("unknown type"); | ||
} | ||
function exprToStr(x, check) { | ||
var t = exprGen(x); | ||
if (check && !check(x[0])) t = '(' + t + ')'; | ||
if (check && !check(x[0])) t = ['(', t, ')']; | ||
return t; | ||
} | ||
function exprGen(x) { | ||
return nodeWithPos(exprGen_original(x), x.pos); | ||
} | ||
function exprGen_original(x) { | ||
switch (x[0]) { | ||
case 't': | ||
return x[1]; //��ʱ����ֱ�ӷ��� | ||
case 'id': | ||
return encodeCommonName(x[1]); | ||
case 'lit': | ||
if (typeof x[1] == 'string') | ||
return quote(x[1]); | ||
return String(x[1]); | ||
return (typeof x[1] == 'string') | ||
? quote(x[1]) | ||
: String(x[1]); | ||
case '.': | ||
return exprToStr(x[1], isMember) + '.' + x[2]; | ||
return [exprToStr(x[1], isMember), '.', x[2]]; | ||
case '[]': | ||
return exprToStr(x[1], isMember) + '[' + exprGen(x[2]) + ']'; | ||
return [exprToStr(x[1], isMember), '[', exprGen(x[2]) + ']']; | ||
case '()': | ||
var a = []; | ||
if (x[2]) | ||
for (var i = 0; i < x[2].length; ++i) | ||
var a = [exprToStr(x[1], isMember), '(']; | ||
if (x[2]) { | ||
for (var i = 0; i < x[2].length; ++i) { | ||
if (i > 0) a.push(','); | ||
a.push(exprGen(x[2][i])); | ||
return exprToStr(x[1], isMember) + '(' + a.join(',') + ')'; | ||
} | ||
} | ||
a.push(')'); | ||
return a; | ||
case '!': | ||
return '!' + exprToStr(x[1], isUnary); | ||
return ['!', exprToStr(x[1], isUnary)]; | ||
case 'u-': | ||
return '- ' + exprToStr(x[1], isUnary); | ||
return ['- ', exprToStr(x[1], isUnary)]; | ||
case '*': case '/': case '%': | ||
return exprToStr(x[1], isMul) + x[0] + exprToStr(x[2], isUnary); | ||
return [exprToStr(x[1], isMul), x[0], exprToStr(x[2], isUnary)]; | ||
case '+': case '-': | ||
return exprToStr(x[1], isAdd) + x[0] + ' ' + exprToStr(x[2], isMul); | ||
return [exprToStr(x[1], isAdd), x[0], ' ', exprToStr(x[2], isMul)]; | ||
case '<': case '>': case '<=': case '>=': | ||
return exprToStr(x[1], isRel) + x[0] + exprToStr(x[2], isAdd); | ||
return [exprToStr(x[1], isRel), x[0], exprToStr(x[2], isAdd)]; | ||
case '==': | ||
@@ -594,7 +711,7 @@ case '!=': | ||
case '!==': | ||
return exprToStr(x[1], isEquality) + x[0] + exprToStr(x[2], isRel); | ||
return [exprToStr(x[1], isEquality), x[0], exprToStr(x[2], isRel)]; | ||
case '&&': | ||
return exprToStr(x[1], isLogicalAnd) + '&&' + exprToStr(x[2], isEquality); | ||
return [exprToStr(x[1], isLogicalAnd), '&&', exprToStr(x[2], isEquality)]; | ||
case '||': | ||
return exprToStr(x[1], isLogicalOr) + '||' + exprToStr(x[2], isLogicalAnd); | ||
return [exprToStr(x[1], isLogicalOr), '||', exprToStr(x[2], isLogicalAnd)]; | ||
default: | ||
@@ -605,6 +722,26 @@ throw Error("unknown expr: " + x[0]); | ||
var body = ''; | ||
var body = []; | ||
stmtsGen(prog[1]); | ||
return body; | ||
var posLog = []; | ||
var jsStr = ''; | ||
function joinJsStr(a) { | ||
if (typeof a == 'string') | ||
jsStr += a; | ||
if (a instanceof Array) { | ||
if (a.pos) { | ||
posLog.push([jsStr.length, a.pos]); | ||
} | ||
for (var i = 0; i < a.length; ++i) { | ||
joinJsStr(a[i]); | ||
} | ||
} | ||
} | ||
joinJsStr(body); | ||
//alert(posLog.join('\n')); | ||
var strObj = new String(jsStr); | ||
strObj.posLog = posLog; | ||
return strObj; | ||
} | ||
@@ -636,3 +773,33 @@ | ||
}"; | ||
body += "var _t,_s = '';" + s + "return _s;"; | ||
body += "var _t,_s = '';"; | ||
if (config && config.debug) { | ||
var posLog = s.posLog; | ||
body += 'try{\n'; | ||
body += 'eval(' + JSON.stringify(s) + ');'; | ||
body += '}catch(_e){throw ' + function(e, posLog) { | ||
var msg = e.stack; | ||
var msgLines = msg.split(/\r\n?|\n/); | ||
var re_pos = /:(\d+):(\d+)\)$/m; | ||
var m = re_pos.exec(msgLines[1]); | ||
//var row = +m[1]; | ||
//if (row != 1) throw Error("row != 1"); | ||
var col = +m[2]; | ||
var pos = null; | ||
for (var i = 0; i < posLog.length; ++i) { | ||
if (posLog[i][0] + 1 >= col) { | ||
pos = posLog[i][1]; | ||
break; | ||
} | ||
} | ||
//if (pos == null) throw Error("pos == null"); | ||
function posToString(pos) { | ||
return '(' + pos.row + ',' + pos.col + ')'; | ||
} | ||
return Error('CroxError: ' + posToString(pos.pos) + '\n' + msg); | ||
} + '(_e,' + JSON.stringify(posLog) + ');}'; | ||
} | ||
else { | ||
body += s; | ||
} | ||
body += "return _s;"; | ||
@@ -922,2 +1089,2 @@ var f = Function('root', body); | ||
Crox.version = "1.3.1";return Crox;})();if ( typeof module == "object" && module && typeof module.exports == "object" ) module.exports = Crox;else if (typeof define == "function" && (define.amd || define.cmd) ) define(function () { return Crox; } );else if (typeof KISSY != "undefined") KISSY.add(function(){ return Crox; });if (root) root.Crox = Crox; })(this); | ||
Crox.version = "1.3.2";return Crox;})();if ( typeof module == "object" && module && typeof module.exports == "object" ) module.exports = Crox;else if (typeof define == "function" && (define.amd || define.cmd) ) define(function () { return Crox; } );else if (typeof KISSY != "undefined") KISSY.add(function(){ return Crox; });if (root) root.Crox = Crox; })(this); |
/* | ||
Crox v1.3.1 | ||
Crox v1.3.2 | ||
https://github.com/thx/crox | ||
Released under the MIT license | ||
md5: 5044d32956236a27ece77f46dbaac172 | ||
md5: c6378ee1e0165e2bd5251ecf6aa5d59a | ||
*/ | ||
(function(v){var t=function(){function t(a,b){this.row=a;this.col=b}function z(a,b){var e=a.substring(0,b),d=e.match(/\r\n?|\n/g),h=1;d&&(h+=d.length);e=1+/[^\r\n]*$/.exec(e)[0].length;return new t(h,e)}function v(a){return'"'+a.replace(/[\x00-\x1f"\\\u2028\u2029]/g,function(b){switch(b){case '"':return'\\"';case "\\":return"\\\\";case "\b":return"\\b";case "\f":return"\\f";case "\n":return"\\n";case "\r":return"\\r";case "\t":return"\\t"}return"\\u"+("000"+b.charCodeAt(0).toString(16)).slice(-4)})+ | ||
'"'}function A(a){return eval(a)}function I(a){function b(c,b,m,a){this.tag=c;this.text=b;this.index=m;this.subMatches=a}function e(){}function d(c){for(var b=1,m=[],a=[1],f=[],k=0;k<c.length;++k)a.push(b+=RegExp("|"+c[k][0].source).exec("").length),f.push(c[k][1]||e),m.push("("+c[k][0].source+")");return[RegExp(m.join("|")+"|","g"),a,f]}b.prototype.toString=function(){return this.text};var h=a.$||"$",c={},f;for(f in a)"$"!=f.charAt(0)&&(c[f]=d(a[f]));return function(a){var f=a.length,m=0,d=[""], | ||
g={text:"",index:0,source:a,pushState:function(c){d.push(c)},popState:function(){d.pop()},retract:function(c){m-=c}};return{scan:function(){do{var k;a:{var e=c[d[d.length-1]],l=e[0];l.lastIndex=m;k=l.exec(a);if(""==k[0]){if(m<f)throw Error("lexer error: "+z(a,m)+"\n"+a.slice(m,m+50));k=new b(h,"",m)}else{g.index=m;m=l.lastIndex;for(var l=e[1],p=0;p<l.length;++p)if(k[l[p]]){e=e[2][p].apply(g,k.slice(l[p],l[p+1]));k=new b(e,k[0],g.index,k.slice(l[p]+1,l[p+1]));break a}k=void 0}}}while(null==k.tag); | ||
return k},getPos:function(c){return z(a,c)}}}}function x(a){var b;a:{switch(a){case "id":case "lit":b=!0;break a}b=!1}return b||"."==a||"[]"==a}function y(a){return x(a)||"!"==a||"u-"==a}function B(a){if(y(a))return!0;switch(a){case "*":case "/":case "%":return!0}return!1}function C(a){if(B(a))return!0;switch(a){case "+":case "-":return!0}return!1}function D(a){if(C(a))return!0;switch(a){case "<":case ">":case "<=":case ">=":return!0}return!1}function E(a){if(D(a))return!0;switch(a){case "eq":case "ne":return!0}return!1} | ||
function F(a){return E(a)||"&&"==a}function J(a){return F(a)||"||"==a}function K(a,b,e){function d(c){q+=c}function h(c){for(var a=0;a<c.length;++a){var g=c[a];switch(g[0]){case "if":d("if("+f(g[1])+"){");h(g[2]);d("}");g[3]&&(d("else{"),h(g[3]),d("}"));break;case "each":var k=g[3]?g[3].replace(/^_+/,"$&$&"):"_"+w++,q=f(g[1]);if(/^\w+$/.test(q))var l=q;else l="_"+w++,d("var "+l+" = "+q+";");g[5]?d("for(var "+k+"=0;"+k+"<"+l+".length;"+k+"++){"):d("for(var "+k+" in "+l+") {");d("var "+g[4]+" = "+l+ | ||
"["+k+"];");h(g[2]);d("}");break;case "set":d("var "+g[1].replace(/^_+/,"$&$&")+"="+f(g[2])+";");break;case "eval":k=f(g[1]);/^\w+$/.test(k)?q=k:(q="_t",d("_t = "+k+";"));d("if("+q+" !=null)_s += "+((e?!g[2]:g[2])?b+"("+q+")":q)+";");break;case "text":d("_s += "+v(g[1])+";");break;case "inc":break;default:throw Error("unknown stmt: "+g[0]);}}}function c(c,a){var b=f(c);a&&!a(c[0])&&(b="("+b+")");return b}function f(a){switch(a[0]){case "id":return a[1].replace(/^_+/,"$&$&");case "lit":return"string"== | ||
typeof a[1]?v(a[1]):String(a[1]);case ".":return c(a[1],x)+"."+a[2];case "[]":return c(a[1],x)+"["+f(a[2])+"]";case "()":var b=[];if(a[2])for(var g=0;g<a[2].length;++g)b.push(f(a[2][g]));return c(a[1],x)+"("+b.join(",")+")";case "!":return"!"+c(a[1],y);case "u-":return"- "+c(a[1],y);case "*":case "/":case "%":return c(a[1],B)+a[0]+c(a[2],y);case "+":case "-":return c(a[1],C)+a[0]+" "+c(a[2],B);case "<":case ">":case "<=":case ">=":return c(a[1],D)+a[0]+c(a[2],C);case "==":case "!=":case "===":case "!==":return c(a[1], | ||
E)+a[0]+c(a[2],D);case "&&":return c(a[1],F)+"&&"+c(a[2],E);case "||":return c(a[1],J)+"||"+c(a[2],F);default:throw Error("unknown expr: "+a[0]);}}var w=0,q="";h(a[1]);return q}function G(a){return L(M(a))}function H(a,b){var e=G(a),d;b&&(d=b.htmlEncode);a=K(e,d||"_htmlEncode",!0);e="";d||(e="var _obj = { '<': '<', '>': '>', '&': '&', '\"': '"' };\tfunction _htmlEncode(s) {\t\treturn String(s).replace(/[<>&\"]/g, function(c) {\t\t\treturn _obj[c];\t\t});\t}");return Function("root", | ||
e+("var _t,_s = '';"+a+"return _s;"))}t.prototype.toString=function(){return"("+this.row+","+this.col+")"};var M=function(){var a=[[/\s+/],[/\/\/[^\r\n]*|\/\*[\s\S]*?\*\//],[/[A-Za-z_]\w*/,function(a){switch(a){case "true":case "false":return"boolean";case "set":case "include":return a;default:if(-1!=" abstract boolean break byte case catch char class const continue debugger default delete do double else enum export extends final finally float for function goto if implements import in instanceof int interface let long native new package private protected public return short static super switch synchronized this throw throws transient try typeof var void volatile while with yield ".indexOf(" "+ | ||
a+" ")||"null"==a)throw Error("Reserved: "+a+" "+z(this.source,this.index));return"realId"}}],[/"(?:[^"\\]|\\[\s\S])*"|'(?:[^'\\]|\\[\s\S])*'/,function(a){return"string"}],[/\d+(?:\.\d+)?(?:e-?\d+)?/,function(a){return"number"}],[function(a){a.sort().reverse();for(var e=0;e<a.length;++e)a[e]=a[e].replace(/[()*+?.[\]|]/g,"\\$&");return RegExp(a.join("|"))}("! % && ( ) * + - . / < <= = > >= [ ] || === !== == != ,".split(" ")),function(a){return/[*/%]/.test(a)?"mul":/[<>]/.test(a)?"rel":/[!=]=/.test(a)? | ||
"eq":a}]];return I({"":[[/(?:(?!{{)[\s\S])+/,function(a){return"text"}],[/{{{/,function(a){this.pushState(a);return a}],[/{{(?:\/if|else|\/each|\/forin|\/raw)}}/,function(a){return a}],[/{{#raw}}/,function(a){this.pushState("raw");return a}],[/{{(?:#(?:if|each|forin)(?=\s))?/,function(a){this.pushState("{{");return a}]],raw:[[/(?:(?!{{\/raw}})[\s\S])+/,function(a){this.popState();return"rawtext"}]],"{{":a.concat([[/}}/,function(a){this.popState();return a}]]),"{{{":a.concat([[/}}}/,function(a){this.popState(); | ||
return a}]])})}(),L=function(){return function(a){function b(a,c){return f[a][c]}for(var e=a.nStart,d=a.tSymbols,h={},c=0;c<d.length;++c)h[d[c]]=c;var f=a.tAction,w=a.tGoto,q=a.tRules,m=a.tFuncs,u=a.actionIndex;u&&(b=function(a,c){var b=f[u[a]];return b[c]||b._});return function(a,c){function f(c){throw Error("Syntax error: "+a.getPos(u.index)+(c?"\n"+c:""));}var l=0,p=[0],u=a.scan(),r=[],t={get:function(a){return r[r.length+a]},set:function(a,c){r[r.length+a]=c}};if(c)for(var n in c)t[n]=c[n];for(;;)if(n= | ||
b(l,h[u.tag]))if(0<n)p.push(l=n),r.push(u),u=a.scan();else if(0>n&&-32768<n){n=-n;var l=q[n],s=l.length-1;p.length-=s;l=w[p[p.length-1]][l[0]-e];p.push(l);m[n]?(n=m[n].apply(t,r.splice(r.length-s,s)),r.push(n)):1!=s&&r.splice(r.length-s,s,null)}else return u.tag!=d[0]&&f(),r[0];else{n=[];for(s=0;s<e;++s)b(l,s)&&n.push(d[s]);f("find "+u.tag+"\nexpect "+n.join(" "))}}}({nStart:37,tSymbols:"$ ! && ( ) + , - . = [ ] boolean eq include mul number rawtext realId rel set string text {{ {{#each {{#forin {{#if {{#raw}} {{/each}} {{/forin}} {{/if}} {{/raw}} {{else}} {{{ || }} }}} AdditiveExpression EqualityExpression LogicalAndExpression LogicalOrExpression MemberExpression MultiplicativeExpression PrimaryExpression RelationalExpression UnaryExpression _text args epsilon expr id name program statement statements texts".split(" "), | ||
tAction:[{_:-2},{_:-32768},{22:3,23:4,24:5,25:6,26:7,27:8,33:9,_:-1},{_:-19},{1:13,3:14,7:15,12:16,14:17,16:18,18:19,20:20,21:21,_:0},{1:13,3:14,7:15,12:16,14:33,16:18,18:19,20:34,21:21,_:0},{17:38,_:0},{_:-17},{_:-3},{22:3,27:8,_:-13},{_:-26},{21:44,_:-23},{_:-25},{_:-21},{14:33,18:19,20:34,_:-22},{_:-24},{5:46,7:47,_:-44},{13:48,_:-48},{2:49,_:-50},{34:50,_:-52},{3:51,8:52,10:53,_:-36},{15:54,_:-41},{_:-29},{19:55,_:-46},{_:-39},{35:56,_:0},{_:-27},{_:-23},{_:-22},{14:33,18:19,20:34,21:57,_:0}, | ||
{35:61,_:0},{31:62,_:0},{36:63,_:0},{_:-18},{_:-37},{4:64,_:0},{_:-38},{35:65,_:0},{9:66,_:0},{1:13,3:14,7:15,12:16,14:33,16:18,18:19,20:34,21:21,_:-53},{14:33,18:19,20:34,_:0},{_:-11},{_:-15},{_:-16},{14:33,18:19,20:34,21:57,_:-53},{_:-20},{_:-12},{_:-28},{_:-14},{15:54,_:-42},{15:54,_:-43},{19:55,_:-47},{13:48,_:-49},{2:49,_:-51},{4:85,6:86,_:0},{4:87,_:0},{_:-34},{_:-30},{11:88,_:0},{_:-40},{5:46,7:47,_:-45},{35:89,_:0},{35:90,_:0},{35:91,_:0},{35:92,_:0},{22:3,23:4,24:5,25:6,26:7,27:8,30:93,32:94, | ||
33:9,_:0},{35:95,_:0},{_:-33},{_:-32},{_:-31},{_:-4},{_:-10},{_:-35},{22:3,23:4,24:5,25:6,26:7,27:8,28:102,33:9,_:0},{22:3,23:4,24:5,25:6,26:7,27:8,28:103,33:9,_:0},{22:3,23:4,24:5,25:6,26:7,27:8,29:104,33:9,_:0},{22:3,23:4,24:5,25:6,26:7,27:8,29:105,33:9,_:0},{22:3,23:4,24:5,25:6,26:7,27:8,30:106,33:9,_:0},{_:-6},{_:-7},{_:-8},{_:-9},{_:-5}],actionIndex:[0,1,2,3,4,5,5,5,6,5,7,8,9,5,5,5,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,29,30,31,32,33,34,35,36,37,38,5,5,5,5,5,39,40,5,5,5, | ||
41,42,43,44,44,0,45,46,47,48,5,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,5,68,69,0,0,0,0,70,0,71,72,73,74,75,76,77,78,79,80,81,82],tGoto:[{15:1,17:2},,{9:10,16:11,18:12},,{0:22,1:23,2:24,3:25,4:26,5:27,6:28,7:29,8:30,12:31,13:32},{0:22,1:23,2:24,3:25,4:26,5:27,6:28,7:29,8:30,12:35,13:32},{0:22,1:23,2:24,3:25,4:26,5:27,6:28,7:29,8:30,12:36,13:32},{0:22,1:23,2:24,3:25,4:26,5:27,6:28,7:29,8:30,12:37,13:32},,{0:22,1:23,2:24,3:25,4:26,5:27,6:28,7:29,8:30,12:39,13:32},,,{9:40},{4:26,6:28, | ||
8:41,13:32},{0:22,1:23,2:24,3:25,4:26,5:27,6:28,7:29,8:30,12:42,13:32},{4:26,6:28,8:43,13:32},,,,,{13:45},,,,,,,,,,,,,,,{13:58,14:59},{13:58,14:60},,,,,,,,,,{4:26,5:67,6:28,8:30,13:32},{4:26,5:68,6:28,8:30,13:32},{0:22,4:26,5:27,6:28,7:69,8:30,13:32},{0:22,1:70,4:26,5:27,6:28,7:29,8:30,13:32},{0:22,1:23,2:71,4:26,5:27,6:28,7:29,8:30,13:32},{0:22,1:23,2:24,3:25,4:26,5:27,6:28,7:29,8:30,10:72,11:73,12:74,13:32},{13:75},{0:22,1:23,2:24,3:25,4:26,5:27,6:28,7:29,8:30,12:76,13:32},{4:26,6:28,8:77,13:32}, | ||
{0:78,4:26,5:27,6:28,8:30,13:32},,,,{11:79,13:58,14:80},{11:81,13:58,14:82},{17:83},,,,,{0:22,1:23,2:24,3:25,4:26,5:27,6:28,7:29,8:30,12:84,13:32},,,,,,,,,,,,,,,,,{9:10,16:11,18:12},,,{0:22,1:23,2:24,3:25,4:26,5:27,6:28,7:29,8:30,12:96,13:32},,,{17:97},{17:98},{17:99},{17:100},,{17:101},,,{9:10,16:11,18:12},{9:10,16:11,18:12},{9:10,16:11,18:12},{9:10,16:11,18:12},{9:10,16:11,18:12}],tRules:[[56,52],[52,54],[54],[54,54,53],[53,26,49,35,54,30],[53,26,49,35,54,32,54,30],[53,24,49,51,48,35,54,28],[53, | ||
24,49,51,51,35,54,28],[53,25,49,51,48,35,54,29],[53,25,49,51,51,35,54,29],[53,23,20,50,9,49,35],[53,23,49,35],[53,33,49,36],[53,55],[53,23,14,21,35],[51,21],[51,50],[55,46],[55,55,46],[46,22],[46,27,17,31],[50,18],[50,20],[50,14],[43,21],[43,16],[43,12],[43,50],[43,3,49,4],[41,43],[41,41,8,50],[41,41,10,49,11],[41,41,3,48,4],[41,41,3,47,4],[47,49],[47,47,6,49],[45,41],[45,1,45],[45,7,45],[42,45],[42,42,15,45],[37,42],[37,37,5,42],[37,37,7,42],[44,37],[44,44,19,37],[38,44],[38,38,13,44],[39,38],[39, | ||
39,2,38],[40,39],[40,40,34,39],[49,40],[48]],tFuncs:function(){function a(a,f,b,d,e,h,g){return["each",f,h,d,b,!0]}function b(a,f,b,d,e,h,g){return["each",f,h,d,b,!1]}function e(a){return a.text}function d(a,f,b,d){return["()",a,b]}function h(a,f,b){return[f.text,a,b]}return[,function(a){return["prog",a]},function(){return[]},function(a,f){a.push(f);return a},function(a,f,b,d,e){return["if",f,d]},function(a,f,b,d,e,h,g){return["if",f,d,h]},a,a,b,b,function(a,f,b,d,e,h){return["set",b.text,e]},function(a, | ||
b,d){return["eval",b,!1]},function(a,b,d){return["eval",b,!0]},function(a){return["text",a]},function(a,b,d,e){return["inc",A(d.text)]},function(a){return A(a.text)},e,function(a){return a},function(a,b){return a+b},e,function(a,b,d){return b.text},,,,function(a){return["lit",A(a.text)]},function(a){return["lit",+a.text]},function(a){return["lit","true"==a.text]},function(a){return["id",a.text]},function(a,b,d){return b},,function(a,b,d){return[".",a,d.text]},function(a,b,d,e){return["[]",a,d]},d, | ||
d,function(a){return[a]},function(a,b,d){a.push(d);return a},,function(a,b){return["!",b]},function(a,b){return["u-",b]},,h,,h,h,,h,,h,,h,,h]}()})}();return{parse:G,compile:H,render:function(a,b){return H(a)(b)},version:"1.3.1"}}();"object"==typeof module&&module&&"object"==typeof module.exports?module.exports=t:"function"==typeof define&&(define.amd||define.cmd)?define(function(){return t}):"undefined"!=typeof KISSY&&KISSY.add(function(){return t});v&&(v.Crox=t)})(this); | ||
(function(z){var m=function(){function m(a,e){this.row=a;this.col=e}function z(a,e){var d=a.substring(0,e),b=d.match(/\r\n?|\n/g),r=1;b&&(r+=b.length);d=1+/[^\r\n]*$/.exec(d)[0].length;return new m(r,d)}function N(a){return'"'+a.replace(/[\x00-\x1f"\\\u2028\u2029]/g,function(a){switch(a){case '"':return'\\"';case "\\":return"\\\\";case "\b":return"\\b";case "\f":return"\\f";case "\n":return"\\n";case "\r":return"\\r";case "\t":return"\\t"}return"\\u"+("000"+a.charCodeAt(0).toString(16)).slice(-4)})+ | ||
'"'}function H(a){return eval(a)}function Q(a){function e(a,e,b,d,r,h){this.tag=a;this.text=e;this.index=b;this.subMatches=d;this.end=r;this.pos=h}function d(){}function b(a){for(var e=1,b=[],r=[1],t=[],h=0;h<a.length;++h)r.push(e+=RegExp("|"+a[h][0].source).exec("").length),t.push(a[h][1]||d),b.push("("+a[h][0].source+")");return[RegExp(b.join("|")+"|","g"),r,t]}e.prototype.toString=function(){return this.text};var r=a.$||"$",t={},p;for(p in a)"$"!=p.charAt(0)&&(t[p]=b(a[p]));return function(a){var b= | ||
a.length,d=0,p=[""],A={text:"",index:0,source:a,pushState:function(k){p.push(k)},popState:function(){p.pop()},retract:function(k){d-=k}},h=new m(1,1),C=/\r\n?|\n/g,g=/[^\r\n\u2028\u2029]*$/;return{scan:function(){do{var k;a:{var v=t[p[p.length-1]],c=v[0];c.lastIndex=d;k=c.exec(a);if(""==k[0]){if(d<b)throw Error("lexer error: "+h+"\n"+a.slice(d,d+50));k=new e(r,"",d,null,d,h)}else{A.index=d;d=c.lastIndex;for(var c=v[1],q=0;q<c.length;++q)if(k[c[q]]){v=v[2][q].apply(A,k.slice(c[q],c[q+1]));k=null== | ||
v?null:new e(v,k[0],A.index,k.slice(c[q]+1,c[q+1]),d,h);break a}k=void 0}}if(null!=k)return v=h.row,c=h.col,q=(q=k.text.match(C))?q.length:0,v+=q,c=0==q?c+k.text.length:g.exec(k.text)[0].length+1,h=new m(v,c),k}while(1)},GetCurrentPosition:function(){return h},getPos:function(k){return z(a,k)}}}}function D(a){var e;a:{switch(a){case "id":case "lit":e=!0;break a}e=!1}return e||"."==a||"[]"==a}function E(a){return D(a)||"!"==a||"u-"==a}function I(a){if(E(a))return!0;switch(a){case "*":case "/":case "%":return!0}return!1} | ||
function J(a){if(I(a))return!0;switch(a){case "+":case "-":return!0}return!1}function K(a){if(J(a))return!0;switch(a){case "<":case ">":case "<=":case ">=":return!0}return!1}function L(a){if(K(a))return!0;switch(a){case "eq":case "ne":return!0}return!1}function M(a){return L(a)||"&&"==a}function R(a){return M(a)||"||"==a}function S(a,e,d){function b(k){h.push(k)}function r(k,a){k.pos=a;return k}function t(k){for(var a=0;a<k.length;++a){var c=k[a];switch(c[0]){case "if":b("if(");b(n(c[1]));b("){"); | ||
t(c[2]);b("}");c[3]&&(b("else{"),t(c[3]),b("}"));break;case "each":var f=c[3]?c[3].replace(/^_+/,"$&$&"):"_"+A++,g=n(c[1]),h=p(g);/^\w+$/.test(h)||(h="_"+A++,b("var "+h+" = "),b(g),b(";"));c[5]?(b("for(var "+f+"=0;"+f+"<"),b(n([".",r(["t",h],c[1].pos),"length"])),b(";"+f+"++){")):b("for(var "+f+" in "+h+") {");b("var "+c[4]+" = ");b(n(["[]",r(["t",h],c[1].pos),["t",f]]));b(";");t(c[2]);b("}");break;case "set":b("var "+c[1].replace(/^_+/,"$&$&")+"=");b(n(c[2]));b(";");break;case "eval":g=n(c[1]);h= | ||
p(g);/^\w+$/.test(h)?f=h:(f="_t",b("_t = "),b(g),b(";"));b("if("+f+" !=null)_s += "+((d?!c[2]:c[2])?e+"("+f+")":f)+";");break;case "text":b("_s += "+N(c[1])+";");break;case "inc":break;default:throw Error("unknown stmt: "+c[0]);}}}function p(a){if("string"==typeof a)return a;if(a instanceof Array){for(var e=[],c=0;c<a.length;++c)e.push(p(a[c]));return e.join("")}throw Error("unknown type");}function f(a,e){var c=n(a);e&&!e(a[0])&&(c=["(",c,")"]);return c}function n(a){return r(F(a),a.pos)}function F(a){switch(a[0]){case "t":return a[1]; | ||
case "id":return a[1].replace(/^_+/,"$&$&");case "lit":return"string"==typeof a[1]?N(a[1]):String(a[1]);case ".":return[f(a[1],D),".",a[2]];case "[]":return[f(a[1],D),"[",n(a[2])+"]"];case "()":var e=[f(a[1],D),"("];if(a[2])for(var c=0;c<a[2].length;++c)0<c&&e.push(","),e.push(n(a[2][c]));e.push(")");return e;case "!":return["!",f(a[1],E)];case "u-":return["- ",f(a[1],E)];case "*":case "/":case "%":return[f(a[1],I),a[0],f(a[2],E)];case "+":case "-":return[f(a[1],J),a[0]," ",f(a[2],I)];case "<":case ">":case "<=":case ">=":return[f(a[1], | ||
K),a[0],f(a[2],J)];case "==":case "!=":case "===":case "!==":return[f(a[1],L),a[0],f(a[2],K)];case "&&":return[f(a[1],M),"&&",f(a[2],L)];case "||":return[f(a[1],R),"||",f(a[2],M)];default:throw Error("unknown expr: "+a[0]);}}function m(a){"string"==typeof a&&(g+=a);if(a instanceof Array){a.pos&&C.push([g.length,a.pos]);for(var e=0;e<a.length;++e)m(a[e])}}var A=0,h=[];t(a[1]);var C=[],g="";m(h);a=new String(g);a.posLog=C;return a}function O(a){return T(U(a))}function P(a,e){var d=O(a),b;e&&(b=e.htmlEncode); | ||
a=S(d,b||"_htmlEncode",!0);d="";b||(d="var _obj = { '<': '<', '>': '>', '&': '&', '\"': '"' };\r\n\tfunction _htmlEncode(s) {\r\n\t\treturn String(s).replace(/[<>&\"]/g, function(c) {\r\n\t\t\treturn _obj[c];\r\n\t\t});\r\n\t}");d+="var _t,_s = '';";e&&e.debug?(b=a.posLog,d=d+"try{\n"+("eval("+JSON.stringify(a)+");"),d+="}catch(_e){throw "+function(a,e){for(var d=a.stack,b=d.split(/\r\n?|\n/),b=+/:(\d+):(\d+)\)$/m.exec(b[1])[2],n=null,m=0;m<e.length;++m)if(e[m][0]+1>=b){n=e[m][1];break}b= | ||
n.pos;return Error("CroxError: "+("("+b.row+","+b.col+")")+"\n"+d)}+"(_e,"+JSON.stringify(b)+");}"):d+=a;d+="return _s;";return Function("root",d)}m.prototype.toString=function(){return"("+this.row+","+this.col+")"};var U=function(){var a=[[/\s+/],[/\/\/[^\r\n]*|\/\*[\s\S]*?\*\//],[/[A-Za-z_]\w*/,function(a){switch(a){case "true":case "false":return"boolean";case "set":case "include":return a;default:if(-1!=" abstract boolean break byte case catch char class const continue debugger default delete do double else enum export extends final finally float for function goto if implements import in instanceof int interface let long native new package private protected public return short static super switch synchronized this throw throws transient try typeof var void volatile while with yield ".indexOf(" "+ | ||
a+" ")||"null"==a)throw Error("Reserved: "+a+" "+z(this.source,this.index));return"realId"}}],[/"(?:[^"\\]|\\[\s\S])*"|'(?:[^'\\]|\\[\s\S])*'/,function(a){return"string"}],[/\d+(?:\.\d+)?(?:e-?\d+)?/,function(a){return"number"}],[function(a){a.sort().reverse();for(var d=0;d<a.length;++d)a[d]=a[d].replace(/[()*+?.[\]|]/g,"\\$&");return RegExp(a.join("|"))}("! % && ( ) * + - . / < <= = > >= [ ] || === !== == != ,".split(" ")),function(a){return/[*/%]/.test(a)?"mul":/[<>]/.test(a)?"rel":/[!=]=/.test(a)? | ||
"eq":a}]];return Q({"":[[/(?:(?!{{)[\s\S])+/,function(a){return"text"}],[/{{{/,function(a){this.pushState(a);return a}],[/{{(?:\/if|else|\/each|\/forin|\/raw)}}/,function(a){return a}],[/{{#raw}}/,function(a){this.pushState("raw");return a}],[/{{(?:#(?:if|each|forin)(?=\s))?/,function(a){this.pushState("{{");return a}]],raw:[[/(?:(?!{{\/raw}})[\s\S])+/,function(a){this.popState();return"rawtext"}]],"{{":a.concat([[/}}/,function(a){this.popState();return a}]]),"{{{":a.concat([[/}}}/,function(a){this.popState(); | ||
return a}]])})}(),T=function(){var a={nStart:37,tSymbols:"$ ! && ( ) + , - . = [ ] boolean eq include mul number rawtext realId rel set string text {{ {{#each {{#forin {{#if {{#raw}} {{/each}} {{/forin}} {{/if}} {{/raw}} {{else}} {{{ || }} }}} AdditiveExpression EqualityExpression LogicalAndExpression LogicalOrExpression MemberExpression MultiplicativeExpression PrimaryExpression RelationalExpression UnaryExpression _text args empty expr id name program statement statements texts program'".split(" "), | ||
actionList:[{_:-2},{_:-32768},{22:11,23:9,24:7,25:8,26:6,27:12,33:10,_:-1},{_:-3},{22:11,27:12,_:-13},{_:-17},{1:32,3:31,7:33,12:30,14:26,16:29,18:28,20:25,21:27,_:0},{1:32,3:31,7:33,12:30,14:38,16:29,18:28,20:37,21:27,_:0},{_:-19},{17:40,_:0},{_:-18},{_:-27},{_:-29},{3:41,8:42,10:43,_:-36},{_:-39},{15:44,_:-41},{5:46,7:45,_:-44},{19:47,_:-46},{13:48,_:-48},{2:49,_:-50},{34:50,_:-52},{35:51,_:0},{_:-22},{_:-23},{_:-24},{_:-21},{_:-25},{_:-26},{14:26,18:28,20:25,21:57,_:0},{35:59,_:0},{14:26,18:28, | ||
20:25,_:-22},{21:61,_:-23},{36:62,_:0},{31:63,_:0},{1:32,3:31,7:33,12:30,14:26,16:29,18:28,20:25,21:27,_:-53},{14:26,18:28,20:25,_:0},{_:-2},{4:77,_:0},{_:-37},{_:-38},{14:26,18:28,20:25,21:57,_:-53},{_:-16},{_:-15},{_:-11},{9:82,_:0},{35:83,_:0},{_:-12},{_:-20},{4:84,6:85,_:0},{_:-34},{4:86,_:0},{_:-30},{11:87,_:0},{_:-40},{15:44,_:-43},{15:44,_:-42},{5:46,7:45,_:-45},{19:47,_:-47},{13:48,_:-49},{2:49,_:-51},{22:11,23:9,24:7,25:8,26:6,27:12,30:88,32:89,33:10,_:0},{_:-28},{35:90,_:0},{35:91,_:0}, | ||
{35:92,_:0},{35:93,_:0},{_:-14},{_:-32},{_:-33},{_:-31},{_:-4},{_:-2},{_:-2},{_:-2},{35:101,_:0},{_:-35},{22:11,23:9,24:7,25:8,26:6,27:12,30:102,33:10,_:0},{22:11,23:9,24:7,25:8,26:6,27:12,28:103,33:10,_:0},{22:11,23:9,24:7,25:8,26:6,27:12,28:104,33:10,_:0},{22:11,23:9,24:7,25:8,26:6,27:12,29:105,33:10,_:0},{22:11,23:9,24:7,25:8,26:6,27:12,29:106,33:10,_:0},{_:-10},{_:-5},{_:-6},{_:-7},{_:-8},{_:-9}],actionIndex:[0,1,2,3,4,5,6,6,6,7,6,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,6,6, | ||
6,28,28,29,30,31,32,33,34,35,6,6,6,6,6,6,6,6,36,37,38,39,40,41,42,40,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,6,66,67,6,68,69,70,71,72,72,73,73,74,75,76,77,78,79,80,81,82,83,84,85,86],tGoto:[{52:1,54:2},{},{53:3,55:4,46:5},{},{46:13},{},{50:14,43:15,41:16,45:17,42:18,37:19,44:20,38:21,39:22,40:23,49:24},{50:14,43:15,41:16,45:17,42:18,37:19,44:20,38:21,39:22,40:23,49:34},{50:14,43:15,41:16,45:17,42:18,37:19,44:20,38:21,39:22,40:23,49:35},{50:14,43:15,41:16,45:17,42:18,37:19, | ||
44:20,38:21,39:22,40:23,49:36},{50:14,43:15,41:16,45:17,42:18,37:19,44:20,38:21,39:22,40:23,49:39},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{50:14,43:15,41:16,45:17,42:18,37:19,44:20,38:21,39:22,40:23,49:52},{50:14,43:15,41:16,45:53},{50:14,43:15,41:16,45:54},{51:55,50:56},{51:58,50:56},{},{50:60},{},{},{},{50:14,43:15,41:16,47:64,45:17,42:18,37:19,44:20,38:21,39:22,40:23,49:65,48:66},{50:67},{50:14,43:15,41:16,45:17,42:18,37:19,44:20,38:21,39:22,40:23,49:68},{50:14,43:15,41:16, | ||
45:69},{50:14,43:15,41:16,45:17,42:70},{50:14,43:15,41:16,45:17,42:71},{50:14,43:15,41:16,45:17,42:18,37:72},{50:14,43:15,41:16,45:17,42:18,37:19,44:73},{50:14,43:15,41:16,45:17,42:18,37:19,44:20,38:74},{50:14,43:15,41:16,45:17,42:18,37:19,44:20,38:21,39:75},{54:76},{},{},{},{51:78,50:56,48:79},{},{},{51:80,50:56,48:81},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{53:3,55:4,46:5},{},{},{},{},{},{50:14,43:15,41:16,45:17,42:18,37:19,44:20,38:21,39:22,40:23,49:94},{},{},{50:14,43:15,41:16,45:17, | ||
42:18,37:19,44:20,38:21,39:22,40:23,49:95},{},{},{},{54:96},{54:97},{54:98},{54:99},{54:100},{},{},{53:3,55:4,46:5},{53:3,55:4,46:5},{53:3,55:4,46:5},{53:3,55:4,46:5},{53:3,55:4,46:5},{},{},{},{},{},{}],tRules:[[56,52],[52,54],[54],[54,54,53],[53,26,49,35,54,30],[53,26,49,35,54,32,54,30],[53,24,49,51,51,35,54,28],[53,24,49,51,48,35,54,28],[53,25,49,51,51,35,54,29],[53,25,49,51,48,35,54,29],[53,23,20,50,9,49,35],[53,23,49,35],[53,33,49,36],[53,55],[53,23,14,21,35],[51,21],[51,50],[55,46],[55,55,46], | ||
[46,22],[46,27,17,31],[50,18],[50,20],[50,14],[43,21],[43,16],[43,12],[43,50],[43,3,49,4],[41,43],[41,41,8,50],[41,41,10,49,11],[41,41,3,47,4],[41,41,3,48,4],[47,49],[47,47,6,49],[45,41],[45,1,45],[45,7,45],[42,45],[42,42,15,45],[37,42],[37,37,5,42],[37,37,7,42],[44,37],[44,44,19,37],[38,44],[38,38,13,44],[39,38],[39,39,2,38],[40,39],[40,40,34,39],[49,40],[48]],objCharset:null};return function(e,d){function b(a,b,c,d,e,f,g){return["each",b,f,d,c,!0]}function m(a,b,c,d,e,f,g){return["each",b,f,d,c, | ||
!1]}function t(a){return a.text}function p(a,b,c,d){return["()",a,c]}function f(a,b,c){return[b.text,a,c]}function n(a,b){return k[a][b]}function F(a,b,c){this.start=a;this.end=b;this.pos=c}function z(a){throw Error("Syntax error: "+e.getPos(w.index)+(a?"\n"+a:""));}for(var A=a.nStart,h=a.tSymbols,C={},g=0;g<h.length;++g)C[h[g]]=g;var k=a.tAction||a.actionList,v=a.tGoto,c=a.tRules,q=a.actionIndex,D=[,function(a){return["prog",a]},function(){return[]},function(a,b){a.push(b);return a},function(a,b, | ||
c,d,e){return["if",b,d]},function(a,b,c,d,e,f,g){return["if",b,d,f]},b,b,m,m,function(a,b,c,d,e,f){return["set",c.text,e]},function(a,b,c){return["eval",b,!1]},function(a,b,c){return["eval",b,!0]},function(a){return["text",a]},function(a,b,c,d){return["inc",H(c.text)]},function(a){return H(a.text)},t,function(a){return a},function(a,b){return a+b},t,function(a,b,c){return b.text},,,,function(a){return["lit",H(a.text)]},function(a){return["lit",+a.text]},function(a){return["lit","true"==a.text]},function(a){return["id", | ||
a.text]},function(a,b,c){return b},,function(a,b,c){return[".",a,c.text]},function(a,b,c,d){return["[]",a,c]},p,p,function(a){return[a]},function(a,b,c){a.push(c);return a},,function(a,b){return["!",b]},function(a,b){return["u-",b]},,f,,f,f,,f,,f,,f,,f];q&&(n=function(a,b){var c=k[q[a]];return c[b]||c._});var B=0,G=[0],w=e.scan(),x=[],E={get:function(a){return x[x.length+a]},set:function(a,b){x[x.length+a]=b}};if(d)for(g in d)E[g]=d[g];g=[];for(F.prototype.toString=function(){return JSON.stringify({start:this.start, | ||
end:this.end,pos:this.pos.toString()})};;){var l=n(B,C[w.tag]);if(l)if(0<l)G.push(B=l),x.push(w),g.push(new F(w.index,w.end,w.pos)),w=e.scan();else if(0>l&&-32768<l){var u=-l,B=c[u],l=B.length-1;G.length-=l;B=v[G[G.length-1]][B[0]];G.push(B);var y=null;D[u]?(y=x.splice(x.length-l,l),y=D[u].apply(E,y),x.push(y)):1!=l&&x.splice(x.length-l,l,null);u=0<g.length?g[g.length-1]:null;0==l?g.push(u=new F(w.index,w.index,w.pos)):1!=l&&(u=new F(g[g.length-l].start,g[g.length-1].end,g[g.length-l].pos),g.splice(g.length- | ||
l,l),g.push(u));y&&y instanceof Array&&0<y.length&&"string"==typeof y[0]&&(y.pos=u)}else return w.tag!=h[0]&&z(),x[0];else{l=[];for(u=0;u<A;++u)n(B,u)&&l.push(h[u]);z("find "+w.tag+"\nexpect "+l.join(" "))}}}}();return{parse:O,compile:P,render:function(a,e){return P(a)(e)},version:"1.3.2"}}();"object"==typeof module&&module&&"object"==typeof module.exports?module.exports=m:"function"==typeof define&&(define.amd||define.cmd)?define(function(){return m}):"undefined"!=typeof KISSY&&KISSY.add(function(){return m}); | ||
z&&(z.Crox=m)})(this); |
/** | ||
* @preserve Crox v1.3.1 | ||
* @preserve Crox v1.3.2 | ||
* https://github.com/thx/crox | ||
* | ||
* Released under the MIT license | ||
* md5: 5044d32956236a27ece77f46dbaac172 | ||
* md5: c6378ee1e0165e2bd5251ecf6aa5d59a | ||
*/ | ||
@@ -149,3 +149,3 @@ (function(root) {var Crox = (function() { | ||
function Token(tag, text, index, subMatches) { | ||
function Token(tag, text, index, subMatches, end, pos) { | ||
this.tag = tag; | ||
@@ -155,2 +155,4 @@ this.text = text; | ||
this.subMatches = subMatches; | ||
this.end = end; | ||
this.pos = pos; | ||
} | ||
@@ -204,2 +206,3 @@ Token.prototype.toString = function() { | ||
}; | ||
var currentPos = new Position(1, 1); | ||
@@ -214,6 +217,6 @@ function scan() { | ||
if (i < Length) { | ||
throw Error('lexer error: ' + getPos(s, i) + | ||
throw Error('lexer error: ' + currentPos + | ||
'\n' + s.slice(i, i + 50)); | ||
} | ||
return new Token(endTag, '', i); | ||
return new Token(endTag, '', i, null, i, currentPos); | ||
} | ||
@@ -226,6 +229,9 @@ obj.index = i; | ||
var tag = rule[2][j].apply(obj, t.slice(idx[j], idx[j + 1])); | ||
return new Token(tag, t[0], obj.index, t.slice(idx[j] + 1, idx[j + 1])); | ||
if (tag == null) return null; | ||
return new Token(tag, t[0], obj.index, t.slice(idx[j] + 1, idx[j + 1]), i, currentPos); | ||
} | ||
} | ||
var re_newLine = /\r\n?|\n/g; | ||
var re_lastLine = /[^\r\n\u2028\u2029]*$/; | ||
return { | ||
@@ -235,5 +241,18 @@ scan: function() { | ||
var t = scan(); | ||
} while (t.tag == null); | ||
return t; | ||
if (t != null) { | ||
var _row = currentPos.row; | ||
var _col = currentPos.col; | ||
var ms = t.text.match(re_newLine); | ||
var h = ms ? ms.length : 0; | ||
_row += h; | ||
if (h == 0) _col += t.text.length; | ||
else _col = re_lastLine.exec(t.text)[0].length + 1; | ||
currentPos = new Position(_row, _col); | ||
return t; | ||
} | ||
} while (true); | ||
}, | ||
GetCurrentPosition: function() { | ||
return currentPos; | ||
}, | ||
getPos: function(i) { | ||
@@ -332,90 +351,146 @@ return getPos(s, i); | ||
var parse = function() { | ||
var table = {/* state num: 107 */ | ||
nStart: 37, | ||
tSymbols: ["$", "!", "&&", "(", ")", "+", ",", "-", ".", "=", "[", "]", "boolean", "eq", "include", "mul", "number", "rawtext", "realId", "rel", "set", "string", "text", "{{", "{{#each", "{{#forin", "{{#if", "{{#raw}}", "{{/each}}", "{{/forin}}", "{{/if}}", "{{/raw}}", "{{else}}", "{{{", "||", "}}", "}}}", "AdditiveExpression", "EqualityExpression", "LogicalAndExpression", "LogicalOrExpression", "MemberExpression", "MultiplicativeExpression", "PrimaryExpression", "RelationalExpression", "UnaryExpression", "_text", "args", "epsilon", "expr", "id", "name", "program", "statement", "statements", "texts"], | ||
tAction: [{ _: -2 }, { _: -32768 }, { 22: 3, 23: 4, 24: 5, 25: 6, 26: 7, 27: 8, 33: 9, _: -1 }, { _: -19 }, { 1: 13, 3: 14, 7: 15, 12: 16, 14: 17, 16: 18, 18: 19, 20: 20, 21: 21, _: 0 }, { 1: 13, 3: 14, 7: 15, 12: 16, 14: 33, 16: 18, 18: 19, 20: 34, 21: 21, _: 0 }, { 17: 38, _: 0 }, { _: -17 }, { _: -3 }, { 22: 3, 27: 8, _: -13 }, { _: -26 }, { 21: 44, _: -23 }, { _: -25 }, { _: -21 }, { 14: 33, 18: 19, 20: 34, _: -22 }, { _: -24 }, { 5: 46, 7: 47, _: -44 }, { 13: 48, _: -48 }, { 2: 49, _: -50 }, { 34: 50, _: -52 }, { 3: 51, 8: 52, 10: 53, _: -36 }, { 15: 54, _: -41 }, { _: -29 }, { 19: 55, _: -46 }, { _: -39 }, { 35: 56, _: 0 }, { _: -27 }, { _: -23 }, { _: -22 }, { 14: 33, 18: 19, 20: 34, 21: 57, _: 0 }, { 35: 61, _: 0 }, { 31: 62, _: 0 }, { 36: 63, _: 0 }, { _: -18 }, { _: -37 }, { 4: 64, _: 0 }, { _: -38 }, { 35: 65, _: 0 }, { 9: 66, _: 0 }, { 1: 13, 3: 14, 7: 15, 12: 16, 14: 33, 16: 18, 18: 19, 20: 34, 21: 21, _: -53 }, { 14: 33, 18: 19, 20: 34, _: 0 }, { _: -11 }, { _: -15 }, { _: -16 }, { 14: 33, 18: 19, 20: 34, 21: 57, _: -53 }, { _: -20 }, { _: -12 }, { _: -28 }, { _: -14 }, { 15: 54, _: -42 }, { 15: 54, _: -43 }, { 19: 55, _: -47 }, { 13: 48, _: -49 }, { 2: 49, _: -51 }, { 4: 85, 6: 86, _: 0 }, { 4: 87, _: 0 }, { _: -34 }, { _: -30 }, { 11: 88, _: 0 }, { _: -40 }, { 5: 46, 7: 47, _: -45 }, { 35: 89, _: 0 }, { 35: 90, _: 0 }, { 35: 91, _: 0 }, { 35: 92, _: 0 }, { 22: 3, 23: 4, 24: 5, 25: 6, 26: 7, 27: 8, 30: 93, 32: 94, 33: 9, _: 0 }, { 35: 95, _: 0 }, { _: -33 }, { _: -32 }, { _: -31 }, { _: -4 }, { _: -10 }, { _: -35 }, { 22: 3, 23: 4, 24: 5, 25: 6, 26: 7, 27: 8, 28: 102, 33: 9, _: 0 }, { 22: 3, 23: 4, 24: 5, 25: 6, 26: 7, 27: 8, 28: 103, 33: 9, _: 0 }, { 22: 3, 23: 4, 24: 5, 25: 6, 26: 7, 27: 8, 29: 104, 33: 9, _: 0 }, { 22: 3, 23: 4, 24: 5, 25: 6, 26: 7, 27: 8, 29: 105, 33: 9, _: 0 }, { 22: 3, 23: 4, 24: 5, 25: 6, 26: 7, 27: 8, 30: 106, 33: 9, _: 0 }, { _: -6 }, { _: -7 }, { _: -8 }, { _: -9 }, { _: -5 }], | ||
actionIndex: [0, 1, 2, 3, 4, 5, 5, 5, 6, 5, 7, 8, 9, 5, 5, 5, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 5, 5, 5, 5, 5, 39, 40, 5, 5, 5, 41, 42, 43, 44, 44, 0, 45, 46, 47, 48, 5, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 5, 68, 69, 0, 0, 0, 0, 70, 0, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82], | ||
tGoto: [{ 15: 1, 17: 2 }, , { 9: 10, 16: 11, 18: 12 }, , { 0: 22, 1: 23, 2: 24, 3: 25, 4: 26, 5: 27, 6: 28, 7: 29, 8: 30, 12: 31, 13: 32 }, { 0: 22, 1: 23, 2: 24, 3: 25, 4: 26, 5: 27, 6: 28, 7: 29, 8: 30, 12: 35, 13: 32 }, { 0: 22, 1: 23, 2: 24, 3: 25, 4: 26, 5: 27, 6: 28, 7: 29, 8: 30, 12: 36, 13: 32 }, { 0: 22, 1: 23, 2: 24, 3: 25, 4: 26, 5: 27, 6: 28, 7: 29, 8: 30, 12: 37, 13: 32 }, , { 0: 22, 1: 23, 2: 24, 3: 25, 4: 26, 5: 27, 6: 28, 7: 29, 8: 30, 12: 39, 13: 32 }, , , { 9: 40 }, { 4: 26, 6: 28, 8: 41, 13: 32 }, { 0: 22, 1: 23, 2: 24, 3: 25, 4: 26, 5: 27, 6: 28, 7: 29, 8: 30, 12: 42, 13: 32 }, { 4: 26, 6: 28, 8: 43, 13: 32 }, , , , , { 13: 45 }, , , , , , , , , , , , , , , { 13: 58, 14: 59 }, { 13: 58, 14: 60 }, , , , , , , , , , { 4: 26, 5: 67, 6: 28, 8: 30, 13: 32 }, { 4: 26, 5: 68, 6: 28, 8: 30, 13: 32 }, { 0: 22, 4: 26, 5: 27, 6: 28, 7: 69, 8: 30, 13: 32 }, { 0: 22, 1: 70, 4: 26, 5: 27, 6: 28, 7: 29, 8: 30, 13: 32 }, { 0: 22, 1: 23, 2: 71, 4: 26, 5: 27, 6: 28, 7: 29, 8: 30, 13: 32 }, { 0: 22, 1: 23, 2: 24, 3: 25, 4: 26, 5: 27, 6: 28, 7: 29, 8: 30, 10: 72, 11: 73, 12: 74, 13: 32 }, { 13: 75 }, { 0: 22, 1: 23, 2: 24, 3: 25, 4: 26, 5: 27, 6: 28, 7: 29, 8: 30, 12: 76, 13: 32 }, { 4: 26, 6: 28, 8: 77, 13: 32 }, { 0: 78, 4: 26, 5: 27, 6: 28, 8: 30, 13: 32 }, , , , { 11: 79, 13: 58, 14: 80 }, { 11: 81, 13: 58, 14: 82 }, { 17: 83 }, , , , , { 0: 22, 1: 23, 2: 24, 3: 25, 4: 26, 5: 27, 6: 28, 7: 29, 8: 30, 12: 84, 13: 32 }, , , , , , , , , , , , , , , , , { 9: 10, 16: 11, 18: 12 }, , , { 0: 22, 1: 23, 2: 24, 3: 25, 4: 26, 5: 27, 6: 28, 7: 29, 8: 30, 12: 96, 13: 32 }, , , { 17: 97 }, { 17: 98 }, { 17: 99 }, { 17: 100 }, , { 17: 101 }, , , { 9: 10, 16: 11, 18: 12 }, { 9: 10, 16: 11, 18: 12 }, { 9: 10, 16: 11, 18: 12 }, { 9: 10, 16: 11, 18: 12 }, { 9: 10, 16: 11, 18: 12 }], | ||
tRules: [[56, 52], [52, 54], [54], [54, 54, 53], [53, 26, 49, 35, 54, 30], [53, 26, 49, 35, 54, 32, 54, 30], [53, 24, 49, 51, 48, 35, 54, 28], [53, 24, 49, 51, 51, 35, 54, 28], [53, 25, 49, 51, 48, 35, 54, 29], [53, 25, 49, 51, 51, 35, 54, 29], [53, 23, 20, 50, 9, 49, 35], [53, 23, 49, 35], [53, 33, 49, 36], [53, 55], [53, 23, 14, 21, 35], [51, 21], [51, 50], [55, 46], [55, 55, 46], [46, 22], [46, 27, 17, 31], [50, 18], [50, 20], [50, 14], [43, 21], [43, 16], [43, 12], [43, 50], [43, 3, 49, 4], [41, 43], [41, 41, 8, 50], [41, 41, 10, 49, 11], [41, 41, 3, 48, 4], [41, 41, 3, 47, 4], [47, 49], [47, 47, 6, 49], [45, 41], [45, 1, 45], [45, 7, 45], [42, 45], [42, 42, 15, 45], [37, 42], [37, 37, 5, 42], [37, 37, 7, 42], [44, 37], [44, 44, 19, 37], [38, 44], [38, 38, 13, 44], [39, 38], [39, 39, 2, 38], [40, 39], [40, 40, 34, 39], [49, 40], [48]], | ||
tFuncs: function() { | ||
function $f0($1, $2, $3, $4, $5, $6, $7) { | ||
var $$; $$ = ['each', $2, $6, $4, $3, true]; return $$; | ||
var table = {//conflicts: 2 | ||
"nStart": 37, | ||
"tSymbols": /*57*/["$", "!", "\u0026\u0026", "(", ")", "+", ",", "-", ".", "=", "[", "]", "boolean", "eq", "include", "mul", "number", "rawtext", "realId", "rel", "set", "string", "text", "{{", "{{#each", "{{#forin", "{{#if", "{{#raw}}", "{{/each}}", "{{/forin}}", "{{/if}}", "{{/raw}}", "{{else}}", "{{{", "||", "}}", "}}}", "AdditiveExpression", "EqualityExpression", "LogicalAndExpression", "LogicalOrExpression", "MemberExpression", "MultiplicativeExpression", "PrimaryExpression", "RelationalExpression", "UnaryExpression", "_text", "args", "empty", "expr", "id", "name", "program", "statement", "statements", "texts", "program\u0027"], | ||
actionList: [{ "_": -2 }, { "_": -32768 }, { "22": 11, "23": 9, "24": 7, "25": 8, "26": 6, "27": 12, "33": 10, "_": -1 }, { "_": -3 }, { "22": 11, "27": 12, "_": -13 }, { "_": -17 }, { "1": 32, "3": 31, "7": 33, "12": 30, "14": 26, "16": 29, "18": 28, "20": 25, "21": 27, "_": 0 }, { "1": 32, "3": 31, "7": 33, "12": 30, "14": 38, "16": 29, "18": 28, "20": 37, "21": 27, "_": 0 }, { "_": -19 }, { "17": 40, "_": 0 }, { "_": -18 }, { "_": -27 }, { "_": -29 }, { "3": 41, "8": 42, "10": 43, "_": -36 }, { "_": -39 }, { "15": 44, "_": -41 }, { "5": 46, "7": 45, "_": -44 }, { "19": 47, "_": -46 }, { "13": 48, "_": -48 }, { "2": 49, "_": -50 }, { "34": 50, "_": -52 }, { "35": 51, "_": 0 }, { "_": -22 }, { "_": -23 }, { "_": -24 }, { "_": -21 }, { "_": -25 }, { "_": -26 }, { "14": 26, "18": 28, "20": 25, "21": 57, "_": 0 }, { "35": 59, "_": 0 }, { "14": 26, "18": 28, "20": 25, "_": -22 }, { "21": 61, "_": -23 }, { "36": 62, "_": 0 }, { "31": 63, "_": 0 }, { "1": 32, "3": 31, "7": 33, "12": 30, "14": 26, "16": 29, "18": 28, "20": 25, "21": 27, "_": -53 }, { "14": 26, "18": 28, "20": 25, "_": 0 }, { "_": -2 }, { "4": 77, "_": 0 }, { "_": -37 }, { "_": -38 }, { "14": 26, "18": 28, "20": 25, "21": 57, "_": -53 }, { "_": -16 }, { "_": -15 }, { "_": -11 }, { "9": 82, "_": 0 }, { "35": 83, "_": 0 }, { "_": -12 }, { "_": -20 }, { "4": 84, "6": 85, "_": 0 }, { "_": -34 }, { "4": 86, "_": 0 }, { "_": -30 }, { "11": 87, "_": 0 }, { "_": -40 }, { "15": 44, "_": -43 }, { "15": 44, "_": -42 }, { "5": 46, "7": 45, "_": -45 }, { "19": 47, "_": -47 }, { "13": 48, "_": -49 }, { "2": 49, "_": -51 }, { "22": 11, "23": 9, "24": 7, "25": 8, "26": 6, "27": 12, "30": 88, "32": 89, "33": 10, "_": 0 }, { "_": -28 }, { "35": 90, "_": 0 }, { "35": 91, "_": 0 }, { "35": 92, "_": 0 }, { "35": 93, "_": 0 }, { "_": -14 }, { "_": -32 }, { "_": -33 }, { "_": -31 }, { "_": -4 }, { "_": -2 }, { "_": -2 }, { "_": -2 }, { "35": 101, "_": 0 }, { "_": -35 }, { "22": 11, "23": 9, "24": 7, "25": 8, "26": 6, "27": 12, "30": 102, "33": 10, "_": 0 }, { "22": 11, "23": 9, "24": 7, "25": 8, "26": 6, "27": 12, "28": 103, "33": 10, "_": 0 }, { "22": 11, "23": 9, "24": 7, "25": 8, "26": 6, "27": 12, "28": 104, "33": 10, "_": 0 }, { "22": 11, "23": 9, "24": 7, "25": 8, "26": 6, "27": 12, "29": 105, "33": 10, "_": 0 }, { "22": 11, "23": 9, "24": 7, "25": 8, "26": 6, "27": 12, "29": 106, "33": 10, "_": 0 }, { "_": -10 }, { "_": -5 }, { "_": -6 }, { "_": -7 }, { "_": -8 }, { "_": -9 }], | ||
actionIndex: [0, 1, 2, 3, 4, 5, 6, 6, 6, 7, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 6, 6, 6, 28, 28, 29, 30, 31, 32, 33, 34, 35, 6, 6, 6, 6, 6, 6, 6, 6, 36, 37, 38, 39, 40, 41, 42, 40, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 6, 66, 67, 6, 68, 69, 70, 71, 72, 72, 73, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86], | ||
"tGoto": /*107*/[{ "52": 1, "54": 2 }, {}, { "53": 3, "55": 4, "46": 5 }, {}, { "46": 13 }, {}, { "50": 14, "43": 15, "41": 16, "45": 17, "42": 18, "37": 19, "44": 20, "38": 21, "39": 22, "40": 23, "49": 24 }, { "50": 14, "43": 15, "41": 16, "45": 17, "42": 18, "37": 19, "44": 20, "38": 21, "39": 22, "40": 23, "49": 34 }, { "50": 14, "43": 15, "41": 16, "45": 17, "42": 18, "37": 19, "44": 20, "38": 21, "39": 22, "40": 23, "49": 35 }, { "50": 14, "43": 15, "41": 16, "45": 17, "42": 18, "37": 19, "44": 20, "38": 21, "39": 22, "40": 23, "49": 36 }, { "50": 14, "43": 15, "41": 16, "45": 17, "42": 18, "37": 19, "44": 20, "38": 21, "39": 22, "40": 23, "49": 39 }, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, { "50": 14, "43": 15, "41": 16, "45": 17, "42": 18, "37": 19, "44": 20, "38": 21, "39": 22, "40": 23, "49": 52 }, { "50": 14, "43": 15, "41": 16, "45": 53 }, { "50": 14, "43": 15, "41": 16, "45": 54 }, { "51": 55, "50": 56 }, { "51": 58, "50": 56 }, {}, { "50": 60 }, {}, {}, {}, { "50": 14, "43": 15, "41": 16, "47": 64, "45": 17, "42": 18, "37": 19, "44": 20, "38": 21, "39": 22, "40": 23, "49": 65, "48": 66 }, { "50": 67 }, { "50": 14, "43": 15, "41": 16, "45": 17, "42": 18, "37": 19, "44": 20, "38": 21, "39": 22, "40": 23, "49": 68 }, { "50": 14, "43": 15, "41": 16, "45": 69 }, { "50": 14, "43": 15, "41": 16, "45": 17, "42": 70 }, { "50": 14, "43": 15, "41": 16, "45": 17, "42": 71 }, { "50": 14, "43": 15, "41": 16, "45": 17, "42": 18, "37": 72 }, { "50": 14, "43": 15, "41": 16, "45": 17, "42": 18, "37": 19, "44": 73 }, { "50": 14, "43": 15, "41": 16, "45": 17, "42": 18, "37": 19, "44": 20, "38": 74 }, { "50": 14, "43": 15, "41": 16, "45": 17, "42": 18, "37": 19, "44": 20, "38": 21, "39": 75 }, { "54": 76 }, {}, {}, {}, { "51": 78, "50": 56, "48": 79 }, {}, {}, { "51": 80, "50": 56, "48": 81 }, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, { "53": 3, "55": 4, "46": 5 }, {}, {}, {}, {}, {}, { "50": 14, "43": 15, "41": 16, "45": 17, "42": 18, "37": 19, "44": 20, "38": 21, "39": 22, "40": 23, "49": 94 }, {}, {}, { "50": 14, "43": 15, "41": 16, "45": 17, "42": 18, "37": 19, "44": 20, "38": 21, "39": 22, "40": 23, "49": 95 }, {}, {}, {}, { "54": 96 }, { "54": 97 }, { "54": 98 }, { "54": 99 }, { "54": 100 }, {}, {}, { "53": 3, "55": 4, "46": 5 }, { "53": 3, "55": 4, "46": 5 }, { "53": 3, "55": 4, "46": 5 }, { "53": 3, "55": 4, "46": 5 }, { "53": 3, "55": 4, "46": 5 }, {}, {}, {}, {}, {}, {}], | ||
"tRules": /*54*/[[56, 52], [52, 54], [54], [54, 54, 53], [53, 26, 49, 35, 54, 30], [53, 26, 49, 35, 54, 32, 54, 30], [53, 24, 49, 51, 51, 35, 54, 28], [53, 24, 49, 51, 48, 35, 54, 28], [53, 25, 49, 51, 51, 35, 54, 29], [53, 25, 49, 51, 48, 35, 54, 29], [53, 23, 20, 50, 9, 49, 35], [53, 23, 49, 35], [53, 33, 49, 36], [53, 55], [53, 23, 14, 21, 35], [51, 21], [51, 50], [55, 46], [55, 55, 46], [46, 22], [46, 27, 17, 31], [50, 18], [50, 20], [50, 14], [43, 21], [43, 16], [43, 12], [43, 50], [43, 3, 49, 4], [41, 43], [41, 41, 8, 50], [41, 41, 10, 49, 11], [41, 41, 3, 47, 4], [41, 41, 3, 48, 4], [47, 49], [47, 47, 6, 49], [45, 41], [45, 1, 45], [45, 7, 45], [42, 45], [42, 42, 15, 45], [37, 42], [37, 37, 5, 42], [37, 37, 7, 42], [44, 37], [44, 44, 19, 37], [38, 44], [38, 38, 13, 44], [39, 38], [39, 39, 2, 38], [40, 39], [40, 40, 34, 39], [49, 40], [48]], | ||
"objCharset": null | ||
} | ||
; | ||
function parse(lexer, others) { | ||
var nStart = table.nStart; | ||
var tSymbols = table.tSymbols; | ||
var tSymbolIndex = {}; | ||
for (var i = 0; i < tSymbols.length; ++i) | ||
tSymbolIndex[tSymbols[i]] = i; | ||
var tAction = table.tAction || table.actionList; | ||
var tGoto = table.tGoto; | ||
var tRules = table.tRules; | ||
var tCodes = table.tCodes; | ||
var actionIndex = table.actionIndex; | ||
function $f0($1, $2, $3, $4, $5, $6, $7) { var $$; { $$ = ['each', $2, $6, $4, $3, true]; } return $$; } | ||
function $f1($1, $2, $3, $4, $5, $6, $7) { var $$; { $$ = ['each', $2, $6, $4, $3, false]; } return $$; } | ||
function $f2($1) { var $$; { $$ = $1.text; } return $$; } | ||
function $f3($1, $2, $3, $4) { var $$; { $$ = ['()', $1, $3]; } return $$; } | ||
function $f4($1, $2, $3) { var $$; { $$ = [$2.text, $1, $3]; } return $$; } var tFuncs = [, function($1) { var $$; { $$ = ['prog', $1]; } return $$; }, function() { var $$; { $$ = []; } return $$; }, function($1, $2) { var $$; { $1.push($2); $$ = $1; } return $$; }, function($1, $2, $3, $4, $5) { var $$; { $$ = ['if', $2, $4]; } return $$; }, function($1, $2, $3, $4, $5, $6, $7) { var $$; { $$ = ['if', $2, $4, $6]; } return $$; }, $f0, $f0, $f1, $f1, function($1, $2, $3, $4, $5, $6) { var $$; { $$ = ['set', $3.text, $5]; } return $$; }, function($1, $2, $3) { var $$; { $$ = ['eval', $2, false]; } return $$; }, function($1, $2, $3) { var $$; { $$ = ['eval', $2, true]; } return $$; }, function($1) { var $$; { $$ = ['text', $1]; } return $$; }, function($1, $2, $3, $4) { var $$; { $$ = ['inc', evalStr($3.text)]; } return $$; }, function($1) { var $$; { $$ = evalStr($1.text); } return $$; }, $f2, function($1) { var $$; { $$ = $1; } return $$; }, function($1, $2) { var $$; { $$ = $1 + $2; } return $$; }, $f2, function($1, $2, $3) { var $$; { $$ = $2.text; } return $$; }, , , , function($1) { var $$; { $$ = ['lit', evalStr($1.text)]; } return $$; }, function($1) { var $$; { $$ = ['lit', evalNum($1.text)]; } return $$; }, function($1) { var $$; { $$ = ['lit', $1.text == 'true']; } return $$; }, function($1) { var $$; { $$ = ['id', $1.text]; } return $$; }, function($1, $2, $3) { var $$; { $$ = $2; } return $$; }, , function($1, $2, $3) { var $$; { $$ = ['.', $1, $3.text]; } return $$; }, function($1, $2, $3, $4) { var $$; { $$ = ['[]', $1, $3]; } return $$; }, $f3, $f3, function($1) { var $$; { $$ = [$1]; } return $$; }, function($1, $2, $3) { var $$; { ($$ = $1).push($3); } return $$; }, , function($1, $2) { var $$; { $$ = ['!', $2]; } return $$; }, function($1, $2) { var $$; { $$ = ['u-', $2]; } return $$; }, , $f4, , $f4, $f4, , $f4, , $f4, , $f4, , $f4]; | ||
function getAction(x, y) { | ||
return tAction[x][y]; | ||
} | ||
var stateNum = tAction.length; | ||
if (actionIndex) { | ||
getAction = function(x, y) { | ||
var list = tAction[actionIndex[x]]; | ||
return list[y] || list._; | ||
}; | ||
stateNum = actionIndex.length; | ||
} | ||
function getToken() { | ||
var t = lexer.scan(); | ||
return t; | ||
} | ||
var s = 0; | ||
var stateStack = [0]; | ||
var a = getToken(); | ||
var valueStack = []; | ||
var obj = { | ||
get: function(i) { | ||
return valueStack[valueStack.length + i]; | ||
}, | ||
set: function(i, v) { | ||
valueStack[valueStack.length + i] = v; | ||
} | ||
function $f1($1, $2, $3, $4, $5, $6, $7) { | ||
var $$; $$ = ['each', $2, $6, $4, $3, false]; return $$; | ||
}; | ||
if (others) for (var i in others) | ||
obj[i] = others[i]; | ||
var $smb = valueStack; | ||
var ctxStack = []; | ||
function Context(index, end, pos) { | ||
this.start = index; | ||
this.end = end; | ||
this.pos = pos; | ||
} | ||
Context.prototype.toString = function() { | ||
return JSON.stringify({ | ||
start: this.start, | ||
end: this.end, | ||
pos: this.pos.toString() | ||
}) | ||
}; | ||
function isAstNode(t) { | ||
return !!t && t instanceof Array && t.length > 0 && typeof t[0] == 'string'; | ||
} | ||
function setPos(node, pos) { | ||
node.pos = pos; | ||
} | ||
while (1) { | ||
var $top = $smb.length - 1; | ||
var t = getAction(s, tSymbolIndex[a.tag]); | ||
if (!t) { | ||
var okTokens = []; | ||
for (var j = 0; j < nStart; ++j) { | ||
if (getAction(s, j)) | ||
okTokens.push(tSymbols[j]); | ||
} | ||
err('find ' + a.tag + '\nexpect ' + okTokens.join(' ')); | ||
} | ||
function $f2($1) { | ||
var $$; $$ = $1.text; return $$; | ||
else if (t > 0) { | ||
stateStack.push(s = t); | ||
valueStack.push(a); | ||
ctxStack.push(new Context(a.index, a.end, a.pos)); | ||
a = getToken(); | ||
} | ||
function $f3($1, $2, $3, $4) { | ||
var $$; $$ = ['()', $1, $3]; return $$; | ||
else if (t < 0 && t > -32768) { | ||
var idx = -t; | ||
var p = tRules[idx]; | ||
var num = p.length - 1; | ||
stateStack.length -= num; | ||
s = tGoto[stateStack[stateStack.length - 1]][p[0]]; | ||
stateStack.push(s); | ||
var val = null; | ||
if (tFuncs[idx]) { | ||
var popped = valueStack.splice(valueStack.length - num, num); | ||
val = tFuncs[idx].apply(obj, popped); | ||
valueStack.push(val); | ||
} | ||
else if (num != 1) { | ||
valueStack.splice(valueStack.length - num, num, null); | ||
} | ||
var ctx = ctxStack.length > 0 ? ctxStack[ctxStack.length - 1] : null; | ||
if (num == 0) { | ||
ctxStack.push(ctx = new Context(a.index, a.index, a.pos)); | ||
} | ||
else if (num != 1) { | ||
ctx = new Context( | ||
ctxStack[ctxStack.length - num].start, | ||
ctxStack[ctxStack.length - 1].end, | ||
ctxStack[ctxStack.length - num].pos | ||
); | ||
ctxStack.splice(ctxStack.length - num, num); | ||
ctxStack.push(ctx); | ||
} | ||
if (isAstNode(val)) { | ||
setPos(val, ctx); | ||
} | ||
} | ||
function $f4($1, $2, $3) { | ||
var $$; $$ = [$2.text, $1, $3]; return $$; | ||
else { | ||
if (a.tag != tSymbols[0]) err(); | ||
return valueStack[0]; | ||
} | ||
return [, function($1) { | ||
var $$; $$ = ['prog', $1]; return $$; | ||
}, function() { | ||
var $$; $$ = []; return $$; | ||
}, function($1, $2) { | ||
var $$; $1.push($2); $$ = $1; return $$; | ||
}, function($1, $2, $3, $4, $5) { | ||
var $$; $$ = ['if', $2, $4]; return $$; | ||
}, function($1, $2, $3, $4, $5, $6, $7) { | ||
var $$; $$ = ['if', $2, $4, $6]; return $$; | ||
}, $f0, $f0, $f1, $f1, function($1, $2, $3, $4, $5, $6) { | ||
var $$; $$ = ['set', $3.text, $5]; return $$; | ||
}, function($1, $2, $3) { | ||
var $$; $$ = ['eval', $2, false]; return $$; | ||
}, function($1, $2, $3) { | ||
var $$; $$ = ['eval', $2, true]; return $$; | ||
}, function($1) { | ||
var $$; $$ = ['text', $1]; return $$; | ||
}, function($1, $2, $3, $4) { | ||
var $$; $$ = ['inc', evalStr($3.text)]; return $$; | ||
}, function($1) { | ||
var $$; $$ = evalStr($1.text); return $$; | ||
}, $f2, function($1) { | ||
var $$; $$ = $1; return $$; | ||
}, function($1, $2) { | ||
var $$; $$ = $1 + $2; return $$; | ||
}, $f2, function($1, $2, $3) { | ||
var $$; $$ = $2.text; return $$; | ||
}, , , , function($1) { | ||
var $$; $$ = ['lit', evalStr($1.text)]; return $$; | ||
}, function($1) { | ||
var $$; $$ = ['lit', evalNum($1.text)]; return $$; | ||
}, function($1) { | ||
var $$; $$ = ['lit', $1.text == 'true']; return $$; | ||
}, function($1) { | ||
var $$; $$ = ['id', $1.text]; return $$; | ||
}, function($1, $2, $3) { | ||
var $$; $$ = $2; return $$; | ||
}, , function($1, $2, $3) { | ||
var $$; $$ = ['.', $1, $3.text]; return $$; | ||
}, function($1, $2, $3, $4) { | ||
var $$; $$ = ['[]', $1, $3]; return $$; | ||
}, $f3, $f3, function($1) { | ||
var $$; $$ = [$1]; return $$; | ||
}, function($1, $2, $3) { | ||
var $$; ($$ = $1).push($3); return $$; | ||
}, , function($1, $2) { | ||
var $$; $$ = ['!', $2]; return $$; | ||
}, function($1, $2) { | ||
var $$; $$ = ['u-', $2]; return $$; | ||
}, , $f4, , $f4, $f4, , $f4, , $f4, , $f4, , $f4]; | ||
}() | ||
}; | ||
return function(a) { | ||
function c(a, b) { return g[a][b] } for (var d = a.nStart, f = a.tSymbols, b = {}, e = 0; e < f.length; ++e) b[f[e]] = e; var g = a.tAction, p = a.tGoto, h = a.tRules, n = a.tFuncs, | ||
m = a.actionIndex; m && (c = function(a, b) { var c = g[m[a]]; return c[b] || c._ }); return function(a, e) { | ||
function g(b) { throw Error("Syntax error: " + a.getPos(l.index) + (b ? "\n" + b : "")); } var m = 0, B = [0], l = a.scan(), v = [], r = { get: function(a) { return v[v.length + a] }, set: function(a, b) { v[v.length + a] = b } }; if (e) for (var y in e) r[y] = e[y]; for (; ;) if (y = c(m, b[l.tag])) if (0 < y) B.push(m = y), v.push(l), l = a.scan(); else if (0 > y && -32768 < y) { | ||
y = -y; var m = h[y], t = m.length - 1; B.length -= t; m = p[B[B.length - 1]][m[0] - d]; B.push(m); n[y] ? (y = n[y].apply(r, v.splice(v.length - | ||
t, t)), v.push(y)) : 1 != t && v.splice(v.length - t, t, null) | ||
} else return l.tag != f[0] && g(), v[0]; else { y = []; for (t = 0; t < d; ++t) c(m, t) && y.push(f[t]); g("find " + l.tag + "\nexpect " + y.join(" ")) } | ||
} | ||
}(table); | ||
function err(msg) { | ||
throw Error('Syntax error: ' + lexer.getPos(a.index) + (msg ? '\n' + msg : '')); | ||
} | ||
} | ||
return parse; | ||
}(); | ||
function isAtom(op) { | ||
@@ -492,4 +567,8 @@ switch (op) { | ||
function emit(s) { | ||
body += s; | ||
body.push(s); | ||
} | ||
function nodeWithPos(node, pos) { | ||
node.pos = pos; | ||
return node; | ||
} | ||
@@ -499,3 +578,5 @@ function stmtGen(a) { | ||
case 'if': | ||
emit('if(' + exprGen(a[1]) + '){'); | ||
emit('if('); | ||
emit(exprGen(a[1])); | ||
emit('){'); | ||
stmtsGen(a[2]); | ||
@@ -511,13 +592,24 @@ emit('}'); | ||
var keyName = a[3] ? encodeCommonName(a[3]) : TMake(); | ||
var sExpr = exprGen(a[1]); | ||
if (/^\w+$/.test(sExpr)) { | ||
var listName = sExpr; | ||
var tmpExpr = exprGen(a[1]); | ||
var tmpStr = joinCode(tmpExpr); | ||
if (/^\w+$/.test(tmpStr)) { | ||
var listName = tmpStr; | ||
} | ||
else { | ||
listName = TMake(); | ||
emit('var ' + listName + ' = ' + sExpr + ';'); | ||
emit('var ' + listName + ' = '); | ||
emit(tmpExpr); | ||
emit(';'); | ||
} | ||
if (a[5]) emit('for(var ' + keyName + '=0;' + keyName + '<' + listName + '.length;' + keyName + '++){'); | ||
if (a[5]) { | ||
emit('for(var ' + keyName + '=0;' + keyName + '<'); | ||
//listName + '.length' | ||
emit(exprGen(['.', nodeWithPos(['t', listName], a[1].pos), 'length'])); | ||
emit(';' + keyName + '++){'); | ||
} | ||
else emit('for(var ' + keyName + ' in ' + listName + ') {'); | ||
emit('var ' + a[4] + ' = ' + listName + '[' + keyName + '];'); | ||
emit('var ' + a[4] + ' = '); | ||
//listName + '[' + keyName + ']' | ||
emit(exprGen(['[]', nodeWithPos(['t', listName], a[1].pos), ['t', keyName]])); | ||
emit(';'); | ||
stmtsGen(a[2]); | ||
@@ -527,11 +619,16 @@ emit('}'); | ||
case 'set': | ||
emit('var ' + encodeCommonName(a[1]) + '=' + exprGen(a[2]) + ';'); | ||
emit('var ' + encodeCommonName(a[1]) + '='); | ||
emit(exprGen(a[2])); | ||
emit(';'); | ||
break; | ||
case 'eval': | ||
var s = exprGen(a[1]); | ||
if (/^\w+$/.test(s)) | ||
var tName = s; | ||
var tmpExpr = exprGen(a[1]); | ||
var tmpStr = joinCode(tmpExpr); | ||
if (/^\w+$/.test(tmpStr)) | ||
var tName = tmpStr; | ||
else { | ||
tName = '_t'; | ||
emit('_t = ' + s + ';'); | ||
emit('_t = '); | ||
emit(tmpExpr); | ||
emit(';'); | ||
} | ||
@@ -555,36 +652,56 @@ emit('if(' + tName + ' !=null)_s += ' + ((defaultEncode ? !a[2] : a[2]) ? encodeName + '(' + tName + ')' : tName) + ';'); | ||
function joinCode(a) { | ||
if (typeof a == 'string') | ||
return a; | ||
if (a instanceof Array) { | ||
var r = []; | ||
for (var i = 0; i < a.length; ++i) { | ||
r.push(joinCode(a[i])); | ||
} | ||
return r.join(''); | ||
} | ||
throw new Error("unknown type"); | ||
} | ||
function exprToStr(x, check) { | ||
var t = exprGen(x); | ||
if (check && !check(x[0])) t = '(' + t + ')'; | ||
if (check && !check(x[0])) t = ['(', t, ')']; | ||
return t; | ||
} | ||
function exprGen(x) { | ||
return nodeWithPos(exprGen_original(x), x.pos); | ||
} | ||
function exprGen_original(x) { | ||
switch (x[0]) { | ||
case 't': | ||
return x[1]; //��ʱ����ֱ�ӷ��� | ||
case 'id': | ||
return encodeCommonName(x[1]); | ||
case 'lit': | ||
if (typeof x[1] == 'string') | ||
return quote(x[1]); | ||
return String(x[1]); | ||
return (typeof x[1] == 'string') | ||
? quote(x[1]) | ||
: String(x[1]); | ||
case '.': | ||
return exprToStr(x[1], isMember) + '.' + x[2]; | ||
return [exprToStr(x[1], isMember), '.', x[2]]; | ||
case '[]': | ||
return exprToStr(x[1], isMember) + '[' + exprGen(x[2]) + ']'; | ||
return [exprToStr(x[1], isMember), '[', exprGen(x[2]) + ']']; | ||
case '()': | ||
var a = []; | ||
if (x[2]) | ||
for (var i = 0; i < x[2].length; ++i) | ||
var a = [exprToStr(x[1], isMember), '(']; | ||
if (x[2]) { | ||
for (var i = 0; i < x[2].length; ++i) { | ||
if (i > 0) a.push(','); | ||
a.push(exprGen(x[2][i])); | ||
return exprToStr(x[1], isMember) + '(' + a.join(',') + ')'; | ||
} | ||
} | ||
a.push(')'); | ||
return a; | ||
case '!': | ||
return '!' + exprToStr(x[1], isUnary); | ||
return ['!', exprToStr(x[1], isUnary)]; | ||
case 'u-': | ||
return '- ' + exprToStr(x[1], isUnary); | ||
return ['- ', exprToStr(x[1], isUnary)]; | ||
case '*': case '/': case '%': | ||
return exprToStr(x[1], isMul) + x[0] + exprToStr(x[2], isUnary); | ||
return [exprToStr(x[1], isMul), x[0], exprToStr(x[2], isUnary)]; | ||
case '+': case '-': | ||
return exprToStr(x[1], isAdd) + x[0] + ' ' + exprToStr(x[2], isMul); | ||
return [exprToStr(x[1], isAdd), x[0], ' ', exprToStr(x[2], isMul)]; | ||
case '<': case '>': case '<=': case '>=': | ||
return exprToStr(x[1], isRel) + x[0] + exprToStr(x[2], isAdd); | ||
return [exprToStr(x[1], isRel), x[0], exprToStr(x[2], isAdd)]; | ||
case '==': | ||
@@ -594,7 +711,7 @@ case '!=': | ||
case '!==': | ||
return exprToStr(x[1], isEquality) + x[0] + exprToStr(x[2], isRel); | ||
return [exprToStr(x[1], isEquality), x[0], exprToStr(x[2], isRel)]; | ||
case '&&': | ||
return exprToStr(x[1], isLogicalAnd) + '&&' + exprToStr(x[2], isEquality); | ||
return [exprToStr(x[1], isLogicalAnd), '&&', exprToStr(x[2], isEquality)]; | ||
case '||': | ||
return exprToStr(x[1], isLogicalOr) + '||' + exprToStr(x[2], isLogicalAnd); | ||
return [exprToStr(x[1], isLogicalOr), '||', exprToStr(x[2], isLogicalAnd)]; | ||
default: | ||
@@ -605,6 +722,26 @@ throw Error("unknown expr: " + x[0]); | ||
var body = ''; | ||
var body = []; | ||
stmtsGen(prog[1]); | ||
return body; | ||
var posLog = []; | ||
var jsStr = ''; | ||
function joinJsStr(a) { | ||
if (typeof a == 'string') | ||
jsStr += a; | ||
if (a instanceof Array) { | ||
if (a.pos) { | ||
posLog.push([jsStr.length, a.pos]); | ||
} | ||
for (var i = 0; i < a.length; ++i) { | ||
joinJsStr(a[i]); | ||
} | ||
} | ||
} | ||
joinJsStr(body); | ||
//alert(posLog.join('\n')); | ||
var strObj = new String(jsStr); | ||
strObj.posLog = posLog; | ||
return strObj; | ||
} | ||
@@ -636,3 +773,33 @@ | ||
}"; | ||
body += "var _t,_s = '';" + s + "return _s;"; | ||
body += "var _t,_s = '';"; | ||
if (config && config.debug) { | ||
var posLog = s.posLog; | ||
body += 'try{\n'; | ||
body += 'eval(' + JSON.stringify(s) + ');'; | ||
body += '}catch(_e){throw ' + function(e, posLog) { | ||
var msg = e.stack; | ||
var msgLines = msg.split(/\r\n?|\n/); | ||
var re_pos = /:(\d+):(\d+)\)$/m; | ||
var m = re_pos.exec(msgLines[1]); | ||
//var row = +m[1]; | ||
//if (row != 1) throw Error("row != 1"); | ||
var col = +m[2]; | ||
var pos = null; | ||
for (var i = 0; i < posLog.length; ++i) { | ||
if (posLog[i][0] + 1 >= col) { | ||
pos = posLog[i][1]; | ||
break; | ||
} | ||
} | ||
//if (pos == null) throw Error("pos == null"); | ||
function posToString(pos) { | ||
return '(' + pos.row + ',' + pos.col + ')'; | ||
} | ||
return Error('CroxError: ' + posToString(pos.pos) + '\n' + msg); | ||
} + '(_e,' + JSON.stringify(posLog) + ');}'; | ||
} | ||
else { | ||
body += s; | ||
} | ||
body += "return _s;"; | ||
@@ -654,2 +821,2 @@ var f = Function('root', body); | ||
Crox.version = "1.3.1";return Crox;})();if ( typeof module == "object" && module && typeof module.exports == "object" ) module.exports = Crox;else if (typeof define == "function" && (define.amd || define.cmd) ) define(function () { return Crox; } );else if (typeof KISSY != "undefined") KISSY.add(function(){ return Crox; });if (root) root.Crox = Crox; })(this); | ||
Crox.version = "1.3.2";return Crox;})();if ( typeof module == "object" && module && typeof module.exports == "object" ) module.exports = Crox;else if (typeof define == "function" && (define.amd || define.cmd) ) define(function () { return Crox; } );else if (typeof KISSY != "undefined") KISSY.add(function(){ return Crox; });if (root) root.Crox = Crox; })(this); |
/* | ||
Crox v1.3.1 | ||
Crox v1.3.2 | ||
https://github.com/thx/crox | ||
Released under the MIT license | ||
md5: 1e0f9b0f7a405f75d1c5e792e2357346 | ||
md5: 481a90b46ec76e3227d58256db7075ed | ||
*/ | ||
KISSY.add("crox",function(){function w(b,a){this.row=b;this.col=a}function s(b,a){var d=b.substring(0,a),e=d.match(/\r\n?|\n/g),m=1;e&&(m+=e.length);d=1+/[^\r\n]*$/.exec(d)[0].length;return new w(m,d)}function z(b){return'"'+b.replace(/[\x00-\x1f"\\\u2028\u2029]/g,function(a){switch(a){case '"':return'\\"';case "\\":return"\\\\";case "\b":return"\\b";case "\f":return"\\f";case "\n":return"\\n";case "\r":return"\\r";case "\t":return"\\t"}return"\\u"+("000"+a.charCodeAt(0).toString(16)).slice(-4)})+ | ||
'"'}function A(b){return eval(b)}function B(b){function a(a,r,f,b){this.tag=a;this.text=r;this.index=f;this.subMatches=b}function d(){}function e(a){for(var r=1,f=[],b=[1],c=[],k=0;k<a.length;++k)b.push(r+=RegExp("|"+a[k][0].source).exec("").length),c.push(a[k][1]||d),f.push("("+a[k][0].source+")");return[RegExp(f.join("|")+"|","g"),b,c]}a.prototype.toString=function(){return this.text};var m=b.$||"$",g={},c;for(c in b)"$"!=c.charAt(0)&&(g[c]=e(b[c]));return function(n){var r=n.length,f=0,b=[""], | ||
d={text:"",index:0,source:n,pushState:function(a){b.push(a)},popState:function(){b.pop()},retract:function(a){f-=a}};return{scan:function(){do{var k;a:{var c=g[b[b.length-1]],h=c[0];h.lastIndex=f;k=h.exec(n);if(""==k[0]){if(f<r)throw Error("lexer error: "+s(n,f)+"\n"+n.slice(f,f+50));k=new a(m,"",f)}else{d.index=f;f=h.lastIndex;for(var h=c[1],e=0;e<h.length;++e)if(k[h[e]]){c=c[2][e].apply(d,k.slice(h[e],h[e+1]));k=new a(c,k[0],d.index,k.slice(h[e]+1,h[e+1]));break a}k=void 0}}}while(null==k.tag); | ||
return k},getPos:function(a){return s(n,a)}}}}function x(b,a,d,e,m){var g="";d=d?d.replace(/^_+/,"$&$&"):"_"+v++;if(/^\w+$/.test(b))var c=b;else c="_"+v++,g="var "+c+" = "+b+";";return g+("for(var "+d+(m?"=0;"+d+"<"+c+".length; ++"+d:" in "+c)+"){var "+e+" = "+c+"["+d+"];"+a+"}")}function y(b){v=0;return C(D(b))}w.prototype.toString=function(){return"("+this.row+","+this.col+")"};var D=function(){var b=[[/\s+/],[/\/\/[^\r\n]*|\/\*[\s\S]*?\*\//],[/[A-Za-z_]\w*/,function(a){switch(a){case "true":case "false":return"boolean"; | ||
case "set":case "include":return a;default:if(-1!=" abstract boolean break byte case catch char class const continue debugger default delete do double else enum export extends final finally float for function goto if implements import in instanceof int interface let long native new package private protected public return short static super switch synchronized this throw throws transient try typeof var void volatile while with yield ".indexOf(" "+a+" ")||"null"==a)throw Error("Reserved: "+a+" "+s(this.source, | ||
this.index));return"realId"}}],[/"(?:[^"\\]|\\[\s\S])*"|'(?:[^'\\]|\\[\s\S])*'/,function(a){return"string"}],[/\d+(?:\.\d+)?(?:e-?\d+)?/,function(a){return"number"}],[function(a){a.sort().reverse();for(var b=0;b<a.length;++b)a[b]=a[b].replace(/[()*+?.[\]|]/g,"\\$&");return RegExp(a.join("|"))}("! % && ( ) * + - . / < <= = > >= [ ] || === !== == != ,".split(" ")),function(a){return/[*/%]/.test(a)?"mul":/[<>]/.test(a)?"rel":/[!=]=/.test(a)?"eq":a}]];return B({"":[[/(?:(?!{{)[\s\S])+/,function(a){return"text"}], | ||
[/{{{/,function(a){this.pushState(a);return a}],[/{{(?:\/if|else|\/each|\/forin|\/raw)}}/,function(a){return a}],[/{{#raw}}/,function(a){this.pushState("raw");return a}],[/{{(?:#(?:if|each|forin)(?=\s))?/,function(a){this.pushState("{{");return a}]],raw:[[/(?:(?!{{\/raw}})[\s\S])+/,function(a){this.popState();return"rawtext"}]],"{{":b.concat([[/}}/,function(a){this.popState();return a}]]),"{{{":b.concat([[/}}}/,function(a){this.popState();return a}]])})}(),C=function(){return function(b){function a(a, | ||
b){return c[a][b]}for(var d=b.nStart,e=b.tSymbols,m={},g=0;g<e.length;++g)m[e[g]]=g;var c=b.tAction,n=b.tGoto,r=b.tRules,f=b.tFuncs,u=b.actionIndex;u&&(a=function(a,b){var n=c[u[a]];return n[b]||n._});return function(b,c){function u(a){throw Error("Syntax error: "+b.getPos(t.index)+(a?"\n"+a:""));}var h=0,g=[0],t=b.scan(),p=[],s={get:function(a){return p[p.length+a]},set:function(a,b){p[p.length+a]=b}};if(c)for(var l in c)s[l]=c[l];for(;;)if(l=a(h,m[t.tag]))if(0<l)g.push(h=l),p.push(t),t=b.scan(); | ||
else if(0>l&&-32768<l){l=-l;var h=r[l],q=h.length-1;g.length-=q;h=n[g[g.length-1]][h[0]-d];g.push(h);f[l]?(l=f[l].apply(s,p.splice(p.length-q,q)),p.push(l)):1!=q&&p.splice(p.length-q,q,null)}else return t.tag!=e[0]&&u(),p[0];else{l=[];for(q=0;q<d;++q)a(h,q)&&l.push(e[q]);u("find "+t.tag+"\nexpect "+l.join(" "))}}}({nStart:37,tSymbols:"$ ! && ( ) + , - . = [ ] boolean eq include mul number rawtext realId rel set string text {{ {{#each {{#forin {{#if {{#raw}} {{/each}} {{/forin}} {{/if}} {{/raw}} {{else}} {{{ || }} }}} AdditiveExpression EqualityExpression LogicalAndExpression LogicalOrExpression MemberExpression MultiplicativeExpression PrimaryExpression RelationalExpression UnaryExpression _text args epsilon expr id name program statement statements texts".split(" "), | ||
KISSY.add("crox",function(){function v(b,a){this.row=b;this.col=a}function x(b,a){var e=b.substring(0,a),h=e.match(/\r\n?|\n/g),q=1;h&&(q+=h.length);e=1+/[^\r\n]*$/.exec(e)[0].length;return new v(q,e)}function A(b){return'"'+b.replace(/[\x00-\x1f"\\\u2028\u2029]/g,function(a){switch(a){case '"':return'\\"';case "\\":return"\\\\";case "\b":return"\\b";case "\f":return"\\f";case "\n":return"\\n";case "\r":return"\\r";case "\t":return"\\t"}return"\\u"+("000"+a.charCodeAt(0).toString(16)).slice(-4)})+ | ||
'"'}function B(b){return eval(b)}function C(b){function a(a,u,c,b,e,k){this.tag=a;this.text=u;this.index=c;this.subMatches=b;this.end=e;this.pos=k}function e(){}function h(a){for(var u=1,c=[],b=[1],d=[],k=0;k<a.length;++k)b.push(u+=RegExp("|"+a[k][0].source).exec("").length),d.push(a[k][1]||e),c.push("("+a[k][0].source+")");return[RegExp(c.join("|")+"|","g"),b,d]}a.prototype.toString=function(){return this.text};var q=b.$||"$",f={},d;for(d in b)"$"!=d.charAt(0)&&(f[d]=h(b[d]));return function(t){var u= | ||
t.length,c=0,b=[""],e={text:"",index:0,source:t,pushState:function(a){b.push(a)},popState:function(){b.pop()},retract:function(a){c-=a}},k=new v(1,1),d=/\r\n?|\n/g,h=/[^\r\n\u2028\u2029]*$/;return{scan:function(){do{var l;a:{var m=f[b[b.length-1]],g=m[0];g.lastIndex=c;l=g.exec(t);if(""==l[0]){if(c<u)throw Error("lexer error: "+k+"\n"+t.slice(c,c+50));l=new a(q,"",c,null,c,k)}else{e.index=c;c=g.lastIndex;for(var g=m[1],p=0;p<g.length;++p)if(l[g[p]]){m=m[2][p].apply(e,l.slice(g[p],g[p+1]));l=null== | ||
m?null:new a(m,l[0],e.index,l.slice(g[p]+1,g[p+1]),c,k);break a}l=void 0}}if(null!=l)return m=k.row,g=k.col,p=(p=l.text.match(d))?p.length:0,m+=p,g=0==p?g+l.text.length:h.exec(l.text)[0].length+1,k=new v(m,g),l}while(1)},GetCurrentPosition:function(){return k},getPos:function(a){return x(t,a)}}}}function y(b,a,e,h,q){var f="";e=e?e.replace(/^_+/,"$&$&"):"_"+w++;if(/^\w+$/.test(b))var d=b;else d="_"+w++,f="var "+d+" = "+b+";";return f+("for(var "+e+(q?"=0;"+e+"<"+d+".length; ++"+e:" in "+d)+"){var "+ | ||
h+" = "+d+"["+e+"];"+a+"}")}function z(b){w=0;return D(E(b))}v.prototype.toString=function(){return"("+this.row+","+this.col+")"};var E=function(){var b=[[/\s+/],[/\/\/[^\r\n]*|\/\*[\s\S]*?\*\//],[/[A-Za-z_]\w*/,function(a){switch(a){case "true":case "false":return"boolean";case "set":case "include":return a;default:if(-1!=" abstract boolean break byte case catch char class const continue debugger default delete do double else enum export extends final finally float for function goto if implements import in instanceof int interface let long native new package private protected public return short static super switch synchronized this throw throws transient try typeof var void volatile while with yield ".indexOf(" "+ | ||
a+" ")||"null"==a)throw Error("Reserved: "+a+" "+x(this.source,this.index));return"realId"}}],[/"(?:[^"\\]|\\[\s\S])*"|'(?:[^'\\]|\\[\s\S])*'/,function(a){return"string"}],[/\d+(?:\.\d+)?(?:e-?\d+)?/,function(a){return"number"}],[function(a){a.sort().reverse();for(var b=0;b<a.length;++b)a[b]=a[b].replace(/[()*+?.[\]|]/g,"\\$&");return RegExp(a.join("|"))}("! % && ( ) * + - . / < <= = > >= [ ] || === !== == != ,".split(" ")),function(a){return/[*/%]/.test(a)?"mul":/[<>]/.test(a)?"rel":/[!=]=/.test(a)? | ||
"eq":a}]];return C({"":[[/(?:(?!{{)[\s\S])+/,function(a){return"text"}],[/{{{/,function(a){this.pushState(a);return a}],[/{{(?:\/if|else|\/each|\/forin|\/raw)}}/,function(a){return a}],[/{{#raw}}/,function(a){this.pushState("raw");return a}],[/{{(?:#(?:if|each|forin)(?=\s))?/,function(a){this.pushState("{{");return a}]],raw:[[/(?:(?!{{\/raw}})[\s\S])+/,function(a){this.popState();return"rawtext"}]],"{{":b.concat([[/}}/,function(a){this.popState();return a}]]),"{{{":b.concat([[/}}}/,function(a){this.popState(); | ||
return a}]])})}(),D=function(){return function(b){function a(a,b){return d[a][b]}for(var e=b.nStart,h=b.tSymbols,q={},f=0;f<h.length;++f)q[h[f]]=f;var d=b.tAction,t=b.tGoto,u=b.tRules,c=b.tFuncs,r=b.actionIndex;r&&(a=function(a,b){var t=d[r[a]];return t[b]||t._});return function(b,k){function d(a){throw Error("Syntax error: "+b.getPos(m.index)+(a?"\n"+a:""));}var r=0,l=[0],m=b.scan(),g=[],p={get:function(a){return g[g.length+a]},set:function(a,b){g[g.length+a]=b}};if(k)for(var n in k)p[n]=k[n];for(;;)if(n= | ||
a(r,q[m.tag]))if(0<n)l.push(r=n),g.push(m),m=b.scan();else if(0>n&&-32768<n){n=-n;var r=u[n],f=r.length-1;l.length-=f;r=t[l[l.length-1]][r[0]-e];l.push(r);c[n]?(n=c[n].apply(p,g.splice(g.length-f,f)),g.push(n)):1!=f&&g.splice(g.length-f,f,null)}else return m.tag!=h[0]&&d(),g[0];else{n=[];for(f=0;f<e;++f)a(r,f)&&n.push(h[f]);d("find "+m.tag+"\nexpect "+n.join(" "))}}}({nStart:37,tSymbols:"$ ! && ( ) + , - . = [ ] boolean eq include mul number rawtext realId rel set string text {{ {{#each {{#forin {{#if {{#raw}} {{/each}} {{/forin}} {{/if}} {{/raw}} {{else}} {{{ || }} }}} AdditiveExpression EqualityExpression LogicalAndExpression LogicalOrExpression MemberExpression MultiplicativeExpression PrimaryExpression RelationalExpression UnaryExpression _text args epsilon expr id name program statement statements texts".split(" "), | ||
tAction:[{_:-2},{_:-32768},{22:3,23:4,24:5,25:6,26:7,27:8,33:9,_:-1},{_:-19},{1:13,3:14,7:15,12:16,14:17,16:18,18:19,20:20,21:21,_:0},{1:13,3:14,7:15,12:16,14:33,16:18,18:19,20:34,21:21,_:0},{17:38,_:0},{_:-17},{_:-3},{22:3,27:8,_:-13},{_:-26},{21:44,_:-23},{_:-25},{_:-21},{14:33,18:19,20:34,_:-22},{_:-24},{5:46,7:47,_:-44},{13:48,_:-48},{2:49,_:-50},{34:50,_:-52},{3:51,8:52,10:53,_:-36},{15:54,_:-41},{_:-29},{19:55,_:-46},{_:-39},{35:56,_:0},{_:-27},{_:-23},{_:-22},{14:33,18:19,20:34,21:57,_:0}, | ||
@@ -24,4 +24,4 @@ {35:61,_:0},{31:62,_:0},{36:63,_:0},{_:-18},{_:-37},{4:64,_:0},{_:-38},{35:65,_:0},{9:66,_:0},{1:13,3:14,7:15,12:16,14:33,16:18,18:19,20:34,21:21,_:-53},{14:33,18:19,20:34,_:0},{_:-11},{_:-15},{_:-16},{14:33,18:19,20:34,21:57,_:-53},{_:-20},{_:-12},{_:-28},{_:-14},{15:54,_:-42},{15:54,_:-43},{19:55,_:-47},{13:48,_:-49},{2:49,_:-51},{4:85,6:86,_:0},{4:87,_:0},{_:-34},{_:-30},{11:88,_:0},{_:-40},{5:46,7:47,_:-45},{35:89,_:0},{35:90,_:0},{35:91,_:0},{35:92,_:0},{22:3,23:4,24:5,25:6,26:7,27:8,30:93,32:94, | ||
24,49,51,51,35,54,28],[53,25,49,51,48,35,54,29],[53,25,49,51,51,35,54,29],[53,23,20,50,9,49,35],[53,23,49,35],[53,33,49,36],[53,55],[53,23,14,21,35],[51,21],[51,50],[55,46],[55,55,46],[46,22],[46,27,17,31],[50,18],[50,20],[50,14],[43,21],[43,16],[43,12],[43,50],[43,3,49,4],[41,43],[41,41,8,50],[41,41,10,49,11],[41,41,3,48,4],[41,41,3,47,4],[47,49],[47,47,6,49],[45,41],[45,1,45],[45,7,45],[42,45],[42,42,15,45],[37,42],[37,37,5,42],[37,37,7,42],[44,37],[44,44,19,37],[38,44],[38,38,13,44],[39,38],[39, | ||
39,2,38],[40,39],[40,40,34,39],[49,40],[48]],tFuncs:function(){function b(a,b){return a+b}function a(a,b,f,c,e,d,g){return x(b,d,c,f,!1)}function d(a,b,f,c,e,d,g){return x(b,d,c,f,!1)}function e(a){return a.text}function m(a){return a}function g(a,b,f,c){return a+"("+(f||"")+")"}function c(a,b,f){return a+b.text+f}return[,function(a){return Function("root","var _obj = { '<': '<', '>': '>', '&': '&', '\"': '"' };\tfunction _htmlEncode(s) {\t\treturn String(s).replace(/[<>&\"]/g, function(c) {\t\t\treturn _obj[c];\t\t});\t}var _t,_s = '';function _print(s,e){if(s!=null){if(e)s=_htmlEncode(s);_s+=s;}}"+ | ||
a+"return _s;")},function(){return""},b,function(a,b,f,c,d){return"if("+b+"){"+c+"}"},function(a,b,f,c,d,e,g){return"if("+b+"){"+c+"}else{"+e+"}"},a,a,d,d,function(a,b,f,c,d,e){return"var "+f.text.replace(/^_+/,"$&$&")+"="+d+";"},function(a,b,c){return"_print("+b+",1);"},function(a,b,c){return"_print("+b+");"},function(a){return"_print("+z(a)+");"},function(a,b,c,d){throw Error("unimplemented: include");},function(a){return A(a.text)},e,m,b,e,function(a,b,c){return b.text},,,,e,e,e,function(a){return a.text.replace(/^_+/, | ||
"$&$&")},function(a,b,c){return"("+b+")"},,function(a,b,c){return a+"."+c},function(a,b,c,d){return a+"["+c+"]"},g,g,m,function(a,b,c){return a+","+c},,function(a,b){return"!"+b},function(a,b){return"- "+b},,c,,c,function(a,b,c){return a+"- "+c},,c,,c,,c,,c]}()})}(),v=0;return{compile:y,render:function(b,a){return y(b)(a)}}}); | ||
39,2,38],[40,39],[40,40,34,39],[49,40],[48]],tFuncs:function(){function b(a,b){return a+b}function a(a,b,c,d,e,k,f){return y(b,k,d,c,!1)}function e(a,b,c,d,e,f,h){return y(b,f,d,c,!1)}function h(a){return a.text}function q(a){return a}function f(a,b,c,d){return a+"("+(c||"")+")"}function d(a,b,c){return a+b.text+c}return[,function(a){return Function("root","var _obj = { '<': '<', '>': '>', '&': '&', '\"': '"' };\r\n\tfunction _htmlEncode(s) {\r\n\t\treturn String(s).replace(/[<>&\"]/g, function(c) {\r\n\t\t\treturn _obj[c];\r\n\t\t});\r\n\t}var _t,_s = '';function _print(s,e){if(s!=null){if(e)s=_htmlEncode(s);_s+=s;}}"+ | ||
a+"return _s;")},function(){return""},b,function(a,b,c,d,e){return"if("+b+"){"+d+"}"},function(a,b,c,d,e,f,h){return"if("+b+"){"+d+"}else{"+f+"}"},a,a,e,e,function(a,b,c,d,e,f){return"var "+c.text.replace(/^_+/,"$&$&")+"="+e+";"},function(a,b,c){return"_print("+b+",1);"},function(a,b,c){return"_print("+b+");"},function(a){return"_print("+A(a)+");"},function(a,b,c,d){throw Error("unimplemented: include");},function(a){return B(a.text)},h,q,b,h,function(a,b,c){return b.text},,,,h,h,h,function(a){return a.text.replace(/^_+/, | ||
"$&$&")},function(a,b,c){return"("+b+")"},,function(a,b,c){return a+"."+c},function(a,b,c,d){return a+"["+c+"]"},f,f,q,function(a,b,c){return a+","+c},,function(a,b){return"!"+b},function(a,b){return"- "+b},,d,,d,function(a,b,c){return a+"- "+c},,d,,d,,d,,d]}()})}(),w=0;return{compile:z,render:function(b,a){return z(b)(a)}}}); |
/** | ||
* @preserve Crox v1.3.1 | ||
* @preserve Crox v1.3.2 | ||
* https://github.com/thx/crox | ||
* | ||
* Released under the MIT license | ||
* md5: 1e0f9b0f7a405f75d1c5e792e2357346 | ||
* md5: 481a90b46ec76e3227d58256db7075ed | ||
*/ | ||
@@ -148,3 +148,3 @@ KISSY.add("crox", function(){function Class(base, constructor, methods) { | ||
function Token(tag, text, index, subMatches) { | ||
function Token(tag, text, index, subMatches, end, pos) { | ||
this.tag = tag; | ||
@@ -154,2 +154,4 @@ this.text = text; | ||
this.subMatches = subMatches; | ||
this.end = end; | ||
this.pos = pos; | ||
} | ||
@@ -203,2 +205,3 @@ Token.prototype.toString = function() { | ||
}; | ||
var currentPos = new Position(1, 1); | ||
@@ -213,6 +216,6 @@ function scan() { | ||
if (i < Length) { | ||
throw Error('lexer error: ' + getPos(s, i) + | ||
throw Error('lexer error: ' + currentPos + | ||
'\n' + s.slice(i, i + 50)); | ||
} | ||
return new Token(endTag, '', i); | ||
return new Token(endTag, '', i, null, i, currentPos); | ||
} | ||
@@ -225,6 +228,9 @@ obj.index = i; | ||
var tag = rule[2][j].apply(obj, t.slice(idx[j], idx[j + 1])); | ||
return new Token(tag, t[0], obj.index, t.slice(idx[j] + 1, idx[j + 1])); | ||
if (tag == null) return null; | ||
return new Token(tag, t[0], obj.index, t.slice(idx[j] + 1, idx[j + 1]), i, currentPos); | ||
} | ||
} | ||
var re_newLine = /\r\n?|\n/g; | ||
var re_lastLine = /[^\r\n\u2028\u2029]*$/; | ||
return { | ||
@@ -234,5 +240,18 @@ scan: function() { | ||
var t = scan(); | ||
} while (t.tag == null); | ||
return t; | ||
if (t != null) { | ||
var _row = currentPos.row; | ||
var _col = currentPos.col; | ||
var ms = t.text.match(re_newLine); | ||
var h = ms ? ms.length : 0; | ||
_row += h; | ||
if (h == 0) _col += t.text.length; | ||
else _col = re_lastLine.exec(t.text)[0].length + 1; | ||
currentPos = new Position(_row, _col); | ||
return t; | ||
} | ||
} while (true); | ||
}, | ||
GetCurrentPosition: function() { | ||
return currentPos; | ||
}, | ||
getPos: function(i) { | ||
@@ -239,0 +258,0 @@ return getPos(s, i); |
{ | ||
"name": "crox", | ||
"version": "1.3.1", | ||
"version": "1.3.2", | ||
"description": "Crox is a high performance cross-language template engine, written by the JavaScript.", | ||
@@ -5,0 +5,0 @@ "homepage": "http://thx.github.io/crox/", |
146369
2943