UNPKG

emcl

Version:

A language designed to compile to mcfunction files.

21 lines (20 loc) 63.7 kB
#!/usr/bin/env node import{createRequire as es}from"node:module";var ve=Object.create;var{getPrototypeOf:me,defineProperty:Vn,getOwnPropertyNames:xe}=Object;var ce=Object.prototype.hasOwnProperty;var ns=(n,e,s)=>{s=n!=null?ve(me(n)):{};let o=e||!n||!n.__esModule?Vn(s,"default",{value:n,enumerable:!0}):s;for(let r of xe(n))if(!ce.call(o,r))Vn(o,r,{get:()=>n[r],enumerable:!0});return o};var G=(n,e)=>{for(var s in e)Vn(n,s,{get:e[s],enumerable:!0,configurable:!0,set:(o)=>e[s]=()=>o})};var ss=es(import.meta.url);class kn{schemes=new Map;createDirectory(n){return this._getFileSystem(n).createDirectory(n)}readTextFile(n){return this._getFileSystem(n).readTextFile(n)}writeTextFile(n,e){return this._getFileSystem(n).writeTextFile(n,e)}_getFileSystem(n){let e=this.schemes.get(n.scheme);if(!e)throw new Error(`"${n.scheme}" is not a registered file system!`);return e}}class yn{}class O{scheme;authority;pathname;constructor(n="",e="",s="/"){this.scheme=n;this.authority=e;this.pathname=s}static fromString(n){try{return new O().setString(n)}catch(e){return}}clone(){return new O().set(this)}isFile(){return!this.pathname.endsWith("/")}pathSegments(){return this.pathname.slice().split("/").filter((n)=>n)}directorySegments(){let n=this.pathSegments();if(this.isFile())n.pop();return n}filename(){if(!this.isFile())return"";return this.pathSegments().pop()??""}slug(){return this.pathSegments().pop()??this.authority}appendString(n){return O._setFromURL(this,new URL(n,this.toString())),this}setString(n){return O._setFromURL(this,new URL(n)),this}set(n){return this.scheme=n.scheme,this.authority=n.authority,this.pathname=n.pathname,this}isOrigin(){return this.pathname==="/"}hasSameOrigin(n){return this.scheme===n.scheme&&this.authority===n.authority}relativePathOf(n){if(!this.hasSameOrigin(n))return n.toString();let e=this.directorySegments(),s=this.directorySegments(),o=(i,f)=>{for(let p=0,d=i.length;p<d;p++)if(i[p]!==f[p])return!1;return!0},r="";while(!o(e,s))r+="../",e.pop();return r+=n.filename(),r}toString(n=!0){let e=`${this.scheme}:`,s=this.authority?`//${this.authority}`:"",o=this.pathname,r=e+s+o;return n?encodeURI(decodeURI(r)):r}setPathSegments(n,e){return this.pathname="/"+n.join("/")+(e?"/"+e:""),this}ascend(n){let e=this.directorySegments();return e.length-=n,this.setPathSegments(e)}descend(n,e){return this.setPathSegments([...this.directorySegments(),...n],e)}asFile(){if(this.pathname.endsWith("/"))this.pathname=this.pathname.slice(0,-1);return this}asDirectory(){if(!this.pathname.endsWith("/"))this.pathname+="/";return this}static _setFromURL(n,e){if(n.scheme=e.protocol.slice(0,-1),n.authority=e.host,e.pathname.startsWith("//")){let s=e.pathname.indexOf("/",3),o=s===-1?e.pathname.length:s;n.authority=e.pathname.slice(2,o),n.pathname=e.pathname.slice(o)}else n.pathname=e.pathname}}class Pn extends yn{async fs(){try{return await import("fs/promises")}catch{throw new Error("Native file access is not supported in this environment.")}}async supported(){return await this.fs().then(()=>!0).catch(()=>!1)}async readTextFile(n){let e=await this.fs(),s=this.#n(n);return await e.readFile(s,{encoding:"utf8"})}async writeTextFile(n,e){let s=await this.fs(),o=this.#n(n);await s.mkdir(o.substring(0,o.lastIndexOf("/")),{recursive:!0}),await s.writeFile(o,e,{encoding:"utf8"})}async createDirectory(n){await(await this.fs()).mkdir(this.#n(n),{recursive:!0})}#n(n){return decodeURI(n.pathname)}}var h={};G(h,{lint:()=>Xn,illegalCharacters:()=>Le});var Le=/[^a-z\d_\-\/\.:]/g;function Xn(n){let e=n.split(":"),s=[];if(e.length!==2)s.push('Namespaced ids should have the format "namespace:id".');if(e[0].includes("/"))s.push("Namespaces cannot contain slashes.");if(n.match(Le))if(n.toLowerCase()!==n)s.push("Namespaced ids cannot contain uppercase characters.");else s.push("Namespaced id contains illegal characters.");if(!s.length)return;return`"${n}" is not a valid namespaced id. `+s.join(` `)}var Mn={};G(Mn,{lint:()=>os});function os(n,e){if(n==="storage")return Xn(e);if(n==="entity"){if(e==="@a"||e==="@e")return`nbt "entity" ${JSON.stringify(e)} is not a valid NBT target as it affects multiple entities. `+rs}return}var rs=`To affect a single target, use a different selector or add a clause. For example: nbt "entity" "@p" ... nbt "entity" "@e[limit=1]" ... To affect multiple entities, use an execute-block and the self-selector (@s). For example: execute "as @e" { nbt "entity" "@s" ... }`;var j={};G(j,{maxObjectiveLength:()=>is,lintObjective:()=>fs,illegalObjectiveCharacters:()=>$e});var $e=/[^\w\-\+\.]/g,is=16;function fs(n){let e=[];if(n.length>16)e.push("Scoreboard objectives can contain at most 16 characters.");if(n.match($e))e.push("Objective contains illegal characters.");if(!e.length)return;return`"${n}" is not a valid scoreboard objective name. `+e.join(` `)}var v;((js)=>{function n(o){try{return{config:JSON.parse(o)}}catch(r){return{error:"Config file is malformed."}}}js.parse=n;function e(o){return{entry:"main.emcl",destination:"dst",initializer:`${o}:init`,destructor:`${o}:destroy`,scoreboardNamespace:`${o}.i`,functionNamespace:`${o}:internal/`,nbtStorageNamespace:`${o}:internal/`,onLoad:[`${o}:init`],onTick:[],packMeta:{pack:{pack_format:7,description:"<ADD DESCRIPTION HERE>"}}}}js.boilerplate=e;function s(o,r,i){if(!o)i.error("Config must not be empty!");if(!o.entry)i.error('"config.entry" must not be empty.');else if(!O.fromString(r.toString()+`${o.entry}`))i.error('"config.entry" is malformed!');if(o.destination&&!O.fromString(r.toString()+`${o.destination}`))i.error('"config.destination" is malformed!');if(!o.initializer)i.error('"config.initializer" must not be empty.');else if(typeof o.initializer!=="string")i.error('"config.initializer" must be a string.');else{let d=h.lint(o.initializer);if(d)i.warn(d)}if(!o.destructor)i.error('"config.destructor" must not be empty.');else if(typeof o.destructor!=="string")i.error('"config.destructor" must be a string.');else{let d=h.lint(o.destructor);if(d)i.warn(d)}if(!o.scoreboardNamespace)i.error('"config.scoreboardNamespace" must not be empty.');else if(typeof o.scoreboardNamespace!=="string")i.error('"config.scoreboardNamespace" must be a string.');else{let d=j.lintObjective(o.scoreboardNamespace);if(d)i.warn(d);let l=j.maxObjectiveLength-3;if(o.scoreboardNamespace.length>l)i.warn(`"config.scoreboardNamespace" should be kept under ${l} characters.`)}if(!o.functionNamespace)i.error('"config.functionNamespace" must not be empty.');else if(typeof o.functionNamespace!=="string")i.error('"config.functionNamespace" must be a string.');else{let d=h.lint(o.functionNamespace);if(d)i.warn(d)}if(!o.nbtStorageNamespace)i.error('"config.nbtStorageNamespace" must not be empty.');else if(typeof o.nbtStorageNamespace!=="string")i.error('"config.nbtStorageNamespace" must be a string.');else{let d=h.lint(o.nbtStorageNamespace);if(d)i.warn(d)}function f(d,l){if(l===void 0)return;if(l instanceof Array){for(let S of l){let H=h.lint(`${S}`);if(H)i.warn(H)}return}i.warn(`"${d}" must be string[] or undefined.`)}f("config.onLoad",o.onLoad),f("config.onTick",o.onTick);let p=e("boilerplate");for(let d of Object.keys(o))if(!(d in p))i.warn(`"config.${d}" is not a known option.`)}js.validate=s})(v||={});class dn{console;fileSystem;uri;async generate(n){if(!this.uri)return this.console.error("No project loaded.");if(this.console.log(`Input Directory: ${this.uri.toString()}`),!n){let s=this.uri.slug().trim().split(/\s+|(?=[A-Z])/).join("_").toLowerCase();n=v.boilerplate(s)}let e=dn.files(n);try{for(let[s,o]of e){let r=this.uri.clone().appendString(s);if(o!==void 0)await this.fileSystem.readTextFile(r).catch(async()=>{this.console.log(`Creating file: ${r}`),await this.fileSystem.writeTextFile(r,o)});else this.console.log(`Creating directory: ${r}`),await this.fileSystem.createDirectory(r)}this.console.log("Complete!")}catch(s){throw this.console.error(`Unexpected error: `+(s instanceof Error?s.message:s)),s}}static files(n){let e=new Map;if(e.set("emcl.config.json",JSON.stringify(n,null,"\t")),e.set(n.entry,""),n.destination)e.set(n.destination,void 0);return e}}class Qn{has(n){for(let e=this._symbols.length-1;e>=0;e--)if(this._symbols[e].has(n))return!0;return!1}hasInScope(n){return this._symbols[this._symbols.length-1].has(n)}get(n){for(let e=this._symbols.length-1;e>=0;e--){let s=this._symbols[e];if(s.has(n))return s.get(n)}return}set(n,e){this._symbols[this._symbols.length-1].set(n,e)}enterScope(){this._symbols.push(new Map)}exitScope(){if(this.isGlobal())throw new Error("Cannot exit the global scope.");this._symbols.pop()}isGlobal(){return this._symbols.length===1}_symbols=[new Map]}class sn{config;index=0;state;constructor(n){this.config=n,this.reset()}reset(){this.index=0}step(n){this.config.regex.lastIndex=this.index;let e=this.config.regex.exec(n);if(!e)return this.config.errorHandler.call(this,n);for(let s=1;s<e.length;s++){let o=e[s];if(o!==void 0){this.index+=o.length;let r=this.config.types[s-1];return{value:o,type:r}}}throw new Error("LEXER: Encountered an unexpected error.")}tokenize(n){let e=[];while(this.index<n.length)e.push(this.step(n));return e}static joinAdjacentTokens(n,e){let s=[];for(let o of n){let r=s[s.length-1];if(o.type===e&&r?.type===e)r.value+=o.value;else s.push(o)}return s}static getTokensMap(n){let e=new Map,s=0,o=0;for(let r of n){e.set(r,{line:s,char:o}),o+=r.value.length;let i=r.value.split(` `);if(i.length>1)s+=i.length-1,o=i[i.length-1].length}return e}}class on{startState;rules=[];errorHandler=function(n){return{type:"ILLEGAL",value:n[this.index++]}};constructor(n="start"){this.startState=n}define(n,e){e=Array.isArray(e)?e:[e];for(let s of e){let o=typeof s==="string"?s:s.source;this.rules.push([n,o])}}defineString(n,e){e=Array.isArray(e)?e:[e];let s=e.map((o)=>on.stringRegex(o));return this.define(n,s)}defineKeyword(n,e){e=Array.isArray(e)?e:[e];let s=(Array.isArray(e)?e:[e]).map((o)=>"\\b"+on.stringRegex(o)+"\\b");return this.define(n,s)}buildConfig(){let n=[],e=[];for(let[s,o]of this.rules)n.push(s),e.push(o);return{types:n,regex:new RegExp(on.unionRegex(e),"gy"),errorHandler:this.errorHandler}}build(){return new sn(this.buildConfig())}static stringRegex(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}static unionRegex(n){return"("+[...n].join(")|(")+")"}}var w=new on;w.define("WHITESPACE",/[^\S\r\n]+|(?:\r?\n)/);w.define("COMMENT",/\/\/.*/);w.define("COMMENT",/\/\*[^]+?\*\//);w.defineKeyword("MCFUNCTION","mcfunction");w.defineKeyword("SCORE","score");w.defineKeyword("NBT","nbt");w.defineKeyword("ALIAS","alias");w.defineKeyword("IMPORT","import");w.defineKeyword("AS","as");w.defineKeyword("FOR","for");w.defineKeyword("WHILE","while");w.defineKeyword("IF","if");w.defineKeyword("EXECUTE","execute");w.defineKeyword("RETURN","return");w.defineKeyword("CONST","const");w.defineKeyword("FINAL","final");w.defineKeyword("TYPE",["uint8","byte","uint16","short","uint32","int","uint64","long","float","double","bool","void","string"]);w.define("IDENTIFIER",/[a-zA-Z_][a-zA-Z0-9_]*/);w.define("STRING_LITERAL",/"(?:\\.|[^\\"])*"/);w.define("STRING_LITERAL",/'(?:\\.|[^\\'])*'/);w.define("FLOAT_LITERAL",/(?:\d*\.\d+)f?/);w.define("DOUBLE_LITERAL",/(?:\d*\.\d+)d?/);w.define("BOOLEAN_LITERAL",/(?:true)|(?:false)/);w.define("INT_LITERAL",/\d+/);w.define("MCCOMMENT_LITERAL",/#[^\n;]+/);w.define("MCCOMMAND_LITERAL",/\/\w[^\n;]+/);for(let n of[";",",",":","{","}","(",")","[","]","."])w.defineString(n,n);w.defineString("COMPOUND_ASSIGNMENT_OPERATOR",["+=","-=","*=","/=","%="]);w.defineString("INC_OPERATOR",["++","--"]);w.defineString("MULTIPLICATIVE_OPERATOR",["*","/","%"]);w.defineString("ADDITIVE_OPERATOR",["+","-"]);w.defineString("RELATIONAL_OPERATOR",["<=",">=","<",">"]);w.defineString("EQUALITY_OPERATOR",["==","!="]);w.defineString("AND_OPERATOR","&&");w.defineString("OR_OPERATOR","||");w.defineString("!","!");w.defineString("=","=");var An=w.build();class A{config;stateStack=[];constructor(n){this.config=n}state(){return this.stateStack[this.stateStack.length-1]||0}reset(){this.stateStack.length=0}next(n,e=[]){let s=e.length,o=[...this.stateStack];while(!0){let r=this.step(n);if(!r){this.stateStack=o,e.length=s;return}if(e.push(r),r.type===A.ActionType.ACCEPT||r.type===A.ActionType.SHIFT)return e}}endOfInput(n=[]){return this.next(this.config.endOfInput,n)}step(n){let s=this.config.actionTable[this.state()]?.get(n);if(!s)return;switch(s.type){case A.ActionType.ACCEPT:return s;case A.ActionType.SHIFT:return this.stateStack.push(s.n),s;case A.ActionType.REDUCE:{let{lhs:o,rhs:{length:r}}=this.config.rules[s.n];this.stateStack.splice(-r,r);let i=this.config.gotoTable[this.state()].get(o);if(i===void 0)return;return this.stateStack.push(i),s}}}}((ts)=>{let n;((r)=>{r[r.SHIFT=0]="SHIFT";r[r.REDUCE=1]="REDUCE";r[r.ACCEPT=2]="ACCEPT"})(n=ts.ActionType||={})})(A||={});class Yn{config;stack=[];map=new Map;constructor(n){this.config=n}reset(){return this.stack=[],this.map=new Map,this}step(n,e){if(n.type===A.ActionType.SHIFT)return this.stack.push(e),!0;else{let{rhs:{length:s}}=this.config.rules[n.n],o=this.stack.splice(-s,s),r=this.config.nodeConstructors[n.n](o);return this.stack.push(r),this.map.set(r,o),!1}}buildTree(n,e){let s=0;for(let o of n)if(this.step(o,e[s]))s++;return this.stack[0]}}class D{define(n,e,s){this._rules.push({lhs:n,rhs:e}),this._nonTerminals.add(n),this._nodes.add(n);for(let o of e)this._nodes.add(o);this._nodeConstructors.push(s||(e.length===1?D.REDUCE_FIRST:D.REDUCE_ARRAY))}defineQuantity(n,e,s){this.define(n,new Array(s).fill(e))}defineZeroOrMore(n,e){this.defineMinQuantity(n,e,0)}defineOneOrMore(n,e){this.defineMinQuantity(n,e,1)}defineMinQuantity(n,e,s){this.defineQuantity(n,e,s),this.define(n,[n,e],([o,r])=>{return o.push(r),o})}defineDelimitedList(n,e,s,o){if(o)this.define(n,[],()=>[]);this.define(n,[e],([r])=>[r]),this.define(n,[n,s,e],([r,,i])=>{return r.push(i),r})}defineTrailingDelimitedList(n,e,s,o,r){this.defineDelimitedList(e,s,o,r),this.define(n,[e,o],D.REDUCE_FIRST),this.define(n,[e],D.REDUCE_FIRST)}buildParserConfig(n,e){let s=[],o=[],r=[this._startItemSet(n)];for(let i=0;i<r.length;i++){let f=r[i],p=new Map;for(let[d,l]of this._nextItemSets(f)){let S=ds(r,l);if(S===-1)S=r.push(l)-1;p.set(d,S)}s[i]=new Map,o[i]=new Map;for(let d of f){let l=this._itemLookahead(d);if(l===void 0){let S=Ln(d),H={type:A.ActionType.REDUCE,n:S};s[i].set(e,H);for(let Cn of this._nodes){if(this._nonTerminals.has(Cn))continue;s[i].set(Cn,H)}if(this._rules[S].lhs===n)s[i].set(e,{type:A.ActionType.ACCEPT,n:S})}else{let S=p.get(l);if(!this._nonTerminals.has(l))s[i].set(l,{type:A.ActionType.SHIFT,n:S});else o[i].set(l,S)}}}return{actionTable:s,gotoTable:o,rules:[...this._rules],endOfInput:e}}buildTreeBuilderConfig(){return{rules:[...this._rules],nodeConstructors:[...this._nodeConstructors]}}buildParser(n,e){return new A(this.buildParserConfig(n,e))}buildTreeBuilder(){return new Yn(this.buildTreeBuilderConfig())}debug_itemString(n){let e=this._rules[Ln(n)],s=zn(n);return e.lhs+" => "+e.rhs.slice(0,s).join(" ")+"."+e.rhs.slice(s).join(" ")}static REDUCE_FIRST=(n)=>n[0];static REDUCE_ARRAY=(n)=>n;static REDUCE_NTH(n){return(e)=>e[n]}_rules=[];_nonTerminals=new Set;_nodes=new Set;_nodeConstructors=[];_itemLookahead(n){return this._rules[Ln(n)].rhs[zn(n)]}_completeClosure(n){for(let e of n){let s=this._itemLookahead(e);if(s===void 0)continue;if(!this._nonTerminals.has(s))continue;for(let o=0;o<this._rules.length;o++)if(this._rules[o].lhs===s)n.add(qn(o,0))}return n}_startItemSet(n){let e=new Set;for(let s=0;s<this._rules.length;s++)if(this._rules[s].lhs===n)e.add(qn(s,0));return this._completeClosure(e)}_nextItemSets(n){let e=new Map;for(let s of n){let o=this._itemLookahead(s);if(!o)continue;let r=e.get(o)||new Set;if(!e.has(o))e.set(o,r);r.add(ps(s))}for(let s of e.values())this._completeClosure(s);return e}}function qn(n,e=0){return`${n}.${e}`}function Ln(n){return parseInt(n.slice(0,n.indexOf(".")))}function zn(n){return parseInt(n.slice(n.indexOf(".")+1))}function ps(n){return qn(Ln(n),zn(n)+1)}function ys(n,e){if(n.size!==e.size)return!1;for(let s of n)if(!e.has(s))return!1;return!0}function ds(n,e){for(let s=0;s<n.length;s++){let o=n[s];if(ys(o,e))return s}return-1}class m{isConst;isFinal;constructor(n=!1,e=!1){this.isConst=n;this.isFinal=e}initialize(n,e,s){if(this.isConst){if(!e.isConst())throw n.semanticError("Cannot initialize a constant with a non constant value");return e.assignToConst(n,this)}if(this.isFinal&&e.isConst())return e.assignToConst(n,this);let o=this.createVariable(n,s);return e.assignToVariable(n,o),o}fullDisplayName(){return(this.isConst?"const ":this.isFinal?"final ":"")+this.displayName()}validateModifiers(n){if(this.isFinal&&this.isConst)throw n.semanticError('Types cannot be declared with both "final" and "const"!')}}class I{async compile(){return this}assignToConst(n,e){throw n.semanticError(`Cannot assign '${this.displayName()}' to '${e.fullDisplayName()}'!`)}assignToVariable(n,e){throw n.semanticError(`Cannot assign '${this.displayName()}' to '${e.displayName()}'!`)}binaryOp(n,e,s){throw n.semanticError(`'${this.displayName()}' ${e} '${s.displayName()}' is not a valid operation!`)}subscript(n,e){throw n.semanticError(`Cannot use '${e.displayName()}' as a subscript of '${this.displayName()}'!`)}member(n,e){throw n.semanticError(`'${e}' is not a member of '${this.displayName()}'!`)}truthy(n){throw n.semanticError(`'${this.displayName()}' cannot be tested for truthiness!`)}subcommand(n){throw n.semanticError(`'${this.displayName()}' cannot be used as an execute-subcommand!`)}invokeFunction(n,e){throw n.semanticError(`'${this.displayName()}' cannot be called as a function!`)}}class Bn extends m{displayName(){return"void"}createVariable(n,e){return new b}isInstance(n){return n instanceof b}}class b extends I{displayName(){return"void"}isConst(){return!0}}var L;((bo)=>{function n(i){return i==="byte"||i==="short"||i==="int"||i==="long"}bo.isInt=n;function e(i){return i==="float"||i==="double"}bo.isDecimal=e;function s(i){return n(i)||e(i)}bo.isNumber=s;function o(i){switch(i){case"byte":return 1;case"short":return 2;case"int":return 3;case"long":return 4;case"float":return 5;case"double":return 6}}bo.specificity=o;function r(i,...f){let p=i;for(let d of f)if(o(d)>o(p))p=d;return p}bo.maxSpecificity=r})(L||={});class Q{displayText(){return this.nbtLiteral()}nbtPointer(n){return n.constantNBT(this.nbtLiteral())}}class t extends Q{value;dataType;constructor(n,e){super();this.value=n;this.dataType=e}nbtLiteral(){return this.value.toString()+this._suffix()}sameAs(n){return n instanceof t&&n.value===this.value&&n.dataType===this.dataType}scorePointer(n){return n.constantScore(this.value)}static double(n){return new t(n,"double")}static equals(n,e){return n instanceof t&&n.value===e}_suffix(){switch(this.dataType){case"byte":return"b";case"short":return"s";case"int":return"";case"long":return"l";case"float":return"f";case"double":return"d"}}}class _e extends Q{value;dataType="string";constructor(n){super();this.value=n}displayText(){return this.nbtLiteral()}sameAs(n){return n instanceof _e&&n.value===this.value}nbtLiteral(){return JSON.stringify(this.value)}}function E(n,e,s){n.appendCommand(`execute store result ${e.executeStoreTarget} ${s.executeStoreValue}`)}class x{executeStoreValue;constructor(n){this.executeStoreValue=n}}class ln{executeStoreTarget;constructor(n){this.executeStoreTarget=n}}var P={};G(P,{setMultipliedScore:()=>Y,setMultipliedNBT:()=>gn,set:()=>Ss,remove:()=>us,executeStoreValue:()=>fn,executeStoreTarget:()=>Sn,copyNBT:()=>_n});class u{sameAs(n){return this.sameTargetAs(n)&&this.dataType===n.dataType}}class c extends u{kind;target;path;dataType;constructor(n,e,s,o){super();this.kind=n;this.target=e;this.path=s;this.dataType=o}clone(){return new c(this.kind,this.target,this.path,this.dataType)}displayText(){return`${this.dataType} nbt ${JSON.stringify(this.kind)} ${JSON.stringify(this.target)} ${JSON.stringify(this.path)}`}nbtPointer(n){return`${this.kind} ${this.target} ${this.path}`}sameTargetAs(n){return n instanceof c&&this.kind===n.kind&&this.target===n.target&&this.path===n.path}isTemporary(){return!1}isStatic(){return this.target==="storage"}isLocallyStatic(){if(this.isStatic())return!0;if(this.kind==="entity"&&ls.has(this.target))return!0;return!1}}class wn extends u{name;dataType;constructor(n,e){super();this.name=n;this.dataType=e}clone(){return new wn(this.name,this.dataType)}displayText(){return this.name}nbtPointer(n){return n.internalNBT(this.name)}sameTargetAs(n){return n instanceof wn&&this.name===n.name}isTemporary(){return!0}isStatic(){return!0}isLocallyStatic(){return!0}}var ls=new Set(["@a","@p","@s","@e"]);class R{dataType="int";sameAs(n){return this.sameTargetAs(n)}}class nn extends R{objective;target;constructor(n,e){super();this.objective=n;this.target=e}scorePointer(){return this.target+" "+this.objective}displayText(){return`score ${JSON.stringify(this.objective)} ${JSON.stringify(this.target)}`}isTemporary(){return!1}sameTargetAs(n){return n instanceof nn&&this.objective===n.objective&&this.target===n.target}isStatic(){return this.target[0]!=="@"}isLocallyStatic(){if(this.isStatic())return!0;return ws.has(this.target)}}class $n extends R{name;constructor(n){super();this.name=n}scorePointer(n){return n.internalScore(this.name)}displayText(){return`score ${this.name}`}isTemporary(){return!0}sameTargetAs(n){return n instanceof $n&&this.name===n.name}isStatic(){return!0}isLocallyStatic(){return!0}}var ws=new Set(["@a","@p","@s","@e"]);class g{lhs;op;rhs;constructor(n,e,s){this.lhs=n;this.op=e;this.rhs=s}displayText(){return`${this.lhs.displayText()} ${this.op} ${this.rhs.displayText()}`}}((Io)=>{function n(o){return o instanceof R||o instanceof u||o instanceof t}Io.isOperand=n;function e(o,r,i){switch(r){case"+":return o+i;case"-":return o-i;case"*":return o*i;case"/":return o/i;case"%":return o%i}}Io.calc=e;function s(o,r,i){let f=L.maxSpecificity(o.dataType,i.dataType);return new t(e(o.value,r,i.value),f)}Io.calcNumberConstant=s})(g||={});var W={};G(W,{writeScaledScore:()=>q,setMultipliedNBT:()=>Tn,set:()=>Ts,removeObjective:()=>bs,operation:()=>a,getScaledScoreOrNumber:()=>J,executeStoreValue:()=>xn,executeStoreTarget:()=>rn,createObjective:()=>gs});function De(n,e,s){if(s.op==="*"&&s.rhs instanceof t){if(s.lhs instanceof u)return Tn(n,e,s.lhs,s.rhs.value)}if(s.op==="/"&&s.rhs instanceof t){if(s.lhs instanceof u)return Tn(n,e,s.lhs,1/s.rhs.value)}if(!e.sameTargetAs(s.rhs))Ie(n,e,s);else{let o=n.ac();Ie(n,o,s),a(n,e,"=",o)}}function He(n,e,s){if(s.op==="*"&&s.rhs instanceof t){if(s.lhs instanceof u)return gn(n,e,s.lhs,s.rhs.value);if(s.lhs instanceof R)return Y(n,e,s.lhs,s.rhs.value)}if(s.op==="/"&&s.rhs instanceof t){if(s.lhs instanceof u)return gn(n,e,s.lhs,1/s.rhs.value);if(s.lhs instanceof R)return Y(n,e,s.lhs,1/s.rhs.value)}let o=L.isNumber(s.lhs.dataType)?n.resolutionOf(s.lhs.dataType):1,r=L.isNumber(s.lhs.dataType)?n.resolutionOf(s.lhs.dataType):1,i=Math.max(o,r),f=n.ac();switch(s.op){case"+":case"-":case"%":{q(n,f,s.lhs,i);let p=J(n,s.rhs,i);a(n,f,s.op,p),Y(n,e,f,1/i);break}case"*":{q(n,f,s.lhs,o);let p=J(n,s.rhs,r);a(n,f,s.op,p),Y(n,e,f,1/(o*r));break}case"/":{q(n,f,s.lhs,o*r);let p=J(n,s.rhs,r);a(n,f,s.op,p),Y(n,e,f,1/o);break}}}function Ie(n,e,s){let o=L.isNumber(s.lhs.dataType)?n.resolutionOf(s.lhs.dataType):1,r=L.isNumber(s.lhs.dataType)?n.resolutionOf(s.lhs.dataType):1,i=Math.max(o,r);switch(s.op){case"+":case"-":case"%":{q(n,e,s.lhs,i);let f=J(n,s.rhs,i);a(n,e,s.op,f),a(n,e,"/",t.double(i));break}case"*":{q(n,e,s.lhs,o);let f=J(n,s.rhs,r);a(n,e,s.op,f),a(n,e,"/",t.double(r*o));break}case"/":{q(n,e,s.lhs,i);let f=J(n,s.rhs,i);a(n,e,s.op,f);break}}}var en={};G(en,{writeToScore:()=>jn,writeToNBT:()=>vn,subcommand:()=>bn,executeStoreValue:()=>mn,compareScoreSubcommand:()=>Oe});function jn(n,e,s){E(n,rn(n,e),mn(n,s))}function vn(n,e,s){E(n,Sn(n,e,1),mn(n,s))}function bn(n,e){let s=Math.max(n.resolutionOf(e.lhs.dataType),n.resolutionOf(e.rhs.dataType)),o=J(n,e.lhs,s),r=J(n,e.rhs,s);return Oe(n,o,e.op,r)}function mn(n,e){return new x(bn(n,e))}function Oe(n,e,s,o){let r=e.scorePointer(n);if(o instanceof t){let i=o.value|0;switch(s){case"<":return`if score ${r} matches ..${i-1}`;case"<=":return`if score ${r} matches ..${i}`;case">":return`if score ${r} matches ${i+1}..`;case">=":return`if score ${r} matches ${i}..`;case"==":return`if score ${r} matches ${i}`;case"!=":return`unless score ${r} matches ${i}`}}else{let i=o.scorePointer(n);if(s==="!=")return`unless score ${r} = ${i}`;return`if score ${r} ${s==="=="?"=":s} ${i}`}}function Ts(n,e,s){if(s instanceof g)return De(n,e,s);if(s instanceof T)return jn(n,e,s);if(s instanceof R)return a(n,e,"=",s);if(s instanceof Q||s instanceof u){if(s instanceof t)return a(n,e,"=",s);return Tn(n,e,s,1)}}function gs(n,e,s){n.appendCommand(`scoreboard objectives add ${e} dummy ${JSON.stringify(s)}`)}function bs(n,e){n.appendCommand(`scoreboard objectives remove ${e}`)}function a(n,e,s,o){if(e.sameTargetAs(o))return;if(s==="+"||s==="-"){if(t.equals(o,0))return}if(s==="*"||s==="/"){if(t.equals(o,1))return}if(o instanceof t&&o.value<0)switch(s){case"+":return a(n,e,"-",t.double(-o.value));case"-":return a(n,e,"+",t.double(-o.value))}if(o instanceof t&&-1<o.value&&o.value<1)switch(s){case"*":return a(n,e,"/",t.double(1/o.value));case"/":return a(n,e,"*",t.double(1/o.value))}let r=e.scorePointer(n);if(o instanceof t){let p=Math.round(o.value);switch(s){case"=":return n.appendCommand(`scoreboard players set ${r} ${p}`);case"+":return n.appendCommand(`scoreboard players add ${r} ${p}`);case"-":return n.appendCommand(`scoreboard players remove ${r} ${p}`)}}let i=o.scorePointer(n),f=s==="="?"=":s+"=";return n.appendCommand(`scoreboard players operation ${r} ${f} ${i}`)}function Tn(n,e,s,o){E(n,rn(n,e),fn(n,s,o))}function J(n,e,s){if(e instanceof R){if(s===1)return e;let o=n.ac();return a(n,o,"=",e),a(n,o,"*",t.double(s)),o}if(e instanceof u){let o=n.ac();return E(n,rn(n,o),fn(n,e,s)),o}return t.double(e.value*s)}function q(n,e,s,o){if(s instanceof R)a(n,e,"=",s),a(n,e,"*",t.double(o));if(s instanceof u)E(n,rn(n,e),fn(n,s,o));if(s instanceof t)a(n,e,"=",t.double(s.value*o))}function rn(n,e){return new ln(`score ${e.scorePointer(n)}`)}function xn(n,e){return new x(`run scoreboard players get ${e.scorePointer(n)}`)}function Ss(n,e,s){if(s instanceof g)return He(n,e,s);if(s instanceof T)return vn(n,e,s);if(s instanceof R)return Y(n,e,s,1);if(s instanceof Q){if(L.isNumber(e.dataType)&&s instanceof t)return _n(n,e,new t(s.value,e.dataType));return _n(n,e,s)}if(s instanceof u){if(e.dataType!==s.dataType){if(L.isNumber(e.dataType)&&L.isNumber(s.dataType))return gn(n,e,s,1)}return _n(n,e,s)}}function gn(n,e,s,o){let r=n.resolutionOf(s.dataType),i=Sn(n,e,1/r),f=fn(n,s,r*o);E(n,i,f)}function Y(n,e,s,o){let r=Sn(n,e,o),i=xn(n,s);E(n,r,i)}function _n(n,e,s){if(s instanceof Q)n.appendCommand(`data modify ${e.nbtPointer(n)} set value ${s.nbtLiteral()}`);else{if(e.sameTargetAs(s))return;n.appendCommand(`data modify ${e.nbtPointer(n)} set from ${s.nbtPointer(n)}`)}}function us(n,e){n.appendCommand(`data remove ${e.nbtPointer(n)}`)}function Sn(n,e,s){return new ln(`${e.nbtPointer(n)} ${e.dataType} ${s}`)}function fn(n,e,s){return new x(`run data get ${e.nbtPointer(n)} ${s}`)}var In={};G(In,{subcommand:()=>Rs});function Rs(n,e){if(e instanceof V)return e.command;if(e instanceof T)return bn(n,e);return bn(n,new T(e,"!=",new t(0,"int")))}class T{lhs;op;rhs;constructor(n,e,s){this.lhs=n;this.op=e;this.rhs=s}displayText(){return this.lhs.displayText()+" "+this.op+" "+this.rhs.displayText()}subcommand(n){return en.subcommand(n,this)}flip(){switch(this.op){case"<":return new T(this.rhs,">",this.lhs);case">":return new T(this.rhs,"<",this.lhs);case"<=":return new T(this.rhs,">=",this.lhs);case">=":return new T(this.rhs,"<=",this.lhs);case"==":return new T(this.rhs,"==",this.lhs);case"!=":return new T(this.rhs,"!=",this.lhs)}}}((ir)=>{function n(o){return o instanceof R||o instanceof u||o instanceof t}ir.isOperand=n;function e(o,r,i){switch(r){case"<":return+(o<i);case"<=":return+(o<=i);case"==":return+(o===i);case">=":return+(o>=i);case">":return+(o>i);case"!=":return+(o!=i)}}ir.calc=e;function s(o,r,i){return new t(e(o.value,r,i.value),"byte")}ir.calcNumberConstant=s})(T||={});class C{subcommands;branch;constructor(n,e){this.subcommands=n;this.branch=e}clone(){return new C([...this.subcommands],this.branch)}displayText(){return`execute (${this.subcommands.map((n)=>n.displayText()).join(" && ")}) ${JSON.stringify(this.branch)}`}generate(n){let e=this.subcommands.map((o)=>In.subcommand(n,o)).join(" "),s=n.generation.generate(this.branch);if(!e)n.appendCommand(s);else n.appendCommand(`execute ${e} run ${s}`)}}var cn;((lr)=>{function n(e){return e instanceof T||e instanceof V||e instanceof R||e instanceof u||e instanceof t}lr.isSubcommand=n})(cn||={});class K{command;constructor(n){this.command=n}displayText(){if(this.command[0]==="#")return this.command;return"/"+this.command}isComment(){return this.command[0]==="#"}generate(n){n.appendCommand(this.command)}}class V{command;constructor(n){this.command=n}displayText(){return JSON.stringify(this.command)}subcommand(n){return this.command}}class F{lhs;rhs;constructor(n,e){this.lhs=n;this.rhs=e}displayText(){if(this.rhs instanceof g&&this.lhs.sameTargetAs(this.rhs.lhs))return this.lhs.displayText()+" "+this.rhs.op+"= "+this.rhs.rhs.displayText();return this.lhs.displayText()+" = "+this.rhs.displayText()}generate(n){if(this.lhs instanceof u)P.set(n,this.lhs,this.rhs);else W.set(n,this.lhs,this.rhs)}}var k;((ur)=>{function n(o,r){if(o instanceof R)return o.sameTargetAs(r);if(o instanceof u)return o.sameTargetAs(r);if(o instanceof g)return n(o.lhs,r)||n(o.rhs,r);if(o instanceof T)return n(o.lhs,r)||n(o.rhs,r);return!1}ur.contains=n;function e(o){return o instanceof T||o instanceof g}ur.movable=e;function s(o){if(o instanceof R)return[o];if(o instanceof u)return[o];if(o instanceof g)return[...s(o.lhs),...s(o.rhs)];if(o instanceof T)return[...s(o.lhs),...s(o.rhs)];return[]}ur.getReferences=s})(k||={});class On{config;constructor(n){this.config=n}branches=new Map;clone(){let n=new On(this.config);for(let[e,s]of this.branches)n.branches.set(e,[...s]);return n}generate(){let n=new he(this);for(let[e]of this.branches)n.generate(e);return n}canInline(n){return n[0]==="_"}}class he{program;constructor(n){this.program=n}constantScores=new Set;constantNBTs=new Map;acs=new Set;generated=new Map;usesInternalScoreboard=!1;files(){let n=new Map;for(let[e,s]of this.mcfunctions()){let[o,r]=e.split(":"),i=`data/${o}/functions/${r}.mcfunction`;n.set(i,s.join(` `))}return n}mcfunctions(){let n=new Map;for(let[i,f]of this.generated){if(this.canInline(i,f))continue;n.set(this.branchNamespacedId(i),[...f])}let e=this.program.config.initializer,s=n.get(e)??[];n.set(e,[...this.initializer(),...s]);let o=this.program.config.destructor,r=n.get(o)??[];return n.set(o,[...r,...this.destructor()]),n}initializer(){let n=new Hn(this,[]);if(this.usesInternalScoreboard)W.createObjective(n,this.program.config.mainScoreboard,"INTERNAL");for(let e of this.constantScores){let s=new nn(this.program.config.mainScoreboard,"C_"+e);W.operation(n,s,"=",t.double(e))}return n.out}destructor(){let n=new Hn(this,[]);if(this.usesInternalScoreboard)W.removeObjective(n,this.program.config.mainScoreboard);return P.remove(n,new c("storage",this.program.config.mainNBTStorage,"variables","int")),n.out}generate(n){if(!this.generated.has(n)){let s=this.program.branches.get(n);if(!s)return"function "+this.branchNamespacedId(n);this.generated.set(n,[]);let o=new Hn(this,[]);for(let r of s)r.generate(o),this.acs.clear();this.generated.set(n,o.out)}let e=this.generated.get(n);if(e&&this.canInline(n,e))return e[0];return"function "+this.branchNamespacedId(n)}canInline(n,e){return e.length===1&&e[0][0]!=="#"&&this.program.canInline(n)}branchNamespacedId(n){return n[0]==="_"?n.slice(1):n}}class Hn{generation;out;constructor(n,e){this.generation=n;this.out=e}appendCommand(n){this.out.push(n)}constantScore(n){this.generation.usesInternalScoreboard=!0;let e=n|0;this.generation.constantScores.add(e);let s="C_"+e,o=this.generation.program.config.mainScoreboard;return`${s} ${o}`}internalScore(n){this.generation.usesInternalScoreboard=!0;let e="variables."+n,s=this.generation.program.config.mainScoreboard;return`${e} ${s}`}constantNBT(n){let e=this.generation.program.config.mainNBTStorage,s=this.generation.constantNBTs.get(n)??`constants.${this.generation.constantNBTs.size}`;return this.generation.constantNBTs.set(n,s),`storage ${e} ${s}`}internalNBT(n){let e=this.generation.program.config.mainNBTStorage,s="variables."+n;return`storage ${e} ${s}`}resolutionOf(n){switch(n){case"byte":case"short":case"int":case"long":return 1;case"float":return this.generation.program.config.floatResolution;case"double":return this.generation.program.config.doubleResolution}return 1}ac(){this.generation.usesInternalScoreboard=!0;let n="AC",e=0;while(this.generation.acs.has(n))n="AC_"+e++;return this.generation.acs.add(n),new nn(this.generation.program.config.mainScoreboard,n)}}class ne{children;constructor(n){this.children=n}async compile(n){for(let e of this.children)await e.compile(n);return new b}}class ee{condition;then;constructor(n,e){this.condition=n;this.then=e}async compile(n){let e=new X(n.compilation,n.moduleURI,n.compilation.suggestBranchName("branch"),n.symbolTable),s=await this.condition.compile(n);return n.appendCommand(new C([s.truthy(n)],e.branchName)),await this.then.compile(e),new b}}class hn{subcommand;then;constructor(n,e){this.subcommand=n;this.then=e}async compile(n){let e=new X(n.compilation,n.moduleURI,n.compilation.suggestBranchName("branch"),n.symbolTable),s=await this.subcommand.compile(n);return n.appendCommand(new C([s.subcommand(n)],e.branchName)),await this.then.compile(e),new b}}class tn{init;condition;afterthought;then;doWhile;constructor(n,e,s,o,r){this.init=n;this.condition=e;this.afterthought=s;this.then=o;this.doWhile=r}async compile(n){let e=new X(n.compilation,n.moduleURI,n.compilation.suggestBranchName("branch"),n.symbolTable);n.symbolTable.enterScope();{await this.init.compile(n);let s=this.doWhile?[]:[(await this.condition.compile(n)).truthy(n)];n.appendCommand(new C(s,e.branchName))}{await this.then.compile(e),await this.afterthought.compile(e);let s=[(await this.condition.compile(e)).truthy(e)];e.appendCommand(new C(s,e.branchName))}return n.symbolTable.exitScope(),new b}}class Nn{command;constructor(n){this.command=n}async compile(n){return n.appendCommand(new K(this.command)),new b}}class se extends I{members;constructor(n){super();this.members=n}isConst(){return!1}displayName(){return"namespace"}member(n,e){let s=this.members.get(e);if(s)return s;return super.member(n,e)}}class un{unused=new Map;constructor(n){this.unused=new Map(n)}use(n){let e=this.unused.get(n);return this.unused.delete(n),e}}class oe extends I{parameters;returnValue;returnType;branchName;constructor(n,e,s,o){super();this.parameters=n;this.returnValue=e;this.returnType=s;this.branchName=o}displayName(){return"function"}isConst(){return!1}invokeFunction(n,e){let s=new un(e);for(let[o,r]of this.parameters){let i=s.use(o);if(!i)throw n.semanticError(`Parameter "${o}" is required for this function.`);i.assignToVariable(n,r)}for(let[o]of s.unused)throw n.semanticError(`Undefined function parameter was provided at position '${o}'.`);return n.appendCommand(new C([],this.branchName)),this.returnType.initialize(n,this.returnValue,{preferredName:"returnValueCopy"})}}class Jn{child;constructor(n){this.child=n}async compile(n){n.symbolTable.enterScope();let e=await this.child.compile(n);return n.symbolTable.exitScope(),e}}class re{name;constructor(n){this.name=n}async compile(n){let e=n.symbolTable.get(this.name);if(!e)throw n.semanticError(`"${this.name}" is undefined.`);return e}}class ie{name;value;constructor(n,e){this.name=n;this.value=e}async compile(n){let e=await this.value.compile(n);if(n.symbolTable.hasInScope(this.name))throw n.semanticError(`"${this.name}" is already defined in this scope.`);return n.symbolTable.set(this.name,e),new b}}class fe{namespacedId;block;constructor(n,e){this.namespacedId=n;this.block=e}async compile(n){let e=h.lint(this.namespacedId);if(e)n.compilation.compiler.console.warn(e);let s=new X(n.compilation,n.moduleURI,this.namespacedId,n.symbolTable);return await this.block.compile(s),new b}}class Wn{uri;namespace;constructor(n,e){this.uri=n;this.namespace=e}async compile(n){if(!n.symbolTable.isGlobal())throw n.semanticError("Import statements can only be used on the top-level.");let e=n.moduleURI.clone().appendString(this.uri);if(!e)n.semanticError(`"${this.uri}" is not a valid path.`);let s=await n.compilation.importModule(e,n.branchName);if(this.namespace){if(n.symbolTable.hasInScope(this.namespace))throw n.semanticError(`"${this.namespace}" is already declared in this scope.`);n.symbolTable.set(this.namespace,new se(s.exports))}return new b}}class te{identifier;value;constructor(n,e){this.identifier=n;this.value=e}async compile(n){if(!n.symbolTable.isGlobal())throw n.semanticError("Export statements can only be used on the top-level.");let e=n.currentModule();if(e.exports.has(this.identifier))throw n.semanticError(`"${this.identifier}" is already declared as an exported.`);return e.exports.set(this.identifier,await this.value.compile(n)),new b}}class pe{type;identifier;value;constructor(n,e,s){this.type=n;this.identifier=e;this.value=s}async compile(n){if(n.symbolTable.hasInScope(this.identifier))throw n.semanticError(`"${this.identifier}" is already declared in this scope.`);this.type.validateModifiers(n);let e=await this.value.compile(n),s=this.type.initialize(n,e,{preferredName:this.identifier});return n.symbolTable.set(this.identifier,s),s}}class ye{type;name;parameters;block;constructor(n,e,s,o){this.type=n;this.name=e;this.parameters=s;this.block=o}async compile(n){let e=new Map;for(let[r,i]of this.parameters){let f=i.type.createVariable(n,{preferredName:i.name});n.symbolTable.set(i.name,f),e.set(r,f)}let s=this.type.createVariable(n,{preferredName:"returnValue"}),o=new X(n.compilation,n.moduleURI,n.compilation.suggestBranchName("branch"),n.symbolTable);return n.symbolTable.set(this.name,new oe(e,s,this.type,o.branchName)),n.symbolTable.enterScope(),n.symbolTable.set("*return",s),await this.block.compile(o),n.symbolTable.exitScope(),new b}}class de{type;name;constructor(n,e){this.type=n;this.name=e}}class le{value;constructor(n){this.value=n}async compile(n){let e=await this.value.compile(n),s=n.symbolTable.get("*return");if(!s)throw n.semanticError("Return statements can only be used inside functions!");return e.assignToVariable(n,s),new b}}class $ extends m{dataType;constructor(n){super();this.dataType=n}displayName(){return this.minecraftName()}minecraftName(){return this.dataType}isInstance(n){return n instanceof M&&n.type.dataType===this.dataType}createVariable(n,e){let s=n.compilation.createUniqueName(e.preferredName);if(L.isDecimal(this.dataType))return new M(this,new wn(s,this.dataType));else return new M(this,new $n(s))}}class M extends I{type;value;constructor(n,e){super();this.type=n;this.value=e}static constant(n,e){return new M(new $(n),new t(e,n))}displayName(){return this.type.fullDisplayName()}isConst(){return this.value instanceof t}assignToConst(n,e){if(e instanceof $)return this;return super.assignToConst(n,e)}assignToVariable(n,e){let s=this;if(e instanceof M){if(e instanceof t)throw n.semanticError("Cannot assign to a 'const' number!");n.appendCommand(new F(e._toVariableMIL(),s._toMIL()));return}return super.assignToVariable(n,e)}binaryOp(n,e,s){let o=s instanceof M?L.maxSpecificity(this.type.dataType,s.type.dataType):this.type.dataType,r=new $(o),i=new $(o);i.isFinal=!0;let f=r.initialize(n,this,{preferredName:"binaryOp"}),p=i.initialize(n,s,{preferredName:"binaryOpRhs"});switch(e){case"<":case">":case"<=":case">=":case"==":case"!=":{let d=new T(f._toMIL(),e,p._toMIL());return n.appendCommand(new F(f._toVariableMIL(),d)),f}case"+":case"-":case"%":case"*":case"/":{let d=new g(f._toMIL(),e,p._toMIL());return n.appendCommand(new F(f._toVariableMIL(),d)),f}}return super.binaryOp(n,e,s)}truthy(n){return new T(this._toMIL(),"!=",new t(0,"int"))}_toMIL(){if(this.value instanceof R)return this.value;if(this.value instanceof u){let n=this.value.clone();return n.dataType=this.type.dataType,n}return new t(this.value.value,this.type.dataType)}_toVariableMIL(){return this._toMIL()}}class z{lhs;op;rhs;constructor(n,e,s){this.lhs=n;this.op=e;this.rhs=s}async compile(n){let e=await this.lhs.compile(n),s=await this.rhs.compile(n);return e.binaryOp(n,this.op,s)}static negative(n){return new z(M.constant("int",0),"-",n)}static not(n){return new z(n,"!=",M.constant("int",0))}}class Z{lhs;op;rhs;constructor(n,e,s){this.lhs=n;this.op=e;this.rhs=s}async compile(n){if(this.op!=="=")return new Z(this.lhs,"=",new z(this.lhs,this.op[0],this.rhs)).compile(n);let e=await this.lhs.compile(n);return(await this.rhs.compile(n)).assignToVariable(n,e),e}static inc(n){return new Z(n,"+=",M.constant("int",1))}static dec(n){return new Z(n,"-=",M.constant("int",1))}}class we{value;member;constructor(n,e){this.value=n;this.member=e}async compile(n){return(await this.value.compile(n)).member(n,this.member)}}class Te{value;parameters;constructor(n,e){this.value=n;this.parameters=e}async compile(n){let e=await this.value.compile(n),s=new Map;for(let[o,r]of this.parameters){let i=await r.compile(n);s.set(o,i)}return e.invokeFunction(n,s)}}class ge{type;value;constructor(n,e){this.type=n;this.value=e}async compile(n){this.type.validateModifiers(n);let e=await this.value.compile(n);return this.type.initialize(n,e,{preferredName:"TypeCastResult"})}}class Kn extends m{displayName(){return"string"}createVariable(n,e){throw n.semanticError('String types must be declared with "const"!')}}class B extends I{value;constructor(n){super();this.value=n}displayName(){return"const string"}isConst(){return!0}assignToConst(n,e){if(e instanceof Kn)return this;return super.assignToConst(n,e)}binaryOp(n,e,s){if(s instanceof B){if(e==="+")return new B(this.value+s.value)}return super.binaryOp(n,e,s)}subscript(n,e){return super.subscript(n,e)}subcommand(){return new V(this.value)}}class be{objective;player;constructor(n,e){this.objective=n;this.player=e}async compile(n){let e=j.lintObjective(this.objective);if(e)n.compilation.compiler.console.warn(e);return new M(new $("int"),new nn(this.objective,this.player))}}class Se{type;kind;target;path;constructor(n,e,s,o){this.type=n;this.kind=e;this.target=s;this.path=o}async compile(n){let e=Mn.lint(this.kind,this.target);if(e)n.compilation.compiler.console.warn(e);let s=new c(this.kind,this.target,this.path,"int");if(this.type instanceof $)return new M(this.type,s);throw n.semanticError("NBT pointers only support numbers currently.")}}var y=new D;y.define("string",["STRING_LITERAL"],([n])=>as(n));y.define("int",["INT_LITERAL"],([n])=>parseInt(n));y.define("float",["FLOAT_LITERAL"],([n])=>parseFloat(n));y.define("boolean",["BOOLEAN_LITERAL"],([n])=>n==="true");y.defineZeroOrMore("statement*","statement");y.define("statement*",["statement*",";"],D.REDUCE_FIRST);y.define("block",["statement*"],([n])=>{return new ne(n)});y.define("statement",["MCCOMMENT_LITERAL"],([n])=>{return new Nn(n)});y.define("statement",["MCCOMMAND_LITERAL"],([n])=>{return new Nn(n.slice(1))});y.define("statement",["IMPORT","string"],([,n])=>{return new Wn(n,void 0)});y.define("statement",["IMPORT","string","AS","IDENTIFIER"],([,n,,e])=>{return new Wn(n,e)});y.define("statement",["ALIAS","IDENTIFIER","complete_expression"],([,n,e])=>{return new ie(n,e)});y.define("statement",["MCFUNCTION","string","{","block","}"],([,n,,e])=>{return new fe(n,new Jn(e))});y.define("statement",["FOR","(","terminated_statement","terminated_statement","complete_expression",")","statement"],([,,n,e,s,,o])=>{return new tn(n,e,s,o,!1)});y.define("statement",["FOR","(","terminated_statement","terminated_statement",")","statement"],([,,n,e,,s])=>{return new tn(n,e,new b,s,!1)});y.define("statement",["WHILE","(","complete_expression",")","statement"],([,,n,,e])=>{return new tn(new b,n,new b,e,!1)});y.define("statement",["DO","(","complete_expression",")","WHILE","statement"],([,,n,,,e])=>{return new tn(new b,n,new b,e,!0)});y.define("statement",["IF","(","complete_expression",")","statement"],([,,n,,e])=>{return new ee(n,e)});y.define("statement",["EXECUTE","(","complete_expression",")","statement"],([,,n,,e])=>{return new hn(n,e)});y.define("statement",["EXECUTE","string","statement"],([,n,e])=>{return new hn(new B(n),e)});y.define("statement",["complete_expression"],D.REDUCE_FIRST);y.define("statement",["{","block","}"],([,n])=>{return new Jn(n)});y.define("statement",["variable_declaration"],D.REDUCE_FIRST);y.define("statement",["EXPORT","variable_declaration"],([,n])=>{return new te(n.identifier,n)});y.define("variable_declaration",["type","IDENTIFIER","=","complete_expression"],([n,e,,s])=>{return new pe(n,e,s)});y.define("parameter_declaration",["type","IDENTIFIER"],([n,e])=>{return new de(n,e)});y.defineTrailingDelimitedList("parameter_declaration_list","parameter_declaration_non_terminated","parameter_declaration",",",!0);y.define("statement",["type","IDENTIFIER","(","parameter_declaration_list",")","{","block","}"],([n,e,,s,,,o])=>{return new ye(n,e,new Map(s.entries()),o)});y.define("statement",["RETURN","complete_expression"],([,n])=>{return new le(n)});y.define("terminated_statement",["statement",";"],D.REDUCE_FIRST);y.define("complete_expression",["or_expression"]);y.define("complete_expression",["or_expression","=","complete_expression"],([n,,e])=>new Z(n,"=",e));y.define("complete_expression",["or_expression","COMPOUND_ASSIGNMENT_OPERATOR","complete_expression"],([n,e,s])=>new Z(n,e,s));var pn=([n,e,s])=>new z(n,e,s);y.define("or_expression",["and_expression"]);y.define("or_expression",["or_expression","OR_OPERATOR","and_expression"],pn);y.define("and_expression",["equality_expression"]);y.define("and_expression",["and_expression","AND_OPERATOR","equality_expression"],pn);y.define("equality_expression",["relational_expression"]);y.define("equality_expression",["equality_expression","EQUALITY_OPERATOR","relational_expression"],pn);y.define("relational_expression",["additive_expression"]);y.define("relational_expression",["relational_expression","RELATIONAL_OPERATOR","additive_expression"],pn);y.define("additive_expression",["multiplicative_expression"]);y.define("additive_expression",["additive_expression","ADDITIVE_OPERATOR","multiplicative_expression"],pn);y.define("multiplicative_expression",["unary_expression"]);y.define("multiplicative_expression",["multiplicative_expression","MULTIPLICATIVE_OPERATOR","unary_expression"],pn);y.define("unary_expression",["primary_expression"]);y.define("unary_expression",["ADDITIVE_OPERATOR","unary_expression"],([n,e])=>{if(n==="+")return e;if(n==="-")return z.negative(e);throw new Error(`EMCL Parser: Unsupported prefix op "${n}".`)});y.define("unary_expression",["!","unary_expression"],([n,e])=>{return z.not(e)});y.define("unary_expression",["INC_OPERATOR","unary_expression"],([n,e])=>{if(n==="++")return Z.inc(e);if(n==="--")return Z.dec(e);throw new Error(`EMCL Parser: Unsupported prefix op "${n}".`)});y.define("primary_expression",["(","complete_expression",")"],D.REDUCE_NTH(1));y.define("primary_expression",["IDENTIFIER"],([n])=>new re(n));y.define("primary_expression",["string"],([n])=>new B(n));y.define("primary_expression",["int"],([n])=>M.constant("int",n));y.define("primary_expression",["float"],([n])=>M.constant("float",n));y.define("primary_expression",["primary_expression",".","IDENTIFIER"],([n,,e])=>{return new we(n,e)});y.define("primary_expression",["(","type",")","primary_expression"],([,n,,e])=>{return new ge(n,e)});y.define("primary_expression",["SCORE","string","string"],([,n,e])=>{return new be(n,e)});y.define("primary_expression",["type","NBT","string","string","string"],([n,,e,s,o])=>{return new Se(n,e,s,o)});y.defineTrailingDelimitedList("parameter_list","parameter_list_non_trailing","complete_expression",",",!0);y.define("primary_expression",["primary_expression","(","parameter_list",")"],([n,,e])=>{return new Te(n,new Map(e.entries()))});y.define("type",["CONST","type"],([,n])=>{return n.isConst=!0,n});y.define("type",["FINAL","type"],([,n])=>{return n.isFinal=!0,n});y.define("type",["TYPE"],([n])=>{if(n==="byte"||n==="uint8")return new $("byte");if(n==="short"||n==="uint16")return new $("short");if(n==="int"||n==="uint32")return new $("int");if(n==="long"||n==="uint64")return new $("long");if(n==="float")return new $("float");if(n==="double")return new $("double");if(n==="string")return new Kn;if(n==="void")return new Bn;throw new Error(`EMCL Parser: Unsupported type "${n}"`)});var Rn=y.buildParser("block","<EOI>"),ue=y.buildTreeBuilder();function as(n){return n.slice(1,n.length-1).replace(/\\(u[0-9a-fA-F]{4}|[^u])/,(e,s)=>{let o=s.charAt(0);if(o==="u")return String.fromCharCode(parseInt(s.slice(1),16));switch(o){case"b":return"\b";case"f":return"\f";case"n":return` `;case"r":return"\r";case"t":return"\t";default:return o}})}var Fs=new Set(["COMMENT","WHITESPACE"]);function Ne(n,e){An.reset(),Rn.reset(),ue.reset();let s=sn.joinAdjacentTokens(An.tokenize(n),"ILLEGAL"),o=sn.getTokensMap(s),r={source:n,tokens:s,tokenMap:o,lexicalErrors:[],syntaxError:[],treeBuilderError:[],ast:void 0},i=[];for(let[p,d]of s.entries())if(d.type==="ILLEGAL"){let l=o.get(d);r.lexicalErrors.push(new Je(p,l))}else if(!Fs.has(d.type))i.push(d);let f=[];for(let p of i)if(!Rn.next(p.type,f)){let d=o.get(p),l=`Syntax Error: Unexpected token "${p.value}" at: line ${d.line+1} char ${d.char+1} file: ${e}`;return r.syntaxError.push(new Re(l,s.indexOf(p))),r}if(!Rn.endOfInput(f))return r.syntaxError.push(new Re("Syntax Error: Unexpected end of inpu