Comparing version 0.0.5 to 0.0.6
@@ -1,1 +0,1 @@ | ||
(function(){var require=function(e,r){var t=require.resolve(e,r||"/"),n=require.modules[t];if(!n)throw Error("Failed to resolve module "+e+", tried "+t);var i=require.cache[t],o=i?i.exports:n();return o};require.paths=[],require.modules={},require.cache={},require.extensions=[".js",".coffee",".json"],require._core={assert:!0,events:!0,fs:!0,path:!0,vm:!0},require.resolve=function(){return function(e,r){function t(e){if(e=a.normalize(e),require.modules[e])return e;for(var r=0;require.extensions.length>r;r++){var t=require.extensions[r];if(require.modules[e+t])return e+t}}function n(e){e=e.replace(/\/+$/,"");var r=a.normalize(e+"/package.json");if(require.modules[r]){var n=require.modules[r](),i=n.browserify;if("object"==typeof i&&i.main){var o=t(a.resolve(e,i.main));if(o)return o}else if("string"==typeof i){var o=t(a.resolve(e,i));if(o)return o}else if(n.main){var o=t(a.resolve(e,n.main));if(o)return o}}return t(e+"/index")}function i(e,r){for(var i=o(r),a=0;i.length>a;a++){var u=i[a],s=t(u+"/"+e);if(s)return s;var c=n(u+"/"+e);if(c)return c}var s=t(e);return s?s:void 0}function o(e){var r;r="/"===e?[""]:a.normalize(e).split("/");for(var t=[],n=r.length-1;n>=0;n--)if("node_modules"!==r[n]){var i=r.slice(0,n+1).join("/")+"/node_modules";t.push(i)}return t}if(r||(r="/"),require._core[e])return e;var a=require.modules.path();r=a.resolve("/",r);var u=r||"/";if(e.match(/^(?:\.\.?\/|\/)/)){var s=t(a.resolve(u,e))||n(a.resolve(u,e));if(s)return s}var c=i(e,u);if(c)return c;throw Error("Cannot find module '"+e+"'")}}(),require.alias=function(e,r){var t=require.modules.path(),n=null;try{n=require.resolve(e+"/package.json","/")}catch(i){n=require.resolve(e,"/")}for(var o=t.dirname(n),a=(Object.keys||function(e){var r=[];for(var t in e)r.push(t);return r})(require.modules),u=0;a.length>u;u++){var s=a[u];if(s.slice(0,o.length+1)===o+"/"){var c=s.slice(o.length);require.modules[r+c]=require.modules[o+c]}else s===o&&(require.modules[r]=require.modules[o])}},function(){var e={},r="undefined"!=typeof window?window:{},t=!1;require.define=function(n,i){!t&&require.modules.__browserify_process&&(e=require.modules.__browserify_process(),t=!0);var o=require._core[n]?"":require.modules.path().dirname(n),a=function(e){var r=require(e,o),t=require.cache[require.resolve(e,o)];return t&&null===t.parent&&(t.parent=u),r};a.resolve=function(e){return require.resolve(e,o)},a.modules=require.modules,a.define=require.define,a.cache=require.cache;var u={id:n,filename:n,exports:{},loaded:!1,parent:null};require.modules[n]=function(){return require.cache[n]=u,i.call(u.exports,a,u,u.exports,o,n,e,r),u.loaded=!0,u.exports}}}(),require.define("path",function(e,r,t,n,i,o){function a(e,r){for(var t=[],n=0;e.length>n;n++)r(e[n],n,e)&&t.push(e[n]);return t}function u(e,r){for(var t=0,n=e.length;n>=0;n--){var i=e[n];"."==i?e.splice(n,1):".."===i?(e.splice(n,1),t++):t&&(e.splice(n,1),t--)}if(r)for(;t--;t)e.unshift("..");return e}var s=/^(.+\/(?!$)|\/)?((?:.+?)?(\.[^.]*)?)$/;t.resolve=function(){for(var e="",r=!1,t=arguments.length;t>=-1&&!r;t--){var n=t>=0?arguments[t]:o.cwd();"string"==typeof n&&n&&(e=n+"/"+e,r="/"===n.charAt(0))}return e=u(a(e.split("/"),function(e){return!!e}),!r).join("/"),(r?"/":"")+e||"."},t.normalize=function(e){var r="/"===e.charAt(0),t="/"===e.slice(-1);return e=u(a(e.split("/"),function(e){return!!e}),!r).join("/"),e||r||(e="."),e&&t&&(e+="/"),(r?"/":"")+e},t.join=function(){var e=Array.prototype.slice.call(arguments,0);return t.normalize(a(e,function(e){return e&&"string"==typeof e}).join("/"))},t.dirname=function(e){var r=s.exec(e)[1]||"",t=!1;return r?1===r.length||t&&3>=r.length&&":"===r.charAt(1)?r:r.substring(0,r.length-1):"."},t.basename=function(e,r){var t=s.exec(e)[2]||"";return r&&t.substr(-1*r.length)===r&&(t=t.substr(0,t.length-r.length)),t},t.extname=function(e){return s.exec(e)[3]||""}}),require.define("__browserify_process",function(e,r,t,n,i,o){var o=r.exports={};o.nextTick=function(){var e="undefined"!=typeof window&&window.setImmediate,r="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(e)return function(e){return window.setImmediate(e)};if(r){var t=[];return window.addEventListener("message",function(e){if(e.source===window&&"browserify-tick"===e.data&&(e.stopPropagation(),t.length>0)){var r=t.shift();r()}},!0),function(e){t.push(e),window.postMessage("browserify-tick","*")}}return function(e){setTimeout(e,0)}}(),o.title="browser",o.browser=!0,o.env={},o.argv=[],o.binding=function(r){if("evals"===r)return e("vm");throw Error("No such module. (Possibly not yet loaded)")},function(){var r,t="/";o.cwd=function(){return t},o.chdir=function(n){r||(r=e("path")),t=r.resolve(n,t)}}()}),require.define("/lib/index.js",function(require,module,exports,__dirname,__filename,process,global){var fs=require("fs"),path=require("path");if(require("./browser_support"),"undefined"==typeof window)var isBrowser=!1;else var isBrowser=!0;var isNode=!isBrowser;if(isNode&&/bright/gim.test(process.env.DEBUG)||isBrowser&&"undefined"!=typeof _BRIGHT_DEBUG)var debug=console.log;else var debug=function(){};var runtime=exports.runtime=require("./runtime/core"),define=exports.define=require("./compiler/define"),parser=exports.parser=require("./compiler/parser");if(exports.compile=function(source){var $$_runtime=runtime,$$_javascript=parser.parse(source);return debug($$_javascript),eval("false || "+$$_javascript)},exports._wrapFile=function(e){return"(function () {\n"+exports._wrapGetRuntime()+e+"(function (err) {\n"+" if (err) console.error(err && err.stack);\n"+"});\n"+"})();"},exports._wrapGetRuntime=function(){return'\nif (typeof(window) === "undefined") {\n var $$_runtime = require("bright").runtime;\n} else {\n var $$_runtime = Bright.runtime;\n}\n'},isNode)require.extensions[".bright"]=function(e,r){e.exports=exports.load(r)},exports.load=function(e){var r=fs.readFileSync(e,"utf8"),t=parser.parse(r);t='var $$_runtime = (global.Bright || require("bright")).runtime;\n'+t+"(function (err) {\n"+" if (err) console.error(err && err.stack);\n"+"});";var n=e+".compile.js";return fs.writeFileSync(n,t),require(n)};else{window.Bright===void 0?window.Bright=module.exports:console.error('Cannot register namespace "Bright".');var run=function(e){var r=exports.compile(e);r(function(e){e&&console.error(e&&e.stack)})};exports.load=function(e,r){var t=window.ActiveXObject?new window.ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest;return t.open("GET",e,!0),"overrideMimeType"in t&&t.overrideMimeType("text/plain"),t.onreadystatechange=function(){var n;if(4===t.readyState){if(0!==(n=t.status)&&200!==n)throw Error("Could not load "+e);if(run(t.responseText),r)return r()}},t.send(null)};var runScripts=function(){for(var e=document.getElementsByTagName("script"),r=0,t=e.length;t>r;r++){var n=e[r];n&&n.type&&"text/bright"===n.type&&(n.src?exports.load(n.src):run(n.innerHTML))}};window.addEventListener?addEventListener("DOMContentLoaded",runScripts,!1):attachEvent("onload",runScripts)}}),require.define("fs",function(){}),require.define("/lib/browser_support.js",function(){"function"!=typeof Array.prototype.forEach&&(Array.prototype.forEach=function(e){for(var r=this.length,t=0;r>t;t++)e(this[t],t,this)}),"function"!=typeof Array.prototype.indexOf&&(Array.prototype.indexOf=function(e){for(var r=0,t=this.length;t>r;r++)if(this[r]===e)return r;return-1}),"function"!=typeof Array.isArray&&(Array.isArray=function(e){return e instanceof Array?!0:!1}),"function"!=typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^\s*((?:[\S\s]*\S)?)\s*$/,"$1")})}),require.define("/lib/runtime/core.js",function(e,r){var t=r.exports;t.error=function(){console.error.apply(console,arguments)},t.runDefers=function(e,r,t){var n=function(i){i&&console.error(i&&i.stack);var o=e.shift();if("function"!=typeof o)return t(null);try{o(r,n)}catch(i){n(i)}};n()},t.ifCondition=function(){for(var e=[],r=0,t=arguments.length;t>r;r+=2){var n=[arguments[r],arguments[r+1]];e.push(n)}var i=e.pop(),o=!1,a=function(){"function"==typeof i[1]?o?i[1](null):i[0](function(){i[1](null)}):i[0](null)},u=function(){var r=e.shift();r?(o=r[0],r[0]?r[1](u):u()):a()};u()},t.conditionLoop=function(e,r,t){var n=function(){e()?r(n,t):t()};n()},t.forEachLoop=function(e,r,t){var n=Object.keys(e),i=function(){if(n.length>0){var e=n.shift();r(e,i,t)}else t()};i()},t.sleep=function(e,r){setTimeout(function(){r(null,e)},e)},t.parseArguments=function(e){var r={arguments:[]};r.callback=e[e.length-1];for(var t=0,n=e.length-1;n>t;t++)r.arguments.push(e[t]);return r}}),require.define("/lib/compiler/define.js",function(e,r,t){t.TOKEN={BLANK:0,SYMBLE:1,NUMBER:2,STRING:4,NAME:8,KEYWORD:16,IDENTIFIER:32,COMMENT:64},t.KEYWORD=["await","argument","break","continue","defer","else","elseif","false","for","function","if","in","javascript","let","NaN","null","return","sleep","throw","true","undefined","var"]}),require.define("/lib/compiler/parser.js",function(e,r,t){var n=e("./define"),i=e("./token"),o=e("./syntax");n.TOKEN;var a=function(e,r,t,n){var i=50;console.error("[33m"),console.error("\n"),console.error(n),console.error("Line: "+(r+1)+", Column: "+(t+1)),console.error("");var o=e[r];if(o){if(t>i){var a=t-i;o=o.substr(a),t-=a}console.error(o);for(var u="",r=0;t>r;r++)u+=32>=o.charCodeAt(r)?o[r]:" ";console.error(u+"^")}return console.error("[39;49m"),o+"\n"+u};t.parse=function(e){var r=function(r,t,n){var i=Error(n);i.line=r,i.column=t;var o=e.split(/\r?\n/gm);throw a(o,i.line,i.column,n),i},t=function(e,t,n){r(e,t,"SyntaxError: "+n)},n=i.parse(e);if(!Array.isArray(n))return n instanceof Error?r(0,0,n.message):r(n.line,n.column,n.error);try{var u=o.parse(n);return u}catch(s){var c=s.token;if(!c)throw s;t(c.line,c.column,s.error)}}}),require.define("/lib/compiler/token.js",function(e,r,t){var n=e("./define"),i=n.TOKEN,o=n.KEYWORD,a={};o.forEach(function(e){a[e]=!0});var u={BLANK:0,SYMBLE:1,NUMBER:2,STRING:4,NAME:8,COMMENT_1:16,COMMENT_2:32},s={NUMBER_BEGIN:48,NUMBER_END:57,LOWER_BEGIN:97,LOWER_END:122,UPPER_BEGIN:65,UPPER_END:90,UNDERLINE:95,QUOTE_1:39,QUOTE_2:34,BACKSLASH:92,DOLLAR:36,STAR:42,FORWARDSLASH:47},c=function(e){return e>=s.NUMBER_BEGIN&&s.NUMBER_END>=e?!0:!1},f=function(e){return e>=s.UPPER_BEGIN&&s.UPPER_END>=e||e>=s.LOWER_BEGIN&&s.LOWER_END>=e||e===s.UNDERLINE||e===s.DOLLAR?!0:!1},l=function(e){return isNaN(e)||32>=e?!0:!1},p=function(e){return e===s.QUOTE_1||e===s.QUOTE_2?!0:!1},v=function(e){return 10===e||13===e?!0:!1},d=function(e){return a[e]?!0:!1};t._parse=function(e){e+=" ";var r,t=e.length,n=0,o=0,a=0,d={line:0,column:0},h=u.BLANK,E=[],x=!1,g=!1,m=!1,y=!1,L=!1,$=function(){o++,a=0},N=function(t){if(13===t)$();else if(10===t){var n=e.charCodeAt(r-1);13===n||$()}else a++},_=function(e){h=e,d={line:o,column:a-1}},k=function(t){if(r>n){var o=e.slice(n,r),a={type:t,line:d.line,column:d.column,text:o.trim()};t===i.BLANK?(o=o.replace(/\r|\n/gim,""),0>a.column&&(a.column=0),o.length>0&&(a.text=o,E.push(a))):(t===i.STRING&&(a.text=a.text.replace(/\n/gm,"\\n").replace(/\r/gm,"\\r")),E.push(a))}n=r,x=!1,g=!1,m=!1,y=!1,L=!1},b=function(){var t=e.charCodeAt(r);N(t),c(t)?_(u.NUMBER):f(t)?_(u.NAME):l(t)?_(u.BLANK):_(u.SYMBLE)},B=function(e){var e={error:"SyntaxError: "+e,line:o,column:a-1};throw e};try{for(r=0;t>r;r++){var M=e[r],S=e.charCodeAt(r);switch(N(S),h){case u.BLANK:c(S)?(k(i.BLANK),_(u.NUMBER)):f(S)?(k(i.BLANK),_(u.NAME)):p(S)?(k(i.BLANK),x=S,_(u.STRING)):l(S)||(k(i.BLANK),_(u.SYMBLE));break;case u.NUMBER:c(S)||(f(S)?g!==!1||"e"!==M&&"E"!==M?B("Unexpected token "+M):(g=!0,y=!1,m=!1):l(S)?(k(i.NUMBER),_(u.BLANK)):"."===M?m?B("Unexpected token "+M):m=!0:g&&"+"===M||"-"===M?y?B("Unexpected token "+M):y=!0:(k(i.NUMBER),_(u.SYMBLE)));break;case u.NAME:c(S)||f(S)||(l(S)?(k(i.NAME),_(u.BLANK)):"_"===M||(k(i.NAME),_(u.SYMBLE)));break;case u.SYMBLE:var R=e.charCodeAt(r-1);S===s.FORWARDSLASH&&R===s.FORWARDSLASH?h=u.COMMENT_1:R===s.FORWARDSLASH&&S===s.STAR?h=u.COMMENT_2:(k(i.SYMBLE),c(S)?_(u.NUMBER):f(S)?_(u.NAME):l(S)?_(u.BLANK):p(S)?(x=S,_(u.STRING)):_(u.SYMBLE));break;case u.STRING:S===x&&L===!1?(r++,k(i.STRING),b()):S===s.BACKSLASH?L=!L:L&&(L=!1);break;case u.COMMENT_1:(v(S)||r>=t-2)&&(r++,k(i.COMMENT),b());break;case u.COMMENT_2:if(S===s.STAR){var A=e.charCodeAt(r+1);A===s.FORWARDSLASH&&(r+=2,k(i.COMMENT),N(),b())}break;default:B("Unexpected token ILLEGAL")}}if(h===u.BLANK)return E;B("Unexpected end of input")}catch(w){return w}},t.parse=function(e){var r=t._parse(e);if(!Array.isArray(r))return r;for(var n=0;r.length>n;n++)(function(e,t){switch(e.type){case i.NAME:if(d(e.text)){var n=r[t-1],o=r[t+1];n=n&&n.type===i.SYMBLE?n.text:null,o=o&&o.type===i.SYMBLE?o.text:null,e.type="."===n||"."===o?i.IDENTIFIER:"{"!==n&&","!==n||":"!==o?i.KEYWORD:i.IDENTIFIER}else e.type=i.IDENTIFIER;break;case i.NUMBER:var n=r[t-1];if(n&&n.type===i.SYMBLE&&"."===n.text&&n.column+1===e.column&&n.line===e.line){var a=r[t-2];if(!a||a.type===i.SYMBLE){var u={type:i.NUMBER,text:n.text+e.text,line:n.line,column:n.column};r[t-1]=u,r.splice(t,1),t--}}break;case i.SYMBLE:var o=r[t+1];if(o&&e.line===o.line&&("+"===e.text&&"+"===o.text||"-"===e.text&&"-"===o.text||"<"===e.text&&"<"===o.text||">"===e.text&&">"===o.text||"="===e.text&&"="===o.text||">"===e.text&&"="===o.text||"<"===e.text&&"="===o.text||"!"===e.text&&"="===o.text)){var u={type:i.SYMBLE,text:e.text+o.text,line:e.line,column:e.column},s=r[t+2];"="!==e.text&&"!"!==e.text||"="!==o.text||!s||s.type!==i.SYMBLE||"="!==s.text?r.splice(t+1,1):(u.text+=s.text,r.splice(t+1,2)),r[t]=u}}})(r[n],n);var o=["true","false","null","undefined","NaN"];return r.forEach(function(e){e.type===i.KEYWORD&&-1!==o.indexOf(e.text)&&(e.type=i.IDENTIFIER)}),r}}),require.define("/lib/compiler/syntax.js",function(e,r){var t=e("./define");e("./token");var n=t.TOKEN,i=r.exports,o=function(e){if(e[0]){for(var r=e[0].line,t=1,n=e.length;n>t&&e[t].line===r;t++);return{line:e.slice(0,t),next:e.slice(t)}}return!1},a=function(e,r){r||(r="Unexpected token "+e.text);var t=Error(r);throw t.error=r,t.token=e,console.error(t.stack),t},u=function(e,r){var t=s(e);e.code.push(t+r)},s=function(e){for(var r="",t=0;e.indent>t;t++)r+=" ";return r},c=function(e){var r={};for(var t in e)r[t]=e[t];return r.defers=[],r.code=[],r},f=function(e,r,t,n){return{type:e,line:r,column:t,text:n}},l=function(e,r){var t=e[e.length-1];if(t){var i=f(n.KEYWORD,t.line+1,0,"return");r&&(i.isNested=r),e.push(i)}return e},p=function(e){var r=e[e.length-1];if(r.type!==n.SYMBLE||"{"!==r.text)return a(r);e.pop();var t="";return e.forEach(function(e){t+=e.type===n.SYMBLE&&"="===e.text?" == ":e.text}),"("+t+")"},v=function(e){for(var r=[],t=0,i=function(i){if(i>t){var o="",u=[];if(e.slice(t,i).forEach(function(e){if(o+=e.text,e.type===n.SYMBLE)if("["===e.text||"("===e.text)u.push(e.text);else if("]"===e.text||")"===e.text){var r=u.pop();if(!("]"===e.text&&"["===r||")"===e.text&&"("===r))return a(e,"brackets do not match")}}),u.length>0)return a(s,"brackets do not match");r.push(o),t=i+1}},o=0,u=e.length;u>o;o++){var s=e[o];if(s.type===n.SYMBLE)if(","===s.text)i(o);else if("="===s.text){i(o);break}}return{names:r,next:e.slice(o+1)}},d=function(e){var r=[],t=[];return e.forEach(function(e,n){r.push("$$_arg_"+n),t.push(e+" = $$_arg_"+n+";")}),{args:r,init:t}},h=function(e){for(var r=[],t=0,i=function(i){if(i>t){var o="",u=[];if(e.slice(t,i).forEach(function(e){if(o+=e.text,e.type===n.SYMBLE)if("["===e.text||"("===e.text)u.push(e.text);else if("]"===e.text||")"===e.text){var r=u.pop();if(!("]"===e.text&&"["===r||")"===e.text&&"("===r))return a(e,"brackets do not match")}}),u.length>0)return a(s,"brackets do not match");r.push(o),t=i+1}},o=0,u=e.length;u>o;o++){var s=e[o];s.type===n.SYMBLE&&","===s.text&&i(o)}return i(o),r},E=function(e){var r=[];return e.forEach(function(e){e.type!==n.BLANK&&r.push(e)}),r};i.wrap=function(e){if(e.vars.length>0)var r=" var "+e.vars.join(", ")+";\n";else var r="";if(e.defers.length>0){var t=" ",n=["\n"+t+"/* defer function start */",t+"var $$_defers = [];"];e.defers.forEach(function(e){n.push(t+"$$_defers.push("+e+");")}),n.push(t+"var $$_oldCallback = $$_callback;"),n.push(t+"$$_callback = $$_callback_global = function () {"),n.push(t+" var $$_args = arguments;"),n.push(t+" $$_runtime.runDefers($$_defers, $$_args[0], function (err) {"),n.push(t+" if (err) $$_runtime.error(err.stack);"),n.push(t+" $$_oldCallback.apply(null, $$_args);"),n.push(t+" });"),n.push(t+"};"),n.push(t+"/* defer function end */\n"),n=n.join("\n")+"\n"}else n="";var t=s(e).substr(4),i="(function ("+e.args.join(", ")+") {\n"+t+' "use strict";\n\n'+t+" /* function header start */\n"+t+" var $$_callback, $arguments;\n"+t+' if (arguments.length < 1 || typeof(arguments[arguments.length - 1]) !== "function") {\n'+t+' throw new Error("Need a callback parameter.");\n'+t+" } else {\n"+t+" $arguments = $$_runtime.parseArguments(arguments);\n"+t+" $$_callback = $arguments.callback;\n"+t+" $arguments = $arguments.arguments;\n"+t+" }\n"+t+" var $$_callback_global = $$_callback;\n"+t+" /* function header end */\n\n"+t+" try {\n"+(r?t+r:"")+(n?t+n:"")+e.code.join("\n")+"\n"+t+" } catch (err) {\n"+t+" return $$_callback_global(err);\n"+t+" }\n"+t+"})";return i},i.parse=function(e,r){if(r)var t=e;else var t={args:[],vars:[],defers:[],tokenList:e,code:[],indent:2};r||(t.tokenList=l(t.tokenList));for(var s,c=function(e,r){u(t,"/* LINE:"+(e.line+1)+" "+r+" */")};s=o(t.tokenList);){var f=E(s.line);if(t.tokenList=s.next,!(1>f.length)){var p=f[0],v=f.slice(1);if(p.type===n.BLANK);else if(p.type===n.KEYWORD){var d=function(){return 1>v.length?a(p,"Unexpected end of input"):void 0};switch(p.text){case"argument":d(),m(t,v);break;case"var":d(),y(t,v);break;case"let":d(),c(p,"START"),L(t,v),c(p,"END");break;case"await":d(),c(p,"START"),N(t,"",v),c(p,"END");break;case"sleep":d(),c(p,"START"),R(t,v),c(p,"END");break;case"function":d(),c(p,"START"),S(t,"",v),c(p,"END");break;case"return":c(p,"START"),_(t,v,p.isNested),c(p,"END");break;case"defer":d(),k(t,v);break;case"if":d(),c(p,"START"),b(t,v),c(p,"END");break;case"for":d(),c(p,"START"),B(t,v),c(p,"END");break;case"break":c(p,"START"),u(t,"return $$_break(null);"),c(p,"END");break;case"continue":c(p,"START"),u(t,"return $$_continue(null);"),c(p,"END");break;case"throw":c(p,"START"),M(t,v),c(p,"END");break;case"javascript":d(),c(p,"START"),A(t,v),c(p,"END");break;default:return a(p)}}else c(p,"START"),$(t,"",f),c(p,"END")}}return r?void 0:i.wrap(t)};var x=function(e,r){for(var t,i=e.tokenList,a=[],u=0,s=!1;t=o(i);){i=t.next;var c=t.line,f=E(c),l=f[0];if(l){var p=f[f.length-1];if(r)l.type===n.SYMBLE&&"}"===l.text?u--:p.type===n.SYMBLE&&"{"===p.text&&u++;else{var v=!1,d=!1;l.type===n.SYMBLE&&"}"===l.text&&(u--,v=!0),p.type===n.SYMBLE&&"{"===p.text&&(u++,d=!0),s||(s=v&&d)}}if(0>u){f.length>1&&(i=f.slice(1).concat(i));break}a=a.concat(c)}if(s){var p=a[a.length-1];p&&p.type===n.SYMBLE&&"}"===p.text&&a.pop()}return{body:a,next:i}},g=function(e,r,t){var n=x(e,t);r&&(n.body=l(n.body,!0)),e.tokenList=n.body,i.parse(e,!0),e.tokenList=n.next},m=function(e,r){var t=!1;r.forEach(function(r){r.type===n.IDENTIFIER?(t=!1,e.args.push(r.text)):r.type!==n.SYMBLE||","!==r.text||t?a(r):t=!0})},y=function(e,r){var t=[],i=!1,o=null,u=[],s=r[r.length-1];r.push(f(n.SYMBLE,s.line,s.column+s.text.length,",")),r.forEach(function(r){if(i)if(r.type===n.SYMBLE)if("("===r.text||"["===r.text)u.push(r),t.push(r);else if(")"===r.text){var s=t.pop();if("("!==s.text)return a(r);u.push(r)}else if("]"===r.text){var s=t.pop();if("["!==s.text)return a(r);u.push(r)}else","===r.text?t.length>0?u.push(r):(u.push(f(n.SYMBLE,r.line,r.column,";")),$(e,o,u),i=!1):u.push(r);else u.push(r);else if(r.type===n.IDENTIFIER)e.vars.push(r.text),o=r.text,t=[],u=[];else{if(!o||r.type!==n.SYMBLE)return a(r);if(","===r.text)i=!1;else{if("="!==r.text)return a(r);i=!0}}})},L=function(e,r){if(3>r.length)return a(r[r.length-1],"Unexpected end of input");var t=v(r),i=t.names;if(1>t.next.length)return a(r[r.length-1],"Unexpected end of input");if(r=t.next,r[0].type===n.KEYWORD)if("await"===r[0].text){if(!r[1])return a(r[0],"Unexpected end of input");N(e,i,r.slice(1))}else{if("function"!==r[0].text)return a(r[0]);if(!r[1])return a(r[0],"Unexpected end of input");if(i.length>1)return a(r[0],"Not support tuple assignment");S(e,i[0],r.slice(1))}else{if(i.length>1)return a(r[0],"Not support tuple assignment");$(e,i[0],r)}},$=function(e,r,t){var i="",o=!1;t.forEach(function(e){e.type===n.IDENTIFIER||e.type===n.KEYWORD?(i+=(o?" ":"")+e.text,o=!0):(i+=e.text,o=!1)}),i=(r?r+" = ":"")+i.trim(),u(e,i)},N=function(e,r,t){var o=t[0];if(1===t.length&&o.type===n.NUMBER)return a(o);if(t[0].type!==n.IDENTIFIER)return a(t[0]);var s=t[t.length-1];if(s.type===n.SYMBLE&&")"===s.text){var c="";t.slice(0,t.length-1).forEach(function(e){c+=e.text});var f=t[t.length-2];f&&f.type===n.SYMBLE&&"("===f.text||(c+=", ")}else{var c="";t.forEach(function(e){c+=e.text}),c+="("}if(r.length>0)var l=d(r);c+="function ("+(r.length>0?l.args.join(", "):"")+") {",u(e,c),e.indent++,r.length>0&&l.init.forEach(function(r){u(e,r)}),i.parse(e,!0),e.indent--,u(e,"});")},_=function(e,r,t){var n=["null"];r.length>0&&(n=n.concat(h(r))),u(e,"return $$_callback"+(t?"":"_global")+"("+n.join(", ")+");")},k=function(e,r){var t=r[r.length-1],i="function (error, $$_callback) {\n",o="\n }";if(t.type===n.SYMBLE)if(")"===t.text&&r.length>=3){var u="";r.forEach(function(e){u+=e.text}),u=" "+u+";\n return $$_callback(null);",e.defers.push(i+u+o)}else{if("{"!==t.text||1!==r.length)return a(t);var s=c(e);s.indent=3,g(s,!0);var f=s.code.join("\n");e.defers.push(i+f+o),e.tokenList=s.tokenList}else{if(t.type!==n.IDENTIFIER)return a(t);var u="";r.forEach(function(e){u+=e.text}),u=" "+u+"();\n return $$_callback(null);",e.defers.push(i+u+o)}},b=function(e,r){var t=[],i=function(){var r=c(e);r.indent++,g(r,!0,!0),e.tokenList=r.tokenList;var t=r.code.join("\n");return t="function ($$_callback) {\n"+t+"\n"+s(e)+"}"};t.push(p(r)),t.push(i());var f=e.tokenList[0];if(f&&f.type===n.KEYWORD&&("else"===f.text||"elseif"===f.text))for(var l,v=!1;l=o(e.tokenList);){var d=l.line,h=E(d);e.tokenList=l.next;var x=h[0],m=h.slice(1);if(x.type!==n.KEYWORD){e.tokenList=d.concat(e.tokenList);break}if("elseif"===x.text)t.push(p(m)),t.push(i());else{if("else"!==x.text){e.tokenList=d.concat(e.tokenList);break}if(v)return a(x);t.push(i()),v=!0}}var y=c(e);y.indent++,g(y),e.tokenList=y.tokenList;var L=y.code.join("\n"),$="$$_runtime.ifCondition("+t.join(", ")+", function () {\n"+L+"\n"+s(e)+"});";u(e,$)},B=function(e,r){var t=function(){var r=c(e);r.indent++,g(r),e.tokenList=r.tokenList;var t=r.code.join("\n");return t};if(r.length>=3&&r[1].type===n.KEYWORD&&"in"===r[1].text){if(r[0].type!==n.IDENTIFIER)return a(r[0]);var i=r[0].text,o="";r.slice(2,r.length-1).forEach(function(e){o+=e.text});var f=c(e);f.indent++,g(f,!0),e.tokenList=f.tokenList;var l=f.code.join("\n"),v=s(e),d="$$_runtime.forEachLoop("+o+", function ("+i+", $$_continue, $$_break) {\n"+v+" var $$_callback = $$_continue;\n"+l+"\n"+v+"}, function () {\n"+t()+"\n"+v+"});";u(e,d)}else{if(1===r.length&&r[0].type===n.SYMBLE&&"{"===r[0].text)var h="true";else var h=p(r);var f=c(e);f.indent++,g(f,!0),e.tokenList=f.tokenList;var l=f.code.join("\n"),v=s(e),d="$$_runtime.conditionLoop(function () {\n"+v+" return "+h+";\n"+v+"}, function ($$_continue, $$_break) {\n"+v+" var $$_callback = $$_continue;\n"+l+"\n"+v+"}, function () {\n"+t()+"\n"+v+"});";u(e,d)}},M=function(e,r){1>r.length?u(e,"return $$_callback_global(new Error());"):($(e,"var $$_err",r),u(e,"return $$_callback_global($$_err);"))},S=function(e,r,t){var o=t[t.length-1];if(o.type!==n.SYMBLE||"{"!==o.text)return a(o);var s=[];if(1===t.length);else{var f=t.slice(0,t.length-1),l=f[0],o=f[f.length-1];if(l.type!==n.SYMBLE||"("!==l.text)return a(l);if(o.type!==n.SYMBLE||")"!==o.text)return a(l);var p=!0;f.slice(1,f.length-1).forEach(function(e){if(p&&e.type===n.IDENTIFIER)s.push(e.text),p=!1;else{if(p||e.type!==n.SYMBLE||","!==e.text)return a(e);p=!0}})}var v=c(e);v.vars=[],v.indent+=2,g(v,!0),v.args=s,v.args.push("$$_callback");var d=i.wrap(v);u(e,"");var h=(r?r+" = ":"")+d+";";u(e,h),u(e,""),e.tokenList=v.tokenList},R=function(e,r){var t=r[r.length-1];r.push(f(n.SYMBLE,t.line,t.column+t.text.length+1,";")),$(e,"var $$_sleep_ms",r);var o="$$_runtime.sleep($$_sleep_ms, function ($$_err) {";u(e,o),e.indent++,i.parse(e,!0),e.indent--,u(e,"});")},A=function(e,r){var t=r[0];if(1!==r.length||t.type!==n.SYMBLE||"{"!==t.text)return a(t);for(var i,s=x(e),r=s.body;i=o(r);){r=i.next;var c=!1,f="";i.line.forEach(function(e){e.type===n.IDENTIFIER||e.type===n.KEYWORD?(f+=(c?" ":"")+e.text,c=!0):(f+=e.text,c=!1)}),u(e,f)}e.tokenList=s.next}}),require.define("/index.js",function(e,r){r.exports=e("./lib")}),require("/index.js")})(); | ||
(function(){var require=function(e,r){var t=require.resolve(e,r||"/"),n=require.modules[t];if(!n)throw Error("Failed to resolve module "+e+", tried "+t);var i=require.cache[t],o=i?i.exports:n();return o};require.paths=[],require.modules={},require.cache={},require.extensions=[".js",".coffee",".json"],require._core={assert:!0,events:!0,fs:!0,path:!0,vm:!0},require.resolve=function(){return function(e,r){function t(e){if(e=a.normalize(e),require.modules[e])return e;for(var r=0;require.extensions.length>r;r++){var t=require.extensions[r];if(require.modules[e+t])return e+t}}function n(e){e=e.replace(/\/+$/,"");var r=a.normalize(e+"/package.json");if(require.modules[r]){var n=require.modules[r](),i=n.browserify;if("object"==typeof i&&i.main){var o=t(a.resolve(e,i.main));if(o)return o}else if("string"==typeof i){var o=t(a.resolve(e,i));if(o)return o}else if(n.main){var o=t(a.resolve(e,n.main));if(o)return o}}return t(e+"/index")}function i(e,r){for(var i=o(r),a=0;i.length>a;a++){var u=i[a],s=t(u+"/"+e);if(s)return s;var c=n(u+"/"+e);if(c)return c}var s=t(e);return s?s:void 0}function o(e){var r;r="/"===e?[""]:a.normalize(e).split("/");for(var t=[],n=r.length-1;n>=0;n--)if("node_modules"!==r[n]){var i=r.slice(0,n+1).join("/")+"/node_modules";t.push(i)}return t}if(r||(r="/"),require._core[e])return e;var a=require.modules.path();r=a.resolve("/",r);var u=r||"/";if(e.match(/^(?:\.\.?\/|\/)/)){var s=t(a.resolve(u,e))||n(a.resolve(u,e));if(s)return s}var c=i(e,u);if(c)return c;throw Error("Cannot find module '"+e+"'")}}(),require.alias=function(e,r){var t=require.modules.path(),n=null;try{n=require.resolve(e+"/package.json","/")}catch(i){n=require.resolve(e,"/")}for(var o=t.dirname(n),a=(Object.keys||function(e){var r=[];for(var t in e)r.push(t);return r})(require.modules),u=0;a.length>u;u++){var s=a[u];if(s.slice(0,o.length+1)===o+"/"){var c=s.slice(o.length);require.modules[r+c]=require.modules[o+c]}else s===o&&(require.modules[r]=require.modules[o])}},function(){var e={},r="undefined"!=typeof window?window:{},t=!1;require.define=function(n,i){!t&&require.modules.__browserify_process&&(e=require.modules.__browserify_process(),t=!0);var o=require._core[n]?"":require.modules.path().dirname(n),a=function(e){var r=require(e,o),t=require.cache[require.resolve(e,o)];return t&&null===t.parent&&(t.parent=u),r};a.resolve=function(e){return require.resolve(e,o)},a.modules=require.modules,a.define=require.define,a.cache=require.cache;var u={id:n,filename:n,exports:{},loaded:!1,parent:null};require.modules[n]=function(){return require.cache[n]=u,i.call(u.exports,a,u,u.exports,o,n,e,r),u.loaded=!0,u.exports}}}(),require.define("path",function(e,r,t,n,i,o){function a(e,r){for(var t=[],n=0;e.length>n;n++)r(e[n],n,e)&&t.push(e[n]);return t}function u(e,r){for(var t=0,n=e.length;n>=0;n--){var i=e[n];"."==i?e.splice(n,1):".."===i?(e.splice(n,1),t++):t&&(e.splice(n,1),t--)}if(r)for(;t--;t)e.unshift("..");return e}var s=/^(.+\/(?!$)|\/)?((?:.+?)?(\.[^.]*)?)$/;t.resolve=function(){for(var e="",r=!1,t=arguments.length;t>=-1&&!r;t--){var n=t>=0?arguments[t]:o.cwd();"string"==typeof n&&n&&(e=n+"/"+e,r="/"===n.charAt(0))}return e=u(a(e.split("/"),function(e){return!!e}),!r).join("/"),(r?"/":"")+e||"."},t.normalize=function(e){var r="/"===e.charAt(0),t="/"===e.slice(-1);return e=u(a(e.split("/"),function(e){return!!e}),!r).join("/"),e||r||(e="."),e&&t&&(e+="/"),(r?"/":"")+e},t.join=function(){var e=Array.prototype.slice.call(arguments,0);return t.normalize(a(e,function(e){return e&&"string"==typeof e}).join("/"))},t.dirname=function(e){var r=s.exec(e)[1]||"",t=!1;return r?1===r.length||t&&3>=r.length&&":"===r.charAt(1)?r:r.substring(0,r.length-1):"."},t.basename=function(e,r){var t=s.exec(e)[2]||"";return r&&t.substr(-1*r.length)===r&&(t=t.substr(0,t.length-r.length)),t},t.extname=function(e){return s.exec(e)[3]||""}}),require.define("__browserify_process",function(e,r,t,n,i,o){var o=r.exports={};o.nextTick=function(){var e="undefined"!=typeof window&&window.setImmediate,r="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(e)return function(e){return window.setImmediate(e)};if(r){var t=[];return window.addEventListener("message",function(e){if(e.source===window&&"browserify-tick"===e.data&&(e.stopPropagation(),t.length>0)){var r=t.shift();r()}},!0),function(e){t.push(e),window.postMessage("browserify-tick","*")}}return function(e){setTimeout(e,0)}}(),o.title="browser",o.browser=!0,o.env={},o.argv=[],o.binding=function(r){if("evals"===r)return e("vm");throw Error("No such module. (Possibly not yet loaded)")},function(){var r,t="/";o.cwd=function(){return t},o.chdir=function(n){r||(r=e("path")),t=r.resolve(n,t)}}()}),require.define("/lib/index.js",function(require,module,exports,__dirname,__filename,process,global){var fs=require("fs"),path=require("path");if(require("./browser_support"),"undefined"==typeof window)var isBrowser=!1;else var isBrowser=!0;var isNode=!isBrowser;if(isNode&&/bright/gim.test(process.env.DEBUG)||isBrowser&&"undefined"!=typeof _BRIGHT_DEBUG)var debug=console.log;else var debug=function(){};var runtime=exports.runtime=require("./runtime/core"),define=exports.define=require("./compiler/define"),parser=exports.parser=require("./compiler/parser");if(exports.compile=function(source){var $$_runtime=runtime,$$_javascript=parser.parse(source);return debug($$_javascript),eval("false || "+$$_javascript)},exports._wrapFile=function(e){return"(function () {\n"+exports._wrapGetRuntime()+e+"(function (err) {\n"+" if (err) console.error(err && err.stack);\n"+"});\n"+"})();"},exports._wrapGetRuntime=function(){return'\nif (typeof(window) === "undefined") {\n var $$_runtime = require("bright").runtime;\n} else {\n var $$_runtime = Bright.runtime;\n}\n'},isNode)require.extensions[".bright"]=function(e,r){e.exports=exports.load(r)},exports.load=function(e){var r=fs.readFileSync(e,"utf8"),t=parser.parse(r);t='var $$_runtime = (global.Bright || require("bright")).runtime;\n'+t+"(function (err) {\n"+" if (err) console.error(err && err.stack);\n"+"});";var n=e+".compile.js";return fs.writeFileSync(n,t),require(n)};else{window.Bright===void 0?window.Bright=module.exports:console.error('Cannot register namespace "Bright".');var run=function(e){var r=exports.compile(e);r(function(e){e&&console.error(e&&e.stack)})};exports.load=function(e,r){var t=window.ActiveXObject?new window.ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest;return t.open("GET",e,!0),"overrideMimeType"in t&&t.overrideMimeType("text/plain"),t.onreadystatechange=function(){var n;if(4===t.readyState){if(0!==(n=t.status)&&200!==n)throw Error("Could not load "+e);if(run(t.responseText),r)return r()}},t.send(null)};var runScripts=function(){for(var e=document.getElementsByTagName("script"),r=0,t=e.length;t>r;r++){var n=e[r];n&&n.type&&"text/bright"===n.type&&(n.src?exports.load(n.src):run(n.innerHTML))}};window.addEventListener?addEventListener("DOMContentLoaded",runScripts,!1):attachEvent("onload",runScripts)}}),require.define("fs",function(){}),require.define("/lib/browser_support.js",function(){"function"!=typeof Array.prototype.forEach&&(Array.prototype.forEach=function(e){for(var r=this.length,t=0;r>t;t++)e(this[t],t,this)}),"function"!=typeof Array.prototype.indexOf&&(Array.prototype.indexOf=function(e){for(var r=0,t=this.length;t>r;r++)if(this[r]===e)return r;return-1}),"function"!=typeof Array.isArray&&(Array.isArray=function(e){return e instanceof Array?!0:!1}),"function"!=typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^\s*((?:[\S\s]*\S)?)\s*$/,"$1")})}),require.define("/lib/runtime/core.js",function(e,r){var t=r.exports;t.error=function(){console.error.apply(console,arguments)},t.runDefers=function(e,r,t){var n=function(i){i&&console.error(i&&i.stack);var o=e.shift();if("function"!=typeof o)return t(null);try{o(r,n)}catch(i){n(i)}};n()},t.ifCondition=function(){for(var e=[],r=0,t=arguments.length;t>r;r+=2){var n=[arguments[r],arguments[r+1]];e.push(n)}var i=e.pop(),o=!1,a=function(){"function"==typeof i[1]?o?i[1](null):i[0](function(){i[1](null)}):i[0](null)},u=function(){var r=e.shift();!r||o?a():(o=r[0],r[0]?r[1](u):u())};u()},t.conditionLoop=function(e,r,t){var n=function(){e()?r(n,t):t()};n()},t.forEachLoop=function(e,r,t){var n=Object.keys(e),i=function(){if(n.length>0){var e=n.shift();r(e,i,t)}else t()};i()},t.sleep=function(e,r){setTimeout(function(){r(null,e)},e)},t.parseArguments=function(e){var r={arguments:[]};r.callback=e[e.length-1];for(var t=0,n=e.length-1;n>t;t++)r.arguments.push(e[t]);return r}}),require.define("/lib/compiler/define.js",function(e,r,t){t.TOKEN={BLANK:0,SYMBLE:1,NUMBER:2,STRING:4,NAME:8,KEYWORD:16,IDENTIFIER:32,COMMENT:64},t.KEYWORD=["await","argument","break","continue","defer","else","elseif","false","for","function","if","in","javascript","let","NaN","null","return","sleep","throw","true","undefined","var"]}),require.define("/lib/compiler/parser.js",function(e,r,t){var n=e("./define"),i=e("./token"),o=e("./syntax");n.TOKEN;var a=function(e,r,t,n){var i=50;console.error("[33m"),console.error("\n"),console.error(n),console.error("Line: "+(r+1)+", Column: "+(t+1)),console.error("");var o=e[r];if(o){if(t>i){var a=t-i;o=o.substr(a),t-=a}console.error(o);for(var u="",r=0;t>r;r++)u+=32>=o.charCodeAt(r)?o[r]:" ";console.error(u+"^")}return console.error("[39;49m"),o+"\n"+u};t.parse=function(e){var r=function(r,t,n){var i=Error(n);i.line=r,i.column=t;var o=e.split(/\r?\n/gm);throw a(o,i.line,i.column,n),i},t=function(e,t,n){r(e,t,"SyntaxError: "+n)},n=i.parse(e);if(!Array.isArray(n))return n instanceof Error?r(0,0,n.message):r(n.line,n.column,n.error);try{var u=o.parse(n);return u}catch(s){var c=s.token;if(!c)throw s;t(c.line,c.column,s.error)}}}),require.define("/lib/compiler/token.js",function(e,r,t){var n=e("./define"),i=n.TOKEN,o=n.KEYWORD,a={};o.forEach(function(e){a[e]=!0});var u={BLANK:0,SYMBLE:1,NUMBER:2,STRING:4,NAME:8,COMMENT_1:16,COMMENT_2:32},s={NUMBER_BEGIN:48,NUMBER_END:57,LOWER_BEGIN:97,LOWER_END:122,UPPER_BEGIN:65,UPPER_END:90,UNDERLINE:95,QUOTE_1:39,QUOTE_2:34,BACKSLASH:92,DOLLAR:36,STAR:42,FORWARDSLASH:47},c=function(e){return e>=s.NUMBER_BEGIN&&s.NUMBER_END>=e?!0:!1},f=function(e){return e>=s.UPPER_BEGIN&&s.UPPER_END>=e||e>=s.LOWER_BEGIN&&s.LOWER_END>=e||e===s.UNDERLINE||e===s.DOLLAR?!0:!1},l=function(e){return isNaN(e)||32>=e?!0:!1},p=function(e){return e===s.QUOTE_1||e===s.QUOTE_2?!0:!1},v=function(e){return 10===e||13===e?!0:!1},d=function(e){return a[e]?!0:!1};t._parse=function(e){e+=" ";var r,t=e.length,n=0,o=0,a=0,d={line:0,column:0},h=u.BLANK,E=[],x=!1,g=!1,m=!1,y=!1,L=!1,$=function(){o++,a=0},N=function(t){if(13===t)$();else if(10===t){var n=e.charCodeAt(r-1);13===n||$()}else a++},_=function(e){h=e,d={line:o,column:a-1}},k=function(t){if(r>n){var o=e.slice(n,r),a={type:t,line:d.line,column:d.column,text:o.trim()};t===i.BLANK?(o=o.replace(/\r|\n/gim,""),0>a.column&&(a.column=0),o.length>0&&(a.text=o,E.push(a))):(t===i.STRING&&(a.text=a.text.replace(/\n/gm,"\\n").replace(/\r/gm,"\\r")),E.push(a))}n=r,x=!1,g=!1,m=!1,y=!1,L=!1},b=function(){var t=e.charCodeAt(r);N(t),c(t)?_(u.NUMBER):f(t)?_(u.NAME):l(t)?_(u.BLANK):_(u.SYMBLE)},B=function(e){var e={error:"SyntaxError: "+e,line:o,column:a-1};throw e};try{for(r=0;t>r;r++){var M=e[r],S=e.charCodeAt(r);switch(N(S),h){case u.BLANK:c(S)?(k(i.BLANK),_(u.NUMBER)):f(S)?(k(i.BLANK),_(u.NAME)):p(S)?(k(i.BLANK),x=S,_(u.STRING)):l(S)||(k(i.BLANK),_(u.SYMBLE));break;case u.NUMBER:c(S)||(f(S)?g!==!1||"e"!==M&&"E"!==M?B("Unexpected token "+M):(g=!0,y=!1,m=!1):l(S)?(k(i.NUMBER),_(u.BLANK)):"."===M?m?B("Unexpected token "+M):m=!0:g&&"+"===M||"-"===M?y?B("Unexpected token "+M):y=!0:(k(i.NUMBER),_(u.SYMBLE)));break;case u.NAME:c(S)||f(S)||(l(S)?(k(i.NAME),_(u.BLANK)):"_"===M||(k(i.NAME),_(u.SYMBLE)));break;case u.SYMBLE:var R=e.charCodeAt(r-1);S===s.FORWARDSLASH&&R===s.FORWARDSLASH?h=u.COMMENT_1:R===s.FORWARDSLASH&&S===s.STAR?h=u.COMMENT_2:(k(i.SYMBLE),c(S)?_(u.NUMBER):f(S)?_(u.NAME):l(S)?_(u.BLANK):p(S)?(x=S,_(u.STRING)):_(u.SYMBLE));break;case u.STRING:S===x&&L===!1?(r++,k(i.STRING),b()):S===s.BACKSLASH?L=!L:L&&(L=!1);break;case u.COMMENT_1:(v(S)||r>=t-2)&&(r++,k(i.COMMENT),b());break;case u.COMMENT_2:if(S===s.STAR){var A=e.charCodeAt(r+1);A===s.FORWARDSLASH&&(r+=2,k(i.COMMENT),N(),b())}break;default:B("Unexpected token ILLEGAL")}}if(h===u.BLANK)return E;B("Unexpected end of input")}catch(w){return w}},t.parse=function(e){var r=t._parse(e);if(!Array.isArray(r))return r;for(var n=0;r.length>n;n++)(function(e,t){switch(e.type){case i.NAME:if(d(e.text)){var n=r[t-1],o=r[t+1];n=n&&n.type===i.SYMBLE?n.text:null,o=o&&o.type===i.SYMBLE?o.text:null,e.type="."===n||"."===o?i.IDENTIFIER:"{"!==n&&","!==n||":"!==o?i.KEYWORD:i.IDENTIFIER}else e.type=i.IDENTIFIER;break;case i.NUMBER:var n=r[t-1];if(n&&n.type===i.SYMBLE&&"."===n.text&&n.column+1===e.column&&n.line===e.line){var a=r[t-2];if(!a||a.type===i.SYMBLE){var u={type:i.NUMBER,text:n.text+e.text,line:n.line,column:n.column};r[t-1]=u,r.splice(t,1),t--}}break;case i.SYMBLE:var o=r[t+1];if(o&&e.line===o.line&&("+"===e.text&&"+"===o.text||"-"===e.text&&"-"===o.text||"<"===e.text&&"<"===o.text||">"===e.text&&">"===o.text||"="===e.text&&"="===o.text||">"===e.text&&"="===o.text||"<"===e.text&&"="===o.text||"!"===e.text&&"="===o.text)){var u={type:i.SYMBLE,text:e.text+o.text,line:e.line,column:e.column},s=r[t+2];"="!==e.text&&"!"!==e.text||"="!==o.text||!s||s.type!==i.SYMBLE||"="!==s.text?r.splice(t+1,1):(u.text+=s.text,r.splice(t+1,2)),r[t]=u}}})(r[n],n);var o=["true","false","null","undefined","NaN"];return r.forEach(function(e){e.type===i.KEYWORD&&-1!==o.indexOf(e.text)&&(e.type=i.IDENTIFIER)}),r}}),require.define("/lib/compiler/syntax.js",function(e,r){var t=e("./define");e("./token");var n=t.TOKEN,i=r.exports,o=function(e){if(e[0]){for(var r=e[0].line,t=1,n=e.length;n>t&&e[t].line===r;t++);return{line:e.slice(0,t),next:e.slice(t)}}return!1},a=function(e,r){r||(r="Unexpected token "+e.text);var t=Error(r);throw t.error=r,t.token=e,console.error(t.stack),t},u=function(e,r){var t=s(e);e.code.push(t+r)},s=function(e){for(var r="",t=0;e.indent>t;t++)r+=" ";return r},c=function(e){var r={};for(var t in e)r[t]=e[t];return r.defers=[],r.code=[],r},f=function(e,r,t,n){return{type:e,line:r,column:t,text:n}},l=function(e,r){var t=e[e.length-1],i=f(n.KEYWORD,t?t.line+1:-1,0,"return");return r&&(i.isNested=r),e.push(i),e},p=function(e){var r=e[e.length-1];if(r.type!==n.SYMBLE||"{"!==r.text)return a(r);e.pop();var t="";return e.forEach(function(e){t+=e.type===n.SYMBLE&&"="===e.text?" == ":e.text}),"("+t+")"},v=function(e){for(var r=[],t=0,i=function(i){if(i>t){var o="",u=[];if(e.slice(t,i).forEach(function(e){if(o+=e.text,e.type===n.SYMBLE)if("["===e.text||"("===e.text)u.push(e.text);else if("]"===e.text||")"===e.text){var r=u.pop();if(!("]"===e.text&&"["===r||")"===e.text&&"("===r))return a(e,"brackets do not match")}}),u.length>0)return a(s,"brackets do not match");r.push(o),t=i+1}},o=0,u=e.length;u>o;o++){var s=e[o];if(s.type===n.SYMBLE)if(","===s.text)i(o);else if("="===s.text){i(o);break}}return{names:r,next:e.slice(o+1)}},d=function(e){var r=[],t=[];return e.forEach(function(e,n){r.push("$$_arg_"+n),t.push(e+" = $$_arg_"+n+";")}),{args:r,init:t}},h=function(e){for(var r=[],t=0,i=function(i){if(i>t){var o="",u=[];if(e.slice(t,i).forEach(function(e){if(o+=e.text,e.type===n.SYMBLE)if("["===e.text||"("===e.text)u.push(e.text);else if("]"===e.text||")"===e.text){var r=u.pop();if(!("]"===e.text&&"["===r||")"===e.text&&"("===r))return a(e,"brackets do not match")}}),u.length>0)return a(s,"brackets do not match");r.push(o),t=i+1}},o=0,u=e.length;u>o;o++){var s=e[o];s.type===n.SYMBLE&&","===s.text&&i(o)}return i(o),r},E=function(e){var r=[];return e.forEach(function(e){e.type!==n.BLANK&&r.push(e)}),r};i.wrap=function(e){if(e.vars.length>0)var r=" var "+e.vars.join(", ")+";\n";else var r="";if(e.defers.length>0){var t=" ",n=["\n"+t+"/* defer function start */",t+"var $$_defers = [];"];e.defers.forEach(function(e){n.push(t+"$$_defers.push("+e+");")}),n.push(t+"var $$_oldCallback = $$_callback;"),n.push(t+"$$_callback = $$_callback_global = function () {"),n.push(t+" var $$_args = arguments;"),n.push(t+" $$_runtime.runDefers($$_defers, $$_args[0], function (err) {"),n.push(t+" if (err) $$_runtime.error(err.stack);"),n.push(t+" $$_oldCallback.apply(null, $$_args);"),n.push(t+" });"),n.push(t+"};"),n.push(t+"/* defer function end */\n"),n=n.join("\n")+"\n"}else n="";var t=s(e).substr(4),i="(function ("+e.args.join(", ")+") {\n"+t+' "use strict";\n\n'+t+" /* function header start */\n"+t+" var $$_callback, $arguments;\n"+t+' if (arguments.length < 1 || typeof(arguments[arguments.length - 1]) !== "function") {\n'+t+' throw new Error("Need a callback parameter.");\n'+t+" } else {\n"+t+" $arguments = $$_runtime.parseArguments(arguments);\n"+t+" $$_callback = $arguments.callback;\n"+t+" $arguments = $arguments.arguments;\n"+t+" }\n"+t+" var $$_callback_global = $$_callback;\n"+t+" /* function header end */\n\n"+t+" try {\n"+(r?t+r:"")+(n?t+n:"")+e.code.join("\n")+"\n"+t+" } catch (err) {\n"+t+" return $$_callback_global(err);\n"+t+" }\n"+t+"})";return i},i.parse=function(e,r){if(r)var t=e;else var t={args:[],vars:[],defers:[],tokenList:e,code:[],indent:2};r||(t.tokenList=l(t.tokenList));for(var s,c=function(e,r){u(t,"/* LINE:"+(e.line+1)+" "+r+" */")};s=o(t.tokenList);){var f=E(s.line);if(t.tokenList=s.next,!(1>f.length)){var p=f[0],v=f.slice(1);if(p.type===n.BLANK);else if(p.type===n.KEYWORD){var d=function(){return 1>v.length?a(p,"Unexpected end of input"):void 0};switch(p.text){case"argument":d(),m(t,v);break;case"var":d(),y(t,v);break;case"let":d(),c(p,"START"),L(t,v),c(p,"END");break;case"await":d(),c(p,"START"),N(t,"",v),c(p,"END");break;case"sleep":d(),c(p,"START"),R(t,v),c(p,"END");break;case"function":d(),c(p,"START"),S(t,"",v),c(p,"END");break;case"return":c(p,"START"),_(t,v,p.isNested),c(p,"END");break;case"defer":d(),k(t,v);break;case"if":d(),c(p,"START"),b(t,v),c(p,"END");break;case"for":d(),c(p,"START"),B(t,v),c(p,"END");break;case"break":c(p,"START"),u(t,"return $$_break(null);"),c(p,"END");break;case"continue":c(p,"START"),u(t,"return $$_continue(null);"),c(p,"END");break;case"throw":c(p,"START"),M(t,v),c(p,"END");break;case"javascript":d(),c(p,"START"),A(t,v),c(p,"END");break;default:return a(p)}}else c(p,"START"),$(t,"",f),c(p,"END")}}return r?void 0:i.wrap(t)};var x=function(e,r){for(var t,i=e.tokenList,a=[],u=0,s=!1;t=o(i);){i=t.next;var c=t.line,f=E(c),l=f[0];if(l){var p=f[f.length-1];if(r)l.type===n.SYMBLE&&"}"===l.text?u--:p.type===n.SYMBLE&&"{"===p.text&&u++;else{var v=!1,d=!1;l.type===n.SYMBLE&&"}"===l.text&&(u--,v=!0),p.type===n.SYMBLE&&"{"===p.text&&(u++,d=!0),s||(s=v&&d)}}if(0>u){f.length>1&&(i=f.slice(1).concat(i));break}a=a.concat(c)}if(s){var p=a[a.length-1];p&&p.type===n.SYMBLE&&"}"===p.text&&a.pop()}return{body:a,next:i}},g=function(e,r,t){var n=x(e,t);r&&(n.body=l(n.body,!0)),e.tokenList=n.body,i.parse(e,!0),e.tokenList=n.next},m=function(e,r){var t=!1;r.forEach(function(r){r.type===n.IDENTIFIER?(t=!1,e.args.push(r.text)):r.type!==n.SYMBLE||","!==r.text||t?a(r):t=!0})},y=function(e,r){var t=[],i=!1,o=null,u=[],s=r[r.length-1];r.push(f(n.SYMBLE,s.line,s.column+s.text.length,",")),r.forEach(function(r){if(i)if(r.type===n.SYMBLE)if("("===r.text||"["===r.text)u.push(r),t.push(r);else if(")"===r.text){var s=t.pop();if("("!==s.text)return a(r);u.push(r)}else if("]"===r.text){var s=t.pop();if("["!==s.text)return a(r);u.push(r)}else","===r.text?t.length>0?u.push(r):(u.push(f(n.SYMBLE,r.line,r.column,";")),$(e,o,u),i=!1):u.push(r);else u.push(r);else if(r.type===n.IDENTIFIER)e.vars.push(r.text),o=r.text,t=[],u=[];else{if(!o||r.type!==n.SYMBLE)return a(r);if(","===r.text)i=!1;else{if("="!==r.text)return a(r);i=!0}}})},L=function(e,r){if(3>r.length)return a(r[r.length-1],"Unexpected end of input");var t=v(r),i=t.names;if(1>t.next.length)return a(r[r.length-1],"Unexpected end of input");if(r=t.next,r[0].type===n.KEYWORD)if("await"===r[0].text){if(!r[1])return a(r[0],"Unexpected end of input");N(e,i,r.slice(1))}else{if("function"!==r[0].text)return a(r[0]);if(!r[1])return a(r[0],"Unexpected end of input");if(i.length>1)return a(r[0],"Not support tuple assignment");S(e,i[0],r.slice(1))}else{if(i.length>1)return a(r[0],"Not support tuple assignment");$(e,i[0],r)}},$=function(e,r,t){var i="",o=!1;t.forEach(function(e){e.type===n.IDENTIFIER||e.type===n.KEYWORD?(i+=(o?" ":"")+e.text,o=!0):(i+=e.text,o=!1)}),i=(r?r+" = ":"")+i.trim(),u(e,i)},N=function(e,r,t){var o=t[0];if(1===t.length&&o.type===n.NUMBER)return a(o);if(t[0].type!==n.IDENTIFIER)return a(t[0]);var s=t[t.length-1];if(s.type===n.SYMBLE&&")"===s.text){var c="";t.slice(0,t.length-1).forEach(function(e){c+=e.text});var f=t[t.length-2];f&&f.type===n.SYMBLE&&"("===f.text||(c+=", ")}else{var c="";t.forEach(function(e){c+=e.text}),c+="("}if(r.length>0)var l=d(r);c+="function ("+(r.length>0?l.args.join(", "):"")+") {",u(e,c),e.indent++,r.length>0&&l.init.forEach(function(r){u(e,r)}),i.parse(e,!0),e.indent--,u(e,"});")},_=function(e,r,t){var n=["null"];r.length>0&&(n=n.concat(h(r))),u(e,"return $$_callback"+(t?"":"_global")+"("+n.join(", ")+");")},k=function(e,r){var t=r[r.length-1],i="function (error, $$_callback) {\n",o="\n }";if(t.type===n.SYMBLE)if(")"===t.text&&r.length>=3){var u="";r.forEach(function(e){u+=e.text}),u=" "+u+";\n return $$_callback(null);",e.defers.push(i+u+o)}else{if("{"!==t.text||1!==r.length)return a(t);var s=c(e);s.indent=3,g(s,!0);var f=s.code.join("\n");e.defers.push(i+f+o),e.tokenList=s.tokenList}else{if(t.type!==n.IDENTIFIER)return a(t);var u="";r.forEach(function(e){u+=e.text}),u=" "+u+"();\n return $$_callback(null);",e.defers.push(i+u+o)}},b=function(e,r){var t=[],i=function(){var r=c(e);r.indent++,g(r,!0,!0),e.tokenList=r.tokenList;var t=r.code.join("\n");return t="function ($$_callback) {\n"+t+"\n"+s(e)+"}"};t.push(p(r)),t.push(i());var f=e.tokenList[0];if(f&&f.type===n.KEYWORD&&("else"===f.text||"elseif"===f.text))for(var l,v=!1;l=o(e.tokenList);){var d=l.line,h=E(d);e.tokenList=l.next;var x=h[0],m=h.slice(1);if(x.type!==n.KEYWORD){e.tokenList=d.concat(e.tokenList);break}if("elseif"===x.text)t.push(p(m)),t.push(i());else{if("else"!==x.text){e.tokenList=d.concat(e.tokenList);break}if(v)return a(x);t.push(i()),v=!0}}var y=c(e);y.indent++,g(y,!0),e.tokenList=y.tokenList;var L=y.code.join("\n"),$="$$_runtime.ifCondition("+t.join(", ")+", function () {\n"+L+"\n"+s(e)+"});";u(e,$)},B=function(e,r){var t=function(){var r=c(e);r.indent++,g(r),e.tokenList=r.tokenList;var t=r.code.join("\n");return t};if(r.length>=3&&r[1].type===n.KEYWORD&&"in"===r[1].text){if(r[0].type!==n.IDENTIFIER)return a(r[0]);var i=r[0].text,o="";r.slice(2,r.length-1).forEach(function(e){o+=e.text});var f=c(e);f.indent++,g(f,!0),e.tokenList=f.tokenList;var l=f.code.join("\n"),v=s(e),d="$$_runtime.forEachLoop("+o+", function ("+i+", $$_continue, $$_break) {\n"+v+" var $$_callback = $$_continue;\n"+l+"\n"+v+"}, function () {\n"+t()+"\n"+v+"});";u(e,d)}else{if(1===r.length&&r[0].type===n.SYMBLE&&"{"===r[0].text)var h="true";else var h=p(r);var f=c(e);f.indent++,g(f,!0),e.tokenList=f.tokenList;var l=f.code.join("\n"),v=s(e),d="$$_runtime.conditionLoop(function () {\n"+v+" return "+h+";\n"+v+"}, function ($$_continue, $$_break) {\n"+v+" var $$_callback = $$_continue;\n"+l+"\n"+v+"}, function () {\n"+t()+"\n"+v+"});";u(e,d)}},M=function(e,r){1>r.length?u(e,"return $$_callback_global(new Error());"):($(e,"var $$_err",r),u(e,"return $$_callback_global($$_err);"))},S=function(e,r,t){var o=t[t.length-1];if(o.type!==n.SYMBLE||"{"!==o.text)return a(o);var s=[];if(1===t.length);else{var f=t.slice(0,t.length-1),l=f[0],o=f[f.length-1];if(l.type!==n.SYMBLE||"("!==l.text)return a(l);if(o.type!==n.SYMBLE||")"!==o.text)return a(l);var p=!0;f.slice(1,f.length-1).forEach(function(e){if(p&&e.type===n.IDENTIFIER)s.push(e.text),p=!1;else{if(p||e.type!==n.SYMBLE||","!==e.text)return a(e);p=!0}})}var v=c(e);v.vars=[],v.indent+=2,g(v,!0),v.args=s,v.args.push("$$_callback");var d=i.wrap(v);u(e,"");var h=(r?r+" = ":"")+d+";";u(e,h),u(e,""),e.tokenList=v.tokenList},R=function(e,r){var t=r[r.length-1];r.push(f(n.SYMBLE,t.line,t.column+t.text.length+1,";")),$(e,"var $$_sleep_ms",r);var o="$$_runtime.sleep($$_sleep_ms, function ($$_err) {";u(e,o),e.indent++,i.parse(e,!0),e.indent--,u(e,"});")},A=function(e,r){var t=r[0];if(1!==r.length||t.type!==n.SYMBLE||"{"!==t.text)return a(t);for(var i,s=x(e),r=s.body;i=o(r);){r=i.next;var c=!1,f="";i.line.forEach(function(e){e.type===n.IDENTIFIER||e.type===n.KEYWORD?(f+=(c?" ":"")+e.text,c=!0):(f+=e.text,c=!1)}),u(e,f)}e.tokenList=s.next}}),require.define("/index.js",function(e,r){r.exports=e("./lib")}),require("/index.js")})(); |
@@ -125,3 +125,3 @@ (function () { | ||
var g = groups.shift(); | ||
if (!g) { | ||
if (!g || lastCondition) { | ||
// 最后一组 | ||
@@ -128,0 +128,0 @@ done(); |
@@ -1,1 +0,1 @@ | ||
(function(){"function"!=typeof Array.prototype.forEach&&(Array.prototype.forEach=function(e){for(var r=this.length,t=0;r>t;t++)e(this[t],t,this)}),"function"!=typeof Array.prototype.indexOf&&(Array.prototype.indexOf=function(e){for(var r=0,t=this.length;t>r;r++)if(this[r]===e)return r;return-1}),"function"!=typeof Array.isArray&&(Array.isArray=function(e){return e instanceof Array?!0:!1}),"function"!=typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^\s*((?:[\S\s]*\S)?)\s*$/,"$1")}),window.Bright===void 0&&(window.Bright={});var e={exports:{}};(function(e){var r=e.exports;r.error=function(){console.error.apply(console,arguments)},r.runDefers=function(e,r,t){var n=function(i){i&&console.error(i&&i.stack);var o=e.shift();if("function"!=typeof o)return t(null);try{o(r,n)}catch(i){n(i)}};n()},r.ifCondition=function(){for(var e=[],r=0,t=arguments.length;t>r;r+=2){var n=[arguments[r],arguments[r+1]];e.push(n)}var i=e.pop(),o=!1,a=function(){"function"==typeof i[1]?o?i[1](null):i[0](function(){i[1](null)}):i[0](null)},u=function(){var r=e.shift();r?(o=r[0],r[0]?r[1](u):u()):a()};u()},r.conditionLoop=function(e,r,t){var n=function(){e()?r(n,t):t()};n()},r.forEachLoop=function(e,r,t){var n=Object.keys(e),i=function(){if(n.length>0){var e=n.shift();r(e,i,t)}else t()};i()},r.sleep=function(e,r){setTimeout(function(){r(null,e)},e)},r.parseArguments=function(e){var r={arguments:[]};r.callback=e[e.length-1];for(var t=0,n=e.length-1;n>t;t++)r.arguments.push(e[t]);return r}})(e,e.exports),window.Bright.runtime=e.exports})(); | ||
(function(){"function"!=typeof Array.prototype.forEach&&(Array.prototype.forEach=function(e){for(var r=this.length,t=0;r>t;t++)e(this[t],t,this)}),"function"!=typeof Array.prototype.indexOf&&(Array.prototype.indexOf=function(e){for(var r=0,t=this.length;t>r;r++)if(this[r]===e)return r;return-1}),"function"!=typeof Array.isArray&&(Array.isArray=function(e){return e instanceof Array?!0:!1}),"function"!=typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^\s*((?:[\S\s]*\S)?)\s*$/,"$1")}),window.Bright===void 0&&(window.Bright={});var e={exports:{}};(function(e){var r=e.exports;r.error=function(){console.error.apply(console,arguments)},r.runDefers=function(e,r,t){var n=function(i){i&&console.error(i&&i.stack);var o=e.shift();if("function"!=typeof o)return t(null);try{o(r,n)}catch(i){n(i)}};n()},r.ifCondition=function(){for(var e=[],r=0,t=arguments.length;t>r;r+=2){var n=[arguments[r],arguments[r+1]];e.push(n)}var i=e.pop(),o=!1,a=function(){"function"==typeof i[1]?o?i[1](null):i[0](function(){i[1](null)}):i[0](null)},u=function(){var r=e.shift();!r||o?a():(o=r[0],r[0]?r[1](u):u())};u()},r.conditionLoop=function(e,r,t){var n=function(){e()?r(n,t):t()};n()},r.forEachLoop=function(e,r,t){var n=Object.keys(e),i=function(){if(n.length>0){var e=n.shift();r(e,i,t)}else t()};i()},r.sleep=function(e,r){setTimeout(function(){r(null,e)},e)},r.parseArguments=function(e){var r={arguments:[]};r.callback=e[e.length-1];for(var t=0,n=e.length-1;n>t;t++)r.arguments.push(e[t]);return r}})(e,e.exports),window.Bright.runtime=e.exports})(); |
@@ -124,9 +124,7 @@ /** | ||
var lastT = tokenList[tokenList.length - 1]; | ||
if (lastT) { | ||
var tReturn = createNewToken(TOKEN.KEYWORD, lastT.line + 1, 0, 'return'); | ||
if (isNested) { | ||
tReturn.isNested = isNested; | ||
} | ||
tokenList.push(tReturn); | ||
var tReturn = createNewToken(TOKEN.KEYWORD, (lastT ? lastT.line + 1 : -1), 0, 'return'); | ||
if (isNested) { | ||
tReturn.isNested = isNested; | ||
} | ||
tokenList.push(tReturn); | ||
return tokenList; | ||
@@ -983,3 +981,3 @@ }; | ||
newContext.indent++; | ||
parseNested(newContext); | ||
parseNested(newContext, true); | ||
context.tokenList = newContext.tokenList; | ||
@@ -986,0 +984,0 @@ var nextCode = newContext.code.join('\n'); |
@@ -80,3 +80,3 @@ /** | ||
var g = groups.shift(); | ||
if (!g) { | ||
if (!g || lastCondition) { | ||
// 最后一组 | ||
@@ -83,0 +83,0 @@ done(); |
{ | ||
"name": "bright", | ||
"main": "./index.js", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "A tiny script language, add async/await support for javascript", | ||
@@ -6,0 +6,0 @@ "keywords": ["async", "await", "compiler", "javascript", "language"], |
@@ -59,3 +59,3 @@ /** | ||
}); | ||
return; | ||
it('#5 多个if elseif', function (done) { | ||
@@ -74,2 +74,13 @@ var fn = compile('5'); | ||
it('#6 for in 里面的 if elseif', function (done) { | ||
var fn = compile('6'); | ||
fn(function (err, ret1, ret2, ret3) { | ||
should.equal(err, null); | ||
ret1.should.eql([2,4,6,8,10]); | ||
ret2.should.eql([3,9]); | ||
ret3.should.eql([1,5,7]); | ||
done(); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is too big to display
222667
37
5811