mevento 2.1.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,8 @@
1
+ var Y=Object.defineProperty;var it=Object.getOwnPropertyDescriptor;var st=Object.getOwnPropertyNames;var nt=Object.prototype.hasOwnProperty;var ot=(c,t)=>{for(var e in t)Y(c,e,{get:t[e],enumerable:!0})},at=(c,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of st(t))!nt.call(c,s)&&s!==e&&Y(c,s,{get:()=>t[s],enumerable:!(i=it(t,s))||i.enumerable});return c};var ct=c=>at(Y({},"__esModule",{value:!0}),c);var lt={};ot(lt,{AST:()=>d,ArrayExpression:()=>N,AssignmentExpressionAST:()=>E,BinaryExpressionAST:()=>V,BlockStatementAST:()=>I,BreakAST:()=>H,BreakBranch:()=>A,CallExpressionAST:()=>R,ContinueAST:()=>z,ContinueBranch:()=>w,ExpressionStatementAST:()=>X,ForLoopStatement:()=>M,ForOfStatement:()=>W,IdentifierAST:()=>g,IfStatementAST:()=>B,IndexAccessorAST:()=>T,LexerDictionary:()=>L,LiteralAST:()=>m,LogicalExpressionAST:()=>P,LoopControl:()=>C,MEventScope:()=>Q,MEvento:()=>O,MEventoAsync:()=>J,NodeVisitor:()=>G,ObjectExpression:()=>j,ObjectProperty:()=>k,ReturnAST:()=>K,ReturnBranch:()=>f,RootAST:()=>F,Token:()=>h,TokenType:()=>r,TupleExpression:()=>D,UnaryExpressionAST:()=>q,WhileLoopStatement:()=>U});module.exports=ct(lt);function b(c,t){let e=`Invalid token ${c.type}[${c.value}] at ${c.line}, ${c.col} ${t?`: expecting ${t} token`:""}
2
+ `;throw Error(e)}function l(c){return typeof c=="number"}function ut(c){return typeof c=="boolean"}function x(c){return typeof c=="string"}function v(c){return!(c===null||l(c)&&c===0||x(c)&&c.length===0||ut(c)&&!c)}function ht(c){let t=0,e=0,i;if(c.length===0)return t;for(e=0;e<c.length;e++)i=c.charCodeAt(e),t=(t<<5)-t+i,t|=0;return t}var r=class{};r.id=0,r.comma=1,r.semi=2,r.numberConst=3,r.stringConst=4,r.equal=5,r.lparen=6,r.rparen=7,r.eol=8,r.eof=9,r.lbrace=10,r.rbrace=11,r.lbracket=12,r.rbracket=13,r.great=14,r.greatEq=15,r.less=16,r.lessEq=17,r.eqeq=18,r.IF=19,r.ELSE=20,r.TRUE=21,r.FALSE=22,r.NULL=23,r.not=24,r.notEq=25,r.and=26,r.or=27,r.plus=28,r.minus=29,r.div=30,r.mult=31,r.mod=32,r.invalid=33,r.colon=34,r.WHILE_TILL=35,r.FOR_LOOP=36,r.up=37,r.down=38,r.with=39,r.in=40,r.TILL=41,r.BREAK=42,r.CONTINUE=43,r.nullity=44,r.RETURN=45;var h=class c{constructor(t,e,i=1,s=1){this.type=t,this.value=e,this.line=i,this.col=s}static from(t,e){return new c(t,e)}toString(){return`[${this.type.toString()}, ${this.value}]`}},u=class{};u.equal=61,u.comma=44,u.semiColon=59,u.lparen=40,u.rparen=41,u.backslash=92,u.quote=34,u.squote=39,u.plus=43,u.minus=45,u.star=42,u.slash=47,u.percent=37,u.lbrace=123,u.rbrace=125,u.lbracket=91,u.rbracket=93,u.not=33,u.great=62,u.less=60,u.and=38,u.pipe=124,u.colon=58,u.questionMark=63,u.shebang=35;var L=class{constructor(t,e){this.keywords={};this.keywords={...e},this.lang=t}},y=class y{constructor(t){this._position=0;this._line=1;this._col=1;this._currentChar=-1;this._source=t,this._currentChar=this._source[this._position].charCodeAt(0),this._resolveLanguage()}get source(){return this._source}_resolveLanguage(){var e;let t=this.nextToken();if(t.type===r.less){let i=this.nextToken();i.type!==r.id&&b(t);let s=i.value.toString();this._language=(e=y.languages.find(n=>n.lang===s))!=null?e:y._defaultLanguage,t=this.nextToken(),t.type!==r.great&&b(t)}else this._language=y._defaultLanguage,this._position=0,this._currentChar=this._source[this._position].charCodeAt(0)}_advance(){if(this._position++,this._position>=this._source.length){this._currentChar=-1;return}this._currentChar=this._source[this._position].charCodeAt(0),this._col++}_jump(t){if(this._position+=t,this._position>=this._source.length){this._currentChar=-1;return}this._currentChar=this._source[this._position].charCodeAt(0),this._col+=t}_pick(){return this._position+1>=this._source.length?-1:this._source[this._position+1].charCodeAt(0)}_isId(t){return t<48?t===36:t<58?!0:t<65?!1:t<91?!0:t<97?t===95:t<123}_isIdStart(t){return t<65?t===36:t<91?!0:t<97?t===95:t<123}_id(){var o,a;let t="",e=this._col,i=this._position,s=this._line;for(;this._isId(this._currentChar);)t+=String.fromCharCode(this._currentChar),this._advance();let n=this._language&&(o=this._language.keywords[t])!=null?o:t;return(a=y.RESERVED[n])!=null?a:new h(r.id,t,s,e)}_isLineEnd(t){return t===10||t===13||[`
3
+ `,"\r","\u2028","\u2029"].includes(String.fromCharCode(t))}_isWhiteSpace(t){return[" "," "].includes(String.fromCharCode(t))}_isDigit(t){return t>0&&(t^48)<=9}_skipWhiteSpace(){for(;this._isWhiteSpace(this._currentChar)===!0;)this._advance()}_number(){let t="",e=this._col,i=this._position,s=this._line,n=String.fromCharCode(this._currentChar);this._advance();let o=String.fromCharCode(this._currentChar),a=10;if(n==="0"&&["b","B","x","X","o","O"].includes(o))switch(this._advance(),o.toLowerCase()){case"b":a=2;break;case"o":a=8;break;case"x":a=16;break;default:a=10}else t+=n,a=10;for(;this._isDigit(this._currentChar)||a===16&&["A","a","B","b","C","c","D","d","E","e","F","f"].includes(String.fromCharCode(this._currentChar));)t+=String.fromCharCode(this._currentChar),this._advance();if(String.fromCharCode(this._currentChar)==="."&&this._isDigit(this._pick())===!0){for(a!==10&&b(new h(r.id,o,s,i)),t+=String.fromCharCode(this._currentChar),this._advance();this._isDigit(this._currentChar);)t+=String.fromCharCode(this._currentChar),this._advance();return new h(r.numberConst,parseFloat(t),s,e)}return new h(r.numberConst,parseInt(t,a),s,e)}_literalString(t){let e="",i=-1,s=this._position,n=this._col,o=this._line;for(;this._currentChar!==-1;){let a=String.fromCharCode(this._pick());if(this._currentChar==u.backslash){switch(a){case"\\":e+="\\";break;case"0":e+="\0";break;case"a":e+="a";break;case"b":e+="\b";break;case"f":e+="\f";break;case"n":e+=`
4
+ `;break;case"r":e+="\r";break;case"t":e+=" ";break;case"u":e+=String.fromCharCode(Number.parseInt(this._source.substring(this._position+2,this._position+6),16)),this._jump(4);break;case"v":e+="\v";break;case"x":e+=String.fromCharCode(Number.parseInt(this._source.substring(this._position+2,this._position+4),16)),this._jump(2);break;default:if(String.fromCharCode(t)==a)e+=String.fromCharCode(t);else{this._advance(),i=this._currentChar,e+=String.fromCharCode(this._currentChar),this._advance();continue}}this._jump(2),i=this._currentChar;continue}if(this._currentChar===t&&i!==u.backslash)break;e+=String.fromCharCode(this._currentChar),i=this._currentChar,this._advance()}return new h(r.stringConst,e,o,n)}_skipLineComment(){for(;!this._isLineEnd(this._currentChar)&&this._currentChar!=-1;)this._advance()}_skipComment(){for(;this._currentChar!==-1;){if(this._currentChar===u.star&&this._pick()===u.shebang){this._advance(),this._advance();break}this._advance()}}nextToken(){let t=this._line,e=this._col,i=this._position;for(;this._currentChar!==-1;){if(this._isLineEnd(this._currentChar))return this._line++,this._col=1,this._advance(),new h(r.eol,`
5
+ `,t,e);if(this._isWhiteSpace(this._currentChar)){this._skipWhiteSpace();continue}if(this._currentChar==u.shebang){this._advance(),this._currentChar===u.star?(this._advance(),this._skipComment()):this._skipLineComment();continue}if(this._isDigit(this._currentChar))return this._number();if(this._isIdStart(this._currentChar))return this._id();if(this._currentChar===u.equal)return this._advance(),this._currentChar===u.equal?(this._advance(),new h(r.eqeq,"==",t,e)):new h(r.equal,"=",t,e);if(this._currentChar===u.great)return this._advance(),this._currentChar===u.equal?(this._advance(),new h(r.greatEq,">=",t,e)):new h(r.great,">",t,e);if(this._currentChar===u.less)return this._advance(),this._currentChar===u.equal?(this._advance(),new h(r.lessEq,"<=",t,e)):new h(r.less,"<",t,e);if(this._currentChar===u.semiColon)return this._advance(),new h(r.semi,";",t,e);if(this._currentChar===u.lparen)return this._advance(),new h(r.lparen,"(",t,e);if(this._currentChar===u.rparen)return this._advance(),new h(r.rparen,")",t,e);if(this._currentChar===u.comma)return this._advance(),new h(r.comma,",",t,e);if(this._currentChar===u.lbrace)return this._advance(),new h(r.lbrace,"{",t,e);if(this._currentChar===u.rbrace)return this._advance(),new h(r.rbrace,"}",t,e);if(this._currentChar===u.lbracket)return this._advance(),new h(r.lbracket,"[",t,e);if(this._currentChar===u.rbracket)return this._advance(),new h(r.rbracket,"]",t,e);if(this._currentChar===u.plus)return this._advance(),new h(r.plus,"+",t,e);if(this._currentChar===u.minus)return this._advance(),new h(r.minus,"-",t,e);if(this._currentChar===u.slash)return this._advance(),new h(r.div,"/",t,e);if(this._currentChar===u.star)return this._advance(),new h(r.mult,"*",t,e);if(this._currentChar===u.percent)return this._advance(),new h(r.mod,"%",t,e);if(this._currentChar===u.colon)return this._advance(),new h(r.colon,":",t,e);if(this._currentChar===u.not)return this._advance(),this._currentChar===u.equal?(this._advance(),new h(r.notEq,"!=",t,e)):new h(r.not,"!",t,e);if(this._currentChar===u.and&&this._pick()===u.and)return this._advance(),this._advance(),new h(r.and,"&&",t,e);if(this._currentChar===u.pipe&&this._pick()===u.pipe)return this._advance(),this._advance(),new h(r.or,"||",t,e);if(this._currentChar===u.questionMark&&this._pick()===u.questionMark)return this._advance(),this._advance(),new h(r.nullity,"??",t,e);if(this._currentChar===u.quote||this._currentChar===u.squote){let s=this._currentChar;this._advance();let n=this._literalString(s);return this._advance(),n}return new h(r.invalid,String.fromCharCode(this._currentChar),t,e)}return new h(r.eof,"",t,e)}};y._defaultLanguage=new L("en",{if:"if",else:"else",true:"true",false:"false",null:"null",while:"while",for:"for",with:"with",up:"up",down:"down",till:"till",in:"in",break:"break",continue:"continue",return:"return"}),y.languages=[y._defaultLanguage,new L("fr",{si:"if",sinon:"else",vrai:"true",faux:"false",nul:"null",tanque:"while",pour:"for",avec:"with",mont:"up",desc:"down",jusqua:"till",dans:"in",couper:"break",continuer:"continue",returner:"return"}),new L("bm",{nii:"if",note:"else",tien:"true",galon:"false",gansan:"null",foo:"while",seginka:"for",niin:"with",kay:"up",kaj:"down",kata:"till",kono:"in",tike:"break",ipan:"continue",segin:"return"})],y.RESERVED={if:h.from(r.IF,"if"),else:h.from(r.ELSE,"else"),true:h.from(r.TRUE,!0),false:h.from(r.FALSE,!1),null:h.from(r.NULL,null),for:h.from(r.FOR_LOOP,"for"),while:h.from(r.WHILE_TILL,"while"),with:h.from(r.with,"with"),up:h.from(r.up,"up"),down:h.from(r.down,"down"),till:h.from(r.TILL,"till"),in:h.from(r.in,"in"),break:h.from(r.BREAK,"break"),continue:h.from(r.CONTINUE,"continue"),return:h.from(r.RETURN,"return")};var Z=y,d=class{constructor(t,e){this.line=t,this.col=e}dump(){return this.toString()}},F=class extends d{constructor(t,e,i){super(1,1),this.body=t,this.name=e,this.source=i}dump(){let t=`Module ${this.name} Start {`;for(let e of this.body)t+=`${e.dump()}
6
+ `;return t+="}",t}},I=class extends d{constructor(t,e){super(e.line,e.col),this.body=t}toString(){return`{
7
+ ${this.body.map(t=>t.toString()).join(`
8
+ `)}}`}},g=class extends d{constructor(t){super(t.line,t.col),this.value=t.value.toString()}toString(){return this.value}},m=class extends d{constructor(t,e){super(t.line,t.col),this.value=t.value,this.raw=e}toString(){return this.value.toString()}},E=class extends d{constructor(t,e){super(t.line,t.col),this.identifier=t,this.init=e}toString(){return`${this.identifier} = ${this.init}`}},X=class extends d{constructor(t){super(t.line,t.col),this.expression=t}toString(){return this.expression.toString()}},R=class extends d{constructor(t,e){super(t.line,t.col),this.callee=t,this.arguments=e}toString(){return`${this.callee.toString()}(...${this.arguments.length})`}},V=class extends d{constructor(t,e,i){super(t.line,t.col),this.left=t,this.operation=e,this.right=i}toString(){return`${this.left} ${this.operation} ${this.right}`}},q=class extends d{constructor(t,e){super(t.line,t.col),this.operation=t,this.argument=e}toString(){return`${this.operation} ${this.argument}`}},B=class extends d{constructor(t,e,i){super(t.line,t.col),this.test=t,this.consequent=e,this.alternate=i}toString(){return`if ${this.test} ${this.consequent} ${this.alternate?`else ${this.alternate} `:""}`}},P=class extends d{constructor(t,e,i){super(t.line,t.col),this.left=t,this.operator=e,this.right=i}toString(){return`${this.left} ${this.operator.value} ${this.right}`}},T=class extends d{constructor(e,i,s=!1){super(e.line,e.col);this.computed=!1;this.owner=e,this.key=i,this.computed=s}toString(){return`${this.owner}[${this.key}]`}},j=class extends d{constructor(t,e,i){super(e==null?void 0:e.line,e==null?void 0:e.col),this.properties=t}toString(){return"{...}"}},N=class extends d{constructor(t,e,i){super(e==null?void 0:e.line,e==null?void 0:e.col),this.elements=t}toString(){return"[...]"}},k=class extends d{constructor(t,e){super(t.line,t.col),this.value=e,this.key=t}},U=class extends d{constructor(e,i,s,n,o=!1){super(s==null?void 0:s.line,s==null?void 0:s.col);this.retain=!1;this.test=e,this.body=i,this.retain=o}},M=class extends d{constructor(e,i,s,n,o,a,p,S=!1){super(a==null?void 0:a.line,a==null?void 0:a.col);this.init=e;this.test=i;this.update=s;this.direction=n;this.body=o;this.retain=S}},W=class extends d{constructor(e,i,s,n,o,a=!1){super(n==null?void 0:n.line,n==null?void 0:n.col);this.identifier=e;this.collection=i;this.body=s;this.retain=a}},D=class extends d{constructor(e,i){super(e.line,e.col);this.first=e;this.second=i}},H=class extends d{constructor(t,e){super(t,e)}},K=class extends d{constructor(t,e,i){super(e,i),this.value=t}},z=class extends d{constructor(t,e){super(t,e)}},tt=class{constructor(t=1/0){this.capacity=t;this.storage=[]}push(t){if(this.size()===this.capacity)throw Error("Stack has reached max capacity, you cannot add more items");this.storage.push(t)}pop(){return this.storage.pop()}peek(){return this.storage[this.size()-1]}size(){return this.storage.length}get isEmpty(){return this.storage.length===0}},$=class ${constructor(t){this._loopTrack=new tt;this.currentToken=t.nextToken(),this.lexer=t}_eat(t){var e;((e=this.currentToken)==null?void 0:e.type)===t?this.currentToken=this.lexer.nextToken():b(this.currentToken,t)}_eatEOL(){var t;for(;((t=this.currentToken)==null?void 0:t.type)===r.eol;)this._eat(r.eol)}_eatSemiOrEOL(){var t,e;for(;((t=this.currentToken)==null?void 0:t.type)===r.eol||((e=this.currentToken)==null?void 0:e.type)===r.semi;)this._eat(this.currentToken.type)}_eatSemi(){var t;for(;((t=this.currentToken)==null?void 0:t.type)===r.semi;)this._eat(r.semi)}_variable(){let t=new g(this.currentToken);return this._eat(r.id),t}_return(){let t=this.currentToken,e;return!this._expect(r.eol)&&!this._expect(r.semi)&&(e=this._expression()),new K(e,t==null?void 0:t.line,t==null?void 0:t.col)}_factor(){let t=this.currentToken;switch(t.type){case r.plus:case r.minus:case r.not:return this._eat(this.currentToken.type),new q(t,this._term());case r.numberConst:return this._eat(r.numberConst),new m(t,t.value.toString());case r.stringConst:return this._eat(r.stringConst),new m(t,t.value.toString());case r.lparen:this._eat(r.lparen);let e=this._expression();return this._eat(r.rparen),e;case r.TRUE:case r.FALSE:return this._eat(this.currentToken.type),new m(t,t.value.toString());case r.NULL:return this._eat(r.NULL),new m(t,"null");case r.lbracket:return this._arrayExpression();case r.lbrace:return this._objectExpression();case r.IF:return this._ifStatement();case r.WHILE_TILL:return this._whileLoop(!0);case r.FOR_LOOP:return this._forLoop(!0);case r.BREAK:return this._breakExpression();case r.CONTINUE:return this._continueExpression();default:return this._variable()}}_breakExpression(){var t,e;return this._loopTrack.isEmpty&&b(this.currentToken),this._eat(r.BREAK),new H((t=this.currentToken)==null?void 0:t.line,(e=this.currentToken)==null?void 0:e.col)}_continueExpression(){var t,e;return this._loopTrack.isEmpty&&b(this.currentToken),this._eat(r.CONTINUE),new z((t=this.currentToken)==null?void 0:t.line,(e=this.currentToken)==null?void 0:e.col)}_term(){let t=this._factor();return t=this._tryParsingFunctionCall(t),t=this._tryParsingMemberExpression(t),t}_expression(){let t=this._term();for(t=this._tryBinaryExpression(0,t);[r.and,r.or,r.nullity].includes(this.currentToken.type);){let e=this.currentToken;this._eat(e.type),t=new P(t,e,this._expression())}if(this._expect(r.equal))if(t instanceof g||t instanceof T){let e=this.currentToken;this._eat(r.equal),t=new E(t,this._expression())}else throw new Error("Unexpected token");return t}_objectProperty(){var s;let t;switch((s=this.currentToken)==null?void 0:s.type){case r.stringConst:{t=new m(this.currentToken,this.currentToken.value),this._eat(r.stringConst);break}case r.lbracket:{this._eat(r.lbracket);var e=this._expression();this._eat(r.rbracket),t=e;break}case r.id:{let n=this._variable();t=new m(new h(r.id,n.value,n.line,n.col),n.value);break}default:throw`Unexpected token ${this.currentToken}`}this._eat(r.colon);var i=this._expression();return new k(t,i)}_property(){return this._objectProperty()}_objectProperties(){var e,i;let t=[];for(((e=this.currentToken)==null?void 0:e.type)!=r.rbrace&&(this._eatEOL(),t.push(this._property()),this._eatEOL());((i=this.currentToken)==null?void 0:i.type)===r.comma&&(this._eat(r.comma),this._eatEOL(),!this._expect(r.rbrace));)t.push(this._property()),this._eatEOL();return t}_objectExpression(t){var e=t!=null?t:this.currentToken;t||this._eat(r.lbrace);var i=this._objectProperties();return this._eat(r.rbrace),new j(i,e,this.currentToken)}_arrayExpression(){this._eat(r.lbracket);let t=this._expect(r.rbracket)?[]:this._expressionsList();this._eat(r.rbracket);var e=t.length!==0?t[0]:void 0,i=t.length!==0?t[t.length-1]:void 0;return new N(t,e,i)}_tryParsingMemberExpression(t){let e=t;for(;this.currentToken.type===r.lbracket;){this._eat(r.lbracket);let i=this._expression();e=new T(e,i),this._eat(r.rbracket)}return e}_tryBinaryExpression(t,e){let i=e;for(;;){let s=$._binopPrecdences[this.currentToken.type]||-1;if(s<t)return i;let n=this.currentToken;this._eat(n.type);let o=this._term(),a=$._binopPrecdences[this.currentToken.type]||-1;if(s<a){let p=this._tryBinaryExpression(s+1,o);if(p===i)return p;o=p}i=new V(i,n,o)}}_expressionsList(){var i;this._eatEOL();let t=this._expression();this._eatEOL();let e=[t];for(;((i=this.currentToken)==null?void 0:i.type)===r.comma&&(this._eat(r.comma),this._eatEOL(),!this._expect(r.rbracket));)t=this._expression(),e.push(t),this._eatEOL();return e}_callExpression(t){this._eat(r.lparen);let e=[];return this._expect(r.rparen)||(e=this._expressionsList()),this._eat(r.rparen),t instanceof g||b(this.currentToken),new R(t,e)}_tryParsingFunctionCall(t){let e=t;for(;this.currentToken.type===r.lparen;)e=this._callExpression(e);return e}_statementExpression(){let t=this._expression();return[r.semi,r.eol,r.eof].includes(this.currentToken.type)||b(this.currentToken),t}_blockStatement(t=!1){var i;if(t||this._eat(r.lbrace),this._eatEOL(),this._expect(r.rbrace))return this._eat(r.rbrace),new I([],this.currentToken);let e=[this._statement()];for(;this._eatSemiOrEOL(),!(this.currentToken.type===r.rbrace||this.currentToken.type===r.eof||(e.push(this._statement()),this._expect(r.rbrace)));)this.currentToken.type!==r.eol&&this.currentToken.type!==r.semi&&this.currentToken.type!==r.eof&&b(this.currentToken);return this._eat(r.rbrace),((i=this.currentToken)==null?void 0:i.type)===r.rbrace&&this._eat(r.rbrace),new I(e,this.currentToken)}_ifStatement(){this._eat(r.IF);let t=this.currentToken.type===r.lparen;t&&this._eat(r.lparen);let e=this._expression();t&&this._eat(r.rparen);let i;this.currentToken.type===r.lbrace?i=this._blockStatement():i=this._expression();let s;if(this.currentToken.type===r.ELSE)switch(this._eat(r.ELSE),this.currentToken.type){case r.IF:s=this._ifStatement();break;case r.lbrace:s=this._blockStatement();break;default:s=this._expression()}return new B(e,i,s)}_pushLoop(){this._loopTrack.push(!0)}_popLoop(){this._loopTrack.pop()}_whileLoop(t=!1){let e=this.currentToken;this._eat(r.WHILE_TILL),this._pushLoop();let i=this._expression(),s=this.currentToken.type===r.lbrace?this._blockStatement():this._expression();return this._popLoop(),new U(i,s,e,this.currentToken,t)}_forOfIdentifier(){switch(this.currentToken.type){case r.lparen:{this._eat(r.lparen);let t=this._variable();this._eat(r.comma);let e=this._variable();return this._eat(r.rparen),new D(t,e)}default:return this._variable()}}_forLoop(t=!1){let e=this.currentToken;this._eat(r.FOR_LOOP),this._pushLoop();let i=[r.lparen].includes(this.currentToken.type),s;if(i)s=this._forOfIdentifier();else{let n=this._expression();n instanceof E||(i=!0),s=n}if(!i&&s instanceof E){this._eat(r.TILL);let n=this._expression(),o;if(this.currentToken.type===r.up||this.currentToken.type===r.down){let S=this.currentToken;this._eat(S.type),o=S}else o=new h(r.up,"up");let a;this._expect(r.with)?(this._eat(r.with),a=this._expression()):a=new m(new h(r.numberConst,1,this.currentToken.line,this.currentToken.col),"1");let p=this.currentToken.type===r.lbrace?this._blockStatement():this._expression();s=new M(s,n,a,o,p,e,this.currentToken,t),this._popLoop()}else if(i){this._eat(r.in);let n=this._expression(),o=this.currentToken.type===r.lbrace?this._blockStatement():this._expression();s=new W(s,n,o,e,this.currentToken,t),this._popLoop()}else b(this.currentToken);return s}_statement(){switch(this.currentToken.type){case r.BREAK:return this._breakExpression();case r.CONTINUE:return this._continueExpression();case r.RETURN:return this._eat(r.RETURN),this._return();case r.semi:return this._eatSemi(),this._statement();case r.eol:return this._eatEOL(),this._statement();case r.WHILE_TILL:return this._whileLoop();case r.FOR_LOOP:return this._forLoop();default:return this._statementExpression()}}_expect(t){var e;return((e=this.currentToken)==null?void 0:e.type)===t}_definition(){if(this._eatSemiOrEOL(),this._expect(r.eof))return[];let t=[this._statement()];for(;;){if(this._eatSemiOrEOL(),this.currentToken.type===r.eof){this._eat(r.eof);break}this.currentToken.type===r.lbrace?t.push(this._blockStatement()):t.push(this._statement())}return t}_root(){let t=this.lexer.source,e="<module>",i=this._definition();return new F(i,e,t)}parse(){return this._root()}};$._binopPrecdences={[r.eqeq]:10,[r.notEq]:10,[r.great]:10,[r.greatEq]:10,[r.less]:10,[r.lessEq]:10,[r.plus]:20,[r.minus]:20,[r.mult]:40,[r.div]:40,[r.mod]:40};var et=$,C=class{},A=class extends C{},w=class extends C{},f=class{constructor(t){this.value=t}},rt=class{constructor(){this._nodesVisitors={}}registerVisitor(t,e){let i=`visit${t.name}`;this._nodesVisitors[i]=e}},G=class extends rt{constructor(){super(),this.registerVisitor(F,this.visitRootAST),this.registerVisitor(I,this.visitBlockStatementAST),this.registerVisitor(g,this.visitIdentifierAST),this.registerVisitor(m,this.visitLiteralAST),this.registerVisitor(E,this.visitAssignmentExpressionAST),this.registerVisitor(X,this.visitExpressionStatementAST),this.registerVisitor(R,this.visitCallExpressionAST),this.registerVisitor(V,this.visitBinaryExpressionAST),this.registerVisitor(q,this.visitUnaryExpressionAST),this.registerVisitor(B,this.visitIfStatementAST),this.registerVisitor(P,this.visitLogicalExpressionAST),this.registerVisitor(T,this.visitIndexAccessorAST),this.registerVisitor(k,this.visitObjectProperty),this.registerVisitor(j,this.visitObjectExpression),this.registerVisitor(N,this.visitArrayExpression),this.registerVisitor(U,this.visitWhileLoopStatement),this.registerVisitor(M,this.visitForLoopStatement),this.registerVisitor(W,this.visitForOfStatement),this.registerVisitor(H,this.visitBreakAST),this.registerVisitor(z,this.visitContinueAST),this.registerVisitor(K,this.visitReturnAST)}visit(t){var e;try{let i=`visit${t.constructor.name}`,s=this._nodesVisitors[i];return(e=s==null?void 0:s.call(this,t))!=null?e:null}catch{return null}}assignProperty(t,e,i){(Array.isArray(t)||typeof t=="object")&&(t[e]=i)}},Q=class{constructor(t,e,i){this.memory={};this.name=t,this.memory=e,this.parent=i}resolve(t){var e,i;return Object.keys(this.memory).includes(t)?this.memory[t]:(i=(e=this.parent)==null?void 0:e.resolve(t))!=null?i:null}change(t,e,i=!0){return Object.keys(this.memory).includes(t)?(this.memory[t]=e,!0):this.parent&&this.parent.change(t,e,!1)?!0:i?(this.memory[t]=e,!0):!1}},_=class _ extends G{constructor(){super();this.rootScope=new Q("Program",{});this.currentScope=this.rootScope;this.debug=!1;this._functionsRegistry={};this._functionsRegistry={..._._globalFunctionsRegistry}}resolve(e){var i,s;return(s=(i=this.currentScope)==null?void 0:i.resolve(e))!=null?s:null}changeVariable(e,i){var s;return(s=this.currentScope)!=null&&s.change(e,i)?i:null}pushScope(e){let i=new Q(e,{},this.currentScope);this.currentScope=i}popScope(){var e;this.currentScope=(e=this.currentScope)==null?void 0:e.parent}log(e){this.debug&&console.log(e)}visitRootAST(e){var n;let i=e.body,s;for(let o of i)if(s=this.visit(o),s instanceof f)return(n=s.value)!=null?n:null;return s!=null?s:null}visitBlockStatementAST(e){let i=e.body,s;this.pushScope("Block");for(let n of i)if(s=this.visit(n),s instanceof C||s instanceof f)break;return this.popScope(),s!=null?s:null}visitIdentifierAST(e){var s;let i=e.value;return(s=this==null?void 0:this.resolve(i))!=null?s:null}visitLiteralAST(e){return e.value}visitAssignmentExpressionAST(e){let i=e.identifier,s=e.init,n=null;if(i instanceof T){var o=this.visit(i.owner);n=this.visit(e.init);var a=this.visit(i.key);this.assignProperty(o,a,n)}else i instanceof g&&(n=this.visit(s),this.changeVariable(i.value,n));return n}visitExpressionStatementAST(e){let i=e.expression;return this.visit(i)}visitCallExpressionAST(e){let i=e.callee,s=e.arguments,n=i.value,o=this.resolveFunction(n),a=s.map(p=>this.visit(p));return o==null?void 0:o(a,this)}visitBinaryExpressionAST(e){let i=e.left,s=e.right,n=e.operation,o=this.visit(i),a=this.visit(s);switch(n.type){case r.plus:return l(o)&&l(a)?o+a:`${o}${a}`;case r.minus:if(l(o)&&l(a))return o-a;throw new Error(`Operation ${n.value} not allowed no num value`);case r.mult:if(l(o)&&l(a))return o*a;if(x(o)&&l(a))return o.repeat(a);if(l(o)&&x(a))return a.repeat(o);throw new Error(`Operation ${n.value} not allowed no num value`);case r.div:if(l(o)&&l(a)){if(a===0)throw new Error("Invalid division by 0");return o/a}throw new Error(`Operation ${n.value} not allowed no num value`);case r.mod:if(l(o)&&l(a))return o%a;throw new Error(`Operation ${n.value} not allowed no num value`);case r.great:if(l(o)&&l(a))return o>a;throw new Error(`Operation ${n.value} not allowed no num value`);case r.greatEq:if(l(o)&&l(a))return o>=a;throw new Error(`Operation ${n.value} not allowed no num value`);case r.less:if(l(o)&&l(a))return o<a;throw new Error(`Operation ${n.value} not allowed no num value`);case r.lessEq:if(l(o)&&l(a))return o<=a;throw new Error(`Operation ${n.value} not allowed no num value`);case r.eqeq:return o===a;case r.notEq:return o!==a;default:throw new Error(`Operation ${n.value} not allowed no num value`)}}visitUnaryExpressionAST(e){let i=e.argument,s=e.operation,n=this.visit(i);if(s.type===r.not)return v(n)===!1;if(!l(n))throw new Error(`Operation ${s.value} not allowed no num value`);if(s.type===r.plus)return n;if(s.type===r.minus)return-n;throw new Error(`Operation ${s.value} not allowed no num value`)}visitIfStatementAST(e){let i=e.test,s=this.visit(i);return v(s)?this.visit(e.consequent):e.alternate?this.visit(e.alternate):null}visitLogicalExpressionAST(e){let i=e.left,s=this.visit(i);if(e.operator.type===r.nullity)return s!=null?s:this.visit(e.right);let n=v(s);return e.operator.type===r.and?n?v(this.visit(e.right)):!1:e.operator.type===r.or?n?!0:v(this.visit(e.right)):null}visitIndexAccessorAST(e){var n,o;let i=e.owner,s=this.visit(i);if(s==null)return null;if(typeof s=="object"){let a=this.visit(e.key);return(n=s[a])!=null?n:null}else if(Array.isArray(s)){let a=this.visit(e.key);return l(a)&&s.length<a&&a>=0&&(o=s[a])!=null?o:null}return null}visitObjectProperty(e){}visitObjectExpression(e){let i={},s=e;for(let n of s.properties)if(n instanceof k){let o=this.visit(n.key);o=x(o)?o:o.toString(),i[o]=this.visit(n.value)}return i}visitArrayExpression(e){let i=e;return this.resolveArguments(i.elements)}visitBreakAST(e){return new A}visitWhileLoopStatement(e){this.log(`WhileLoopStatement ${e.test} ${e.body}`);let i=e.retain?[]:void 0;for(;v(this.visit(e.test));){let s=this.visit(e.body);if(s instanceof A)break;if(!(s instanceof w)){if(s instanceof f)return this.popScope(),s;i==null||i.push(s)}}return i!=null?i:null}visitForLoopStatement(e){let i=e.retain?[]:void 0,s=e.init.identifier;if(!(s instanceof g))throw new Error("Unexpected identifer found");this.pushScope("ForLoopStatement");let n=this.visit(e.init.init);this.changeVariable(s.value,n);let o=()=>{let p=this.visit(e.test);if(l(p)){let S=this.resolve(s.value);return e.direction.type===r.up?p>=S:p<=S}return v(p)},a=()=>{let p=this.visit(e.update);if(l(p)){let S=this.resolve(s.value);if(!l(S))throw Error("Cant update value");this.changeVariable(s.value,e.direction.type===r.up?S+p:S-p)}else throw Error("Update value cant be non number")};for(;o();){let p=this.visit(e.body);if(p instanceof A)break;if(p instanceof w){a();continue}if(p instanceof f)return this.popScope(),p;i==null||i.push(p),a()}return this.popScope(),i!=null?i:null}visitForOfStatement(e){let i=this.visit(e.collection);if(!Array.isArray(i))throw Error("Can iterate non array object");let s=e.retain?[]:void 0;this.pushScope("ForOfStatement");for(let n of i){this._declareForIdentifier(e.identifier,n);let o=this.visit(e.body);if(o instanceof A)break;if(!(o instanceof w)){if(o instanceof f)return this.popScope(),o;s==null||s.push(o)}}return this.popScope(),s!=null?s:null}visitContinueAST(e){return new w}visitReturnAST(e){return new f(e.value!=null?this.visit(e.value):null)}_declareForIdentifier(e,i){if(e instanceof D){if(!Array.isArray(i))throw Error("Unable to make a tuple from non Array element");this.changeVariable(e.first.value,i[0]),this.changeVariable(e.second.value,i[1])}this.changeVariable(e.value,i)}resolveArguments(e){return e.map(i=>this.visit(i))}setFunctionResolver(e){this._functionResolver=e}resolveFunction(e){var i,s;return(s=this._functionsRegistry[e])!=null?s:(i=this._functionResolver)==null?void 0:i.call(this,e)}registerFunction(e,i){this._functionsRegistry[e]=i}unregisterFunction(e){delete this._functionsRegistry[e]}execute(e,i=!0,s){let n=_.compile(e,i);return s&&Object.keys(s).forEach(o=>this.changeVariable(o,s[o])),this.visit(n)}static compile(e,i=!1){let s=ht(e);if(i&&this._cache.has(s))return this._cache.get(s);let n=new Z(e),a=new et(n).parse();return i&&this._cache.set(s,a),a}static register(e,i){_._globalFunctionsRegistry[e]=i}static unregister(e){delete _._globalFunctionsRegistry[e]}static run(e,i=!1,s){let n=new _,o=_.compile(e,i);return s&&Object.keys(s).forEach(a=>n.changeVariable(a,s[a])),n.visit(o)}static newInstance(){return new _}clone(){var e=new _;return e._functionsRegistry={...this._functionsRegistry},e.rootScope.memory={...this.rootScope.memory},e}newAsyncInstance(){let e=J.newInstance();return e.rootScope.memory=this.rootScope.memory,e._functionsRegistry=this._functionsRegistry,e}};_._globalFunctionsRegistry={},_._cache=new Map;var O=_,J=class c extends O{constructor(){super()}async visitRootAST(t){var s;let e=t.body,i;for(let n of e)if(i=await this.visit(n),i instanceof f)return(s=i.value)!=null?s:null;return i!=null?i:null}async visitBlockStatementAST(t){let e=t.body,i;this.pushScope("Block");for(let s of e)if(i=await this.visit(s),i instanceof C||i instanceof f)break;return this.popScope(),i}async visitIdentifierAST(t){let e=t.value;return this.resolve(e)}async visitLiteralAST(t){return t.value}async visitAssignmentExpressionAST(t){let e=t.identifier,i=t.init,s=null;if(e instanceof T){var n=await this.visit(e.owner);s=await this.visit(t.init);var o=await this.visit(e.key);this.assignProperty(n,o,s)}else e instanceof g&&(s=await this.visit(i),this.changeVariable(e.value,s));return s}async visitExpressionStatementAST(t){let e=t.expression;return await this.visit(e)}async visitCallExpressionAST(t){let e=t.callee,i=t.arguments,s=e.value,n=this._functionsRegistry[s],o=await Promise.all(i.map(a=>this.visit(a)));return await(n==null?void 0:n(o,this))}async visitBinaryExpressionAST(t){let e=t.left,i=t.right,s=t.operation,n=await this.visit(e),o=await this.visit(i);switch(s.type){case r.plus:return l(n)&&l(o)?n+o:`${n}${o}`;case r.minus:if(l(n)&&l(o))return n-o;if(x(n)&&l(o))return n.repeat(o);if(l(n)&&x(o))return o.repeat(n);throw new Error(`Operation ${s.value} not allowed no num value`);case r.mult:if(l(n)&&l(o))return n*o;throw new Error(`Operation ${s.value} not allowed no num value`);case r.div:if(l(n)&&l(o)){if(o===0)throw new Error("Invalid division by 0");return n/o}throw new Error(`Operation ${s.value} not allowed no num value`);case r.mod:if(l(n)&&l(o))return n%o;throw new Error(`Operation ${s.value} not allowed no num value`);case r.great:if(l(n)&&l(o))return n>o;throw new Error(`Operation ${s.value} not allowed no num value`);case r.greatEq:if(l(n)&&l(o))return n>=o;throw new Error(`Operation ${s.value} not allowed no num value`);case r.less:if(l(n)&&l(o))return n<o;throw new Error(`Operation ${s.value} not allowed no num value`);case r.lessEq:if(l(n)&&l(o))return n<=o;throw new Error(`Operation ${s.value} not allowed no num value`);case r.eqeq:return n===o;case r.notEq:return n!==o;default:throw new Error(`Operation ${s.value} not allowed no num value`)}}async visitUnaryExpressionAST(t){let e=t.argument,i=t.operation,s=await this.visit(e);if(i.type===r.not)return v(s)===!1;if(!l(s))throw new Error(`Operation ${i.value} not allowed no num value`);if(i.type===r.plus)return s;if(i.type===r.minus)return-s;throw new Error(`Operation ${i.value} not allowed no num value`)}async visitIfStatementAST(t){let e=t.test,i=await this.visit(e);return v(i)?await this.visit(t.consequent):t.alternate?await this.visit(t.alternate):null}async visitLogicalExpressionAST(t){let e=t.left,i=await this.visit(e);if(t.operator.type===r.nullity)return i!=null?i:await this.visit(t.right);let s=v(i);return t.operator.type===r.and?s?v(await this.visit(t.right)):!1:t.operator.type===r.or?s?!0:v(await this.visit(t.right)):!1}async visitIndexAccessorAST(t){var s,n;let e=t.owner,i=await this.visit(e);if(i==null)return null;if(typeof i=="object"){let o=await this.visit(t.key);return(s=i[o])!=null?s:null}else if(Array.isArray(i)){let o=await this.visit(t.key);return l(o)&&i.length<o&&o>=0&&(n=i[o])!=null?n:null}return null}async visitObjectProperty(t){}async visitObjectExpression(t){let e={},i=t;for(let s of i.properties)if(s instanceof k){let n=await this.visit(s.key);n=x(n)?n:n.toString(),e[n]=await this.visit(s.value)}return e}async visitArrayExpression(t){let e=t;return await this.resolveArgumentsAsync(e.elements)}async visitWhileLoopStatement(t){this.log(`WhileLoopStatement ${t.test} ${t.body}`);let e=t.retain?[]:void 0;for(;v(await this.visit(t.test));){let i=await this.visit(t.body);if(i instanceof A)break;if(!(i instanceof w)){if(i instanceof f)return this.popScope(),i;e==null||e.push(i)}}return e}async visitForLoopStatement(t){let e=t.retain?[]:void 0,i=t.init.identifier;if(!(i instanceof g))throw new Error("Unexpected identifer found");this.pushScope("ForLoopStatement");let s=await this.visit(t.init.init);this.changeVariable(i.value,s);let n=async()=>{let a=await this.visit(t.test);if(l(a)){let p=this.resolve(i.value);return t.direction.type===r.up?a>=p:a<=p}return v(a)},o=async()=>{let a=await this.visit(t.update);if(l(a)){let p=this.resolve(i.value);if(!l(p))throw Error("Cant update value");this.changeVariable(i.value,t.direction.type===r.up?p+a:p-a)}else throw Error("Update value cant be non number")};for(;await n();){let a=await this.visit(t.body);if(a instanceof A)break;if(a instanceof w){await o();continue}if(a instanceof f)return this.popScope(),a;e==null||e.push(a),await o()}return this.popScope(),e!=null?e:null}async visitForOfStatement(t){let e=await this.visit(t.collection);if(!Array.isArray(e))throw Error("Can iterate non array object");let i=t.retain?[]:void 0;this.pushScope("ForOfStatement");for(let s of e){this._declareForIdentifier(t.identifier,s);let n=await this.visit(t.body);if(n instanceof A)break;if(!(n instanceof w)){if(n instanceof f)return this.popScope(),n;i==null||i.push(n)}}return this.popScope(),i}async visitReturnAST(t){return new f(t.value!=null?await this.visit(t.value):null)}async resolveArgumentsAsync(t){return await Promise.all(t.map(async e=>await this.visit(e)))}registerFunction(t,e){this._functionsRegistry[t]=e}unregisterFunction(t){delete this._functionsRegistry[t]}async execute(t,e=!0,i){let s=O.compile(t,e);return i&&Object.keys(i).forEach(n=>this.changeVariable(n,i[n])),await this.visit(s)}static async run(t,e=!1,i){let s=new c,n=O.compile(t,e);return i&&Object.keys(i).forEach(o=>s.changeVariable(o,i[o])),await s.visit(n)}static newInstance(){return new c}clone(){var t=new c;return t._functionsRegistry={...this._functionsRegistry},t.rootScope.memory={...this.rootScope.memory},t}};0&&(module.exports={AST,ArrayExpression,AssignmentExpressionAST,BinaryExpressionAST,BlockStatementAST,BreakAST,BreakBranch,CallExpressionAST,ContinueAST,ContinueBranch,ExpressionStatementAST,ForLoopStatement,ForOfStatement,IdentifierAST,IfStatementAST,IndexAccessorAST,LexerDictionary,LiteralAST,LogicalExpressionAST,LoopControl,MEventScope,MEvento,MEventoAsync,NodeVisitor,ObjectExpression,ObjectProperty,ReturnAST,ReturnBranch,RootAST,Token,TokenType,TupleExpression,UnaryExpressionAST,WhileLoopStatement});
@@ -1,4 +1,4 @@
1
- export declare class TokenType {
1
+ declare class TokenType {
2
2
  static id: number;
3
3
  static comma: number;
4
4
  static semi: number;
@@ -46,7 +46,7 @@ export declare class TokenType {
46
46
  static nullity: number;
47
47
  static RETURN: number;
48
48
  }
49
- export declare class Token {
49
+ declare class Token {
50
50
  type: number;
51
51
  value: any;
52
52
  line?: number;
@@ -55,7 +55,7 @@ export declare class Token {
55
55
  static from(type: number, value: any): Token;
56
56
  toString(): string;
57
57
  }
58
- export declare class LexerDictionary {
58
+ declare class LexerDictionary {
59
59
  lang: string;
60
60
  keywords: {
61
61
  [key: string]: string;
@@ -67,108 +67,108 @@ export declare class LexerDictionary {
67
67
  /**
68
68
  * Parser
69
69
  */
70
- export declare abstract class AST {
70
+ declare abstract class AST {
71
71
  line?: number;
72
72
  col?: number;
73
73
  constructor(line?: number, col?: number);
74
74
  dump(): string;
75
75
  }
76
- export declare class RootAST extends AST {
76
+ declare class RootAST extends AST {
77
77
  body: AST[];
78
78
  source: string;
79
79
  name: string;
80
80
  constructor(body: AST[], name: string, source: string);
81
81
  dump(): string;
82
82
  }
83
- export declare class BlockStatementAST extends AST {
83
+ declare class BlockStatementAST extends AST {
84
84
  body: AST[];
85
85
  constructor(body: AST[], token: Token);
86
86
  toString(): string;
87
87
  }
88
- export declare class IdentifierAST extends AST {
88
+ declare class IdentifierAST extends AST {
89
89
  value: string;
90
90
  constructor(token: Token);
91
91
  toString(): string;
92
92
  }
93
- export declare class LiteralAST extends AST {
93
+ declare class LiteralAST extends AST {
94
94
  value: any;
95
95
  raw: string;
96
96
  constructor(token: Token, raw: string);
97
97
  toString(): string;
98
98
  }
99
- export declare class AssignmentExpressionAST extends AST {
99
+ declare class AssignmentExpressionAST extends AST {
100
100
  identifier: AST;
101
101
  init: AST;
102
102
  constructor(identifier: AST, init: AST);
103
103
  toString(): string;
104
104
  }
105
- export declare class ExpressionStatementAST extends AST {
105
+ declare class ExpressionStatementAST extends AST {
106
106
  expression: AST;
107
107
  constructor(expression: AST);
108
108
  toString(): string;
109
109
  }
110
- export declare class CallExpressionAST extends AST {
110
+ declare class CallExpressionAST extends AST {
111
111
  callee: IdentifierAST;
112
112
  arguments: AST[];
113
113
  constructor(callee: IdentifierAST, ags: AST[]);
114
114
  toString(): string;
115
115
  }
116
- export declare class BinaryExpressionAST extends AST {
116
+ declare class BinaryExpressionAST extends AST {
117
117
  left: AST;
118
118
  operation: Token;
119
119
  right: AST;
120
120
  constructor(left: AST, operation: Token, right: AST);
121
121
  toString(): string;
122
122
  }
123
- export declare class UnaryExpressionAST extends AST {
123
+ declare class UnaryExpressionAST extends AST {
124
124
  operation: Token;
125
125
  argument: AST;
126
126
  constructor(operation: Token, argument: AST);
127
127
  toString(): string;
128
128
  }
129
- export declare class IfStatementAST extends AST {
129
+ declare class IfStatementAST extends AST {
130
130
  test: AST;
131
131
  consequent: AST;
132
132
  alternate?: AST;
133
133
  constructor(test: AST, consequent: AST, alternate?: AST);
134
134
  toString(): string;
135
135
  }
136
- export declare class LogicalExpressionAST extends AST {
136
+ declare class LogicalExpressionAST extends AST {
137
137
  left: AST;
138
138
  operator: Token;
139
139
  right: AST;
140
140
  constructor(left: AST, operator: Token, right: AST);
141
141
  toString(): string;
142
142
  }
143
- export declare class IndexAccessorAST extends AST {
143
+ declare class IndexAccessorAST extends AST {
144
144
  owner: AST;
145
145
  key: AST;
146
146
  computed: boolean;
147
147
  constructor(owner: AST, key: AST, computed?: boolean);
148
148
  toString(): string;
149
149
  }
150
- export declare class ObjectExpression extends AST {
150
+ declare class ObjectExpression extends AST {
151
151
  properties: AST[];
152
152
  constructor(props: AST[], startToken?: Token, endToken?: Token);
153
153
  toString(): string;
154
154
  }
155
- export declare class ArrayExpression extends AST {
155
+ declare class ArrayExpression extends AST {
156
156
  elements: AST[];
157
157
  constructor(props: AST[], start?: AST, end?: AST);
158
158
  toString(): string;
159
159
  }
160
- export declare class ObjectProperty extends AST {
160
+ declare class ObjectProperty extends AST {
161
161
  key: AST;
162
162
  value: AST;
163
163
  constructor(key: AST, value: AST);
164
164
  }
165
- export declare class WhileLoopStatement extends AST {
165
+ declare class WhileLoopStatement extends AST {
166
166
  test: AST;
167
167
  body: AST;
168
168
  retain: boolean;
169
169
  constructor(test: AST, body: AST, startToken?: Token, endToken?: Token, retain?: boolean);
170
170
  }
171
- export declare class ForLoopStatement extends AST {
171
+ declare class ForLoopStatement extends AST {
172
172
  init: AssignmentExpressionAST;
173
173
  test: AST;
174
174
  update: AST;
@@ -177,39 +177,39 @@ export declare class ForLoopStatement extends AST {
177
177
  retain: boolean;
178
178
  constructor(init: AssignmentExpressionAST, test: AST, update: AST, direction: Token, body: AST, startToken?: Token, endToken?: Token, retain?: boolean);
179
179
  }
180
- export declare class ForOfStatement extends AST {
180
+ declare class ForOfStatement extends AST {
181
181
  identifier: AST;
182
182
  collection: AST;
183
183
  body: AST;
184
184
  retain: boolean;
185
185
  constructor(identifier: AST, collection: AST, body: AST, startToken?: Token, endToken?: Token, retain?: boolean);
186
186
  }
187
- export declare class TupleExpression extends AST {
187
+ declare class TupleExpression extends AST {
188
188
  first: AST;
189
189
  second: AST;
190
190
  constructor(first: AST, second: AST);
191
191
  }
192
- export declare class BreakAST extends AST {
192
+ declare class BreakAST extends AST {
193
193
  constructor(line?: number, col?: number);
194
194
  }
195
- export declare class ReturnAST extends AST {
195
+ declare class ReturnAST extends AST {
196
196
  value?: AST;
197
197
  constructor(value?: AST, line?: number, col?: number);
198
198
  }
199
- export declare class ContinueAST extends AST {
199
+ declare class ContinueAST extends AST {
200
200
  constructor(line?: number, col?: number);
201
201
  }
202
- export declare class LoopControl {
202
+ declare class LoopControl {
203
203
  }
204
- export declare class BreakBranch extends LoopControl {
204
+ declare class BreakBranch extends LoopControl {
205
205
  }
206
- export declare class ContinueBranch extends LoopControl {
206
+ declare class ContinueBranch extends LoopControl {
207
207
  }
208
- export declare class ReturnBranch {
208
+ declare class ReturnBranch {
209
209
  value: any;
210
210
  constructor(value: any);
211
211
  }
212
- declare type Func = (node: any) => any;
212
+ type Func = (node: any) => any;
213
213
  declare abstract class ANodeVisitor {
214
214
  protected _nodesVisitors: {
215
215
  [k: string]: Func;
@@ -217,7 +217,7 @@ declare abstract class ANodeVisitor {
217
217
  protected registerVisitor(type: any, visitor: Func): void;
218
218
  abstract visit(node: AST): any;
219
219
  }
220
- export declare abstract class NodeVisitor extends ANodeVisitor {
220
+ declare abstract class NodeVisitor extends ANodeVisitor {
221
221
  constructor();
222
222
  visit(node: AST): any;
223
223
  protected assignProperty(owner: any, property: any, value: any): any;
@@ -243,7 +243,7 @@ export declare abstract class NodeVisitor extends ANodeVisitor {
243
243
  protected abstract visitContinueAST(node: ContinueAST): any;
244
244
  protected abstract visitReturnAST(node: ReturnAST): any;
245
245
  }
246
- export declare class MEventScope {
246
+ declare class MEventScope {
247
247
  name: string;
248
248
  parent?: MEventScope;
249
249
  memory: {
@@ -255,8 +255,8 @@ export declare class MEventScope {
255
255
  resolve(key: string): any;
256
256
  change(key: string, value: any, declare?: boolean): boolean;
257
257
  }
258
- export declare type MEventoFBinding = (args: any[], vm: MEvento) => any;
259
- export declare class MEvento extends NodeVisitor {
258
+ type MEventoFBinding = (args: any[], vm: MEvento) => any;
259
+ declare class MEvento extends NodeVisitor {
260
260
  rootScope: MEventScope;
261
261
  protected currentScope?: MEventScope;
262
262
  debug: boolean;
@@ -312,7 +312,7 @@ export declare class MEvento extends NodeVisitor {
312
312
  clone(): MEvento;
313
313
  newAsyncInstance(): MEventoAsync;
314
314
  }
315
- export declare class MEventoAsync extends MEvento {
315
+ declare class MEventoAsync extends MEvento {
316
316
  constructor();
317
317
  protected visitRootAST(node: RootAST): Promise<any>;
318
318
  protected visitBlockStatementAST(node: BlockStatementAST): Promise<any>;
@@ -321,17 +321,17 @@ export declare class MEventoAsync extends MEvento {
321
321
  protected visitAssignmentExpressionAST(node: AssignmentExpressionAST): Promise<any>;
322
322
  protected visitExpressionStatementAST(node: ExpressionStatementAST): Promise<any>;
323
323
  protected visitCallExpressionAST(node: CallExpressionAST): Promise<any>;
324
- protected visitBinaryExpressionAST(node: BinaryExpressionAST): Promise<any>;
325
- protected visitUnaryExpressionAST(node: UnaryExpressionAST): Promise<any>;
324
+ protected visitBinaryExpressionAST(node: BinaryExpressionAST): Promise<string | number | boolean>;
325
+ protected visitUnaryExpressionAST(node: UnaryExpressionAST): Promise<number | boolean>;
326
326
  protected visitIfStatementAST(node: IfStatementAST): Promise<any>;
327
327
  protected visitLogicalExpressionAST(node: LogicalExpressionAST): Promise<any>;
328
328
  protected visitIndexAccessorAST(node: IndexAccessorAST): Promise<any>;
329
329
  protected visitObjectProperty(node: AST): Promise<void>;
330
330
  protected visitObjectExpression(ast: AST): Promise<any>;
331
331
  protected visitArrayExpression(ast: AST): Promise<any[]>;
332
- protected visitWhileLoopStatement(node: WhileLoopStatement): Promise<any[] | ReturnBranch | undefined>;
333
- protected visitForLoopStatement(node: ForLoopStatement): Promise<any[] | ReturnBranch | null>;
334
- protected visitForOfStatement(node: ForOfStatement): Promise<any[] | ReturnBranch | undefined>;
332
+ protected visitWhileLoopStatement(node: WhileLoopStatement): Promise<any[] | ReturnBranch>;
333
+ protected visitForLoopStatement(node: ForLoopStatement): Promise<any[] | ReturnBranch>;
334
+ protected visitForOfStatement(node: ForOfStatement): Promise<any[] | ReturnBranch>;
335
335
  protected visitReturnAST(node: ReturnAST): Promise<any>;
336
336
  resolveArgumentsAsync(args: AST[]): Promise<any[]>;
337
337
  registerFunction(id: string, fn: MEventoFBinding): void;
@@ -345,4 +345,5 @@ export declare class MEventoAsync extends MEvento {
345
345
  static newInstance(): MEventoAsync;
346
346
  clone(): MEventoAsync;
347
347
  }
348
- export {};
348
+
349
+ export { AST, ArrayExpression, AssignmentExpressionAST, BinaryExpressionAST, BlockStatementAST, BreakAST, BreakBranch, CallExpressionAST, ContinueAST, ContinueBranch, ExpressionStatementAST, ForLoopStatement, ForOfStatement, IdentifierAST, IfStatementAST, IndexAccessorAST, LexerDictionary, LiteralAST, LogicalExpressionAST, LoopControl, MEventScope, MEvento, MEventoAsync, type MEventoFBinding, NodeVisitor, ObjectExpression, ObjectProperty, ReturnAST, ReturnBranch, RootAST, Token, TokenType, TupleExpression, UnaryExpressionAST, WhileLoopStatement };
@@ -0,0 +1,8 @@
1
+ function g(u,t){let e=`Invalid token ${u.type}[${u.value}] at ${u.line}, ${u.col} ${t?`: expecting ${t} token`:""}
2
+ `;throw Error(e)}function l(u){return typeof u=="number"}function rt(u){return typeof u=="boolean"}function T(u){return typeof u=="string"}function f(u){return!(u===null||l(u)&&u===0||T(u)&&u.length===0||rt(u)&&!u)}function it(u){let t=0,e=0,i;if(u.length===0)return t;for(e=0;e<u.length;e++)i=u.charCodeAt(e),t=(t<<5)-t+i,t|=0;return t}var r=class{};r.id=0,r.comma=1,r.semi=2,r.numberConst=3,r.stringConst=4,r.equal=5,r.lparen=6,r.rparen=7,r.eol=8,r.eof=9,r.lbrace=10,r.rbrace=11,r.lbracket=12,r.rbracket=13,r.great=14,r.greatEq=15,r.less=16,r.lessEq=17,r.eqeq=18,r.IF=19,r.ELSE=20,r.TRUE=21,r.FALSE=22,r.NULL=23,r.not=24,r.notEq=25,r.and=26,r.or=27,r.plus=28,r.minus=29,r.div=30,r.mult=31,r.mod=32,r.invalid=33,r.colon=34,r.WHILE_TILL=35,r.FOR_LOOP=36,r.up=37,r.down=38,r.with=39,r.in=40,r.TILL=41,r.BREAK=42,r.CONTINUE=43,r.nullity=44,r.RETURN=45;var h=class u{constructor(t,e,i=1,s=1){this.type=t,this.value=e,this.line=i,this.col=s}static from(t,e){return new u(t,e)}toString(){return`[${this.type.toString()}, ${this.value}]`}},c=class{};c.equal=61,c.comma=44,c.semiColon=59,c.lparen=40,c.rparen=41,c.backslash=92,c.quote=34,c.squote=39,c.plus=43,c.minus=45,c.star=42,c.slash=47,c.percent=37,c.lbrace=123,c.rbrace=125,c.lbracket=91,c.rbracket=93,c.not=33,c.great=62,c.less=60,c.and=38,c.pipe=124,c.colon=58,c.questionMark=63,c.shebang=35;var L=class{constructor(t,e){this.keywords={};this.keywords={...e},this.lang=t}},m=class m{constructor(t){this._position=0;this._line=1;this._col=1;this._currentChar=-1;this._source=t,this._currentChar=this._source[this._position].charCodeAt(0),this._resolveLanguage()}get source(){return this._source}_resolveLanguage(){var e;let t=this.nextToken();if(t.type===r.less){let i=this.nextToken();i.type!==r.id&&g(t);let s=i.value.toString();this._language=(e=m.languages.find(n=>n.lang===s))!=null?e:m._defaultLanguage,t=this.nextToken(),t.type!==r.great&&g(t)}else this._language=m._defaultLanguage,this._position=0,this._currentChar=this._source[this._position].charCodeAt(0)}_advance(){if(this._position++,this._position>=this._source.length){this._currentChar=-1;return}this._currentChar=this._source[this._position].charCodeAt(0),this._col++}_jump(t){if(this._position+=t,this._position>=this._source.length){this._currentChar=-1;return}this._currentChar=this._source[this._position].charCodeAt(0),this._col+=t}_pick(){return this._position+1>=this._source.length?-1:this._source[this._position+1].charCodeAt(0)}_isId(t){return t<48?t===36:t<58?!0:t<65?!1:t<91?!0:t<97?t===95:t<123}_isIdStart(t){return t<65?t===36:t<91?!0:t<97?t===95:t<123}_id(){var o,a;let t="",e=this._col,i=this._position,s=this._line;for(;this._isId(this._currentChar);)t+=String.fromCharCode(this._currentChar),this._advance();let n=this._language&&(o=this._language.keywords[t])!=null?o:t;return(a=m.RESERVED[n])!=null?a:new h(r.id,t,s,e)}_isLineEnd(t){return t===10||t===13||[`
3
+ `,"\r","\u2028","\u2029"].includes(String.fromCharCode(t))}_isWhiteSpace(t){return[" "," "].includes(String.fromCharCode(t))}_isDigit(t){return t>0&&(t^48)<=9}_skipWhiteSpace(){for(;this._isWhiteSpace(this._currentChar)===!0;)this._advance()}_number(){let t="",e=this._col,i=this._position,s=this._line,n=String.fromCharCode(this._currentChar);this._advance();let o=String.fromCharCode(this._currentChar),a=10;if(n==="0"&&["b","B","x","X","o","O"].includes(o))switch(this._advance(),o.toLowerCase()){case"b":a=2;break;case"o":a=8;break;case"x":a=16;break;default:a=10}else t+=n,a=10;for(;this._isDigit(this._currentChar)||a===16&&["A","a","B","b","C","c","D","d","E","e","F","f"].includes(String.fromCharCode(this._currentChar));)t+=String.fromCharCode(this._currentChar),this._advance();if(String.fromCharCode(this._currentChar)==="."&&this._isDigit(this._pick())===!0){for(a!==10&&g(new h(r.id,o,s,i)),t+=String.fromCharCode(this._currentChar),this._advance();this._isDigit(this._currentChar);)t+=String.fromCharCode(this._currentChar),this._advance();return new h(r.numberConst,parseFloat(t),s,e)}return new h(r.numberConst,parseInt(t,a),s,e)}_literalString(t){let e="",i=-1,s=this._position,n=this._col,o=this._line;for(;this._currentChar!==-1;){let a=String.fromCharCode(this._pick());if(this._currentChar==c.backslash){switch(a){case"\\":e+="\\";break;case"0":e+="\0";break;case"a":e+="a";break;case"b":e+="\b";break;case"f":e+="\f";break;case"n":e+=`
4
+ `;break;case"r":e+="\r";break;case"t":e+=" ";break;case"u":e+=String.fromCharCode(Number.parseInt(this._source.substring(this._position+2,this._position+6),16)),this._jump(4);break;case"v":e+="\v";break;case"x":e+=String.fromCharCode(Number.parseInt(this._source.substring(this._position+2,this._position+4),16)),this._jump(2);break;default:if(String.fromCharCode(t)==a)e+=String.fromCharCode(t);else{this._advance(),i=this._currentChar,e+=String.fromCharCode(this._currentChar),this._advance();continue}}this._jump(2),i=this._currentChar;continue}if(this._currentChar===t&&i!==c.backslash)break;e+=String.fromCharCode(this._currentChar),i=this._currentChar,this._advance()}return new h(r.stringConst,e,o,n)}_skipLineComment(){for(;!this._isLineEnd(this._currentChar)&&this._currentChar!=-1;)this._advance()}_skipComment(){for(;this._currentChar!==-1;){if(this._currentChar===c.star&&this._pick()===c.shebang){this._advance(),this._advance();break}this._advance()}}nextToken(){let t=this._line,e=this._col,i=this._position;for(;this._currentChar!==-1;){if(this._isLineEnd(this._currentChar))return this._line++,this._col=1,this._advance(),new h(r.eol,`
5
+ `,t,e);if(this._isWhiteSpace(this._currentChar)){this._skipWhiteSpace();continue}if(this._currentChar==c.shebang){this._advance(),this._currentChar===c.star?(this._advance(),this._skipComment()):this._skipLineComment();continue}if(this._isDigit(this._currentChar))return this._number();if(this._isIdStart(this._currentChar))return this._id();if(this._currentChar===c.equal)return this._advance(),this._currentChar===c.equal?(this._advance(),new h(r.eqeq,"==",t,e)):new h(r.equal,"=",t,e);if(this._currentChar===c.great)return this._advance(),this._currentChar===c.equal?(this._advance(),new h(r.greatEq,">=",t,e)):new h(r.great,">",t,e);if(this._currentChar===c.less)return this._advance(),this._currentChar===c.equal?(this._advance(),new h(r.lessEq,"<=",t,e)):new h(r.less,"<",t,e);if(this._currentChar===c.semiColon)return this._advance(),new h(r.semi,";",t,e);if(this._currentChar===c.lparen)return this._advance(),new h(r.lparen,"(",t,e);if(this._currentChar===c.rparen)return this._advance(),new h(r.rparen,")",t,e);if(this._currentChar===c.comma)return this._advance(),new h(r.comma,",",t,e);if(this._currentChar===c.lbrace)return this._advance(),new h(r.lbrace,"{",t,e);if(this._currentChar===c.rbrace)return this._advance(),new h(r.rbrace,"}",t,e);if(this._currentChar===c.lbracket)return this._advance(),new h(r.lbracket,"[",t,e);if(this._currentChar===c.rbracket)return this._advance(),new h(r.rbracket,"]",t,e);if(this._currentChar===c.plus)return this._advance(),new h(r.plus,"+",t,e);if(this._currentChar===c.minus)return this._advance(),new h(r.minus,"-",t,e);if(this._currentChar===c.slash)return this._advance(),new h(r.div,"/",t,e);if(this._currentChar===c.star)return this._advance(),new h(r.mult,"*",t,e);if(this._currentChar===c.percent)return this._advance(),new h(r.mod,"%",t,e);if(this._currentChar===c.colon)return this._advance(),new h(r.colon,":",t,e);if(this._currentChar===c.not)return this._advance(),this._currentChar===c.equal?(this._advance(),new h(r.notEq,"!=",t,e)):new h(r.not,"!",t,e);if(this._currentChar===c.and&&this._pick()===c.and)return this._advance(),this._advance(),new h(r.and,"&&",t,e);if(this._currentChar===c.pipe&&this._pick()===c.pipe)return this._advance(),this._advance(),new h(r.or,"||",t,e);if(this._currentChar===c.questionMark&&this._pick()===c.questionMark)return this._advance(),this._advance(),new h(r.nullity,"??",t,e);if(this._currentChar===c.quote||this._currentChar===c.squote){let s=this._currentChar;this._advance();let n=this._literalString(s);return this._advance(),n}return new h(r.invalid,String.fromCharCode(this._currentChar),t,e)}return new h(r.eof,"",t,e)}};m._defaultLanguage=new L("en",{if:"if",else:"else",true:"true",false:"false",null:"null",while:"while",for:"for",with:"with",up:"up",down:"down",till:"till",in:"in",break:"break",continue:"continue",return:"return"}),m.languages=[m._defaultLanguage,new L("fr",{si:"if",sinon:"else",vrai:"true",faux:"false",nul:"null",tanque:"while",pour:"for",avec:"with",mont:"up",desc:"down",jusqua:"till",dans:"in",couper:"break",continuer:"continue",returner:"return"}),new L("bm",{nii:"if",note:"else",tien:"true",galon:"false",gansan:"null",foo:"while",seginka:"for",niin:"with",kay:"up",kaj:"down",kata:"till",kono:"in",tike:"break",ipan:"continue",segin:"return"})],m.RESERVED={if:h.from(r.IF,"if"),else:h.from(r.ELSE,"else"),true:h.from(r.TRUE,!0),false:h.from(r.FALSE,!1),null:h.from(r.NULL,null),for:h.from(r.FOR_LOOP,"for"),while:h.from(r.WHILE_TILL,"while"),with:h.from(r.with,"with"),up:h.from(r.up,"up"),down:h.from(r.down,"down"),till:h.from(r.TILL,"till"),in:h.from(r.in,"in"),break:h.from(r.BREAK,"break"),continue:h.from(r.CONTINUE,"continue"),return:h.from(r.RETURN,"return")};var X=m,d=class{constructor(t,e){this.line=t,this.col=e}dump(){return this.toString()}},F=class extends d{constructor(t,e,i){super(1,1),this.body=t,this.name=e,this.source=i}dump(){let t=`Module ${this.name} Start {`;for(let e of this.body)t+=`${e.dump()}
6
+ `;return t+="}",t}},$=class extends d{constructor(t,e){super(e.line,e.col),this.body=t}toString(){return`{
7
+ ${this.body.map(t=>t.toString()).join(`
8
+ `)}}`}},b=class extends d{constructor(t){super(t.line,t.col),this.value=t.value.toString()}toString(){return this.value}},y=class extends d{constructor(t,e){super(t.line,t.col),this.value=t.value,this.raw=e}toString(){return this.value.toString()}},E=class extends d{constructor(t,e){super(t.line,t.col),this.identifier=t,this.init=e}toString(){return`${this.identifier} = ${this.init}`}},G=class extends d{constructor(t){super(t.line,t.col),this.expression=t}toString(){return this.expression.toString()}},R=class extends d{constructor(t,e){super(t.line,t.col),this.callee=t,this.arguments=e}toString(){return`${this.callee.toString()}(...${this.arguments.length})`}},V=class extends d{constructor(t,e,i){super(t.line,t.col),this.left=t,this.operation=e,this.right=i}toString(){return`${this.left} ${this.operation} ${this.right}`}},q=class extends d{constructor(t,e){super(t.line,t.col),this.operation=t,this.argument=e}toString(){return`${this.operation} ${this.argument}`}},B=class extends d{constructor(t,e,i){super(t.line,t.col),this.test=t,this.consequent=e,this.alternate=i}toString(){return`if ${this.test} ${this.consequent} ${this.alternate?`else ${this.alternate} `:""}`}},P=class extends d{constructor(t,e,i){super(t.line,t.col),this.left=t,this.operator=e,this.right=i}toString(){return`${this.left} ${this.operator.value} ${this.right}`}},x=class extends d{constructor(e,i,s=!1){super(e.line,e.col);this.computed=!1;this.owner=e,this.key=i,this.computed=s}toString(){return`${this.owner}[${this.key}]`}},j=class extends d{constructor(t,e,i){super(e==null?void 0:e.line,e==null?void 0:e.col),this.properties=t}toString(){return"{...}"}},N=class extends d{constructor(t,e,i){super(e==null?void 0:e.line,e==null?void 0:e.col),this.elements=t}toString(){return"[...]"}},k=class extends d{constructor(t,e){super(t.line,t.col),this.value=e,this.key=t}},U=class extends d{constructor(e,i,s,n,o=!1){super(s==null?void 0:s.line,s==null?void 0:s.col);this.retain=!1;this.test=e,this.body=i,this.retain=o}},M=class extends d{constructor(e,i,s,n,o,a,p,S=!1){super(a==null?void 0:a.line,a==null?void 0:a.col);this.init=e;this.test=i;this.update=s;this.direction=n;this.body=o;this.retain=S}},W=class extends d{constructor(e,i,s,n,o,a=!1){super(n==null?void 0:n.line,n==null?void 0:n.col);this.identifier=e;this.collection=i;this.body=s;this.retain=a}},D=class extends d{constructor(e,i){super(e.line,e.col);this.first=e;this.second=i}},H=class extends d{constructor(t,e){super(t,e)}},K=class extends d{constructor(t,e,i){super(e,i),this.value=t}},z=class extends d{constructor(t,e){super(t,e)}},J=class{constructor(t=1/0){this.capacity=t;this.storage=[]}push(t){if(this.size()===this.capacity)throw Error("Stack has reached max capacity, you cannot add more items");this.storage.push(t)}pop(){return this.storage.pop()}peek(){return this.storage[this.size()-1]}size(){return this.storage.length}get isEmpty(){return this.storage.length===0}},I=class I{constructor(t){this._loopTrack=new J;this.currentToken=t.nextToken(),this.lexer=t}_eat(t){var e;((e=this.currentToken)==null?void 0:e.type)===t?this.currentToken=this.lexer.nextToken():g(this.currentToken,t)}_eatEOL(){var t;for(;((t=this.currentToken)==null?void 0:t.type)===r.eol;)this._eat(r.eol)}_eatSemiOrEOL(){var t,e;for(;((t=this.currentToken)==null?void 0:t.type)===r.eol||((e=this.currentToken)==null?void 0:e.type)===r.semi;)this._eat(this.currentToken.type)}_eatSemi(){var t;for(;((t=this.currentToken)==null?void 0:t.type)===r.semi;)this._eat(r.semi)}_variable(){let t=new b(this.currentToken);return this._eat(r.id),t}_return(){let t=this.currentToken,e;return!this._expect(r.eol)&&!this._expect(r.semi)&&(e=this._expression()),new K(e,t==null?void 0:t.line,t==null?void 0:t.col)}_factor(){let t=this.currentToken;switch(t.type){case r.plus:case r.minus:case r.not:return this._eat(this.currentToken.type),new q(t,this._term());case r.numberConst:return this._eat(r.numberConst),new y(t,t.value.toString());case r.stringConst:return this._eat(r.stringConst),new y(t,t.value.toString());case r.lparen:this._eat(r.lparen);let e=this._expression();return this._eat(r.rparen),e;case r.TRUE:case r.FALSE:return this._eat(this.currentToken.type),new y(t,t.value.toString());case r.NULL:return this._eat(r.NULL),new y(t,"null");case r.lbracket:return this._arrayExpression();case r.lbrace:return this._objectExpression();case r.IF:return this._ifStatement();case r.WHILE_TILL:return this._whileLoop(!0);case r.FOR_LOOP:return this._forLoop(!0);case r.BREAK:return this._breakExpression();case r.CONTINUE:return this._continueExpression();default:return this._variable()}}_breakExpression(){var t,e;return this._loopTrack.isEmpty&&g(this.currentToken),this._eat(r.BREAK),new H((t=this.currentToken)==null?void 0:t.line,(e=this.currentToken)==null?void 0:e.col)}_continueExpression(){var t,e;return this._loopTrack.isEmpty&&g(this.currentToken),this._eat(r.CONTINUE),new z((t=this.currentToken)==null?void 0:t.line,(e=this.currentToken)==null?void 0:e.col)}_term(){let t=this._factor();return t=this._tryParsingFunctionCall(t),t=this._tryParsingMemberExpression(t),t}_expression(){let t=this._term();for(t=this._tryBinaryExpression(0,t);[r.and,r.or,r.nullity].includes(this.currentToken.type);){let e=this.currentToken;this._eat(e.type),t=new P(t,e,this._expression())}if(this._expect(r.equal))if(t instanceof b||t instanceof x){let e=this.currentToken;this._eat(r.equal),t=new E(t,this._expression())}else throw new Error("Unexpected token");return t}_objectProperty(){var s;let t;switch((s=this.currentToken)==null?void 0:s.type){case r.stringConst:{t=new y(this.currentToken,this.currentToken.value),this._eat(r.stringConst);break}case r.lbracket:{this._eat(r.lbracket);var e=this._expression();this._eat(r.rbracket),t=e;break}case r.id:{let n=this._variable();t=new y(new h(r.id,n.value,n.line,n.col),n.value);break}default:throw`Unexpected token ${this.currentToken}`}this._eat(r.colon);var i=this._expression();return new k(t,i)}_property(){return this._objectProperty()}_objectProperties(){var e,i;let t=[];for(((e=this.currentToken)==null?void 0:e.type)!=r.rbrace&&(this._eatEOL(),t.push(this._property()),this._eatEOL());((i=this.currentToken)==null?void 0:i.type)===r.comma&&(this._eat(r.comma),this._eatEOL(),!this._expect(r.rbrace));)t.push(this._property()),this._eatEOL();return t}_objectExpression(t){var e=t!=null?t:this.currentToken;t||this._eat(r.lbrace);var i=this._objectProperties();return this._eat(r.rbrace),new j(i,e,this.currentToken)}_arrayExpression(){this._eat(r.lbracket);let t=this._expect(r.rbracket)?[]:this._expressionsList();this._eat(r.rbracket);var e=t.length!==0?t[0]:void 0,i=t.length!==0?t[t.length-1]:void 0;return new N(t,e,i)}_tryParsingMemberExpression(t){let e=t;for(;this.currentToken.type===r.lbracket;){this._eat(r.lbracket);let i=this._expression();e=new x(e,i),this._eat(r.rbracket)}return e}_tryBinaryExpression(t,e){let i=e;for(;;){let s=I._binopPrecdences[this.currentToken.type]||-1;if(s<t)return i;let n=this.currentToken;this._eat(n.type);let o=this._term(),a=I._binopPrecdences[this.currentToken.type]||-1;if(s<a){let p=this._tryBinaryExpression(s+1,o);if(p===i)return p;o=p}i=new V(i,n,o)}}_expressionsList(){var i;this._eatEOL();let t=this._expression();this._eatEOL();let e=[t];for(;((i=this.currentToken)==null?void 0:i.type)===r.comma&&(this._eat(r.comma),this._eatEOL(),!this._expect(r.rbracket));)t=this._expression(),e.push(t),this._eatEOL();return e}_callExpression(t){this._eat(r.lparen);let e=[];return this._expect(r.rparen)||(e=this._expressionsList()),this._eat(r.rparen),t instanceof b||g(this.currentToken),new R(t,e)}_tryParsingFunctionCall(t){let e=t;for(;this.currentToken.type===r.lparen;)e=this._callExpression(e);return e}_statementExpression(){let t=this._expression();return[r.semi,r.eol,r.eof].includes(this.currentToken.type)||g(this.currentToken),t}_blockStatement(t=!1){var i;if(t||this._eat(r.lbrace),this._eatEOL(),this._expect(r.rbrace))return this._eat(r.rbrace),new $([],this.currentToken);let e=[this._statement()];for(;this._eatSemiOrEOL(),!(this.currentToken.type===r.rbrace||this.currentToken.type===r.eof||(e.push(this._statement()),this._expect(r.rbrace)));)this.currentToken.type!==r.eol&&this.currentToken.type!==r.semi&&this.currentToken.type!==r.eof&&g(this.currentToken);return this._eat(r.rbrace),((i=this.currentToken)==null?void 0:i.type)===r.rbrace&&this._eat(r.rbrace),new $(e,this.currentToken)}_ifStatement(){this._eat(r.IF);let t=this.currentToken.type===r.lparen;t&&this._eat(r.lparen);let e=this._expression();t&&this._eat(r.rparen);let i;this.currentToken.type===r.lbrace?i=this._blockStatement():i=this._expression();let s;if(this.currentToken.type===r.ELSE)switch(this._eat(r.ELSE),this.currentToken.type){case r.IF:s=this._ifStatement();break;case r.lbrace:s=this._blockStatement();break;default:s=this._expression()}return new B(e,i,s)}_pushLoop(){this._loopTrack.push(!0)}_popLoop(){this._loopTrack.pop()}_whileLoop(t=!1){let e=this.currentToken;this._eat(r.WHILE_TILL),this._pushLoop();let i=this._expression(),s=this.currentToken.type===r.lbrace?this._blockStatement():this._expression();return this._popLoop(),new U(i,s,e,this.currentToken,t)}_forOfIdentifier(){switch(this.currentToken.type){case r.lparen:{this._eat(r.lparen);let t=this._variable();this._eat(r.comma);let e=this._variable();return this._eat(r.rparen),new D(t,e)}default:return this._variable()}}_forLoop(t=!1){let e=this.currentToken;this._eat(r.FOR_LOOP),this._pushLoop();let i=[r.lparen].includes(this.currentToken.type),s;if(i)s=this._forOfIdentifier();else{let n=this._expression();n instanceof E||(i=!0),s=n}if(!i&&s instanceof E){this._eat(r.TILL);let n=this._expression(),o;if(this.currentToken.type===r.up||this.currentToken.type===r.down){let S=this.currentToken;this._eat(S.type),o=S}else o=new h(r.up,"up");let a;this._expect(r.with)?(this._eat(r.with),a=this._expression()):a=new y(new h(r.numberConst,1,this.currentToken.line,this.currentToken.col),"1");let p=this.currentToken.type===r.lbrace?this._blockStatement():this._expression();s=new M(s,n,a,o,p,e,this.currentToken,t),this._popLoop()}else if(i){this._eat(r.in);let n=this._expression(),o=this.currentToken.type===r.lbrace?this._blockStatement():this._expression();s=new W(s,n,o,e,this.currentToken,t),this._popLoop()}else g(this.currentToken);return s}_statement(){switch(this.currentToken.type){case r.BREAK:return this._breakExpression();case r.CONTINUE:return this._continueExpression();case r.RETURN:return this._eat(r.RETURN),this._return();case r.semi:return this._eatSemi(),this._statement();case r.eol:return this._eatEOL(),this._statement();case r.WHILE_TILL:return this._whileLoop();case r.FOR_LOOP:return this._forLoop();default:return this._statementExpression()}}_expect(t){var e;return((e=this.currentToken)==null?void 0:e.type)===t}_definition(){if(this._eatSemiOrEOL(),this._expect(r.eof))return[];let t=[this._statement()];for(;;){if(this._eatSemiOrEOL(),this.currentToken.type===r.eof){this._eat(r.eof);break}this.currentToken.type===r.lbrace?t.push(this._blockStatement()):t.push(this._statement())}return t}_root(){let t=this.lexer.source,e="<module>",i=this._definition();return new F(i,e,t)}parse(){return this._root()}};I._binopPrecdences={[r.eqeq]:10,[r.notEq]:10,[r.great]:10,[r.greatEq]:10,[r.less]:10,[r.lessEq]:10,[r.plus]:20,[r.minus]:20,[r.mult]:40,[r.div]:40,[r.mod]:40};var Y=I,C=class{},A=class extends C{},w=class extends C{},v=class{constructor(t){this.value=t}},Z=class{constructor(){this._nodesVisitors={}}registerVisitor(t,e){let i=`visit${t.name}`;this._nodesVisitors[i]=e}},tt=class extends Z{constructor(){super(),this.registerVisitor(F,this.visitRootAST),this.registerVisitor($,this.visitBlockStatementAST),this.registerVisitor(b,this.visitIdentifierAST),this.registerVisitor(y,this.visitLiteralAST),this.registerVisitor(E,this.visitAssignmentExpressionAST),this.registerVisitor(G,this.visitExpressionStatementAST),this.registerVisitor(R,this.visitCallExpressionAST),this.registerVisitor(V,this.visitBinaryExpressionAST),this.registerVisitor(q,this.visitUnaryExpressionAST),this.registerVisitor(B,this.visitIfStatementAST),this.registerVisitor(P,this.visitLogicalExpressionAST),this.registerVisitor(x,this.visitIndexAccessorAST),this.registerVisitor(k,this.visitObjectProperty),this.registerVisitor(j,this.visitObjectExpression),this.registerVisitor(N,this.visitArrayExpression),this.registerVisitor(U,this.visitWhileLoopStatement),this.registerVisitor(M,this.visitForLoopStatement),this.registerVisitor(W,this.visitForOfStatement),this.registerVisitor(H,this.visitBreakAST),this.registerVisitor(z,this.visitContinueAST),this.registerVisitor(K,this.visitReturnAST)}visit(t){var e;try{let i=`visit${t.constructor.name}`,s=this._nodesVisitors[i];return(e=s==null?void 0:s.call(this,t))!=null?e:null}catch{return null}}assignProperty(t,e,i){(Array.isArray(t)||typeof t=="object")&&(t[e]=i)}},Q=class{constructor(t,e,i){this.memory={};this.name=t,this.memory=e,this.parent=i}resolve(t){var e,i;return Object.keys(this.memory).includes(t)?this.memory[t]:(i=(e=this.parent)==null?void 0:e.resolve(t))!=null?i:null}change(t,e,i=!0){return Object.keys(this.memory).includes(t)?(this.memory[t]=e,!0):this.parent&&this.parent.change(t,e,!1)?!0:i?(this.memory[t]=e,!0):!1}},_=class _ extends tt{constructor(){super();this.rootScope=new Q("Program",{});this.currentScope=this.rootScope;this.debug=!1;this._functionsRegistry={};this._functionsRegistry={..._._globalFunctionsRegistry}}resolve(e){var i,s;return(s=(i=this.currentScope)==null?void 0:i.resolve(e))!=null?s:null}changeVariable(e,i){var s;return(s=this.currentScope)!=null&&s.change(e,i)?i:null}pushScope(e){let i=new Q(e,{},this.currentScope);this.currentScope=i}popScope(){var e;this.currentScope=(e=this.currentScope)==null?void 0:e.parent}log(e){this.debug&&console.log(e)}visitRootAST(e){var n;let i=e.body,s;for(let o of i)if(s=this.visit(o),s instanceof v)return(n=s.value)!=null?n:null;return s!=null?s:null}visitBlockStatementAST(e){let i=e.body,s;this.pushScope("Block");for(let n of i)if(s=this.visit(n),s instanceof C||s instanceof v)break;return this.popScope(),s!=null?s:null}visitIdentifierAST(e){var s;let i=e.value;return(s=this==null?void 0:this.resolve(i))!=null?s:null}visitLiteralAST(e){return e.value}visitAssignmentExpressionAST(e){let i=e.identifier,s=e.init,n=null;if(i instanceof x){var o=this.visit(i.owner);n=this.visit(e.init);var a=this.visit(i.key);this.assignProperty(o,a,n)}else i instanceof b&&(n=this.visit(s),this.changeVariable(i.value,n));return n}visitExpressionStatementAST(e){let i=e.expression;return this.visit(i)}visitCallExpressionAST(e){let i=e.callee,s=e.arguments,n=i.value,o=this.resolveFunction(n),a=s.map(p=>this.visit(p));return o==null?void 0:o(a,this)}visitBinaryExpressionAST(e){let i=e.left,s=e.right,n=e.operation,o=this.visit(i),a=this.visit(s);switch(n.type){case r.plus:return l(o)&&l(a)?o+a:`${o}${a}`;case r.minus:if(l(o)&&l(a))return o-a;throw new Error(`Operation ${n.value} not allowed no num value`);case r.mult:if(l(o)&&l(a))return o*a;if(T(o)&&l(a))return o.repeat(a);if(l(o)&&T(a))return a.repeat(o);throw new Error(`Operation ${n.value} not allowed no num value`);case r.div:if(l(o)&&l(a)){if(a===0)throw new Error("Invalid division by 0");return o/a}throw new Error(`Operation ${n.value} not allowed no num value`);case r.mod:if(l(o)&&l(a))return o%a;throw new Error(`Operation ${n.value} not allowed no num value`);case r.great:if(l(o)&&l(a))return o>a;throw new Error(`Operation ${n.value} not allowed no num value`);case r.greatEq:if(l(o)&&l(a))return o>=a;throw new Error(`Operation ${n.value} not allowed no num value`);case r.less:if(l(o)&&l(a))return o<a;throw new Error(`Operation ${n.value} not allowed no num value`);case r.lessEq:if(l(o)&&l(a))return o<=a;throw new Error(`Operation ${n.value} not allowed no num value`);case r.eqeq:return o===a;case r.notEq:return o!==a;default:throw new Error(`Operation ${n.value} not allowed no num value`)}}visitUnaryExpressionAST(e){let i=e.argument,s=e.operation,n=this.visit(i);if(s.type===r.not)return f(n)===!1;if(!l(n))throw new Error(`Operation ${s.value} not allowed no num value`);if(s.type===r.plus)return n;if(s.type===r.minus)return-n;throw new Error(`Operation ${s.value} not allowed no num value`)}visitIfStatementAST(e){let i=e.test,s=this.visit(i);return f(s)?this.visit(e.consequent):e.alternate?this.visit(e.alternate):null}visitLogicalExpressionAST(e){let i=e.left,s=this.visit(i);if(e.operator.type===r.nullity)return s!=null?s:this.visit(e.right);let n=f(s);return e.operator.type===r.and?n?f(this.visit(e.right)):!1:e.operator.type===r.or?n?!0:f(this.visit(e.right)):null}visitIndexAccessorAST(e){var n,o;let i=e.owner,s=this.visit(i);if(s==null)return null;if(typeof s=="object"){let a=this.visit(e.key);return(n=s[a])!=null?n:null}else if(Array.isArray(s)){let a=this.visit(e.key);return l(a)&&s.length<a&&a>=0&&(o=s[a])!=null?o:null}return null}visitObjectProperty(e){}visitObjectExpression(e){let i={},s=e;for(let n of s.properties)if(n instanceof k){let o=this.visit(n.key);o=T(o)?o:o.toString(),i[o]=this.visit(n.value)}return i}visitArrayExpression(e){let i=e;return this.resolveArguments(i.elements)}visitBreakAST(e){return new A}visitWhileLoopStatement(e){this.log(`WhileLoopStatement ${e.test} ${e.body}`);let i=e.retain?[]:void 0;for(;f(this.visit(e.test));){let s=this.visit(e.body);if(s instanceof A)break;if(!(s instanceof w)){if(s instanceof v)return this.popScope(),s;i==null||i.push(s)}}return i!=null?i:null}visitForLoopStatement(e){let i=e.retain?[]:void 0,s=e.init.identifier;if(!(s instanceof b))throw new Error("Unexpected identifer found");this.pushScope("ForLoopStatement");let n=this.visit(e.init.init);this.changeVariable(s.value,n);let o=()=>{let p=this.visit(e.test);if(l(p)){let S=this.resolve(s.value);return e.direction.type===r.up?p>=S:p<=S}return f(p)},a=()=>{let p=this.visit(e.update);if(l(p)){let S=this.resolve(s.value);if(!l(S))throw Error("Cant update value");this.changeVariable(s.value,e.direction.type===r.up?S+p:S-p)}else throw Error("Update value cant be non number")};for(;o();){let p=this.visit(e.body);if(p instanceof A)break;if(p instanceof w){a();continue}if(p instanceof v)return this.popScope(),p;i==null||i.push(p),a()}return this.popScope(),i!=null?i:null}visitForOfStatement(e){let i=this.visit(e.collection);if(!Array.isArray(i))throw Error("Can iterate non array object");let s=e.retain?[]:void 0;this.pushScope("ForOfStatement");for(let n of i){this._declareForIdentifier(e.identifier,n);let o=this.visit(e.body);if(o instanceof A)break;if(!(o instanceof w)){if(o instanceof v)return this.popScope(),o;s==null||s.push(o)}}return this.popScope(),s!=null?s:null}visitContinueAST(e){return new w}visitReturnAST(e){return new v(e.value!=null?this.visit(e.value):null)}_declareForIdentifier(e,i){if(e instanceof D){if(!Array.isArray(i))throw Error("Unable to make a tuple from non Array element");this.changeVariable(e.first.value,i[0]),this.changeVariable(e.second.value,i[1])}this.changeVariable(e.value,i)}resolveArguments(e){return e.map(i=>this.visit(i))}setFunctionResolver(e){this._functionResolver=e}resolveFunction(e){var i,s;return(s=this._functionsRegistry[e])!=null?s:(i=this._functionResolver)==null?void 0:i.call(this,e)}registerFunction(e,i){this._functionsRegistry[e]=i}unregisterFunction(e){delete this._functionsRegistry[e]}execute(e,i=!0,s){let n=_.compile(e,i);return s&&Object.keys(s).forEach(o=>this.changeVariable(o,s[o])),this.visit(n)}static compile(e,i=!1){let s=it(e);if(i&&this._cache.has(s))return this._cache.get(s);let n=new X(e),a=new Y(n).parse();return i&&this._cache.set(s,a),a}static register(e,i){_._globalFunctionsRegistry[e]=i}static unregister(e){delete _._globalFunctionsRegistry[e]}static run(e,i=!1,s){let n=new _,o=_.compile(e,i);return s&&Object.keys(s).forEach(a=>n.changeVariable(a,s[a])),n.visit(o)}static newInstance(){return new _}clone(){var e=new _;return e._functionsRegistry={...this._functionsRegistry},e.rootScope.memory={...this.rootScope.memory},e}newAsyncInstance(){let e=et.newInstance();return e.rootScope.memory=this.rootScope.memory,e._functionsRegistry=this._functionsRegistry,e}};_._globalFunctionsRegistry={},_._cache=new Map;var O=_,et=class u extends O{constructor(){super()}async visitRootAST(t){var s;let e=t.body,i;for(let n of e)if(i=await this.visit(n),i instanceof v)return(s=i.value)!=null?s:null;return i!=null?i:null}async visitBlockStatementAST(t){let e=t.body,i;this.pushScope("Block");for(let s of e)if(i=await this.visit(s),i instanceof C||i instanceof v)break;return this.popScope(),i}async visitIdentifierAST(t){let e=t.value;return this.resolve(e)}async visitLiteralAST(t){return t.value}async visitAssignmentExpressionAST(t){let e=t.identifier,i=t.init,s=null;if(e instanceof x){var n=await this.visit(e.owner);s=await this.visit(t.init);var o=await this.visit(e.key);this.assignProperty(n,o,s)}else e instanceof b&&(s=await this.visit(i),this.changeVariable(e.value,s));return s}async visitExpressionStatementAST(t){let e=t.expression;return await this.visit(e)}async visitCallExpressionAST(t){let e=t.callee,i=t.arguments,s=e.value,n=this._functionsRegistry[s],o=await Promise.all(i.map(a=>this.visit(a)));return await(n==null?void 0:n(o,this))}async visitBinaryExpressionAST(t){let e=t.left,i=t.right,s=t.operation,n=await this.visit(e),o=await this.visit(i);switch(s.type){case r.plus:return l(n)&&l(o)?n+o:`${n}${o}`;case r.minus:if(l(n)&&l(o))return n-o;if(T(n)&&l(o))return n.repeat(o);if(l(n)&&T(o))return o.repeat(n);throw new Error(`Operation ${s.value} not allowed no num value`);case r.mult:if(l(n)&&l(o))return n*o;throw new Error(`Operation ${s.value} not allowed no num value`);case r.div:if(l(n)&&l(o)){if(o===0)throw new Error("Invalid division by 0");return n/o}throw new Error(`Operation ${s.value} not allowed no num value`);case r.mod:if(l(n)&&l(o))return n%o;throw new Error(`Operation ${s.value} not allowed no num value`);case r.great:if(l(n)&&l(o))return n>o;throw new Error(`Operation ${s.value} not allowed no num value`);case r.greatEq:if(l(n)&&l(o))return n>=o;throw new Error(`Operation ${s.value} not allowed no num value`);case r.less:if(l(n)&&l(o))return n<o;throw new Error(`Operation ${s.value} not allowed no num value`);case r.lessEq:if(l(n)&&l(o))return n<=o;throw new Error(`Operation ${s.value} not allowed no num value`);case r.eqeq:return n===o;case r.notEq:return n!==o;default:throw new Error(`Operation ${s.value} not allowed no num value`)}}async visitUnaryExpressionAST(t){let e=t.argument,i=t.operation,s=await this.visit(e);if(i.type===r.not)return f(s)===!1;if(!l(s))throw new Error(`Operation ${i.value} not allowed no num value`);if(i.type===r.plus)return s;if(i.type===r.minus)return-s;throw new Error(`Operation ${i.value} not allowed no num value`)}async visitIfStatementAST(t){let e=t.test,i=await this.visit(e);return f(i)?await this.visit(t.consequent):t.alternate?await this.visit(t.alternate):null}async visitLogicalExpressionAST(t){let e=t.left,i=await this.visit(e);if(t.operator.type===r.nullity)return i!=null?i:await this.visit(t.right);let s=f(i);return t.operator.type===r.and?s?f(await this.visit(t.right)):!1:t.operator.type===r.or?s?!0:f(await this.visit(t.right)):!1}async visitIndexAccessorAST(t){var s,n;let e=t.owner,i=await this.visit(e);if(i==null)return null;if(typeof i=="object"){let o=await this.visit(t.key);return(s=i[o])!=null?s:null}else if(Array.isArray(i)){let o=await this.visit(t.key);return l(o)&&i.length<o&&o>=0&&(n=i[o])!=null?n:null}return null}async visitObjectProperty(t){}async visitObjectExpression(t){let e={},i=t;for(let s of i.properties)if(s instanceof k){let n=await this.visit(s.key);n=T(n)?n:n.toString(),e[n]=await this.visit(s.value)}return e}async visitArrayExpression(t){let e=t;return await this.resolveArgumentsAsync(e.elements)}async visitWhileLoopStatement(t){this.log(`WhileLoopStatement ${t.test} ${t.body}`);let e=t.retain?[]:void 0;for(;f(await this.visit(t.test));){let i=await this.visit(t.body);if(i instanceof A)break;if(!(i instanceof w)){if(i instanceof v)return this.popScope(),i;e==null||e.push(i)}}return e}async visitForLoopStatement(t){let e=t.retain?[]:void 0,i=t.init.identifier;if(!(i instanceof b))throw new Error("Unexpected identifer found");this.pushScope("ForLoopStatement");let s=await this.visit(t.init.init);this.changeVariable(i.value,s);let n=async()=>{let a=await this.visit(t.test);if(l(a)){let p=this.resolve(i.value);return t.direction.type===r.up?a>=p:a<=p}return f(a)},o=async()=>{let a=await this.visit(t.update);if(l(a)){let p=this.resolve(i.value);if(!l(p))throw Error("Cant update value");this.changeVariable(i.value,t.direction.type===r.up?p+a:p-a)}else throw Error("Update value cant be non number")};for(;await n();){let a=await this.visit(t.body);if(a instanceof A)break;if(a instanceof w){await o();continue}if(a instanceof v)return this.popScope(),a;e==null||e.push(a),await o()}return this.popScope(),e!=null?e:null}async visitForOfStatement(t){let e=await this.visit(t.collection);if(!Array.isArray(e))throw Error("Can iterate non array object");let i=t.retain?[]:void 0;this.pushScope("ForOfStatement");for(let s of e){this._declareForIdentifier(t.identifier,s);let n=await this.visit(t.body);if(n instanceof A)break;if(!(n instanceof w)){if(n instanceof v)return this.popScope(),n;i==null||i.push(n)}}return this.popScope(),i}async visitReturnAST(t){return new v(t.value!=null?await this.visit(t.value):null)}async resolveArgumentsAsync(t){return await Promise.all(t.map(async e=>await this.visit(e)))}registerFunction(t,e){this._functionsRegistry[t]=e}unregisterFunction(t){delete this._functionsRegistry[t]}async execute(t,e=!0,i){let s=O.compile(t,e);return i&&Object.keys(i).forEach(n=>this.changeVariable(n,i[n])),await this.visit(s)}static async run(t,e=!1,i){let s=new u,n=O.compile(t,e);return i&&Object.keys(i).forEach(o=>s.changeVariable(o,i[o])),await s.visit(n)}static newInstance(){return new u}clone(){var t=new u;return t._functionsRegistry={...this._functionsRegistry},t.rootScope.memory={...this.rootScope.memory},t}};export{d as AST,N as ArrayExpression,E as AssignmentExpressionAST,V as BinaryExpressionAST,$ as BlockStatementAST,H as BreakAST,A as BreakBranch,R as CallExpressionAST,z as ContinueAST,w as ContinueBranch,G as ExpressionStatementAST,M as ForLoopStatement,W as ForOfStatement,b as IdentifierAST,B as IfStatementAST,x as IndexAccessorAST,L as LexerDictionary,y as LiteralAST,P as LogicalExpressionAST,C as LoopControl,Q as MEventScope,O as MEvento,et as MEventoAsync,tt as NodeVisitor,j as ObjectExpression,k as ObjectProperty,K as ReturnAST,v as ReturnBranch,F as RootAST,h as Token,r as TokenType,D as TupleExpression,q as UnaryExpressionAST,U as WhileLoopStatement};
package/package.json CHANGED
@@ -1,32 +1,26 @@
1
1
  {
2
- "name": "mevento",
3
- "version": "2.1.0",
4
- "dependencies": {
5
- "tslib": "^2.0.3"
6
- },
7
- "keywords": [
8
- "MEvento",
9
- "MEvent",
10
- "Event code"
11
- ],
12
- "module": "fesm2015/mevento.mjs",
13
- "es2020": "fesm2020/mevento.mjs",
14
- "esm2020": "esm2020/mevento.mjs",
15
- "fesm2020": "fesm2020/mevento.mjs",
16
- "fesm2015": "fesm2015/mevento.mjs",
17
- "typings": "index.d.ts",
18
- "exports": {
19
- "./package.json": {
20
- "default": "./package.json"
2
+ "name": "mevento",
3
+ "version": "3.0.0",
4
+ "main": "dist/cjs/index.js",
5
+ "module": "dist/esm/index.js",
6
+ "types": "dist/esm/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsup"
21
9
  },
22
- ".": {
23
- "types": "./index.d.ts",
24
- "esm2020": "./esm2020/mevento.mjs",
25
- "es2020": "./fesm2020/mevento.mjs",
26
- "es2015": "./fesm2015/mevento.mjs",
27
- "node": "./fesm2015/mevento.mjs",
28
- "default": "./fesm2020/mevento.mjs"
10
+ "files": [
11
+ "/dist"
12
+ ],
13
+ "dependencies": {
14
+ "tslib": "^2.0.3"
15
+ },
16
+ "exports": {
17
+ ".": {
18
+ "require": "./dist/cjs/index.js",
19
+ "import": "./dist/esm/index.js"
20
+ }
21
+ },
22
+ "devDependencies": {
23
+ "tsup": "^8.3.0",
24
+ "typescript": "^5.6.2"
29
25
  }
30
- },
31
- "sideEffects": false
32
- }
26
+ }
package/README.md DELETED
@@ -1,59 +0,0 @@
1
- # Mevento
2
-
3
- Mevento is a tiny VM one single file that handles `MEvento code` executions inside JS engine. `MEvento` is simple programming language that allows developers exposing an app host function, that way they have the ability to dynamically execute simple script that call host function.
4
-
5
- The VM uses a AST Walker to execute MEvento script, so of course the performace is not its concern a lot.
6
-
7
- ## MEvento code syntax
8
- Syntaxically MEvento is a c-like language, but very limited: no function declaration, no class, just assignation, function call and conditional check.
9
-
10
- ```js
11
- a = 12
12
- a = 23
13
- b = functon1()
14
- c = function2()
15
- d = a + b
16
- if(a == b) {
17
- log('a = b')
18
- } else {
19
- log("a != b")
20
- }
21
- ```
22
-
23
- ## How to use
24
- The host application can expose functions through Mevento VM that way:
25
- ```ts
26
- import {MEvento} from 'mevento';
27
- MEvento.register('log', (args) => console.log); // exposes console.log through MEvento as log function
28
- MEvento.register('cos2', (args) => Math.cos);
29
- ```
30
-
31
- Let's assume you want to execute a `MEvento code`:
32
-
33
- ```ts
34
- import {MEvento} from 'mevento';
35
-
36
- const mevento = MEvento.newInstance();
37
-
38
- mevento.execute(`log("molo")`)
39
-
40
- ```
41
-
42
- `MEvento` instance execution is syncrhrone, that's to say, if you wan to consume `async` function exposed through Mevento, you nee to use `MEventoAsync` instead.
43
-
44
-
45
- ```ts
46
- import {MEvento} from 'mevento';
47
-
48
- MEvento.register('async', async (args) => await asyncF(args[0]));
49
- const mevento = MEventoAsync.newInstance();
50
-
51
- await mevento.execute(`async("molo")`)
52
-
53
- ```
54
- `execute` method on `MEventoAsync` instance return a `Promise`.
55
-
56
-
57
- ## Notes
58
- MEvento does not have scope variables, all variables are visible everywhere.
59
-