-
Notifications
You must be signed in to change notification settings - Fork 4
/
justin.min.js
1 lines (1 loc) · 6.92 KB
/
justin.min.js
1
let r,e,t=t=>(r=0,e=t,t=a(),e[r]?n():t||""),n=(t="Bad syntax",n=e.slice(0,r).split("\n"),l=n.pop())=>{let i=e.slice(r-108,r).split("\n").pop(),a=e.slice(r,r+108).split("\n").shift();throw EvalError(`${t} at ${n.length}:${l.length} \`${r>=108?"…":""}${i}┃${a}\``,"font-weight: bold")},l=(t,n=r,l)=>{for(;l=t(e.charCodeAt(r));)r+=l;return e.slice(n,r)},i=(t=1,n=r)=>(r+=t,e.slice(n,r)),a=(e=0,i)=>{let a,p,c,d;for(;(a=o())&&(c=((d=s[a])&&d(p,e))??(!p&&l(t.id)));)p=c;return i&&(a==i?r++:n()),p},o=t=>{for(;(t=e.charCodeAt(r))<=32;)r++;return t};t.id=r=>r>=48&&r<=57||r>=65&&r<=90||r>=97&&r<=122||36==r||95==r||r>=192&&215!=r&&247!=r;let s=[],p=(l,i=32,a,o=l.charCodeAt(0),p=l.length,c=s[o],d=l.toUpperCase()!==l)=>s[o]=(o,s,f,h=r)=>(f?l==f:(p<2||e.substr(r,p)==l)&&(f=l))&&s<i&&!(d&&t.id(e.charCodeAt(r+p)))&&(r+=p,a(o)||(r=h,!c&&n()))||c?.(o,s,f),c=(r,e,t=!1)=>p(r,e,((n,l)=>n&&(l=a(e-(t?.5:0)))&&[r,n,l])),d=(r,e,t)=>p(r,e,(n=>t?n&&[r,n]:!n&&(n=a(e-.5))&&[r,n])),f=(r,e,t)=>{p(r,e,((t,n)=>(n=a(e),t?.[0]!==r&&(t=[r,t||null]),n?.[0]===r?t.push(...n.slice(1)):t.push(n||null),t)))},h=(r,e)=>p(r[0],e,(e=>!e&&[r,a(0,r.charCodeAt(1))])),u=(r,e)=>p(r[0],e,(e=>e&&[r,e,a(0,r.charCodeAt(1))||null]));const A=r=>Array.isArray(r)?r[0]?g[r[0]](...r.slice(1)):()=>r[1]:A.id(r);A.id=r=>e=>e?.[r];const g={},m=(r,e,t=g[r])=>g[r]=(...r)=>e(...r)||t?.(...r),y=(r,e,t,l,i)=>"()"===r[0]&&2==r.length?y(r[1],e,t):"string"==typeof r?t=>e(t,r,t):"."===r[0]?(l=A(r[1]),i=r[2],r=>e(l(r),i,r)):"[]"===r[0]&&3===r.length?(l=A(r[1]),i=A(r[2]),r=>e(l(r),i(r),r)):t?(r=A(r),t=>e([r(t)],0,t)):()=>n("Bad left value"),v=(r,e)=>[,(r=+l((r=>46===r||r>=48&&r<=57||(69===r||101===r?2:0))))!=r?n():r];s[46]=r=>!r&&v();for(let r=48;r<=57;r++)s[r]=r=>r?n():v();const C={n:"\n",r:"\r",t:"\t",b:"\b",f:"\f",v:"\v"},b=t=>(l,a,o="")=>{for(l&&n("Unexpected string"),i();(a=e.charCodeAt(r))-t;)92===a?(i(),a=i(),o+=C[a]||a):o+=i();return i()||n("Bad string"),[,o]};s[34]=b(34),s[39]=b(39),u("()",170),m("()",((r,e,t)=>void 0!==e&&(t=e?","===e[0]?(e=e.slice(1).map((r=>r?A(r):err())),r=>e.map((e=>e(r)))):(e=A(e),r=>[e(r)]):()=>[],y(r,((r,e,n)=>r[e](...t(n))),!0)))),u("[]",170),m("[]",((r,e)=>e?(r=A(r),e=A(e),t=>r(t)[e(t)]):err())),c(".",170),m(".",((r,e)=>(r=A(r),e=e[0]?e:e[1],t=>r(t)[e]))),h("()",170),m("()",((r,e)=>void 0===e&&(!r&&n("Empty ()"),A(r))));const $=(...r)=>(r=r.map(A),e=>r.map((r=>r(e))).pop());function N(r){if(!r)return"";if(Array.isArray(r)){const[e,...t]=r;return e?"[]"==e||"{}"==e||"()"==e?(t.length>1?N(t.shift()):"")+e[0]+N(t[0])+e[1]:1===t.length?e+N(t[0]):2===t.length?N(t[0])+("."===e?e:" "+e+" ")+N(t[1]):t.filter(Boolean).map((r=>N(r))).join(e+"\n"):JSON.stringify(t[0])}return r}f(",",10),m(",",$),f(";",5),m(";",$),c("=",20,!0),m("=",((r,e)=>(e=A(e),y(r,((r,t,n)=>r[t]=e(n)))))),c("*",120),m("*",((r,e)=>e&&(r=A(r),e=A(e),t=>r(t)*e(t)))),c("/",120),m("/",((r,e)=>e&&(r=A(r),e=A(e),t=>r(t)/e(t)))),c("%",120),m("%",((r,e)=>e&&(r=A(r),e=A(e),t=>r(t)%e(t)))),c("*=",20,!0),m("*=",((r,e)=>(e=A(e),y(r,((r,t,n)=>r[t]*=e(n)))))),c("/=",20,!0),m("/=",((r,e)=>(e=A(e),y(r,((r,t,n)=>r[t]/=e(n)))))),c("%=",20,!0),m("%=",((r,e)=>(e=A(e),y(r,((r,t,n)=>r[t]%=e(n)))))),c("+",110),m("+",((r,e)=>e&&(r=A(r),e=A(e),t=>r(t)+e(t)))),c("-",110),m("-",((r,e)=>e&&(r=A(r),e=A(e),t=>r(t)-e(t)))),d("+",140),m("+",((r,e)=>!e&&(r=A(r),e=>+r(e)))),d("-",140),m("-",((r,e)=>!e&&(r=A(r),e=>-r(e)))),c("+=",20,!0),m("+=",((r,e)=>(e=A(e),y(r,((r,t,n)=>r[t]+=e(n)))))),c("-=",20,!0),m("-=",((r,e)=>(e=A(e),y(r,((r,t,n)=>r[t]-=e(n)))))),p("++",150,(r=>r?["++-",r]:["++",a(149)])),m("++",(r=>y(r,((r,e)=>++r[e])))),m("++-",(r=>y(r,((r,e)=>r[e]++)))),p("--",150,(r=>r?["--+",r]:["--",a(149)])),m("--",(r=>y(r,((r,e)=>--r[e])))),m("--+",(r=>y(r,((r,e)=>r[e]--)))),d("~",140),m("~",((r,e)=>!e&&(r=A(r),e=>~r(e)))),c("|",50),m("|",((r,e)=>e&&(r=A(r),e=A(e),t=>r(t)|e(t)))),c("&",70),m("&",((r,e)=>e&&(r=A(r),e=A(e),t=>r(t)&e(t)))),c("^",60),m("^",((r,e)=>e&&(r=A(r),e=A(e),t=>r(t)^e(t)))),c("==",80),m("==",((r,e)=>e&&(r=A(r),e=A(e),t=>r(t)==e(t)))),c("!=",80),m("!=",((r,e)=>e&&(r=A(r),e=A(e),t=>r(t)!=e(t)))),c(">",90),m(">",((r,e)=>e&&(r=A(r),e=A(e),t=>r(t)>e(t)))),c("<",90),m("<",((r,e)=>e&&(r=A(r),e=A(e),t=>r(t)<e(t)))),c(">=",90),m(">=",((r,e)=>e&&(r=A(r),e=A(e),t=>r(t)>=e(t)))),c("<=",90),m("<=",((r,e)=>e&&(r=A(r),e=A(e),t=>r(t)<=e(t)))),c(">>",100),m(">>",((r,e)=>e&&(r=A(r),e=A(e),t=>r(t)>>e(t)))),c("<<",100),m("<<",((r,e)=>e&&(r=A(r),e=A(e),t=>r(t)<<e(t)))),c(">>=",20,!0),m(">>=",((r,e)=>(e=A(e),prop(r,((r,t,n)=>r[t]>>=e(n)))))),c("<<=",20,!0),m("<<=",((r,e)=>(e=A(e),prop(r,((r,t,n)=>r[t]<<=e(n)))))),d("!",140),m("!",((r,e)=>!e&&(r=A(r),e=>!r(e)))),c("||",30),m("||",((r,e)=>(r=A(r),e=A(e),t=>r(t)||e(t)))),c("&&",40),m("&&",((r,e)=>(r=A(r),e=A(e),t=>r(t)&&e(t))));var j=r=>A(t(r));p("/*",200,((t,n)=>(l((t=>42!==t&&47!==e.charCodeAt(r+1))),i(2),t||a(n)||[]))),p("//",200,((r,e)=>(l((r=>r>=32)),r||a(e)||[]))),c("**",130,!0),m("**",((r,e)=>e&&(r=A(r),e=A(e),t=>r(t)**e(t)))),p("?",20,((r,e,t)=>r&&(e=a(19))&&l((r=>58===r))&&["?",r,e,a(19)])),m("?",((r,e,t)=>(r=A(r),e=A(e),t=A(t),n=>r(n)?e(n):t(n)))),p("true",200,(r=>r?err():[,!0])),p("false",200,(r=>r?err():[,!1])),h("[]",200),m("[]",((r,e)=>void 0===e&&(r=(r=r?","===r[0]?r.slice(1):[r]:[]).map((r=>"..."===r[0]?(r=A(r[1]),e=>r(e)):(r=A(r),e=>[r(e)]))),e=>r.flatMap((r=>r(e)))))),h("{}",200),m("{}",((r,e)=>void 0===e&&(r=(r=r?","!==r[0]?[r]:r.slice(1):[]).map((r=>A("string"==typeof r?[":",r,r]:r))),e=>Object.fromEntries(r.flatMap((r=>r(e))))))),c(":",19,!0),m(":",((r,e)=>(e=A(e),Array.isArray(r)?(r=A(r),t=>[[r(t),e(t)]]):t=>[[r,e(t)]]))),c("=>",20,!0),m("=>",((r,e)=>(r=(r="()"===r[0]?r[1]:r)?r=","===r[0]?r.slice(1):[r]:[],e=A("{}"===e[0]?e[1]:e),(t=null)=>(t=Object.create(t),(...n)=>(r.map(((r,e)=>t[r]=n[e])),e(t)))))),c(""),p("?.",170,(r=>r&&["?.",r])),m("?.",(r=>(r=A(r),e=>r(e)||(()=>{})))),p("?.",170,((r,e)=>r&&!(e=a(170))?.map&&["?.",r,e])),m("?.",((r,e)=>e&&(r=A(r),t=>r(t)?.[e]))),m("()",((r,e,t,n,l,i)=>void 0!==e&&"?."===r[0]&&(r[2]||Array.isArray(r[1]))&&(n=e?","===e[0]?(e=e.slice(1).map(A),r=>e.map((e=>e(r)))):(e=A(e),r=>[e(r)]):()=>[],!r[2]&&(r=r[1]),l="[]"===r[0]&&3===r.length?A(r[2]):()=>r[2],t=A(r[1]),r=>t(r)?.[l(r)]?.(...n(r))))),d("...",140),m("...",(r=>(r=A(r),e=>Object.entries(r(e))))),c("in",90),m("in",((r,e)=>e&&(r=A(r),e=A(e),t=>r(t)in e(t)))),c("===",80),c("!==",9),m("===",((r,e)=>(r=A(r),e=A(e),t=>r(t)===e(t)))),m("!==",((r,e)=>(r=A(r),e=A(e),t=>r(t)!==e(t)))),c("??",30),m("??",((r,e)=>e&&(r=A(r),e=A(e),t=>r(t)??e(t)))),c("??=",20,!0),m("??=",((r,e)=>(e=A(e),y(r,((r,t,n)=>r[t]??=e(n)))))),c("||=",20,!0),m("||=",((r,e)=>(e=A(e),y(r,((r,t,n)=>r[t]||=e(n)))))),c("&&=",20,!0),m("&&=",((r,e)=>(e=A(e),y(r,((r,t,n)=>r[t]&&=e(n)))))),c(">>>",80),m(">>>",((r,e)=>(r=A(r),e=A(e),t=>r(t)>>>e(t)))),c(">>>=",20,!0),m(">>>=",((r,e)=>(e=A(e),y(r,((r,t,n)=>r[t]>>>=e(n)))))),p("undefined",20,(r=>r?n():[,void 0])),p("NaN",20,(r=>r?n():[,NaN])),p("null",20,(r=>r?n():[,null]));export{u as access,c as binary,A as compile,j as default,h as group,f as nary,m as operator,t as parse,N as stringify,p as token,d as unary};