@improviz/language
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["improviz-language"]=t():e["improviz-language"]=t()}(global,(function(){return(()=>{var e={508:e=>{global,e.exports=function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){return!t||"object"!==r(t)&&"function"!=typeof t?function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e):t}function a(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&l(e,t)}function c(e){var t="function"==typeof Map?new Map:void 0;return(c=function(e){if(null===e||(n=e,-1===Function.toString.call(n).indexOf("[native code]")))return e;var n;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return s(e,arguments,h(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),l(r,e)})(e)}function u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}function s(e,t,n){return(s=u()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var o=new(Function.bind.apply(e,r));return n&&l(o,n.prototype),o}).apply(null,arguments)}function l(e,t){return(l=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function h(e){return(h=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}n.r(t);var f=function(e){function t(e){return o(this,t),i(this,h(t).call(this,e))}return a(t,e),t}(c(Error)),p=function(e){function t(e){return o(this,t),i(this,h(t).call(this,e))}return a(t,e),t}(c(Error)),y=function(e){function t(e,n,r){var a;o(this,t);var c="No viable match in '".concat(e,"...'");return(a=i(this,h(t).call(this,c))).name="UnmatchedCharacterException",a.displayable=!0,a.line=n,a.character=r,a}return a(t,e),t}(p),v=function(e){function t(e){var n;return o(this,t),(n=i(this,h(t).call(this,e))).name="ParserException",n}return a(t,e),t}(c(Error)),d=function(e){function t(e,n){var r;o(this,t);var a="Expected ".concat(e," but found ").concat(n.type);return(r=i(this,h(t).call(this,a))).name="UnexpectedTokenException",r.displayable=!0,r.line=n.line,r.character=n.character,r.length="".concat(n.content).length,r}return a(t,e),t}(v);function b(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var m=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)}var t,n;return t=e,(n=[{key:"initialize",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!e)throw new v("No tokens provided to the parser");if(!(e instanceof Array))throw new v("A non-array was provided to the parser instead of a token array");this.debug=t.debug||!1,this.testing=t.testing||!1,this.tokens=e}},{key:"la1",value:function(e){if(this.eof())throw new v("No tokens available");return this.tokens[0].type==e}},{key:"peek",value:function(){if(this.eof())throw new v("No tokens available");return this.tokens[0]}},{key:"match",value:function(e){if(this.eof())throw new v("Expected ".concat(e," but found EOF"));if(!this.la1(e))throw new d(e,this.tokens[0]);return this.tokens.shift()}},{key:"next",value:function(){if(this.eof())throw new v("Expected token but found EOF");return this.tokens.shift()}},{key:"eof",value:function(){return 0===this.tokens.length}},{key:"expectEof",value:function(){if(!this.eof())throw new d("EOF",this.tokens[0])}},{key:"resetStream",value:function(e){for(;!this.eof()&&!this.la1(e);)this.tokens.shift();!this.eof()&&this.la1(e)&&this.tokens.shift()}},{key:"position",value:function(){return this.testing?{}:{line:this.tokens[0].line,character:this.tokens[0].character}}},{key:"tokenPosition",value:function(e){return this.testing?{}:{line:e.line,character:e.character}}},{key:"debugLog",value:function(e){this.debug&&console.log(e)}}])&&b(t.prototype,n),e}();function k(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var g=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.line=1,this.character=1,this.justSeenSlashR=!1}var t,n;return t=e,(n=[{key:"consume",value:function(e){for(var t=0,n=e.length;t<n;t++)"\r"==e[t]?(this.line+=1,this.character=1,this.justSeenSlashR=!0):"\n"==e[t]?(this.justSeenSlashR||(this.line+=1),this.character=1,this.justSeenSlashR=!1):(this.character+=1,this.justSeenSlashR=!1)}}])&&k(t.prototype,n),e}();function w(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var x=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.tokenTypes=[]}var t,n;return t=e,(n=[{key:"addTokenType",value:function(e){if(!e.name)throw new f("Token types must have a 'name' property");if(!e.regexp&&!e.consume)throw new f("Token types must have a 'regexp' property or a 'consume' function");if(e.regexp&&!(e.regexp instanceof RegExp))throw new f("Token types 'regexp' property must be an instance of RegExp");if(e.consume&&"function"!=typeof e.consume)throw new f("Token types 'consume' property must be a function");if(e.interpret&&"function"!=typeof e.interpret)throw new f("Token types 'interpret' property must be a function");this.tokenTypes.push(e)}},{key:"tokenize",value:function(e){if(void 0===e)throw new p("No content provided");if(0===this.tokenTypes.length)throw new p("No token types defined");for(var t,n,r=[],o=[],i=e,a=new g,c=this.tokenTypes.length;i.length>0;){for(var u=!1,s=0;s<c;s++){var l=this.tokenTypes[s];if(n=void 0,l.consume){if(!(n=l.consume(i)).success)continue;if(0!==i.indexOf(n.consumed))throw new p("The consume function for ".concat(l.name," failed to return the start of the remaining content at ").concat(a.line,".").concat(a.character," and instead returned ").concat(n.consumed));u=!0,t=n.consumed}else{var h=l.regexp.exec(i);if(!h)continue;if(0!==h.index)continue;u=!0,t=h[0]}var f={content:e=l.interpret?l.interpret(t):n&&null!=n.content?n.content:t,type:l.name,line:a.line,character:a.character};l.ignore||r.push(f),i=i.substring(t.length),a.consume(t);break}if(!u){var v=i.substring(0,15).replace("\r","\\r").replace("\t","\\t").replace("\n","\\n");o.push(new y(v,a.line,a.character)),a.consume(i.charAt(0)),i=i.substring(1)}}return{tokens:r,errors:o}}}])&&w(t.prototype,n),e}();function T(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var S=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)}var t,n;return t=e,n=[{key:"constant",value:function(e,t){return{name:t,regexp:new RegExp("^".concat((n=e,n.replace(/([.*+?^=!:${}()|[\]/\\])/g,"\\$1"))))};var n}},{key:"floatingPoint",value:function(){return{name:"floating point",regexp:/(^-?\d*\.\d+)/,interpret:function(e){return parseFloat(e)}}}},{key:"integer",value:function(){return{name:"integer",regexp:/^-?\d+/,interpret:function(e){return parseInt(e)}}}},{key:"whitespace",value:function(){return{name:"whitespace",ignore:!0,regexp:/^[ \t]+/}}},{key:"whitespaceWithNewlines",value:function(){return{name:"whitespace",ignore:!0,regexp:/^[ \t\r\n]+/}}},{key:"real",value:function(){return{name:"real number",regexp:/^X/}}},{key:"comma",value:function(){return this.constant(",","comma")}},{key:"period",value:function(){return this.constant(".","period")}},{key:"star",value:function(){return this.constant("*","star")}},{key:"colon",value:function(){return this.constant(":","colon")}},{key:"openParen",value:function(){return this.constant("(","open paren")}},{key:"closeParen",value:function(){return this.constant(")","close paren")}},{key:"openBracket",value:function(){return this.constant("{","open bracket")}},{key:"closeBracket",value:function(){return this.constant("}","close bracket")}},{key:"openSquareBracket",value:function(){return this.constant("[","open square bracket")}},{key:"closeSquareBracket",value:function(){return this.constant("]","close square bracket")}},{key:"JsonString",value:function(){return{name:"string",regexp:/"(?:[^"\\]|\\.)*"/,consume:function(e){var t={success:!1};if(0!==e.indexOf('"'))return t;var n,r="",o=1,i=!1;do{n=e[o],o+=1;var a=void 0,c=void 0;switch(n){case'"':i=!0;break;case"\\":switch(a=e[o],o+=1,a){default:return t;case"t":r+="\t";break;case"r":r+="\r";break;case"n":r+="\n";break;case"u":if(4==(c=e.substr(o,4)).length&&/\d{4}/.test(c)){o+=4;var u=parseInt(c,10);r+=String.fromCharCode(u)}else r+="\\u"}break;default:r+=n}}while(!i);return{success:!0,consumed:e.substring(0,o),content:r}}}}}],null&&T(t.prototype,null),n&&T(t,n),e}();function O(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function E(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var L=function(){function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};O(this,e),this.operatorStack=[],this.output=[],this.precedences=t,this.astConstructor=n.astConstructor||this.defaultAstConstructor}var t,n;return t=e,(n=[{key:"defaultAstConstructor",value:function(e,t,n){return{op:e,value1:t,value2:n}}},{key:"shuntValue",value:function(e){this.output.push(e)}},{key:"collapseOp",value:function(e){var t=this.output.pop(),n=this.output.pop(),r=this.astConstructor(e,n,t);this.output.push(r)}},{key:"shuntOp",value:function(e){var t=e.content;if(!this.precedences[t])throw new d("".concat(t," is not a valid operator"),e);if(this.operatorStack.length<1)this.operatorStack.push(e);else{var n=this.operatorStack[this.operatorStack.length-1];if(this.precedences[t]<=this.precedences[n.content]){var r=this.operatorStack.pop();this.collapseOp(r)}this.operatorStack.push(e)}}},{key:"getOutput",value:function(){for(;this.operatorStack.length>0;)this.collapseOp(this.operatorStack.pop());if(1!==this.output.length)throw new v("Should only be a single expression in shunter output");return this.output.pop()}}])&&E(t.prototype,n),e}(),P=function(e){return{message:function(){return e},pass:!0}},j=function(e){return{message:function(){return e},pass:!1}},A={toHaveTokenTypes:function(e,t){var n=e.length,r=t.length;if(n!==r)return j("Expected ".concat(r," tokens but found ").concat(n));for(var o=0;o<n;o++){var i=e[o].type,a=t[o];if(i!==a)return j("Expected token type '".concat(a,"' but found '").concat(i,"' at index ").concat(o))}return P("")},toHaveTokenContent:function(e,t){var n=e.length,r=t.length;if(n!==r)return j("Expected ".concat(r," tokens but found ").concat(n));for(var o=0;o<n;o++){var i=e[o].content,a=t[o];if(i!==a)return j("Expected token content '".concat(a,"' but found '").concat(i,"' at index").concat(o))}return P("")},toBeAt:function(e,t,n){var r=e.line,o=e.character;return r!==t?j("Expected line to be ".concat(t," but it was ").concat(r)):(o!==n&&j("Expected character to be ".concat(n," but it was ").concat(o)),P(""))}};n.d(t,"Parser",(function(){return m})),n.d(t,"Lexer",(function(){return x})),n.d(t,"StandardTokenTypes",(function(){return S})),n.d(t,"LineTracker",(function(){return g})),n.d(t,"ArithmaticShunter",(function(){return L})),n.d(t,"PatternDefinitionException",(function(){return f})),n.d(t,"LexerException",(function(){return p})),n.d(t,"UnmatchedCharacterException",(function(){return y})),n.d(t,"ParserException",(function(){return v})),n.d(t,"UnexpectedTokenException",(function(){return d})),n.d(t,"expectMatchers",(function(){return A}))}])}},t={};function n(r){var o=t[r];if(void 0!==o)return o.exports;var i=t[r]={exports:{}};return e[r](i,i.exports,n),i.exports}n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var r={};return(()=>{"use strict";n.r(r),n.d(r,{Ast:()=>He,FFI:()=>Ke,Interpreter:()=>Ye,Lexer:()=>$e,Parser:()=>Pe});var e={};n.r(e),n.d(e,{Application:()=>te,Assignment:()=>H,BinaryOp:()=>ne,Block:()=>Y,BlockArg:()=>ee,BuiltIn:()=>Z,ConditionalAssignment:()=>K,Func:()=>J,If:()=>W,Index:()=>ie,Lambda:()=>X,List:()=>se,Loop:()=>$,Null:()=>ce,Num:()=>ae,Program:()=>q,Symbol:()=>ue,UnaryOp:()=>re,VarArg:()=>Q,Variable:()=>oe});var t={};n.r(t),n.d(t,{isNull:()=>le,isNum:()=>he,isSymbol:()=>fe,makeFunc:()=>pe,makeNum:()=>ye});var o=n(508),i=o.StandardTokenTypes.whitespace(),a={name:"comment",ignore:!0,regexp:/^\/\/[^\n]*/},c={name:"newline",regexp:/^\n+/},u=o.StandardTokenTypes.constant(",","comma"),s=o.StandardTokenTypes.constant(":","colon"),l=o.StandardTokenTypes.constant("=>","lambda arrow"),h=o.StandardTokenTypes.constant("=","assignment"),f=o.StandardTokenTypes.constant("&","&"),p=o.StandardTokenTypes.constant("(","open paren"),y=o.StandardTokenTypes.constant(")","close paren"),v=o.StandardTokenTypes.constant("[","open bracket"),d=o.StandardTokenTypes.constant("]","close bracket"),b=o.StandardTokenTypes.constant("|","pipe"),m=["if","elif","else","null","loop","times","with","func"],k={name:"operator",regexp:/^(==|>=|<=|<|>|&&|\|\||\+|-|\*|\/|%)/},g={name:"number",regexp:/^\d+(\.\d+)?/,interpret:function(e){return parseFloat(e)}},w={name:"identifier",regexp:/^[a-zA-Z][a-zA-Z0-9]*/},x={whiteSpace:i,newline:c,comment:a,comma:u,colon:s,lambdaArrow:l,assignment:h,blockArgSymbol:f,openParen:p,closeParen:y,openBracket:v,closeBracket:d,operator:k,number:g,identifier:w};function T(){var e=new o.Lexer({languageName:"improviz"});return e.addTokenType(i),e.addTokenType(c),e.addTokenType(a),e.addTokenType(k),e.addTokenType(u),e.addTokenType(s),e.addTokenType(b),e.addTokenType(l),e.addTokenType(h),e.addTokenType(f),e.addTokenType(p),e.addTokenType(y),e.addTokenType(v),e.addTokenType(d),e.addTokenType(g),m.forEach((function(t){e.addTokenType(o.StandardTokenTypes.constant(t,t))})),e.addTokenType(w),e}var S="PROGRAM",O="BLOCK",E="LOOP",L="ASSIGNMENT",P="CONDASSIGNMENT",j="IF",A="LAMBDA",N="BUILTIN",R="FUNC",C="APPLICATION",_="BINARYOP",B="UNARYOP",I="VARIABLE",D="INDEX",U="NUM",M="NULL",F="SYMBOL",V="LIST",z="VARARG",G="BLOCKARG";function q(e){return{type:S,statements:e}}function Y(e){return{type:O,elements:e}}function $(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:ce(),r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},o=r.line,i=r.character;return{type:E,count:e,block:t,loopVar:n,line:o,character:i}}function H(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=n.line,o=n.character;return{type:L,identifier:e,expression:t,line:r,character:o}}function K(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=n.line,o=n.character;return{type:P,identifier:e,expression:t,line:r,character:o}}function W(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.line,r=t.character;return{type:j,conditionals:e,line:n,character:r}}function X(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},o=r.line,i=r.character;return{type:A,args:e,scope:t,body:n,line:o,character:i}}function Z(e,t){return{type:N,name:e,func:t}}function J(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:ce(),r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},o=r.line,i=r.character;return{type:R,name:e,args:t,body:n,line:o,character:i}}function Q(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.line,r=t.character;return{type:z,name:e,line:n,character:r}}function ee(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.line,r=t.character;return{type:G,name:e,line:n,character:r}}function te(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:ce(),r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},o=r.line,i=r.character;return{type:C,name:e,args:t,lambda:n,line:o,character:i}}function ne(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},o=r.line,i=r.character;return{type:_,operator:e,left:t,right:n,line:o,character:i}}function re(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=n.line,o=n.character;return{type:B,operator:e,expr:t,line:r,character:o}}function oe(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.line,r=t.character;return{type:I,identifier:e,line:n,character:r}}function ie(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=n.line,o=n.character;return{type:D,collection:e,index:t,line:r,character:o}}function ae(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.line,r=t.character;return{type:U,value:e,line:n,character:r}}function ce(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.line,n=e.character;return{type:M,line:t,character:n}}function ue(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.line,r=t.character;return{type:F,value:e,line:n,character:r}}function se(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.line,r=t.character;return{type:V,values:e,line:n,character:r}}function le(e){return e&&e.type===M}function he(e){return e&&e.type===U}function fe(e){return e&&e.type===F}function pe(e,t){return Z(e,t)}function ye(e){return ae(e)}function ve(e){return ve="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},ve(e)}function de(e,t){return de=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},de(e,t)}function be(e,t){if(t&&("object"===ve(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}function me(e){return me=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},me(e)}var ke=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&de(e,t)}(o,e);var t,n,r=(t=o,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}(),function(){var e,r=me(t);if(n){var o=me(this).constructor;e=Reflect.construct(r,arguments,o)}else e=r.apply(this,arguments);return be(this,e)});function o(e,t,n){var i;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,o);var a="Expected ".concat(e," levels of indentation but found ").concat(t);return(i=r.call(this,a)).name="IncorrectIndentationException",i.displayable=!0,i.line=n.line,i.character=n.character,i.length=n.content.length,i}return o}(o.ParserException);function ge(e){return ge="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},ge(e)}function we(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function xe(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function Te(e,t){return Te=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},Te(e,t)}function Se(e,t){if(t&&("object"===ge(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}function Oe(e){return Oe=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},Oe(e)}var Ee={"^":15,"*":14,"/":14,"%":14,"+":13,"-":13,"<":11,"<=":11,">":11,">=":11,"==":10,"!=":10,"&&":6,"||":5},Le=function(e,t,n){return ne(e.content,t,n,void 0,{})},Pe=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&Te(e,t)}(c,e);var t,n,r,i,a=(r=c,i=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}(),function(){var e,t=Oe(r);if(i){var n=Oe(this).constructor;e=Reflect.construct(t,arguments,n)}else e=t.apply(this,arguments);return Se(this,e)});function c(){return we(this,c),a.apply(this,arguments)}return t=c,n=[{key:"clearNewlines",value:function(){for(;!this.eof()&&this.la1("newline");)this.match("newline")}},{key:"calculateBlockLevel",value:function(e){return Math.round((e.character-1)/2)}},{key:"blockDepthCheck",value:function(e,t){var n=this.calculateBlockLevel(t);return e!==n&&this.errors.push(new ke(e,n,t)),n}},{key:"skipUntil",value:function(e){for(;!this.eof();){var t=this.peek();if(e.includes(t.type))break;this.next()}}},{key:"parse",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.debugLog("With Debugging"),this.errors=[];var r=T(),o=r.tokenize(e);o.errors.forEach((function(e){return t.errors.push(e)})),this.initialize(o.tokens,n);var i=this.program();return{ast:i,errors:this.errors}}},{key:"program",value:function(){this.debugLog("Program");var e=[];for(this.clearNewlines();!this.eof();)e.push(this.statement(0));return q(e)}},{key:"statement",value:function(e){if(this.debugLog("Statement"),this.la1("if"))return this.if(e);if(this.la1("func"))return this.funcDef(e);if(this.la1("loop"))return this.loop(e);if(this.la1("identifier")){var t=this.match("identifier");if(this.blockDepthCheck(e,t),this.la1("assignment")||this.la1("colon"))return this.assignment(t);if(this.la1("open paren"))return this.application(e,t)}var n=this.peek();this.errors.push(new o.UnexpectedTokenException(n.type,n)),this.skipUntil(["newline"]),this.clearNewlines()}},{key:"block",value:function(e){this.debugLog("Block");for(var t=e,n=[];!this.eof();){var r=this.peek();if(this.calculateBlockLevel(r)<t)break;n.push(this.element(e))}return Y(n)}},{key:"element",value:function(e){if(this.debugLog("Element"),this.la1("if"))return this.if(e);if(this.la1("func"))return this.funcDef(e);if(this.la1("loop"))return this.loop(e);if(this.la1("identifier")){var t=this.match("identifier");if(this.blockDepthCheck(e,t),this.la1("assignment")||this.la1("colon"))return this.assignment(t);if(this.la1("open paren"))return this.application(e,t)}var n=this.peek();this.errors.push(new o.UnexpectedTokenException(n.type,n)),this.skipUntil(["newline"]),this.clearNewlines()}},{key:"if",value:function(e){this.debugLog("If");var t,n=this.position(),r=[],o=this.match("if");this.blockDepthCheck(e,o);try{t=this.expression()}catch(e){this.errors.push(e),this.resetStream("newline"),t=ce()}this.clearNewlines();var i=this.block(e+1);if(r.push([t,i]),this.eof()||!this.la1("else"))return W(r,n);for(;!this.eof()&&this.la1("else");){var a=this.match("else");this.blockDepthCheck(e,a);var c=void 0;if(this.la1("if")){this.match("if");try{c=this.expression()}catch(e){this.errors.push(e),this.resetStream("newline"),c=ce()}}else c=ae(1);this.clearNewlines();var u=this.block(e+1);r.push([c,u])}return W(r,n)}},{key:"funcDef",value:function(e){this.debugLog("Function Definition");var t,n,r,o=this.position(),i=this.match("func");this.blockDepthCheck(e,i);try{if(t=this.match("identifier").content,this.match("open paren"),n=this.argList("close paren","comma"),this.match("close paren"),this.la1("lambda arrow"))return this.match("lambda arrow"),r=this.expression(),this.clearNewlines(),J(t,n,Y([r]),o)}catch(e){this.errors.push(e),this.resetStream("newline")}return this.clearNewlines(),J(t,n,this.block(e+1),o)}},{key:"argList",value:function(e,t){var n=[];if(this.la1(e))return this.debugLog("argList: 0 args"),n;for(n.push(this.functionArg());this.la1(t);)this.match(t),n.push(this.functionArg());return this.debugLog("argList: ".concat(n.length," args")),n}},{key:"functionArg",value:function(){return this.debugLog("Function Argument"),this.la1("&")?(this.match("&"),ee(this.match("identifier").content)):Q(this.match("identifier").content)}},{key:"loop",value:function(e){this.debugLog("Loop");var t,n,r=this.position(),o=this.match("loop");this.blockDepthCheck(e,o);try{t=this.expression(),this.match("times"),n=ce(),this.la1("with")&&(this.match("with"),n=this.variable())}catch(e){this.errors.push(e),this.resetStream("newline")}return this.clearNewlines(),$(t,this.block(e+1),n,r)}},{key:"assignment",value:function(e){this.debugLog("Assignment");var t,n=this.tokenPosition(e);if(this.la1("colon")){try{this.match("colon"),this.match("assignment"),t=this.expression()}catch(e){this.errors.push(e),this.resetStream("newline")}return this.clearNewlines(),K(e.content,t,n)}try{this.match("assignment"),t=this.expression()}catch(e){this.errors.push(e),this.resetStream("newline")}return this.clearNewlines(),H(e.content,t,n)}},{key:"application",value:function(e,t){this.debugLog("Application");var n,r=this.tokenPosition(t);try{this.match("open paren"),n=this.exprList(),this.match("close paren")}catch(e){this.errors.push(e),this.resetStream("newline")}if(this.eof()||!this.la1("newline"))return te(t.content,n,ce(),r);if(this.clearNewlines(),this.eof())return te(t.content,n,ce(),r);if(this.calculateBlockLevel(this.peek())<=e)return te(t.content,n,ce(),r);var o=this.applicationLambda(e+1);return te(t.content,n,o,r)}},{key:"applicationLambda",value:function(e){var t=this.position(),n=[];if(this.la1("pipe")){var r=this.match("pipe");this.blockDepthCheck(e,r);try{n=this.argList("pipe","comma"),this.match("pipe"),this.match("newline")}catch(e){this.errors.push(e),this.resetStream("newline")}}var o=this.block(e);return X(n,ce(),o,t)}},{key:"expressionApplication",value:function(e){var t,n=this.position();try{this.match("open paren"),t=this.exprList(),this.match("close paren")}catch(e){this.errors.push(e),this.resetStream("newline")}return te(e.content,t,ce(),n)}},{key:"exprList",value:function(){var e=[];if(this.la1("close paren"))return this.debugLog("exprList: 0 args"),e;for(e.push(this.expression());this.la1("comma");){this.match("comma");var t=void 0;try{t=this.expression()}catch(e){this.errors.push(e),this.resetStream("comma")}e.push(t)}return this.debugLog("exprList: ".concat(e.length," args")),e}},{key:"expression",value:function(){this.debugLog("Expression");var e=this.baseExpression();return!this.eof()&&this.la1("operator")?this.operator(e):e}},{key:"operator",value:function(e){this.debugLog("Operator");var t=new o.ArithmaticShunter(Ee,{astConstructor:Le});for(t.shuntValue(e);!this.eof()&&this.la1("operator");)t.shuntOp(this.match("operator")),t.shuntValue(this.baseExpression());return t.getOutput()}},{key:"baseExpression",value:function(){var e;if(this.debugLog("Base Expression"),this.la1("number"))e=this.number();else if(this.la1("open paren"))this.match("open paren"),e=this.expression(),this.match("close paren");else if(this.la1("operator")){var t=this.match("operator"),n=this.baseExpression();e=re(t.content,n)}else if(this.la1("colon"))this.match("colon"),e=ue(this.match("identifier").content);else if(this.la1("null"))this.match("null"),e=ce();else if(this.la1("open bracket")){this.match("open bracket");var r=this.exprList();this.match("close bracket"),e=se(r)}else if(this.la1("identifier")){var o=this.match("identifier");e=!this.eof()&&this.la1("open paren")?this.expressionApplication(o):oe(o.content)}for(;!this.eof()&&this.la1("open bracket");){this.match("open bracket");var i=this.expression();this.match("close bracket"),e=ie(e,i)}return e}},{key:"number",value:function(){this.debugLog("Number");var e=this.position();return ae(this.match("number").content,e)}},{key:"variable",value:function(){this.debugLog("Variable");var e=this.position();return oe(this.match("identifier").content,e)}}],n&&xe(t.prototype,n),c}(o.Parser);function je(e){return je="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},je(e)}function Ae(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function Ne(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&De(e,t)}function Re(e){var t=Ie();return function(){var n,r=Ue(e);if(t){var o=Ue(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return Ce(this,n)}}function Ce(e,t){if(t&&("object"===je(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}function _e(e){var t="function"==typeof Map?new Map:void 0;return _e=function(e){if(null===e||(n=e,-1===Function.toString.call(n).indexOf("[native code]")))return e;var n;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return Be(e,arguments,Ue(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),De(r,e)},_e(e)}function Be(e,t,n){return Be=Ie()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var o=new(Function.bind.apply(e,r));return n&&De(o,n.prototype),o},Be.apply(null,arguments)}function Ie(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function De(e,t){return De=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},De(e,t)}function Ue(e){return Ue=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},Ue(e)}var Me=function(e){Ne(n,e);var t=Re(n);function n(e){var r;return Ae(this,n),(r=t.call(this,e)).name="InvalidProgramError",r}return n}(_e(Error)),Fe=function(e){Ne(n,e);var t=Re(n);function n(e,r){var o;return Ae(this,n),(o=t.call(this,e)).name="InterpreterError",o.line=r.line,o.character=r.character,o}return n}(_e(Error));function Ve(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,o,i=[],a=!0,c=!1;try{for(n=n.call(e);!(a=(r=n.next()).done)&&(i.push(r.value),!t||i.length!==t);a=!0);}catch(e){c=!0,o=e}finally{try{a||null==n.return||n.return()}finally{if(c)throw o}}return i}}(e,t)||function(e,t){if(e){if("string"==typeof e)return ze(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?ze(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function ze(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function Ge(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function qe(e){return Object.create(e)}var Ye=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)}var t,n;return t=e,n=[{key:"run",value:function(e,t,n){var r,o={errors:[],exitCode:0};if(!e||e.type!==S)return o.errors.push(new Me("Invalid Program")),o.exitCode=1,o;r=n?t:qe(t);try{this.evaluateProgram(e,r)}catch(e){o.errors.push(e),o.exitCode=1}return o}},{key:"evaluateProgram",value:function(e,t){for(var n=0;n<e.statements.length;n+=1){var r=e.statements[n];this.evaluate(r,t)}}},{key:"evaluate",value:function(e,t){var n,r=this;switch(e.type){case O:n=this.evaluateBlock(e,t);break;case E:n=this.evaluateLoop(e,t);break;case L:case P:n=this.evaluateAssignment(e,t);break;case j:n=this.evaluateIf(e,t);break;case A:n=this.evaluateLambda(e,t);break;case R:n=this.evaluateFunctionDefinition(e,t);break;case C:n=this.evaluateApplication(e,t);break;case _:n=this.evaluateBinaryOp(e,t);break;case B:n=this.evaluateUnaryOp(e,t);break;case I:n=this.evaluateVariable(e,t);break;case D:n=this.evaluateDeIndex(e,t);break;case U:case F:n=e;break;case V:n=e.values.map((function(e){return r.evaluate(e,t)}));break;default:throw new Fe("Unknown AST Type: ".concat(e.type),e)}return n}},{key:"evaluateBlock",value:function(e,t){for(var n=qe(t),r=ce(),o=0;o<e.elements.length;o+=1){var i=e.elements[o];r=this.evaluate(i,n)}return r}},{key:"evaluateAssignment",value:function(e,t){var n=this.evaluate(e.expression,t);return e.type===L?t[e.identifier]=n:e.type!==P||void 0!==t[e.identifier]&&t[e.identifier].type!==M||(t[e.identifier]=n),n}},{key:"isNull",value:function(e){return null==e||e.type===M}},{key:"notNull",value:function(e){return null!=e&&e.type!==M}},{key:"truthyValue",value:function(e){return!this.isNull(e)&&(e.type!==U||0!==e.value)}},{key:"checkNum",value:function(e){if(!e||e.type!==U)throw new Fe("Expected Number but found: ".concat(e.type),e)}},{key:"evaluateIf",value:function(e,t){for(var n=e.conditionals,r=0;r<n.length;r+=1){var o=Ve(n[r],2),i=o[0],a=o[1];this.truthyValue(this.evaluate(i,t))&&this.evaluateBlock(a,t)}}},{key:"evaluateApplication",value:function(e,t){var n=this,r=e.name,o=e.args,i=e.lambda,a=t[r];if(!a||a.type===A&&a.type===N)throw new Fe("".concat(r," is not a function"),e);var c=o.map((function(e){return n.evaluate(e,t)}));if(a.type===A){for(var u=this.notNull(a.scope)?a.scope:qe(t),s=0;s<a.args.length;s+=1){var l=a.args[s];switch(l.type){case z:u[l.name]=c[s]||ce();break;case G:if(this.isNull(i)){u[l.name]=ce();break}this.isNull(i.scope)&&(i.scope=t),u[l.name]=i;break;default:throw new Fe("Unknown variable type ".concat(l.type),l)}}return this.evaluateBlock(a.body,u)}if(a.type===N)return a.func(c,i)}},{key:"blockToLambda",value:function(e,t){return X([],t,e)}},{key:"evaluateLambda",value:function(e){throw new Fe("Shouldn't be evaluating a lambda",e)}},{key:"evaluateFunctionDefinition",value:function(e,t){var n=e.name,r=X(e.args,t,e.body);t[n]=r}},{key:"evaluateLoop",value:function(e,t){var n=e.count,r=e.block,o=e.loopVar,i=this.evaluate(n,t);if(i.type!==U)throw new Fe("Loop count should be a number",n);for(var a=i.value,c=qe(t),u=0;u<a;u+=1)this.notNull(o)&&(c[o.identifier]=ae(u)),this.evaluate(r,c)}},{key:"evaluateUnaryOp",value:function(e,t){var n=this.evaluate(e.expr,t);this.checkNum(n);var r=n.value;if("-"!==e.operator)throw new Fe("".concat(e.operator," is an unknown operator"),e);return ae(-1*r)}},{key:"evaluateBinaryOp",value:function(e,t){var n,r=this.evaluate(e.left,t);this.checkNum(r);var o=this.evaluate(e.right,t);this.checkNum(o);var i=r.value,a=o.value;switch(e.operator){case"+":n=i+a;break;case"-":n=i-a;break;case"*":n=i*a;break;case"/":n=i/a;break;case"^":n=Math.pow(i,a);break;case"%":n=i%a;break;case">":n=i>a?1:0;break;case"<":n=i<a?1:0;break;case">=":n=i>=a?1:0;break;case"<=":n=i<=a?1:0;break;case"==":n=i===a?1:0;break;case"&&":n=i&&a?1:0;break;case"||":n=i||a?1:0;break;default:throw new Fe("".concat(e.operator," is an unknown operator"),e)}return ae(n)}},{key:"evaluateVariable",value:function(e,t){var n=t[e.identifier];if(void 0===n)throw new Fe("Undefined Variable: ".concat(e.identifier),e);return n}},{key:"evaluateDeIndex",value:function(e,t){var n=this.evaluate(e.collection,t);if(!Array.isArray(n))throw new Fe("Can only deindex a list",e);var r=this.evaluate(e.index,t);return this.checkNum(r),n[r.value]}}],n&&Ge(t.prototype,n),e}(),$e={tokenIdentifiers:x,keywords:m},He=e,Ke=t})(),r})()})); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["improviz-language"]=t():e["improviz-language"]=t()}(global,(function(){return(()=>{var e={508:e=>{global,e.exports=function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){return!t||"object"!==r(t)&&"function"!=typeof t?function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e):t}function a(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&l(e,t)}function c(e){var t="function"==typeof Map?new Map:void 0;return(c=function(e){if(null===e||(n=e,-1===Function.toString.call(n).indexOf("[native code]")))return e;var n;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return s(e,arguments,h(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),l(r,e)})(e)}function u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}function s(e,t,n){return(s=u()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var o=new(Function.bind.apply(e,r));return n&&l(o,n.prototype),o}).apply(null,arguments)}function l(e,t){return(l=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function h(e){return(h=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}n.r(t);var f=function(e){function t(e){return o(this,t),i(this,h(t).call(this,e))}return a(t,e),t}(c(Error)),p=function(e){function t(e){return o(this,t),i(this,h(t).call(this,e))}return a(t,e),t}(c(Error)),y=function(e){function t(e,n,r){var a;o(this,t);var c="No viable match in '".concat(e,"...'");return(a=i(this,h(t).call(this,c))).name="UnmatchedCharacterException",a.displayable=!0,a.line=n,a.character=r,a}return a(t,e),t}(p),v=function(e){function t(e){var n;return o(this,t),(n=i(this,h(t).call(this,e))).name="ParserException",n}return a(t,e),t}(c(Error)),d=function(e){function t(e,n){var r;o(this,t);var a="Expected ".concat(e," but found ").concat(n.type);return(r=i(this,h(t).call(this,a))).name="UnexpectedTokenException",r.displayable=!0,r.line=n.line,r.character=n.character,r.length="".concat(n.content).length,r}return a(t,e),t}(v);function b(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var m=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)}var t,n;return t=e,(n=[{key:"initialize",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!e)throw new v("No tokens provided to the parser");if(!(e instanceof Array))throw new v("A non-array was provided to the parser instead of a token array");this.debug=t.debug||!1,this.testing=t.testing||!1,this.tokens=e}},{key:"la1",value:function(e){if(this.eof())throw new v("No tokens available");return this.tokens[0].type==e}},{key:"peek",value:function(){if(this.eof())throw new v("No tokens available");return this.tokens[0]}},{key:"match",value:function(e){if(this.eof())throw new v("Expected ".concat(e," but found EOF"));if(!this.la1(e))throw new d(e,this.tokens[0]);return this.tokens.shift()}},{key:"next",value:function(){if(this.eof())throw new v("Expected token but found EOF");return this.tokens.shift()}},{key:"eof",value:function(){return 0===this.tokens.length}},{key:"expectEof",value:function(){if(!this.eof())throw new d("EOF",this.tokens[0])}},{key:"resetStream",value:function(e){for(;!this.eof()&&!this.la1(e);)this.tokens.shift();!this.eof()&&this.la1(e)&&this.tokens.shift()}},{key:"position",value:function(){return this.testing?{}:{line:this.tokens[0].line,character:this.tokens[0].character}}},{key:"tokenPosition",value:function(e){return this.testing?{}:{line:e.line,character:e.character}}},{key:"debugLog",value:function(e){this.debug&&console.log(e)}}])&&b(t.prototype,n),e}();function k(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var g=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.line=1,this.character=1,this.justSeenSlashR=!1}var t,n;return t=e,(n=[{key:"consume",value:function(e){for(var t=0,n=e.length;t<n;t++)"\r"==e[t]?(this.line+=1,this.character=1,this.justSeenSlashR=!0):"\n"==e[t]?(this.justSeenSlashR||(this.line+=1),this.character=1,this.justSeenSlashR=!1):(this.character+=1,this.justSeenSlashR=!1)}}])&&k(t.prototype,n),e}();function w(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var x=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.tokenTypes=[]}var t,n;return t=e,(n=[{key:"addTokenType",value:function(e){if(!e.name)throw new f("Token types must have a 'name' property");if(!e.regexp&&!e.consume)throw new f("Token types must have a 'regexp' property or a 'consume' function");if(e.regexp&&!(e.regexp instanceof RegExp))throw new f("Token types 'regexp' property must be an instance of RegExp");if(e.consume&&"function"!=typeof e.consume)throw new f("Token types 'consume' property must be a function");if(e.interpret&&"function"!=typeof e.interpret)throw new f("Token types 'interpret' property must be a function");this.tokenTypes.push(e)}},{key:"tokenize",value:function(e){if(void 0===e)throw new p("No content provided");if(0===this.tokenTypes.length)throw new p("No token types defined");for(var t,n,r=[],o=[],i=e,a=new g,c=this.tokenTypes.length;i.length>0;){for(var u=!1,s=0;s<c;s++){var l=this.tokenTypes[s];if(n=void 0,l.consume){if(!(n=l.consume(i)).success)continue;if(0!==i.indexOf(n.consumed))throw new p("The consume function for ".concat(l.name," failed to return the start of the remaining content at ").concat(a.line,".").concat(a.character," and instead returned ").concat(n.consumed));u=!0,t=n.consumed}else{var h=l.regexp.exec(i);if(!h)continue;if(0!==h.index)continue;u=!0,t=h[0]}var f={content:e=l.interpret?l.interpret(t):n&&null!=n.content?n.content:t,type:l.name,line:a.line,character:a.character};l.ignore||r.push(f),i=i.substring(t.length),a.consume(t);break}if(!u){var v=i.substring(0,15).replace("\r","\\r").replace("\t","\\t").replace("\n","\\n");o.push(new y(v,a.line,a.character)),a.consume(i.charAt(0)),i=i.substring(1)}}return{tokens:r,errors:o}}}])&&w(t.prototype,n),e}();function T(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var S=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)}var t,n;return t=e,n=[{key:"constant",value:function(e,t){return{name:t,regexp:new RegExp("^".concat((n=e,n.replace(/([.*+?^=!:${}()|[\]/\\])/g,"\\$1"))))};var n}},{key:"floatingPoint",value:function(){return{name:"floating point",regexp:/(^-?\d*\.\d+)/,interpret:function(e){return parseFloat(e)}}}},{key:"integer",value:function(){return{name:"integer",regexp:/^-?\d+/,interpret:function(e){return parseInt(e)}}}},{key:"whitespace",value:function(){return{name:"whitespace",ignore:!0,regexp:/^[ \t]+/}}},{key:"whitespaceWithNewlines",value:function(){return{name:"whitespace",ignore:!0,regexp:/^[ \t\r\n]+/}}},{key:"real",value:function(){return{name:"real number",regexp:/^X/}}},{key:"comma",value:function(){return this.constant(",","comma")}},{key:"period",value:function(){return this.constant(".","period")}},{key:"star",value:function(){return this.constant("*","star")}},{key:"colon",value:function(){return this.constant(":","colon")}},{key:"openParen",value:function(){return this.constant("(","open paren")}},{key:"closeParen",value:function(){return this.constant(")","close paren")}},{key:"openBracket",value:function(){return this.constant("{","open bracket")}},{key:"closeBracket",value:function(){return this.constant("}","close bracket")}},{key:"openSquareBracket",value:function(){return this.constant("[","open square bracket")}},{key:"closeSquareBracket",value:function(){return this.constant("]","close square bracket")}},{key:"JsonString",value:function(){return{name:"string",regexp:/"(?:[^"\\]|\\.)*"/,consume:function(e){var t={success:!1};if(0!==e.indexOf('"'))return t;var n,r="",o=1,i=!1;do{n=e[o],o+=1;var a=void 0,c=void 0;switch(n){case'"':i=!0;break;case"\\":switch(a=e[o],o+=1,a){default:return t;case"t":r+="\t";break;case"r":r+="\r";break;case"n":r+="\n";break;case"u":if(4==(c=e.substr(o,4)).length&&/\d{4}/.test(c)){o+=4;var u=parseInt(c,10);r+=String.fromCharCode(u)}else r+="\\u"}break;default:r+=n}}while(!i);return{success:!0,consumed:e.substring(0,o),content:r}}}}}],null&&T(t.prototype,null),n&&T(t,n),e}();function O(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function E(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var L=function(){function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};O(this,e),this.operatorStack=[],this.output=[],this.precedences=t,this.astConstructor=n.astConstructor||this.defaultAstConstructor}var t,n;return t=e,(n=[{key:"defaultAstConstructor",value:function(e,t,n){return{op:e,value1:t,value2:n}}},{key:"shuntValue",value:function(e){this.output.push(e)}},{key:"collapseOp",value:function(e){var t=this.output.pop(),n=this.output.pop(),r=this.astConstructor(e,n,t);this.output.push(r)}},{key:"shuntOp",value:function(e){var t=e.content;if(!this.precedences[t])throw new d("".concat(t," is not a valid operator"),e);if(this.operatorStack.length<1)this.operatorStack.push(e);else{var n=this.operatorStack[this.operatorStack.length-1];if(this.precedences[t]<=this.precedences[n.content]){var r=this.operatorStack.pop();this.collapseOp(r)}this.operatorStack.push(e)}}},{key:"getOutput",value:function(){for(;this.operatorStack.length>0;)this.collapseOp(this.operatorStack.pop());if(1!==this.output.length)throw new v("Should only be a single expression in shunter output");return this.output.pop()}}])&&E(t.prototype,n),e}(),P=function(e){return{message:function(){return e},pass:!0}},j=function(e){return{message:function(){return e},pass:!1}},A={toHaveTokenTypes:function(e,t){var n=e.length,r=t.length;if(n!==r)return j("Expected ".concat(r," tokens but found ").concat(n));for(var o=0;o<n;o++){var i=e[o].type,a=t[o];if(i!==a)return j("Expected token type '".concat(a,"' but found '").concat(i,"' at index ").concat(o))}return P("")},toHaveTokenContent:function(e,t){var n=e.length,r=t.length;if(n!==r)return j("Expected ".concat(r," tokens but found ").concat(n));for(var o=0;o<n;o++){var i=e[o].content,a=t[o];if(i!==a)return j("Expected token content '".concat(a,"' but found '").concat(i,"' at index").concat(o))}return P("")},toBeAt:function(e,t,n){var r=e.line,o=e.character;return r!==t?j("Expected line to be ".concat(t," but it was ").concat(r)):(o!==n&&j("Expected character to be ".concat(n," but it was ").concat(o)),P(""))}};n.d(t,"Parser",(function(){return m})),n.d(t,"Lexer",(function(){return x})),n.d(t,"StandardTokenTypes",(function(){return S})),n.d(t,"LineTracker",(function(){return g})),n.d(t,"ArithmaticShunter",(function(){return L})),n.d(t,"PatternDefinitionException",(function(){return f})),n.d(t,"LexerException",(function(){return p})),n.d(t,"UnmatchedCharacterException",(function(){return y})),n.d(t,"ParserException",(function(){return v})),n.d(t,"UnexpectedTokenException",(function(){return d})),n.d(t,"expectMatchers",(function(){return A}))}])}},t={};function n(r){var o=t[r];if(void 0!==o)return o.exports;var i=t[r]={exports:{}};return e[r](i,i.exports,n),i.exports}n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var r={};return(()=>{"use strict";n.r(r),n.d(r,{Ast:()=>Ke,Errors:()=>He,FFI:()=>We,Interpreter:()=>Ye,Lexer:()=>$e,Parser:()=>Fe});var e={};n.r(e),n.d(e,{Application:()=>me,Assignment:()=>le,BinaryOp:()=>ke,Block:()=>ue,BlockArg:()=>be,BuiltIn:()=>ye,ConditionalAssignment:()=>he,Func:()=>ve,If:()=>fe,Index:()=>xe,Lambda:()=>pe,List:()=>Ee,Loop:()=>se,Null:()=>Se,Num:()=>Te,Program:()=>ce,Symbol:()=>Oe,UnaryOp:()=>ge,VarArg:()=>de,Variable:()=>we});var t={};n.r(t),n.d(t,{isNull:()=>Le,isNum:()=>Pe,isSymbol:()=>je,makeFunc:()=>Ae,makeNum:()=>Ne});var o=n(508),i=o.StandardTokenTypes.whitespace(),a={name:"comment",ignore:!0,regexp:/^\/\/[^\n]*/},c={name:"newline",regexp:/^\n+/},u=o.StandardTokenTypes.constant(",","comma"),s=o.StandardTokenTypes.constant(":","colon"),l=o.StandardTokenTypes.constant("=>","lambda arrow"),h=o.StandardTokenTypes.constant("=","assignment"),f=o.StandardTokenTypes.constant("&","&"),p=o.StandardTokenTypes.constant("(","open paren"),y=o.StandardTokenTypes.constant(")","close paren"),v=o.StandardTokenTypes.constant("[","open bracket"),d=o.StandardTokenTypes.constant("]","close bracket"),b=o.StandardTokenTypes.constant("|","pipe"),m=["if","elif","else","null","loop","times","with","func"],k={name:"operator",regexp:/^(==|>=|<=|<|>|&&|\|\||\+|-|\*|\/|%)/},g={name:"number",regexp:/^\d+(\.\d+)?/,interpret:function(e){return parseFloat(e)}},w={name:"identifier",regexp:/^[a-zA-Z][a-zA-Z0-9]*/},x={whiteSpace:i,newline:c,comment:a,comma:u,colon:s,lambdaArrow:l,assignment:h,blockArgSymbol:f,openParen:p,closeParen:y,openBracket:v,closeBracket:d,operator:k,number:g,identifier:w};function T(){var e=new o.Lexer({languageName:"improviz"});return e.addTokenType(i),e.addTokenType(c),e.addTokenType(a),e.addTokenType(k),e.addTokenType(u),e.addTokenType(s),e.addTokenType(b),e.addTokenType(l),e.addTokenType(h),e.addTokenType(f),e.addTokenType(p),e.addTokenType(y),e.addTokenType(v),e.addTokenType(d),e.addTokenType(g),m.forEach((function(t){e.addTokenType(o.StandardTokenTypes.constant(t,t))})),e.addTokenType(w),e}function S(e){return S="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},S(e)}function O(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function E(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&R(e,t)}function L(e){var t=N();return function(){var n,r=C(e);if(t){var o=C(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return P(this,n)}}function P(e,t){if(t&&("object"===S(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}function j(e){var t="function"==typeof Map?new Map:void 0;return j=function(e){if(null===e||(n=e,-1===Function.toString.call(n).indexOf("[native code]")))return e;var n;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return A(e,arguments,C(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),R(r,e)},j(e)}function A(e,t,n){return A=N()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var o=new(Function.bind.apply(e,r));return n&&R(o,n.prototype),o},A.apply(null,arguments)}function N(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function R(e,t){return R=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},R(e,t)}function C(e){return C=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},C(e)}var _=function(e){E(n,e);var t=L(n);function n(e){var r;return O(this,n),(r=t.call(this,e)).name="InvalidProgramError",r}return n}(j(Error)),B=function(e){E(n,e);var t=L(n);function n(e,r){var o;return O(this,n),(o=t.call(this,e)).name="InterpreterError",o.line=r.line,o.character=r.character,o}return n}(j(Error));function I(e){return I="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},I(e)}function D(e,t){return D=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},D(e,t)}function U(e,t){if(t&&("object"===I(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}function M(e){return M=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},M(e)}var F=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&D(e,t)}(o,e);var t,n,r=(t=o,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}(),function(){var e,r=M(t);if(n){var o=M(this).constructor;e=Reflect.construct(r,arguments,o)}else e=r.apply(this,arguments);return U(this,e)});function o(e,t,n){var i;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,o);var a="Expected ".concat(e," levels of indentation but found ").concat(t);return(i=r.call(this,a)).name="IncorrectIndentationException",i.displayable=!0,i.line=n.line,i.character=n.character,i.length=n.content.length,i}return o}(o.ParserException),V="PROGRAM",z="BLOCK",G="LOOP",q="ASSIGNMENT",Y="CONDASSIGNMENT",$="IF",H="LAMBDA",K="BUILTIN",W="FUNC",X="APPLICATION",Z="BINARYOP",J="UNARYOP",Q="VARIABLE",ee="INDEX",te="NUM",ne="NULL",re="SYMBOL",oe="LIST",ie="VARARG",ae="BLOCKARG";function ce(e){return{type:V,statements:e}}function ue(e){return{type:z,elements:e}}function se(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Se(),r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},o=r.line,i=r.character;return{type:G,count:e,block:t,loopVar:n,line:o,character:i}}function le(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=n.line,o=n.character;return{type:q,identifier:e,expression:t,line:r,character:o}}function he(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=n.line,o=n.character;return{type:Y,identifier:e,expression:t,line:r,character:o}}function fe(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.line,r=t.character;return{type:$,conditionals:e,line:n,character:r}}function pe(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},o=r.line,i=r.character;return{type:H,args:e,scope:t,body:n,line:o,character:i}}function ye(e,t){return{type:K,name:e,func:t}}function ve(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Se(),r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},o=r.line,i=r.character;return{type:W,name:e,args:t,body:n,line:o,character:i}}function de(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.line,r=t.character;return{type:ie,name:e,line:n,character:r}}function be(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.line,r=t.character;return{type:ae,name:e,line:n,character:r}}function me(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Se(),r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},o=r.line,i=r.character;return{type:X,name:e,args:t,lambda:n,line:o,character:i}}function ke(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},o=r.line,i=r.character;return{type:Z,operator:e,left:t,right:n,line:o,character:i}}function ge(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=n.line,o=n.character;return{type:J,operator:e,expr:t,line:r,character:o}}function we(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.line,r=t.character;return{type:Q,identifier:e,line:n,character:r}}function xe(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=n.line,o=n.character;return{type:ee,collection:e,index:t,line:r,character:o}}function Te(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.line,r=t.character;return{type:te,value:e,line:n,character:r}}function Se(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.line,n=e.character;return{type:ne,line:t,character:n}}function Oe(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.line,r=t.character;return{type:re,value:e,line:n,character:r}}function Ee(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.line,r=t.character;return{type:oe,values:e,line:n,character:r}}function Le(e){return e&&e.type===ne}function Pe(e){return e&&e.type===te}function je(e){return e&&e.type===re}function Ae(e,t){return ye(e,t)}function Ne(e){return Te(e)}function Re(e){return Re="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Re(e)}function Ce(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function Be(e,t){return Be=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},Be(e,t)}function Ie(e,t){if(t&&("object"===Re(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}function De(e){return De=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},De(e)}var Ue={"^":15,"*":14,"/":14,"%":14,"+":13,"-":13,"<":11,"<=":11,">":11,">=":11,"==":10,"!=":10,"&&":6,"||":5},Me=function(e,t,n){return ke(e.content,t,n,void 0,{})},Fe=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&Be(e,t)}(c,e);var t,n,r,i,a=(r=c,i=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}(),function(){var e,t=De(r);if(i){var n=De(this).constructor;e=Reflect.construct(t,arguments,n)}else e=t.apply(this,arguments);return Ie(this,e)});function c(){return Ce(this,c),a.apply(this,arguments)}return t=c,n=[{key:"clearNewlines",value:function(){for(;!this.eof()&&this.la1("newline");)this.match("newline")}},{key:"calculateBlockLevel",value:function(e){return Math.round((e.character-1)/2)}},{key:"blockDepthCheck",value:function(e,t){var n=this.calculateBlockLevel(t);return e!==n&&this.errors.push(new F(e,n,t)),n}},{key:"skipUntil",value:function(e){for(;!this.eof();){var t=this.peek();if(e.includes(t.type))break;this.next()}}},{key:"parse",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.debugLog("With Debugging"),this.errors=[];var r=T(),o=r.tokenize(e);o.errors.forEach((function(e){return t.errors.push(e)})),this.initialize(o.tokens,n);var i=this.program();return{ast:i,errors:this.errors}}},{key:"program",value:function(){this.debugLog("Program");var e=[];for(this.clearNewlines();!this.eof();)e.push(this.statement(0));return ce(e)}},{key:"statement",value:function(e){if(this.debugLog("Statement"),this.la1("if"))return this.if(e);if(this.la1("func"))return this.funcDef(e);if(this.la1("loop"))return this.loop(e);if(this.la1("identifier")){var t=this.match("identifier");if(this.blockDepthCheck(e,t),this.la1("assignment")||this.la1("colon"))return this.assignment(t);if(this.la1("open paren"))return this.application(e,t)}var n=this.peek();this.errors.push(new o.UnexpectedTokenException(n.type,n)),this.skipUntil(["newline"]),this.clearNewlines()}},{key:"block",value:function(e){this.debugLog("Block");for(var t=e,n=[];!this.eof();){var r=this.peek();if(this.calculateBlockLevel(r)<t)break;n.push(this.element(e))}return ue(n)}},{key:"element",value:function(e){if(this.debugLog("Element"),this.la1("if"))return this.if(e);if(this.la1("func"))return this.funcDef(e);if(this.la1("loop"))return this.loop(e);if(this.la1("identifier")){var t=this.match("identifier");if(this.blockDepthCheck(e,t),this.la1("assignment")||this.la1("colon"))return this.assignment(t);if(this.la1("open paren"))return this.application(e,t)}var n=this.peek();this.errors.push(new o.UnexpectedTokenException(n.type,n)),this.skipUntil(["newline"]),this.clearNewlines()}},{key:"if",value:function(e){this.debugLog("If");var t,n=this.position(),r=[],o=this.match("if");this.blockDepthCheck(e,o);try{t=this.expression()}catch(e){this.errors.push(e),this.resetStream("newline"),t=Se()}this.clearNewlines();var i=this.block(e+1);if(r.push([t,i]),this.eof()||!this.la1("else"))return fe(r,n);for(;!this.eof()&&this.la1("else");){var a=this.match("else");this.blockDepthCheck(e,a);var c=void 0;if(this.la1("if")){this.match("if");try{c=this.expression()}catch(e){this.errors.push(e),this.resetStream("newline"),c=Se()}}else c=Te(1);this.clearNewlines();var u=this.block(e+1);r.push([c,u])}return fe(r,n)}},{key:"funcDef",value:function(e){this.debugLog("Function Definition");var t,n,r,o=this.position(),i=this.match("func");this.blockDepthCheck(e,i);try{if(t=this.match("identifier").content,this.match("open paren"),n=this.argList("close paren","comma"),this.match("close paren"),this.la1("lambda arrow"))return this.match("lambda arrow"),r=this.expression(),this.clearNewlines(),ve(t,n,ue([r]),o)}catch(e){this.errors.push(e),this.resetStream("newline")}return this.clearNewlines(),ve(t,n,this.block(e+1),o)}},{key:"argList",value:function(e,t){var n=[];if(this.la1(e))return this.debugLog("argList: 0 args"),n;for(n.push(this.functionArg());this.la1(t);)this.match(t),n.push(this.functionArg());return this.debugLog("argList: ".concat(n.length," args")),n}},{key:"functionArg",value:function(){return this.debugLog("Function Argument"),this.la1("&")?(this.match("&"),be(this.match("identifier").content)):de(this.match("identifier").content)}},{key:"loop",value:function(e){this.debugLog("Loop");var t,n,r=this.position(),o=this.match("loop");this.blockDepthCheck(e,o);try{t=this.expression(),this.match("times"),n=Se(),this.la1("with")&&(this.match("with"),n=this.variable())}catch(e){this.errors.push(e),this.resetStream("newline")}return this.clearNewlines(),se(t,this.block(e+1),n,r)}},{key:"assignment",value:function(e){this.debugLog("Assignment");var t,n=this.tokenPosition(e);if(this.la1("colon")){try{this.match("colon"),this.match("assignment"),t=this.expression()}catch(e){this.errors.push(e),this.resetStream("newline")}return this.clearNewlines(),he(e.content,t,n)}try{this.match("assignment"),t=this.expression()}catch(e){this.errors.push(e),this.resetStream("newline")}return this.clearNewlines(),le(e.content,t,n)}},{key:"application",value:function(e,t){this.debugLog("Application");var n,r=this.tokenPosition(t);try{this.match("open paren"),n=this.exprList(),this.match("close paren")}catch(e){this.errors.push(e),this.resetStream("newline")}if(this.eof()||!this.la1("newline"))return me(t.content,n,Se(),r);if(this.clearNewlines(),this.eof())return me(t.content,n,Se(),r);if(this.calculateBlockLevel(this.peek())<=e)return me(t.content,n,Se(),r);var o=this.applicationLambda(e+1);return me(t.content,n,o,r)}},{key:"applicationLambda",value:function(e){var t=this.position(),n=[];if(this.la1("pipe")){var r=this.match("pipe");this.blockDepthCheck(e,r);try{n=this.argList("pipe","comma"),this.match("pipe"),this.match("newline")}catch(e){this.errors.push(e),this.resetStream("newline")}}var o=this.block(e);return pe(n,Se(),o,t)}},{key:"expressionApplication",value:function(e){var t,n=this.position();try{this.match("open paren"),t=this.exprList(),this.match("close paren")}catch(e){this.errors.push(e),this.resetStream("newline")}return me(e.content,t,Se(),n)}},{key:"exprList",value:function(){var e=[];if(this.la1("close paren"))return this.debugLog("exprList: 0 args"),e;for(e.push(this.expression());this.la1("comma");){this.match("comma");var t=void 0;try{t=this.expression()}catch(e){this.errors.push(e),this.resetStream("comma")}e.push(t)}return this.debugLog("exprList: ".concat(e.length," args")),e}},{key:"expression",value:function(){this.debugLog("Expression");var e=this.baseExpression();return!this.eof()&&this.la1("operator")?this.operator(e):e}},{key:"operator",value:function(e){this.debugLog("Operator");var t=new o.ArithmaticShunter(Ue,{astConstructor:Me});for(t.shuntValue(e);!this.eof()&&this.la1("operator");)t.shuntOp(this.match("operator")),t.shuntValue(this.baseExpression());return t.getOutput()}},{key:"baseExpression",value:function(){var e;if(this.debugLog("Base Expression"),this.la1("number"))e=this.number();else if(this.la1("open paren"))this.match("open paren"),e=this.expression(),this.match("close paren");else if(this.la1("operator")){var t=this.match("operator"),n=this.baseExpression();e=ge(t.content,n)}else if(this.la1("colon"))this.match("colon"),e=Oe(this.match("identifier").content);else if(this.la1("null"))this.match("null"),e=Se();else if(this.la1("open bracket")){this.match("open bracket");var r=this.exprList();this.match("close bracket"),e=Ee(r)}else if(this.la1("identifier")){var o=this.match("identifier");e=!this.eof()&&this.la1("open paren")?this.expressionApplication(o):we(o.content)}for(;!this.eof()&&this.la1("open bracket");){this.match("open bracket");var i=this.expression();this.match("close bracket"),e=xe(e,i)}return e}},{key:"number",value:function(){this.debugLog("Number");var e=this.position();return Te(this.match("number").content,e)}},{key:"variable",value:function(){this.debugLog("Variable");var e=this.position();return we(this.match("identifier").content,e)}}],n&&_e(t.prototype,n),c}(o.Parser);function Ve(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,o,i=[],a=!0,c=!1;try{for(n=n.call(e);!(a=(r=n.next()).done)&&(i.push(r.value),!t||i.length!==t);a=!0);}catch(e){c=!0,o=e}finally{try{a||null==n.return||n.return()}finally{if(c)throw o}}return i}}(e,t)||function(e,t){if(e){if("string"==typeof e)return ze(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?ze(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function ze(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function Ge(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function qe(e){return Object.create(e)}var Ye=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)}var t,n;return t=e,n=[{key:"run",value:function(e,t,n){var r,o={errors:[],exitCode:0};if(!e||e.type!==V)return o.errors.push(new _("Invalid Program")),o.exitCode=1,o;r=n?t:qe(t);try{this.evaluateProgram(e,r)}catch(e){o.errors.push(e),o.exitCode=1}return o}},{key:"evaluateProgram",value:function(e,t){for(var n=0;n<e.statements.length;n+=1){var r=e.statements[n];this.evaluate(r,t)}}},{key:"evaluate",value:function(e,t){var n,r=this;switch(e.type){case z:n=this.evaluateBlock(e,t);break;case G:n=this.evaluateLoop(e,t);break;case q:case Y:n=this.evaluateAssignment(e,t);break;case $:n=this.evaluateIf(e,t);break;case H:n=this.evaluateLambda(e,t);break;case W:n=this.evaluateFunctionDefinition(e,t);break;case X:n=this.evaluateApplication(e,t);break;case Z:n=this.evaluateBinaryOp(e,t);break;case J:n=this.evaluateUnaryOp(e,t);break;case Q:n=this.evaluateVariable(e,t);break;case ee:n=this.evaluateDeIndex(e,t);break;case te:case re:n=e;break;case oe:n=e.values.map((function(e){return r.evaluate(e,t)}));break;default:throw new B("Unknown AST Type: ".concat(e.type),e)}return n}},{key:"evaluateBlock",value:function(e,t){for(var n=qe(t),r=Se(),o=0;o<e.elements.length;o+=1){var i=e.elements[o];r=this.evaluate(i,n)}return r}},{key:"evaluateAssignment",value:function(e,t){var n=this.evaluate(e.expression,t);return e.type===q?t[e.identifier]=n:e.type!==Y||void 0!==t[e.identifier]&&t[e.identifier].type!==ne||(t[e.identifier]=n),n}},{key:"isNull",value:function(e){return null==e||e.type===ne}},{key:"notNull",value:function(e){return null!=e&&e.type!==ne}},{key:"truthyValue",value:function(e){return!this.isNull(e)&&(e.type!==te||0!==e.value)}},{key:"checkNum",value:function(e){if(!e||e.type!==te)throw new B("Expected Number but found: ".concat(e.type),e)}},{key:"evaluateIf",value:function(e,t){for(var n=e.conditionals,r=0;r<n.length;r+=1){var o=Ve(n[r],2),i=o[0],a=o[1];this.truthyValue(this.evaluate(i,t))&&this.evaluateBlock(a,t)}}},{key:"evaluateApplication",value:function(e,t){var n=this,r=e.name,o=e.args,i=e.lambda,a=t[r];if(!a||a.type===H&&a.type===K)throw new B("".concat(r," is not a function"),e);var c=o.map((function(e){return n.evaluate(e,t)}));if(a.type===H){for(var u=this.notNull(a.scope)?a.scope:qe(t),s=0;s<a.args.length;s+=1){var l=a.args[s];switch(l.type){case ie:u[l.name]=c[s]||Se();break;case ae:if(this.isNull(i)){u[l.name]=Se();break}this.isNull(i.scope)&&(i.scope=t),u[l.name]=i;break;default:throw new B("Unknown variable type ".concat(l.type),l)}}return this.evaluateBlock(a.body,u)}if(a.type===K)return a.func(c,i)}},{key:"blockToLambda",value:function(e,t){return pe([],t,e)}},{key:"evaluateLambda",value:function(e){throw new B("Shouldn't be evaluating a lambda",e)}},{key:"evaluateFunctionDefinition",value:function(e,t){var n=e.name,r=pe(e.args,t,e.body);t[n]=r}},{key:"evaluateLoop",value:function(e,t){var n=e.count,r=e.block,o=e.loopVar,i=this.evaluate(n,t);if(i.type!==te)throw new B("Loop count should be a number",n);for(var a=i.value,c=qe(t),u=0;u<a;u+=1)this.notNull(o)&&(c[o.identifier]=Te(u)),this.evaluate(r,c)}},{key:"evaluateUnaryOp",value:function(e,t){var n=this.evaluate(e.expr,t);this.checkNum(n);var r=n.value;if("-"!==e.operator)throw new B("".concat(e.operator," is an unknown operator"),e);return Te(-1*r)}},{key:"evaluateBinaryOp",value:function(e,t){var n,r=this.evaluate(e.left,t);this.checkNum(r);var o=this.evaluate(e.right,t);this.checkNum(o);var i=r.value,a=o.value;switch(e.operator){case"+":n=i+a;break;case"-":n=i-a;break;case"*":n=i*a;break;case"/":n=i/a;break;case"^":n=Math.pow(i,a);break;case"%":n=i%a;break;case">":n=i>a?1:0;break;case"<":n=i<a?1:0;break;case">=":n=i>=a?1:0;break;case"<=":n=i<=a?1:0;break;case"==":n=i===a?1:0;break;case"&&":n=i&&a?1:0;break;case"||":n=i||a?1:0;break;default:throw new B("".concat(e.operator," is an unknown operator"),e)}return Te(n)}},{key:"evaluateVariable",value:function(e,t){var n=t[e.identifier];if(void 0===n)throw new B("Undefined Variable: ".concat(e.identifier),e);return n}},{key:"evaluateDeIndex",value:function(e,t){var n=this.evaluate(e.collection,t);if(!Array.isArray(n))throw new B("Can only deindex a list",e);var r=this.evaluate(e.index,t);return this.checkNum(r),n[r.value]}}],n&&Ge(t.prototype,n),e}(),$e={tokenIdentifiers:x,keywords:m},He={InvalidProgramError:_,InterpreterError:B,IncorrectIndentationException:F},Ke=e,We=t})(),r})()})); | ||
//# sourceMappingURL=improviz-language.min.js.map |
{ | ||
"name": "@improviz/language", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "The language parser and interpreter for Improviz", | ||
@@ -5,0 +5,0 @@ "main": "lib/improviz-language.min.js", |
@@ -7,2 +7,11 @@ import { tokenIdentifiers, keywords } from './parser/lexer'; | ||
import { InvalidProgramError, InterpreterError } from './interpreter/errors'; | ||
import { IncorrectIndentationException } from './parser/errors'; | ||
export const Errors = { | ||
InvalidProgramError, | ||
InterpreterError, | ||
IncorrectIndentationException | ||
}; | ||
import * as ast from './ast'; | ||
@@ -9,0 +18,0 @@ export const Ast = ast; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
349217
4014