subscript 10.3.6 → 10.4.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 +9 -2
- package/eval/access.js +57 -0
- package/eval/accessor.js +19 -0
- package/eval/async.js +13 -0
- package/eval/class.js +35 -0
- package/eval/collection.js +41 -0
- package/eval/function.js +37 -0
- package/eval/if.js +7 -0
- package/eval/jessie.js +19 -0
- package/eval/justin.js +21 -0
- package/eval/loop.js +108 -0
- package/eval/module.js +8 -0
- package/eval/op/arithmetic.js +12 -0
- package/eval/op/arrow.js +35 -0
- package/eval/op/assign-logical.js +23 -0
- package/eval/op/assignment.js +15 -0
- package/eval/op/bitwise-unsigned.js +8 -0
- package/eval/op/bitwise.js +9 -0
- package/eval/op/comparison.js +7 -0
- package/eval/op/defer.js +4 -0
- package/eval/op/equality.js +5 -0
- package/eval/op/identity.js +5 -0
- package/eval/op/increment.js +13 -0
- package/eval/op/logical.js +6 -0
- package/eval/op/membership.js +4 -0
- package/eval/op/nullish.js +4 -0
- package/eval/op/optional.js +38 -0
- package/eval/op/pow.js +8 -0
- package/eval/op/range.js +13 -0
- package/eval/op/spread.js +4 -0
- package/eval/op/ternary.js +4 -0
- package/eval/op/type.js +5 -0
- package/eval/op/unary.js +24 -0
- package/eval/prop.js +16 -0
- package/eval/regex.js +7 -0
- package/eval/seq.js +10 -0
- package/eval/subscript.js +15 -0
- package/eval/switch.js +27 -0
- package/eval/template.js +14 -0
- package/eval/try.js +36 -0
- package/eval/unit.js +10 -0
- package/eval/var.js +69 -0
- package/feature/access.js +2 -58
- package/feature/accessor.js +2 -21
- package/feature/asi.js +55 -11
- package/feature/async.js +2 -14
- package/feature/class.js +2 -35
- package/feature/collection.js +2 -43
- package/feature/function.js +2 -39
- package/feature/if.js +2 -8
- package/feature/jessie.js +32 -0
- package/feature/justin.js +36 -0
- package/feature/loop.js +2 -109
- package/feature/module.js +1 -10
- package/feature/op/arithmetic.js +2 -13
- package/feature/op/arrow.js +2 -38
- package/feature/op/assign-logical.js +3 -24
- package/feature/op/assignment.js +2 -18
- package/feature/op/bitwise-unsigned.js +2 -8
- package/feature/op/bitwise.js +2 -14
- package/feature/op/comparison.js +2 -8
- package/feature/op/defer.js +2 -7
- package/feature/op/equality.js +2 -7
- package/feature/op/identity.js +2 -6
- package/feature/op/increment.js +2 -14
- package/feature/op/logical.js +2 -8
- package/feature/op/membership.js +2 -7
- package/feature/op/nullish.js +2 -5
- package/feature/op/optional.js +2 -41
- package/feature/op/pow.js +2 -10
- package/feature/op/range.js +2 -16
- package/feature/op/spread.js +2 -7
- package/feature/op/ternary.js +2 -7
- package/feature/op/type.js +2 -8
- package/feature/op/unary.js +2 -27
- package/feature/prop.js +2 -17
- package/feature/regex.js +3 -12
- package/feature/seq.js +2 -11
- package/feature/shebang.js +7 -0
- package/feature/subscript.js +23 -0
- package/feature/switch.js +2 -28
- package/feature/template.js +4 -16
- package/feature/try.js +4 -38
- package/feature/unit.js +4 -7
- package/feature/var.js +2 -70
- package/jessie.js +4 -25
- package/jessie.min.js +9 -8
- package/justin.js +4 -30
- package/justin.min.js +8 -8
- package/package.json +9 -1
- package/parse.js +27 -29
- package/subscript.js +7 -16
- package/subscript.min.js +5 -5
package/jessie.min.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
var
|
|
2
|
-
`),
|
|
3
|
-
${
|
|
4
|
-
`,""+
|
|
5
|
-
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},
|
|
6
|
-
`,"/*":"*/"};var
|
|
7
|
-
`)for(;
|
|
8
|
-
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},
|
|
1
|
+
var u,c,l=r=>(u=0,c=r,l.enter?.(),r=a(),c[u]?R():r||""),R=(r="Unexpected token",t=u,e=c.slice(0,t).split(`
|
|
2
|
+
`),o=e.pop(),n=c.slice(Math.max(0,t-40),t),p="\u032D",m=(c[t]||" ")+p,f=c.slice(t+1,t+20))=>{throw SyntaxError(`${r} at ${e.length+1}:${o.length+1}
|
|
3
|
+
${c[t-41]!==`
|
|
4
|
+
`,""+n}${m}${f}`)},vr=(r,t=u)=>(Array.isArray(r)&&(r.loc=t),r),N=(r,t=u,e)=>{for(;e=r(c.charCodeAt(u));)u+=e;return c.slice(t,u)},h=(r=1)=>c[u+=r],O=r=>u=r,a=(r=0,t)=>{let e,o,n;for(t&&l.enter?.(r,t);(e=d())&&e!==t&&(n=fr(o,r,e,a));)o=n;return t&&(e==t?(u++,l.exit?.(r,t)):R("Unclosed "+String.fromCharCode(t-(t>42?2:1)))),o},fr=(r,t,e,o,n)=>(n=T[e])&&n(r,t)||(r?null:N(l.id)||null),d=r=>{for(;(r=c.charCodeAt(u))<=32;)u++;return r},Z=(r=u)=>{for(;c.charCodeAt(r)<=32;)r++;return c.charCodeAt(r)},je=l.id=r=>r>=48&&r<=57||r>=65&&r<=90||r>=97&&r<=122||r==36||r==95||r>=192&&r!=215&&r!=247,I=(r,t=r.length)=>c.substr(u,t)===r&&!l.id(c.charCodeAt(u+t)),v=()=>(h(),a(0,41)),T=[],$={},k=(r,t=32,e,o=r.charCodeAt(0),n=r.length,p=T[o],m=r.toUpperCase()!==r,f,A)=>(t=$[r]=!p&&$[r]||t,T[o]=(g,S,E,C=u)=>(f=E,(E?r==E:(n<2||r.charCodeAt(1)===c.charCodeAt(u+1)&&(n<3||c.substr(u,n)==r))&&(!m||!l.id(c.charCodeAt(u+n)))&&(f=E=r))&&S<t&&(u+=n,(A=e(g))?vr(A,C):(u=C,f=0,!m&&!p&&!g&&R()),A)||p?.(g,S,f))),y=(r,t,e=!1)=>k(r,t,o=>o&&(n=>n&&[r,o,n])(a(t-(e?.5:0)))),P=(r,t,e)=>k(r,t,o=>e?o&&[r,o]:!o&&(o=a(t-.5))&&[r,o]),Q=(r,t)=>k(r,200,e=>!e&&[,t]),lr=(r,t,e)=>k(r,t,(o,n)=>(n=a(t-(e?.5:0)),o?.[0]!==r&&(o=[r,o||null]),n?.[0]===r?o.push(...n.slice(1)):o.push(n||null),o)),W=(r,t)=>k(r[0],t,e=>!e&&[r,a(0,r.charCodeAt(1))||null]),mr=(r,t)=>k(r[0],t,e=>e&&[r,e,a(0,r.charCodeAt(1))||null]),w=(r,t,e,o=r.charCodeAt(0),n=r.length,p=T[o],m)=>T[o]=(f,A,g,S=u)=>!f&&(g?r==g:(n<2||c.substr(u,n)==r)&&(g=r))&&A<t&&!l.id(c.charCodeAt(u+n))&&(!l.prop||l.prop(u+n))&&(O(u+n),(m=e())?vr(m,S):O(S),m)||p?.(f,A,g);Object.defineProperty(l,"space",{configurable:!0,enumerable:!0,get:()=>d,set:r=>d=r});Object.defineProperty(l,"step",{configurable:!0,enumerable:!0,get:()=>fr,set:r=>fr=r});var ur={},s=(r,t,e=ur[r])=>ur[r]=(...o)=>t(...o)||e?.(...o),i=r=>Array.isArray(r)?r[0]==null?(t=>()=>t)(r[1]):ur[r[0]]?.(...r.slice(1))??R(`Unknown operator: ${r[0]}`,r?.loc):r===void 0?()=>{}:t=>t?.[r];var x=46,z=48,b=57,at=69,ht=101,At=43,yt=45,q=95,Br=110,gt=97,wt=102,Ct=65,Et=70,Mr=r=>r.indexOf("_")<0?r:r.replaceAll("_",""),cr=r=>{let t=Mr(N(e=>e===x&&c.charCodeAt(u+1)!==x||e>=z&&e<=b||e===q||((e===at||e===ht)&&((e=c.charCodeAt(u+1))>=z&&e<=b||e===At||e===yt)?2:0)));return c.charCodeAt(u)===Br?(h(),[,BigInt(t)]):(r=+t)!=r?R():[,r]},St={2:r=>r===48||r===49||r===q,8:r=>r>=48&&r<=55||r===q,16:r=>r>=z&&r<=b||r>=gt&&r<=wt||r>=Ct&&r<=Et||r===q};l.number=null;T[x]=r=>!r&&c.charCodeAt(u+1)!==x&&cr();for(let r=z;r<=b;r++)T[r]=t=>t?void 0:cr();T[z]=r=>{if(r)return;let t=l.number;if(t){for(let[e,o]of Object.entries(t))if(e[0]==="0"&&c[u+1]?.toLowerCase()===e[1]){h(2);let n=Mr(N(St[o]));return c.charCodeAt(u)===Br?(h(),[,BigInt("0"+e[1]+n)]):[,parseInt(n,o)]}}return cr()};var kt=92,Lr=34,Ur=39,It={n:`
|
|
5
|
+
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},Dr=r=>(t,e,o="")=>{if(!(t||!l.string?.[String.fromCharCode(r)]))return h(),N(n=>n-r&&(n===kt?(o+=It[c[u+1]]||c[u+1],2):(o+=c[u],1))),c[u]===String.fromCharCode(r)?h():R("Bad string"),[,o]};T[Lr]=Dr(Lr);T[Ur]=Dr(Ur);l.string={'"':!0};var Tt=20;"= += -= *= /= %= |= &= ^= >>= <<=".split(" ").map(r=>y(r,Tt,!0));var Nt=30,Rt=40,_t=140;P("!",_t);y("||",Nt);y("&&",Rt);var Ot=50,Pt=60,vt=70,Fr=100,Bt=140;y("|",Ot);y("&",vt);y("^",Pt);y(">>",Fr);y("<<",Fr);P("~",Bt);var rr=90;y("<",rr);y(">",rr);y("<=",rr);y(">=",rr);var Gr=80;y("==",Gr);y("!=",Gr);var Xr=110,dr=120,Kr=140;y("+",Xr);y("-",Xr);y("*",dr);y("/",dr);y("%",dr);P("+",Kr);P("-",Kr);var tr=150;k("++",tr,r=>r?["++",r,null]:["++",a(tr-1)]);k("--",tr,r=>r?["--",r,null]:["--",a(tr-1)]);var Mt=5,Lt=10;lr(",",Lt);lr(";",Mt,!0);var Ut=170;W("()",Ut);var ar=170;mr("[]",ar);y(".",ar);mr("()",ar);var Dt=32,Ft=l.space;l.comment??={"//":`
|
|
6
|
+
`,"/*":"*/"};var hr;l.space=()=>{hr||(hr=Object.entries(l.comment).map(([n,p])=>[n,p,n.charCodeAt(0)]));for(var r;r=Ft();){for(var t=0,e;e=hr[t++];)if(r===e[2]&&c.substr(u,e[0].length)===e[0]){var o=u+e[0].length;if(e[1]===`
|
|
7
|
+
`)for(;c.charCodeAt(o)>=Dt;)o++;else{for(;c[o]&&c.substr(o,e[1].length)!==e[1];)o++;c[o]&&(o+=e[1].length)}O(o),r=0;break}if(r)return r}return r};var Hr=80;y("===",Hr);y("!==",Hr);var Gt=30;y("??",Gt);var Xt=130,Kt=20;y("**",Xt,!0);y("**=",Kt,!0);var jr=90;y("in",jr);y("of",jr);var Ht=20,jt=100;y(">>>",jt);y(">>>=",Ht,!0);var Ar=20;y("||=",Ar,!0);y("&&=",Ar,!0);y("??=",Ar,!0);Q("true",!0);Q("false",!1);Q("null",null);w("undefined",200,()=>[]);Q("NaN",NaN);Q("Infinity",1/0);var yr=20;k("?",yr,(r,t,e)=>r&&(t=a(yr-1))&&N(o=>o===58)&&(e=a(yr-1),["?",r,t,e]));var Qt=20;y("=>",Qt,!0);var $t=140;P("...",$t);var Qr=170;k("?.",Qr,(r,t)=>{if(!r)return;let e=d();return e===40?(h(),["?.()",r,a(0,41)||null]):e===91?(h(),["?.[]",r,a(0,93)]):(t=a(Qr),t?["?.",r,t]:void 0)});var J=140;P("typeof",J);P("void",J);P("delete",J);w("new",J,()=>I(".target")?(h(7),["new.target"]):["new",a(J)]);var Wt=20,$r=200;l.prop=r=>Z(r)!==58;W("[]",$r);W("{}",$r);y(":",Wt-1,!0);var zt=170,er=96,Jt=36,Vt=123,Yt=92,Zt={n:`
|
|
8
|
+
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},Wr=()=>{let r=[];for(let t="",e;(e=c.charCodeAt(u))!==er;)e?e===Yt?(h(),t+=Zt[c[u]]||c[u],h()):e===Jt&&c.charCodeAt(u+1)===Vt?(t&&r.push([,t]),t="",h(2),r.push(a(0,125))):(t+=c[u],h(),e=c.charCodeAt(u),e===er&&t&&r.push([,t])):R("Unterminated template");return h(),r},qt=T[er];T[er]=(r,t)=>r&&t<zt?l.asi&&l.newline?void 0:(h(),["``",r,...Wr()]):r?qt?.(r,t):(h(),(e=>e.length<2&&e[0]?.[0]===void 0?e[0]||[,""]:["`",...e])(Wr()));l.string["'"]=!0;l.number={"0x":16,"0b":2,"0o":8};var xt=92,bt=117,re=123,te=125,ee=183,oe=l.id,zr=r=>r>=48&&r<=57||r>=65&&r<=70||r>=97&&r<=102,ne=(r=u+2,t,e=0,o=0)=>{if(c.charCodeAt(u)!==xt||c.charCodeAt(u+1)!==bt)return 0;if(c.charCodeAt(r)===re){for(;zr(t=c.charCodeAt(++r));)e=e*16+(t<=57?t-48:(t&31)+9);return r>u+3&&e<=1114111&&c.charCodeAt(r)===te?r-u+1:0}for(;o<4&&zr(c.charCodeAt(r+o));)o++;return o===4?6:0};l.id=r=>oe(r)||r===ee||ne();var gr=5,ie=10,se=20,Jr=r=>{if(r==="let"){let e=u;if(d(),I("in")){O(e);return}O(e)}let t=a(ie-1);return t?.[0]==="in"||t?.[0]==="of"?[t[0],[r,t[1]],t[2]]:t?.[0]===","?[r,...t.slice(1)]:[r,t]};w("let",gr+1,()=>Jr("let"));w("const",gr+1,()=>Jr("const"));w("var",gr,()=>(d(),["var",a(se)]));var or=5,pe=59,M=()=>(d()===123||R("Expected {"),h(),a(or-.5,125)||null),D=()=>d()!==123?a(or+.5):(h(),a(or-.5,125)||null),fe=()=>{let r=u;return d()===pe&&h(),d(),I("else")?(h(4),!0):(O(r),!1)};w("if",or+1,()=>{d();let r=["if",v(),D()];return fe()&&r.push(D()),r});var ue=200;w("function",ue,()=>{d();let r=!1;c[u]==="*"&&(r=!0,h(),d());let t=N(l.id);return t&&d(),r?["function*",t,v()||null,M()]:["function",t,v()||null,M()]});var nr=140,wr=20;P("await",nr);w("yield",nr,()=>(d(),c[u]==="*"?(h(),d(),["yield*",a(wr)]):["yield",a(wr)]));w("async",nr,()=>{if(d(),I("function"))return["async",a(nr)];let r=a(wr-.5);return r&&["async",r]});var Cr=200,le=140,me=90;P("static",le);y("instanceof",me);k("#",Cr,r=>{if(r)return;let t=N(l.id);return t?"#"+t:void 0});w("class",Cr,()=>{d();let r=N(l.id)||null;if(r==="extends")r=null,d();else{if(d(),!I("extends"))return["class",r,null,M()];h(7),d()}return["class",r,a(Cr),M()]});var ce=140,Er=47,de=92,ae=r=>r===de?2:r&&r!==Er,he=r=>r===103||r===105||r===109||r===115||r===117||r===121;k("/",ce,r=>{if(r)return;let t=c.charCodeAt(u);if(t===Er||t===42||t===43||t===63||t===61)return;let e=N(ae);c.charCodeAt(u)===Er||R("Unterminated regex"),h();let o=N(he);try{new RegExp(e,o)}catch(n){R("Invalid regex: "+n.message)}return o?["//",e,o]:["//",e]});var H=5,V=125,Y=59;w("while",H+1,()=>(d(),["while",v(),D()]));w("do",H+1,()=>(r=>(d(),h(5),d(),["do",r,v()]))(D()));w("for",H+1,()=>(d(),I("await")?(h(5),d(),["for await",v(),D()]):["for",v(),D()]));w("break",H+1,()=>{l.asi&&(l.newline=!1);let r=u;d();let t=c.charCodeAt(u);if(!t||t===V||t===Y||l.newline)return["break"];let e=N(l.id);if(!e)return["break"];d();let o=c.charCodeAt(u);return!o||o===V||o===Y||l.newline?["break",e]:(O(r),["break"])});w("continue",H+1,()=>{l.asi&&(l.newline=!1);let r=u;d();let t=c.charCodeAt(u);if(!t||t===V||t===Y||l.newline)return["continue"];let e=N(l.id);if(!e)return["continue"];d();let o=c.charCodeAt(u);return!o||o===V||o===Y||l.newline?["continue",e]:(O(r),["continue"])});w("return",H+1,()=>{l.asi&&(l.newline=!1);let r=d();return!r||r===V||r===Y||l.newline?["return"]:["return",a(H)]});var Sr=5;w("try",Sr+1,()=>{let r=["try",M()];return d(),I("catch")&&(h(5),d(),r.push(["catch",Z()===40?v():null,M()])),d(),I("finally")&&(h(7),r.push(["finally",M()])),r});w("throw",Sr+1,()=>{if(l.asi&&(l.newline=!1),d(),l.newline)throw SyntaxError("Unexpected newline after throw");return["throw",a(Sr)]});var Zr=5,Ae=20,Vr=58,ye=59,qr=125,kr=0,xr=(r,t=r.length,e=r.charCodeAt(0),o=T[e])=>T[e]=(n,p,m)=>I(r)&&!n&&kr||o?.(n,p,m);xr("case");xr("default");var Yr=r=>{let t=[];for(;(r=d())!==qr&&!I("case")&&!I("default");){if(r===ye){h();continue}t.push(a(Zr-.5))||R()}return t.length>1?[";",...t]:t[0]||null},ge=()=>{d()===123||R("Expected {"),h(),kr++;let r=[];try{for(;d()!==qr;)if(I("case")){O(u+4),d();let t=a(Ae-.5);d()===Vr&&h(),r.push(["case",t,Yr()])}else I("default")?(O(u+7),d()===Vr&&h(),r.push(["default",Yr()])):R("Expected case or default")}finally{kr--}return h(),r};w("switch",Zr+1,()=>d()===40&&["switch",v(),...ge()]);var br=5;w("debugger",br+1,()=>["debugger"]);w("with",br+1,()=>(d(),["with",v(),D()]));var Ir=5,j=10,rt=42,we=T[rt];T[rt]=(r,t)=>r?we?.(r,t):(h(),"*");k("from",j+1,r=>r?r[0]!=="="&&r[0]!==","&&(d(),["from",r,a(j+1)]):!1);k("as",j+2,r=>r?(d(),["as",r,a(j+2)]):!1);w("import",Ir,()=>I(".meta")?(h(5),["import.meta"]):["import",a(j)]);w("export",Ir,()=>(d(),["export",a(Ir)]));w("default",j+1,()=>d()!==58&&(d(),["default",a(j)]));var Tr=20,Ce=40,tt=41,et=123,ot=125,nt=r=>t=>{if(t)return;d();let e=N(l.id);if(!e||(d(),c.charCodeAt(u)!==Ce))return!1;h();let o=a(0,tt);return d(),c.charCodeAt(u)!==et?!1:(h(),[r,e,o,a(0,ot)])};k("get",Tr-1,nt("get"));k("set",Tr-1,nt("set"));k("(",Tr-1,r=>{if(!r||typeof r!="string")return;let t=a(0,tt)||null;if(d(),c.charCodeAt(u)===et)return h(),[":",r,["=>",["()",t],a(0,ot)||null]]});l.comment["#!"]=`
|
|
9
|
+
`;var st=32,_r=10,Ee=59,Se=125,ke=91,Ie=40,Rr=$.asi??$[";"],Te=l._baseSpace??=l.space,Ne=l._baseStep??=l.step,Re=(r,t)=>{for(;(t=c.charCodeAt(r))<=st;){if(t===_r)return!0;r++}return!1},_e=(r=u,t)=>{for(;r-- >0&&(t=c.charCodeAt(r))<=st;)if(t===_r)return!0;return!1};l.space=(r,t)=>{for(;;){for(t=u,r=Te();t<u;)if(c.charCodeAt(t++)===_r){l.newline=!0;break}if(r===Ee&&Re(u+1)){O(u+1),l.newline=l.semi=!0;continue}return r}};l.enter=()=>l.newline=l.semi=!1;l.exit=(r,t)=>{t===Se&&(l.newline=!0)};l.step=(r,t,e,o)=>{if(l.semi&&t>=Rr)return!1;if(r&&(l.semi||(e===ke||e===Ie)&&_e()))return it(r,t,o)??null;let n=l.newline;return Ne(r,t,e,o)??(r&&n?it(r,t,o)??null:null)};var Nr=0,Oe=100,it=l.asi=(r,t,e,o,n)=>{if(t>=Rr||Nr>=Oe)return;l.semi=!1;let p=u;Nr++;try{o=e(Rr-.5)}finally{Nr--}if(!(!o||u===p))return n=o?.[0]===";"?o.slice(1):[o],r?.[0]===";"?(r.push(...n),r):[";",r,...n]};var ft=(r,t,e,o)=>typeof r=="string"?n=>t(n,r,n):r[0]==="."?(e=i(r[1]),o=r[2],n=>t(e(n),o,n)):r[0]==="[]"&&r.length===3?(e=i(r[1]),o=i(r[2]),n=>t(e(n),o(n),n)):r[0]==="()"&&r.length===2?ft(r[1],t):(()=>{throw Error("Invalid assignment target")})(),pt={"=":(r,t,e)=>r[t]=e,"+=":(r,t,e)=>r[t]+=e,"-=":(r,t,e)=>r[t]-=e,"*=":(r,t,e)=>r[t]*=e,"/=":(r,t,e)=>r[t]/=e,"%=":(r,t,e)=>r[t]%=e,"|=":(r,t,e)=>r[t]|=e,"&=":(r,t,e)=>r[t]&=e,"^=":(r,t,e)=>r[t]^=e,">>=":(r,t,e)=>r[t]>>=e,"<<=":(r,t,e)=>r[t]<<=e};for(let r in pt)s(r,(t,e)=>(e=i(e),ft(t,(o,n,p)=>pt[r](o,n,e(p)))));s("!",r=>(r=i(r),t=>!r(t)));s("||",(r,t)=>(r=i(r),t=i(t),e=>r(e)||t(e)));s("&&",(r,t)=>(r=i(r),t=i(t),e=>r(e)&&t(e)));s("~",r=>(r=i(r),t=>~r(t)));s("|",(r,t)=>(r=i(r),t=i(t),e=>r(e)|t(e)));s("&",(r,t)=>(r=i(r),t=i(t),e=>r(e)&t(e)));s("^",(r,t)=>(r=i(r),t=i(t),e=>r(e)^t(e)));s(">>",(r,t)=>(r=i(r),t=i(t),e=>r(e)>>t(e)));s("<<",(r,t)=>(r=i(r),t=i(t),e=>r(e)<<t(e)));s(">",(r,t)=>(r=i(r),t=i(t),e=>r(e)>t(e)));s("<",(r,t)=>(r=i(r),t=i(t),e=>r(e)<t(e)));s(">=",(r,t)=>(r=i(r),t=i(t),e=>r(e)>=t(e)));s("<=",(r,t)=>(r=i(r),t=i(t),e=>r(e)<=t(e)));s("==",(r,t)=>(r=i(r),t=i(t),e=>r(e)==t(e)));s("!=",(r,t)=>(r=i(r),t=i(t),e=>r(e)!=t(e)));s("+",(r,t)=>t!==void 0?(r=i(r),t=i(t),e=>r(e)+t(e)):(r=i(r),e=>+r(e)));s("-",(r,t)=>t!==void 0?(r=i(r),t=i(t),e=>r(e)-t(e)):(r=i(r),e=>-r(e)));s("*",(r,t)=>(r=i(r),t=i(t),e=>r(e)*t(e)));s("/",(r,t)=>(r=i(r),t=i(t),e=>r(e)/t(e)));s("%",(r,t)=>(r=i(r),t=i(t),e=>r(e)%t(e)));var Or=(r,t,e,o)=>typeof r=="string"?n=>t(n,r):r[0]==="."?(e=i(r[1]),o=r[2],n=>t(e(n),o)):r[0]==="[]"&&r.length===3?(e=i(r[1]),o=i(r[2]),n=>t(e(n),o(n))):r[0]==="()"&&r.length===2?Or(r[1],t):(()=>{throw Error("Invalid increment target")})();s("++",(r,t)=>Or(r,t===null?(e,o)=>e[o]++:(e,o)=>++e[o]));s("--",(r,t)=>Or(r,t===null?(e,o)=>e[o]--:(e,o)=>--e[o]));var ut=(...r)=>(r=r.map(i),t=>{let e;for(let o of r)e=o(t);return e});s(",",ut);s(";",ut);var F=r=>r?.[0]==="_"&&r[1]==="_"||r==="constructor"||r==="prototype",ir=r=>{throw Error(r)};s("[]",(r,t)=>t===void 0?(r=r?r[0]===","?r.slice(1):[r]:[],r=r.map(e=>e==null?(()=>{}):e[0]==="..."?(e=i(e[1]),o=>e(o)):(e=i(e),o=>[e(o)])),e=>r.flatMap(o=>o(e))):(t==null&&ir("Missing index"),r=i(r),t=i(t),e=>{let o=t(e);return F(o)?void 0:r(e)[o]}));s(".",(r,t)=>(r=i(r),t=t[0]?t:t[1],F(t)?()=>{}:e=>r(e)[t]));s("()",(r,t)=>{if(t===void 0)return r==null?ir("Empty ()"):i(r);let e=n=>n?.[0]===","&&n.slice(1).some(p=>p==null||e(p));e(t)&&ir("Empty argument");let o=t?t[0]===","?(t=t.slice(1).map(i),n=>t.map(p=>p(n))):(t=i(t),n=>[t(n)]):()=>[];return Pr(r,(n,p,m)=>n[p](...o(m)))});var L=r=>typeof r=="string"||Array.isArray(r)&&(r[0]==="."||r[0]==="?."||r[0]==="[]"&&r.length===3||r[0]==="?.[]"||r[0]==="()"&&r.length===2&&L(r[1])||r[0]==="{}"),Pr=(r,t,e,o)=>r==null?ir("Empty ()"):r[0]==="()"&&r.length==2?Pr(r[1],t):typeof r=="string"?n=>t(n,r,n):r[0]==="."?(e=i(r[1]),o=r[2],n=>t(e(n),o,n)):r[0]==="?."?(e=i(r[1]),o=r[2],n=>{let p=e(n);return p==null?void 0:t(p,o,n)}):r[0]==="[]"&&r.length===3?(e=i(r[1]),o=i(r[2]),n=>t(e(n),o(n),n)):r[0]==="?.[]"?(e=i(r[1]),o=i(r[2]),n=>{let p=e(n);return p==null?void 0:t(p,o(n),n)}):(r=i(r),n=>t([r(n)],0,n)),G=Pr;s("===",(r,t)=>(r=i(r),t=i(t),e=>r(e)===t(e)));s("!==",(r,t)=>(r=i(r),t=i(t),e=>r(e)!==t(e)));s("??",(r,t)=>(r=i(r),t=i(t),e=>r(e)??t(e)));var Pe=r=>{throw Error(r)};s("**",(r,t)=>(r=i(r),t=i(t),e=>r(e)**t(e)));s("**=",(r,t)=>(L(r)||Pe("Invalid assignment target"),t=i(t),G(r,(e,o,n)=>e[o]**=t(n))));s("in",(r,t)=>(r=i(r),t=i(t),e=>r(e)in t(e)));var ve=r=>{throw Error(r)};s(">>>",(r,t)=>(r=i(r),t=i(t),e=>r(e)>>>t(e)));s(">>>=",(r,t)=>(L(r)||ve("Invalid assignment target"),t=i(t),G(r,(e,o,n)=>e[o]>>>=t(n))));var Be=r=>r[0]?.[0]===","?r[0].slice(1):r,X=(r,t,e)=>{if(typeof r=="string"){e[r]=t;return}let[o,...n]=r,p=Be(n);if(o==="{}"){let m=[];for(let f of p){if(Array.isArray(f)&&f[0]==="..."){let C={};for(let _ in t)m.includes(_)||(C[_]=t[_]);e[f[1]]=C;break}let A,g,S;typeof f=="string"?A=g=f:f[0]==="="?(typeof f[1]=="string"?A=g=f[1]:[,A,g]=f[1],S=f[2]):[,A,g]=f,m.push(A);let E=t[A];E===void 0&&S&&(E=i(S)(e)),X(g,E,e)}}else if(o==="[]"){let m=0;for(let f of p){if(f===null){m++;continue}if(Array.isArray(f)&&f[0]==="..."){e[f[1]]=t.slice(m);break}let A=f,g;Array.isArray(f)&&f[0]==="="&&([,A,g]=f);let S=t[m++];S===void 0&&g&&(S=i(g)(e)),X(A,S,e)}}},lt=(...r)=>(r=r.map(t=>{if(typeof t=="string")return e=>{e[t]=void 0};if(t[0]==="="){let[,e,o]=t,n=i(o);return typeof e=="string"?p=>{p[e]=n(p)}:p=>X(e,n(p),p)}return i(t)}),t=>{for(let e of r)e(t)});s("let",lt);s("const",lt);s("var",r=>typeof r=="string"?t=>{t[r]=void 0}:()=>{});var sr=r=>{throw Error(r)};s("=",(r,t)=>{if(Array.isArray(r)&&(r[0]==="let"||r[0]==="const"||r[0]==="var")){let e=r[1];return t=i(t),typeof e=="string"?o=>{o[e]=t(o)}:o=>X(e,t(o),o)}return L(r)||sr("Invalid assignment target"),t=i(t),G(r,(e,o,n)=>e[o]=t(n))});s("||=",(r,t)=>(L(r)||sr("Invalid assignment target"),t=i(t),G(r,(e,o,n)=>e[o]||=t(n))));s("&&=",(r,t)=>(L(r)||sr("Invalid assignment target"),t=i(t),G(r,(e,o,n)=>e[o]&&=t(n))));s("??=",(r,t)=>(L(r)||sr("Invalid assignment target"),t=i(t),G(r,(e,o,n)=>e[o]??=t(n))));s("?",(r,t,e)=>(r=i(r),t=i(t),e=i(e),o=>r(o)?t(o):e(o)));var B=[];s("=>",(r,t)=>{r=r?.[0]==="()"?r[1]:r;let e=r?r[0]===","?r.slice(1):[r]:[],o=-1,n=null,p=e[e.length-1];Array.isArray(p)&&p[0]==="..."&&(o=e.length-1,n=p[1],e.length--);let m=t?.[0]==="{}";return t=i(m?["{",t[1]]:t),f=>(...A)=>{let g={};e.forEach((E,C)=>g[E]=A[C]),n&&(g[n]=A.slice(o));let S=new Proxy(g,{get:(E,C)=>C in E?E[C]:f?.[C],set:(E,C,_)=>((C in E?E:f)[C]=_,!0),has:(E,C)=>C in E||(f?C in f:!1)});try{let E=t(S);return m?void 0:E}catch(E){if(E===B)return E[0];throw E}}});s("...",r=>(r=i(r),t=>Object.entries(r(t))));s("?.",(r,t)=>(r=i(r),F(t)?()=>{}:e=>r(e)?.[t]));s("?.[]",(r,t)=>(r=i(r),t=i(t),e=>{let o=t(e);return F(o)?void 0:r(e)?.[o]}));s("?.()",(r,t)=>{let e=t?t[0]===","?(t=t.slice(1).map(i),n=>t.map(p=>p(n))):(t=i(t),n=>[t(n)]):()=>[];if(r[0]==="?."){let n=i(r[1]),p=r[2];return F(p)?()=>{}:m=>n(m)?.[p]?.(...e(m))}if(r[0]==="?.[]"){let n=i(r[1]),p=i(r[2]);return m=>{let f=n(m),A=p(m);return F(A)?void 0:f?.[A]?.(...e(m))}}if(r[0]==="."){let n=i(r[1]),p=r[2];return F(p)?()=>{}:m=>n(m)?.[p]?.(...e(m))}if(r[0]==="[]"&&r.length===3){let n=i(r[1]),p=i(r[2]);return m=>{let f=n(m),A=p(m);return F(A)?void 0:f?.[A]?.(...e(m))}}let o=i(r);return n=>o(n)?.(...e(n))});s("typeof",r=>(r=i(r),t=>typeof r(t)));s("void",r=>(r=i(r),t=>(r(t),void 0)));s("delete",r=>{if(r[0]==="."){let t=i(r[1]),e=r[2];return o=>delete t(o)[e]}if(r[0]==="[]"){let t=i(r[1]),e=i(r[2]);return o=>delete t(o)[e(o)]}return()=>!0});s("new",r=>{let t=i(r?.[0]==="()"?r[1]:r),e=r?.[0]==="()"?r[2]:null,o=e?e[0]===","?(n=>p=>n.map(m=>m(p)))(e.slice(1).map(i)):(n=>p=>[n(p)])(i(e)):()=>[];return n=>new(t(n))(...o(n))});var pr=Symbol("accessor");s("get",(r,t)=>(t=t?i(t):()=>{},e=>[[pr,r,{get:function(){let o=Object.create(e||{});return o.this=this,t(o)}}]]));s("set",(r,t,e)=>(e=e?i(e):()=>{},o=>[[pr,r,{set:function(n){let p=Object.create(o||{});p.this=this,p[t]=n,e(p)}}]]));var Me=r=>r==null||typeof r=="string"||[":",",","...","get","set"].includes(r[0]);s("{}",(r,t)=>{if(t!==void 0)return;if(!Me(r))return i(["{",r]);r=r?r[0]!==","?[r]:r.slice(1):[];let e=r.map(o=>i(typeof o=="string"?[":",o,o]:o));return o=>{let n={},p={};for(let m of e.flatMap(f=>f(o)))if(m[0]===pr){let[,f,A]=m;p[f]={...p[f],...A,configurable:!0,enumerable:!0}}else n[m[0]]=m[1];for(let m in p)Object.defineProperty(n,m,p[m]);return n}});s("{",r=>(r=r?i(r):()=>{},t=>r(Object.create(t))));s(":",(r,t)=>(t=i(t),Array.isArray(r)?(r=i(r),e=>[[r(e),t(e)]]):e=>[[r,t(e)]]));s("`",(...r)=>(r=r.map(i),t=>r.map(e=>e(t)).join("")));s("``",(r,...t)=>{r=i(r);let e=[],o=[];for(let p of t)Array.isArray(p)&&p[0]===void 0?e.push(p[1]):o.push(i(p));let n=Object.assign([...e],{raw:e});return p=>r(p)(n,...o.map(m=>m(p)))});s("function",(r,t,e)=>{e=e?i(e):()=>{};let o=t?t[0]===","?t.slice(1):[t]:[],n=null,p=-1,m=o[o.length-1];return Array.isArray(m)&&m[0]==="..."&&(p=o.length-1,n=m[1],o.length--),f=>{let A=(...g)=>{let S={};o.forEach((C,_)=>S[C]=g[_]),n&&(S[n]=g.slice(p));let E=new Proxy(S,{get:(C,_)=>_ in C?C[_]:f[_],set:(C,_,dt)=>((_ in C?C:f)[_]=dt,!0),has:(C,_)=>_ in C||_ in f});try{return e(E)}catch(C){if(C===B)return C[0];throw C}};return r&&(f[r]=A),A}});s("function*",(r,t,e)=>{throw Error("Generator functions are not supported in evaluation")});s("async",r=>{let t=i(r);return e=>{let o=t(e);return async function(...n){return o(...n)}}});s("await",r=>(r=i(r),async t=>await r(t)));s("yield",r=>(r=r?i(r):null,t=>{throw{__yield__:r?r(t):void 0}}));s("yield*",r=>(r=i(r),t=>{throw{__yield_all__:r(t)}}));var Le=Symbol("static"),Ue=r=>{throw Error(r)};s("instanceof",(r,t)=>(r=i(r),t=i(t),e=>r(e)instanceof t(e)));s("class",(r,t,e)=>(t=t?i(t):null,e=e?i(e):null,o=>{let n=t?t(o):Object,p=function(...m){if(!(this instanceof p))return Ue("Class constructor must be called with new");let f=t?Reflect.construct(n,m,p):this;return p.prototype.__constructor__&&p.prototype.__constructor__.apply(f,m),f};if(Object.setPrototypeOf(p.prototype,n.prototype),Object.setPrototypeOf(p,n),e){let m=Object.create(o);m.super=n;let f=e(m),A=Array.isArray(f)&&typeof f[0]?.[0]=="string"?f:[];for(let[g,S]of A)g==="constructor"?p.prototype.__constructor__=S:p.prototype[g]=S}return r&&(o[r]=p),p}));s("static",r=>(r=i(r),t=>[[Le,r(t)]]));s("//",(r,t)=>{let e=new RegExp(r,t||"");return()=>e});s("if",(r,t,e)=>(r=i(r),t=i(t),e=e!==void 0?i(e):null,o=>r(o)?t(o):e?.(o)));var U=Symbol("break"),K=Symbol("continue");s("while",(r,t)=>(r=i(r),t=i(t),e=>{let o;for(;r(e);)try{o=t(e)}catch(n){if(n===U)break;if(n===K)continue;if(n===B)return n[0];throw n}return o}));s("do",(r,t)=>(r=i(r),t=i(t),e=>{let o;do try{o=r(e)}catch(n){if(n===U)break;if(n===K)continue;if(n===B)return n[0];throw n}while(t(e));return o}));s("for",(r,t)=>{if(Array.isArray(r)&&r[0]===";"){let[,e,o,n]=r;return e=e?i(e):null,o=o?i(o):()=>!0,n=n?i(n):null,t=i(t),p=>{let m;for(e?.(p);o(p);n?.(p))try{m=t(p)}catch(f){if(f===U)break;if(f===K)continue;if(f===B)return f[0];throw f}return m}}if(Array.isArray(r)&&(r[0]==="in"||r[0]==="of")){let[e,o,n]=r;if(Array.isArray(o)&&(o[0]==="let"||o[0]==="const"||o[0]==="var")&&(o=o[1]),e==="in")return Fe(o,n,t);if(e==="of")return De(o,n,t)}});var De=(r,t,e)=>{t=i(t),e=i(e);let o=Array.isArray(r);return n=>{let p,m=o?null:n[r];for(let f of t(n)){o?X(r,f,n):n[r]=f;try{p=e(n)}catch(A){if(A===U)break;if(A===K)continue;if(A===B)return A[0];throw A}}return o||(n[r]=m),p}},Fe=(r,t,e)=>{t=i(t),e=i(e);let o=Array.isArray(r);return n=>{let p,m=o?null:n[r];for(let f in t(n)){o?X(r,f,n):n[r]=f;try{p=e(n)}catch(A){if(A===U)break;if(A===K)continue;if(A===B)return A[0];throw A}}return o||(n[r]=m),p}};s("break",()=>()=>{throw U});s("continue",()=>()=>{throw K});s("return",r=>(r=r!==void 0?i(r):null,t=>{throw B[0]=r?.(t),B}));s("try",(r,...t)=>{r=r?i(r):null;let e=t.find(f=>f?.[0]==="catch"),o=t.find(f=>f?.[0]==="finally"),n=e?.[1],p=e?.[2]?i(e[2]):null,m=o?.[1]?i(o[1]):null;return f=>{let A;try{A=r?.(f)}catch(g){if(g===U||g===K||g===B)throw g;if(n!=null&&p){let S=n in f,E=f[n];f[n]=g;try{A=p(f)}finally{S?f[n]=E:delete f[n]}}else if(!p)throw g}finally{m?.(f)}return A}});s("throw",r=>(r=i(r),t=>{throw r(t)}));s("switch",(r,...t)=>(r=i(r),t.length?(t=t.map(e=>[e[0]==="case"?i(e[1]):null,(e[0]==="case"?e[2]:e[1])?.[0]===";"?(e[0]==="case"?e[2]:e[1]).slice(1).map(i):(e[0]==="case"?e[2]:e[1])?[i(e[0]==="case"?e[2]:e[1])]:[]]),e=>{let o=r(e),n=!1,p;for(let[f,A]of t)if(n||f===null||f(e)===o)for(n=!0,m=0;m<A.length;m++)try{p=A[m](e)}catch(g){if(g===U)return p;throw g}var m;return p}):e=>r(e)));s("import",()=>()=>{});s("export",()=>()=>{});s("from",(r,t)=>()=>{});s("as",(r,t)=>()=>{});s("default",r=>i(r));var mt=new WeakMap,Ge=(r,...t)=>typeof r=="string"?i(l(r)):mt.get(r)||mt.set(r,Xe(r,t)).get(r),ct=57344,Xe=(r,t)=>{let e=r.reduce((p,m,f)=>p+(f?String.fromCharCode(ct+f-1):"")+m,""),o=l(e),n=p=>{if(typeof p=="string"&&p.length===1){let m=p.charCodeAt(0)-ct,f;if(m>=0&&m<t.length)return f=t[m],Ke(f)?f:[,f]}return Array.isArray(p)?p.map(n):p};return i(n(o))},Ke=r=>typeof r=="string"||Array.isArray(r)&&(typeof r[0]=="string"||r[0]===void 0),He=Ge;export{mr as access,y as binary,i as compile,c as cur,He as default,R as err,a as expr,W as group,je as id,u as idx,w as keyword,Q as literal,vr as loc,T as lookup,lr as nary,N as next,s as operator,ur as operators,v as parens,l as parse,Z as peek,$ as prec,O as seek,h as skip,d as space,fr as step,k as token,P as unary,I as word};
|
package/justin.js
CHANGED
|
@@ -3,37 +3,11 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Builds on subscript with JS-specific features:
|
|
5
5
|
* optional chaining, arrow functions, spread, templates.
|
|
6
|
+
*
|
|
7
|
+
* For parse-only: import { parse } from 'subscript/feature/justin.js'
|
|
6
8
|
*/
|
|
7
|
-
import './
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
// Add single quotes
|
|
11
|
-
parse.string["'"] = true;
|
|
12
|
-
|
|
13
|
-
// Add hex, binary, octal prefixes
|
|
14
|
-
parse.number = { '0x': 16, '0b': 2, '0o': 8 };
|
|
15
|
-
|
|
16
|
-
import './feature/comment.js';
|
|
17
|
-
|
|
18
|
-
// Extended operators
|
|
19
|
-
// Note: assignment (=) is in subscript, must come BEFORE identity (===)
|
|
20
|
-
import './feature/op/identity.js'; // === !==
|
|
21
|
-
import './feature/op/nullish.js'; // ??
|
|
22
|
-
import './feature/op/pow.js'; // ** **=
|
|
23
|
-
import './feature/op/membership.js'; // in (instanceof is in jessie/class.js)
|
|
24
|
-
import './feature/op/bitwise-unsigned.js'; // >>> >>>=
|
|
25
|
-
import './feature/op/assign-logical.js'; // ||= &&= ??= + destructuring
|
|
26
|
-
|
|
27
|
-
// JS-specific operators (ternary, arrow, spread, optional chaining, typeof/void/delete/new)
|
|
28
|
-
import './feature/literal.js';
|
|
29
|
-
import './feature/op/ternary.js';
|
|
30
|
-
import './feature/op/arrow.js';
|
|
31
|
-
import './feature/op/spread.js';
|
|
32
|
-
import './feature/op/optional.js';
|
|
33
|
-
import './feature/op/unary.js';
|
|
34
|
-
|
|
35
|
-
import './feature/collection.js';
|
|
36
|
-
import './feature/template.js';
|
|
9
|
+
import './feature/justin.js';
|
|
10
|
+
import './eval/justin.js';
|
|
37
11
|
|
|
38
12
|
export * from './parse.js';
|
|
39
13
|
export { default } from './subscript.js';
|
package/justin.min.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
var
|
|
2
|
-
`),
|
|
3
|
-
${
|
|
4
|
-
`,""+i}${
|
|
5
|
-
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},
|
|
6
|
-
`,"/*":"*/"};var
|
|
7
|
-
`)for(;
|
|
8
|
-
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},
|
|
1
|
+
var u,c,d=r=>(u=0,c=r,d.enter?.(),r=y(),c[u]?v():r||""),v=(r="Unexpected token",t=u,e=c.slice(0,t).split(`
|
|
2
|
+
`),o=e.pop(),i=c.slice(Math.max(0,t-40),t),p="\u032D",f=(c[t]||" ")+p,m=c.slice(t+1,t+20))=>{throw SyntaxError(`${r} at ${e.length+1}:${o.length+1}
|
|
3
|
+
${c[t-41]!==`
|
|
4
|
+
`,""+i}${f}${m}`)},sr=(r,t=u)=>(Array.isArray(r)&&(r.loc=t),r),R=(r,t=u,e)=>{for(;e=r(c.charCodeAt(u));)u+=e;return c.slice(t,u)},C=(r=1)=>c[u+=r],F=r=>u=r,y=(r=0,t)=>{let e,o,i;for(t&&d.enter?.(r,t);(e=_())&&e!==t&&(i=J(o,r,e,y));)o=i;return t&&(e==t?(u++,d.exit?.(r,t)):v("Unclosed "+String.fromCharCode(t-(t>42?2:1)))),o},J=(r,t,e,o,i)=>(i=I[e])&&i(r,t)||(r?null:R(d.id)||null),_=r=>{for(;(r=c.charCodeAt(u))<=32;)u++;return r},pr=(r=u)=>{for(;c.charCodeAt(r)<=32;)r++;return c.charCodeAt(r)},wt=d.id=r=>r>=48&&r<=57||r>=65&&r<=90||r>=97&&r<=122||r==36||r==95||r>=192&&r!=215&&r!=247,mr=(r,t=r.length)=>c.substr(u,t)===r&&!d.id(c.charCodeAt(u+t)),kt=()=>(C(),y(0,41)),I=[],ir={},w=(r,t=32,e,o=r.charCodeAt(0),i=r.length,p=I[o],f=r.toUpperCase()!==r,m,g)=>(t=ir[r]=!p&&ir[r]||t,I[o]=(h,E,A,S=u)=>(m=A,(A?r==A:(i<2||r.charCodeAt(1)===c.charCodeAt(u+1)&&(i<3||c.substr(u,i)==r))&&(!f||!d.id(c.charCodeAt(u+i)))&&(m=A=r))&&E<t&&(u+=i,(g=e(h))?sr(g,S):(u=S,m=0,!f&&!p&&!h&&v()),g)||p?.(h,E,m))),l=(r,t,e=!1)=>w(r,t,o=>o&&(i=>i&&[r,o,i])(y(t-(e?.5:0)))),k=(r,t,e)=>w(r,t,o=>e?o&&[r,o]:!o&&(o=y(t-.5))&&[r,o]),L=(r,t)=>w(r,200,e=>!e&&[,t]),Y=(r,t,e)=>w(r,t,(o,i)=>(i=y(t-(e?.5:0)),o?.[0]!==r&&(o=[r,o||null]),i?.[0]===r?o.push(...i.slice(1)):o.push(i||null),o)),U=(r,t)=>w(r[0],t,e=>!e&&[r,y(0,r.charCodeAt(1))||null]),Z=(r,t)=>w(r[0],t,e=>e&&[r,e,y(0,r.charCodeAt(1))||null]),X=(r,t,e,o=r.charCodeAt(0),i=r.length,p=I[o],f)=>I[o]=(m,g,h,E=u)=>!m&&(h?r==h:(i<2||c.substr(u,i)==r)&&(h=r))&&g<t&&!d.id(c.charCodeAt(u+i))&&(!d.prop||d.prop(u+i))&&(F(u+i),(f=e())?sr(f,E):F(E),f)||p?.(m,g,h);Object.defineProperty(d,"space",{configurable:!0,enumerable:!0,get:()=>_,set:r=>_=r});Object.defineProperty(d,"step",{configurable:!0,enumerable:!0,get:()=>J,set:r=>J=r});var V={},s=(r,t,e=V[r])=>V[r]=(...o)=>t(...o)||e?.(...o),n=r=>Array.isArray(r)?r[0]==null?(t=>()=>t)(r[1]):V[r[0]]?.(...r.slice(1))??v(`Unknown operator: ${r[0]}`,r?.loc):r===void 0?()=>{}:t=>t?.[r];var $=46,M=48,a=57,Lr=69,Tr=101,_r=43,Ur=45,G=95,fr=110,Mr=97,Br=102,Dr=65,Fr=70,ur=r=>r.indexOf("_")<0?r:r.replaceAll("_",""),q=r=>{let t=ur(R(e=>e===$&&c.charCodeAt(u+1)!==$||e>=M&&e<=a||e===G||((e===Lr||e===Tr)&&((e=c.charCodeAt(u+1))>=M&&e<=a||e===_r||e===Ur)?2:0)));return c.charCodeAt(u)===fr?(C(),[,BigInt(t)]):(r=+t)!=r?v():[,r]},Xr={2:r=>r===48||r===49||r===G,8:r=>r>=48&&r<=55||r===G,16:r=>r>=M&&r<=a||r>=Mr&&r<=Br||r>=Dr&&r<=Fr||r===G};d.number=null;I[$]=r=>!r&&c.charCodeAt(u+1)!==$&&q();for(let r=M;r<=a;r++)I[r]=t=>t?void 0:q();I[M]=r=>{if(r)return;let t=d.number;if(t){for(let[e,o]of Object.entries(t))if(e[0]==="0"&&c[u+1]?.toLowerCase()===e[1]){C(2);let i=ur(R(Xr[o]));return c.charCodeAt(u)===fr?(C(),[,BigInt("0"+e[1]+i)]):[,parseInt(i,o)]}}return q()};var Gr=92,lr=34,cr=39,$r={n:`
|
|
5
|
+
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},dr=r=>(t,e,o="")=>{if(!(t||!d.string?.[String.fromCharCode(r)]))return C(),R(i=>i-r&&(i===Gr?(o+=$r[c[u+1]]||c[u+1],2):(o+=c[u],1))),c[u]===String.fromCharCode(r)?C():v("Bad string"),[,o]};I[lr]=dr(lr);I[cr]=dr(cr);d.string={'"':!0};var ar=20;"= += -= *= /= %= |= &= ^= >>= <<=".split(" ").map(r=>l(r,ar,!0));var jr=30,Qr=40,Hr=140;k("!",Hr);l("||",jr);l("&&",Qr);var Kr=50,Wr=60,zr=70,gr=100,Jr=140;l("|",Kr);l("&",zr);l("^",Wr);l(">>",gr);l("<<",gr);k("~",Jr);var j=90;l("<",j);l(">",j);l("<=",j);l(">=",j);var Ar=80;l("==",Ar);l("!=",Ar);var hr=110,x=120,yr=140;l("+",hr);l("-",hr);l("*",x);l("/",x);l("%",x);k("+",yr);k("-",yr);var Q=150;w("++",Q,r=>r?["++",r,null]:["++",y(Q-1)]);w("--",Q,r=>r?["--",r,null]:["--",y(Q-1)]);var Vr=5,Yr=10;Y(",",Yr);Y(";",Vr,!0);var Zr=170;U("()",Zr);var b=170;Z("[]",b);l(".",b);Z("()",b);var qr=32,xr=d.space;d.comment??={"//":`
|
|
6
|
+
`,"/*":"*/"};var rr;d.space=()=>{rr||(rr=Object.entries(d.comment).map(([i,p])=>[i,p,i.charCodeAt(0)]));for(var r;r=xr();){for(var t=0,e;e=rr[t++];)if(r===e[2]&&c.substr(u,e[0].length)===e[0]){var o=u+e[0].length;if(e[1]===`
|
|
7
|
+
`)for(;c.charCodeAt(o)>=qr;)o++;else{for(;c[o]&&c.substr(o,e[1].length)!==e[1];)o++;c[o]&&(o+=e[1].length)}F(o),r=0;break}if(r)return r}return r};var Cr=80;l("===",Cr);l("!==",Cr);var br=30;l("??",br);var rt=130,tt=20;l("**",rt,!0);l("**=",tt,!0);var Sr=90;l("in",Sr);l("of",Sr);var et=20,ot=100;l(">>>",ot);l(">>>=",et,!0);var tr=20;l("||=",tr,!0);l("&&=",tr,!0);l("??=",tr,!0);L("true",!0);L("false",!1);L("null",null);X("undefined",200,()=>[]);L("NaN",NaN);L("Infinity",1/0);var er=20;w("?",er,(r,t,e)=>r&&(t=y(er-1))&&R(o=>o===58)&&(e=y(er-1),["?",r,t,e]));var nt=20;l("=>",nt,!0);var it=140;k("...",it);var Er=170;w("?.",Er,(r,t)=>{if(!r)return;let e=_();return e===40?(C(),["?.()",r,y(0,41)||null]):e===91?(C(),["?.[]",r,y(0,93)]):(t=y(Er),t?["?.",r,t]:void 0)});var B=140;k("typeof",B);k("void",B);k("delete",B);X("new",B,()=>mr(".target")?(C(7),["new.target"]):["new",y(B)]);var st=20,Ir=200;d.prop=r=>pr(r)!==58;U("[]",Ir);U("{}",Ir);l(":",st-1,!0);var pt=170,H=96,mt=36,ft=123,ut=92,lt={n:`
|
|
8
|
+
`,r:"\r",t:" ",b:"\b",f:"\f",v:"\v"},wr=()=>{let r=[];for(let t="",e;(e=c.charCodeAt(u))!==H;)e?e===ut?(C(),t+=lt[c[u]]||c[u],C()):e===mt&&c.charCodeAt(u+1)===ft?(t&&r.push([,t]),t="",C(2),r.push(y(0,125))):(t+=c[u],C(),e=c.charCodeAt(u),e===H&&t&&r.push([,t])):v("Unterminated template");return C(),r},ct=I[H];I[H]=(r,t)=>r&&t<pt?d.asi&&d.newline?void 0:(C(),["``",r,...wr()]):r?ct?.(r,t):(C(),(e=>e.length<2&&e[0]?.[0]===void 0?e[0]||[,""]:["`",...e])(wr()));d.string["'"]=!0;d.number={"0x":16,"0b":2,"0o":8};var vr=(r,t,e,o)=>typeof r=="string"?i=>t(i,r,i):r[0]==="."?(e=n(r[1]),o=r[2],i=>t(e(i),o,i)):r[0]==="[]"&&r.length===3?(e=n(r[1]),o=n(r[2]),i=>t(e(i),o(i),i)):r[0]==="()"&&r.length===2?vr(r[1],t):(()=>{throw Error("Invalid assignment target")})(),kr={"=":(r,t,e)=>r[t]=e,"+=":(r,t,e)=>r[t]+=e,"-=":(r,t,e)=>r[t]-=e,"*=":(r,t,e)=>r[t]*=e,"/=":(r,t,e)=>r[t]/=e,"%=":(r,t,e)=>r[t]%=e,"|=":(r,t,e)=>r[t]|=e,"&=":(r,t,e)=>r[t]&=e,"^=":(r,t,e)=>r[t]^=e,">>=":(r,t,e)=>r[t]>>=e,"<<=":(r,t,e)=>r[t]<<=e};for(let r in kr)s(r,(t,e)=>(e=n(e),vr(t,(o,i,p)=>kr[r](o,i,e(p)))));s("!",r=>(r=n(r),t=>!r(t)));s("||",(r,t)=>(r=n(r),t=n(t),e=>r(e)||t(e)));s("&&",(r,t)=>(r=n(r),t=n(t),e=>r(e)&&t(e)));s("~",r=>(r=n(r),t=>~r(t)));s("|",(r,t)=>(r=n(r),t=n(t),e=>r(e)|t(e)));s("&",(r,t)=>(r=n(r),t=n(t),e=>r(e)&t(e)));s("^",(r,t)=>(r=n(r),t=n(t),e=>r(e)^t(e)));s(">>",(r,t)=>(r=n(r),t=n(t),e=>r(e)>>t(e)));s("<<",(r,t)=>(r=n(r),t=n(t),e=>r(e)<<t(e)));s(">",(r,t)=>(r=n(r),t=n(t),e=>r(e)>t(e)));s("<",(r,t)=>(r=n(r),t=n(t),e=>r(e)<t(e)));s(">=",(r,t)=>(r=n(r),t=n(t),e=>r(e)>=t(e)));s("<=",(r,t)=>(r=n(r),t=n(t),e=>r(e)<=t(e)));s("==",(r,t)=>(r=n(r),t=n(t),e=>r(e)==t(e)));s("!=",(r,t)=>(r=n(r),t=n(t),e=>r(e)!=t(e)));s("+",(r,t)=>t!==void 0?(r=n(r),t=n(t),e=>r(e)+t(e)):(r=n(r),e=>+r(e)));s("-",(r,t)=>t!==void 0?(r=n(r),t=n(t),e=>r(e)-t(e)):(r=n(r),e=>-r(e)));s("*",(r,t)=>(r=n(r),t=n(t),e=>r(e)*t(e)));s("/",(r,t)=>(r=n(r),t=n(t),e=>r(e)/t(e)));s("%",(r,t)=>(r=n(r),t=n(t),e=>r(e)%t(e)));var or=(r,t,e,o)=>typeof r=="string"?i=>t(i,r):r[0]==="."?(e=n(r[1]),o=r[2],i=>t(e(i),o)):r[0]==="[]"&&r.length===3?(e=n(r[1]),o=n(r[2]),i=>t(e(i),o(i))):r[0]==="()"&&r.length===2?or(r[1],t):(()=>{throw Error("Invalid increment target")})();s("++",(r,t)=>or(r,t===null?(e,o)=>e[o]++:(e,o)=>++e[o]));s("--",(r,t)=>or(r,t===null?(e,o)=>e[o]--:(e,o)=>--e[o]));var Or=(...r)=>(r=r.map(n),t=>{let e;for(let o of r)e=o(t);return e});s(",",Or);s(";",Or);var N=r=>r?.[0]==="_"&&r[1]==="_"||r==="constructor"||r==="prototype",K=r=>{throw Error(r)};s("[]",(r,t)=>t===void 0?(r=r?r[0]===","?r.slice(1):[r]:[],r=r.map(e=>e==null?(()=>{}):e[0]==="..."?(e=n(e[1]),o=>e(o)):(e=n(e),o=>[e(o)])),e=>r.flatMap(o=>o(e))):(t==null&&K("Missing index"),r=n(r),t=n(t),e=>{let o=t(e);return N(o)?void 0:r(e)[o]}));s(".",(r,t)=>(r=n(r),t=t[0]?t:t[1],N(t)?()=>{}:e=>r(e)[t]));s("()",(r,t)=>{if(t===void 0)return r==null?K("Empty ()"):n(r);let e=i=>i?.[0]===","&&i.slice(1).some(p=>p==null||e(p));e(t)&&K("Empty argument");let o=t?t[0]===","?(t=t.slice(1).map(n),i=>t.map(p=>p(i))):(t=n(t),i=>[t(i)]):()=>[];return nr(r,(i,p,f)=>i[p](...o(f)))});var O=r=>typeof r=="string"||Array.isArray(r)&&(r[0]==="."||r[0]==="?."||r[0]==="[]"&&r.length===3||r[0]==="?.[]"||r[0]==="()"&&r.length===2&&O(r[1])||r[0]==="{}"),nr=(r,t,e,o)=>r==null?K("Empty ()"):r[0]==="()"&&r.length==2?nr(r[1],t):typeof r=="string"?i=>t(i,r,i):r[0]==="."?(e=n(r[1]),o=r[2],i=>t(e(i),o,i)):r[0]==="?."?(e=n(r[1]),o=r[2],i=>{let p=e(i);return p==null?void 0:t(p,o,i)}):r[0]==="[]"&&r.length===3?(e=n(r[1]),o=n(r[2]),i=>t(e(i),o(i),i)):r[0]==="?.[]"?(e=n(r[1]),o=n(r[2]),i=>{let p=e(i);return p==null?void 0:t(p,o(i),i)}):(r=n(r),i=>t([r(i)],0,i)),P=nr;s("===",(r,t)=>(r=n(r),t=n(t),e=>r(e)===t(e)));s("!==",(r,t)=>(r=n(r),t=n(t),e=>r(e)!==t(e)));s("??",(r,t)=>(r=n(r),t=n(t),e=>r(e)??t(e)));var dt=r=>{throw Error(r)};s("**",(r,t)=>(r=n(r),t=n(t),e=>r(e)**t(e)));s("**=",(r,t)=>(O(r)||dt("Invalid assignment target"),t=n(t),P(r,(e,o,i)=>e[o]**=t(i))));s("in",(r,t)=>(r=n(r),t=n(t),e=>r(e)in t(e)));var gt=r=>{throw Error(r)};s(">>>",(r,t)=>(r=n(r),t=n(t),e=>r(e)>>>t(e)));s(">>>=",(r,t)=>(O(r)||gt("Invalid assignment target"),t=n(t),P(r,(e,o,i)=>e[o]>>>=t(i))));var At=r=>r[0]?.[0]===","?r[0].slice(1):r,D=(r,t,e)=>{if(typeof r=="string"){e[r]=t;return}let[o,...i]=r,p=At(i);if(o==="{}"){let f=[];for(let m of p){if(Array.isArray(m)&&m[0]==="..."){let S={};for(let T in t)f.includes(T)||(S[T]=t[T]);e[m[1]]=S;break}let g,h,E;typeof m=="string"?g=h=m:m[0]==="="?(typeof m[1]=="string"?g=h=m[1]:[,g,h]=m[1],E=m[2]):[,g,h]=m,f.push(g);let A=t[g];A===void 0&&E&&(A=n(E)(e)),D(h,A,e)}}else if(o==="[]"){let f=0;for(let m of p){if(m===null){f++;continue}if(Array.isArray(m)&&m[0]==="..."){e[m[1]]=t.slice(f);break}let g=m,h;Array.isArray(m)&&m[0]==="="&&([,g,h]=m);let E=t[f++];E===void 0&&h&&(E=n(h)(e)),D(g,E,e)}}},Nr=(...r)=>(r=r.map(t=>{if(typeof t=="string")return e=>{e[t]=void 0};if(t[0]==="="){let[,e,o]=t,i=n(o);return typeof e=="string"?p=>{p[e]=i(p)}:p=>D(e,i(p),p)}return n(t)}),t=>{for(let e of r)e(t)});s("let",Nr);s("const",Nr);s("var",r=>typeof r=="string"?t=>{t[r]=void 0}:()=>{});var W=r=>{throw Error(r)};s("=",(r,t)=>{if(Array.isArray(r)&&(r[0]==="let"||r[0]==="const"||r[0]==="var")){let e=r[1];return t=n(t),typeof e=="string"?o=>{o[e]=t(o)}:o=>D(e,t(o),o)}return O(r)||W("Invalid assignment target"),t=n(t),P(r,(e,o,i)=>e[o]=t(i))});s("||=",(r,t)=>(O(r)||W("Invalid assignment target"),t=n(t),P(r,(e,o,i)=>e[o]||=t(i))));s("&&=",(r,t)=>(O(r)||W("Invalid assignment target"),t=n(t),P(r,(e,o,i)=>e[o]&&=t(i))));s("??=",(r,t)=>(O(r)||W("Invalid assignment target"),t=n(t),P(r,(e,o,i)=>e[o]??=t(i))));s("?",(r,t,e)=>(r=n(r),t=n(t),e=n(e),o=>r(o)?t(o):e(o)));var ht=[];s("=>",(r,t)=>{r=r?.[0]==="()"?r[1]:r;let e=r?r[0]===","?r.slice(1):[r]:[],o=-1,i=null,p=e[e.length-1];Array.isArray(p)&&p[0]==="..."&&(o=e.length-1,i=p[1],e.length--);let f=t?.[0]==="{}";return t=n(f?["{",t[1]]:t),m=>(...g)=>{let h={};e.forEach((A,S)=>h[A]=g[S]),i&&(h[i]=g.slice(o));let E=new Proxy(h,{get:(A,S)=>S in A?A[S]:m?.[S],set:(A,S,T)=>((S in A?A:m)[S]=T,!0),has:(A,S)=>S in A||(m?S in m:!1)});try{let A=t(E);return f?void 0:A}catch(A){if(A===ht)return A[0];throw A}}});s("...",r=>(r=n(r),t=>Object.entries(r(t))));s("?.",(r,t)=>(r=n(r),N(t)?()=>{}:e=>r(e)?.[t]));s("?.[]",(r,t)=>(r=n(r),t=n(t),e=>{let o=t(e);return N(o)?void 0:r(e)?.[o]}));s("?.()",(r,t)=>{let e=t?t[0]===","?(t=t.slice(1).map(n),i=>t.map(p=>p(i))):(t=n(t),i=>[t(i)]):()=>[];if(r[0]==="?."){let i=n(r[1]),p=r[2];return N(p)?()=>{}:f=>i(f)?.[p]?.(...e(f))}if(r[0]==="?.[]"){let i=n(r[1]),p=n(r[2]);return f=>{let m=i(f),g=p(f);return N(g)?void 0:m?.[g]?.(...e(f))}}if(r[0]==="."){let i=n(r[1]),p=r[2];return N(p)?()=>{}:f=>i(f)?.[p]?.(...e(f))}if(r[0]==="[]"&&r.length===3){let i=n(r[1]),p=n(r[2]);return f=>{let m=i(f),g=p(f);return N(g)?void 0:m?.[g]?.(...e(f))}}let o=n(r);return i=>o(i)?.(...e(i))});s("typeof",r=>(r=n(r),t=>typeof r(t)));s("void",r=>(r=n(r),t=>(r(t),void 0)));s("delete",r=>{if(r[0]==="."){let t=n(r[1]),e=r[2];return o=>delete t(o)[e]}if(r[0]==="[]"){let t=n(r[1]),e=n(r[2]);return o=>delete t(o)[e(o)]}return()=>!0});s("new",r=>{let t=n(r?.[0]==="()"?r[1]:r),e=r?.[0]==="()"?r[2]:null,o=e?e[0]===","?(i=>p=>i.map(f=>f(p)))(e.slice(1).map(n)):(i=>p=>[i(p)])(n(e)):()=>[];return i=>new(t(i))(...o(i))});var z=Symbol("accessor");s("get",(r,t)=>(t=t?n(t):()=>{},e=>[[z,r,{get:function(){let o=Object.create(e||{});return o.this=this,t(o)}}]]));s("set",(r,t,e)=>(e=e?n(e):()=>{},o=>[[z,r,{set:function(i){let p=Object.create(o||{});p.this=this,p[t]=i,e(p)}}]]));var yt=r=>r==null||typeof r=="string"||[":",",","...","get","set"].includes(r[0]);s("{}",(r,t)=>{if(t!==void 0)return;if(!yt(r))return n(["{",r]);r=r?r[0]!==","?[r]:r.slice(1):[];let e=r.map(o=>n(typeof o=="string"?[":",o,o]:o));return o=>{let i={},p={};for(let f of e.flatMap(m=>m(o)))if(f[0]===z){let[,m,g]=f;p[m]={...p[m],...g,configurable:!0,enumerable:!0}}else i[f[0]]=f[1];for(let f in p)Object.defineProperty(i,f,p[f]);return i}});s("{",r=>(r=r?n(r):()=>{},t=>r(Object.create(t))));s(":",(r,t)=>(t=n(t),Array.isArray(r)?(r=n(r),e=>[[r(e),t(e)]]):e=>[[r,t(e)]]));s("`",(...r)=>(r=r.map(n),t=>r.map(e=>e(t)).join("")));s("``",(r,...t)=>{r=n(r);let e=[],o=[];for(let p of t)Array.isArray(p)&&p[0]===void 0?e.push(p[1]):o.push(n(p));let i=Object.assign([...e],{raw:e});return p=>r(p)(i,...o.map(f=>f(p)))});var Pr=new WeakMap,Ct=(r,...t)=>typeof r=="string"?n(d(r)):Pr.get(r)||Pr.set(r,St(r,t)).get(r),Rr=57344,St=(r,t)=>{let e=r.reduce((p,f,m)=>p+(m?String.fromCharCode(Rr+m-1):"")+f,""),o=d(e),i=p=>{if(typeof p=="string"&&p.length===1){let f=p.charCodeAt(0)-Rr,m;if(f>=0&&f<t.length)return m=t[f],Et(m)?m:[,m]}return Array.isArray(p)?p.map(i):p};return n(i(o))},Et=r=>typeof r=="string"||Array.isArray(r)&&(typeof r[0]=="string"||r[0]===void 0),It=Ct;export{Z as access,l as binary,n as compile,c as cur,It as default,v as err,y as expr,U as group,wt as id,u as idx,X as keyword,L as literal,sr as loc,I as lookup,Y as nary,R as next,s as operator,V as operators,kt as parens,d as parse,pr as peek,ir as prec,F as seek,C as skip,_ as space,J as step,w as token,k as unary,mr as word};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "subscript",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.4.1",
|
|
4
4
|
"description": "Modular expression parser & evaluator",
|
|
5
5
|
"main": "subscript.js",
|
|
6
6
|
"module": "subscript.js",
|
|
@@ -11,12 +11,20 @@
|
|
|
11
11
|
"./parse": "./parse.js",
|
|
12
12
|
"./justin": "./justin.js",
|
|
13
13
|
"./jessie": "./jessie.js",
|
|
14
|
+
"./feature/subscript": "./feature/subscript.js",
|
|
15
|
+
"./feature/justin": "./feature/justin.js",
|
|
16
|
+
"./feature/jessie": "./feature/jessie.js",
|
|
14
17
|
"./feature/*": "./feature/*",
|
|
18
|
+
"./eval/subscript": "./eval/subscript.js",
|
|
19
|
+
"./eval/justin": "./eval/justin.js",
|
|
20
|
+
"./eval/jessie": "./eval/jessie.js",
|
|
21
|
+
"./eval/*": "./eval/*",
|
|
15
22
|
"./util/*": "./util/*"
|
|
16
23
|
},
|
|
17
24
|
"type": "module",
|
|
18
25
|
"files": [
|
|
19
26
|
"feature",
|
|
27
|
+
"eval",
|
|
20
28
|
"util",
|
|
21
29
|
"subscript.js",
|
|
22
30
|
"subscript.min.js",
|
package/parse.js
CHANGED
|
@@ -2,13 +2,11 @@
|
|
|
2
2
|
// Character codes
|
|
3
3
|
const SPACE = 32;
|
|
4
4
|
|
|
5
|
-
let lineBreak;
|
|
6
|
-
|
|
7
5
|
// current string, index
|
|
8
6
|
export let idx, cur,
|
|
9
7
|
|
|
10
8
|
// parse input string to AST
|
|
11
|
-
parse = s => (idx = 0, cur = s, parse.
|
|
9
|
+
parse = s => (idx = 0, cur = s, parse.enter?.(), s = expr(), cur[idx] ? err() : s || ''),
|
|
12
10
|
|
|
13
11
|
// display error with context
|
|
14
12
|
err = (msg = 'Unexpected token', at = idx,
|
|
@@ -37,37 +35,30 @@ export let idx, cur,
|
|
|
37
35
|
// set position (for backtracking)
|
|
38
36
|
seek = n => idx = n,
|
|
39
37
|
|
|
40
|
-
// a + b - c
|
|
38
|
+
// a + b - c. Pratt loop. Each iteration tries operator handlers via lookup,
|
|
39
|
+
// then identifier (when no token yet). Dialect layers (e.g. ASI) override
|
|
40
|
+
// step() to inject pre-empt or post-step decisions; default just inlines the
|
|
41
|
+
// op-then-id rule.
|
|
41
42
|
expr = (p = 0, end) => {
|
|
42
|
-
let cc, token, newNode
|
|
43
|
-
if (end) parse.
|
|
44
|
-
|
|
45
|
-
while (
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
cc !== end &&
|
|
49
|
-
(newNode =
|
|
50
|
-
// ASI before [ on new line (access handler would consume it; lineBreak distinguishes real \n from synthetic } flag)
|
|
51
|
-
((token && cc === 91 && lineBreak && parse.asi?.(token, p, expr)) || null) ??
|
|
52
|
-
((fn = lookup[cc]) && fn(token, p)) ??
|
|
53
|
-
(token && nl && parse.asi?.(token, p, expr)) ??
|
|
54
|
-
(!token && next(parse.id))
|
|
55
|
-
)
|
|
56
|
-
) token = newNode;
|
|
57
|
-
|
|
58
|
-
if (end) cc == end ? (idx++, end === 125 && parse.asi && (parse.newline = true)) : err('Unclosed ' + String.fromCharCode(end - (end > 42 ? 2 : 1)));
|
|
43
|
+
let cc, token, newNode;
|
|
44
|
+
if (end) parse.enter?.(p, end);
|
|
45
|
+
|
|
46
|
+
while ((cc = space()) && cc !== end && (newNode = step(token, p, cc, expr))) token = newNode;
|
|
47
|
+
|
|
48
|
+
if (end) cc == end ? (idx++, parse.exit?.(p, end)) : err('Unclosed ' + String.fromCharCode(end - (end > 42 ? 2 : 1)));
|
|
59
49
|
|
|
60
50
|
return token;
|
|
61
51
|
},
|
|
62
52
|
|
|
53
|
+
// one Pratt iteration: try operator, else identifier (only at start). Returns
|
|
54
|
+
// truthy node or null (never `false`/`undefined`, so wrapper overrides can
|
|
55
|
+
// chain via `??`).
|
|
56
|
+
step = (a, p, cc, expr, fn) => ((fn = lookup[cc]) && fn(a, p)) || (a ? null : next(parse.id) || null),
|
|
57
|
+
|
|
63
58
|
// skip space chars, return first non-space character
|
|
64
|
-
space = (cc
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if (parse.asi && cc === 10) parse.newline = lineBreak = true
|
|
68
|
-
idx++
|
|
69
|
-
}
|
|
70
|
-
return cc
|
|
59
|
+
space = (cc) => {
|
|
60
|
+
while ((cc = cur.charCodeAt(idx)) <= SPACE) idx++;
|
|
61
|
+
return cc;
|
|
71
62
|
},
|
|
72
63
|
|
|
73
64
|
// peek at next non-space char without modifying idx
|
|
@@ -148,13 +139,20 @@ export let idx, cur,
|
|
|
148
139
|
(seek(idx + l), (r = map()) ? loc(r, from) : seek(from), r) ||
|
|
149
140
|
prev?.(a, curPrec, curOp);
|
|
150
141
|
|
|
151
|
-
// Keep parse.space overrides in sync with the exported
|
|
142
|
+
// Keep parse.space / parse.step overrides in sync with the exported bindings,
|
|
143
|
+
// so wrappers installed via parse.X = ... are picked up by the hot loops here.
|
|
152
144
|
Object.defineProperty(parse, 'space', {
|
|
153
145
|
configurable: true,
|
|
154
146
|
enumerable: true,
|
|
155
147
|
get: () => space,
|
|
156
148
|
set: fn => (space = fn)
|
|
157
149
|
});
|
|
150
|
+
Object.defineProperty(parse, 'step', {
|
|
151
|
+
configurable: true,
|
|
152
|
+
enumerable: true,
|
|
153
|
+
get: () => step,
|
|
154
|
+
set: fn => (step = fn)
|
|
155
|
+
});
|
|
158
156
|
|
|
159
157
|
// === Compile: AST → Evaluator ===
|
|
160
158
|
|
package/subscript.js
CHANGED
|
@@ -9,24 +9,15 @@
|
|
|
9
9
|
* For more features:
|
|
10
10
|
* import { parse, compile } from 'subscript/justin.js' // + JSON, arrows, templates
|
|
11
11
|
* import { parse, compile } from 'subscript/jessie.js' // + statements, functions
|
|
12
|
+
*
|
|
13
|
+
* For parse-only (no eval bundle weight):
|
|
14
|
+
* import { parse } from 'subscript/feature/subscript.js'
|
|
15
|
+
* import { parse } from 'subscript/feature/justin.js'
|
|
16
|
+
* import { parse } from 'subscript/feature/jessie.js'
|
|
12
17
|
*/
|
|
13
18
|
|
|
14
|
-
|
|
15
|
-
import './
|
|
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/seq.js'; // Sequences: a, b; a; b
|
|
28
|
-
import './feature/group.js'; // Grouping: (a)
|
|
29
|
-
import './feature/access.js'; // Property access: a.b, a[b], f(), [a,b]
|
|
19
|
+
import './feature/subscript.js';
|
|
20
|
+
import './eval/subscript.js';
|
|
30
21
|
|
|
31
22
|
import { parse, compile } from './parse.js';
|
|
32
23
|
export * from './parse.js';
|