subscript 9.2.0 → 10.0.1
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.
- package/README.md +101 -184
- package/feature/access.js +68 -7
- package/feature/accessor.js +49 -0
- package/feature/asi.js +15 -0
- package/feature/async.js +45 -0
- package/feature/block.js +41 -0
- package/feature/class.js +69 -0
- package/feature/collection.js +40 -0
- package/feature/comment.js +25 -5
- package/feature/control.js +2 -142
- package/feature/destruct.js +33 -0
- package/feature/function.js +44 -0
- package/feature/group.js +13 -9
- package/feature/if.js +23 -38
- package/feature/literal.js +13 -0
- package/feature/loop.js +107 -106
- package/feature/module.js +42 -0
- package/feature/number.js +41 -38
- package/feature/op/arithmetic.js +29 -0
- package/feature/op/arrow.js +33 -0
- package/feature/op/assign-logical.js +33 -0
- package/feature/op/assignment.js +26 -0
- package/feature/op/bitwise-unsigned.js +17 -0
- package/feature/op/bitwise.js +29 -0
- package/feature/op/comparison.js +19 -0
- package/feature/op/defer.js +15 -0
- package/feature/op/equality.js +16 -0
- package/feature/op/identity.js +15 -0
- package/feature/op/increment.js +23 -0
- package/feature/op/logical.js +21 -0
- package/feature/op/membership.js +17 -0
- package/feature/op/nullish.js +13 -0
- package/feature/op/optional.js +61 -0
- package/feature/op/pow.js +19 -0
- package/feature/op/range.js +26 -0
- package/feature/op/spread.js +15 -0
- package/feature/op/ternary.js +15 -0
- package/feature/op/type.js +18 -0
- package/feature/op/unary.js +41 -0
- package/feature/prop.js +34 -0
- package/feature/regex.js +31 -0
- package/feature/seq.js +21 -0
- package/feature/string.js +24 -17
- package/feature/switch.js +48 -0
- package/feature/template.js +39 -0
- package/feature/try.js +57 -0
- package/feature/unit.js +35 -0
- package/feature/var.js +51 -41
- package/jessie.js +31 -0
- package/jessie.min.js +8 -0
- package/justin.js +39 -48
- package/justin.min.js +8 -4
- package/package.json +15 -16
- package/parse.js +146 -0
- package/subscript.d.ts +45 -5
- package/subscript.js +62 -22
- package/subscript.min.js +5 -4
- package/util/bundle.js +507 -0
- package/util/stringify.js +172 -0
- package/feature/add.js +0 -22
- package/feature/array.js +0 -11
- package/feature/arrow.js +0 -23
- package/feature/assign.js +0 -11
- package/feature/bitwise.js +0 -11
- package/feature/bool.js +0 -5
- package/feature/call.js +0 -15
- package/feature/compare.js +0 -11
- package/feature/increment.js +0 -11
- package/feature/logic.js +0 -11
- package/feature/mult.js +0 -25
- package/feature/object.js +0 -17
- package/feature/optional.js +0 -23
- package/feature/pow.js +0 -5
- package/feature/shift.js +0 -12
- package/feature/spread.js +0 -6
- package/feature/ternary.js +0 -10
- package/src/compile.d.ts +0 -17
- package/src/compile.js +0 -28
- package/src/const.js +0 -45
- package/src/parse.d.ts +0 -22
- package/src/parse.js +0 -113
- package/src/stringify.js +0 -27
- /package/{LICENSE → license} +0 -0
package/justin.min.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
var
|
|
2
|
-
`),
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
var u,c,f=r=>(u=0,c=r,f.newline=!1,r=A(),c[u]?I():r||""),I=(r="Unexpected token",e=u,t=c.slice(0,e).split(`
|
|
2
|
+
`),o=t.pop(),i=c.slice(Math.max(0,e-40),e),p="\u032D",m=(c[e]||"\u2205")+p,d=c.slice(e+1,e+20))=>{throw SyntaxError(`${r} at ${t.length+1}:${o.length+1}
|
|
3
|
+
${(c[e-41]!==`
|
|
4
|
+
`?"...":"")+i}${m}${d}`)},Ir=(r,e=u)=>(Array.isArray(r)&&(r.loc=e),r),v=(r,e=u,t)=>{for(;t=r(c.charCodeAt(u));)u+=t;return c.slice(e,u)},h=(r=1)=>c[u+=r],rr=r=>u=r,A=(r=0,e)=>{let t,o,i,p,m=f.reserved,d;for(e&&f.asi&&(f.newline=!1),f.reserved=0;(t=f.space())&&(d=f.newline,1)&&t!==e&&(i=((p=S[t])&&p(o,r))??(f.asi&&o&&d&&(i=f.asi(o,r,A)))??(!o&&!f.reserved&&v(f.id)));)o=i,f.reserved=0;return f.reserved=m,e&&(t==e?u++:I("Unclosed "+String.fromCharCode(e-(e>42?2:1)))),o},P=f.space=(r,e=u)=>{for(;(r=c.charCodeAt(u))<=32;)f.asi&&r===10&&(f.newline=!0),u++;return r},ge=f.id=r=>r>=48&&r<=57||r>=65&&r<=90||r>=97&&r<=122||r==36||r==95||r>=192&&r!=215&&r!=247,he=(r,e=r.length)=>c.substr(u,e)===r&&!f.id(c.charCodeAt(u+e)),ye=()=>(h(),A(0,41)),S=[],y=(r,e=32,t,o=r.charCodeAt(0),i=r.length,p=S[o],m=r.toUpperCase()!==r,d,g)=>S[o]=(E,x,T,b=u)=>(d=T,(T?r==T:(i<2||r.charCodeAt(1)===c.charCodeAt(u+1)&&(i<3||c.substr(u,i)==r))&&(!m||!f.id(c.charCodeAt(u+i)))&&(d=T=r))&&x<e&&(u+=i,(g=t(E))?Ir(g,b):(u=b,d=0,m&&g!==!1&&(f.reserved=1),!m&&!p&&I()),g)||p?.(E,x,d)),l=(r,e,t=!1)=>y(r,e,(o,i)=>o&&(i=A(e-(t?.5:0)))&&[r,o,i]),C=(r,e,t)=>y(r,e,o=>t?o&&[r,o]:!o&&(o=A(e-.5))&&[r,o]),k=(r,e)=>y(r,200,t=>!t&&[,e]),K=(r,e,t)=>{y(r,e,(o,i)=>(i=A(e-(t?.5:0)),o?.[0]!==r&&(o=[r,o||null]),i?.[0]===r?o.push(...i.slice(1)):o.push(i||null),o))},R=(r,e)=>y(r[0],e,t=>!t&&[r,A(0,r.charCodeAt(1))||null]),j=(r,e)=>y(r[0],e,t=>t&&[r,t,A(0,r.charCodeAt(1))||null]),H={},s=(r,e,t=H[r])=>H[r]=(...o)=>e(...o)||t?.(...o),n=r=>Array.isArray(r)?r[0]===void 0?(e=>()=>e)(r[1]):H[r[0]]?.(...r.slice(1))??I(`Unknown operator: ${r[0]}`,r?.loc):r===void 0?()=>{}:e=>e?.[r];var U=46,L=48,_=57,vr=69,wr=101,Nr=43,Or=45,kr=97,Pr=102,Rr=65,Lr=70,W=r=>[,(r=+v(e=>e===U&&c.charCodeAt(u+1)!==U||e>=L&&e<=_||((e===vr||e===wr)&&((e=c.charCodeAt(u+1))>=L&&e<=_||e===Nr||e===Or)?2:0)))!=r?I():r],Tr={2:r=>r===48||r===49,8:r=>r>=48&&r<=55,16:r=>r>=L&&r<=_||r>=kr&&r<=Pr||r>=Rr&&r<=Lr};f.number=null;S[U]=r=>!r&&c.charCodeAt(u+1)!==U&&W();for(let r=L;r<=_;r++)S[r]=e=>e?void 0:W();S[L]=r=>{if(r)return;let e=f.number;if(e){for(let[t,o]of Object.entries(e))if(t[0]==="0"&&c[u+1]?.toLowerCase()===t[1])return h(2),[,parseInt(v(Tr[o]),o)]}return W()};var Ur=92,er=34,tr=39,_r={n:`
|
|
5
|
+
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},or=r=>(e,t,o="")=>{if(!(e||!f.string?.[String.fromCharCode(r)]))return h(),v(i=>i-r&&(i===Ur?(o+=_r[c[u+1]]||c[u+1],2):(o+=c[u],1))),c[u]===String.fromCharCode(r)?h():I("Bad string"),[,o]};S[er]=or(er);S[tr]=or(tr);f.string={'"':!0};var Mr=20;"= += -= *= /= %= |= &= ^= >>= <<=".split(" ").map(r=>l(r,Mr,!0));var ir=(r,e,t,o)=>typeof r=="string"?i=>e(i,r,i):r[0]==="."?(t=n(r[1]),o=r[2],i=>e(t(i),o,i)):r[0]==="[]"&&r.length===3?(t=n(r[1]),o=n(r[2]),i=>e(t(i),o(i),i)):r[0]==="()"&&r.length===2?ir(r[1],e):(()=>{throw Error("Invalid assignment target")})(),nr={"=":(r,e,t)=>r[e]=t,"+=":(r,e,t)=>r[e]+=t,"-=":(r,e,t)=>r[e]-=t,"*=":(r,e,t)=>r[e]*=t,"/=":(r,e,t)=>r[e]/=t,"%=":(r,e,t)=>r[e]%=t,"|=":(r,e,t)=>r[e]|=t,"&=":(r,e,t)=>r[e]&=t,"^=":(r,e,t)=>r[e]^=t,">>=":(r,e,t)=>r[e]>>=t,"<<=":(r,e,t)=>r[e]<<=t};for(let r in nr)s(r,(e,t)=>(t=n(t),ir(e,(o,i,p)=>nr[r](o,i,t(p)))));var Fr=30,Br=40,sr=140;l("!",sr);C("!",sr);l("||",Fr);l("&&",Br);s("!",r=>(r=n(r),e=>!r(e)));s("||",(r,e)=>(r=n(r),e=n(e),t=>r(t)||e(t)));s("&&",(r,e)=>(r=n(r),e=n(e),t=>r(t)&&e(t)));var Dr=50,Gr=60,Xr=70,pr=100,$r=140;l("|",Dr);l("&",Xr);l("^",Gr);l(">>",pr);l("<<",pr);C("~",$r);s("~",r=>(r=n(r),e=>~r(e)));s("|",(r,e)=>(r=n(r),e=n(e),t=>r(t)|e(t)));s("&",(r,e)=>(r=n(r),e=n(e),t=>r(t)&e(t)));s("^",(r,e)=>(r=n(r),e=n(e),t=>r(t)^e(t)));s(">>",(r,e)=>(r=n(r),e=n(e),t=>r(t)>>e(t)));s("<<",(r,e)=>(r=n(r),e=n(e),t=>r(t)<<e(t)));var M=90;l("<",M);l(">",M);l("<=",M);l(">=",M);s(">",(r,e)=>(r=n(r),e=n(e),t=>r(t)>e(t)));s("<",(r,e)=>(r=n(r),e=n(e),t=>r(t)<e(t)));s(">=",(r,e)=>(r=n(r),e=n(e),t=>r(t)>=e(t)));s("<=",(r,e)=>(r=n(r),e=n(e),t=>r(t)<=e(t)));var mr=80;l("==",mr);l("!=",mr);s("==",(r,e)=>(r=n(r),e=n(e),t=>r(t)==e(t)));s("!=",(r,e)=>(r=n(r),e=n(e),t=>r(t)!=e(t)));var lr=110,z=120,ur=140;l("+",lr);l("-",lr);l("*",z);l("/",z);l("%",z);C("+",ur);C("-",ur);s("+",(r,e)=>e!==void 0?(r=n(r),e=n(e),t=>r(t)+e(t)):(r=n(r),t=>+r(t)));s("-",(r,e)=>e!==void 0?(r=n(r),e=n(e),t=>r(t)-e(t)):(r=n(r),t=>-r(t)));s("*",(r,e)=>(r=n(r),e=n(e),t=>r(t)*e(t)));s("/",(r,e)=>(r=n(r),e=n(e),t=>r(t)/e(t)));s("%",(r,e)=>(r=n(r),e=n(e),t=>r(t)%e(t)));var F=150;y("++",F,r=>r?["++",r,null]:["++",A(F-1)]);y("--",F,r=>r?["--",r,null]:["--",A(F-1)]);var J=(r,e,t,o)=>typeof r=="string"?i=>e(i,r):r[0]==="."?(t=n(r[1]),o=r[2],i=>e(t(i),o)):r[0]==="[]"&&r.length===3?(t=n(r[1]),o=n(r[2]),i=>e(t(i),o(i))):r[0]==="()"&&r.length===2?J(r[1],e):(()=>{throw Error("Invalid increment target")})();s("++",(r,e)=>J(r,e===null?(t,o)=>t[o]++:(t,o)=>++t[o]));s("--",(r,e)=>J(r,e===null?(t,o)=>t[o]--:(t,o)=>--t[o]));var Qr=5,Hr=10,Kr=170;R("()",Kr);K(",",Hr);K(";",Qr,!0);var fr=(...r)=>(r=r.map(n),e=>{let t;for(let o of r)t=o(e);return t});s(",",fr);s(";",fr);var N=r=>r?.[0]==="_"&&r[1]==="_"||r==="constructor"||r==="prototype",V=170;j("[]",V);l(".",V);j("()",V);var B=r=>{throw Error(r)};s("[]",(r,e)=>e===void 0?(r=r?r[0]===","?r.slice(1):[r]:[],r=r.map(t=>t==null?(()=>{}):t[0]==="..."?(t=n(t[1]),o=>t(o)):(t=n(t),o=>[t(o)])),t=>r.flatMap(o=>o(t))):(e==null&&B("Missing index"),r=n(r),e=n(e),t=>{let o=e(t);return N(o)?void 0:r(t)[o]}));s(".",(r,e)=>(r=n(r),e=e[0]?e:e[1],N(e)?()=>{}:t=>r(t)[e]));s("()",(r,e)=>{if(e===void 0)return r==null?B("Empty ()"):n(r);let t=i=>i?.[0]===","&&i.slice(1).some(p=>p==null||t(p));t(e)&&B("Empty argument");let o=e?e[0]===","?(e=e.slice(1).map(n),i=>e.map(p=>p(i))):(e=n(e),i=>[e(i)]):()=>[];return Y(r,(i,p,m)=>i[p](...o(m)))});var w=r=>typeof r=="string"||Array.isArray(r)&&(r[0]==="."||r[0]==="?."||r[0]==="[]"&&r.length===3||r[0]==="?.[]"||r[0]==="()"&&r.length===2&&w(r[1])||r[0]==="{}"),Y=(r,e,t,o)=>r==null?B("Empty ()"):r[0]==="()"&&r.length==2?Y(r[1],e):typeof r=="string"?i=>e(i,r,i):r[0]==="."?(t=n(r[1]),o=r[2],i=>e(t(i),o,i)):r[0]==="?."?(t=n(r[1]),o=r[2],i=>{let p=t(i);return p==null?void 0:e(p,o,i)}):r[0]==="[]"&&r.length===3?(t=n(r[1]),o=n(r[2]),i=>e(t(i),o(i),i)):r[0]==="?.[]"?(t=n(r[1]),o=n(r[2]),i=>{let p=t(i);return p==null?void 0:e(p,o(i),i)}):(r=n(r),i=>e([r(i)],0,i)),O=Y;var cr=new WeakMap,jr=(r,...e)=>typeof r=="string"?n(f(r)):cr.get(r)||cr.set(r,Wr(r,e)).get(r),dr=57344,Wr=(r,e)=>{let t=r.reduce((p,m,d)=>p+(d?String.fromCharCode(dr+d-1):"")+m,""),o=f(t),i=p=>{if(typeof p=="string"&&p.length===1){let m=p.charCodeAt(0)-dr,d;if(m>=0&&m<e.length)return d=e[m],zr(d)?d:[,d]}return Array.isArray(p)?p.map(i):p};return n(i(o))},zr=r=>typeof r=="string"||Array.isArray(r)&&(typeof r[0]=="string"||r[0]===void 0),Jr=jr;var Vr=32,Yr=f.space;f.comment??={"//":`
|
|
6
|
+
`,"/*":"*/"};var Z;f.space=()=>{Z||(Z=Object.entries(f.comment).map(([i,p])=>[i,p,i.charCodeAt(0)]));for(var r;r=Yr();){for(var e=0,t;t=Z[e++];)if(r===t[2]&&c.substr(u,t[0].length)===t[0]){var o=u+t[0].length;if(t[1]===`
|
|
7
|
+
`)for(;c.charCodeAt(o)>=Vr;)o++;else{for(;c[o]&&c.substr(o,t[1].length)!==t[1];)o++;c[o]&&(o+=t[1].length)}rr(o),r=0;break}if(r)return r}return r};var Ar=80;l("===",Ar);l("!==",Ar);s("===",(r,e)=>(r=n(r),e=n(e),t=>r(t)===e(t)));s("!==",(r,e)=>(r=n(r),e=n(e),t=>r(t)!==e(t)));var Zr=30;l("??",Zr);s("??",(r,e)=>(r=n(r),e=n(e),t=>r(t)??e(t)));var qr=130,ar=20;l("**",qr,!0);l("**=",ar,!0);s("**",(r,e)=>(r=n(r),e=n(e),t=>r(t)**e(t)));var xr=r=>{throw Error(r)};s("**=",(r,e)=>(w(r)||xr("Invalid assignment target"),e=n(e),O(r,(t,o,i)=>t[o]**=e(i))));var gr=90;l("in",gr);l("of",gr);s("in",(r,e)=>(r=n(r),e=n(e),t=>r(t)in e(t)));var br=20,re=100,ee=r=>{throw Error(r)};l(">>>",re);l(">>>=",br,!0);s(">>>",(r,e)=>(r=n(r),e=n(e),t=>r(t)>>>e(t)));s(">>>=",(r,e)=>(w(r)||ee("Invalid assignment target"),e=n(e),O(r,(t,o,i)=>t[o]>>>=e(i))));var D=(r,e,t)=>{if(typeof r=="string"){t[r]=e;return}let[o,...i]=r;if(o==="{}")for(let p of i){let m,d,g;p[0]==="="?[,[,m,d],g]=p:[,m,d]=p;let E=e[m];E===void 0&&g&&(E=n(g)(t)),D(d,E,t)}else if(o==="[]"){let p=0;for(let m of i){if(m===null){p++;continue}if(Array.isArray(m)&&m[0]==="..."){t[m[1]]=e.slice(p);break}let d=m,g;Array.isArray(m)&&m[0]==="="&&([,d,g]=m);let E=e[p++];E===void 0&&g&&(E=n(g)(t)),D(d,E,t)}}};var q=20,G=r=>{throw Error(r)};l("||=",q,!0);l("&&=",q,!0);l("??=",q,!0);s("=",(r,e)=>{if(Array.isArray(r)&&(r[0]==="let"||r[0]==="const"||r[0]==="var")){let t=r[1];return e=n(e),typeof t=="string"?o=>{o[t]=e(o)}:o=>D(t,e(o),o)}return w(r)||G("Invalid assignment target"),e=n(e),O(r,(t,o,i)=>t[o]=e(i))});s("||=",(r,e)=>(w(r)||G("Invalid assignment target"),e=n(e),O(r,(t,o,i)=>t[o]||=e(i))));s("&&=",(r,e)=>(w(r)||G("Invalid assignment target"),e=n(e),O(r,(t,o,i)=>t[o]&&=e(i))));s("??=",(r,e)=>(w(r)||G("Invalid assignment target"),e=n(e),O(r,(t,o,i)=>t[o]??=e(i))));k("true",!0);k("false",!1);k("null",null);k("undefined",void 0);k("NaN",NaN);k("Infinity",1/0);var a=20;y("?",a,(r,e,t)=>r&&(e=A(a-1))&&v(o=>o===58)&&(t=A(a-1),["?",r,e,t]));s("?",(r,e,t)=>(r=n(r),e=n(e),t=n(t),o=>r(o)?e(o):t(o)));var te=20;l("=>",te,!0);s("=>",(r,e)=>{r=r[0]==="()"?r[1]:r,r=r?r[0]===","?r.slice(1):[r]:[];let t=-1,o=null;return r.length&&Array.isArray(r[r.length-1])&&r[r.length-1][0]==="..."&&(t=r.length-1,o=r[t][1],r=r.slice(0,-1)),e=n(e[0]==="{}"?e[1]:e),(i=null)=>(i=Object.create(i),(...p)=>(r.forEach((m,d)=>i[m]=p[d]),o&&(i[o]=p.slice(t)),e(i)))});var oe=140;C("...",oe);s("...",r=>(r=n(r),e=>Object.entries(r(e))));var hr=170;y("?.",hr,(r,e)=>{if(!r)return;let t=P();return t===40?(h(),["?.()",r,A(0,41)||null]):t===91?(h(),["?.[]",r,A(0,93)]):(e=A(hr),e?["?.",r,e]:void 0)});s("?.",(r,e)=>(r=n(r),N(e)?()=>{}:t=>r(t)?.[e]));s("?.[]",(r,e)=>(r=n(r),e=n(e),t=>{let o=e(t);return N(o)?void 0:r(t)?.[o]}));s("?.()",(r,e)=>{let t=e?e[0]===","?(e=e.slice(1).map(n),i=>e.map(p=>p(i))):(e=n(e),i=>[e(i)]):()=>[];if(r[0]==="?."){let i=n(r[1]),p=r[2];return N(p)?()=>{}:m=>i(m)?.[p]?.(...t(m))}if(r[0]==="?.[]"){let i=n(r[1]),p=n(r[2]);return m=>{let d=i(m),g=p(m);return N(g)?void 0:d?.[g]?.(...t(m))}}if(r[0]==="."){let i=n(r[1]),p=r[2];return N(p)?()=>{}:m=>i(m)?.[p]?.(...t(m))}if(r[0]==="[]"&&r.length===3){let i=n(r[1]),p=n(r[2]);return m=>{let d=i(m),g=p(m);return N(g)?void 0:d?.[g]?.(...t(m))}}let o=n(r);return i=>o(i)?.(...t(i))});var X=140;C("typeof",X);C("void",X);C("delete",X);C("new",X);s("typeof",r=>(r=n(r),e=>typeof r(e)));s("void",r=>(r=n(r),e=>(r(e),void 0)));s("delete",r=>{if(r[0]==="."){let e=n(r[1]),t=r[2];return o=>delete e(o)[t]}if(r[0]==="[]"){let e=n(r[1]),t=n(r[2]);return o=>delete e(o)[t(o)]}return()=>!0});s("new",r=>{let e=n(r?.[0]==="()"?r[1]:r),t=r?.[0]==="()"?r[2]:null,o=t?t[0]===","?(i=>p=>i.map(m=>m(p)))(t.slice(1).map(n)):(i=>p=>[i(p)])(n(t)):()=>[];return i=>new(e(i))(...o(i))});var $=Symbol("accessor"),yr=20,ne=40,ie=41,se=123,pe=125,Cr=r=>e=>{if(e)return;P();let t=v(f.id);if(!t||(P(),c.charCodeAt(u)!==ne))return!1;h();let o=A(0,ie);return P(),c.charCodeAt(u)!==se?!1:(h(),[r,t,o,A(0,pe)])};y("get",yr-1,Cr("get"));y("set",yr-1,Cr("set"));s("get",(r,e)=>(e=e?n(e):()=>{},t=>[[$,r,{get:function(){let o=Object.create(t||{});return o.this=this,e(o)}}]]));s("set",(r,e,t)=>(t=t?n(t):()=>{},o=>[[$,r,{set:function(i){let p=Object.create(o||{});p.this=this,p[e]=i,t(p)}}]]));var me=20,Sr=200;R("[]",Sr);R("{}",Sr);l(":",me-1,!0);s("{}",(r,e)=>{if(e!==void 0)return;r=r?r[0]!==","?[r]:r.slice(1):[];let t=r.map(o=>n(typeof o=="string"?[":",o,o]:o));return o=>{let i={},p={};for(let m of t.flatMap(d=>d(o)))if(m[0]===$){let[,d,g]=m;p[d]={...p[d],...g,configurable:!0,enumerable:!0}}else i[m[0]]=m[1];for(let m in p)Object.defineProperty(i,m,p[m]);return i}});s(":",(r,e)=>(e=n(e),Array.isArray(r)?(r=n(r),t=>[[r(t),e(t)]]):t=>[[r,e(t)]]));var le=170,Q=96,ue=36,fe=123,ce=92,de={n:`
|
|
8
|
+
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},Er=()=>{let r=[];for(let e="",t;(t=c.charCodeAt(u))!==Q;)t?t===ce?(h(),e+=de[c[u]]||c[u],h()):t===ue&&c.charCodeAt(u+1)===fe?(e&&r.push([,e]),e="",h(2),r.push(A(0,125))):(e+=c[u],h(),t=c.charCodeAt(u),t===Q&&e&&r.push([,e])):I("Unterminated template");return h(),r},Ae=S[Q];S[Q]=(r,e)=>r&&e<le?f.asi&&f.newline?void 0:(h(),["``",r,...Er()]):r?Ae?.(r,e):(h(),(t=>t.length<2&&t[0]?.[0]===void 0?t[0]||[,""]:["`",...t])(Er()));s("`",(...r)=>(r=r.map(n),e=>r.map(t=>t(e)).join("")));s("``",(r,...e)=>{r=n(r);let t=[],o=[];for(let p of e)Array.isArray(p)&&p[0]===void 0?t.push(p[1]):o.push(n(p));let i=Object.assign([...t],{raw:t});return p=>r(p)(i,...o.map(m=>m(p)))});f.string["'"]=!0;f.number={"0x":16,"0b":2,"0o":8};export{j as access,l as binary,n as compile,c as cur,Jr as default,I as err,A as expr,R as group,ge as id,u as idx,k as literal,Ir as loc,S as lookup,K as nary,v as next,s as operator,H as operators,ye as parens,f as parse,rr as seek,h as skip,P as space,y as token,C as unary,he as word};
|
package/package.json
CHANGED
|
@@ -1,37 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "subscript",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "10.0.1",
|
|
4
|
+
"description": "Tiny expression parser & evaluator",
|
|
5
5
|
"main": "subscript.js",
|
|
6
6
|
"module": "subscript.js",
|
|
7
7
|
"browser": "subscript.js",
|
|
8
8
|
"types": "./subscript.d.ts",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": "./subscript.js",
|
|
11
|
-
"./parse": "./
|
|
12
|
-
"./compile": "./src/compile.js",
|
|
13
|
-
"./const": "./src/const.js",
|
|
11
|
+
"./parse": "./parse.js",
|
|
14
12
|
"./justin": "./justin.js",
|
|
15
|
-
"./
|
|
16
|
-
"./feature/*": "./feature/*"
|
|
13
|
+
"./jessie": "./jessie.js",
|
|
14
|
+
"./feature/*": "./feature/*",
|
|
15
|
+
"./util/*": "./util/*"
|
|
17
16
|
},
|
|
18
17
|
"type": "module",
|
|
19
18
|
"files": [
|
|
20
|
-
"src",
|
|
21
19
|
"feature",
|
|
20
|
+
"util",
|
|
22
21
|
"subscript.js",
|
|
23
22
|
"subscript.min.js",
|
|
24
23
|
"subscript.d.ts",
|
|
24
|
+
"parse.js",
|
|
25
25
|
"justin.js",
|
|
26
|
-
"justin.min.js"
|
|
26
|
+
"justin.min.js",
|
|
27
|
+
"jessie.js",
|
|
28
|
+
"jessie.min.js"
|
|
27
29
|
],
|
|
28
|
-
"directories": {
|
|
29
|
-
"lib": "lib",
|
|
30
|
-
"src": "src",
|
|
31
|
-
"test": "test"
|
|
32
|
-
},
|
|
33
30
|
"scripts": {
|
|
34
|
-
"build": "esbuild subscript.js --bundle --minify --format=esm --outfile=subscript.min.js && esbuild justin.js --bundle --minify --format=esm --outfile=justin.min.js",
|
|
31
|
+
"build": "esbuild subscript.js --bundle --minify --format=esm --outfile=subscript.min.js && esbuild justin.js --bundle --minify --format=esm --outfile=justin.min.js && esbuild jessie.js --bundle --minify --format=esm --outfile=jessie.min.js",
|
|
35
32
|
"prepublishOnly": "npm run build",
|
|
36
33
|
"test": "node test/test.js",
|
|
37
34
|
"check-types": "tsc --noEmit subscript.d.ts"
|
|
@@ -79,6 +76,8 @@
|
|
|
79
76
|
"devDependencies": {
|
|
80
77
|
"@playwright/test": "^1.57.0",
|
|
81
78
|
"esbuild": "^0.27.2",
|
|
82
|
-
"
|
|
79
|
+
"jsep": "^1.4.0",
|
|
80
|
+
"terser": "^5.44.1",
|
|
81
|
+
"tst": "^9.2.0"
|
|
83
82
|
}
|
|
84
83
|
}
|
package/parse.js
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
// Pratt parser core + operator registry + compile
|
|
2
|
+
// Character codes
|
|
3
|
+
const SPACE = 32;
|
|
4
|
+
|
|
5
|
+
// current string, index
|
|
6
|
+
export let idx, cur,
|
|
7
|
+
|
|
8
|
+
// parse input string to AST
|
|
9
|
+
parse = s => (idx = 0, cur = s, parse.newline = false, s = expr(), cur[idx] ? err() : s || ''),
|
|
10
|
+
|
|
11
|
+
// display error with context
|
|
12
|
+
err = (msg = 'Unexpected token', at = idx,
|
|
13
|
+
lines = cur.slice(0, at).split('\n'),
|
|
14
|
+
last = lines.pop(),
|
|
15
|
+
before = cur.slice(Math.max(0, at - 40), at),
|
|
16
|
+
ptr = '\u032D',
|
|
17
|
+
chr = (cur[at] || '∅') + ptr,
|
|
18
|
+
after = cur.slice(at + 1, at + 20)
|
|
19
|
+
) => {
|
|
20
|
+
throw SyntaxError(`${msg} at ${lines.length + 1}:${last.length + 1}\n${(cur[at-41]!=='\n' ? '...' : '') +before}${chr}${after}`)
|
|
21
|
+
},
|
|
22
|
+
|
|
23
|
+
// attach location to node (returns node for chaining)
|
|
24
|
+
loc = (node, at = idx) => (Array.isArray(node) && (node.loc = at), node),
|
|
25
|
+
|
|
26
|
+
// advance until condition meets
|
|
27
|
+
next = (is, from = idx, l) => {
|
|
28
|
+
while (l = is(cur.charCodeAt(idx))) idx += l;
|
|
29
|
+
return cur.slice(from, idx);
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
// advance n characters
|
|
33
|
+
skip = (n=1) => cur[idx+=n],
|
|
34
|
+
|
|
35
|
+
// set position (for backtracking)
|
|
36
|
+
seek = n => idx = n,
|
|
37
|
+
|
|
38
|
+
// a + b - c
|
|
39
|
+
expr = (prec = 0, end) => {
|
|
40
|
+
let cc, token, newNode, fn, prevReserved = parse.reserved, nl;
|
|
41
|
+
if (end) parse.asi && (parse.newline = false);
|
|
42
|
+
parse.reserved = 0;
|
|
43
|
+
|
|
44
|
+
while (
|
|
45
|
+
(cc = parse.space()) &&
|
|
46
|
+
(nl = parse.newline, 1) &&
|
|
47
|
+
cc !== end &&
|
|
48
|
+
(newNode =
|
|
49
|
+
((fn = lookup[cc]) && fn(token, prec)) ??
|
|
50
|
+
(parse.asi && token && nl && (newNode = parse.asi(token, prec, expr))) ??
|
|
51
|
+
(!token && !parse.reserved && next(parse.id))
|
|
52
|
+
)
|
|
53
|
+
) token = newNode, parse.reserved = 0;
|
|
54
|
+
parse.reserved = prevReserved;
|
|
55
|
+
|
|
56
|
+
if (end) cc == end ? idx++ : err('Unclosed ' + String.fromCharCode(end - (end > 42 ? 2 : 1)));
|
|
57
|
+
|
|
58
|
+
return token;
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
// skip space chars, return first non-space character
|
|
62
|
+
space = parse.space = (cc, from = idx) => {
|
|
63
|
+
while ((cc = cur.charCodeAt(idx)) <= SPACE) {
|
|
64
|
+
if (parse.asi && cc === 10) parse.newline = true
|
|
65
|
+
idx++
|
|
66
|
+
}
|
|
67
|
+
return cc
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
// is char an id?
|
|
71
|
+
id = parse.id = c =>
|
|
72
|
+
(c >= 48 && c <= 57) ||
|
|
73
|
+
(c >= 65 && c <= 90) ||
|
|
74
|
+
(c >= 97 && c <= 122) ||
|
|
75
|
+
c == 36 || c == 95 ||
|
|
76
|
+
(c >= 192 && c != 215 && c != 247),
|
|
77
|
+
|
|
78
|
+
// check if word matches at current position
|
|
79
|
+
word = (w, l = w.length) => cur.substr(idx, l) === w && !parse.id(cur.charCodeAt(idx + l)),
|
|
80
|
+
|
|
81
|
+
// parse (...) group
|
|
82
|
+
parens = () => (skip(), expr(0, 41)),
|
|
83
|
+
|
|
84
|
+
// operator lookup table
|
|
85
|
+
lookup = [],
|
|
86
|
+
|
|
87
|
+
// create operator checker/mapper
|
|
88
|
+
token = (
|
|
89
|
+
op,
|
|
90
|
+
prec = SPACE,
|
|
91
|
+
map,
|
|
92
|
+
c = op.charCodeAt(0),
|
|
93
|
+
l = op.length,
|
|
94
|
+
prev = lookup[c],
|
|
95
|
+
word = op.toUpperCase() !== op,
|
|
96
|
+
matched, r
|
|
97
|
+
) => lookup[c] = (a, curPrec, curOp, from = idx) =>
|
|
98
|
+
(matched = curOp,
|
|
99
|
+
(curOp ?
|
|
100
|
+
op == curOp :
|
|
101
|
+
(l < 2 || (op.charCodeAt(1) === cur.charCodeAt(idx + 1) && (l < 3 || cur.substr(idx, l) == op))) && (!word || !parse.id(cur.charCodeAt(idx + l))) && (matched = curOp = op)
|
|
102
|
+
) &&
|
|
103
|
+
curPrec < prec &&
|
|
104
|
+
(idx += l, (r = map(a)) ? loc(r, from) : (idx = from, matched = 0, word && r !== false && (parse.reserved = 1), !word && !prev && err()), r)
|
|
105
|
+
) ||
|
|
106
|
+
prev?.(a, curPrec, matched),
|
|
107
|
+
|
|
108
|
+
binary = (op, prec, right = false) => token(op, prec, (a, b) => a && (b = expr(prec - (right ? .5 : 0))) && [op, a, b]),
|
|
109
|
+
|
|
110
|
+
unary = (op, prec, post) => token(op, prec, a => post ? (a && [op, a]) : (!a && (a = expr(prec - .5)) && [op, a])),
|
|
111
|
+
|
|
112
|
+
literal = (op, val) => token(op, 200, a => !a && [, val]),
|
|
113
|
+
|
|
114
|
+
nary = (op, prec, right) => {
|
|
115
|
+
token(op, prec,
|
|
116
|
+
(a, b) => (
|
|
117
|
+
b = expr(prec - (right ? .5 : 0)),
|
|
118
|
+
(
|
|
119
|
+
(a?.[0] !== op) && (a = [op, a || null]),
|
|
120
|
+
b?.[0] === op ? a.push(...b.slice(1)) : a.push(b || null),
|
|
121
|
+
a
|
|
122
|
+
))
|
|
123
|
+
)
|
|
124
|
+
},
|
|
125
|
+
|
|
126
|
+
group = (op, prec) => token(op[0], prec, a => (!a && [op, expr(0, op.charCodeAt(1)) || null])),
|
|
127
|
+
|
|
128
|
+
access = (op, prec) => token(op[0], prec, a => (a && [op, a, expr(0, op.charCodeAt(1)) || null]));
|
|
129
|
+
|
|
130
|
+
// === Compile: AST → Evaluator ===
|
|
131
|
+
|
|
132
|
+
// Operator registry
|
|
133
|
+
export const operators = {};
|
|
134
|
+
|
|
135
|
+
// Register an operator (chainable for overrides)
|
|
136
|
+
export const operator = (op, fn, prev = operators[op]) =>
|
|
137
|
+
(operators[op] = (...args) => fn(...args) || prev?.(...args));
|
|
138
|
+
|
|
139
|
+
// Compile AST to evaluator function
|
|
140
|
+
export const compile = node => (
|
|
141
|
+
!Array.isArray(node) ? (node === undefined ? () => undefined : ctx => ctx?.[node]) :
|
|
142
|
+
node[0] === undefined ? (v => () => v)(node[1]) :
|
|
143
|
+
operators[node[0]]?.(...node.slice(1)) ?? err(`Unknown operator: ${node[0]}`, node?.loc)
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
export default parse;
|
package/subscript.d.ts
CHANGED
|
@@ -1,6 +1,46 @@
|
|
|
1
|
-
|
|
1
|
+
// AST node types
|
|
2
|
+
export type Identifier = string;
|
|
3
|
+
export type Literal = [undefined, any];
|
|
4
|
+
export type Operation = [string, ...AST[]];
|
|
5
|
+
export type AST = Identifier | Literal | Operation;
|
|
2
6
|
|
|
3
|
-
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
+
// Evaluator function
|
|
8
|
+
export type Evaluator = (ctx?: any) => any;
|
|
9
|
+
|
|
10
|
+
// Operator compiler: receives args, returns evaluator
|
|
11
|
+
export type Operator = (...args: AST[]) => Evaluator | undefined;
|
|
12
|
+
|
|
13
|
+
// Parse exports
|
|
14
|
+
export let idx: number;
|
|
15
|
+
export let cur: string;
|
|
16
|
+
export function parse(s: string): AST;
|
|
17
|
+
export function err(msg?: string, at?: number): never;
|
|
18
|
+
export function loc<T>(node: T, at?: number): T;
|
|
19
|
+
export function next(is: (c: number) => number, from?: number): string;
|
|
20
|
+
export function skip(n?: number): string;
|
|
21
|
+
export function seek(n: number): number;
|
|
22
|
+
export function expr(prec?: number, end?: number): AST;
|
|
23
|
+
export const lookup: ((a: AST, prec: number, op?: string) => AST)[];
|
|
24
|
+
export function token(op: string, prec?: number, map?: (a: AST) => AST): void;
|
|
25
|
+
export function binary(op: string, prec: number, right?: boolean): void;
|
|
26
|
+
export function unary(op: string, prec: number, post?: boolean): void;
|
|
27
|
+
export function literal(op: string, val: any): void;
|
|
28
|
+
export function nary(op: string, prec: number, right?: boolean): void;
|
|
29
|
+
export function group(op: string, prec: number): void;
|
|
30
|
+
export function access(op: string, prec: number): void;
|
|
31
|
+
|
|
32
|
+
// Compile exports
|
|
33
|
+
export const operators: Record<string, Operator>;
|
|
34
|
+
export function operator(op: string, fn: Operator): void;
|
|
35
|
+
export function compile(node: AST): Evaluator;
|
|
36
|
+
|
|
37
|
+
// Default export
|
|
38
|
+
export default parse;
|
|
39
|
+
|
|
40
|
+
// subscript template tag
|
|
41
|
+
interface Subscript {
|
|
42
|
+
(strings: TemplateStringsArray, ...values: any[]): Evaluator;
|
|
43
|
+
(s: string): Evaluator;
|
|
44
|
+
}
|
|
45
|
+
declare const subscript: Subscript;
|
|
46
|
+
export { subscript };
|
package/subscript.js
CHANGED
|
@@ -1,24 +1,64 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* subscript: Minimal expression parser + compiler
|
|
3
|
+
*
|
|
4
|
+
* Usage:
|
|
5
|
+
* subscript`a + b`(ctx) - template tag, returns compiled evaluator
|
|
6
|
+
* subscript`a + ${x}`(ctx) - interpolations: primitives, objects, AST nodes
|
|
7
|
+
* subscript('a + b')(ctx) - direct call (no caching)
|
|
8
|
+
*
|
|
9
|
+
* For more features:
|
|
10
|
+
* import { parse, compile } from 'subscript/justin.js' // + JSON, arrows, templates
|
|
11
|
+
* import { parse, compile } from 'subscript/jessie.js' // + statements, functions
|
|
3
12
|
*/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import './feature/
|
|
7
|
-
import './feature/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
import './feature/
|
|
11
|
-
import './feature/
|
|
12
|
-
import './feature/
|
|
13
|
-
import './feature/
|
|
14
|
-
import './feature/
|
|
15
|
-
import './feature/
|
|
16
|
-
import './feature/
|
|
17
|
-
|
|
18
|
-
import
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
export
|
|
23
|
-
|
|
24
|
-
|
|
13
|
+
|
|
14
|
+
// Expression features
|
|
15
|
+
import './feature/number.js'; // Decimal numbers: 123, 1.5, 1e3
|
|
16
|
+
import './feature/string.js'; // Double-quoted strings with escapes
|
|
17
|
+
|
|
18
|
+
// Operators (C-family common set) - order matters for token chain performance
|
|
19
|
+
import './feature/op/assignment.js'; // = += -= *= /= %= |= &= ^= >>= <<=
|
|
20
|
+
import './feature/op/logical.js'; // ! && ||
|
|
21
|
+
import './feature/op/bitwise.js'; // ~ | & ^ >> <<
|
|
22
|
+
import './feature/op/comparison.js'; // < > <= >=
|
|
23
|
+
import './feature/op/equality.js'; // == !=
|
|
24
|
+
import './feature/op/arithmetic.js'; // + - * / %
|
|
25
|
+
import './feature/op/increment.js'; // ++ --
|
|
26
|
+
|
|
27
|
+
import './feature/group.js'; // Grouping: (a), sequences: a, b; a; b
|
|
28
|
+
import './feature/access.js'; // Property access: a.b, a[b], f(), [a,b]
|
|
29
|
+
|
|
30
|
+
import { parse, compile } from './parse.js';
|
|
31
|
+
export * from './parse.js';
|
|
32
|
+
|
|
33
|
+
// Cache for compiled templates (keyed by template strings array reference)
|
|
34
|
+
const cache = new WeakMap();
|
|
35
|
+
|
|
36
|
+
// Template tag: subscript`a + b` or subscript`a + ${x}`
|
|
37
|
+
const subscript = (strings, ...values) =>
|
|
38
|
+
// Direct call subscript('code') - strings is just a string
|
|
39
|
+
typeof strings === 'string' ? compile(parse(strings)) :
|
|
40
|
+
// Template literal - use cache
|
|
41
|
+
cache.get(strings) || cache.set(strings, compileTemplate(strings, values)).get(strings);
|
|
42
|
+
|
|
43
|
+
// Compile template with placeholders (using Private Use Area chars)
|
|
44
|
+
const PUA = 0xE000;
|
|
45
|
+
const compileTemplate = (strings, values) => {
|
|
46
|
+
const code = strings.reduce((acc, s, i) => acc + (i ? String.fromCharCode(PUA + i - 1) : '') + s, '');
|
|
47
|
+
const ast = parse(code);
|
|
48
|
+
const inject = node => {
|
|
49
|
+
if (typeof node === 'string' && node.length === 1) {
|
|
50
|
+
let i = node.charCodeAt(0) - PUA, v;
|
|
51
|
+
if (i >= 0 && i < values.length) return v = values[i], isAST(v) ? v : [, v];
|
|
52
|
+
}
|
|
53
|
+
return Array.isArray(node) ? node.map(inject) : node;
|
|
54
|
+
};
|
|
55
|
+
return compile(inject(ast));
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
// Detect AST node vs regular value
|
|
59
|
+
// AST: string (identifier), or array with string/undefined first element
|
|
60
|
+
const isAST = v =>
|
|
61
|
+
typeof v === 'string' ||
|
|
62
|
+
(Array.isArray(v) && (typeof v[0] === 'string' || v[0] === undefined));
|
|
63
|
+
|
|
64
|
+
export default subscript;
|
package/subscript.min.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
var
|
|
2
|
-
`),t
|
|
3
|
-
|
|
4
|
-
`)
|
|
1
|
+
var l,f,u=r=>(l=0,f=r,u.newline=!1,r=A(),f[l]?y():r||""),y=(r="Unexpected token",e=l,t=f.slice(0,e).split(`
|
|
2
|
+
`),o=t.pop(),i=f.slice(Math.max(0,e-40),e),p="\u032D",c=(f[e]||"\u2205")+p,d=f.slice(e+1,e+20))=>{throw SyntaxError(`${r} at ${t.length+1}:${o.length+1}
|
|
3
|
+
${(f[e-41]!==`
|
|
4
|
+
`?"...":"")+i}${c}${d}`)},er=(r,e=l)=>(Array.isArray(r)&&(r.loc=e),r),S=(r,e=l,t)=>{for(;t=r(f.charCodeAt(l));)l+=t;return f.slice(e,l)},E=(r=1)=>f[l+=r],Pr=r=>l=r,A=(r=0,e)=>{let t,o,i,p,c=u.reserved,d;for(e&&u.asi&&(u.newline=!1),u.reserved=0;(t=u.space())&&(d=u.newline,1)&&t!==e&&(i=((p=g[t])&&p(o,r))??(u.asi&&o&&d&&(i=u.asi(o,r,A)))??(!o&&!u.reserved&&S(u.id)));)o=i,u.reserved=0;return u.reserved=c,e&&(t==e?l++:y("Unclosed "+String.fromCharCode(e-(e>42?2:1)))),o},Ur=u.space=(r,e=l)=>{for(;(r=f.charCodeAt(l))<=32;)u.asi&&r===10&&(u.newline=!0),l++;return r},Mr=u.id=r=>r>=48&&r<=57||r>=65&&r<=90||r>=97&&r<=122||r==36||r==95||r>=192&&r!=215&&r!=247,Rr=(r,e=r.length)=>f.substr(l,e)===r&&!u.id(f.charCodeAt(l+e)),Dr=()=>(E(),A(0,41)),g=[],h=(r,e=32,t,o=r.charCodeAt(0),i=r.length,p=g[o],c=r.toUpperCase()!==r,d,I)=>g[o]=(k,X,T,Q=l)=>(d=T,(T?r==T:(i<2||r.charCodeAt(1)===f.charCodeAt(l+1)&&(i<3||f.substr(l,i)==r))&&(!c||!u.id(f.charCodeAt(l+i)))&&(d=T=r))&&X<e&&(l+=i,(I=t(k))?er(I,Q):(l=Q,d=0,c&&I!==!1&&(u.reserved=1),!c&&!p&&y()),I)||p?.(k,X,d)),m=(r,e,t=!1)=>h(r,e,(o,i)=>o&&(i=A(e-(t?.5:0)))&&[r,o,i]),C=(r,e,t)=>h(r,e,o=>t?o&&[r,o]:!o&&(o=A(e-.5))&&[r,o]),Lr=(r,e)=>h(r,200,t=>!t&&[,e]),D=(r,e,t)=>{h(r,e,(o,i)=>(i=A(e-(t?.5:0)),o?.[0]!==r&&(o=[r,o||null]),i?.[0]===r?o.push(...i.slice(1)):o.push(i||null),o))},B=(r,e)=>h(r[0],e,t=>!t&&[r,A(0,r.charCodeAt(1))||null]),L=(r,e)=>h(r[0],e,t=>t&&[r,t,A(0,r.charCodeAt(1))||null]),R={},s=(r,e,t=R[r])=>R[r]=(...o)=>e(...o)||t?.(...o),n=r=>Array.isArray(r)?r[0]===void 0?(e=>()=>e)(r[1]):R[r[0]]?.(...r.slice(1))??y(`Unknown operator: ${r[0]}`,r?.loc):r===void 0?()=>{}:e=>e?.[r];var _=46,w=48,v=57,tr=69,or=101,nr=43,ir=45,sr=97,lr=102,pr=65,ur=70,$=r=>[,(r=+S(e=>e===_&&f.charCodeAt(l+1)!==_||e>=w&&e<=v||((e===tr||e===or)&&((e=f.charCodeAt(l+1))>=w&&e<=v||e===nr||e===ir)?2:0)))!=r?y():r],mr={2:r=>r===48||r===49,8:r=>r>=48&&r<=55,16:r=>r>=w&&r<=v||r>=sr&&r<=lr||r>=pr&&r<=ur};u.number=null;g[_]=r=>!r&&f.charCodeAt(l+1)!==_&&$();for(let r=w;r<=v;r++)g[r]=e=>e?void 0:$();g[w]=r=>{if(r)return;let e=u.number;if(e){for(let[t,o]of Object.entries(e))if(t[0]==="0"&&f[l+1]?.toLowerCase()===t[1])return E(2),[,parseInt(S(mr[o]),o)]}return $()};var fr=92,H=34,G=39,dr={n:`
|
|
5
|
+
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},W=r=>(e,t,o="")=>{if(!(e||!u.string?.[String.fromCharCode(r)]))return E(),S(i=>i-r&&(i===fr?(o+=dr[f[l+1]]||f[l+1],2):(o+=f[l],1))),f[l]===String.fromCharCode(r)?E():y("Bad string"),[,o]};g[H]=W(H);g[G]=W(G);u.string={'"':!0};var cr=20;"= += -= *= /= %= |= &= ^= >>= <<=".split(" ").map(r=>m(r,cr,!0));var J=(r,e,t,o)=>typeof r=="string"?i=>e(i,r,i):r[0]==="."?(t=n(r[1]),o=r[2],i=>e(t(i),o,i)):r[0]==="[]"&&r.length===3?(t=n(r[1]),o=n(r[2]),i=>e(t(i),o(i),i)):r[0]==="()"&&r.length===2?J(r[1],e):(()=>{throw Error("Invalid assignment target")})(),z={"=":(r,e,t)=>r[e]=t,"+=":(r,e,t)=>r[e]+=t,"-=":(r,e,t)=>r[e]-=t,"*=":(r,e,t)=>r[e]*=t,"/=":(r,e,t)=>r[e]/=t,"%=":(r,e,t)=>r[e]%=t,"|=":(r,e,t)=>r[e]|=t,"&=":(r,e,t)=>r[e]&=t,"^=":(r,e,t)=>r[e]^=t,">>=":(r,e,t)=>r[e]>>=t,"<<=":(r,e,t)=>r[e]<<=t};for(let r in z)s(r,(e,t)=>(t=n(t),J(e,(o,i,p)=>z[r](o,i,t(p)))));var Ar=30,gr=40,K=140;m("!",K);C("!",K);m("||",Ar);m("&&",gr);s("!",r=>(r=n(r),e=>!r(e)));s("||",(r,e)=>(r=n(r),e=n(e),t=>r(t)||e(t)));s("&&",(r,e)=>(r=n(r),e=n(e),t=>r(t)&&e(t)));var hr=50,yr=60,Cr=70,V=100,Sr=140;m("|",hr);m("&",Cr);m("^",yr);m(">>",V);m("<<",V);C("~",Sr);s("~",r=>(r=n(r),e=>~r(e)));s("|",(r,e)=>(r=n(r),e=n(e),t=>r(t)|e(t)));s("&",(r,e)=>(r=n(r),e=n(e),t=>r(t)&e(t)));s("^",(r,e)=>(r=n(r),e=n(e),t=>r(t)^e(t)));s(">>",(r,e)=>(r=n(r),e=n(e),t=>r(t)>>e(t)));s("<<",(r,e)=>(r=n(r),e=n(e),t=>r(t)<<e(t)));var P=90;m("<",P);m(">",P);m("<=",P);m(">=",P);s(">",(r,e)=>(r=n(r),e=n(e),t=>r(t)>e(t)));s("<",(r,e)=>(r=n(r),e=n(e),t=>r(t)<e(t)));s(">=",(r,e)=>(r=n(r),e=n(e),t=>r(t)>=e(t)));s("<=",(r,e)=>(r=n(r),e=n(e),t=>r(t)<=e(t)));var Y=80;m("==",Y);m("!=",Y);s("==",(r,e)=>(r=n(r),e=n(e),t=>r(t)==e(t)));s("!=",(r,e)=>(r=n(r),e=n(e),t=>r(t)!=e(t)));var Z=110,F=120,q=140;m("+",Z);m("-",Z);m("*",F);m("/",F);m("%",F);C("+",q);C("-",q);s("+",(r,e)=>e!==void 0?(r=n(r),e=n(e),t=>r(t)+e(t)):(r=n(r),t=>+r(t)));s("-",(r,e)=>e!==void 0?(r=n(r),e=n(e),t=>r(t)-e(t)):(r=n(r),t=>-r(t)));s("*",(r,e)=>(r=n(r),e=n(e),t=>r(t)*e(t)));s("/",(r,e)=>(r=n(r),e=n(e),t=>r(t)/e(t)));s("%",(r,e)=>(r=n(r),e=n(e),t=>r(t)%e(t)));var U=150;h("++",U,r=>r?["++",r,null]:["++",A(U-1)]);h("--",U,r=>r?["--",r,null]:["--",A(U-1)]);var N=(r,e,t,o)=>typeof r=="string"?i=>e(i,r):r[0]==="."?(t=n(r[1]),o=r[2],i=>e(t(i),o)):r[0]==="[]"&&r.length===3?(t=n(r[1]),o=n(r[2]),i=>e(t(i),o(i))):r[0]==="()"&&r.length===2?N(r[1],e):(()=>{throw Error("Invalid increment target")})();s("++",(r,e)=>N(r,e===null?(t,o)=>t[o]++:(t,o)=>++t[o]));s("--",(r,e)=>N(r,e===null?(t,o)=>t[o]--:(t,o)=>--t[o]));var Er=5,wr=10,Ir=170;B("()",Ir);D(",",wr);D(";",Er,!0);var x=(...r)=>(r=r.map(n),e=>{let t;for(let o of r)t=o(e);return t});s(",",x);s(";",x);var j=r=>r?.[0]==="_"&&r[1]==="_"||r==="constructor"||r==="prototype",O=170;L("[]",O);m(".",O);L("()",O);var M=r=>{throw Error(r)};s("[]",(r,e)=>e===void 0?(r=r?r[0]===","?r.slice(1):[r]:[],r=r.map(t=>t==null?(()=>{}):t[0]==="..."?(t=n(t[1]),o=>t(o)):(t=n(t),o=>[t(o)])),t=>r.flatMap(o=>o(t))):(e==null&&M("Missing index"),r=n(r),e=n(e),t=>{let o=e(t);return j(o)?void 0:r(t)[o]}));s(".",(r,e)=>(r=n(r),e=e[0]?e:e[1],j(e)?()=>{}:t=>r(t)[e]));s("()",(r,e)=>{if(e===void 0)return r==null?M("Empty ()"):n(r);let t=i=>i?.[0]===","&&i.slice(1).some(p=>p==null||t(p));t(e)&&M("Empty argument");let o=e?e[0]===","?(e=e.slice(1).map(n),i=>e.map(p=>p(i))):(e=n(e),i=>[e(i)]):()=>[];return a(r,(i,p,c)=>i[p](...o(c)))});var a=(r,e,t,o)=>r==null?M("Empty ()"):r[0]==="()"&&r.length==2?a(r[1],e):typeof r=="string"?i=>e(i,r,i):r[0]==="."?(t=n(r[1]),o=r[2],i=>e(t(i),o,i)):r[0]==="?."?(t=n(r[1]),o=r[2],i=>{let p=t(i);return p==null?void 0:e(p,o,i)}):r[0]==="[]"&&r.length===3?(t=n(r[1]),o=n(r[2]),i=>e(t(i),o(i),i)):r[0]==="?.[]"?(t=n(r[1]),o=n(r[2]),i=>{let p=t(i);return p==null?void 0:e(p,o(i),i)}):(r=n(r),i=>e([r(i)],0,i));var b=new WeakMap,Tr=(r,...e)=>typeof r=="string"?n(u(r)):b.get(r)||b.set(r,_r(r,e)).get(r),rr=57344,_r=(r,e)=>{let t=r.reduce((p,c,d)=>p+(d?String.fromCharCode(rr+d-1):"")+c,""),o=u(t),i=p=>{if(typeof p=="string"&&p.length===1){let c=p.charCodeAt(0)-rr,d;if(c>=0&&c<e.length)return d=e[c],vr(d)?d:[,d]}return Array.isArray(p)?p.map(i):p};return n(i(o))},vr=r=>typeof r=="string"||Array.isArray(r)&&(typeof r[0]=="string"||r[0]===void 0),ne=Tr;export{L as access,m as binary,n as compile,f as cur,ne as default,y as err,A as expr,B as group,Mr as id,l as idx,Lr as literal,er as loc,g as lookup,D as nary,S as next,s as operator,R as operators,Dr as parens,u as parse,Pr as seek,E as skip,Ur as space,h as token,C as unary,Rr as word};
|