diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..b1aa086 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,2 @@ +node_modules/* +**/*.test.js \ No newline at end of file diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000..2a3e949 --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,19 @@ +module.exports = { + "env": { + "browser": true, + "es6": true, + "node": true + }, + "extends": "eslint:recommended", + "globals": { + "Atomics": "readonly", + "SharedArrayBuffer": "readonly" + }, + "parserOptions": { + "ecmaVersion": 2018, + "sourceType": "commonjs" + }, + "rules": { + "no-console": 0 + } +}; \ No newline at end of file diff --git a/browser.js b/browser.js index 859cda8..47be46c 100644 --- a/browser.js +++ b/browser.js @@ -27,7 +27,7 @@ const examplePrograms = exampleProgramSource.map(program => { const handleError = (e, source = '') => { if (!e) { - document.getElementById('error').style.display = 'none' + document.getElementById('error').style.maxHeight = '0' return null } console.error(e) @@ -37,7 +37,7 @@ const handleError = (e, source = '') => { errorStr += '
' errorStr += `${preErrorSection}${errorSection}${postErrorSection}` } - document.getElementById('error').style.display = '' + document.getElementById('error').style.maxHeight = '150px' document.getElementById('errorText').innerHTML = errorStr } @@ -51,9 +51,13 @@ exampleProgram.onchange = e => { const selectedProgram = e.target.value code.value = examplePrograms[selectedProgram].program } + +// Pick default program to load let defaultProgram = 0 if (window.location.hash) { - defaultProgram = +window.location.hash.replace(/[^\w\s]/gi, '').trim() + let hashValue = +window.location.hash.replace(/[^\w\s]/gi, '').trim() + if (hashValue < exampleProgram.length) defaultProgram = hashValue + exampleProgram.value = defaultProgram } code.value = examplePrograms[defaultProgram].program @@ -89,7 +93,12 @@ button.onclick = () => { const formatButton = document.getElementById('format') formatButton.onclick = () => { - code.value = parse(code.value) - .map(stmt => printLoxAST(stmt)) - .join('\n') + try { + code.value = parse(code.value) + .map(stmt => printLoxAST(stmt)) + .join('\n') + handleError(null) + } catch (e) { + handleError(e, code.value) + } } diff --git a/cli.js b/cli.js index ab36168..69f8061 100755 --- a/cli.js +++ b/cli.js @@ -96,7 +96,7 @@ const main = argv => { const args = processOptions(argv.slice(2)) if (options.debug) console.log(options) if (args.length > 1) { - console.error('Usage: jlox [script]') + console.error('Usage: yali [script]') return 64 } else if (args.length === 1) { runFile(args[0]) diff --git a/docs/browser.4a180639.js b/docs/browser.4a180639.js deleted file mode 100644 index 1e59116..0000000 --- a/docs/browser.4a180639.js +++ /dev/null @@ -1,41 +0,0 @@ -parcelRequire=function(e,r,t,n){var i,o="function"==typeof parcelRequire&&parcelRequire,u="function"==typeof require&&require;function f(t,n){if(!r[t]){if(!e[t]){var i="function"==typeof parcelRequire&&parcelRequire;if(!n&&i)return i(t,!0);if(o)return o(t,!0);if(u&&"string"==typeof t)return u(t);var c=new Error("Cannot find module '"+t+"'");throw c.code="MODULE_NOT_FOUND",c}p.resolve=function(r){return e[t][1][r]||r},p.cache={};var l=r[t]=new f.Module(t);e[t][0].call(l.exports,p,l,l.exports,this)}return r[t].exports;function p(e){return f(p.resolve(e))}}f.isParcelRequire=!0,f.Module=function(e){this.id=e,this.bundle=f,this.exports={}},f.modules=e,f.cache=r,f.parent=o,f.register=function(r,t){e[r]=[function(e,r){r.exports=t},{}]};for(var c=0;c1&&(e-=1)),[360*e,100*h,100*s]},t.rgb.hwb=function(r){var n=r[0],a=r[1],e=r[2];return[t.rgb.hsl(r)[0],100*(1/255*Math.min(n,Math.min(a,e))),100*(e=1-1/255*Math.max(n,Math.max(a,e)))]},t.rgb.cmyk=function(r){var n,a=r[0]/255,t=r[1]/255,e=r[2]/255;return[100*((1-a-(n=Math.min(1-a,1-t,1-e)))/(1-n)||0),100*((1-t-n)/(1-n)||0),100*((1-e-n)/(1-n)||0),100*n]},t.rgb.keyword=function(a){var t=n[a];if(t)return t;var e,h=1/0;for(var u in r)if(r.hasOwnProperty(u)){var c=o(a,r[u]);c.04045?Math.pow((n+.055)/1.055,2.4):n/12.92)+.3576*(a=a>.04045?Math.pow((a+.055)/1.055,2.4):a/12.92)+.1805*(t=t>.04045?Math.pow((t+.055)/1.055,2.4):t/12.92)),100*(.2126*n+.7152*a+.0722*t),100*(.0193*n+.1192*a+.9505*t)]},t.rgb.lab=function(r){var n=t.rgb.xyz(r),a=n[0],e=n[1],h=n[2];return e/=100,h/=108.883,a=(a/=95.047)>.008856?Math.pow(a,1/3):7.787*a+16/116,[116*(e=e>.008856?Math.pow(e,1/3):7.787*e+16/116)-16,500*(a-e),200*(e-(h=h>.008856?Math.pow(h,1/3):7.787*h+16/116))]},t.hsl.rgb=function(r){var n,a,t,e,h,u=r[0]/360,o=r[1]/100,c=r[2]/100;if(0===o)return[h=255*c,h,h];n=2*c-(a=c<.5?c*(1+o):c+o-c*o),e=[0,0,0];for(var s=0;s<3;s++)(t=u+1/3*-(s-1))<0&&t++,t>1&&t--,h=6*t<1?n+6*(a-n)*t:2*t<1?a:3*t<2?n+(a-n)*(2/3-t)*6:n,e[s]=255*h;return e},t.hsl.hsv=function(r){var n=r[0],a=r[1]/100,t=r[2]/100,e=a,h=Math.max(t,.01);return a*=(t*=2)<=1?t:2-t,e*=h<=1?h:2-h,[n,100*(0===t?2*e/(h+e):2*a/(t+a)),100*((t+a)/2)]},t.hsv.rgb=function(r){var n=r[0]/60,a=r[1]/100,t=r[2]/100,e=Math.floor(n)%6,h=n-Math.floor(n),u=255*t*(1-a),o=255*t*(1-a*h),c=255*t*(1-a*(1-h));switch(t*=255,e){case 0:return[t,c,u];case 1:return[o,t,u];case 2:return[u,t,c];case 3:return[u,o,t];case 4:return[c,u,t];case 5:return[t,u,o]}},t.hsv.hsl=function(r){var n,a,t,e=r[0],h=r[1]/100,u=r[2]/100,o=Math.max(u,.01);return t=(2-h)*u,a=h*o,[e,100*(a=(a/=(n=(2-h)*o)<=1?n:2-n)||0),100*(t/=2)]},t.hwb.rgb=function(r){var n,a,t,e,h,u,o,c=r[0]/360,s=r[1]/100,l=r[2]/100,i=s+l;switch(i>1&&(s/=i,l/=i),t=6*c-(n=Math.floor(6*c)),0!=(1&n)&&(t=1-t),e=s+t*((a=1-l)-s),n){default:case 6:case 0:h=a,u=e,o=s;break;case 1:h=e,u=a,o=s;break;case 2:h=s,u=a,o=e;break;case 3:h=s,u=e,o=a;break;case 4:h=e,u=s,o=a;break;case 5:h=a,u=s,o=e}return[255*h,255*u,255*o]},t.cmyk.rgb=function(r){var n=r[0]/100,a=r[1]/100,t=r[2]/100,e=r[3]/100;return[255*(1-Math.min(1,n*(1-e)+e)),255*(1-Math.min(1,a*(1-e)+e)),255*(1-Math.min(1,t*(1-e)+e))]},t.xyz.rgb=function(r){var n,a,t,e=r[0]/100,h=r[1]/100,u=r[2]/100;return a=-.9689*e+1.8758*h+.0415*u,t=.0557*e+-.204*h+1.057*u,n=(n=3.2406*e+-1.5372*h+-.4986*u)>.0031308?1.055*Math.pow(n,1/2.4)-.055:12.92*n,a=a>.0031308?1.055*Math.pow(a,1/2.4)-.055:12.92*a,t=t>.0031308?1.055*Math.pow(t,1/2.4)-.055:12.92*t,[255*(n=Math.min(Math.max(0,n),1)),255*(a=Math.min(Math.max(0,a),1)),255*(t=Math.min(Math.max(0,t),1))]},t.xyz.lab=function(r){var n=r[0],a=r[1],t=r[2];return a/=100,t/=108.883,n=(n/=95.047)>.008856?Math.pow(n,1/3):7.787*n+16/116,[116*(a=a>.008856?Math.pow(a,1/3):7.787*a+16/116)-16,500*(n-a),200*(a-(t=t>.008856?Math.pow(t,1/3):7.787*t+16/116))]},t.lab.xyz=function(r){var n,a,t,e=r[0];n=r[1]/500+(a=(e+16)/116),t=a-r[2]/200;var h=Math.pow(a,3),u=Math.pow(n,3),o=Math.pow(t,3);return a=h>.008856?h:(a-16/116)/7.787,n=u>.008856?u:(n-16/116)/7.787,t=o>.008856?o:(t-16/116)/7.787,[n*=95.047,a*=100,t*=108.883]},t.lab.lch=function(r){var n,a=r[0],t=r[1],e=r[2];return(n=360*Math.atan2(e,t)/2/Math.PI)<0&&(n+=360),[a,Math.sqrt(t*t+e*e),n]},t.lch.lab=function(r){var n,a=r[0],t=r[1];return n=r[2]/360*2*Math.PI,[a,t*Math.cos(n),t*Math.sin(n)]},t.rgb.ansi16=function(r){var n=r[0],a=r[1],e=r[2],h=1 in arguments?arguments[1]:t.rgb.hsv(r)[2];if(0===(h=Math.round(h/50)))return 30;var u=30+(Math.round(e/255)<<2|Math.round(a/255)<<1|Math.round(n/255));return 2===h&&(u+=60),u},t.hsv.ansi16=function(r){return t.rgb.ansi16(t.hsv.rgb(r),r[2])},t.rgb.ansi256=function(r){var n=r[0],a=r[1],t=r[2];return n===a&&a===t?n<8?16:n>248?231:Math.round((n-8)/247*24)+232:16+36*Math.round(n/255*5)+6*Math.round(a/255*5)+Math.round(t/255*5)},t.ansi16.rgb=function(r){var n=r%10;if(0===n||7===n)return r>50&&(n+=3.5),[n=n/10.5*255,n,n];var a=.5*(1+~~(r>50));return[(1&n)*a*255,(n>>1&1)*a*255,(n>>2&1)*a*255]},t.ansi256.rgb=function(r){if(r>=232){var n=10*(r-232)+8;return[n,n,n]}var a;return r-=16,[Math.floor(r/36)/5*255,Math.floor((a=r%36)/6)/5*255,a%6/5*255]},t.rgb.hex=function(r){var n=(((255&Math.round(r[0]))<<16)+((255&Math.round(r[1]))<<8)+(255&Math.round(r[2]))).toString(16).toUpperCase();return"000000".substring(n.length)+n},t.hex.rgb=function(r){var n=r.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);if(!n)return[0,0,0];var a=n[0];3===n[0].length&&(a=a.split("").map(function(r){return r+r}).join(""));var t=parseInt(a,16);return[t>>16&255,t>>8&255,255&t]},t.rgb.hcg=function(r){var n,a=r[0]/255,t=r[1]/255,e=r[2]/255,h=Math.max(Math.max(a,t),e),u=Math.min(Math.min(a,t),e),o=h-u;return n=o<=0?0:h===a?(t-e)/o%6:h===t?2+(e-a)/o:4+(a-t)/o+4,n/=6,[360*(n%=1),100*o,100*(o<1?u/(1-o):0)]},t.hsl.hcg=function(r){var n=r[1]/100,a=r[2]/100,t=1,e=0;return(t=a<.5?2*n*a:2*n*(1-a))<1&&(e=(a-.5*t)/(1-t)),[r[0],100*t,100*e]},t.hsv.hcg=function(r){var n=r[1]/100,a=r[2]/100,t=n*a,e=0;return t<1&&(e=(a-t)/(1-t)),[r[0],100*t,100*e]},t.hcg.rgb=function(r){var n=r[0]/360,a=r[1]/100,t=r[2]/100;if(0===a)return[255*t,255*t,255*t];var e,h=[0,0,0],u=n%1*6,o=u%1,c=1-o;switch(Math.floor(u)){case 0:h[0]=1,h[1]=o,h[2]=0;break;case 1:h[0]=c,h[1]=1,h[2]=0;break;case 2:h[0]=0,h[1]=1,h[2]=o;break;case 3:h[0]=0,h[1]=c,h[2]=1;break;case 4:h[0]=o,h[1]=0,h[2]=1;break;default:h[0]=1,h[1]=0,h[2]=c}return e=(1-a)*t,[255*(a*h[0]+e),255*(a*h[1]+e),255*(a*h[2]+e)]},t.hcg.hsv=function(r){var n=r[1]/100,a=n+r[2]/100*(1-n),t=0;return a>0&&(t=n/a),[r[0],100*t,100*a]},t.hcg.hsl=function(r){var n=r[1]/100,a=r[2]/100*(1-n)+.5*n,t=0;return a>0&&a<.5?t=n/(2*a):a>=.5&&a<1&&(t=n/(2*(1-a))),[r[0],100*t,100*a]},t.hcg.hwb=function(r){var n=r[1]/100,a=n+r[2]/100*(1-n);return[r[0],100*(a-n),100*(1-a)]},t.hwb.hcg=function(r){var n=r[1]/100,a=1-r[2]/100,t=a-n,e=0;return t<1&&(e=(a-t)/(1-t)),[r[0],100*t,100*e]},t.apple.rgb=function(r){return[r[0]/65535*255,r[1]/65535*255,r[2]/65535*255]},t.rgb.apple=function(r){return[r[0]/255*65535,r[1]/255*65535,r[2]/255*65535]},t.gray.rgb=function(r){return[r[0]/100*255,r[0]/100*255,r[0]/100*255]},t.gray.hsl=t.gray.hsv=function(r){return[0,0,r[0]]},t.gray.hwb=function(r){return[0,100,r[0]]},t.gray.cmyk=function(r){return[0,0,0,r[0]]},t.gray.lab=function(r){return[r[0],0,0]},t.gray.hex=function(r){var n=255&Math.round(r[0]/100*255),a=((n<<16)+(n<<8)+n).toString(16).toUpperCase();return"000000".substring(a.length)+a},t.rgb.gray=function(r){return[(r[0]+r[1]+r[2])/3/255*100]}; -},{"color-name":"auEH"}],"fg2k":[function(require,module,exports) { -var n=require("./conversions");function r(){for(var r={},e=Object.keys(n),t=e.length,a=0;a1&&(n=Array.prototype.slice.call(arguments)),e(n))};return"conversion"in e&&(n.conversion=e.conversion),n}function c(e){var n=function(n){if(null==n)return n;arguments.length>1&&(n=Array.prototype.slice.call(arguments));var r=e(n);if("object"==typeof r)for(var o=r.length,t=0;t(function(){const t=o.apply(n,arguments);return"[".concat(t+e,"m")}),t=(o,e)=>(function(){const t=o.apply(n,arguments);return"[".concat(38+e,";5;").concat(t,"m")}),r=(o,e)=>(function(){const t=o.apply(n,arguments);return"[".concat(38+e,";2;").concat(t[0],";").concat(t[1],";").concat(t[2],"m")});function i(){const i=new Map,c={modifier:{reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],inverse:[7,27],hidden:[8,28],strikethrough:[9,29]},color:{black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],gray:[90,39],redBright:[91,39],greenBright:[92,39],yellowBright:[93,39],blueBright:[94,39],magentaBright:[95,39],cyanBright:[96,39],whiteBright:[97,39]},bgColor:{bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],bgBlackBright:[100,49],bgRedBright:[101,49],bgGreenBright:[102,49],bgYellowBright:[103,49],bgBlueBright:[104,49],bgMagentaBright:[105,49],bgCyanBright:[106,49],bgWhiteBright:[107,49]}};c.color.grey=c.color.gray;for(const o of Object.keys(c)){const n=c[o];for(const o of Object.keys(n)){const e=n[o];c[o]={open:"[".concat(e[0],"m"),close:"[".concat(e[1],"m")},n[o]=c[o],i.set(e[0],e[1])}Object.defineProperty(c,o,{value:n,enumerable:!1}),Object.defineProperty(c,"codes",{value:i,enumerable:!1})}const a=o=>o,l=(o,n,e)=>[o,n,e];c.color.close="",c.bgColor.close="",c.color.ansi={ansi:e(a,0)},c.color.ansi256={ansi256:t(a,0)},c.color.ansi16m={rgb:r(l,0)},c.bgColor.ansi={ansi:e(a,10)},c.bgColor.ansi256={ansi256:t(a,10)},c.bgColor.ansi16m={rgb:r(l,10)};for(let g of Object.keys(n)){if("object"!==o(n[g]))continue;const i=n[g];"ansi16"===g&&(g="ansi"),"ansi16"in i&&(c.color.ansi[g]=e(i.ansi16,0),c.bgColor.ansi[g]=e(i.ansi16,10)),"ansi256"in i&&(c.color.ansi256[g]=t(i.ansi256,0),c.bgColor.ansi256[g]=t(i.ansi256,10)),"rgb"in i&&(c.color.ansi16m[g]=r(i.rgb,0),c.bgColor.ansi16m[g]=r(i.rgb,10))}return c}Object.defineProperty(module,"exports",{enumerable:!0,get:i}); -},{"color-convert":"PawV"}],"foIL":[function(require,module,exports) { -"use strict";module.exports={stdout:!1,stderr:!1}; -},{}],"PLSQ":[function(require,module,exports) { -"use strict";const t=/(?:\\(u[a-f\d]{4}|x[a-f\d]{2}|.))|(?:\{(~)?(\w+(?:\([^)]*\))?(?:\.\w+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n)))|(\})|((?:.|[\r\n\f])+?)/gi,e=/(?:^|\.)(\w+)(?:\(([^)]*)\))?/g,n=/^(['"])((?:\\.|(?!\1)[^\\])*)\1$/,r=/\\(u[a-f\d]{4}|x[a-f\d]{2}|.)|([^\\])/gi,s=new Map([["n","\n"],["r","\r"],["t","\t"],["b","\b"],["f","\f"],["v","\v"],["0","\0"],["\\","\\"],["e",""],["a",""]]);function o(t){return"u"===t[0]&&5===t.length||"x"===t[0]&&3===t.length?String.fromCharCode(parseInt(t.slice(1),16)):s.get(t)||t}function l(t,e){const s=[],l=e.trim().split(/\s*,\s*/g);let i;for(const c of l)if(isNaN(c)){if(!(i=c.match(n)))throw new Error("Invalid Chalk template style argument: ".concat(c," (in style '").concat(t,"')"));s.push(i[2].replace(r,(t,e,n)=>e?o(e):n))}else s.push(Number(c));return s}function i(t){e.lastIndex=0;const n=[];let r;for(;null!==(r=e.exec(t));){const t=r[1];if(r[2]){const e=l(t,r[2]);n.push([t].concat(e))}else n.push([t])}return n}function c(t,e){const n={};for(const s of e)for(const t of s.styles)n[t[0]]=s.inverse?null:t.slice(1);let r=t;for(const s of Object.keys(n))if(Array.isArray(n[s])){if(!(s in r))throw new Error("Unknown Chalk style: ".concat(s));r=n[s].length>0?r[s].apply(r,n[s]):r[s]}return r}module.exports=((e,n)=>{const r=[],s=[];let l=[];if(n.replace(t,(t,n,a,f,u,h)=>{if(n)l.push(o(n));else if(f){const t=l.join("");l=[],s.push(0===r.length?t:c(e,r)(t)),r.push({inverse:a,styles:i(f)})}else if(u){if(0===r.length)throw new Error("Found extraneous } in Chalk template literal");s.push(c(e,r)(l.join(""))),l=[],r.pop()}else l.push(h)}),s.push(l.join("")),r.length>0){const t="Chalk template literal is missing ".concat(r.length," closing bracket").concat(1===r.length?"":"s"," (`}`)");throw new Error(t)}return s.join("")}); -},{}],"g5I+":[function(require,module,exports) { - -var t,e,n=module.exports={};function r(){throw new Error("setTimeout has not been defined")}function o(){throw new Error("clearTimeout has not been defined")}function i(e){if(t===setTimeout)return setTimeout(e,0);if((t===r||!t)&&setTimeout)return t=setTimeout,setTimeout(e,0);try{return t(e,0)}catch(n){try{return t.call(null,e,0)}catch(n){return t.call(this,e,0)}}}function u(t){if(e===clearTimeout)return clearTimeout(t);if((e===o||!e)&&clearTimeout)return e=clearTimeout,clearTimeout(t);try{return e(t)}catch(n){try{return e.call(null,t)}catch(n){return e.call(this,t)}}}!function(){try{t="function"==typeof setTimeout?setTimeout:r}catch(n){t=r}try{e="function"==typeof clearTimeout?clearTimeout:o}catch(n){e=o}}();var c,s=[],l=!1,a=-1;function f(){l&&c&&(l=!1,c.length?s=c.concat(s):a=-1,s.length&&h())}function h(){if(!l){var t=i(f);l=!0;for(var e=s.length;e;){for(c=s,s=[];++a1)for(var n=1;n0}function p(e){if(!this||!(this instanceof p)||this.template){const t={};return a(t,e),t.template=function(){const e=[].slice.call(arguments);return y.apply(null,[t.template].concat(e))},Object.setPrototypeOf(t,p.prototype),Object.setPrototypeOf(t.template,t),t.template.constructor=p,t.template}a(this,e)}l&&(o.blue.open="");for(const g of Object.keys(o))o[g].closeRe=new RegExp(t(o[g].close),"g"),i[g]={get:function(){const e=o[g];return f.call(this,this._styles?this._styles.concat(e):[e],this._empty,g)}};i.visible={get:function(){return f.call(this,this._styles||[],!0,"visible")}},o.color.closeRe=new RegExp(t(o.color.close),"g");for(const g of Object.keys(o.color.ansi))c.has(g)||(i[g]={get:function(){const e=this.level;return function(){const t={open:o.color[r[e]][g].apply(null,arguments),close:o.color.close,closeRe:o.color.closeRe};return f.call(this,this._styles?this._styles.concat(t):[t],this._empty,g)}}});o.bgColor.closeRe=new RegExp(t(o.bgColor.close),"g");for(const g of Object.keys(o.bgColor.ansi)){if(c.has(g))continue;i["bg"+g[0].toUpperCase()+g.slice(1)]={get:function(){const e=this.level;return function(){const t={open:o.bgColor[r[e]][g].apply(null,arguments),close:o.bgColor.close,closeRe:o.bgColor.closeRe};return f.call(this,this._styles?this._styles.concat(t):[t],this._empty,g)}}}}const u=Object.defineProperties(()=>{},i);function f(e,t,o){const s=function(){return h.apply(s,arguments)};s._styles=e,s._empty=t;const n=this;return Object.defineProperty(s,"level",{enumerable:!0,get:function(){return n.level},set:function(e){n.level=e}}),Object.defineProperty(s,"enabled",{enumerable:!0,get:function(){return n.enabled},set:function(e){n.enabled=e}}),s.hasGrey=this.hasGrey||"gray"===o||"grey"===o,s.__proto__=u,s}function h(){const e=arguments,t=e.length;let s=String(arguments[0]);if(0===t)return"";if(t>1)for(let o=1;o":function(t){t.addToken(t.nextMatch("=")?h.GREATER_EQUAL:h.GREATER)},"<":function(t){t.addToken(t.nextMatch("=")?h.LESS_EQUAL:h.LESS)}," ":r,"\t":r,"\r":r,"\n":function(t){t.newline()},'"':function(t){t.handleStringLiterals()}},a=function(t){return/\d/.test(t)},l=function(t){return/[a-zA-Z_]/.test(t)},f=function(t){return l(t)||a(t)},d=function(){function n(e){t(this,n),this.source=e,this.length=e.length,this.tokens=[],this.startPosition=null,this.column=0,this.start=0,this.line=1,this.current=0}return e(n,null,[{key:"tokens",get:function(){return o}},{key:"tokenEnum",get:function(){return h}}]),e(n,[{key:"handleStringLiterals",value:function(){for(;'"'!==this.peek()&&""!==this.peek();)"\n"===this.peek()&&this.newline(),this.chomp();if(""===this.peek())throw s("Unfinished string",this.startPosition,this.endPosition);this.chomp();var t=this.source.substring(this.start+1,this.current-1);this.addToken(h.STRING,t)}},{key:"handleNumberLiterals",value:function(){for(var t=!1;a(this.peek())||!t&&"."===this.peek();)"."===this.peek()&&(t=!0),this.chomp();var n=this.source.substring(this.start,this.current);this.addToken(h.NUMBER,parseFloat(n))}},{key:"handleIdentifiers",value:function(){for(;f(this.peek());)this.chomp();var t=this.source.substring(this.start,this.current);u[t]?this.addToken(u[t],t):this.addToken(h.IDENTIFIER,t)}},{key:"scanTokens",value:function(){for(;this.current1&&void 0!==arguments[1]?arguments[1]:null,e=this.source.substring(this.start,this.current);this.tokens.push(new k(t,e,n,new E(this.column,this.line,this.current),this.startPosition))}},{key:"increment",value:function(){this.current++,this.column++}},{key:"newline",value:function(){this.line++,this.column=0}},{key:"chomp",value:function(){return this.increment(),this.source.charAt(this.current-1)}},{key:"peek",value:function(){return this.source.charAt(this.current)}},{key:"nextMatch",value:function(t){return this.peek()===t&&(this.increment(),!0)}},{key:"endPosition",get:function(){return new E(this.column-1,this.line,this.current)}}]),n}(),E=function n(e,i,s){t(this,n),this.col=e,this.line=i,this.index=s},k=function n(e,i,s,r,o){t(this,n),this.type=e,this.lexeme=i,this.literal=s,this.startCoordinates=o,this.endCoordinates=r};module.exports=d; -},{"./errors":"p8GN"}],"39eF":[function(require,module,exports) { -function t(t,n){for(var i=0;i"}}]),t}(),P=function t(n,i){h(this,t),this.keyword=n,this.value=i},C=function t(n,i){h(this,t),this.name=n,this.methods=i},k=function t(n,i,e){h(this,t),this.name=n,this.params=i,this.bodyStatements=e};module.exports={Var:p,Binary:c,Unary:f,Block:O,Call:_,Callable:x,While:w,Class:C,Get:y,Set:b,Literal:l,Return:P,Logical:a,LoxFunction:k,Grouping:m,Condition:j,ExpressionStatement:d,PrintStatement:g,VarStatement:v,Assignment:S}; -},{}],"CUYV":[function(require,module,exports) { -function e(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function t(e,t){for(var n=0;n2?i-2:0),s=2;s1?e-1:0),i=1;i")}}]),t}(),M=function(t){function n(t){var r;return o(this,n),(r=e(this,i(n).call(this))).name=t,r}return r(n,V),u(n,[{key:"call",value:function(){return new Q(this)}},{key:"toString",value:function(){return"<".concat(this.name,">")}}]),n}(),Q=function(){function t(e){o(this,t),this.klass=e,this.fields=new Map}return u(t,[{key:"get",value:function(t){var e=t.lexeme;if(this.fields.has(e))return this.fields.get(e);throw c("Undefined property ".concat(e),t)}},{key:"set",value:function(t,e){var n=t.lexeme;this.fields.set(n,e)}},{key:"toString",value:function(){return"<+".concat(this.klass.name,">")}}]),t}(),q=function(){function t(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:console.log;o(this,t),this.printfunction=n,this.environment=e||new G,this.environment.setBuiltin("PI",Math.PI),this.environment.setBuiltin("cos",function(t,e){return Math.cos(e[0])}),this.environment.setBuiltin("mod",function(t,e){return e[0]%e[1]}),this.environment.setBuiltin("strlen",function(t,e){return e[0].length}),this.environment.setBuiltin("charAt",function(t,e){return e[0][e[1]]}),this.environment.setBuiltin("clock",function(){return(new Date).getTime()})}return u(t,[{key:"interpret",value:function(t){return this.evaluate(t)}},{key:"evaluate",value:function(t){return t instanceof A?this.visitBlock(t):t instanceof L?this.visitFunction(t):t instanceof x?this.visitAssignment(t):t instanceof g?this.visitClass(t):t instanceof S?this.visitGet(t):t instanceof d?this.visitSet(t):t instanceof k?this.visitLogical(t):t instanceof m?this.visitCall(t):t instanceof E?this.visitWhile(t):t instanceof C?this.visitCondition(t):t instanceof U?this.visitVarStatement(t):t instanceof _?this.visitPrintStatement(t):t instanceof B?this.visitReturnStatement(t):t instanceof O?this.visitGrouping(t):t instanceof w?this.visitGrouping(t):t instanceof b?this.visitVar(t):t instanceof p?this.visitLiteral(t):t instanceof y?this.visitUnary(t):t instanceof h?this.visitBinary(t):void 0}},{key:"visitLiteral",value:function(t){return t.value}},{key:"visitGrouping",value:function(t){return this.evaluate(t.expression)}},{key:"visitPrintStatement",value:function(t){var e=this.evaluate(t.expression);return this.printfunction(null===e?"nil":e.toString()),e}},{key:"visitFunction",value:function(t){var e=new V(t,this.environment);this.environment.set(t.name,e)}},{key:"visitLogical",value:function(t){var e=this.evaluate(t.left);if(t.operator.type===R.OR){if(j(e))return e}else if(!j(e))return e;return this.evaluate(t.right)}},{key:"visitWhile",value:function(t){for(;j(this.evaluate(t.condition));)this.evaluate(t.body);return null}},{key:"visitReturnStatement",value:function(t){var e=null;throw t.value&&(e=this.evaluate(t.value)),new v(e)}},{key:"visitVar",value:function(t){return this.environment.get(t)}},{key:"visitVarStatement",value:function(t){var e=null;return null!==t.initializer&&(e=this.evaluate(t.initializer)),this.environment.set(t.name,e),null}},{key:"visitClass",value:function(t){this.environment.set(t.name,null);var e=new M(t.name.lexeme);return this.environment.assign(t.name,e),null}},{key:"visitGet",value:function(t){var e=this.evaluate(t.object);if(e instanceof Q)return e.get(t.name);throw c("Only instances have properties",t.name)}},{key:"visitSet",value:function(t){var e=this.evaluate(t.object);if(!(e instanceof Q))throw c("Only instances have fields",t.name);var n=this.evaluate(t.value);return e.set(t.name,n)}},{key:"visitBlock",value:function(t){return this.interpretBlock(t.statements,new G(this.environment)),null}},{key:"visitCondition",value:function(t){return j(this.evaluate(t.condition))?this.evaluate(t.thenBranch):t.elseBranch&&this.evaluate(t.elseBranch),null}},{key:"interpretBlock",value:function(t,e){var n=this.environment;try{this.environment=e;var i=!0,r=!1,a=void 0;try{for(var o,s=t[Symbol.iterator]();!(i=(o=s.next()).done);i=!0){var u=o.value;this.interpret(u)}}catch(l){r=!0,a=l}finally{try{i||null==s.return||s.return()}finally{if(r)throw a}}this.environment=n}catch(c){throw this.environment=n,c}}},{key:"visitAssignment",value:function(t){var e=this.evaluate(t.value);return this.environment.assign(t.name,e),e}},{key:"visitCall",value:function(t){var e=this,n=this.evaluate(t.callee),i=t.arguments.map(function(t){return e.evaluate(t)});if(!n.call)throw c("Can only call functions and classes",t.paren);return n.call(this,i)}},{key:"visitUnary",value:function(t){var e=this.evaluate(t.right);switch(t.operator.type){case R.MINUS:return T(t.operator,e),-e;case R.BANG:return!j(e)}}},{key:"visitBinary",value:function(t){var e=this.evaluate(t.left),n=this.evaluate(t.right);switch(t.operator.type){case R.MINUS:return T(t.operator,n,e),e-n;case R.PLUS:return e+n;case R.SLASH:return T(t.operator,n,e),e/n;case R.STAR:return T(t.operator,n,e),e*n;case R.GREATER:return T(t.operator,n,e),e>n;case R.GREATER_EQUAL:return T(t.operator,n,e),e>=n;case R.LESS:return T(t.operator,n,e),e3&&void 0!==arguments[3]&&arguments[3];try{var d=new e(o).scanTokens();l&&console.log(d);var c=new n(d).parse();l&&console.log(c);var u,v=new i(a,s),x=!0,f=!1,g=void 0;try{for(var C,p=c[Symbol.iterator]();!(x=(C=p.next()).done);x=!0){var h=C.value;u=v.interpret(h)}}catch(O){f=!0,g=O}finally{try{x||null==p.return||p.return()}finally{if(f)throw g}}return u}catch(S){if(console.log(S),S instanceof t){console.error("Parse Error:",S.toString(),"at ".concat(S.endCoordinates.line,":").concat(S.endCoordinates.col+1));var q=o.lastIndexOf("\n",S.startCoordinates.index),y=q<0?0:q,b=o.substr(y,S.startCoordinates.index),m=o.substr(S.startCoordinates.index,S.endCoordinates.index),w=o.indexOf("\n",S.endCoordinates.index),E=w<0?o.length:w,k=o.substr(S.endCoordinates.index,E);console.error(b+r.bgRed(m)+k)}else console.log("Unexpected javascript Error: "),console.log(S)}};module.exports={run:s,Environment:a}; -},{"chalk":"ug4C","./tokenizer":"u74b","./parser":"CUYV","./errors":"p8GN","./interpreter":"lmrS","./environment":"brut"}],"KVVd":[function(require,module,exports) { - -},{}],"3hpa":[function(require,module,exports) { -"use strict";var n=require("./index"),t=require("fs"),e="",r=document.getElementById("code"),i=['// Interactive Iterative Fibonacci\nvar a = 0;\nvar b = 1;\nvar limit = prompt("Limit to find fib numbers", 10000);\n\nwhile (a < limit) {\n print a;\n var temp = a;\n a = b;\n b = temp + b;\n}\n','// Linked List via Closures\nfun Link(value, next) {\n fun access(method) {\n if (method == "value") return value;\n if (method == "next") return next;\n print "unknown method " + method;\n }\n\n return access;\n}\n\nfun traverse(n, fn) {\n fn(n);\n if (n("next") != nil) {\n return traverse(n("next"), fn);\n }\n return n;\n}\n\nfun printValue (n) {\n print n("value");\n}\n\nfun blank (n) {}\n\nfun printTail (n) {\n var tail = traverse(n, blank);\n print tail("value");\n}\n\nvar list = Link(1, Link(2, Link(3, nil)));\n\ntraverse(list, printValue);\nprintTail(list, printTail);'],a=i.map(function(n){return{name:n.split("\n")[0].replace(/[^\w\s]/gi,"").trim(),program:n}}),u=document.getElementById("exampleProgram"),o=a.map(function(n,t){return'")}).join("\n");u.innerHTML=o,u.onchange=function(n){var t=n.target.value;r.value=a[t].program};var l=0;window.location.hash&&(l=+window.location.hash.replace(/[^\w\s]/gi,"").trim()),r.value=a[l].program;var m=function(n){e+=n+"\n",console.log(n),document.getElementById("output").value=e},c=document.getElementById("run");c.onclick=function(){var t=r.value,i=new n.Environment;i.setBuiltin("alert",function(n,t){return alert(t[0])}),i.setBuiltin("confirm",function(n,t){return confirm(t[0])}),i.setBuiltin("prompt",function(n,t){return prompt(t[0],t.length>1?t[1]:null)}),e="",(0,n.run)(t,i,m)}; -},{"./index":"Focm","fs":"KVVd"}]},{},["3hpa"], null) \ No newline at end of file diff --git a/docs/browser.5d1cf53e.js b/docs/browser.5d1cf53e.js deleted file mode 100644 index 6263f88..0000000 --- a/docs/browser.5d1cf53e.js +++ /dev/null @@ -1,21 +0,0 @@ -parcelRequire=function(e,r,t,n){var i,o="function"==typeof parcelRequire&&parcelRequire,u="function"==typeof require&&require;function f(t,n){if(!r[t]){if(!e[t]){var i="function"==typeof parcelRequire&&parcelRequire;if(!n&&i)return i(t,!0);if(o)return o(t,!0);if(u&&"string"==typeof t)return u(t);var c=new Error("Cannot find module '"+t+"'");throw c.code="MODULE_NOT_FOUND",c}p.resolve=function(r){return e[t][1][r]||r},p.cache={};var l=r[t]=new f.Module(t);e[t][0].call(l.exports,p,l,l.exports,this)}return r[t].exports;function p(e){return f(p.resolve(e))}}f.isParcelRequire=!0,f.Module=function(e){this.id=e,this.bundle=f,this.exports={}},f.modules=e,f.cache=r,f.parent=o,f.register=function(r,t){e[r]=[function(e,r){r.exports=t},{}]};for(var c=0;c":function(t){t.addToken(t.nextMatch("=")?h.GREATER_EQUAL:h.GREATER)},"<":function(t){t.addToken(t.nextMatch("=")?h.LESS_EQUAL:h.LESS)}," ":r,"\t":r,"\r":r,"\n":function(t){t.newline()},'"':function(t){t.handleStringLiterals()}},a=function(t){return/\d/.test(t)},l=function(t){return/[a-zA-Z_]/.test(t)},f=function(t){return l(t)||a(t)},d=function(){function n(e){t(this,n),this.source=e,this.length=e.length,this.tokens=[],this.startPosition=null,this.column=0,this.start=0,this.line=1,this.current=0}return e(n,null,[{key:"tokens",get:function(){return o}},{key:"tokenEnum",get:function(){return h}}]),e(n,[{key:"handleStringLiterals",value:function(){for(;'"'!==this.peek()&&""!==this.peek();)"\n"===this.peek()&&this.newline(),this.chomp();if(""===this.peek())throw new s("Unfinished string",this.startPosition,this.endPosition);this.chomp();var t=this.source.substring(this.start+1,this.current-1);this.addToken(h.STRING,t)}},{key:"handleNumberLiterals",value:function(){for(var t=!1;a(this.peek())||!t&&"."===this.peek();)"."===this.peek()&&(t=!0),this.chomp();var n=this.source.substring(this.start,this.current);this.addToken(h.NUMBER,parseFloat(n))}},{key:"handleIdentifiers",value:function(){for(;f(this.peek());)this.chomp();var t=this.source.substring(this.start,this.current);u[t]?this.addToken(u[t],t):this.addToken(h.IDENTIFIER,t)}},{key:"scanTokens",value:function(){for(;this.current1&&void 0!==arguments[1]?arguments[1]:null,e=this.source.substring(this.start,this.current);this.tokens.push(new k(t,e,n,new E(this.column,this.line,this.current),this.startPosition))}},{key:"increment",value:function(){this.current++,this.column++}},{key:"newline",value:function(){this.line++,this.column=0}},{key:"chomp",value:function(){return this.increment(),this.source.charAt(this.current-1)}},{key:"peek",value:function(){return this.source.charAt(this.current)}},{key:"nextMatch",value:function(t){return this.peek()===t&&(this.increment(),!0)}},{key:"endPosition",get:function(){return new E(this.column-1,this.line,this.current)}}]),n}(),E=function n(e,i,s){t(this,n),this.col=e,this.line=i,this.index=s},k=function n(e,i,s,r,o){t(this,n),this.type=e,this.lexeme=i,this.literal=s,this.startCoordinates=o,this.endCoordinates=r};module.exports=d; -},{"./errors":"p8GN"}],"39eF":[function(require,module,exports) { -function t(n){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(n)}function n(n,e){return!e||"object"!==t(e)&&"function"!=typeof e?i(n):e}function i(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function e(t){return(e=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function o(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(n&&n.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),n&&r(t,n)}function r(t,n){return(r=Object.setPrototypeOf||function(t,n){return t.__proto__=n,t})(t,n)}function s(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}var h=function t(n,i,e){s(this,t),this.left=n,this.operator=i,this.right=e},u=function(t){function i(){return s(this,i),n(this,e(i).apply(this,arguments))}return o(i,h),i}(),c=function t(n,i){s(this,t),this.operator=n,this.right=i},a=function t(n){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"regular";s(this,t),this.context=i,this.value=n},f=function t(n){s(this,t),this.name=n},l=function t(n,i){s(this,t),this.object=n,this.name=i},p=function t(n,i,e){s(this,t),this.object=n,this.name=i,this.value=e},y=function t(n){s(this,t),this.expression=n},m=function(t){function i(t){var o,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"regular";return s(this,i),(o=n(this,e(i).call(this,t))).context=r,o}return o(i,y),i}(),b=function(t){function i(){return s(this,i),n(this,e(i).apply(this,arguments))}return o(i,y),i}(),g=function t(n,i){s(this,t),this.name=n,this.initializer=i},d=function t(n,i){s(this,t),this.name=n,this.value=i},v=function t(n){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"regular";s(this,t),this.context=i,this.statements=n},S=function t(n,i,e){s(this,t),this.condition=n,this.thenBranch=i,this.elseBranch=e},w=function t(n,i){var e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"while";s(this,t),this.context=e,this.condition=n,this.body=i},x=function t(n,i,e){s(this,t),this.callee=n,this.paren=i,this.arguments=e},O=function t(n,i){s(this,t),this.keyword=n,this.value=i},j=function t(n,i){s(this,t),this.name=n,this.methods=i},_=function t(n,i,e){s(this,t),this.name=n,this.params=i,this.bodyStatements=e};module.exports={Var:f,Binary:h,Unary:c,Block:v,Call:x,While:w,Class:j,Get:l,Set:p,Literal:a,Return:O,Logical:u,LoxFunction:_,Grouping:y,Condition:S,ExpressionStatement:m,PrintStatement:b,VarStatement:g,Assignment:d}; -},{}],"CUYV":[function(require,module,exports) { -function e(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function t(e,t){for(var n=0;n2?i-2:0),s=2;s1?e-1:0),i=1;i")}}]),t}(),M=function(t){function n(t){var r;return o(this,n),(r=e(this,i(n).call(this))).name=t,r}return r(n,V),u(n,[{key:"call",value:function(){return new Q(this)}},{key:"toString",value:function(){return"<".concat(this.name,">")}}]),n}(),Q=function(){function t(e){o(this,t),this.klass=e,this.fields=new Map}return u(t,[{key:"get",value:function(t){var e=t.lexeme;if(this.fields.has(e))return this.fields.get(e);throw c("Undefined property ".concat(e),t)}},{key:"set",value:function(t,e){var n=t.lexeme;this.fields.set(n,e)}},{key:"toString",value:function(){return"<+".concat(this.klass.name,">")}}]),t}(),q=function(){function t(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:console.log;o(this,t),this.printfunction=n,this.environment=e||new G,this.environment.setBuiltin("PI",Math.PI),this.environment.setBuiltin("cos",function(t,e){return Math.cos(e[0])}),this.environment.setBuiltin("mod",function(t,e){return e[0]%e[1]}),this.environment.setBuiltin("strlen",function(t,e){return e[0].length}),this.environment.setBuiltin("charAt",function(t,e){return e[0][e[1]]}),this.environment.setBuiltin("clock",function(){return(new Date).getTime()})}return u(t,[{key:"interpret",value:function(t){return this.evaluate(t)}},{key:"evaluate",value:function(t){return t instanceof A?this.visitBlock(t):t instanceof L?this.visitFunction(t):t instanceof x?this.visitAssignment(t):t instanceof g?this.visitClass(t):t instanceof S?this.visitGet(t):t instanceof d?this.visitSet(t):t instanceof k?this.visitLogical(t):t instanceof m?this.visitCall(t):t instanceof E?this.visitWhile(t):t instanceof C?this.visitCondition(t):t instanceof U?this.visitVarStatement(t):t instanceof _?this.visitPrintStatement(t):t instanceof B?this.visitReturnStatement(t):t instanceof O?this.visitGrouping(t):t instanceof w?this.visitGrouping(t):t instanceof b?this.visitVar(t):t instanceof p?this.visitLiteral(t):t instanceof y?this.visitUnary(t):t instanceof h?this.visitBinary(t):void 0}},{key:"visitLiteral",value:function(t){return t.value}},{key:"visitGrouping",value:function(t){return this.evaluate(t.expression)}},{key:"visitPrintStatement",value:function(t){var e=this.evaluate(t.expression);return this.printfunction(null===e?"nil":e.toString()),e}},{key:"visitFunction",value:function(t){var e=new V(t,this.environment);this.environment.set(t.name,e)}},{key:"visitLogical",value:function(t){var e=this.evaluate(t.left);if(t.operator.type===R.OR){if(j(e))return e}else if(!j(e))return e;return this.evaluate(t.right)}},{key:"visitWhile",value:function(t){for(;j(this.evaluate(t.condition));)this.evaluate(t.body);return null}},{key:"visitReturnStatement",value:function(t){var e=null;throw t.value&&(e=this.evaluate(t.value)),new v(e)}},{key:"visitVar",value:function(t){return this.environment.get(t)}},{key:"visitVarStatement",value:function(t){var e=null;return null!==t.initializer&&(e=this.evaluate(t.initializer)),this.environment.set(t.name,e),null}},{key:"visitClass",value:function(t){this.environment.set(t.name,null);var e=new M(t.name.lexeme);return this.environment.assign(t.name,e),null}},{key:"visitGet",value:function(t){var e=this.evaluate(t.object);if(e instanceof Q)return e.get(t.name);throw c("Only instances have properties",t.name)}},{key:"visitSet",value:function(t){var e=this.evaluate(t.object);if(!(e instanceof Q))throw c("Only instances have fields",t.name);var n=this.evaluate(t.value);return e.set(t.name,n)}},{key:"visitBlock",value:function(t){return this.interpretBlock(t.statements,new G(this.environment)),null}},{key:"visitCondition",value:function(t){return j(this.evaluate(t.condition))?this.evaluate(t.thenBranch):t.elseBranch&&this.evaluate(t.elseBranch),null}},{key:"interpretBlock",value:function(t,e){var n=this.environment;try{this.environment=e;var i=!0,r=!1,a=void 0;try{for(var o,s=t[Symbol.iterator]();!(i=(o=s.next()).done);i=!0){var u=o.value;this.interpret(u)}}catch(l){r=!0,a=l}finally{try{i||null==s.return||s.return()}finally{if(r)throw a}}this.environment=n}catch(c){throw this.environment=n,c}}},{key:"visitAssignment",value:function(t){var e=this.evaluate(t.value);return this.environment.assign(t.name,e),e}},{key:"visitCall",value:function(t){var e=this,n=this.evaluate(t.callee),i=t.arguments.map(function(t){return e.evaluate(t)});if(!n.call)throw c("Can only call functions and classes",t.paren);return n.call(this,i)}},{key:"visitUnary",value:function(t){var e=this.evaluate(t.right);switch(t.operator.type){case R.MINUS:return T(t.operator,e),-e;case R.BANG:return!j(e)}}},{key:"visitBinary",value:function(t){var e=this.evaluate(t.left),n=this.evaluate(t.right);switch(t.operator.type){case R.MINUS:return T(t.operator,n,e),e-n;case R.PLUS:return e+n;case R.SLASH:return T(t.operator,n,e),e/n;case R.STAR:return T(t.operator,n,e),e*n;case R.GREATER:return T(t.operator,n,e),e>n;case R.GREATER_EQUAL:return T(t.operator,n,e),e>=n;case R.LESS:return T(t.operator,n,e),e3&&void 0!==arguments[3]&&arguments[3],l=new r(o).scanTokens();i&&console.log(l);var u=new e(l).parse();i&&console.log(u);var v,s=new n(t,a),c=!0,p=!1,f=void 0;try{for(var w,y=u[Symbol.iterator]();!(c=(w=y.next()).done);c=!0){var d=w.value;v=s.interpret(d)}}catch(m){p=!0,f=m}finally{try{c||null==y.return||y.return()}finally{if(p)throw f}}return v},a=function(n){var o=new r(n).scanTokens();return new e(o).parse()};module.exports={run:t,parse:a,Environment:o}; -},{"./tokenizer":"u74b","./parser":"CUYV","./interpreter":"lmrS","./environment":"brut"}],"9/6S":[function(require,module,exports) { -function n(n){return r(n)||e(n)||t()}function t(){throw new TypeError("Invalid attempt to spread non-iterable instance")}function e(n){if(Symbol.iterator in Object(n)||"[object Arguments]"===Object.prototype.toString.call(n))return Array.from(n)}function r(n){if(Array.isArray(n)){for(var t=0,e=new Array(n.length);t3&&void 0!==arguments[3]?arguments[3]:";",i="forLoop"!==o.context?z(o):"",c="",u=r;if(r instanceof L&&"forLoop"===r.context){var s=r.statements;u=s[0],s.length>1&&(c=z(s[s.length-1],t,e,!1))}var f=z(u,t,e,!1),l=[i,c];return"for (".concat(a," ").concat(l.join("; "),") ").concat(f)};w.set(f,function(n,t,e){return"forLoop"===n.context?B(n,t,e):A(n,t,e)});var C=function(n,t,e){var r=n.statements,o=z(r[0],t,e,!1);return B(r[1],t,e,o)},E=function(n,t,e){return"{\n"+n.statements.map(function(n){return z(n,t+1)}).join("\n")+"\n".concat(e.indent.repeat(t),"}")};w.set(L,function(n,t,e){return"forLoop"===n.context?C(n,t,e):E(n,t,e)}),w.set(c,function(n){return n.name.lexeme}),w.set(v,function(n){var t=n.expression;return"("+z(t)+")"});var O=function(n){return[z(n.left),n.operator.lexeme,z(n.right)].join(" ")};w.set(a,O),w.set(b,O),w.set(i,function(n){return n.operator.lexeme+z(n.right)}),w.set(u,function(n){var t=n.arguments.map(function(n){return z(n)}).join(", "),e=z(n.callee);return"".concat(e,"(").concat(t,")")}),w.set(j,function(n){return n.name.lexeme+" = "+z(n.value)}),w.set(s,function(n){var t=n.value;return"string"==typeof t?'"'.concat(t,'"'):null===t?"nil":t});var z=function(n){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],o=Object.assign({},{indent:"\t",spaceBeforeParams:!0},e);if(w.has(n.constructor))return(r?o.indent.repeat(t):"")+w.get(n.constructor)(n,t,o);throw new Error("Don't support that context yet",n.constructor)};module.exports={printLoxAST:z}; -},{"../types":"39eF"}],"KVVd":[function(require,module,exports) { - -},{}],"3hpa":[function(require,module,exports) { -"use strict";var n=require("./index"),e=require("./errors"),r=require("./transpilers/lox"),t=require("fs"),a="",i=document.getElementById("code"),o=['// Interactive Iterative Fibonacci\nvar a = 0;\nvar b = 1;\nvar limit = prompt("Limit to find fib numbers", 10000);\n\nwhile (a < limit) {\n print a;\n var temp = a;\n a = b;\n b = temp + b;\n}\n','// Linked List via Closures\nfun Link(value, next) {\n fun access(method) {\n if (method == "value") return value;\n if (method == "next") return next;\n print "unknown method " + method;\n }\n\n return access;\n}\n\nfun traverse(n, fn) {\n fn(n);\n if (n("next") != nil) {\n return traverse(n("next"), fn);\n }\n return n;\n}\n\nfun printValue (n) {\n print n("value");\n}\n\nfun blank (n) {}\n\nfun printTail (n) {\n var tail = traverse(n, blank);\n print tail("value");\n}\n\nvar list = Link(1, Link(2, Link(3, nil)));\n\ntraverse(list, printValue);\nprintTail(list, printTail);','// Kitchen Sink\nfun hello (arg1, arg2) {\n fun secondHi (helloer) {\n print helloer + " says hello";\n }\n var str = arg1 + " says hello to " + arg2;\n var maxAge = 18;\n var age;\n age = maxAge + 3;\n if (age < 21) {\n alert("Too young");\n while(age < 21) {\n age = age + 1;\n }\n } else {\n print "come on in";\n }\n for (var i = 0; i < 18; i = i + 1) {\n print i;\n }\n return age or maxAge;\n}\n\n\nprint "hello source: ";\nprint printFunctionBody(hello);\n\n// hello("boss", "man");','// Class Example\nclass Lox {\n breakfast() {\n print "Toast";\n }\n}\n\nfun hello () {\n print "Would you like some breakfast?";\n}\n\nprint Lox;\n\nprint hello;\nvar loxInstance = Lox();\n\nloxInstance.category = "Breakfast";\nprint loxInstance.category;\n\nprint Lox();\n\nreadFile("./examples/classExample.lox");\n\n// class Bagel {}\n// var bagel = Bagel();\n// print bagel; // Prints "Bagel instance".\n// print bagel.lox;'],l=o.map(function(n){return{name:n.split("\n")[0].replace(/[^\w\s]/gi,"").trim(),program:n}}),u=function(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";if(!n)return document.getElementById("error").style.display="none",null;console.error(n);var t=(0,e.formatLoxError)(n,r),a=t.oneLiner,i=t.preErrorSection,o=t.errorSection,l=t.postErrorSection,u=a;o&&(u+="
",u+="".concat(i,'').concat(o,"").concat(l)),document.getElementById("error").style.display="",document.getElementById("errorText").innerHTML=u},c=document.getElementById("exampleProgram"),s=l.map(function(n,e){return'")}).join("\n");c.innerHTML=s,c.onchange=function(n){var e=n.target.value;i.value=l[e].program};var p=0;window.location.hash&&(p=+window.location.hash.replace(/[^\w\s]/gi,"").trim()),i.value=l[p].program;var m=function(n){a+=n+"\n",console.log(n),document.getElementById("output").value=a},g=document.getElementById("run");g.onclick=function(){var e=i.value,t=new n.Environment;t.setBuiltin("alert",function(n,e){return alert(e[0])}),t.setBuiltin("printFunctionBody",function(n,e){var t=e[0];if(t&&!t.declaration)throw new Error("Argument is not a lox function");return(0,r.printLoxAST)(t.declaration)}),t.setBuiltin("confirm",function(n,e){return confirm(e[0])}),t.setBuiltin("prompt",function(n,e){return prompt(e[0],e.length>1?e[1]:null)}),a="";try{(0,n.run)(e,t,m),u(null)}catch(o){u(o,e)}};var v=document.getElementById("format");v.onclick=function(){i.value=(0,n.parse)(i.value).map(function(n){return(0,r.printLoxAST)(n)}).join("\n")}; -},{"./index":"Focm","./errors":"p8GN","./transpilers/lox":"9/6S","fs":"KVVd"}]},{},["3hpa"], null) \ No newline at end of file diff --git a/docs/browser.5da0a6dc.js b/docs/browser.5da0a6dc.js deleted file mode 100644 index 220fde6..0000000 --- a/docs/browser.5da0a6dc.js +++ /dev/null @@ -1,41 +0,0 @@ -parcelRequire=function(e,r,t,n){var i,o="function"==typeof parcelRequire&&parcelRequire,u="function"==typeof require&&require;function f(t,n){if(!r[t]){if(!e[t]){var i="function"==typeof parcelRequire&&parcelRequire;if(!n&&i)return i(t,!0);if(o)return o(t,!0);if(u&&"string"==typeof t)return u(t);var c=new Error("Cannot find module '"+t+"'");throw c.code="MODULE_NOT_FOUND",c}p.resolve=function(r){return e[t][1][r]||r},p.cache={};var l=r[t]=new f.Module(t);e[t][0].call(l.exports,p,l,l.exports,this)}return r[t].exports;function p(e){return f(p.resolve(e))}}f.isParcelRequire=!0,f.Module=function(e){this.id=e,this.bundle=f,this.exports={}},f.modules=e,f.cache=r,f.parent=o,f.register=function(r,t){e[r]=[function(e,r){r.exports=t},{}]};for(var c=0;c1&&(e-=1)),[360*e,100*h,100*s]},t.rgb.hwb=function(r){var n=r[0],a=r[1],e=r[2];return[t.rgb.hsl(r)[0],100*(1/255*Math.min(n,Math.min(a,e))),100*(e=1-1/255*Math.max(n,Math.max(a,e)))]},t.rgb.cmyk=function(r){var n,a=r[0]/255,t=r[1]/255,e=r[2]/255;return[100*((1-a-(n=Math.min(1-a,1-t,1-e)))/(1-n)||0),100*((1-t-n)/(1-n)||0),100*((1-e-n)/(1-n)||0),100*n]},t.rgb.keyword=function(a){var t=n[a];if(t)return t;var e,h=1/0;for(var u in r)if(r.hasOwnProperty(u)){var c=o(a,r[u]);c.04045?Math.pow((n+.055)/1.055,2.4):n/12.92)+.3576*(a=a>.04045?Math.pow((a+.055)/1.055,2.4):a/12.92)+.1805*(t=t>.04045?Math.pow((t+.055)/1.055,2.4):t/12.92)),100*(.2126*n+.7152*a+.0722*t),100*(.0193*n+.1192*a+.9505*t)]},t.rgb.lab=function(r){var n=t.rgb.xyz(r),a=n[0],e=n[1],h=n[2];return e/=100,h/=108.883,a=(a/=95.047)>.008856?Math.pow(a,1/3):7.787*a+16/116,[116*(e=e>.008856?Math.pow(e,1/3):7.787*e+16/116)-16,500*(a-e),200*(e-(h=h>.008856?Math.pow(h,1/3):7.787*h+16/116))]},t.hsl.rgb=function(r){var n,a,t,e,h,u=r[0]/360,o=r[1]/100,c=r[2]/100;if(0===o)return[h=255*c,h,h];n=2*c-(a=c<.5?c*(1+o):c+o-c*o),e=[0,0,0];for(var s=0;s<3;s++)(t=u+1/3*-(s-1))<0&&t++,t>1&&t--,h=6*t<1?n+6*(a-n)*t:2*t<1?a:3*t<2?n+(a-n)*(2/3-t)*6:n,e[s]=255*h;return e},t.hsl.hsv=function(r){var n=r[0],a=r[1]/100,t=r[2]/100,e=a,h=Math.max(t,.01);return a*=(t*=2)<=1?t:2-t,e*=h<=1?h:2-h,[n,100*(0===t?2*e/(h+e):2*a/(t+a)),100*((t+a)/2)]},t.hsv.rgb=function(r){var n=r[0]/60,a=r[1]/100,t=r[2]/100,e=Math.floor(n)%6,h=n-Math.floor(n),u=255*t*(1-a),o=255*t*(1-a*h),c=255*t*(1-a*(1-h));switch(t*=255,e){case 0:return[t,c,u];case 1:return[o,t,u];case 2:return[u,t,c];case 3:return[u,o,t];case 4:return[c,u,t];case 5:return[t,u,o]}},t.hsv.hsl=function(r){var n,a,t,e=r[0],h=r[1]/100,u=r[2]/100,o=Math.max(u,.01);return t=(2-h)*u,a=h*o,[e,100*(a=(a/=(n=(2-h)*o)<=1?n:2-n)||0),100*(t/=2)]},t.hwb.rgb=function(r){var n,a,t,e,h,u,o,c=r[0]/360,s=r[1]/100,l=r[2]/100,i=s+l;switch(i>1&&(s/=i,l/=i),t=6*c-(n=Math.floor(6*c)),0!=(1&n)&&(t=1-t),e=s+t*((a=1-l)-s),n){default:case 6:case 0:h=a,u=e,o=s;break;case 1:h=e,u=a,o=s;break;case 2:h=s,u=a,o=e;break;case 3:h=s,u=e,o=a;break;case 4:h=e,u=s,o=a;break;case 5:h=a,u=s,o=e}return[255*h,255*u,255*o]},t.cmyk.rgb=function(r){var n=r[0]/100,a=r[1]/100,t=r[2]/100,e=r[3]/100;return[255*(1-Math.min(1,n*(1-e)+e)),255*(1-Math.min(1,a*(1-e)+e)),255*(1-Math.min(1,t*(1-e)+e))]},t.xyz.rgb=function(r){var n,a,t,e=r[0]/100,h=r[1]/100,u=r[2]/100;return a=-.9689*e+1.8758*h+.0415*u,t=.0557*e+-.204*h+1.057*u,n=(n=3.2406*e+-1.5372*h+-.4986*u)>.0031308?1.055*Math.pow(n,1/2.4)-.055:12.92*n,a=a>.0031308?1.055*Math.pow(a,1/2.4)-.055:12.92*a,t=t>.0031308?1.055*Math.pow(t,1/2.4)-.055:12.92*t,[255*(n=Math.min(Math.max(0,n),1)),255*(a=Math.min(Math.max(0,a),1)),255*(t=Math.min(Math.max(0,t),1))]},t.xyz.lab=function(r){var n=r[0],a=r[1],t=r[2];return a/=100,t/=108.883,n=(n/=95.047)>.008856?Math.pow(n,1/3):7.787*n+16/116,[116*(a=a>.008856?Math.pow(a,1/3):7.787*a+16/116)-16,500*(n-a),200*(a-(t=t>.008856?Math.pow(t,1/3):7.787*t+16/116))]},t.lab.xyz=function(r){var n,a,t,e=r[0];n=r[1]/500+(a=(e+16)/116),t=a-r[2]/200;var h=Math.pow(a,3),u=Math.pow(n,3),o=Math.pow(t,3);return a=h>.008856?h:(a-16/116)/7.787,n=u>.008856?u:(n-16/116)/7.787,t=o>.008856?o:(t-16/116)/7.787,[n*=95.047,a*=100,t*=108.883]},t.lab.lch=function(r){var n,a=r[0],t=r[1],e=r[2];return(n=360*Math.atan2(e,t)/2/Math.PI)<0&&(n+=360),[a,Math.sqrt(t*t+e*e),n]},t.lch.lab=function(r){var n,a=r[0],t=r[1];return n=r[2]/360*2*Math.PI,[a,t*Math.cos(n),t*Math.sin(n)]},t.rgb.ansi16=function(r){var n=r[0],a=r[1],e=r[2],h=1 in arguments?arguments[1]:t.rgb.hsv(r)[2];if(0===(h=Math.round(h/50)))return 30;var u=30+(Math.round(e/255)<<2|Math.round(a/255)<<1|Math.round(n/255));return 2===h&&(u+=60),u},t.hsv.ansi16=function(r){return t.rgb.ansi16(t.hsv.rgb(r),r[2])},t.rgb.ansi256=function(r){var n=r[0],a=r[1],t=r[2];return n===a&&a===t?n<8?16:n>248?231:Math.round((n-8)/247*24)+232:16+36*Math.round(n/255*5)+6*Math.round(a/255*5)+Math.round(t/255*5)},t.ansi16.rgb=function(r){var n=r%10;if(0===n||7===n)return r>50&&(n+=3.5),[n=n/10.5*255,n,n];var a=.5*(1+~~(r>50));return[(1&n)*a*255,(n>>1&1)*a*255,(n>>2&1)*a*255]},t.ansi256.rgb=function(r){if(r>=232){var n=10*(r-232)+8;return[n,n,n]}var a;return r-=16,[Math.floor(r/36)/5*255,Math.floor((a=r%36)/6)/5*255,a%6/5*255]},t.rgb.hex=function(r){var n=(((255&Math.round(r[0]))<<16)+((255&Math.round(r[1]))<<8)+(255&Math.round(r[2]))).toString(16).toUpperCase();return"000000".substring(n.length)+n},t.hex.rgb=function(r){var n=r.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);if(!n)return[0,0,0];var a=n[0];3===n[0].length&&(a=a.split("").map(function(r){return r+r}).join(""));var t=parseInt(a,16);return[t>>16&255,t>>8&255,255&t]},t.rgb.hcg=function(r){var n,a=r[0]/255,t=r[1]/255,e=r[2]/255,h=Math.max(Math.max(a,t),e),u=Math.min(Math.min(a,t),e),o=h-u;return n=o<=0?0:h===a?(t-e)/o%6:h===t?2+(e-a)/o:4+(a-t)/o+4,n/=6,[360*(n%=1),100*o,100*(o<1?u/(1-o):0)]},t.hsl.hcg=function(r){var n=r[1]/100,a=r[2]/100,t=1,e=0;return(t=a<.5?2*n*a:2*n*(1-a))<1&&(e=(a-.5*t)/(1-t)),[r[0],100*t,100*e]},t.hsv.hcg=function(r){var n=r[1]/100,a=r[2]/100,t=n*a,e=0;return t<1&&(e=(a-t)/(1-t)),[r[0],100*t,100*e]},t.hcg.rgb=function(r){var n=r[0]/360,a=r[1]/100,t=r[2]/100;if(0===a)return[255*t,255*t,255*t];var e,h=[0,0,0],u=n%1*6,o=u%1,c=1-o;switch(Math.floor(u)){case 0:h[0]=1,h[1]=o,h[2]=0;break;case 1:h[0]=c,h[1]=1,h[2]=0;break;case 2:h[0]=0,h[1]=1,h[2]=o;break;case 3:h[0]=0,h[1]=c,h[2]=1;break;case 4:h[0]=o,h[1]=0,h[2]=1;break;default:h[0]=1,h[1]=0,h[2]=c}return e=(1-a)*t,[255*(a*h[0]+e),255*(a*h[1]+e),255*(a*h[2]+e)]},t.hcg.hsv=function(r){var n=r[1]/100,a=n+r[2]/100*(1-n),t=0;return a>0&&(t=n/a),[r[0],100*t,100*a]},t.hcg.hsl=function(r){var n=r[1]/100,a=r[2]/100*(1-n)+.5*n,t=0;return a>0&&a<.5?t=n/(2*a):a>=.5&&a<1&&(t=n/(2*(1-a))),[r[0],100*t,100*a]},t.hcg.hwb=function(r){var n=r[1]/100,a=n+r[2]/100*(1-n);return[r[0],100*(a-n),100*(1-a)]},t.hwb.hcg=function(r){var n=r[1]/100,a=1-r[2]/100,t=a-n,e=0;return t<1&&(e=(a-t)/(1-t)),[r[0],100*t,100*e]},t.apple.rgb=function(r){return[r[0]/65535*255,r[1]/65535*255,r[2]/65535*255]},t.rgb.apple=function(r){return[r[0]/255*65535,r[1]/255*65535,r[2]/255*65535]},t.gray.rgb=function(r){return[r[0]/100*255,r[0]/100*255,r[0]/100*255]},t.gray.hsl=t.gray.hsv=function(r){return[0,0,r[0]]},t.gray.hwb=function(r){return[0,100,r[0]]},t.gray.cmyk=function(r){return[0,0,0,r[0]]},t.gray.lab=function(r){return[r[0],0,0]},t.gray.hex=function(r){var n=255&Math.round(r[0]/100*255),a=((n<<16)+(n<<8)+n).toString(16).toUpperCase();return"000000".substring(a.length)+a},t.rgb.gray=function(r){return[(r[0]+r[1]+r[2])/3/255*100]}; -},{"color-name":"auEH"}],"fg2k":[function(require,module,exports) { -var n=require("./conversions");function r(){for(var r={},e=Object.keys(n),t=e.length,a=0;a1&&(n=Array.prototype.slice.call(arguments)),e(n))};return"conversion"in e&&(n.conversion=e.conversion),n}function c(e){var n=function(n){if(null==n)return n;arguments.length>1&&(n=Array.prototype.slice.call(arguments));var r=e(n);if("object"==typeof r)for(var o=r.length,t=0;t(function(){const t=o.apply(n,arguments);return"[".concat(t+e,"m")}),t=(o,e)=>(function(){const t=o.apply(n,arguments);return"[".concat(38+e,";5;").concat(t,"m")}),r=(o,e)=>(function(){const t=o.apply(n,arguments);return"[".concat(38+e,";2;").concat(t[0],";").concat(t[1],";").concat(t[2],"m")});function i(){const i=new Map,c={modifier:{reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],inverse:[7,27],hidden:[8,28],strikethrough:[9,29]},color:{black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],gray:[90,39],redBright:[91,39],greenBright:[92,39],yellowBright:[93,39],blueBright:[94,39],magentaBright:[95,39],cyanBright:[96,39],whiteBright:[97,39]},bgColor:{bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],bgBlackBright:[100,49],bgRedBright:[101,49],bgGreenBright:[102,49],bgYellowBright:[103,49],bgBlueBright:[104,49],bgMagentaBright:[105,49],bgCyanBright:[106,49],bgWhiteBright:[107,49]}};c.color.grey=c.color.gray;for(const o of Object.keys(c)){const n=c[o];for(const o of Object.keys(n)){const e=n[o];c[o]={open:"[".concat(e[0],"m"),close:"[".concat(e[1],"m")},n[o]=c[o],i.set(e[0],e[1])}Object.defineProperty(c,o,{value:n,enumerable:!1}),Object.defineProperty(c,"codes",{value:i,enumerable:!1})}const a=o=>o,l=(o,n,e)=>[o,n,e];c.color.close="",c.bgColor.close="",c.color.ansi={ansi:e(a,0)},c.color.ansi256={ansi256:t(a,0)},c.color.ansi16m={rgb:r(l,0)},c.bgColor.ansi={ansi:e(a,10)},c.bgColor.ansi256={ansi256:t(a,10)},c.bgColor.ansi16m={rgb:r(l,10)};for(let g of Object.keys(n)){if("object"!==o(n[g]))continue;const i=n[g];"ansi16"===g&&(g="ansi"),"ansi16"in i&&(c.color.ansi[g]=e(i.ansi16,0),c.bgColor.ansi[g]=e(i.ansi16,10)),"ansi256"in i&&(c.color.ansi256[g]=t(i.ansi256,0),c.bgColor.ansi256[g]=t(i.ansi256,10)),"rgb"in i&&(c.color.ansi16m[g]=r(i.rgb,0),c.bgColor.ansi16m[g]=r(i.rgb,10))}return c}Object.defineProperty(module,"exports",{enumerable:!0,get:i}); -},{"color-convert":"PawV"}],"foIL":[function(require,module,exports) { -"use strict";module.exports={stdout:!1,stderr:!1}; -},{}],"PLSQ":[function(require,module,exports) { -"use strict";const t=/(?:\\(u[a-f\d]{4}|x[a-f\d]{2}|.))|(?:\{(~)?(\w+(?:\([^)]*\))?(?:\.\w+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n)))|(\})|((?:.|[\r\n\f])+?)/gi,e=/(?:^|\.)(\w+)(?:\(([^)]*)\))?/g,n=/^(['"])((?:\\.|(?!\1)[^\\])*)\1$/,r=/\\(u[a-f\d]{4}|x[a-f\d]{2}|.)|([^\\])/gi,s=new Map([["n","\n"],["r","\r"],["t","\t"],["b","\b"],["f","\f"],["v","\v"],["0","\0"],["\\","\\"],["e",""],["a",""]]);function o(t){return"u"===t[0]&&5===t.length||"x"===t[0]&&3===t.length?String.fromCharCode(parseInt(t.slice(1),16)):s.get(t)||t}function l(t,e){const s=[],l=e.trim().split(/\s*,\s*/g);let i;for(const c of l)if(isNaN(c)){if(!(i=c.match(n)))throw new Error("Invalid Chalk template style argument: ".concat(c," (in style '").concat(t,"')"));s.push(i[2].replace(r,(t,e,n)=>e?o(e):n))}else s.push(Number(c));return s}function i(t){e.lastIndex=0;const n=[];let r;for(;null!==(r=e.exec(t));){const t=r[1];if(r[2]){const e=l(t,r[2]);n.push([t].concat(e))}else n.push([t])}return n}function c(t,e){const n={};for(const s of e)for(const t of s.styles)n[t[0]]=s.inverse?null:t.slice(1);let r=t;for(const s of Object.keys(n))if(Array.isArray(n[s])){if(!(s in r))throw new Error("Unknown Chalk style: ".concat(s));r=n[s].length>0?r[s].apply(r,n[s]):r[s]}return r}module.exports=((e,n)=>{const r=[],s=[];let l=[];if(n.replace(t,(t,n,a,f,u,h)=>{if(n)l.push(o(n));else if(f){const t=l.join("");l=[],s.push(0===r.length?t:c(e,r)(t)),r.push({inverse:a,styles:i(f)})}else if(u){if(0===r.length)throw new Error("Found extraneous } in Chalk template literal");s.push(c(e,r)(l.join(""))),l=[],r.pop()}else l.push(h)}),s.push(l.join("")),r.length>0){const t="Chalk template literal is missing ".concat(r.length," closing bracket").concat(1===r.length?"":"s"," (`}`)");throw new Error(t)}return s.join("")}); -},{}],"g5I+":[function(require,module,exports) { - -var t,e,n=module.exports={};function r(){throw new Error("setTimeout has not been defined")}function o(){throw new Error("clearTimeout has not been defined")}function i(e){if(t===setTimeout)return setTimeout(e,0);if((t===r||!t)&&setTimeout)return t=setTimeout,setTimeout(e,0);try{return t(e,0)}catch(n){try{return t.call(null,e,0)}catch(n){return t.call(this,e,0)}}}function u(t){if(e===clearTimeout)return clearTimeout(t);if((e===o||!e)&&clearTimeout)return e=clearTimeout,clearTimeout(t);try{return e(t)}catch(n){try{return e.call(null,t)}catch(n){return e.call(this,t)}}}!function(){try{t="function"==typeof setTimeout?setTimeout:r}catch(n){t=r}try{e="function"==typeof clearTimeout?clearTimeout:o}catch(n){e=o}}();var c,s=[],l=!1,a=-1;function f(){l&&c&&(l=!1,c.length?s=c.concat(s):a=-1,s.length&&h())}function h(){if(!l){var t=i(f);l=!0;for(var e=s.length;e;){for(c=s,s=[];++a1)for(var n=1;n0}function p(e){if(!this||!(this instanceof p)||this.template){const t={};return a(t,e),t.template=function(){const e=[].slice.call(arguments);return y.apply(null,[t.template].concat(e))},Object.setPrototypeOf(t,p.prototype),Object.setPrototypeOf(t.template,t),t.template.constructor=p,t.template}a(this,e)}l&&(o.blue.open="");for(const g of Object.keys(o))o[g].closeRe=new RegExp(t(o[g].close),"g"),i[g]={get:function(){const e=o[g];return f.call(this,this._styles?this._styles.concat(e):[e],this._empty,g)}};i.visible={get:function(){return f.call(this,this._styles||[],!0,"visible")}},o.color.closeRe=new RegExp(t(o.color.close),"g");for(const g of Object.keys(o.color.ansi))c.has(g)||(i[g]={get:function(){const e=this.level;return function(){const t={open:o.color[r[e]][g].apply(null,arguments),close:o.color.close,closeRe:o.color.closeRe};return f.call(this,this._styles?this._styles.concat(t):[t],this._empty,g)}}});o.bgColor.closeRe=new RegExp(t(o.bgColor.close),"g");for(const g of Object.keys(o.bgColor.ansi)){if(c.has(g))continue;i["bg"+g[0].toUpperCase()+g.slice(1)]={get:function(){const e=this.level;return function(){const t={open:o.bgColor[r[e]][g].apply(null,arguments),close:o.bgColor.close,closeRe:o.bgColor.closeRe};return f.call(this,this._styles?this._styles.concat(t):[t],this._empty,g)}}}}const u=Object.defineProperties(()=>{},i);function f(e,t,o){const s=function(){return h.apply(s,arguments)};s._styles=e,s._empty=t;const n=this;return Object.defineProperty(s,"level",{enumerable:!0,get:function(){return n.level},set:function(e){n.level=e}}),Object.defineProperty(s,"enabled",{enumerable:!0,get:function(){return n.enabled},set:function(e){n.enabled=e}}),s.hasGrey=this.hasGrey||"gray"===o||"grey"===o,s.__proto__=u,s}function h(){const e=arguments,t=e.length;let s=String(arguments[0]);if(0===t)return"";if(t>1)for(let o=1;o":function(t){t.addToken(t.nextMatch("=")?h.GREATER_EQUAL:h.GREATER)},"<":function(t){t.addToken(t.nextMatch("=")?h.LESS_EQUAL:h.LESS)}," ":r,"\t":r,"\r":r,"\n":function(t){t.newline()},'"':function(t){t.handleStringLiterals()}},a=function(t){return/\d/.test(t)},l=function(t){return/[a-zA-Z_]/.test(t)},f=function(t){return l(t)||a(t)},d=function(){function n(e){t(this,n),this.source=e,this.length=e.length,this.tokens=[],this.startPosition=null,this.column=0,this.start=0,this.line=1,this.current=0}return e(n,null,[{key:"tokens",get:function(){return o}},{key:"tokenEnum",get:function(){return h}}]),e(n,[{key:"handleStringLiterals",value:function(){for(;'"'!==this.peek()&&""!==this.peek();)"\n"===this.peek()&&this.newline(),this.chomp();if(""===this.peek())throw s("Unfinished string",this.startPosition,this.endPosition);this.chomp();var t=this.source.substring(this.start+1,this.current-1);this.addToken(h.STRING,t)}},{key:"handleNumberLiterals",value:function(){for(var t=!1;a(this.peek())||!t&&"."===this.peek();)"."===this.peek()&&(t=!0),this.chomp();var n=this.source.substring(this.start,this.current);this.addToken(h.NUMBER,parseFloat(n))}},{key:"handleIdentifiers",value:function(){for(;f(this.peek());)this.chomp();var t=this.source.substring(this.start,this.current);u[t]?this.addToken(u[t],t):this.addToken(h.IDENTIFIER,t)}},{key:"scanTokens",value:function(){for(;this.current1&&void 0!==arguments[1]?arguments[1]:null,e=this.source.substring(this.start,this.current);this.tokens.push(new k(t,e,n,new E(this.column,this.line,this.current),this.startPosition))}},{key:"increment",value:function(){this.current++,this.column++}},{key:"newline",value:function(){this.line++,this.column=0}},{key:"chomp",value:function(){return this.increment(),this.source.charAt(this.current-1)}},{key:"peek",value:function(){return this.source.charAt(this.current)}},{key:"nextMatch",value:function(t){return this.peek()===t&&(this.increment(),!0)}},{key:"endPosition",get:function(){return new E(this.column-1,this.line,this.current)}}]),n}(),E=function n(e,i,s){t(this,n),this.col=e,this.line=i,this.index=s},k=function n(e,i,s,r,o){t(this,n),this.type=e,this.lexeme=i,this.literal=s,this.startCoordinates=o,this.endCoordinates=r};module.exports=d; -},{"./errors":"p8GN"}],"39eF":[function(require,module,exports) { -function t(t,n){for(var i=0;i"}}]),t}(),j=function t(n,i){c(this,t),this.keyword=n,this.value=i},x=function t(n,i,e){c(this,t),this.name=n,this.params=i,this.bodyStatements=e};module.exports={Var:p,Binary:h,Unary:a,Block:v,Call:w,Callable:_,While:O,Literal:l,Return:j,Logical:f,LoxFunction:x,Grouping:y,Condition:S,ExpressionStatement:b,PrintStatement:m,VarStatement:g,Assignment:d}; -},{}],"CUYV":[function(require,module,exports) { -function t(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function e(t,e){for(var n=0;n2?i-2:0),s=2;s1?e-1:0),i=1;i1&&void 0!==arguments[1]?arguments[1]:console.log;t(this,e),this.printfunction=i,this.environment=n||new A,this.environment.setBuiltin("PI",Math.PI),this.environment.setBuiltin("cos",function(t,e){return Math.cos(e[0])}),this.environment.setBuiltin("mod",function(t,e){return e[0]%e[1]}),this.environment.setBuiltin("strlen",function(t,e){return e[0].length}),this.environment.setBuiltin("charAt",function(t,e){return e[0][e[1]]}),this.environment.setBuiltin("clock",function(){return(new Date).getTime()})}return n(e,[{key:"interpret",value:function(t){return this.evaluate(t)}},{key:"evaluate",value:function(t){return t instanceof p?this.visitBlock(t):t instanceof k?this.visitFunction(t):t instanceof d?this.visitAssignment(t):t instanceof c?this.visitLogical(t):t instanceof l?this.visitCall(t):t instanceof y?this.visitWhile(t):t instanceof w?this.visitCondition(t):t instanceof S?this.visitVarStatement(t):t instanceof B?this.visitPrintStatement(t):t instanceof m?this.visitReturnStatement(t):t instanceof g?this.visitGrouping(t):t instanceof f?this.visitGrouping(t):t instanceof h?this.visitVar(t):t instanceof v?this.visitLiteral(t):t instanceof u?this.visitUnary(t):t instanceof s?this.visitBinary(t):void 0}},{key:"visitLiteral",value:function(t){return t.value}},{key:"visitGrouping",value:function(t){return this.evaluate(t.expression)}},{key:"visitPrintStatement",value:function(t){var e=this.evaluate(t.expression);return this.printfunction(null===e?"nil":e.toString()),e}},{key:"visitFunction",value:function(t){var e=new C(t,this.environment);this.environment.set(t.name,e)}},{key:"visitLogical",value:function(t){var e=this.evaluate(t.left);if(t.operator.type===L.OR){if(U(e))return e}else if(!U(e))return e;return this.evaluate(t.right)}},{key:"visitWhile",value:function(t){for(;U(this.evaluate(t.condition));)this.evaluate(t.body);return null}},{key:"visitReturnStatement",value:function(t){var e=null;throw t.value&&(e=this.evaluate(t.value)),new a(e)}},{key:"visitVar",value:function(t){return this.environment.get(t)}},{key:"visitVarStatement",value:function(t){var e=null;return null!==t.initializer&&(e=this.evaluate(t.initializer)),this.environment.set(t.name,e),null}},{key:"visitBlock",value:function(t){return this.interpretBlock(t.statements,new A(this.environment)),null}},{key:"visitCondition",value:function(t){return U(this.evaluate(t.condition))?this.evaluate(t.thenBranch):t.elseBranch&&this.evaluate(t.elseBranch),null}},{key:"interpretBlock",value:function(t,e){var n=this.environment;try{this.environment=e;var i=!0,r=!1,a=void 0;try{for(var o,s=t[Symbol.iterator]();!(i=(o=s.next()).done);i=!0){var u=o.value;this.interpret(u)}}catch(l){r=!0,a=l}finally{try{i||null==s.return||s.return()}finally{if(r)throw a}}this.environment=n}catch(v){throw this.environment=n,v}}},{key:"visitAssignment",value:function(t){var e=this.evaluate(t.value);return this.environment.assign(t.name,e),e}},{key:"visitCall",value:function(t){var e=this,n=this.evaluate(t.callee),i=t.arguments.map(function(t){return e.evaluate(t)});if(!n.call)throw r("Can only call functions and classes",t.paren);return n.call(this,i)}},{key:"visitUnary",value:function(t){var e=this.evaluate(t.right);switch(t.operator.type){case L.MINUS:return R(t.operator,e),-e;case L.BANG:return!U(e)}}},{key:"visitBinary",value:function(t){var e=this.evaluate(t.left),n=this.evaluate(t.right);switch(t.operator.type){case L.MINUS:return R(t.operator,n,e),e-n;case L.PLUS:return e+n;case L.SLASH:return R(t.operator,n,e),e/n;case L.STAR:return R(t.operator,n,e),e*n;case L.GREATER:return R(t.operator,n,e),e>n;case L.GREATER_EQUAL:return R(t.operator,n,e),e>=n;case L.LESS:return R(t.operator,n,e),e3&&void 0!==arguments[3]&&arguments[3];try{var d=new e(o).scanTokens();l&&console.log(d);var c=new n(d).parse();l&&console.log(c);var u,v=new i(a,s),x=!0,f=!1,g=void 0;try{for(var C,p=c[Symbol.iterator]();!(x=(C=p.next()).done);x=!0){var h=C.value;u=v.interpret(h)}}catch(O){f=!0,g=O}finally{try{x||null==p.return||p.return()}finally{if(f)throw g}}return u}catch(S){if(console.log(S),S instanceof t){console.error("Parse Error:",S.toString(),"at ".concat(S.endCoordinates.line,":").concat(S.endCoordinates.col+1));var q=o.lastIndexOf("\n",S.startCoordinates.index),y=q<0?0:q,b=o.substr(y,S.startCoordinates.index),m=o.substr(S.startCoordinates.index,S.endCoordinates.index),w=o.indexOf("\n",S.endCoordinates.index),E=w<0?o.length:w,k=o.substr(S.endCoordinates.index,E);console.error(b+r.bgRed(m)+k)}else console.log("Unexpected javascript Error: "),console.log(S)}};module.exports={run:s,Environment:a}; -},{"chalk":"ug4C","./tokenizer":"u74b","./parser":"CUYV","./errors":"p8GN","./interpreter":"lmrS","./environment":"brut"}],"KVVd":[function(require,module,exports) { - -},{}],"3hpa":[function(require,module,exports) { -"use strict";var n=require("./index"),t=require("fs"),e="",r=document.getElementById("code"),i=['// Interactive Iterative Fibonacci\nvar a = 0;\nvar b = 1;\nvar limit = prompt("Limit to find fib numbers", 10000);\n\nwhile (a < limit) {\n print a;\n var temp = a;\n a = b;\n b = temp + b;\n}\n','// Linked List via Closures\nfun Link(value, next) {\n fun access(method) {\n if (method == "value") return value;\n if (method == "next") return next;\n print "unknown method " + method;\n }\n\n return access;\n}\n\nfun traverse(n, fn) {\n fn(n);\n if (n("next") != nil) {\n return traverse(n("next"), fn);\n }\n return n;\n}\n\nfun printValue (n) {\n print n("value");\n}\n\nfun blank (n) {}\n\nfun printTail (n) {\n var tail = traverse(n, blank);\n print tail("value");\n}\n\nvar list = Link(1, Link(2, Link(3, nil)));\n\ntraverse(list, printValue);\nprintTail(list, printTail);'],a=i.map(function(n){return{name:n.split("\n")[0].replace(/[^\w\s]/gi,"").trim(),program:n}}),u=document.getElementById("exampleProgram"),o=a.map(function(n,t){return'")}).join("\n");u.innerHTML=o,u.onchange=function(n){var t=n.target.value;r.value=a[t].program};var l=0;window.location.hash&&(l=+window.location.hash.replace(/[^\w\s]/gi,"").trim()),r.value=a[l].program;var m=function(n){e+=n+"\n",console.log(n),document.getElementById("output").value=e},c=document.getElementById("run");c.onclick=function(){var t=r.value,i=new n.Environment;i.setBuiltin("alert",function(n,t){return alert(t[0])}),i.setBuiltin("confirm",function(n,t){return confirm(t[0])}),i.setBuiltin("prompt",function(n,t){return prompt(t[0],t.length>1?t[1]:null)}),e="",(0,n.run)(t,i,m)}; -},{"./index":"Focm","fs":"KVVd"}]},{},["3hpa"], null) \ No newline at end of file diff --git a/docs/browser.993001ea.js b/docs/browser.993001ea.js deleted file mode 100644 index c1a8745..0000000 --- a/docs/browser.993001ea.js +++ /dev/null @@ -1,41 +0,0 @@ -parcelRequire=function(e,r,t,n){var i,o="function"==typeof parcelRequire&&parcelRequire,u="function"==typeof require&&require;function f(t,n){if(!r[t]){if(!e[t]){var i="function"==typeof parcelRequire&&parcelRequire;if(!n&&i)return i(t,!0);if(o)return o(t,!0);if(u&&"string"==typeof t)return u(t);var c=new Error("Cannot find module '"+t+"'");throw c.code="MODULE_NOT_FOUND",c}p.resolve=function(r){return e[t][1][r]||r},p.cache={};var l=r[t]=new f.Module(t);e[t][0].call(l.exports,p,l,l.exports,this)}return r[t].exports;function p(e){return f(p.resolve(e))}}f.isParcelRequire=!0,f.Module=function(e){this.id=e,this.bundle=f,this.exports={}},f.modules=e,f.cache=r,f.parent=o,f.register=function(r,t){e[r]=[function(e,r){r.exports=t},{}]};for(var c=0;c1&&(e-=1)),[360*e,100*h,100*s]},t.rgb.hwb=function(r){var n=r[0],a=r[1],e=r[2];return[t.rgb.hsl(r)[0],100*(1/255*Math.min(n,Math.min(a,e))),100*(e=1-1/255*Math.max(n,Math.max(a,e)))]},t.rgb.cmyk=function(r){var n,a=r[0]/255,t=r[1]/255,e=r[2]/255;return[100*((1-a-(n=Math.min(1-a,1-t,1-e)))/(1-n)||0),100*((1-t-n)/(1-n)||0),100*((1-e-n)/(1-n)||0),100*n]},t.rgb.keyword=function(a){var t=n[a];if(t)return t;var e,h=1/0;for(var u in r)if(r.hasOwnProperty(u)){var c=o(a,r[u]);c.04045?Math.pow((n+.055)/1.055,2.4):n/12.92)+.3576*(a=a>.04045?Math.pow((a+.055)/1.055,2.4):a/12.92)+.1805*(t=t>.04045?Math.pow((t+.055)/1.055,2.4):t/12.92)),100*(.2126*n+.7152*a+.0722*t),100*(.0193*n+.1192*a+.9505*t)]},t.rgb.lab=function(r){var n=t.rgb.xyz(r),a=n[0],e=n[1],h=n[2];return e/=100,h/=108.883,a=(a/=95.047)>.008856?Math.pow(a,1/3):7.787*a+16/116,[116*(e=e>.008856?Math.pow(e,1/3):7.787*e+16/116)-16,500*(a-e),200*(e-(h=h>.008856?Math.pow(h,1/3):7.787*h+16/116))]},t.hsl.rgb=function(r){var n,a,t,e,h,u=r[0]/360,o=r[1]/100,c=r[2]/100;if(0===o)return[h=255*c,h,h];n=2*c-(a=c<.5?c*(1+o):c+o-c*o),e=[0,0,0];for(var s=0;s<3;s++)(t=u+1/3*-(s-1))<0&&t++,t>1&&t--,h=6*t<1?n+6*(a-n)*t:2*t<1?a:3*t<2?n+(a-n)*(2/3-t)*6:n,e[s]=255*h;return e},t.hsl.hsv=function(r){var n=r[0],a=r[1]/100,t=r[2]/100,e=a,h=Math.max(t,.01);return a*=(t*=2)<=1?t:2-t,e*=h<=1?h:2-h,[n,100*(0===t?2*e/(h+e):2*a/(t+a)),100*((t+a)/2)]},t.hsv.rgb=function(r){var n=r[0]/60,a=r[1]/100,t=r[2]/100,e=Math.floor(n)%6,h=n-Math.floor(n),u=255*t*(1-a),o=255*t*(1-a*h),c=255*t*(1-a*(1-h));switch(t*=255,e){case 0:return[t,c,u];case 1:return[o,t,u];case 2:return[u,t,c];case 3:return[u,o,t];case 4:return[c,u,t];case 5:return[t,u,o]}},t.hsv.hsl=function(r){var n,a,t,e=r[0],h=r[1]/100,u=r[2]/100,o=Math.max(u,.01);return t=(2-h)*u,a=h*o,[e,100*(a=(a/=(n=(2-h)*o)<=1?n:2-n)||0),100*(t/=2)]},t.hwb.rgb=function(r){var n,a,t,e,h,u,o,c=r[0]/360,s=r[1]/100,l=r[2]/100,i=s+l;switch(i>1&&(s/=i,l/=i),t=6*c-(n=Math.floor(6*c)),0!=(1&n)&&(t=1-t),e=s+t*((a=1-l)-s),n){default:case 6:case 0:h=a,u=e,o=s;break;case 1:h=e,u=a,o=s;break;case 2:h=s,u=a,o=e;break;case 3:h=s,u=e,o=a;break;case 4:h=e,u=s,o=a;break;case 5:h=a,u=s,o=e}return[255*h,255*u,255*o]},t.cmyk.rgb=function(r){var n=r[0]/100,a=r[1]/100,t=r[2]/100,e=r[3]/100;return[255*(1-Math.min(1,n*(1-e)+e)),255*(1-Math.min(1,a*(1-e)+e)),255*(1-Math.min(1,t*(1-e)+e))]},t.xyz.rgb=function(r){var n,a,t,e=r[0]/100,h=r[1]/100,u=r[2]/100;return a=-.9689*e+1.8758*h+.0415*u,t=.0557*e+-.204*h+1.057*u,n=(n=3.2406*e+-1.5372*h+-.4986*u)>.0031308?1.055*Math.pow(n,1/2.4)-.055:12.92*n,a=a>.0031308?1.055*Math.pow(a,1/2.4)-.055:12.92*a,t=t>.0031308?1.055*Math.pow(t,1/2.4)-.055:12.92*t,[255*(n=Math.min(Math.max(0,n),1)),255*(a=Math.min(Math.max(0,a),1)),255*(t=Math.min(Math.max(0,t),1))]},t.xyz.lab=function(r){var n=r[0],a=r[1],t=r[2];return a/=100,t/=108.883,n=(n/=95.047)>.008856?Math.pow(n,1/3):7.787*n+16/116,[116*(a=a>.008856?Math.pow(a,1/3):7.787*a+16/116)-16,500*(n-a),200*(a-(t=t>.008856?Math.pow(t,1/3):7.787*t+16/116))]},t.lab.xyz=function(r){var n,a,t,e=r[0];n=r[1]/500+(a=(e+16)/116),t=a-r[2]/200;var h=Math.pow(a,3),u=Math.pow(n,3),o=Math.pow(t,3);return a=h>.008856?h:(a-16/116)/7.787,n=u>.008856?u:(n-16/116)/7.787,t=o>.008856?o:(t-16/116)/7.787,[n*=95.047,a*=100,t*=108.883]},t.lab.lch=function(r){var n,a=r[0],t=r[1],e=r[2];return(n=360*Math.atan2(e,t)/2/Math.PI)<0&&(n+=360),[a,Math.sqrt(t*t+e*e),n]},t.lch.lab=function(r){var n,a=r[0],t=r[1];return n=r[2]/360*2*Math.PI,[a,t*Math.cos(n),t*Math.sin(n)]},t.rgb.ansi16=function(r){var n=r[0],a=r[1],e=r[2],h=1 in arguments?arguments[1]:t.rgb.hsv(r)[2];if(0===(h=Math.round(h/50)))return 30;var u=30+(Math.round(e/255)<<2|Math.round(a/255)<<1|Math.round(n/255));return 2===h&&(u+=60),u},t.hsv.ansi16=function(r){return t.rgb.ansi16(t.hsv.rgb(r),r[2])},t.rgb.ansi256=function(r){var n=r[0],a=r[1],t=r[2];return n===a&&a===t?n<8?16:n>248?231:Math.round((n-8)/247*24)+232:16+36*Math.round(n/255*5)+6*Math.round(a/255*5)+Math.round(t/255*5)},t.ansi16.rgb=function(r){var n=r%10;if(0===n||7===n)return r>50&&(n+=3.5),[n=n/10.5*255,n,n];var a=.5*(1+~~(r>50));return[(1&n)*a*255,(n>>1&1)*a*255,(n>>2&1)*a*255]},t.ansi256.rgb=function(r){if(r>=232){var n=10*(r-232)+8;return[n,n,n]}var a;return r-=16,[Math.floor(r/36)/5*255,Math.floor((a=r%36)/6)/5*255,a%6/5*255]},t.rgb.hex=function(r){var n=(((255&Math.round(r[0]))<<16)+((255&Math.round(r[1]))<<8)+(255&Math.round(r[2]))).toString(16).toUpperCase();return"000000".substring(n.length)+n},t.hex.rgb=function(r){var n=r.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);if(!n)return[0,0,0];var a=n[0];3===n[0].length&&(a=a.split("").map(function(r){return r+r}).join(""));var t=parseInt(a,16);return[t>>16&255,t>>8&255,255&t]},t.rgb.hcg=function(r){var n,a=r[0]/255,t=r[1]/255,e=r[2]/255,h=Math.max(Math.max(a,t),e),u=Math.min(Math.min(a,t),e),o=h-u;return n=o<=0?0:h===a?(t-e)/o%6:h===t?2+(e-a)/o:4+(a-t)/o+4,n/=6,[360*(n%=1),100*o,100*(o<1?u/(1-o):0)]},t.hsl.hcg=function(r){var n=r[1]/100,a=r[2]/100,t=1,e=0;return(t=a<.5?2*n*a:2*n*(1-a))<1&&(e=(a-.5*t)/(1-t)),[r[0],100*t,100*e]},t.hsv.hcg=function(r){var n=r[1]/100,a=r[2]/100,t=n*a,e=0;return t<1&&(e=(a-t)/(1-t)),[r[0],100*t,100*e]},t.hcg.rgb=function(r){var n=r[0]/360,a=r[1]/100,t=r[2]/100;if(0===a)return[255*t,255*t,255*t];var e,h=[0,0,0],u=n%1*6,o=u%1,c=1-o;switch(Math.floor(u)){case 0:h[0]=1,h[1]=o,h[2]=0;break;case 1:h[0]=c,h[1]=1,h[2]=0;break;case 2:h[0]=0,h[1]=1,h[2]=o;break;case 3:h[0]=0,h[1]=c,h[2]=1;break;case 4:h[0]=o,h[1]=0,h[2]=1;break;default:h[0]=1,h[1]=0,h[2]=c}return e=(1-a)*t,[255*(a*h[0]+e),255*(a*h[1]+e),255*(a*h[2]+e)]},t.hcg.hsv=function(r){var n=r[1]/100,a=n+r[2]/100*(1-n),t=0;return a>0&&(t=n/a),[r[0],100*t,100*a]},t.hcg.hsl=function(r){var n=r[1]/100,a=r[2]/100*(1-n)+.5*n,t=0;return a>0&&a<.5?t=n/(2*a):a>=.5&&a<1&&(t=n/(2*(1-a))),[r[0],100*t,100*a]},t.hcg.hwb=function(r){var n=r[1]/100,a=n+r[2]/100*(1-n);return[r[0],100*(a-n),100*(1-a)]},t.hwb.hcg=function(r){var n=r[1]/100,a=1-r[2]/100,t=a-n,e=0;return t<1&&(e=(a-t)/(1-t)),[r[0],100*t,100*e]},t.apple.rgb=function(r){return[r[0]/65535*255,r[1]/65535*255,r[2]/65535*255]},t.rgb.apple=function(r){return[r[0]/255*65535,r[1]/255*65535,r[2]/255*65535]},t.gray.rgb=function(r){return[r[0]/100*255,r[0]/100*255,r[0]/100*255]},t.gray.hsl=t.gray.hsv=function(r){return[0,0,r[0]]},t.gray.hwb=function(r){return[0,100,r[0]]},t.gray.cmyk=function(r){return[0,0,0,r[0]]},t.gray.lab=function(r){return[r[0],0,0]},t.gray.hex=function(r){var n=255&Math.round(r[0]/100*255),a=((n<<16)+(n<<8)+n).toString(16).toUpperCase();return"000000".substring(a.length)+a},t.rgb.gray=function(r){return[(r[0]+r[1]+r[2])/3/255*100]}; -},{"color-name":"auEH"}],"fg2k":[function(require,module,exports) { -var n=require("./conversions");function r(){for(var r={},e=Object.keys(n),t=e.length,a=0;a1&&(n=Array.prototype.slice.call(arguments)),e(n))};return"conversion"in e&&(n.conversion=e.conversion),n}function c(e){var n=function(n){if(null==n)return n;arguments.length>1&&(n=Array.prototype.slice.call(arguments));var r=e(n);if("object"==typeof r)for(var o=r.length,t=0;t(function(){const t=o.apply(n,arguments);return"[".concat(t+e,"m")}),t=(o,e)=>(function(){const t=o.apply(n,arguments);return"[".concat(38+e,";5;").concat(t,"m")}),r=(o,e)=>(function(){const t=o.apply(n,arguments);return"[".concat(38+e,";2;").concat(t[0],";").concat(t[1],";").concat(t[2],"m")});function i(){const i=new Map,c={modifier:{reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],inverse:[7,27],hidden:[8,28],strikethrough:[9,29]},color:{black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],gray:[90,39],redBright:[91,39],greenBright:[92,39],yellowBright:[93,39],blueBright:[94,39],magentaBright:[95,39],cyanBright:[96,39],whiteBright:[97,39]},bgColor:{bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],bgBlackBright:[100,49],bgRedBright:[101,49],bgGreenBright:[102,49],bgYellowBright:[103,49],bgBlueBright:[104,49],bgMagentaBright:[105,49],bgCyanBright:[106,49],bgWhiteBright:[107,49]}};c.color.grey=c.color.gray;for(const o of Object.keys(c)){const n=c[o];for(const o of Object.keys(n)){const e=n[o];c[o]={open:"[".concat(e[0],"m"),close:"[".concat(e[1],"m")},n[o]=c[o],i.set(e[0],e[1])}Object.defineProperty(c,o,{value:n,enumerable:!1}),Object.defineProperty(c,"codes",{value:i,enumerable:!1})}const a=o=>o,l=(o,n,e)=>[o,n,e];c.color.close="",c.bgColor.close="",c.color.ansi={ansi:e(a,0)},c.color.ansi256={ansi256:t(a,0)},c.color.ansi16m={rgb:r(l,0)},c.bgColor.ansi={ansi:e(a,10)},c.bgColor.ansi256={ansi256:t(a,10)},c.bgColor.ansi16m={rgb:r(l,10)};for(let g of Object.keys(n)){if("object"!==o(n[g]))continue;const i=n[g];"ansi16"===g&&(g="ansi"),"ansi16"in i&&(c.color.ansi[g]=e(i.ansi16,0),c.bgColor.ansi[g]=e(i.ansi16,10)),"ansi256"in i&&(c.color.ansi256[g]=t(i.ansi256,0),c.bgColor.ansi256[g]=t(i.ansi256,10)),"rgb"in i&&(c.color.ansi16m[g]=r(i.rgb,0),c.bgColor.ansi16m[g]=r(i.rgb,10))}return c}Object.defineProperty(module,"exports",{enumerable:!0,get:i}); -},{"color-convert":"PawV"}],"foIL":[function(require,module,exports) { -"use strict";module.exports={stdout:!1,stderr:!1}; -},{}],"PLSQ":[function(require,module,exports) { -"use strict";const t=/(?:\\(u[a-f\d]{4}|x[a-f\d]{2}|.))|(?:\{(~)?(\w+(?:\([^)]*\))?(?:\.\w+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n)))|(\})|((?:.|[\r\n\f])+?)/gi,e=/(?:^|\.)(\w+)(?:\(([^)]*)\))?/g,n=/^(['"])((?:\\.|(?!\1)[^\\])*)\1$/,r=/\\(u[a-f\d]{4}|x[a-f\d]{2}|.)|([^\\])/gi,s=new Map([["n","\n"],["r","\r"],["t","\t"],["b","\b"],["f","\f"],["v","\v"],["0","\0"],["\\","\\"],["e",""],["a",""]]);function o(t){return"u"===t[0]&&5===t.length||"x"===t[0]&&3===t.length?String.fromCharCode(parseInt(t.slice(1),16)):s.get(t)||t}function l(t,e){const s=[],l=e.trim().split(/\s*,\s*/g);let i;for(const c of l)if(isNaN(c)){if(!(i=c.match(n)))throw new Error("Invalid Chalk template style argument: ".concat(c," (in style '").concat(t,"')"));s.push(i[2].replace(r,(t,e,n)=>e?o(e):n))}else s.push(Number(c));return s}function i(t){e.lastIndex=0;const n=[];let r;for(;null!==(r=e.exec(t));){const t=r[1];if(r[2]){const e=l(t,r[2]);n.push([t].concat(e))}else n.push([t])}return n}function c(t,e){const n={};for(const s of e)for(const t of s.styles)n[t[0]]=s.inverse?null:t.slice(1);let r=t;for(const s of Object.keys(n))if(Array.isArray(n[s])){if(!(s in r))throw new Error("Unknown Chalk style: ".concat(s));r=n[s].length>0?r[s].apply(r,n[s]):r[s]}return r}module.exports=((e,n)=>{const r=[],s=[];let l=[];if(n.replace(t,(t,n,a,f,u,h)=>{if(n)l.push(o(n));else if(f){const t=l.join("");l=[],s.push(0===r.length?t:c(e,r)(t)),r.push({inverse:a,styles:i(f)})}else if(u){if(0===r.length)throw new Error("Found extraneous } in Chalk template literal");s.push(c(e,r)(l.join(""))),l=[],r.pop()}else l.push(h)}),s.push(l.join("")),r.length>0){const t="Chalk template literal is missing ".concat(r.length," closing bracket").concat(1===r.length?"":"s"," (`}`)");throw new Error(t)}return s.join("")}); -},{}],"g5I+":[function(require,module,exports) { - -var t,e,n=module.exports={};function r(){throw new Error("setTimeout has not been defined")}function o(){throw new Error("clearTimeout has not been defined")}function i(e){if(t===setTimeout)return setTimeout(e,0);if((t===r||!t)&&setTimeout)return t=setTimeout,setTimeout(e,0);try{return t(e,0)}catch(n){try{return t.call(null,e,0)}catch(n){return t.call(this,e,0)}}}function u(t){if(e===clearTimeout)return clearTimeout(t);if((e===o||!e)&&clearTimeout)return e=clearTimeout,clearTimeout(t);try{return e(t)}catch(n){try{return e.call(null,t)}catch(n){return e.call(this,t)}}}!function(){try{t="function"==typeof setTimeout?setTimeout:r}catch(n){t=r}try{e="function"==typeof clearTimeout?clearTimeout:o}catch(n){e=o}}();var c,s=[],l=!1,a=-1;function f(){l&&c&&(l=!1,c.length?s=c.concat(s):a=-1,s.length&&h())}function h(){if(!l){var t=i(f);l=!0;for(var e=s.length;e;){for(c=s,s=[];++a1)for(var n=1;n0}function p(e){if(!this||!(this instanceof p)||this.template){const t={};return a(t,e),t.template=function(){const e=[].slice.call(arguments);return y.apply(null,[t.template].concat(e))},Object.setPrototypeOf(t,p.prototype),Object.setPrototypeOf(t.template,t),t.template.constructor=p,t.template}a(this,e)}l&&(o.blue.open="");for(const g of Object.keys(o))o[g].closeRe=new RegExp(t(o[g].close),"g"),i[g]={get:function(){const e=o[g];return f.call(this,this._styles?this._styles.concat(e):[e],this._empty,g)}};i.visible={get:function(){return f.call(this,this._styles||[],!0,"visible")}},o.color.closeRe=new RegExp(t(o.color.close),"g");for(const g of Object.keys(o.color.ansi))c.has(g)||(i[g]={get:function(){const e=this.level;return function(){const t={open:o.color[r[e]][g].apply(null,arguments),close:o.color.close,closeRe:o.color.closeRe};return f.call(this,this._styles?this._styles.concat(t):[t],this._empty,g)}}});o.bgColor.closeRe=new RegExp(t(o.bgColor.close),"g");for(const g of Object.keys(o.bgColor.ansi)){if(c.has(g))continue;i["bg"+g[0].toUpperCase()+g.slice(1)]={get:function(){const e=this.level;return function(){const t={open:o.bgColor[r[e]][g].apply(null,arguments),close:o.bgColor.close,closeRe:o.bgColor.closeRe};return f.call(this,this._styles?this._styles.concat(t):[t],this._empty,g)}}}}const u=Object.defineProperties(()=>{},i);function f(e,t,o){const s=function(){return h.apply(s,arguments)};s._styles=e,s._empty=t;const n=this;return Object.defineProperty(s,"level",{enumerable:!0,get:function(){return n.level},set:function(e){n.level=e}}),Object.defineProperty(s,"enabled",{enumerable:!0,get:function(){return n.enabled},set:function(e){n.enabled=e}}),s.hasGrey=this.hasGrey||"gray"===o||"grey"===o,s.__proto__=u,s}function h(){const e=arguments,t=e.length;let s=String(arguments[0]);if(0===t)return"";if(t>1)for(let o=1;o":function(t){t.addToken(t.nextMatch("=")?h.GREATER_EQUAL:h.GREATER)},"<":function(t){t.addToken(t.nextMatch("=")?h.LESS_EQUAL:h.LESS)}," ":r,"\t":r,"\r":r,"\n":function(t){t.newline()},'"':function(t){t.handleStringLiterals()}},a=function(t){return/\d/.test(t)},l=function(t){return/[a-zA-Z_]/.test(t)},f=function(t){return l(t)||a(t)},d=function(){function n(e){t(this,n),this.source=e,this.length=e.length,this.tokens=[],this.startPosition=null,this.column=0,this.start=0,this.line=1,this.current=0}return e(n,null,[{key:"tokens",get:function(){return o}},{key:"tokenEnum",get:function(){return h}}]),e(n,[{key:"handleStringLiterals",value:function(){for(;'"'!==this.peek()&&""!==this.peek();)"\n"===this.peek()&&this.newline(),this.chomp();if(""===this.peek())throw s("Unfinished string",this.startPosition,this.endPosition);this.chomp();var t=this.source.substring(this.start+1,this.current-1);this.addToken(h.STRING,t)}},{key:"handleNumberLiterals",value:function(){for(var t=!1;a(this.peek())||!t&&"."===this.peek();)"."===this.peek()&&(t=!0),this.chomp();var n=this.source.substring(this.start,this.current);this.addToken(h.NUMBER,parseFloat(n))}},{key:"handleIdentifiers",value:function(){for(;f(this.peek());)this.chomp();var t=this.source.substring(this.start,this.current);u[t]?this.addToken(u[t],t):this.addToken(h.IDENTIFIER,t)}},{key:"scanTokens",value:function(){for(;this.current1&&void 0!==arguments[1]?arguments[1]:null,e=this.source.substring(this.start,this.current);this.tokens.push(new k(t,e,n,new E(this.column,this.line,this.current),this.startPosition))}},{key:"increment",value:function(){this.current++,this.column++}},{key:"newline",value:function(){this.line++,this.column=0}},{key:"chomp",value:function(){return this.increment(),this.source.charAt(this.current-1)}},{key:"peek",value:function(){return this.source.charAt(this.current)}},{key:"nextMatch",value:function(t){return this.peek()===t&&(this.increment(),!0)}},{key:"endPosition",get:function(){return new E(this.column-1,this.line,this.current)}}]),n}(),E=function n(e,i,s){t(this,n),this.col=e,this.line=i,this.index=s},k=function n(e,i,s,r,o){t(this,n),this.type=e,this.lexeme=i,this.literal=s,this.startCoordinates=o,this.endCoordinates=r};module.exports=d; -},{"./errors":"p8GN"}],"39eF":[function(require,module,exports) { -function t(t,n){for(var i=0;i"}}]),t}(),j=function t(n,i){c(this,t),this.keyword=n,this.value=i},x=function t(n,i,e){c(this,t),this.name=n,this.params=i,this.bodyStatements=e};module.exports={Var:p,Binary:h,Unary:a,Block:v,Call:w,Callable:_,While:O,Literal:l,Return:j,Logical:f,LoxFunction:x,Grouping:y,Condition:S,ExpressionStatement:b,PrintStatement:m,VarStatement:g,Assignment:d}; -},{}],"CUYV":[function(require,module,exports) { -function t(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function e(t,e){for(var n=0;n2?i-2:0),s=2;s1?e-1:0),i=1;i1&&void 0!==arguments[1]?arguments[1]:console.log;t(this,e),this.printfunction=i,this.environment=n||new A,this.environment.setBuiltin("PI",Math.PI),this.environment.setBuiltin("cos",function(t,e){return Math.cos(e[0])}),this.environment.setBuiltin("mod",function(t,e){return e[0]%e[1]}),this.environment.setBuiltin("strlen",function(t,e){return e[0].length}),this.environment.setBuiltin("charAt",function(t,e){return e[0][e[1]]}),this.environment.setBuiltin("clock",function(){return(new Date).getTime()})}return n(e,[{key:"interpret",value:function(t){return this.evaluate(t)}},{key:"evaluate",value:function(t){return t instanceof p?this.visitBlock(t):t instanceof k?this.visitFunction(t):t instanceof d?this.visitAssignment(t):t instanceof c?this.visitLogical(t):t instanceof l?this.visitCall(t):t instanceof y?this.visitWhile(t):t instanceof w?this.visitCondition(t):t instanceof S?this.visitVarStatement(t):t instanceof B?this.visitPrintStatement(t):t instanceof m?this.visitReturnStatement(t):t instanceof g?this.visitGrouping(t):t instanceof f?this.visitGrouping(t):t instanceof h?this.visitVar(t):t instanceof v?this.visitLiteral(t):t instanceof u?this.visitUnary(t):t instanceof s?this.visitBinary(t):void 0}},{key:"visitLiteral",value:function(t){return t.value}},{key:"visitGrouping",value:function(t){return this.evaluate(t.expression)}},{key:"visitPrintStatement",value:function(t){var e=this.evaluate(t.expression);return this.printfunction(null===e?"nil":e.toString()),e}},{key:"visitFunction",value:function(t){var e=new C(t,this.environment);this.environment.set(t.name,e)}},{key:"visitLogical",value:function(t){var e=this.evaluate(t.left);if(t.operator.type===L.OR){if(U(e))return e}else if(!U(e))return e;return this.evaluate(t.right)}},{key:"visitWhile",value:function(t){for(;U(this.evaluate(t.condition));)this.evaluate(t.body);return null}},{key:"visitReturnStatement",value:function(t){var e=null;throw t.value&&(e=this.evaluate(t.value)),new a(e)}},{key:"visitVar",value:function(t){return this.environment.get(t)}},{key:"visitVarStatement",value:function(t){var e=null;return null!==t.initializer&&(e=this.evaluate(t.initializer)),this.environment.set(t.name,e),null}},{key:"visitBlock",value:function(t){return this.interpretBlock(t.statements,new A(this.environment)),null}},{key:"visitCondition",value:function(t){return U(this.evaluate(t.condition))?this.evaluate(t.thenBranch):t.elseBranch&&this.evaluate(t.elseBranch),null}},{key:"interpretBlock",value:function(t,e){var n=this.environment;try{this.environment=e;var i=!0,r=!1,a=void 0;try{for(var o,s=t[Symbol.iterator]();!(i=(o=s.next()).done);i=!0){var u=o.value;this.interpret(u)}}catch(l){r=!0,a=l}finally{try{i||null==s.return||s.return()}finally{if(r)throw a}}this.environment=n}catch(v){throw this.environment=n,v}}},{key:"visitAssignment",value:function(t){var e=this.evaluate(t.value);return this.environment.assign(t.name,e),e}},{key:"visitCall",value:function(t){var e=this,n=this.evaluate(t.callee),i=t.arguments.map(function(t){return e.evaluate(t)});if(!n.call)throw r("Can only call functions and classes",t.paren);return n.call(this,i)}},{key:"visitUnary",value:function(t){var e=this.evaluate(t.right);switch(t.operator.type){case L.MINUS:return R(t.operator,e),-e;case L.BANG:return!U(e)}}},{key:"visitBinary",value:function(t){var e=this.evaluate(t.left),n=this.evaluate(t.right);switch(t.operator.type){case L.MINUS:return R(t.operator,n,e),e-n;case L.PLUS:return e+n;case L.SLASH:return R(t.operator,n,e),e/n;case L.STAR:return R(t.operator,n,e),e*n;case L.GREATER:return R(t.operator,n,e),e>n;case L.GREATER_EQUAL:return R(t.operator,n,e),e>=n;case L.LESS:return R(t.operator,n,e),e3&&void 0!==arguments[3]&&arguments[3];try{var d=new e(o).scanTokens();l&&console.log(d);var c=new n(d).parse();l&&console.log(c);var u,v=new i(a,s),x=!0,f=!1,g=void 0;try{for(var C,p=c[Symbol.iterator]();!(x=(C=p.next()).done);x=!0){var h=C.value;u=v.interpret(h)}}catch(O){f=!0,g=O}finally{try{x||null==p.return||p.return()}finally{if(f)throw g}}return u}catch(S){if(console.log(S),S instanceof t){console.error("Parse Error:",S.toString(),"at ".concat(S.endCoordinates.line,":").concat(S.endCoordinates.col+1));var q=o.lastIndexOf("\n",S.startCoordinates.index),y=q<0?0:q,b=o.substr(y,S.startCoordinates.index),m=o.substr(S.startCoordinates.index,S.endCoordinates.index),w=o.indexOf("\n",S.endCoordinates.index),E=w<0?o.length:w,k=o.substr(S.endCoordinates.index,E);console.error(b+r.bgRed(m)+k)}else console.log("Unexpected javascript Error: "),console.log(S)}};module.exports={run:s,Environment:a}; -},{"chalk":"ug4C","./tokenizer":"u74b","./parser":"CUYV","./errors":"p8GN","./interpreter":"lmrS","./environment":"brut"}],"KVVd":[function(require,module,exports) { - -},{}],"3hpa":[function(require,module,exports) { -"use strict";var n=require("./index"),e=require("fs"),t="",r=document.getElementById("code"),i=['// Interactive Iterative Fibonacci\nvar a = 0;\nvar b = 1;\nvar limit = prompt("Limit to find fib numbers", 10000);\n\nwhile (a < limit) {\n print a;\n var temp = a;\n a = b;\n b = temp + b;\n}\n','// Linked List via Closures\nfun Link(value, next) {\n fun access(method) {\n if (method == "value") return value;\n if (method == "next") return next;\n print "unknown method " + method;\n }\n\n return access;\n}\n\nfun traverse(n, fn) {\n fn(n);\n if (n("next") != nil) {\n return traverse(n("next"), fn);\n }\n return n;\n}\n\nfun printValue (n) {\n print n("value");\n}\n\nfun blank (n) {}\n\nfun printTail (n) {\n var tail = traverse(n, blank);\n print tail("value");\n}\n\nvar list = Link(1, Link(2, Link(3, nil)));\n\ntraverse(list, printValue);\nprintTail(list, printTail);'],a=i.map(function(n){return{name:n.split("\n")[0].replace(/[^\w\s]/gi,"").trim(),program:n}}),u=document.getElementById("exampleProgram"),l=a.map(function(n,e){return'")}).join("\n");u.innerHTML=l,u.onchange=function(n){var e=n.target.value;r.value=a[e].program},r.value=a[0].program;var o=function(n){t+=n+"\n",console.log(n),document.getElementById("output").value=t},m=document.getElementById("run");m.onclick=function(){var e=r.value,i=new n.Environment;i.setBuiltin("alert",function(n,e){return alert(e[0])}),i.setBuiltin("confirm",function(n,e){return confirm(e[0])}),i.setBuiltin("prompt",function(n,e){return prompt(e[0],e.length>1?e[1]:null)}),t="",(0,n.run)(e,i,o)}; -},{"./index":"Focm","fs":"KVVd"}]},{},["3hpa"], null) \ No newline at end of file diff --git a/docs/browser.b0516530.js b/docs/browser.b0516530.js deleted file mode 100644 index f5b477b..0000000 --- a/docs/browser.b0516530.js +++ /dev/null @@ -1,41 +0,0 @@ -parcelRequire=function(e,r,t,n){var i,o="function"==typeof parcelRequire&&parcelRequire,u="function"==typeof require&&require;function f(t,n){if(!r[t]){if(!e[t]){var i="function"==typeof parcelRequire&&parcelRequire;if(!n&&i)return i(t,!0);if(o)return o(t,!0);if(u&&"string"==typeof t)return u(t);var c=new Error("Cannot find module '"+t+"'");throw c.code="MODULE_NOT_FOUND",c}p.resolve=function(r){return e[t][1][r]||r},p.cache={};var l=r[t]=new f.Module(t);e[t][0].call(l.exports,p,l,l.exports,this)}return r[t].exports;function p(e){return f(p.resolve(e))}}f.isParcelRequire=!0,f.Module=function(e){this.id=e,this.bundle=f,this.exports={}},f.modules=e,f.cache=r,f.parent=o,f.register=function(r,t){e[r]=[function(e,r){r.exports=t},{}]};for(var c=0;c1&&(e-=1)),[360*e,100*h,100*s]},t.rgb.hwb=function(r){var n=r[0],a=r[1],e=r[2];return[t.rgb.hsl(r)[0],100*(1/255*Math.min(n,Math.min(a,e))),100*(e=1-1/255*Math.max(n,Math.max(a,e)))]},t.rgb.cmyk=function(r){var n,a=r[0]/255,t=r[1]/255,e=r[2]/255;return[100*((1-a-(n=Math.min(1-a,1-t,1-e)))/(1-n)||0),100*((1-t-n)/(1-n)||0),100*((1-e-n)/(1-n)||0),100*n]},t.rgb.keyword=function(a){var t=n[a];if(t)return t;var e,h=1/0;for(var u in r)if(r.hasOwnProperty(u)){var c=o(a,r[u]);c.04045?Math.pow((n+.055)/1.055,2.4):n/12.92)+.3576*(a=a>.04045?Math.pow((a+.055)/1.055,2.4):a/12.92)+.1805*(t=t>.04045?Math.pow((t+.055)/1.055,2.4):t/12.92)),100*(.2126*n+.7152*a+.0722*t),100*(.0193*n+.1192*a+.9505*t)]},t.rgb.lab=function(r){var n=t.rgb.xyz(r),a=n[0],e=n[1],h=n[2];return e/=100,h/=108.883,a=(a/=95.047)>.008856?Math.pow(a,1/3):7.787*a+16/116,[116*(e=e>.008856?Math.pow(e,1/3):7.787*e+16/116)-16,500*(a-e),200*(e-(h=h>.008856?Math.pow(h,1/3):7.787*h+16/116))]},t.hsl.rgb=function(r){var n,a,t,e,h,u=r[0]/360,o=r[1]/100,c=r[2]/100;if(0===o)return[h=255*c,h,h];n=2*c-(a=c<.5?c*(1+o):c+o-c*o),e=[0,0,0];for(var s=0;s<3;s++)(t=u+1/3*-(s-1))<0&&t++,t>1&&t--,h=6*t<1?n+6*(a-n)*t:2*t<1?a:3*t<2?n+(a-n)*(2/3-t)*6:n,e[s]=255*h;return e},t.hsl.hsv=function(r){var n=r[0],a=r[1]/100,t=r[2]/100,e=a,h=Math.max(t,.01);return a*=(t*=2)<=1?t:2-t,e*=h<=1?h:2-h,[n,100*(0===t?2*e/(h+e):2*a/(t+a)),100*((t+a)/2)]},t.hsv.rgb=function(r){var n=r[0]/60,a=r[1]/100,t=r[2]/100,e=Math.floor(n)%6,h=n-Math.floor(n),u=255*t*(1-a),o=255*t*(1-a*h),c=255*t*(1-a*(1-h));switch(t*=255,e){case 0:return[t,c,u];case 1:return[o,t,u];case 2:return[u,t,c];case 3:return[u,o,t];case 4:return[c,u,t];case 5:return[t,u,o]}},t.hsv.hsl=function(r){var n,a,t,e=r[0],h=r[1]/100,u=r[2]/100,o=Math.max(u,.01);return t=(2-h)*u,a=h*o,[e,100*(a=(a/=(n=(2-h)*o)<=1?n:2-n)||0),100*(t/=2)]},t.hwb.rgb=function(r){var n,a,t,e,h,u,o,c=r[0]/360,s=r[1]/100,l=r[2]/100,i=s+l;switch(i>1&&(s/=i,l/=i),t=6*c-(n=Math.floor(6*c)),0!=(1&n)&&(t=1-t),e=s+t*((a=1-l)-s),n){default:case 6:case 0:h=a,u=e,o=s;break;case 1:h=e,u=a,o=s;break;case 2:h=s,u=a,o=e;break;case 3:h=s,u=e,o=a;break;case 4:h=e,u=s,o=a;break;case 5:h=a,u=s,o=e}return[255*h,255*u,255*o]},t.cmyk.rgb=function(r){var n=r[0]/100,a=r[1]/100,t=r[2]/100,e=r[3]/100;return[255*(1-Math.min(1,n*(1-e)+e)),255*(1-Math.min(1,a*(1-e)+e)),255*(1-Math.min(1,t*(1-e)+e))]},t.xyz.rgb=function(r){var n,a,t,e=r[0]/100,h=r[1]/100,u=r[2]/100;return a=-.9689*e+1.8758*h+.0415*u,t=.0557*e+-.204*h+1.057*u,n=(n=3.2406*e+-1.5372*h+-.4986*u)>.0031308?1.055*Math.pow(n,1/2.4)-.055:12.92*n,a=a>.0031308?1.055*Math.pow(a,1/2.4)-.055:12.92*a,t=t>.0031308?1.055*Math.pow(t,1/2.4)-.055:12.92*t,[255*(n=Math.min(Math.max(0,n),1)),255*(a=Math.min(Math.max(0,a),1)),255*(t=Math.min(Math.max(0,t),1))]},t.xyz.lab=function(r){var n=r[0],a=r[1],t=r[2];return a/=100,t/=108.883,n=(n/=95.047)>.008856?Math.pow(n,1/3):7.787*n+16/116,[116*(a=a>.008856?Math.pow(a,1/3):7.787*a+16/116)-16,500*(n-a),200*(a-(t=t>.008856?Math.pow(t,1/3):7.787*t+16/116))]},t.lab.xyz=function(r){var n,a,t,e=r[0];n=r[1]/500+(a=(e+16)/116),t=a-r[2]/200;var h=Math.pow(a,3),u=Math.pow(n,3),o=Math.pow(t,3);return a=h>.008856?h:(a-16/116)/7.787,n=u>.008856?u:(n-16/116)/7.787,t=o>.008856?o:(t-16/116)/7.787,[n*=95.047,a*=100,t*=108.883]},t.lab.lch=function(r){var n,a=r[0],t=r[1],e=r[2];return(n=360*Math.atan2(e,t)/2/Math.PI)<0&&(n+=360),[a,Math.sqrt(t*t+e*e),n]},t.lch.lab=function(r){var n,a=r[0],t=r[1];return n=r[2]/360*2*Math.PI,[a,t*Math.cos(n),t*Math.sin(n)]},t.rgb.ansi16=function(r){var n=r[0],a=r[1],e=r[2],h=1 in arguments?arguments[1]:t.rgb.hsv(r)[2];if(0===(h=Math.round(h/50)))return 30;var u=30+(Math.round(e/255)<<2|Math.round(a/255)<<1|Math.round(n/255));return 2===h&&(u+=60),u},t.hsv.ansi16=function(r){return t.rgb.ansi16(t.hsv.rgb(r),r[2])},t.rgb.ansi256=function(r){var n=r[0],a=r[1],t=r[2];return n===a&&a===t?n<8?16:n>248?231:Math.round((n-8)/247*24)+232:16+36*Math.round(n/255*5)+6*Math.round(a/255*5)+Math.round(t/255*5)},t.ansi16.rgb=function(r){var n=r%10;if(0===n||7===n)return r>50&&(n+=3.5),[n=n/10.5*255,n,n];var a=.5*(1+~~(r>50));return[(1&n)*a*255,(n>>1&1)*a*255,(n>>2&1)*a*255]},t.ansi256.rgb=function(r){if(r>=232){var n=10*(r-232)+8;return[n,n,n]}var a;return r-=16,[Math.floor(r/36)/5*255,Math.floor((a=r%36)/6)/5*255,a%6/5*255]},t.rgb.hex=function(r){var n=(((255&Math.round(r[0]))<<16)+((255&Math.round(r[1]))<<8)+(255&Math.round(r[2]))).toString(16).toUpperCase();return"000000".substring(n.length)+n},t.hex.rgb=function(r){var n=r.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);if(!n)return[0,0,0];var a=n[0];3===n[0].length&&(a=a.split("").map(function(r){return r+r}).join(""));var t=parseInt(a,16);return[t>>16&255,t>>8&255,255&t]},t.rgb.hcg=function(r){var n,a=r[0]/255,t=r[1]/255,e=r[2]/255,h=Math.max(Math.max(a,t),e),u=Math.min(Math.min(a,t),e),o=h-u;return n=o<=0?0:h===a?(t-e)/o%6:h===t?2+(e-a)/o:4+(a-t)/o+4,n/=6,[360*(n%=1),100*o,100*(o<1?u/(1-o):0)]},t.hsl.hcg=function(r){var n=r[1]/100,a=r[2]/100,t=1,e=0;return(t=a<.5?2*n*a:2*n*(1-a))<1&&(e=(a-.5*t)/(1-t)),[r[0],100*t,100*e]},t.hsv.hcg=function(r){var n=r[1]/100,a=r[2]/100,t=n*a,e=0;return t<1&&(e=(a-t)/(1-t)),[r[0],100*t,100*e]},t.hcg.rgb=function(r){var n=r[0]/360,a=r[1]/100,t=r[2]/100;if(0===a)return[255*t,255*t,255*t];var e,h=[0,0,0],u=n%1*6,o=u%1,c=1-o;switch(Math.floor(u)){case 0:h[0]=1,h[1]=o,h[2]=0;break;case 1:h[0]=c,h[1]=1,h[2]=0;break;case 2:h[0]=0,h[1]=1,h[2]=o;break;case 3:h[0]=0,h[1]=c,h[2]=1;break;case 4:h[0]=o,h[1]=0,h[2]=1;break;default:h[0]=1,h[1]=0,h[2]=c}return e=(1-a)*t,[255*(a*h[0]+e),255*(a*h[1]+e),255*(a*h[2]+e)]},t.hcg.hsv=function(r){var n=r[1]/100,a=n+r[2]/100*(1-n),t=0;return a>0&&(t=n/a),[r[0],100*t,100*a]},t.hcg.hsl=function(r){var n=r[1]/100,a=r[2]/100*(1-n)+.5*n,t=0;return a>0&&a<.5?t=n/(2*a):a>=.5&&a<1&&(t=n/(2*(1-a))),[r[0],100*t,100*a]},t.hcg.hwb=function(r){var n=r[1]/100,a=n+r[2]/100*(1-n);return[r[0],100*(a-n),100*(1-a)]},t.hwb.hcg=function(r){var n=r[1]/100,a=1-r[2]/100,t=a-n,e=0;return t<1&&(e=(a-t)/(1-t)),[r[0],100*t,100*e]},t.apple.rgb=function(r){return[r[0]/65535*255,r[1]/65535*255,r[2]/65535*255]},t.rgb.apple=function(r){return[r[0]/255*65535,r[1]/255*65535,r[2]/255*65535]},t.gray.rgb=function(r){return[r[0]/100*255,r[0]/100*255,r[0]/100*255]},t.gray.hsl=t.gray.hsv=function(r){return[0,0,r[0]]},t.gray.hwb=function(r){return[0,100,r[0]]},t.gray.cmyk=function(r){return[0,0,0,r[0]]},t.gray.lab=function(r){return[r[0],0,0]},t.gray.hex=function(r){var n=255&Math.round(r[0]/100*255),a=((n<<16)+(n<<8)+n).toString(16).toUpperCase();return"000000".substring(a.length)+a},t.rgb.gray=function(r){return[(r[0]+r[1]+r[2])/3/255*100]}; -},{"color-name":"auEH"}],"fg2k":[function(require,module,exports) { -var n=require("./conversions");function r(){for(var r={},e=Object.keys(n),t=e.length,a=0;a1&&(n=Array.prototype.slice.call(arguments)),e(n))};return"conversion"in e&&(n.conversion=e.conversion),n}function c(e){var n=function(n){if(null==n)return n;arguments.length>1&&(n=Array.prototype.slice.call(arguments));var r=e(n);if("object"==typeof r)for(var o=r.length,t=0;t(function(){const t=o.apply(n,arguments);return"[".concat(t+e,"m")}),t=(o,e)=>(function(){const t=o.apply(n,arguments);return"[".concat(38+e,";5;").concat(t,"m")}),r=(o,e)=>(function(){const t=o.apply(n,arguments);return"[".concat(38+e,";2;").concat(t[0],";").concat(t[1],";").concat(t[2],"m")});function i(){const i=new Map,c={modifier:{reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],inverse:[7,27],hidden:[8,28],strikethrough:[9,29]},color:{black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],gray:[90,39],redBright:[91,39],greenBright:[92,39],yellowBright:[93,39],blueBright:[94,39],magentaBright:[95,39],cyanBright:[96,39],whiteBright:[97,39]},bgColor:{bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],bgBlackBright:[100,49],bgRedBright:[101,49],bgGreenBright:[102,49],bgYellowBright:[103,49],bgBlueBright:[104,49],bgMagentaBright:[105,49],bgCyanBright:[106,49],bgWhiteBright:[107,49]}};c.color.grey=c.color.gray;for(const o of Object.keys(c)){const n=c[o];for(const o of Object.keys(n)){const e=n[o];c[o]={open:"[".concat(e[0],"m"),close:"[".concat(e[1],"m")},n[o]=c[o],i.set(e[0],e[1])}Object.defineProperty(c,o,{value:n,enumerable:!1}),Object.defineProperty(c,"codes",{value:i,enumerable:!1})}const a=o=>o,l=(o,n,e)=>[o,n,e];c.color.close="",c.bgColor.close="",c.color.ansi={ansi:e(a,0)},c.color.ansi256={ansi256:t(a,0)},c.color.ansi16m={rgb:r(l,0)},c.bgColor.ansi={ansi:e(a,10)},c.bgColor.ansi256={ansi256:t(a,10)},c.bgColor.ansi16m={rgb:r(l,10)};for(let g of Object.keys(n)){if("object"!==o(n[g]))continue;const i=n[g];"ansi16"===g&&(g="ansi"),"ansi16"in i&&(c.color.ansi[g]=e(i.ansi16,0),c.bgColor.ansi[g]=e(i.ansi16,10)),"ansi256"in i&&(c.color.ansi256[g]=t(i.ansi256,0),c.bgColor.ansi256[g]=t(i.ansi256,10)),"rgb"in i&&(c.color.ansi16m[g]=r(i.rgb,0),c.bgColor.ansi16m[g]=r(i.rgb,10))}return c}Object.defineProperty(module,"exports",{enumerable:!0,get:i}); -},{"color-convert":"PawV"}],"foIL":[function(require,module,exports) { -"use strict";module.exports={stdout:!1,stderr:!1}; -},{}],"PLSQ":[function(require,module,exports) { -"use strict";const t=/(?:\\(u[a-f\d]{4}|x[a-f\d]{2}|.))|(?:\{(~)?(\w+(?:\([^)]*\))?(?:\.\w+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n)))|(\})|((?:.|[\r\n\f])+?)/gi,e=/(?:^|\.)(\w+)(?:\(([^)]*)\))?/g,n=/^(['"])((?:\\.|(?!\1)[^\\])*)\1$/,r=/\\(u[a-f\d]{4}|x[a-f\d]{2}|.)|([^\\])/gi,s=new Map([["n","\n"],["r","\r"],["t","\t"],["b","\b"],["f","\f"],["v","\v"],["0","\0"],["\\","\\"],["e",""],["a",""]]);function o(t){return"u"===t[0]&&5===t.length||"x"===t[0]&&3===t.length?String.fromCharCode(parseInt(t.slice(1),16)):s.get(t)||t}function l(t,e){const s=[],l=e.trim().split(/\s*,\s*/g);let i;for(const c of l)if(isNaN(c)){if(!(i=c.match(n)))throw new Error("Invalid Chalk template style argument: ".concat(c," (in style '").concat(t,"')"));s.push(i[2].replace(r,(t,e,n)=>e?o(e):n))}else s.push(Number(c));return s}function i(t){e.lastIndex=0;const n=[];let r;for(;null!==(r=e.exec(t));){const t=r[1];if(r[2]){const e=l(t,r[2]);n.push([t].concat(e))}else n.push([t])}return n}function c(t,e){const n={};for(const s of e)for(const t of s.styles)n[t[0]]=s.inverse?null:t.slice(1);let r=t;for(const s of Object.keys(n))if(Array.isArray(n[s])){if(!(s in r))throw new Error("Unknown Chalk style: ".concat(s));r=n[s].length>0?r[s].apply(r,n[s]):r[s]}return r}module.exports=((e,n)=>{const r=[],s=[];let l=[];if(n.replace(t,(t,n,a,f,u,h)=>{if(n)l.push(o(n));else if(f){const t=l.join("");l=[],s.push(0===r.length?t:c(e,r)(t)),r.push({inverse:a,styles:i(f)})}else if(u){if(0===r.length)throw new Error("Found extraneous } in Chalk template literal");s.push(c(e,r)(l.join(""))),l=[],r.pop()}else l.push(h)}),s.push(l.join("")),r.length>0){const t="Chalk template literal is missing ".concat(r.length," closing bracket").concat(1===r.length?"":"s"," (`}`)");throw new Error(t)}return s.join("")}); -},{}],"g5I+":[function(require,module,exports) { - -var t,e,n=module.exports={};function r(){throw new Error("setTimeout has not been defined")}function o(){throw new Error("clearTimeout has not been defined")}function i(e){if(t===setTimeout)return setTimeout(e,0);if((t===r||!t)&&setTimeout)return t=setTimeout,setTimeout(e,0);try{return t(e,0)}catch(n){try{return t.call(null,e,0)}catch(n){return t.call(this,e,0)}}}function u(t){if(e===clearTimeout)return clearTimeout(t);if((e===o||!e)&&clearTimeout)return e=clearTimeout,clearTimeout(t);try{return e(t)}catch(n){try{return e.call(null,t)}catch(n){return e.call(this,t)}}}!function(){try{t="function"==typeof setTimeout?setTimeout:r}catch(n){t=r}try{e="function"==typeof clearTimeout?clearTimeout:o}catch(n){e=o}}();var c,s=[],l=!1,a=-1;function f(){l&&c&&(l=!1,c.length?s=c.concat(s):a=-1,s.length&&h())}function h(){if(!l){var t=i(f);l=!0;for(var e=s.length;e;){for(c=s,s=[];++a1)for(var n=1;n0}function p(e){if(!this||!(this instanceof p)||this.template){const t={};return a(t,e),t.template=function(){const e=[].slice.call(arguments);return y.apply(null,[t.template].concat(e))},Object.setPrototypeOf(t,p.prototype),Object.setPrototypeOf(t.template,t),t.template.constructor=p,t.template}a(this,e)}l&&(o.blue.open="");for(const g of Object.keys(o))o[g].closeRe=new RegExp(t(o[g].close),"g"),i[g]={get:function(){const e=o[g];return f.call(this,this._styles?this._styles.concat(e):[e],this._empty,g)}};i.visible={get:function(){return f.call(this,this._styles||[],!0,"visible")}},o.color.closeRe=new RegExp(t(o.color.close),"g");for(const g of Object.keys(o.color.ansi))c.has(g)||(i[g]={get:function(){const e=this.level;return function(){const t={open:o.color[r[e]][g].apply(null,arguments),close:o.color.close,closeRe:o.color.closeRe};return f.call(this,this._styles?this._styles.concat(t):[t],this._empty,g)}}});o.bgColor.closeRe=new RegExp(t(o.bgColor.close),"g");for(const g of Object.keys(o.bgColor.ansi)){if(c.has(g))continue;i["bg"+g[0].toUpperCase()+g.slice(1)]={get:function(){const e=this.level;return function(){const t={open:o.bgColor[r[e]][g].apply(null,arguments),close:o.bgColor.close,closeRe:o.bgColor.closeRe};return f.call(this,this._styles?this._styles.concat(t):[t],this._empty,g)}}}}const u=Object.defineProperties(()=>{},i);function f(e,t,o){const s=function(){return h.apply(s,arguments)};s._styles=e,s._empty=t;const n=this;return Object.defineProperty(s,"level",{enumerable:!0,get:function(){return n.level},set:function(e){n.level=e}}),Object.defineProperty(s,"enabled",{enumerable:!0,get:function(){return n.enabled},set:function(e){n.enabled=e}}),s.hasGrey=this.hasGrey||"gray"===o||"grey"===o,s.__proto__=u,s}function h(){const e=arguments,t=e.length;let s=String(arguments[0]);if(0===t)return"";if(t>1)for(let o=1;o":function(t){t.addToken(t.nextMatch("=")?h.GREATER_EQUAL:h.GREATER)},"<":function(t){t.addToken(t.nextMatch("=")?h.LESS_EQUAL:h.LESS)}," ":r,"\t":r,"\r":r,"\n":function(t){t.newline()},'"':function(t){t.handleStringLiterals()}},a=function(t){return/\d/.test(t)},l=function(t){return/[a-zA-Z_]/.test(t)},f=function(t){return l(t)||a(t)},d=function(){function n(e){t(this,n),this.source=e,this.length=e.length,this.tokens=[],this.startPosition=null,this.column=0,this.start=0,this.line=1,this.current=0}return e(n,null,[{key:"tokens",get:function(){return o}},{key:"tokenEnum",get:function(){return h}}]),e(n,[{key:"handleStringLiterals",value:function(){for(;'"'!==this.peek()&&""!==this.peek();)"\n"===this.peek()&&this.newline(),this.chomp();if(""===this.peek())throw s("Unfinished string",this.startPosition,this.endPosition);this.chomp();var t=this.source.substring(this.start+1,this.current-1);this.addToken(h.STRING,t)}},{key:"handleNumberLiterals",value:function(){for(var t=!1;a(this.peek())||!t&&"."===this.peek();)"."===this.peek()&&(t=!0),this.chomp();var n=this.source.substring(this.start,this.current);this.addToken(h.NUMBER,parseFloat(n))}},{key:"handleIdentifiers",value:function(){for(;f(this.peek());)this.chomp();var t=this.source.substring(this.start,this.current);u[t]?this.addToken(u[t],t):this.addToken(h.IDENTIFIER,t)}},{key:"scanTokens",value:function(){for(;this.current1&&void 0!==arguments[1]?arguments[1]:null,e=this.source.substring(this.start,this.current);this.tokens.push(new k(t,e,n,new E(this.column,this.line,this.current),this.startPosition))}},{key:"increment",value:function(){this.current++,this.column++}},{key:"newline",value:function(){this.line++,this.column=0}},{key:"chomp",value:function(){return this.increment(),this.source.charAt(this.current-1)}},{key:"peek",value:function(){return this.source.charAt(this.current)}},{key:"nextMatch",value:function(t){return this.peek()===t&&(this.increment(),!0)}},{key:"endPosition",get:function(){return new E(this.column-1,this.line,this.current)}}]),n}(),E=function n(e,i,s){t(this,n),this.col=e,this.line=i,this.index=s},k=function n(e,i,s,r,o){t(this,n),this.type=e,this.lexeme=i,this.literal=s,this.startCoordinates=o,this.endCoordinates=r};module.exports=d; -},{"./errors":"p8GN"}],"39eF":[function(require,module,exports) { -function t(t,n){for(var i=0;i"}}]),t}(),j=function t(n,i){c(this,t),this.keyword=n,this.value=i},x=function t(n,i,e){c(this,t),this.name=n,this.params=i,this.bodyStatements=e};module.exports={Var:p,Binary:h,Unary:a,Block:v,Call:w,Callable:_,While:O,Literal:l,Return:j,Logical:f,LoxFunction:x,Grouping:y,Condition:S,ExpressionStatement:b,PrintStatement:m,VarStatement:g,Assignment:d}; -},{}],"CUYV":[function(require,module,exports) { -function t(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function e(t,e){for(var n=0;n2?i-2:0),s=2;s1?e-1:0),i=1;in;case L.GREATER_EQUAL:return R(t.operator,n,e),e>=n;case L.LESS:return R(t.operator,n,e),e2&&void 0!==arguments[2]&&arguments[2];try{var l=new e(o).scanTokens();s&&console.log(l);var d=new n(l).parse();s&&console.log(d);var c,u=new i(a),v=!0,x=!1,f=void 0;try{for(var g,C=d[Symbol.iterator]();!(v=(g=C.next()).done);v=!0){var p=g.value;c=u.interpret(p)}}catch(k){x=!0,f=k}finally{try{v||null==C.return||C.return()}finally{if(x)throw f}}return c}catch(O){if(console.log(O),O instanceof t){console.error("Parse Error:",O.toString(),"at ".concat(O.endCoordinates.line,":").concat(O.endCoordinates.col+1));var h=o.lastIndexOf("\n",O.startCoordinates.index),q=h<0?0:h,y=o.substr(q,O.startCoordinates.index),b=o.substr(O.startCoordinates.index,O.endCoordinates.index),m=o.indexOf("\n",O.endCoordinates.index),w=m<0?o.length:m,E=o.substr(O.endCoordinates.index,w);console.error(y+r.bgRed(b)+E)}else console.log("Unexpected javascript Error: "),console.log(O)}};module.exports={run:s,Environment:a}; -},{"chalk":"ug4C","./tokenizer":"u74b","./parser":"CUYV","./errors":"p8GN","./interpreter":"lmrS","./environment":"brut"}],"KVVd":[function(require,module,exports) { - -},{}],"3hpa":[function(require,module,exports) { -"use strict";var n=require("./index"),e=require("fs"),t=document.getElementById("code"),r=['// Interactive Iterative Fibonacci\nvar a = 0;\nvar b = 1;\nvar limit = prompt("Limit to find fib numbers", 10000);\n\nwhile (a < limit) {\n print a;\n var temp = a;\n a = b;\n b = temp + b;\n}\n','// Linked List via Closures\nfun Link(value, next) {\n fun access(method) {\n if (method == "value") return value;\n if (method == "next") return next;\n print "unknown method " + method;\n }\n\n return access;\n}\n\nfun traverse(n, fn) {\n fn(n);\n if (n("next") != nil) {\n return traverse(n("next"), fn);\n }\n return n;\n}\n\nfun printValue (n) {\n print n("value");\n}\n\nfun blank (n) {}\n\nfun printTail (n) {\n var tail = traverse(n, blank);\n print tail("value");\n}\n\nvar list = Link(1, Link(2, Link(3, nil)));\n\ntraverse(list, printValue);\nprintTail(list, printTail);'],i=r.map(function(n){return{name:n.split("\n")[0].replace(/[^\w\s]/gi,"").trim(),program:n}}),a=document.getElementById("exampleProgram"),u=i.map(function(n,e){return'")}).join("\n");a.innerHTML=u,a.onchange=function(n){var e=n.target.value;t.value=i[e].program},t.value=i[0].program;var l=document.getElementById("run");l.onclick=function(){var e=t.value,r=new n.Environment;r.setBuiltin("alert",function(n,e){return alert(e[0])}),r.setBuiltin("confirm",function(n,e){return confirm(e[0])}),r.setBuiltin("prompt",function(n,e){return prompt(e[0],e.length>1?e[1]:null)}),(0,n.run)(e,r)}; -},{"./index":"Focm","fs":"KVVd"}]},{},["3hpa"], null) \ No newline at end of file diff --git a/docs/browser.da209bc9.js b/docs/browser.da209bc9.js deleted file mode 100644 index 25b9708..0000000 --- a/docs/browser.da209bc9.js +++ /dev/null @@ -1,43 +0,0 @@ -parcelRequire=function(e,r,t,n){var i,o="function"==typeof parcelRequire&&parcelRequire,u="function"==typeof require&&require;function f(t,n){if(!r[t]){if(!e[t]){var i="function"==typeof parcelRequire&&parcelRequire;if(!n&&i)return i(t,!0);if(o)return o(t,!0);if(u&&"string"==typeof t)return u(t);var c=new Error("Cannot find module '"+t+"'");throw c.code="MODULE_NOT_FOUND",c}p.resolve=function(r){return e[t][1][r]||r},p.cache={};var l=r[t]=new f.Module(t);e[t][0].call(l.exports,p,l,l.exports,this)}return r[t].exports;function p(e){return f(p.resolve(e))}}f.isParcelRequire=!0,f.Module=function(e){this.id=e,this.bundle=f,this.exports={}},f.modules=e,f.cache=r,f.parent=o,f.register=function(r,t){e[r]=[function(e,r){r.exports=t},{}]};for(var c=0;c1&&(e-=1)),[360*e,100*h,100*s]},t.rgb.hwb=function(r){var n=r[0],a=r[1],e=r[2];return[t.rgb.hsl(r)[0],100*(1/255*Math.min(n,Math.min(a,e))),100*(e=1-1/255*Math.max(n,Math.max(a,e)))]},t.rgb.cmyk=function(r){var n,a=r[0]/255,t=r[1]/255,e=r[2]/255;return[100*((1-a-(n=Math.min(1-a,1-t,1-e)))/(1-n)||0),100*((1-t-n)/(1-n)||0),100*((1-e-n)/(1-n)||0),100*n]},t.rgb.keyword=function(a){var t=n[a];if(t)return t;var e,h=1/0;for(var u in r)if(r.hasOwnProperty(u)){var c=o(a,r[u]);c.04045?Math.pow((n+.055)/1.055,2.4):n/12.92)+.3576*(a=a>.04045?Math.pow((a+.055)/1.055,2.4):a/12.92)+.1805*(t=t>.04045?Math.pow((t+.055)/1.055,2.4):t/12.92)),100*(.2126*n+.7152*a+.0722*t),100*(.0193*n+.1192*a+.9505*t)]},t.rgb.lab=function(r){var n=t.rgb.xyz(r),a=n[0],e=n[1],h=n[2];return e/=100,h/=108.883,a=(a/=95.047)>.008856?Math.pow(a,1/3):7.787*a+16/116,[116*(e=e>.008856?Math.pow(e,1/3):7.787*e+16/116)-16,500*(a-e),200*(e-(h=h>.008856?Math.pow(h,1/3):7.787*h+16/116))]},t.hsl.rgb=function(r){var n,a,t,e,h,u=r[0]/360,o=r[1]/100,c=r[2]/100;if(0===o)return[h=255*c,h,h];n=2*c-(a=c<.5?c*(1+o):c+o-c*o),e=[0,0,0];for(var s=0;s<3;s++)(t=u+1/3*-(s-1))<0&&t++,t>1&&t--,h=6*t<1?n+6*(a-n)*t:2*t<1?a:3*t<2?n+(a-n)*(2/3-t)*6:n,e[s]=255*h;return e},t.hsl.hsv=function(r){var n=r[0],a=r[1]/100,t=r[2]/100,e=a,h=Math.max(t,.01);return a*=(t*=2)<=1?t:2-t,e*=h<=1?h:2-h,[n,100*(0===t?2*e/(h+e):2*a/(t+a)),100*((t+a)/2)]},t.hsv.rgb=function(r){var n=r[0]/60,a=r[1]/100,t=r[2]/100,e=Math.floor(n)%6,h=n-Math.floor(n),u=255*t*(1-a),o=255*t*(1-a*h),c=255*t*(1-a*(1-h));switch(t*=255,e){case 0:return[t,c,u];case 1:return[o,t,u];case 2:return[u,t,c];case 3:return[u,o,t];case 4:return[c,u,t];case 5:return[t,u,o]}},t.hsv.hsl=function(r){var n,a,t,e=r[0],h=r[1]/100,u=r[2]/100,o=Math.max(u,.01);return t=(2-h)*u,a=h*o,[e,100*(a=(a/=(n=(2-h)*o)<=1?n:2-n)||0),100*(t/=2)]},t.hwb.rgb=function(r){var n,a,t,e,h,u,o,c=r[0]/360,s=r[1]/100,l=r[2]/100,i=s+l;switch(i>1&&(s/=i,l/=i),t=6*c-(n=Math.floor(6*c)),0!=(1&n)&&(t=1-t),e=s+t*((a=1-l)-s),n){default:case 6:case 0:h=a,u=e,o=s;break;case 1:h=e,u=a,o=s;break;case 2:h=s,u=a,o=e;break;case 3:h=s,u=e,o=a;break;case 4:h=e,u=s,o=a;break;case 5:h=a,u=s,o=e}return[255*h,255*u,255*o]},t.cmyk.rgb=function(r){var n=r[0]/100,a=r[1]/100,t=r[2]/100,e=r[3]/100;return[255*(1-Math.min(1,n*(1-e)+e)),255*(1-Math.min(1,a*(1-e)+e)),255*(1-Math.min(1,t*(1-e)+e))]},t.xyz.rgb=function(r){var n,a,t,e=r[0]/100,h=r[1]/100,u=r[2]/100;return a=-.9689*e+1.8758*h+.0415*u,t=.0557*e+-.204*h+1.057*u,n=(n=3.2406*e+-1.5372*h+-.4986*u)>.0031308?1.055*Math.pow(n,1/2.4)-.055:12.92*n,a=a>.0031308?1.055*Math.pow(a,1/2.4)-.055:12.92*a,t=t>.0031308?1.055*Math.pow(t,1/2.4)-.055:12.92*t,[255*(n=Math.min(Math.max(0,n),1)),255*(a=Math.min(Math.max(0,a),1)),255*(t=Math.min(Math.max(0,t),1))]},t.xyz.lab=function(r){var n=r[0],a=r[1],t=r[2];return a/=100,t/=108.883,n=(n/=95.047)>.008856?Math.pow(n,1/3):7.787*n+16/116,[116*(a=a>.008856?Math.pow(a,1/3):7.787*a+16/116)-16,500*(n-a),200*(a-(t=t>.008856?Math.pow(t,1/3):7.787*t+16/116))]},t.lab.xyz=function(r){var n,a,t,e=r[0];n=r[1]/500+(a=(e+16)/116),t=a-r[2]/200;var h=Math.pow(a,3),u=Math.pow(n,3),o=Math.pow(t,3);return a=h>.008856?h:(a-16/116)/7.787,n=u>.008856?u:(n-16/116)/7.787,t=o>.008856?o:(t-16/116)/7.787,[n*=95.047,a*=100,t*=108.883]},t.lab.lch=function(r){var n,a=r[0],t=r[1],e=r[2];return(n=360*Math.atan2(e,t)/2/Math.PI)<0&&(n+=360),[a,Math.sqrt(t*t+e*e),n]},t.lch.lab=function(r){var n,a=r[0],t=r[1];return n=r[2]/360*2*Math.PI,[a,t*Math.cos(n),t*Math.sin(n)]},t.rgb.ansi16=function(r){var n=r[0],a=r[1],e=r[2],h=1 in arguments?arguments[1]:t.rgb.hsv(r)[2];if(0===(h=Math.round(h/50)))return 30;var u=30+(Math.round(e/255)<<2|Math.round(a/255)<<1|Math.round(n/255));return 2===h&&(u+=60),u},t.hsv.ansi16=function(r){return t.rgb.ansi16(t.hsv.rgb(r),r[2])},t.rgb.ansi256=function(r){var n=r[0],a=r[1],t=r[2];return n===a&&a===t?n<8?16:n>248?231:Math.round((n-8)/247*24)+232:16+36*Math.round(n/255*5)+6*Math.round(a/255*5)+Math.round(t/255*5)},t.ansi16.rgb=function(r){var n=r%10;if(0===n||7===n)return r>50&&(n+=3.5),[n=n/10.5*255,n,n];var a=.5*(1+~~(r>50));return[(1&n)*a*255,(n>>1&1)*a*255,(n>>2&1)*a*255]},t.ansi256.rgb=function(r){if(r>=232){var n=10*(r-232)+8;return[n,n,n]}var a;return r-=16,[Math.floor(r/36)/5*255,Math.floor((a=r%36)/6)/5*255,a%6/5*255]},t.rgb.hex=function(r){var n=(((255&Math.round(r[0]))<<16)+((255&Math.round(r[1]))<<8)+(255&Math.round(r[2]))).toString(16).toUpperCase();return"000000".substring(n.length)+n},t.hex.rgb=function(r){var n=r.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);if(!n)return[0,0,0];var a=n[0];3===n[0].length&&(a=a.split("").map(function(r){return r+r}).join(""));var t=parseInt(a,16);return[t>>16&255,t>>8&255,255&t]},t.rgb.hcg=function(r){var n,a=r[0]/255,t=r[1]/255,e=r[2]/255,h=Math.max(Math.max(a,t),e),u=Math.min(Math.min(a,t),e),o=h-u;return n=o<=0?0:h===a?(t-e)/o%6:h===t?2+(e-a)/o:4+(a-t)/o+4,n/=6,[360*(n%=1),100*o,100*(o<1?u/(1-o):0)]},t.hsl.hcg=function(r){var n=r[1]/100,a=r[2]/100,t=1,e=0;return(t=a<.5?2*n*a:2*n*(1-a))<1&&(e=(a-.5*t)/(1-t)),[r[0],100*t,100*e]},t.hsv.hcg=function(r){var n=r[1]/100,a=r[2]/100,t=n*a,e=0;return t<1&&(e=(a-t)/(1-t)),[r[0],100*t,100*e]},t.hcg.rgb=function(r){var n=r[0]/360,a=r[1]/100,t=r[2]/100;if(0===a)return[255*t,255*t,255*t];var e,h=[0,0,0],u=n%1*6,o=u%1,c=1-o;switch(Math.floor(u)){case 0:h[0]=1,h[1]=o,h[2]=0;break;case 1:h[0]=c,h[1]=1,h[2]=0;break;case 2:h[0]=0,h[1]=1,h[2]=o;break;case 3:h[0]=0,h[1]=c,h[2]=1;break;case 4:h[0]=o,h[1]=0,h[2]=1;break;default:h[0]=1,h[1]=0,h[2]=c}return e=(1-a)*t,[255*(a*h[0]+e),255*(a*h[1]+e),255*(a*h[2]+e)]},t.hcg.hsv=function(r){var n=r[1]/100,a=n+r[2]/100*(1-n),t=0;return a>0&&(t=n/a),[r[0],100*t,100*a]},t.hcg.hsl=function(r){var n=r[1]/100,a=r[2]/100*(1-n)+.5*n,t=0;return a>0&&a<.5?t=n/(2*a):a>=.5&&a<1&&(t=n/(2*(1-a))),[r[0],100*t,100*a]},t.hcg.hwb=function(r){var n=r[1]/100,a=n+r[2]/100*(1-n);return[r[0],100*(a-n),100*(1-a)]},t.hwb.hcg=function(r){var n=r[1]/100,a=1-r[2]/100,t=a-n,e=0;return t<1&&(e=(a-t)/(1-t)),[r[0],100*t,100*e]},t.apple.rgb=function(r){return[r[0]/65535*255,r[1]/65535*255,r[2]/65535*255]},t.rgb.apple=function(r){return[r[0]/255*65535,r[1]/255*65535,r[2]/255*65535]},t.gray.rgb=function(r){return[r[0]/100*255,r[0]/100*255,r[0]/100*255]},t.gray.hsl=t.gray.hsv=function(r){return[0,0,r[0]]},t.gray.hwb=function(r){return[0,100,r[0]]},t.gray.cmyk=function(r){return[0,0,0,r[0]]},t.gray.lab=function(r){return[r[0],0,0]},t.gray.hex=function(r){var n=255&Math.round(r[0]/100*255),a=((n<<16)+(n<<8)+n).toString(16).toUpperCase();return"000000".substring(a.length)+a},t.rgb.gray=function(r){return[(r[0]+r[1]+r[2])/3/255*100]}; -},{"color-name":"auEH"}],"fg2k":[function(require,module,exports) { -var n=require("./conversions");function r(){for(var r={},e=Object.keys(n),t=e.length,a=0;a1&&(n=Array.prototype.slice.call(arguments)),e(n))};return"conversion"in e&&(n.conversion=e.conversion),n}function c(e){var n=function(n){if(null==n)return n;arguments.length>1&&(n=Array.prototype.slice.call(arguments));var r=e(n);if("object"==typeof r)for(var o=r.length,t=0;t(function(){const t=o.apply(n,arguments);return"[".concat(t+e,"m")}),t=(o,e)=>(function(){const t=o.apply(n,arguments);return"[".concat(38+e,";5;").concat(t,"m")}),r=(o,e)=>(function(){const t=o.apply(n,arguments);return"[".concat(38+e,";2;").concat(t[0],";").concat(t[1],";").concat(t[2],"m")});function i(){const i=new Map,c={modifier:{reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],inverse:[7,27],hidden:[8,28],strikethrough:[9,29]},color:{black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],gray:[90,39],redBright:[91,39],greenBright:[92,39],yellowBright:[93,39],blueBright:[94,39],magentaBright:[95,39],cyanBright:[96,39],whiteBright:[97,39]},bgColor:{bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],bgBlackBright:[100,49],bgRedBright:[101,49],bgGreenBright:[102,49],bgYellowBright:[103,49],bgBlueBright:[104,49],bgMagentaBright:[105,49],bgCyanBright:[106,49],bgWhiteBright:[107,49]}};c.color.grey=c.color.gray;for(const o of Object.keys(c)){const n=c[o];for(const o of Object.keys(n)){const e=n[o];c[o]={open:"[".concat(e[0],"m"),close:"[".concat(e[1],"m")},n[o]=c[o],i.set(e[0],e[1])}Object.defineProperty(c,o,{value:n,enumerable:!1}),Object.defineProperty(c,"codes",{value:i,enumerable:!1})}const a=o=>o,l=(o,n,e)=>[o,n,e];c.color.close="",c.bgColor.close="",c.color.ansi={ansi:e(a,0)},c.color.ansi256={ansi256:t(a,0)},c.color.ansi16m={rgb:r(l,0)},c.bgColor.ansi={ansi:e(a,10)},c.bgColor.ansi256={ansi256:t(a,10)},c.bgColor.ansi16m={rgb:r(l,10)};for(let g of Object.keys(n)){if("object"!==o(n[g]))continue;const i=n[g];"ansi16"===g&&(g="ansi"),"ansi16"in i&&(c.color.ansi[g]=e(i.ansi16,0),c.bgColor.ansi[g]=e(i.ansi16,10)),"ansi256"in i&&(c.color.ansi256[g]=t(i.ansi256,0),c.bgColor.ansi256[g]=t(i.ansi256,10)),"rgb"in i&&(c.color.ansi16m[g]=r(i.rgb,0),c.bgColor.ansi16m[g]=r(i.rgb,10))}return c}Object.defineProperty(module,"exports",{enumerable:!0,get:i}); -},{"color-convert":"PawV"}],"foIL":[function(require,module,exports) { -"use strict";module.exports={stdout:!1,stderr:!1}; -},{}],"PLSQ":[function(require,module,exports) { -"use strict";const t=/(?:\\(u[a-f\d]{4}|x[a-f\d]{2}|.))|(?:\{(~)?(\w+(?:\([^)]*\))?(?:\.\w+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n)))|(\})|((?:.|[\r\n\f])+?)/gi,e=/(?:^|\.)(\w+)(?:\(([^)]*)\))?/g,n=/^(['"])((?:\\.|(?!\1)[^\\])*)\1$/,r=/\\(u[a-f\d]{4}|x[a-f\d]{2}|.)|([^\\])/gi,s=new Map([["n","\n"],["r","\r"],["t","\t"],["b","\b"],["f","\f"],["v","\v"],["0","\0"],["\\","\\"],["e",""],["a",""]]);function o(t){return"u"===t[0]&&5===t.length||"x"===t[0]&&3===t.length?String.fromCharCode(parseInt(t.slice(1),16)):s.get(t)||t}function l(t,e){const s=[],l=e.trim().split(/\s*,\s*/g);let i;for(const c of l)if(isNaN(c)){if(!(i=c.match(n)))throw new Error("Invalid Chalk template style argument: ".concat(c," (in style '").concat(t,"')"));s.push(i[2].replace(r,(t,e,n)=>e?o(e):n))}else s.push(Number(c));return s}function i(t){e.lastIndex=0;const n=[];let r;for(;null!==(r=e.exec(t));){const t=r[1];if(r[2]){const e=l(t,r[2]);n.push([t].concat(e))}else n.push([t])}return n}function c(t,e){const n={};for(const s of e)for(const t of s.styles)n[t[0]]=s.inverse?null:t.slice(1);let r=t;for(const s of Object.keys(n))if(Array.isArray(n[s])){if(!(s in r))throw new Error("Unknown Chalk style: ".concat(s));r=n[s].length>0?r[s].apply(r,n[s]):r[s]}return r}module.exports=((e,n)=>{const r=[],s=[];let l=[];if(n.replace(t,(t,n,a,f,u,h)=>{if(n)l.push(o(n));else if(f){const t=l.join("");l=[],s.push(0===r.length?t:c(e,r)(t)),r.push({inverse:a,styles:i(f)})}else if(u){if(0===r.length)throw new Error("Found extraneous } in Chalk template literal");s.push(c(e,r)(l.join(""))),l=[],r.pop()}else l.push(h)}),s.push(l.join("")),r.length>0){const t="Chalk template literal is missing ".concat(r.length," closing bracket").concat(1===r.length?"":"s"," (`}`)");throw new Error(t)}return s.join("")}); -},{}],"g5I+":[function(require,module,exports) { - -var t,e,n=module.exports={};function r(){throw new Error("setTimeout has not been defined")}function o(){throw new Error("clearTimeout has not been defined")}function i(e){if(t===setTimeout)return setTimeout(e,0);if((t===r||!t)&&setTimeout)return t=setTimeout,setTimeout(e,0);try{return t(e,0)}catch(n){try{return t.call(null,e,0)}catch(n){return t.call(this,e,0)}}}function u(t){if(e===clearTimeout)return clearTimeout(t);if((e===o||!e)&&clearTimeout)return e=clearTimeout,clearTimeout(t);try{return e(t)}catch(n){try{return e.call(null,t)}catch(n){return e.call(this,t)}}}!function(){try{t="function"==typeof setTimeout?setTimeout:r}catch(n){t=r}try{e="function"==typeof clearTimeout?clearTimeout:o}catch(n){e=o}}();var c,s=[],l=!1,a=-1;function f(){l&&c&&(l=!1,c.length?s=c.concat(s):a=-1,s.length&&h())}function h(){if(!l){var t=i(f);l=!0;for(var e=s.length;e;){for(c=s,s=[];++a1)for(var n=1;n0}function p(e){if(!this||!(this instanceof p)||this.template){const t={};return a(t,e),t.template=function(){const e=[].slice.call(arguments);return y.apply(null,[t.template].concat(e))},Object.setPrototypeOf(t,p.prototype),Object.setPrototypeOf(t.template,t),t.template.constructor=p,t.template}a(this,e)}l&&(o.blue.open="");for(const g of Object.keys(o))o[g].closeRe=new RegExp(t(o[g].close),"g"),i[g]={get:function(){const e=o[g];return f.call(this,this._styles?this._styles.concat(e):[e],this._empty,g)}};i.visible={get:function(){return f.call(this,this._styles||[],!0,"visible")}},o.color.closeRe=new RegExp(t(o.color.close),"g");for(const g of Object.keys(o.color.ansi))c.has(g)||(i[g]={get:function(){const e=this.level;return function(){const t={open:o.color[r[e]][g].apply(null,arguments),close:o.color.close,closeRe:o.color.closeRe};return f.call(this,this._styles?this._styles.concat(t):[t],this._empty,g)}}});o.bgColor.closeRe=new RegExp(t(o.bgColor.close),"g");for(const g of Object.keys(o.bgColor.ansi)){if(c.has(g))continue;i["bg"+g[0].toUpperCase()+g.slice(1)]={get:function(){const e=this.level;return function(){const t={open:o.bgColor[r[e]][g].apply(null,arguments),close:o.bgColor.close,closeRe:o.bgColor.closeRe};return f.call(this,this._styles?this._styles.concat(t):[t],this._empty,g)}}}}const u=Object.defineProperties(()=>{},i);function f(e,t,o){const s=function(){return h.apply(s,arguments)};s._styles=e,s._empty=t;const n=this;return Object.defineProperty(s,"level",{enumerable:!0,get:function(){return n.level},set:function(e){n.level=e}}),Object.defineProperty(s,"enabled",{enumerable:!0,get:function(){return n.enabled},set:function(e){n.enabled=e}}),s.hasGrey=this.hasGrey||"gray"===o||"grey"===o,s.__proto__=u,s}function h(){const e=arguments,t=e.length;let s=String(arguments[0]);if(0===t)return"";if(t>1)for(let o=1;o":function(t){t.addToken(t.nextMatch("=")?h.GREATER_EQUAL:h.GREATER)},"<":function(t){t.addToken(t.nextMatch("=")?h.LESS_EQUAL:h.LESS)}," ":r,"\t":r,"\r":r,"\n":function(t){t.newline()},'"':function(t){t.handleStringLiterals()}},a=function(t){return/\d/.test(t)},l=function(t){return/[a-zA-Z_]/.test(t)},f=function(t){return l(t)||a(t)},d=function(){function n(e){t(this,n),this.source=e,this.length=e.length,this.tokens=[],this.startPosition=null,this.column=0,this.start=0,this.line=1,this.current=0}return e(n,null,[{key:"tokens",get:function(){return o}},{key:"tokenEnum",get:function(){return h}}]),e(n,[{key:"handleStringLiterals",value:function(){for(;'"'!==this.peek()&&""!==this.peek();)"\n"===this.peek()&&this.newline(),this.chomp();if(""===this.peek())throw s("Unfinished string",this.startPosition,this.endPosition);this.chomp();var t=this.source.substring(this.start+1,this.current-1);this.addToken(h.STRING,t)}},{key:"handleNumberLiterals",value:function(){for(var t=!1;a(this.peek())||!t&&"."===this.peek();)"."===this.peek()&&(t=!0),this.chomp();var n=this.source.substring(this.start,this.current);this.addToken(h.NUMBER,parseFloat(n))}},{key:"handleIdentifiers",value:function(){for(;f(this.peek());)this.chomp();var t=this.source.substring(this.start,this.current);u[t]?this.addToken(u[t],t):this.addToken(h.IDENTIFIER,t)}},{key:"scanTokens",value:function(){for(;this.current1&&void 0!==arguments[1]?arguments[1]:null,e=this.source.substring(this.start,this.current);this.tokens.push(new k(t,e,n,new E(this.column,this.line,this.current),this.startPosition))}},{key:"increment",value:function(){this.current++,this.column++}},{key:"newline",value:function(){this.line++,this.column=0}},{key:"chomp",value:function(){return this.increment(),this.source.charAt(this.current-1)}},{key:"peek",value:function(){return this.source.charAt(this.current)}},{key:"nextMatch",value:function(t){return this.peek()===t&&(this.increment(),!0)}},{key:"endPosition",get:function(){return new E(this.column-1,this.line,this.current)}}]),n}(),E=function n(e,i,s){t(this,n),this.col=e,this.line=i,this.index=s},k=function n(e,i,s,r,o){t(this,n),this.type=e,this.lexeme=i,this.literal=s,this.startCoordinates=o,this.endCoordinates=r};module.exports=d; -},{"./errors":"p8GN"}],"39eF":[function(require,module,exports) { -function t(n){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(n)}function n(n,e){return!e||"object"!==t(e)&&"function"!=typeof e?i(n):e}function i(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function e(t){return(e=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function o(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(n&&n.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),n&&r(t,n)}function r(t,n){return(r=Object.setPrototypeOf||function(t,n){return t.__proto__=n,t})(t,n)}function s(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}var h=function t(n,i,e){s(this,t),this.left=n,this.operator=i,this.right=e},u=function(t){function i(){return s(this,i),n(this,e(i).apply(this,arguments))}return o(i,h),i}(),c=function t(n,i){s(this,t),this.operator=n,this.right=i},a=function t(n){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"regular";s(this,t),this.context=i,this.value=n},f=function t(n){s(this,t),this.name=n},l=function t(n,i){s(this,t),this.object=n,this.name=i},p=function t(n,i,e){s(this,t),this.object=n,this.name=i,this.value=e},y=function t(n){s(this,t),this.expression=n},m=function(t){function i(t){var o,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"regular";return s(this,i),(o=n(this,e(i).call(this,t))).context=r,o}return o(i,y),i}(),b=function(t){function i(){return s(this,i),n(this,e(i).apply(this,arguments))}return o(i,y),i}(),g=function t(n,i){s(this,t),this.name=n,this.initializer=i},d=function t(n,i){s(this,t),this.name=n,this.value=i},v=function t(n){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"regular";s(this,t),this.context=i,this.statements=n},S=function t(n,i,e){s(this,t),this.condition=n,this.thenBranch=i,this.elseBranch=e},w=function t(n,i){var e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"while";s(this,t),this.context=e,this.condition=n,this.body=i},x=function t(n,i,e){s(this,t),this.callee=n,this.paren=i,this.arguments=e},O=function t(n,i){s(this,t),this.keyword=n,this.value=i},j=function t(n,i){s(this,t),this.name=n,this.methods=i},_=function t(n,i,e){s(this,t),this.name=n,this.params=i,this.bodyStatements=e};module.exports={Var:f,Binary:h,Unary:c,Block:v,Call:x,While:w,Class:j,Get:l,Set:p,Literal:a,Return:O,Logical:u,LoxFunction:_,Grouping:y,Condition:S,ExpressionStatement:m,PrintStatement:b,VarStatement:g,Assignment:d}; -},{}],"CUYV":[function(require,module,exports) { -function e(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function t(e,t){for(var n=0;n2?i-2:0),s=2;s1?e-1:0),i=1;i")}}]),t}(),M=function(t){function n(t){var r;return o(this,n),(r=e(this,i(n).call(this))).name=t,r}return r(n,V),u(n,[{key:"call",value:function(){return new Q(this)}},{key:"toString",value:function(){return"<".concat(this.name,">")}}]),n}(),Q=function(){function t(e){o(this,t),this.klass=e,this.fields=new Map}return u(t,[{key:"get",value:function(t){var e=t.lexeme;if(this.fields.has(e))return this.fields.get(e);throw c("Undefined property ".concat(e),t)}},{key:"set",value:function(t,e){var n=t.lexeme;this.fields.set(n,e)}},{key:"toString",value:function(){return"<+".concat(this.klass.name,">")}}]),t}(),q=function(){function t(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:console.log;o(this,t),this.printfunction=n,this.environment=e||new G,this.environment.setBuiltin("PI",Math.PI),this.environment.setBuiltin("cos",function(t,e){return Math.cos(e[0])}),this.environment.setBuiltin("mod",function(t,e){return e[0]%e[1]}),this.environment.setBuiltin("strlen",function(t,e){return e[0].length}),this.environment.setBuiltin("charAt",function(t,e){return e[0][e[1]]}),this.environment.setBuiltin("clock",function(){return(new Date).getTime()})}return u(t,[{key:"interpret",value:function(t){return this.evaluate(t)}},{key:"evaluate",value:function(t){return t instanceof A?this.visitBlock(t):t instanceof L?this.visitFunction(t):t instanceof x?this.visitAssignment(t):t instanceof g?this.visitClass(t):t instanceof S?this.visitGet(t):t instanceof d?this.visitSet(t):t instanceof k?this.visitLogical(t):t instanceof m?this.visitCall(t):t instanceof E?this.visitWhile(t):t instanceof C?this.visitCondition(t):t instanceof U?this.visitVarStatement(t):t instanceof _?this.visitPrintStatement(t):t instanceof B?this.visitReturnStatement(t):t instanceof O?this.visitGrouping(t):t instanceof w?this.visitGrouping(t):t instanceof b?this.visitVar(t):t instanceof p?this.visitLiteral(t):t instanceof y?this.visitUnary(t):t instanceof h?this.visitBinary(t):void 0}},{key:"visitLiteral",value:function(t){return t.value}},{key:"visitGrouping",value:function(t){return this.evaluate(t.expression)}},{key:"visitPrintStatement",value:function(t){var e=this.evaluate(t.expression);return this.printfunction(null===e?"nil":e.toString()),e}},{key:"visitFunction",value:function(t){var e=new V(t,this.environment);this.environment.set(t.name,e)}},{key:"visitLogical",value:function(t){var e=this.evaluate(t.left);if(t.operator.type===R.OR){if(j(e))return e}else if(!j(e))return e;return this.evaluate(t.right)}},{key:"visitWhile",value:function(t){for(;j(this.evaluate(t.condition));)this.evaluate(t.body);return null}},{key:"visitReturnStatement",value:function(t){var e=null;throw t.value&&(e=this.evaluate(t.value)),new v(e)}},{key:"visitVar",value:function(t){return this.environment.get(t)}},{key:"visitVarStatement",value:function(t){var e=null;return null!==t.initializer&&(e=this.evaluate(t.initializer)),this.environment.set(t.name,e),null}},{key:"visitClass",value:function(t){this.environment.set(t.name,null);var e=new M(t.name.lexeme);return this.environment.assign(t.name,e),null}},{key:"visitGet",value:function(t){var e=this.evaluate(t.object);if(e instanceof Q)return e.get(t.name);throw c("Only instances have properties",t.name)}},{key:"visitSet",value:function(t){var e=this.evaluate(t.object);if(!(e instanceof Q))throw c("Only instances have fields",t.name);var n=this.evaluate(t.value);return e.set(t.name,n)}},{key:"visitBlock",value:function(t){return this.interpretBlock(t.statements,new G(this.environment)),null}},{key:"visitCondition",value:function(t){return j(this.evaluate(t.condition))?this.evaluate(t.thenBranch):t.elseBranch&&this.evaluate(t.elseBranch),null}},{key:"interpretBlock",value:function(t,e){var n=this.environment;try{this.environment=e;var i=!0,r=!1,a=void 0;try{for(var o,s=t[Symbol.iterator]();!(i=(o=s.next()).done);i=!0){var u=o.value;this.interpret(u)}}catch(l){r=!0,a=l}finally{try{i||null==s.return||s.return()}finally{if(r)throw a}}this.environment=n}catch(c){throw this.environment=n,c}}},{key:"visitAssignment",value:function(t){var e=this.evaluate(t.value);return this.environment.assign(t.name,e),e}},{key:"visitCall",value:function(t){var e=this,n=this.evaluate(t.callee),i=t.arguments.map(function(t){return e.evaluate(t)});if(!n.call)throw c("Can only call functions and classes",t.paren);return n.call(this,i)}},{key:"visitUnary",value:function(t){var e=this.evaluate(t.right);switch(t.operator.type){case R.MINUS:return T(t.operator,e),-e;case R.BANG:return!j(e)}}},{key:"visitBinary",value:function(t){var e=this.evaluate(t.left),n=this.evaluate(t.right);switch(t.operator.type){case R.MINUS:return T(t.operator,n,e),e-n;case R.PLUS:return e+n;case R.SLASH:return T(t.operator,n,e),e/n;case R.STAR:return T(t.operator,n,e),e*n;case R.GREATER:return T(t.operator,n,e),e>n;case R.GREATER_EQUAL:return T(t.operator,n,e),e>=n;case R.LESS:return T(t.operator,n,e),e3&&void 0!==arguments[3]&&arguments[3];try{var d=new e(o).scanTokens();l&&console.log(d);var c=new n(d).parse();l&&console.log(c);var u,v=new a(i,s),x=!0,f=!1,g=void 0;try{for(var p,C=c[Symbol.iterator]();!(x=(p=C.next()).done);x=!0){var h=p.value;u=v.interpret(h)}}catch(O){f=!0,g=O}finally{try{x||null==C.return||C.return()}finally{if(f)throw g}}return u}catch(S){if(console.log(S),S instanceof t){console.error("Parse Error:",S.toString(),"at ".concat(S.endCoordinates.line,":").concat(S.endCoordinates.col+1));var q=o.lastIndexOf("\n",S.startCoordinates.index),w=q<0?0:q,y=o.substr(w,S.startCoordinates.index),b=o.substr(S.startCoordinates.index,S.endCoordinates.index),k=o.indexOf("\n",S.endCoordinates.index),m=k<0?o.length:k,E=o.substr(S.endCoordinates.index,m);console.error(y+r.bgRed(b)+E)}else console.log("Unexpected javascript Error: "),console.log(S)}},l=function(r){var o=new e(r).scanTokens();return new n(o).parse()};module.exports={run:s,parse:l,Environment:i}; -},{"chalk":"ug4C","./tokenizer":"u74b","./parser":"CUYV","./errors":"p8GN","./interpreter":"lmrS","./environment":"brut"}],"9/6S":[function(require,module,exports) { -function n(n){return r(n)||e(n)||t()}function t(){throw new TypeError("Invalid attempt to spread non-iterable instance")}function e(n){if(Symbol.iterator in Object(n)||"[object Arguments]"===Object.prototype.toString.call(n))return Array.from(n)}function r(n){if(Array.isArray(n)){for(var t=0,e=new Array(n.length);t3&&void 0!==arguments[3]?arguments[3]:";",i="forLoop"!==o.context?z(o):"",c="",u=r;if(r instanceof L&&"forLoop"===r.context){var s=r.statements;u=s[0],s.length>1&&(c=z(s[s.length-1],t,e,!1))}var f=z(u,t,e,!1),l=[i,c];return"for (".concat(a," ").concat(l.join("; "),") ").concat(f)};w.set(f,function(n,t,e){return"forLoop"===n.context?B(n,t,e):A(n,t,e)});var C=function(n,t,e){var r=n.statements,o=z(r[0],t,e,!1);return B(r[1],t,e,o)},E=function(n,t,e){return"{\n"+n.statements.map(function(n){return z(n,t+1)}).join("\n")+"\n".concat(e.indent.repeat(t),"}")};w.set(L,function(n,t,e){return"forLoop"===n.context?C(n,t,e):E(n,t,e)}),w.set(c,function(n){return n.name.lexeme}),w.set(v,function(n){var t=n.expression;return"("+z(t)+")"});var O=function(n){return[z(n.left),n.operator.lexeme,z(n.right)].join(" ")};w.set(a,O),w.set(b,O),w.set(i,function(n){return n.operator.lexeme+z(n.right)}),w.set(u,function(n){var t=n.arguments.map(function(n){return z(n)}).join(", "),e=z(n.callee);return"".concat(e,"(").concat(t,")")}),w.set(j,function(n){return n.name.lexeme+" = "+z(n.value)}),w.set(s,function(n){var t=n.value;return"string"==typeof t?'"'.concat(t,'"'):null===t?"nil":t});var z=function(n){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],o=Object.assign({},{indent:"\t",spaceBeforeParams:!0},e);if(w.has(n.constructor))return(r?o.indent.repeat(t):"")+w.get(n.constructor)(n,t,o);throw new Error("Don't support that context yet",n.constructor)};module.exports={printLoxAST:z}; -},{"../types":"39eF"}],"KVVd":[function(require,module,exports) { - -},{}],"3hpa":[function(require,module,exports) { -"use strict";var n=require("./index"),e=require("./transpilers/lox"),t=require("fs"),r="",a=document.getElementById("code"),i=['// Interactive Iterative Fibonacci\nvar a = 0;\nvar b = 1;\nvar limit = prompt("Limit to find fib numbers", 10000);\n\nwhile (a < limit) {\n print a;\n var temp = a;\n a = b;\n b = temp + b;\n}\n','// Linked List via Closures\nfun Link(value, next) {\n fun access(method) {\n if (method == "value") return value;\n if (method == "next") return next;\n print "unknown method " + method;\n }\n\n return access;\n}\n\nfun traverse(n, fn) {\n fn(n);\n if (n("next") != nil) {\n return traverse(n("next"), fn);\n }\n return n;\n}\n\nfun printValue (n) {\n print n("value");\n}\n\nfun blank (n) {}\n\nfun printTail (n) {\n var tail = traverse(n, blank);\n print tail("value");\n}\n\nvar list = Link(1, Link(2, Link(3, nil)));\n\ntraverse(list, printValue);\nprintTail(list, printTail);','// Kitchen Sink\nfun hello (arg1, arg2) {\n fun secondHi (helloer) {\n print helloer + " says hello";\n }\n var str = arg1 + " says hello to " + arg2;\n var maxAge = 18;\n var age;\n age = maxAge + 3;\n if (age < 21) {\n alert("Too young");\n while(age < 21) {\n age = age + 1;\n }\n } else {\n print "come on in";\n }\n for (var i = 0; i < 18; i = i + 1) {\n print i;\n }\n return age or maxAge;\n}\n\n\nprint "hello source: ";\nprint printFunctionBody(hello);\n\n// hello("boss", "man");','// Class Example\nclass Lox {\n breakfast() {\n print "Toast";\n }\n}\n\nfun hello () {\n print "Would you like some breakfast?";\n}\n\nprint Lox;\n\nprint hello;\nvar loxInstance = Lox();\n\nloxInstance.category = "Breakfast";\nprint loxInstance.category;\n\nprint Lox();\n\n// class Bagel {}\n// var bagel = Bagel();\n// print bagel; // Prints "Bagel instance".\n// print bagel.lox;'],o=i.map(function(n){return{name:n.split("\n")[0].replace(/[^\w\s]/gi,"").trim(),program:n}}),l=document.getElementById("exampleProgram"),u=o.map(function(n,e){return'")}).join("\n");l.innerHTML=u,l.onchange=function(n){var e=n.target.value;a.value=o[e].program};var c=0;window.location.hash&&(c=+window.location.hash.replace(/[^\w\s]/gi,"").trim()),a.value=o[c].program;var s=function(n){r+=n+"\n",console.log(n),document.getElementById("output").value=r},p=document.getElementById("run");p.onclick=function(){var t=a.value,i=new n.Environment;i.setBuiltin("alert",function(n,e){return alert(e[0])}),i.setBuiltin("printFunctionBody",function(n,t){var r=t[0];if(r&&!r.declaration)throw new Error("Argument is not a lox function");return(0,e.printLoxAST)(r.declaration)}),i.setBuiltin("confirm",function(n,e){return confirm(e[0])}),i.setBuiltin("prompt",function(n,e){return prompt(e[0],e.length>1?e[1]:null)}),r="",(0,n.run)(t,i,s)};var m=document.getElementById("format");m.onclick=function(){a.value=(0,n.parse)(a.value).map(function(n){return(0,e.printLoxAST)(n)}).join("\n")}; -},{"./index":"Focm","./transpilers/lox":"9/6S","fs":"KVVd"}]},{},["3hpa"], null) \ No newline at end of file diff --git a/docs/browser.3e1d6a44.js b/docs/browser.e9f8be96.js similarity index 86% rename from docs/browser.3e1d6a44.js rename to docs/browser.e9f8be96.js index dd9114c..c9dea57 100644 --- a/docs/browser.3e1d6a44.js +++ b/docs/browser.e9f8be96.js @@ -13,9 +13,9 @@ function t(e){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterat },{"./errors":"p8GN","./types":"39eF","./environment":"brut","./tokenizer":"u74b"}],"Focm":[function(require,module,exports) { var r=require("./tokenizer"),e=require("./parser"),n=require("./interpreter"),o=require("./environment"),t=function(o,t,a){var i=arguments.length>3&&void 0!==arguments[3]&&arguments[3],l=new r(o).scanTokens();i&&console.log(l);var u=new e(l).parse();i&&console.log(u);var v,s=new n(t,a),c=!0,p=!1,f=void 0;try{for(var w,y=u[Symbol.iterator]();!(c=(w=y.next()).done);c=!0){var d=w.value;v=s.interpret(d)}}catch(m){p=!0,f=m}finally{try{c||null==y.return||y.return()}finally{if(p)throw f}}return v},a=function(n){var o=new r(n).scanTokens();return new e(o).parse()};module.exports={run:t,parse:a,Environment:o}; },{"./tokenizer":"u74b","./parser":"CUYV","./interpreter":"lmrS","./environment":"brut"}],"9/6S":[function(require,module,exports) { -function n(n){return r(n)||e(n)||t()}function t(){throw new TypeError("Invalid attempt to spread non-iterable instance")}function e(n){if(Symbol.iterator in Object(n)||"[object Arguments]"===Object.prototype.toString.call(n))return Array.from(n)}function r(n){if(Array.isArray(n)){for(var t=0,e=new Array(n.length);t3&&void 0!==arguments[3]?arguments[3]:";",i="forLoop"!==o.context?z(o):"",c="",u=r;if(r instanceof L&&"forLoop"===r.context){var s=r.statements;u=s[0],s.length>1&&(c=z(s[s.length-1],t,e,!1))}var f=z(u,t,e,!1),l=[i,c];return"for (".concat(a," ").concat(l.join("; "),") ").concat(f)};w.set(f,function(n,t,e){return"forLoop"===n.context?B(n,t,e):A(n,t,e)});var C=function(n,t,e){var r=n.statements,o=z(r[0],t,e,!1);return B(r[1],t,e,o)},E=function(n,t,e){return"{\n"+n.statements.map(function(n){return z(n,t+1)}).join("\n")+"\n".concat(e.indent.repeat(t),"}")};w.set(L,function(n,t,e){return"forLoop"===n.context?C(n,t,e):E(n,t,e)}),w.set(c,function(n){return n.name.lexeme}),w.set(v,function(n){var t=n.expression;return"("+z(t)+")"});var O=function(n){return[z(n.left),n.operator.lexeme,z(n.right)].join(" ")};w.set(a,O),w.set(b,O),w.set(i,function(n){return n.operator.lexeme+z(n.right)}),w.set(u,function(n){var t=n.arguments.map(function(n){return z(n)}).join(", "),e=z(n.callee);return"".concat(e,"(").concat(t,")")}),w.set(j,function(n){return n.name.lexeme+" = "+z(n.value)}),w.set(s,function(n){var t=n.value;return"string"==typeof t?'"'.concat(t,'"'):null===t?"nil":t});var z=function(n){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],o=Object.assign({},{indent:"\t",spaceBeforeParams:!0},e);if(w.has(n.constructor))return(r?o.indent.repeat(t):"")+w.get(n.constructor)(n,t,o);throw new Error("Don't support that context yet",n.constructor)};module.exports={printLoxAST:z}; +function n(n){return r(n)||e(n)||t()}function t(){throw new TypeError("Invalid attempt to spread non-iterable instance")}function e(n){if(Symbol.iterator in Object(n)||"[object Arguments]"===Object.prototype.toString.call(n))return Array.from(n)}function r(n){if(Array.isArray(n)){for(var t=0,e=new Array(n.length);t1&&void 0!==arguments[1]?arguments[1]:" ";return n?t:""},S=new Map;S.set(d,function(n,t,e){return z(n.expression,0,e)+("forLoop"===n.context?"":";")}),S.set(x,function(n){return"print "+z(n.expression)+";"}),S.set(g,function(n){return"return "+z(n.value)+";"}),S.set(y,function(n){var t=n.name.lexeme,e=n.initializer?z(n.initializer):null;return"var ".concat(t)+(e?" = ".concat(e):"")+";"}),S.set(B,function(n,t,e){var r=n.condition,o=n.thenBranch,a=n.elseBranch,c=z(r),i="if".concat(L(e.spaceBeforeParams),"(").concat(c,") "),u=z(o,t,e,!1),s=a&&z(a,t,e,!1);return i+u+(s?" else ".concat(s):"")}),S.set(h,function(t,e,r){var o=t.bodyStatements,a=t.name.lexeme,c=t.params.map(function(n){return n.lexeme}),i="fun ".concat(a).concat(L(r.spaceBeforeParams),"(").concat(c.join(", "),") {"),u=o.map(function(n){return z(n,e+1,r)}),s=r.indent.repeat(e)+"}"+L(r.functionNewlines,"\n");return[i].concat(n(u),[s]).join("\n")});var A=function(n,t,e){var r=n.body,o=n.condition,a=z(o);return"while".concat(L(e.spaceBeforeParams),"(").concat(a,") ")+z(r,t,e,!1)},P=function(n,t,e){var r=n.body,o=n.condition,a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:";",c="forLoop"!==o.context?z(o):"",i="",u=r;if(r instanceof w&&"forLoop"===r.context){var s=r.statements;u=s[0],s.length>1&&(i=z(s[s.length-1],t,e,!1))}var f=z(u,t,e,!1),l=[c,i];return"for".concat(L(e.spaceBeforeParams),"(").concat(a," ").concat(l.join("; "),") ").concat(f)};S.set(f,function(n,t,e){return"forLoop"===n.context?P(n,t,e):A(n,t,e)});var C=function(n,t,e){var r=n.statements,o=z(r[0],t,e,!1);return P(r[1],t,e,o)},E=function(n,t,e){return"{\n"+n.statements.map(function(n){return z(n,t+1,e)}).join("\n")+"\n".concat(e.indent.repeat(t),"}")};S.set(w,function(n,t,e){return"forLoop"===n.context?C(n,t,e):E(n,t,e)}),S.set(i,function(n){return n.name.lexeme}),S.set(v,function(n){var t=n.expression;return"("+z(t)+")"});var O=function(n){return[z(n.left),n.operator.lexeme,z(n.right)].join(" ")};S.set(a,O),S.set(b,O),S.set(c,function(n){return n.operator.lexeme+z(n.right)}),S.set(u,function(n){var t=n.arguments.map(function(n){return z(n)}).join(", "),e=z(n.callee);return"".concat(e,"(").concat(t,")")}),S.set(j,function(n){return n.name.lexeme+" = "+z(n.value)}),S.set(s,function(n){var t=n.value;return"string"==typeof t?'"'.concat(t,'"'):null===t?"nil":t});var z=function(n){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],o=Object.assign({},{indent:"\t",spaceBeforeParams:!0,functionNewlines:!0},e);if(S.has(n.constructor))return(r?o.indent.repeat(t):"")+S.get(n.constructor)(n,t,o);throw new Error("Don't support that context yet",n.constructor)};module.exports={printLoxAST:z}; },{"../types":"39eF"}],"KVVd":[function(require,module,exports) { },{}],"3hpa":[function(require,module,exports) { -"use strict";var n=require("./index"),e=require("./errors"),r=require("./transpilers/lox"),t=require("fs"),a="",i=document.getElementById("code"),o=['// Interactive Iterative Fibonacci\nvar a = 0;\nvar b = 1;\nvar limit = prompt("Limit to find fib numbers", 10000);\n\nwhile (a < limit) {\n print a;\n var temp = a;\n a = b;\n b = temp + b;\n}\n','// Linked List via Closures\nfun Link(value, next) {\n fun access(method) {\n if (method == "value") return value;\n if (method == "next") return next;\n print "unknown method " + method;\n }\n\n return access;\n}\n\nfun traverse(n, fn) {\n fn(n);\n if (n("next") != nil) {\n return traverse(n("next"), fn);\n }\n return n;\n}\n\nfun printValue (n) {\n print n("value");\n}\n\nfun blank (n) {}\n\nfun printTail (n) {\n var tail = traverse(n, blank);\n print tail("value");\n}\n\nvar list = Link(1, Link(2, Link(3, nil)));\n\ntraverse(list, printValue);\nprintTail(list, printTail);','// Kitchen Sink\nfun hello (arg1, arg2) {\n fun secondHi (helloer) {\n print helloer + " says hello";\n }\n var str = arg1 + " says hello to " + arg2;\n var maxAge = 18;\n var age;\n age = maxAge + 3;\n if (age < 21) {\n alert("Too young");\n while(age < 21) {\n age = age + 1;\n }\n } else {\n print "come on in";\n }\n for (var i = 0; i < 18; i = i + 1) {\n print i;\n }\n return age or maxAge;\n}\n\n\nprint "hello source: ";\nprint printFunctionBody(hello);\n\n// hello("boss", "man");','// Class Example\nclass Lox {\n breakfast() {\n print "Toast";\n }\n}\n\nfun hello () {\n print "Would you like some breakfast?";\n}\n\nprint Lox;\n\nprint hello;\nvar loxInstance = Lox();\n\nloxInstance.category = "Breakfast";\nprint loxInstance.category;\n\nprint Lox();\n\n// class Bagel {}\n// var bagel = Bagel();\n// print bagel; // Prints "Bagel instance".\n// print bagel.lox;'],l=o.map(function(n){return{name:n.split("\n")[0].replace(/[^\w\s]/gi,"").trim(),program:n}}),u=function(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";if(!n)return document.getElementById("error").style.display="none",null;console.error(n);var t=(0,e.formatLoxError)(n,r),a=t.oneLiner,i=t.preErrorSection,o=t.errorSection,l=t.postErrorSection,u=a;o&&(u+="
",u+="".concat(i,'').concat(o,"").concat(l)),document.getElementById("error").style.display="",document.getElementById("errorText").innerHTML=u},c=document.getElementById("exampleProgram"),s=l.map(function(n,e){return'")}).join("\n");c.innerHTML=s,c.onchange=function(n){var e=n.target.value;i.value=l[e].program};var p=0;window.location.hash&&(p=+window.location.hash.replace(/[^\w\s]/gi,"").trim()),i.value=l[p].program;var m=function(n){a+=n+"\n",console.log(n),document.getElementById("output").value=a},g=document.getElementById("run");g.onclick=function(){var e=i.value,t=new n.Environment;t.setBuiltin("alert",function(n,e){return alert(e[0])}),t.setBuiltin("printFunctionBody",function(n,e){var t=e[0];if(t&&!t.declaration)throw new Error("Argument is not a lox function");return(0,r.printLoxAST)(t.declaration)}),t.setBuiltin("confirm",function(n,e){return confirm(e[0])}),t.setBuiltin("prompt",function(n,e){return prompt(e[0],e.length>1?e[1]:null)}),a="";try{(0,n.run)(e,t,m),u(null)}catch(o){u(o,e)}};var v=document.getElementById("format");v.onclick=function(){i.value=(0,n.parse)(i.value).map(function(n){return(0,r.printLoxAST)(n)}).join("\n")}; +"use strict";var n=require("./index"),e=require("./errors"),r=require("./transpilers/lox"),t=require("fs"),a="",i=document.getElementById("code"),o=['// Interactive Iterative Fibonacci\nvar a = 0;\nvar b = 1;\nvar limit = prompt("Limit to find fib numbers", 10000);\n\nwhile (a < limit) {\n print a;\n var temp = a;\n a = b;\n b = temp + b;\n}\n','// Linked List via Closures\nfun Link(value, next) {\n fun access(method) {\n if (method == "value") return value;\n if (method == "next") return next;\n print "unknown method " + method;\n }\n\n return access;\n}\n\nfun traverse(n, fn) {\n fn(n);\n if (n("next") != nil) {\n return traverse(n("next"), fn);\n }\n return n;\n}\n\nfun printValue (n) {\n print n("value");\n}\n\nfun blank (n) {}\n\nfun printTail (n) {\n var tail = traverse(n, blank);\n print tail("value");\n}\n\nvar list = Link(1, Link(2, Link(3, nil)));\n\ntraverse(list, printValue);\nprintTail(list, printTail);','// Kitchen Sink\nfun hello (arg1, arg2) {\n fun secondHi (helloer) {\n print helloer + " says hello";\n }\n var str = arg1 + " says hello to " + arg2;\n var maxAge = 18;\n var age;\n age = maxAge + 3;\n if (age < 21) {\n alert("Too young");\n while(age < 21) {\n age = age + 1;\n }\n } else {\n print "come on in";\n }\n for (var i = 0; i < 18; i = i + 1) {\n print i;\n }\n return age or maxAge;\n}\n\n\nprint "hello source: ";\nprint printFunctionBody(hello);\n\n// hello("boss", "man");','// Class Example\nclass Lox {\n breakfast() {\n print "Toast";\n }\n}\n\nfun hello () {\n print "Would you like some breakfast?";\n}\n\nprint Lox;\n\nprint hello;\nvar loxInstance = Lox();\n\nloxInstance.category = "Breakfast";\nprint loxInstance.category;\n\nprint Lox();\n\n// class Bagel {}\n// var bagel = Bagel();\n// print bagel; // Prints "Bagel instance".\n// print bagel.lox;'],l=o.map(function(n){return{name:n.split("\n")[0].replace(/[^\w\s]/gi,"").trim(),program:n}}),u=function(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";if(!n)return document.getElementById("error").style.maxHeight="0",null;console.error(n);var t=(0,e.formatLoxError)(n,r),a=t.oneLiner,i=t.preErrorSection,o=t.errorSection,l=t.postErrorSection,u=a;o&&(u+="
",u+="".concat(i,'').concat(o,"").concat(l)),document.getElementById("error").style.maxHeight="150px",document.getElementById("errorText").innerHTML=u},c=document.getElementById("exampleProgram"),s=l.map(function(n,e){return'")}).join("\n");c.innerHTML=s,c.onchange=function(n){var e=n.target.value;i.value=l[e].program};var m=0;if(window.location.hash){var p=+window.location.hash.replace(/[^\w\s]/gi,"").trim();p1?e[1]:null)}),a="";try{(0,n.run)(e,t,g),u(null)}catch(o){u(o,e)}};var f=document.getElementById("format");f.onclick=function(){try{i.value=(0,n.parse)(i.value).map(function(n){return(0,r.printLoxAST)(n)}).join("\n"),u(null)}catch(e){u(e,i.value)}}; },{"./index":"Focm","./errors":"p8GN","./transpilers/lox":"9/6S","fs":"KVVd"}]},{},["3hpa"], null) \ No newline at end of file diff --git a/docs/index.html b/docs/index.html index a57fe4e..24b9ffc 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1,2 +1,2 @@ -YALI.js

YALI.js: Yet Another Lox Interpreter. Javascript Implementation

Please open your javascript console with Command + Option + J (Mac) or Control + Shift + J (Windows, Linux, Chrome OS)
+YALI.js

YALI.js: Yet Another Lox Interpreter. Javascript Implementation

Please open your javascript console with Command + Option + J (Mac) or Control + Shift + J (Windows, Linux, Chrome OS)
\ No newline at end of file diff --git a/index.html b/index.html index 2b594db..9838a13 100644 --- a/index.html +++ b/index.html @@ -17,6 +17,7 @@ pre#error { margin-top: -12px; + transition: max-height 1s; } .error { color: #d24b46; @@ -51,21 +52,21 @@

+
+ + +
- +
-
- - -
Please open your javascript console with Command + Option + J (Mac) or Control + Shift + J (Windows, Linux, Chrome OS) diff --git a/loxfmt.js b/loxfmt.js new file mode 100755 index 0000000..3a698a5 --- /dev/null +++ b/loxfmt.js @@ -0,0 +1,83 @@ +#! /usr/bin/env node +const fs = require('fs') +const chalk = require('chalk') +const { parse } = require('./index') +const { printLoxAST } = require('./transpilers/lox') +const { formatLoxError } = require('./errors') + +let options = {} + +const printErrorMessage = (e, code) => { + const { oneLiner, preErrorSection, errorSection, postErrorSection } = formatLoxError(e, code) + console.error(oneLiner) + if (errorSection) { + console.error(preErrorSection + chalk.bgRed(errorSection) + postErrorSection) + } +} + +const fmtFile = filename => { + try { + const file = fs.readFileSync(filename, 'utf8') + try { + const newText = parse(file) + .map(stmt => printLoxAST(stmt, 0, options)) + .join('\n') + if (!options.silent) console.log(newText) + if (options.write) { + fs.writeFileSync(filename, newText) + } + } catch (e) { + printErrorMessage(e, file) + } + } catch (e) { + console.error(`YALI could not read the file ${filename}`) + console.error(e) + } +} + +const optionRegex = /--(\w+)(?:=(.+))?/ +const processOptions = args => + args + .map(arg => { + const match = optionRegex.exec(arg) + if (match) { + const [, option, value] = match + if (!value) { + options[option] = !options[option] + } else { + options[option] = value + } + } else { + return arg + } + }) + .filter(Boolean) + +const main = argv => { + process.title = 'loxfmt' + const args = processOptions(argv.slice(2)) + if (options.help) { + console.log( + ` + Usage: loxfmt [script]* + + Options: + + --write Writes linting to files + + --indent="{indentstring}" Defines indent string to use + --spaceBeforeParams Adds space before params. fun hello() { => fun hello () { + --functionNewlines Adds an extra newline after function bodies + ` + ) + return 0 + } + if (args.length >= 1) { + args.forEach(fmtFile) + } else { + console.error('Usage: loxfmt [script]*') + return 64 + } +} + +return main(process.argv) diff --git a/package-lock.json b/package-lock.json index 066385b..17c76ab 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1439,6 +1439,12 @@ } } }, + "acorn-jsx": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.0.1.tgz", + "integrity": "sha512-HJ7CfNHrfJLlNTzIEUTj43LNWGkqpRLxm3YjAlcD0ACydk9XynzYsCBHxut+iqt+1aBXkx9UP/w/ZqMr13XIzg==", + "dev": true + }, "acorn-walk": { "version": "6.1.1", "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-6.1.1.tgz", @@ -2178,6 +2184,12 @@ "supports-color": "^5.3.0" } }, + "chardet": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/chardet/-/chardet-0.7.0.tgz", + "integrity": "sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA==", + "dev": true + }, "chokidar": { "version": "2.1.6", "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-2.1.6.tgz", @@ -2260,6 +2272,12 @@ "integrity": "sha512-1QL4544moEsDVH9T/l6Cemov/37iv1RtoKf7NJ04A60+4MREXNfx/QvavbH6QoGdsD4N4Mwy49cmaINR/o2mdg==", "dev": true }, + "cli-width": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/cli-width/-/cli-width-2.2.0.tgz", + "integrity": "sha1-/xnt6Kml5XkyQUewwR8PvLq+1jk=", + "dev": true + }, "cliui": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/cliui/-/cliui-4.1.0.tgz", @@ -3083,6 +3101,15 @@ "randombytes": "^2.0.0" } }, + "doctrine": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz", + "integrity": "sha512-yS+Q5i3hBf7GBkd4KG8a7eBNNWNGLTaEwwYWUijIYM7zrlYDM0BFXHjjPWlWZ1Rg7UaddZeIDmi9jF3HmqiQ2w==", + "dev": true, + "requires": { + "esutils": "^2.0.2" + } + }, "dom-serializer": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-0.1.1.tgz", @@ -3212,6 +3239,12 @@ "minimalistic-crypto-utils": "^1.0.0" } }, + "emoji-regex": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-7.0.3.tgz", + "integrity": "sha512-CwBLREIQ7LvYFB0WyRvwhq5N5qPhc6PMjD6bYggFlI5YyDgl+0vxq5VHbMOFqLg7hfWzmu8T5Z1QofhmTIhItA==", + "dev": true + }, "encodeurl": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", @@ -3299,12 +3332,163 @@ } } }, + "eslint": { + "version": "5.16.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-5.16.0.tgz", + "integrity": "sha512-S3Rz11i7c8AA5JPv7xAH+dOyq/Cu/VXHiHXBPOU1k/JAM5dXqQPt3qcrhpHSorXmrpu2g0gkIBVXAqCpzfoZIg==", + "dev": true, + "requires": { + "@babel/code-frame": "^7.0.0", + "ajv": "^6.9.1", + "chalk": "^2.1.0", + "cross-spawn": "^6.0.5", + "debug": "^4.0.1", + "doctrine": "^3.0.0", + "eslint-scope": "^4.0.3", + "eslint-utils": "^1.3.1", + "eslint-visitor-keys": "^1.0.0", + "espree": "^5.0.1", + "esquery": "^1.0.1", + "esutils": "^2.0.2", + "file-entry-cache": "^5.0.1", + "functional-red-black-tree": "^1.0.1", + "glob": "^7.1.2", + "globals": "^11.7.0", + "ignore": "^4.0.6", + "import-fresh": "^3.0.0", + "imurmurhash": "^0.1.4", + "inquirer": "^6.2.2", + "js-yaml": "^3.13.0", + "json-stable-stringify-without-jsonify": "^1.0.1", + "levn": "^0.3.0", + "lodash": "^4.17.11", + "minimatch": "^3.0.4", + "mkdirp": "^0.5.1", + "natural-compare": "^1.4.0", + "optionator": "^0.8.2", + "path-is-inside": "^1.0.2", + "progress": "^2.0.0", + "regexpp": "^2.0.1", + "semver": "^5.5.1", + "strip-ansi": "^4.0.0", + "strip-json-comments": "^2.0.1", + "table": "^5.2.3", + "text-table": "^0.2.0" + }, + "dependencies": { + "ansi-regex": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", + "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=", + "dev": true + }, + "debug": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", + "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", + "dev": true, + "requires": { + "ms": "^2.1.1" + } + }, + "import-fresh": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.0.0.tgz", + "integrity": "sha512-pOnA9tfM3Uwics+SaBLCNyZZZbK+4PTu0OPZtLlMIrv17EdBoC15S9Kn8ckJ9TZTyKb3ywNE5y1yeDxxGA7nTQ==", + "dev": true, + "requires": { + "parent-module": "^1.0.0", + "resolve-from": "^4.0.0" + } + }, + "ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "dev": true + }, + "resolve-from": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", + "integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==", + "dev": true + }, + "strip-ansi": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", + "integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=", + "dev": true, + "requires": { + "ansi-regex": "^3.0.0" + } + } + } + }, + "eslint-scope": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-4.0.3.tgz", + "integrity": "sha512-p7VutNr1O/QrxysMo3E45FjYDTeXBy0iTltPFNSqKAIfjDSXC+4dj+qfyuD8bfAXrW/y6lW3O76VaYNPKfpKrg==", + "dev": true, + "requires": { + "esrecurse": "^4.1.0", + "estraverse": "^4.1.1" + } + }, + "eslint-utils": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-1.3.1.tgz", + "integrity": "sha512-Z7YjnIldX+2XMcjr7ZkgEsOj/bREONV60qYeB/bjMAqqqZ4zxKyWX+BOUkdmRmA9riiIPVvo5x86m5elviOk0Q==", + "dev": true + }, + "eslint-visitor-keys": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz", + "integrity": "sha512-qzm/XxIbxm/FHyH341ZrbnMUpe+5Bocte9xkmFMzPMjRaZMcXww+MpBptFvtU+79L362nqiLhekCxCxDPaUMBQ==", + "dev": true + }, + "espree": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/espree/-/espree-5.0.1.tgz", + "integrity": "sha512-qWAZcWh4XE/RwzLJejfcofscgMc9CamR6Tn1+XRXNzrvUSSbiAjGOI/fggztjIi7y9VLPqnICMIPiGyr8JaZ0A==", + "dev": true, + "requires": { + "acorn": "^6.0.7", + "acorn-jsx": "^5.0.0", + "eslint-visitor-keys": "^1.0.0" + }, + "dependencies": { + "acorn": { + "version": "6.1.1", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-6.1.1.tgz", + "integrity": "sha512-jPTiwtOxaHNaAPg/dmrJ/beuzLRnXtB0kQPQ8JpotKJgTB6rX6c8mlf315941pyjBSaPg8NHXS9fhP4u17DpGA==", + "dev": true + } + } + }, "esprima": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==", "dev": true }, + "esquery": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.0.1.tgz", + "integrity": "sha512-SmiyZ5zIWH9VM+SRUReLS5Q8a7GxtRdxEBVZpm98rJM7Sb+A9DVCndXfkeFUd3byderg+EbDkfnevfCwynWaNA==", + "dev": true, + "requires": { + "estraverse": "^4.0.0" + } + }, + "esrecurse": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.2.1.tgz", + "integrity": "sha512-64RBB++fIOAXPw3P9cy89qfMlvZEXZkqqJkjqqXIvzP5ezRZjW+lPWjw35UX/3EhUPFYbg5ER4JYgDw4007/DQ==", + "dev": true, + "requires": { + "estraverse": "^4.1.0" + } + }, "estraverse": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-4.2.0.tgz", @@ -3442,6 +3626,17 @@ } } }, + "external-editor": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/external-editor/-/external-editor-3.0.3.tgz", + "integrity": "sha512-bn71H9+qWoOQKyZDo25mOMVpSmXROAsTJVVVYzrrtol3d4y+AsKjf4Iwl2Q+IuT0kFSQ1qo166UuIwqYq7mGnA==", + "dev": true, + "requires": { + "chardet": "^0.7.0", + "iconv-lite": "^0.4.24", + "tmp": "^0.0.33" + } + }, "extglob": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/extglob/-/extglob-2.0.4.tgz", @@ -3580,6 +3775,24 @@ "bser": "^2.0.0" } }, + "figures": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/figures/-/figures-2.0.0.tgz", + "integrity": "sha1-OrGi0qYsi/tDGgyUy3l6L84nyWI=", + "dev": true, + "requires": { + "escape-string-regexp": "^1.0.5" + } + }, + "file-entry-cache": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-5.0.1.tgz", + "integrity": "sha512-bCg29ictuBaKUwwArK4ouCaqDgLZcysCFLmM/Yn/FDoqndh/9vNuQfXRDvTuXKLxfD/JtZQGKFT8MGcJBK644g==", + "dev": true, + "requires": { + "flat-cache": "^2.0.1" + } + }, "fileset": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/fileset/-/fileset-2.0.3.tgz", @@ -3628,6 +3841,23 @@ "locate-path": "^3.0.0" } }, + "flat-cache": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-2.0.1.tgz", + "integrity": "sha512-LoQe6yDuUMDzQAEH8sgmh4Md6oZnc/7PjtwjNFSzveXqSHt6ka9fPBuso7IGf9Rz4uqnSnWiFH2B/zj24a5ReA==", + "dev": true, + "requires": { + "flatted": "^2.0.0", + "rimraf": "2.6.3", + "write": "1.0.3" + } + }, + "flatted": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/flatted/-/flatted-2.0.0.tgz", + "integrity": "sha512-R+H8IZclI8AAkSBRQJLVOsxwAoHd6WC40b4QTNWIjzAa6BXOBfQcM587MXDTVPeYaopFNWHUFLx7eNmHDSxMWg==", + "dev": true + }, "for-in": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/for-in/-/for-in-1.0.2.tgz", @@ -4213,6 +4443,12 @@ "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==", "dev": true }, + "functional-red-black-tree": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz", + "integrity": "sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=", + "dev": true + }, "get-caller-file": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-1.0.3.tgz", @@ -4585,6 +4821,12 @@ "integrity": "sha512-4vf7I2LYV/HaWerSo3XmlMkp5eZ83i+/CDluXi/IGTs/O1sejBNhTtnxzmRZfvOUqj7lZjqHkeTvpgSFDlWZTg==", "dev": true }, + "ignore": { + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-4.0.6.tgz", + "integrity": "sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg==", + "dev": true + }, "import-fresh": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-2.0.0.tgz", @@ -4645,6 +4887,27 @@ "integrity": "sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw==", "dev": true }, + "inquirer": { + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/inquirer/-/inquirer-6.3.1.tgz", + "integrity": "sha512-MmL624rfkFt4TG9y/Jvmt8vdmOo836U7Y0Hxr2aFk3RelZEGX4Igk0KabWrcaaZaTv9uzglOqWh1Vly+FAWAXA==", + "dev": true, + "requires": { + "ansi-escapes": "^3.2.0", + "chalk": "^2.4.2", + "cli-cursor": "^2.1.0", + "cli-width": "^2.0.0", + "external-editor": "^3.0.3", + "figures": "^2.0.0", + "lodash": "^4.17.11", + "mute-stream": "0.0.7", + "run-async": "^2.2.0", + "rxjs": "^6.4.0", + "string-width": "^2.1.0", + "strip-ansi": "^5.1.0", + "through": "^2.3.6" + } + }, "invariant": { "version": "2.2.4", "resolved": "https://registry.npmjs.org/invariant/-/invariant-2.2.4.tgz", @@ -4864,6 +5127,12 @@ "isobject": "^3.0.1" } }, + "is-promise": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-promise/-/is-promise-2.1.0.tgz", + "integrity": "sha1-eaKp7OfwlugPNtKy87wWwf9L8/o=", + "dev": true + }, "is-regex": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.0.4.tgz", @@ -5578,6 +5847,12 @@ "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", "dev": true }, + "json-stable-stringify-without-jsonify": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz", + "integrity": "sha1-nbe1lJatPzz+8wp1FC0tkwrXJlE=", + "dev": true + }, "json-stringify-safe": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz", @@ -5968,6 +6243,12 @@ "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", "dev": true }, + "mute-stream": { + "version": "0.0.7", + "resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.7.tgz", + "integrity": "sha1-MHXOk7whuPq0PhvE2n6BFe0ee6s=", + "dev": true + }, "nan": { "version": "2.13.2", "resolved": "https://registry.npmjs.org/nan/-/nan-2.13.2.tgz", @@ -6678,6 +6959,15 @@ } } }, + "parent-module": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz", + "integrity": "sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==", + "dev": true, + "requires": { + "callsites": "^3.0.0" + } + }, "parse-asn1": { "version": "5.1.4", "resolved": "https://registry.npmjs.org/parse-asn1/-/parse-asn1-5.1.4.tgz", @@ -6744,6 +7034,12 @@ "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", "dev": true }, + "path-is-inside": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/path-is-inside/-/path-is-inside-1.0.2.tgz", + "integrity": "sha1-NlQX3t5EQw0cEa9hAn+s8HS9/FM=", + "dev": true + }, "path-key": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/path-key/-/path-key-2.0.1.tgz", @@ -7360,6 +7656,12 @@ "integrity": "sha512-MtEC1TqN0EU5nephaJ4rAtThHtC86dNN9qCuEhtshvpVBkAW5ZO7BASN9REnF9eoXGcRub+pFuKEpOHE+HbEMw==", "dev": true }, + "progress": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/progress/-/progress-2.0.3.tgz", + "integrity": "sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==", + "dev": true + }, "prompts": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/prompts/-/prompts-2.0.4.tgz", @@ -7586,6 +7888,12 @@ "integrity": "sha512-LFrA98Dw/heXqDojz7qKFdygZmFoiVlvE1Zp7Cq2cvF+ZA+03Gmhy0k0PQlsC1jvHPiTUSs+pDHEuSWv6+6D7w==", "dev": true }, + "regexpp": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-2.0.1.tgz", + "integrity": "sha512-lv0M6+TkDVniA3aD1Eg0DVpfU/booSu7Eev3TDO/mZKHBfVjgCGTV4t4buppESEYDtkArYFOxTJWv6S5C+iaNw==", + "dev": true + }, "regexpu-core": { "version": "4.5.4", "resolved": "https://registry.npmjs.org/regexpu-core/-/regexpu-core-4.5.4.tgz", @@ -7802,6 +8110,24 @@ "integrity": "sha512-6FomvYPfs+Jy9TfXmBpBuMWNH94SgCsZmJKcanySzgNNP6LjWxBvyLTa9KaMfDDM5oxRfrKDB0r/qeRsLwnBfA==", "dev": true }, + "run-async": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/run-async/-/run-async-2.3.0.tgz", + "integrity": "sha1-A3GrSuC91yDUFm19/aZP96RFpsA=", + "dev": true, + "requires": { + "is-promise": "^2.1.0" + } + }, + "rxjs": { + "version": "6.5.2", + "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.5.2.tgz", + "integrity": "sha512-HUb7j3kvb7p7eCUHE3FqjoDsC1xfZQ4AHFWfTKSpZ+sAhhz5X1WX0ZuUqWbzB2QhSLp3DoLUG+hMdEDKqWo2Zg==", + "dev": true, + "requires": { + "tslib": "^1.9.0" + } + }, "safe-buffer": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", @@ -8031,6 +8357,17 @@ "integrity": "sha512-ZYKh3Wh2z1PpEXWr0MpSBZ0V6mZHAQfYevttO11c51CaWjGTaadiKZ+wVt1PbMlDV5qhMFslpZCemhwOK7C89A==", "dev": true }, + "slice-ansi": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-2.1.0.tgz", + "integrity": "sha512-Qu+VC3EwYLldKa1fCxuuvULvSJOKEgk9pi8dZeCVK7TqBfUNTH4sFkk4joj8afVSfAYgJoSOetjx9QWOJ5mYoQ==", + "dev": true, + "requires": { + "ansi-styles": "^3.2.0", + "astral-regex": "^1.0.0", + "is-fullwidth-code-point": "^2.0.0" + } + }, "snapdragon": { "version": "0.8.2", "resolved": "https://registry.npmjs.org/snapdragon/-/snapdragon-0.8.2.tgz", @@ -8447,6 +8784,12 @@ "integrity": "sha1-u0P/VZim6wXYm1n80SnJgzE2Br8=", "dev": true }, + "strip-json-comments": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz", + "integrity": "sha1-PFMZQukIwml8DsNEhYwobHygpgo=", + "dev": true + }, "stylehacks": { "version": "4.0.3", "resolved": "https://registry.npmjs.org/stylehacks/-/stylehacks-4.0.3.tgz", @@ -8507,6 +8850,31 @@ "integrity": "sha1-rifbOPZgp64uHDt9G8KQgZuFGeY=", "dev": true }, + "table": { + "version": "5.4.0", + "resolved": "https://registry.npmjs.org/table/-/table-5.4.0.tgz", + "integrity": "sha512-nHFDrxmbrkU7JAFKqKbDJXfzrX2UBsWmrieXFTGxiI5e4ncg3VqsZeI4EzNmX0ncp4XNGVeoxIWJXfCIXwrsvw==", + "dev": true, + "requires": { + "ajv": "^6.9.1", + "lodash": "^4.17.11", + "slice-ansi": "^2.1.0", + "string-width": "^3.0.0" + }, + "dependencies": { + "string-width": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-3.1.0.tgz", + "integrity": "sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w==", + "dev": true, + "requires": { + "emoji-regex": "^7.0.1", + "is-fullwidth-code-point": "^2.0.0", + "strip-ansi": "^5.1.0" + } + } + } + }, "terser": { "version": "3.17.0", "resolved": "https://registry.npmjs.org/terser/-/terser-3.17.0.tgz", @@ -8530,12 +8898,24 @@ "require-main-filename": "^1.0.1" } }, + "text-table": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", + "integrity": "sha1-f17oI66AUgfACvLfSoTsP8+lcLQ=", + "dev": true + }, "throat": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/throat/-/throat-4.1.0.tgz", "integrity": "sha1-iQN8vJLFarGJJua6TLsgDhVnKmo=", "dev": true }, + "through": { + "version": "2.3.8", + "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", + "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=", + "dev": true + }, "through2": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/through2/-/through2-2.0.5.tgz", @@ -8567,6 +8947,15 @@ "integrity": "sha1-k9nez/yIBb1X6uQxDwt0Xptvs6c=", "dev": true }, + "tmp": { + "version": "0.0.33", + "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz", + "integrity": "sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw==", + "dev": true, + "requires": { + "os-tmpdir": "~1.0.2" + } + }, "tmpl": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/tmpl/-/tmpl-1.0.4.tgz", @@ -8658,6 +9047,12 @@ "integrity": "sha1-yy4SAwZ+DI3h9hQJS5/kVwTqYAM=", "dev": true }, + "tslib": { + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.9.3.tgz", + "integrity": "sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ==", + "dev": true + }, "tty-browserify": { "version": "0.0.0", "resolved": "https://registry.npmjs.org/tty-browserify/-/tty-browserify-0.0.0.tgz", @@ -9134,6 +9529,15 @@ "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", "dev": true }, + "write": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/write/-/write-1.0.3.tgz", + "integrity": "sha512-/lg70HAjtkUgWPVZhZcm+T4hkL8Zbtp1nFNOn3lRrxnlv50SRBv7cR7RqR+GMsd3hUXy9hWBo4CHTbFTcOYwig==", + "dev": true, + "requires": { + "mkdirp": "^0.5.1" + } + }, "write-file-atomic": { "version": "2.4.1", "resolved": "https://registry.npmjs.org/write-file-atomic/-/write-file-atomic-2.4.1.tgz", diff --git a/package.json b/package.json index 7a19b9c..b9caadf 100644 --- a/package.json +++ b/package.json @@ -3,13 +3,17 @@ "version": "0.10.2", "description": "Yet Another Lox Interpreter. Javascript Implementation of the Lox Programming Language", "main": "index.js", - "bin": "./cli.js", + "bin": { + "yali": "./cli.js", + "loxfmt": "./loxfmt.js" + }, "scripts": { "test": "jest", "format": "prettier --write *.js", "check": "prettier --check *.js", "dev": "parcel dev index.html", - "build": "parcel build --no-source-maps index.html --public-url ./ -d docs" + "lint": "./node_modules/.bin/eslint **.js", + "build": "parcel build --no-source-maps index.html --no-content-hash --public-url ./ -d docs" }, "repository": { "type": "git", @@ -22,6 +26,7 @@ }, "homepage": "https://github.com/danman113/YALI.js#readme", "devDependencies": { + "eslint": "^5.16.0", "jest": "^24.7.1", "parcel": "^1.12.3", "prettier": "1.17.0" diff --git a/transpilers/lox.js b/transpilers/lox.js index fa3d60e..fabbd03 100644 --- a/transpilers/lox.js +++ b/transpilers/lox.js @@ -26,7 +26,7 @@ const condChar = (condition, replacer = ' ') => condition ? replacer : '' const ASTNodeMap = new Map() // Declarations -ASTNodeMap.set(ExpressionStatement, node => printLoxAST(node.expression) + (node.context === 'forLoop' ? '' : ';')) +ASTNodeMap.set(ExpressionStatement, (node, scope, options) => printLoxAST(node.expression, 0, options) + (node.context === 'forLoop' ? '' : ';')) ASTNodeMap.set(PrintStatement, node => 'print ' + printLoxAST(node.expression) + ';') @@ -94,7 +94,7 @@ const blockForLoop = ({ statements }, scope, options) => { const printBlock = ({ statements }, scope, options) => '{\n' + - statements.map(stmt => printLoxAST(stmt, scope + 1)).join('\n') + + statements.map(stmt => printLoxAST(stmt, scope + 1, options)).join('\n') + `\n${options.indent.repeat(scope)}}` ASTNodeMap.set(Block, (node, scope, options) => { @@ -134,6 +134,7 @@ ASTNodeMap.set(Call, node => { const callee = printLoxAST(node.callee) return `${callee}(${args})` }) + ASTNodeMap.set(Assignment, node => { const name = node.name.lexeme const value = printLoxAST(node.value)