-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli
executable file
·2 lines (2 loc) · 2.92 KB
/
cli
1
2
#!/usr/bin/env node
const g=e=>console.log(e),maka={run(code){maka.tape=[new this.Cell("str","")];const locale=code.split("\n")[0],stringRegex=/[‘’`"'「«].*[»」'"`“”‘’]/g;locale in maka.locales||maka.throw(`🗣 "${locale}" = ❓`),code=code.split("\n").slice(1);for(let lnNo=0;lnNo<code.length;lnNo++){const line=code[lnNo].trim();Object.keys(maka.locales[locale]).forEach(item=>{"function"!=typeof maka.locales[locale][item]&&maka.locales[locale][item].test(line.replace(stringRegex,"%%"))&&(console.log(item),maka.abilities[item]((line.match(/".*"/)??[]).map(e=>e.slice(1,-1)),e=>eval(e)))})}return maka.tape},locales:{db:{strToNum(str){return parseFloat(str)},numToStr(num){return num+""}}},labels:{},abilities:{label([name],e){maka.labels[name]=e("lnNo")},nextCell(){maka.ptr++,void 0===maka.tape[maka.ptr]&&(maka.tape[maka.ptr]=new maka.Cell("str",""))},prevCell(){maka.ptr--,void 0===maka.tape[maka.ptr]&&(maka.tape[maka.ptr]=new maka.Cell("str",""))},addNum([name],e){maka.tape[maka.ptr].type="num",maka.tape[maka.ptr].value=maka.tape[maka.ptr].value+maka.locales[e("locale")].strToNum(name)},appendStr([str]){maka.tape[maka.ptr].type="str",maka.tape[maka.ptr].value=String(maka.tape[maka.ptr].value)+String(str)},prependStr([str]){maka.tape[maka.ptr].type="str",maka.tape[maka.ptr].value=String(str)+String(maka.tape[maka.ptr])},jump([label],e){maka.tape[maka.ptr].value&&e("lnNo="+maka.labels[label])},emptyStr(){maka.tape[maka.ptr].type="str",maka.tape[maka.ptr].value=""},printCell(_,e){e="num"==maka.tape[maka.ptr].type?e("maka.locales[locale].numToStr")(maka.tape[maka.ptr].value):maka.tape[maka.ptr].value;console.log(e)},printText([text]){console.log(text)},setStr([str]){maka.tape[maka.ptr].type="str",maka.tape[maka.ptr].value=str}},tape:[],Cell:class{constructor(type,value){this.type=type||"num",this.value=value||0}},ptr:0,throw(error){console.log("%c😕: "+error,"color: red"),process.exit(1)}};function h(){try{module.exports=maka}catch(_){this.maka=maka}try{if(module==require.main){let fn=process.argv[2];fn.endsWith(".maka");try{var h=require("fs").readFileSync(fn,{encoding:"utf-8"});maka.run(h)}catch(e){throw maka.throw(`📄 '${fn}' = ❌`),e}}}catch(_){throw _}}maka.locales.English={label:/^this (line )?is (named )?%%\.?$/i,nextCell:/^(move|go) to (the )?next box\.?$/i,prevCell:/^(move|go) to (the )?(last|previous) box\.?$/i,addNum:/^add (the )?number %% to (this )?box\.?$/i,appendStr:/^add (the )?text %% after (the contents of )?(this )?box\.?$/i,prependStr:/^add (the )?text %% before (the contents of )?(this )?box\.?$/i,jump:/^if there is (something|anything|a (nonzero )?value) in (this )?box, (go|move) to (the )?(line named )?%%\.?$/i,emptyStr:/^remove (anything|everything) (from|in) (this )?box\.?$/i,printCell:/^(say|show|display|tell) (what(ever)? is in|anything in|everything in|the contents of) (this )?box\.?$/i,printText:/^(say|show|display|tell) %%\.?$/i,setStr:/^put (the )?text %% (in|inside|into) (this )?box\.?$/i},h();