subscript 8.1.2 → 8.1.3

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/feature/add.js CHANGED
@@ -12,11 +12,11 @@ binary('-', PREC_ADD), operator('-', (a, b) => b && (a = compile(a), b = compile
12
12
  binary('+=', PREC_ASSIGN, true)
13
13
  operator('+=', (a, b) => (
14
14
  b = compile(b),
15
- prop(a, (container, path, ctx) => container(ctx)[path(ctx)] += b(ctx))
15
+ prop(a, (container, path, ctx) => container[path] += b(ctx))
16
16
  ))
17
17
 
18
18
  binary('-=', PREC_ASSIGN, true)
19
19
  operator('-=', (a, b) => (
20
20
  b = compile(b),
21
- prop(a, (container, path, ctx) => (container(ctx)[path(ctx)] -= b(ctx)))
21
+ prop(a, (container, path, ctx) => (container[path] -= b(ctx)))
22
22
  ))
package/feature/assign.js CHANGED
@@ -7,5 +7,5 @@ binary('=', PREC_ASSIGN, true)
7
7
  operator('=', (a, b) => (
8
8
  b = compile(b),
9
9
  // a = x, ((a)) = x, a.b = x, a['b'] = x
10
- prop(a, (container, path, ctx) => container(ctx)[path(ctx)] = b(ctx))
10
+ prop(a, (container, path, ctx) => container[path] = b(ctx))
11
11
  ))
package/feature/call.js CHANGED
@@ -10,6 +10,6 @@ operator('(', (a, b, args) => (
10
10
  (b = compile(b), ctx => [b(ctx)]), // a(b)
11
11
 
12
12
  // a(...args), a.b(...args), a[b](...args)
13
- prop(a, (obj, path, ctx) => obj(ctx)[path(ctx)](...args(ctx)), true)
13
+ prop(a, (obj, path, ctx) => obj[path](...args(ctx)), true)
14
14
  )
15
15
  )
@@ -3,14 +3,12 @@ import { operator, compile, prop } from "../src/compile.js"
3
3
  import { PREC_POSTFIX } from "../src/const.js"
4
4
 
5
5
  let inc, dec
6
- token('++', PREC_POSTFIX, a => a ? ['-', ['++', a], [, 1]] : ['++', expr(PREC_POSTFIX - 1)])
7
- operator('++', inc = (a) =>
8
- // ++a, ++((a)), ++a.b, ++a[b]
9
- prop(a, (obj, path, ctx) => ++obj(ctx)[path(ctx)])
10
- )
6
+ token('++', PREC_POSTFIX, a => a ? ['++-', a] : ['++', expr(PREC_POSTFIX - 1)])
7
+ // ++a, ++((a)), ++a.b, ++a[b]
8
+ operator('++', inc = (a) => prop(a, (obj, path, ctx) => ++obj[path]))
9
+ operator('++-', inc = (a) => prop(a, (obj, path, ctx) => obj[path]++))
11
10
 
12
- token('--', PREC_POSTFIX, a => a ? ['+', ['--', a], [, 1]] : ['--', expr(PREC_POSTFIX - 1)])
13
- operator('--', dec = (a) => (
14
- // --a, --a.b, --a[b]
15
- prop(a, (obj, path, ctx) => --obj(ctx)[path(ctx)])
16
- ))
11
+ token('--', PREC_POSTFIX, a => a ? ['--+', a] : ['--', expr(PREC_POSTFIX - 1)])
12
+ // --a, --a.b, --a[b]
13
+ operator('--', dec = (a) => (prop(a, (obj, path, ctx) => --obj[path])))
14
+ operator('--+', dec = (a) => (prop(a, (obj, path, ctx) => obj[path]--)))
package/feature/mult.js CHANGED
@@ -9,17 +9,17 @@ binary('%', PREC_MULT), operator('%', (a, b) => b && (a = compile(a), b = compil
9
9
  binary('*=', PREC_ASSIGN, true)
10
10
  operator('*=', (a, b) => (
11
11
  b = compile(b),
12
- prop(a, (container, path, ctx) => container(ctx)[path(ctx)] *= b(ctx))
12
+ prop(a, (container, path, ctx) => container[path] *= b(ctx))
13
13
  ))
14
14
 
15
15
  binary('/=', PREC_ASSIGN, true)
16
16
  operator('/=', (a, b) => (
17
17
  b = compile(b),
18
- prop(a, (container, path, ctx) => container(ctx)[path(ctx)] /= b(ctx))
18
+ prop(a, (container, path, ctx) => container[path] /= b(ctx))
19
19
  ))
20
20
 
21
21
  binary('%=', PREC_ASSIGN, true)
22
22
  operator('%=', (a, b) => (
23
23
  b = compile(b),
24
- prop(a, (container, path, ctx) => container(ctx)[path(ctx)] %= b(ctx))
24
+ prop(a, (container, path, ctx) => container[path] %= b(ctx))
25
25
  ))
package/justin.min.js CHANGED
@@ -1 +1 @@
1
- let r,e,t=t=>(r=0,e=t,t=n(),e[r]?a():t||""),a=(t="Bad syntax",a=e.slice(0,r).split("\n"),s=a.pop())=>{let n=e.slice(r-108,r).split("\n").pop(),i=e.slice(r,r+108).split("\n").shift();throw EvalError(`${t} at ${a.length}:${s.length} \`${r>=108?"…":""}${n}▶${i}\``,"font-weight: bold")},s=(t=1,a=r,s)=>{if("number"==typeof t)r+=t;else for(;s=t(e.charCodeAt(r));)r+=s;return e.slice(a,r)},n=(e=0,s,n,i,p,l)=>{for(;(n=t.space())&&(p=((l=o[n])&&l(i,e))??(!i&&t.id()));)i=p;return s&&(n==s?r++:a()),i},i=r=>r>=48&&r<=57||r>=65&&r<=90||r>=97&&r<=122||36==r||95==r||r>=192&&215!=r&&247!=r,p=t.id=()=>s(i),l=t.space=t=>{for(;(t=e.charCodeAt(r))<=32;)r++;return t},o=[],c=(t,a=32,s,n=t.charCodeAt(0),p=t.length,l=o[n],c=t.toUpperCase()!==t)=>o[n]=(n,o,d=r)=>o<a&&(p<2||e.substr(r,p)==t)&&(!c||!i(e.charCodeAt(r+p)))&&(r+=p,s(n,o))||(r=d,l?.(n,o)),d=(r,e,t=!1)=>c(r,e,((a,s)=>a&&(s=n(e-(t?.5:0)))&&[r,a,s])),f=(r,e,t)=>c(r,e,(a=>t?a&&[r,a]:!a&&(a=n(e-.5))&&[r,a])),h=(r,e)=>{c(r,e,((t,a)=>(a=n(e),(!t||t[0]!==r)&&(t=[r,t]),t.push(a),t)))},m=(r,e)=>c(r[0],e,(e=>!e&&[r,n(0,r.charCodeAt(1))])),A=(r,e)=>c(r[0],e,(e=>e&&[r[0],e,n(0,r.charCodeAt(1))]));const b=r=>Array.isArray(r)?r[0]?u[r[0]](...r.slice(1)):()=>r[1]:e=>e?.[r],u={},y=(r,e,t=u[r])=>u[r]=(...r)=>e(...r)||t&&t(...r),C=(r,e,t)=>"()"===r[0]?C(r[1],e,t):"string"==typeof r?e.bind(0,(r=>r),(()=>r)):"."===r[0]?e.bind(0,b(r[1]),(r=r[2],()=>r)):"["===r[0]?e.bind(0,b(r[1]),b(r[2])):t?(r=b(r),e.bind(0,(e=>[r(e)]),(()=>0))):()=>a("Bad left value"),g=r=>r?a():[,(r=+s((r=>46===r||r>=48&&r<=57||(69===r||101===r?2:0))))!=r?a():r];o[46]=r=>!r&&g();for(let r=48;r<=57;r++)o[r]=g;const $={n:"\n",r:"\r",t:"\t",b:"\b",f:"\f",v:"\v"},v=t=>(n,i,p="")=>{for(n&&a("Unexpected string"),s();(i=e.charCodeAt(r))-t;)92===i?(s(),i=s(),p+=$[i]||i):p+=s();return s()||a("Bad string"),[,p]};o[34]=v(34),o[39]=v(39),A("()",17),y("(",((r,e,t)=>(t=e?","===e[0]?(e=e.slice(1).map((r=>r?b(r):err())),r=>e.map((e=>e(r)))):(e=b(e),r=>[e(r)]):()=>[],C(r,((r,e,a)=>r(a)[e(a)](...t(a))),!0)))),A("[]",17),y("[",((r,e)=>e?(r=b(r),e=b(e),t=>r(t)[e(t)]):err())),d(".",17),y(".",((r,e)=>(r=b(r),e=e[0]?e:e[1],t=>r(t)[e]))),m("()",17),y("()",(r=>(!r&&a("Empty ()"),b(r))));const E=(...r)=>(r=r.map(b),e=>r.map((r=>r(e))).pop());h(",",1),y(",",E),h(";",1),y(";",E),d("*",12),y("*",((r,e)=>e&&(r=b(r),e=b(e),t=>r(t)*e(t)))),d("/",12),y("/",((r,e)=>e&&(r=b(r),e=b(e),t=>r(t)/e(t)))),d("%",12),y("%",((r,e)=>e&&(r=b(r),e=b(e),t=>r(t)%e(t)))),d("*=",2,!0),y("*=",((r,e)=>(e=b(e),C(r,((r,t,a)=>r(a)[t(a)]*=e(a)))))),d("/=",2,!0),y("/=",((r,e)=>(e=b(e),C(r,((r,t,a)=>r(a)[t(a)]/=e(a)))))),d("%=",2,!0),y("%=",((r,e)=>(e=b(e),C(r,((r,t,a)=>r(a)[t(a)]%=e(a)))))),f("+",14),y("+",((r,e)=>!e&&(r=b(r),e=>+r(e)))),f("-",14),y("-",((r,e)=>!e&&(r=b(r),e=>-r(e)))),d("+",11),y("+",((r,e)=>e&&(r=b(r),e=b(e),t=>r(t)+e(t)))),d("-",11),y("-",((r,e)=>e&&(r=b(r),e=b(e),t=>r(t)-e(t)))),d("+=",2,!0),y("+=",((r,e)=>(e=b(e),C(r,((r,t,a)=>r(a)[t(a)]+=e(a)))))),d("-=",2,!0),y("-=",((r,e)=>(e=b(e),C(r,((r,t,a)=>r(a)[t(a)]-=e(a)))))),c("++",15,(r=>r?["-",["++",r],[,1]]:["++",n(14)])),y("++",(r=>C(r,((r,e,t)=>++r(t)[e(t)])))),c("--",15,(r=>r?["+",["--",r],[,1]]:["--",n(14)])),y("--",(r=>C(r,((r,e,t)=>--r(t)[e(t)])))),f("~",14),y("~",((r,e)=>!e&&(r=b(r),e=>~r(e)))),d("|",5),y("|",((r,e)=>e&&(r=b(r),e=b(e),t=>r(t)|e(t)))),d("&",7),y("&",((r,e)=>e&&(r=b(r),e=b(e),t=>r(t)&e(t)))),d("^",6),y("^",((r,e)=>e&&(r=b(r),e=b(e),t=>r(t)^e(t)))),d(">>",10),y(">>",((r,e)=>e&&(r=b(r),e=b(e),t=>r(t)>>e(t)))),d("<<",10),y("<<",((r,e)=>e&&(r=b(r),e=b(e),t=>r(t)<<e(t)))),d("==",8),y("==",((r,e)=>e&&(r=b(r),e=b(e),t=>r(t)==e(t)))),d("!=",8),y("!=",((r,e)=>e&&(r=b(r),e=b(e),t=>r(t)!=e(t)))),d(">",8),y(">",((r,e)=>e&&(r=b(r),e=b(e),t=>r(t)>e(t)))),d("<",8),y("<",((r,e)=>e&&(r=b(r),e=b(e),t=>r(t)<e(t)))),d(">=",8),y(">=",((r,e)=>e&&(r=b(r),e=b(e),t=>r(t)>=e(t)))),d("<=",8),y("<=",((r,e)=>e&&(r=b(r),e=b(e),t=>r(t)<=e(t)))),f("!",14),y("!",((r,e)=>!e&&(r=b(r),e=>!r(e)))),d("||",3),y("||",((r,e)=>(r=b(r),e=b(e),t=>r(t)||e(t)))),d("&&",4),y("&&",((r,e)=>(r=b(r),e=b(e),t=>r(t)&&e(t)))),d("=",2,!0),y("=",((r,e)=>(e=b(e),C(r,((r,t,a)=>r(a)[t(a)]=e(a))))));var x=r=>b(t(r));c("/*",20,((t,a)=>(s((t=>42!==t&&47!==e.charCodeAt(r+1))),s(2),t||n(a)||[]))),c("//",20,((r,e)=>(s((r=>r>=32)),r||n(e)||[""]))),d("**",13,!0),y("**",((r,e)=>e&&(r=b(r),e=b(e),t=>r(t)**e(t)))),d("in",9),y("in",((r,e)=>e&&(r=b(r),e=b(e),t=>r(t)in e(t)))),c("?",2,((r,e,t)=>r&&(e=n(2,58))&&["?",r,e,n(3)])),y("?",((r,e,t)=>(r=b(r),e=b(e),t=b(t),a=>r(a)?e(a):t(a)))),c("true",20,(r=>r?err():[,!0])),c("false",20,(r=>r?err():[,!1])),m("[]",20),y("[]",((r,e)=>r?","===r[0]?(r=r.slice(1).map(b),e=>r.map((r=>r(e)))):(r=b(r),e=>[r(e)]):()=>[])),m("{}",20),y("{}",((r,e)=>r?","===r[0]?(r=r.slice(1).map(b),e=>Object.fromEntries(r.map((r=>r(e))))):":"===r[0]?(r=b(r),e=>Object.fromEntries([r(e)])):(e=b(r),t=>({[r]:e(t)})):()=>({}))),d(":",2,!0),y(":",((r,e)=>(e=b(e),r=Array.isArray(r)?b(r):(r=>r).bind(0,r),t=>[r(t),e(t)]))),c("?.",17,(r=>r&&["?.",r])),y("?.",(r=>(r=b(r),e=>r(e)||(()=>{})))),c("?.",17,((r,e)=>r&&!(e=n(17))?.map&&["?.",r,e])),y("?.",((r,e)=>e&&(r=b(r),t=>r(t)?.[e]))),y("(",((r,e,t,a,s,n)=>"?."===r[0]&&(r[2]||Array.isArray(r[1]))&&(a=e?","===e[0]?(e=e.slice(1).map(b),r=>e.map((e=>e(r)))):(e=b(e),r=>[e(r)]):()=>[],!r[2]&&(r=r[1]),s="["===r[0]?b(r[2]):()=>r[2],t=b(r[1]),r=>t(r)?.[s(r)]?.(...a(r))))),c("null",20,(r=>r?a():[,null]));export{A as access,d as binary,b as compile,e as cur,x as default,a as err,n as expr,m as group,p as id,r as idx,i as isId,o as lookup,h as nary,y as operator,u as operators,t as parse,C as prop,s as skip,l as space,c as token,f as unary};
1
+ let r,e,t=t=>(r=0,e=t,t=i(),e[r]?a():t||""),a=(t="Bad syntax",a=e.slice(0,r).split("\n"),s=a.pop())=>{let i=e.slice(r-108,r).split("\n").pop(),n=e.slice(r,r+108).split("\n").shift();throw EvalError(`${t} at ${a.length}:${s.length} \`${r>=108?"…":""}${i}▶${n}\``,"font-weight: bold")},s=(t=1,a=r,s)=>{if("number"==typeof t)r+=t;else for(;s=t(e.charCodeAt(r));)r+=s;return e.slice(a,r)},i=(e=0,s,i,n,l,p)=>{for(;(i=t.space())&&(l=((p=o[i])&&p(n,e))??(!n&&t.id()));)n=l;return s&&(i==s?r++:a()),n},n=r=>r>=48&&r<=57||r>=65&&r<=90||r>=97&&r<=122||36==r||95==r||r>=192&&215!=r&&247!=r;t.id=()=>s(n);let l=t.space=t=>{for(;(t=e.charCodeAt(r))<=32;)r++;return t},o=[],p=(t,a=32,s,i=t.charCodeAt(0),l=t.length,p=o[i],c=t.toUpperCase()!==t)=>o[i]=(i,o,d=r)=>o<a&&(l<2||e.substr(r,l)==t)&&(!c||!n(e.charCodeAt(r+l)))&&(r+=l,s(i,o))||(r=d,p?.(i,o)),c=(r,e,t=!1)=>p(r,e,((a,s)=>a&&(s=i(e-(t?.5:0)))&&[r,a,s])),d=(r,e,t)=>p(r,e,(a=>t?a&&[r,a]:!a&&(a=i(e-.5))&&[r,a])),f=(r,e)=>{p(r,e,((t,a)=>(a=i(e),(!t||t[0]!==r)&&(t=[r,t]),t.push(a),t)))},h=(r,e)=>p(r[0],e,(e=>!e&&[r,i(0,r.charCodeAt(1))])),m=(r,e)=>p(r[0],e,(e=>e&&[r[0],e,i(0,r.charCodeAt(1))]));const A=r=>Array.isArray(r)?r[0]?u[r[0]](...r.slice(1)):()=>r[1]:A.id(r);A.id=r=>e=>e?.[r];const u={},y=(r,e,t=u[r])=>u[r]=(...r)=>e(...r)||t&&t(...r),C=(r,e,t,s,i)=>"()"===r[0]?C(r[1],e,t):"string"==typeof r?t=>e(t,r,t):"."===r[0]?(s=A(r[1]),i=r[2],r=>e(s(r),i,r)):"["===r[0]?(s=A(r[1]),i=A(r[2]),r=>e(s(r),i(r),r)):t?(r=A(r),t=>e([r(t)],0,t)):()=>a("Bad left value"),b=r=>r?a():[,(r=+s((r=>46===r||r>=48&&r<=57||(69===r||101===r?2:0))))!=r?a():r];o[46]=r=>!r&&b();for(let r=48;r<=57;r++)o[r]=b;const g={n:"\n",r:"\r",t:"\t",b:"\b",f:"\f",v:"\v"},$=t=>(i,n,l="")=>{for(i&&a("Unexpected string"),s();(n=e.charCodeAt(r))-t;)92===n?(s(),n=s(),l+=g[n]||n):l+=s();return s()||a("Bad string"),[,l]};o[34]=$(34),o[39]=$(39),m("()",17),y("(",((r,e,t)=>(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)]):()=>[],C(r,((r,e,a)=>r[e](...t(a))),!0)))),m("[]",17),y("[",((r,e)=>e?(r=A(r),e=A(e),t=>r(t)[e(t)]):err())),c(".",17),y(".",((r,e)=>(r=A(r),e=e[0]?e:e[1],t=>r(t)[e]))),h("()",17),y("()",(r=>(!r&&a("Empty ()"),A(r))));const v=(...r)=>(r=r.map(A),e=>r.map((r=>r(e))).pop());f(",",1),y(",",v),f(";",1),y(";",v),c("*",12),y("*",((r,e)=>e&&(r=A(r),e=A(e),t=>r(t)*e(t)))),c("/",12),y("/",((r,e)=>e&&(r=A(r),e=A(e),t=>r(t)/e(t)))),c("%",12),y("%",((r,e)=>e&&(r=A(r),e=A(e),t=>r(t)%e(t)))),c("*=",2,!0),y("*=",((r,e)=>(e=A(e),C(r,((r,t,a)=>r[t]*=e(a)))))),c("/=",2,!0),y("/=",((r,e)=>(e=A(e),C(r,((r,t,a)=>r[t]/=e(a)))))),c("%=",2,!0),y("%=",((r,e)=>(e=A(e),C(r,((r,t,a)=>r[t]%=e(a)))))),d("+",14),y("+",((r,e)=>!e&&(r=A(r),e=>+r(e)))),d("-",14),y("-",((r,e)=>!e&&(r=A(r),e=>-r(e)))),c("+",11),y("+",((r,e)=>e&&(r=A(r),e=A(e),t=>r(t)+e(t)))),c("-",11),y("-",((r,e)=>e&&(r=A(r),e=A(e),t=>r(t)-e(t)))),c("+=",2,!0),y("+=",((r,e)=>(e=A(e),C(r,((r,t,a)=>r[t]+=e(a)))))),c("-=",2,!0),y("-=",((r,e)=>(e=A(e),C(r,((r,t,a)=>r[t]-=e(a)))))),p("++",15,(r=>r?["++-",r]:["++",i(14)])),y("++",(r=>C(r,((r,e,t)=>++r[e])))),y("++-",(r=>C(r,((r,e,t)=>r[e]++)))),p("--",15,(r=>r?["--+",r]:["--",i(14)])),y("--",(r=>C(r,((r,e,t)=>--r[e])))),y("--+",(r=>C(r,((r,e,t)=>r[e]--)))),d("~",14),y("~",((r,e)=>!e&&(r=A(r),e=>~r(e)))),c("|",5),y("|",((r,e)=>e&&(r=A(r),e=A(e),t=>r(t)|e(t)))),c("&",7),y("&",((r,e)=>e&&(r=A(r),e=A(e),t=>r(t)&e(t)))),c("^",6),y("^",((r,e)=>e&&(r=A(r),e=A(e),t=>r(t)^e(t)))),c(">>",10),y(">>",((r,e)=>e&&(r=A(r),e=A(e),t=>r(t)>>e(t)))),c("<<",10),y("<<",((r,e)=>e&&(r=A(r),e=A(e),t=>r(t)<<e(t)))),c("==",8),y("==",((r,e)=>e&&(r=A(r),e=A(e),t=>r(t)==e(t)))),c("!=",8),y("!=",((r,e)=>e&&(r=A(r),e=A(e),t=>r(t)!=e(t)))),c(">",8),y(">",((r,e)=>e&&(r=A(r),e=A(e),t=>r(t)>e(t)))),c("<",8),y("<",((r,e)=>e&&(r=A(r),e=A(e),t=>r(t)<e(t)))),c(">=",8),y(">=",((r,e)=>e&&(r=A(r),e=A(e),t=>r(t)>=e(t)))),c("<=",8),y("<=",((r,e)=>e&&(r=A(r),e=A(e),t=>r(t)<=e(t)))),d("!",14),y("!",((r,e)=>!e&&(r=A(r),e=>!r(e)))),c("||",3),y("||",((r,e)=>(r=A(r),e=A(e),t=>r(t)||e(t)))),c("&&",4),y("&&",((r,e)=>(r=A(r),e=A(e),t=>r(t)&&e(t)))),c("=",2,!0),y("=",((r,e)=>(e=A(e),C(r,((r,t,a)=>r[t]=e(a))))));var E=r=>A(t(r));p("/*",20,((t,a)=>(s((t=>42!==t&&47!==e.charCodeAt(r+1))),s(2),t||i(a)||[]))),p("//",20,((r,e)=>(s((r=>r>=32)),r||i(e)||[""]))),c("**",13,!0),y("**",((r,e)=>e&&(r=A(r),e=A(e),t=>r(t)**e(t)))),c("in",9),y("in",((r,e)=>e&&(r=A(r),e=A(e),t=>r(t)in e(t)))),p("?",2,((r,e,t)=>r&&(e=i(2,58))&&["?",r,e,i(3)])),y("?",((r,e,t)=>(r=A(r),e=A(e),t=A(t),a=>r(a)?e(a):t(a)))),p("true",20,(r=>r?err():[,!0])),p("false",20,(r=>r?err():[,!1])),h("[]",20),y("[]",((r,e)=>r?","===r[0]?(r=r.slice(1).map(A),e=>r.map((r=>r(e)))):(r=A(r),e=>[r(e)]):()=>[])),h("{}",20),y("{}",((r,e)=>r?","===r[0]?(r=r.slice(1).map(A),e=>Object.fromEntries(r.map((r=>r(e))))):":"===r[0]?(r=A(r),e=>Object.fromEntries([r(e)])):(e=A(r),t=>({[r]:e(t)})):()=>({}))),c(":",2,!0),y(":",((r,e)=>(e=A(e),r=Array.isArray(r)?A(r):(r=>r).bind(0,r),t=>[r(t),e(t)]))),p("?.",17,(r=>r&&["?.",r])),y("?.",(r=>(r=A(r),e=>r(e)||(()=>{})))),p("?.",17,((r,e)=>r&&!(e=i(17))?.map&&["?.",r,e])),y("?.",((r,e)=>e&&(r=A(r),t=>r(t)?.[e]))),y("(",((r,e,t,a,s,i)=>"?."===r[0]&&(r[2]||Array.isArray(r[1]))&&(a=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]),s="["===r[0]?A(r[2]):()=>r[2],t=A(r[1]),r=>t(r)?.[s(r)]?.(...a(r))))),p("null",20,(r=>r?a():[,null]));export{m as access,c as binary,A as compile,e as cur,E as default,a as err,i as expr,h as group,r as idx,n as isId,o as lookup,f as nary,y as operator,u as operators,t as parse,C as prop,s as skip,l as space,p as token,d as unary};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "subscript",
3
- "version": "8.1.2",
3
+ "version": "8.1.3",
4
4
  "description": "Fast and tiny expression evaluator with minimal syntax.",
5
5
  "main": "subscript.js",
6
6
  "module": "subscript.js",
package/src/compile.js CHANGED
@@ -1,7 +1,10 @@
1
1
  import { err } from "./parse.js"
2
2
 
3
3
  // build optimized evaluator for the tree
4
- export const compile = (node) => !Array.isArray(node) ? ctx => ctx?.[node] : !node[0] ? () => node[1] : operators[node[0]](...node.slice(1)),
4
+ export const compile = (node) => !Array.isArray(node) ? compile.id(node) : !node[0] ? () => node[1] : operators[node[0]](...node.slice(1)),
5
+ // compile id getter
6
+ id = compile.id = name => ctx => ctx?.[name],
7
+
5
8
 
6
9
  // registered operators
7
10
  operators = {},
@@ -10,17 +13,17 @@ export const compile = (node) => !Array.isArray(node) ? ctx => ctx?.[node] : !no
10
13
  operator = (op, fn, prev = operators[op]) => (operators[op] = (...args) => fn(...args) || prev && prev(...args)),
11
14
 
12
15
  // takes node and returns evaluator depending on the case with passed params (container, path, ctx) =>
13
- prop = (a, fn, generic) => (
16
+ prop = (a, fn, generic, obj, path) => (
14
17
  // (((x))) => x
15
18
  a[0] === '()' ? prop(a[1], fn, generic) :
16
19
  // (_, name, ctx) => ctx[path]
17
- typeof a === 'string' ? fn.bind(0, ctx => ctx, () => a) :
20
+ typeof a === 'string' ? ctx => fn(ctx, a, ctx) :
18
21
  // (container, path, ctx) => container(ctx)[path]
19
- a[0] === '.' ? fn.bind(0, compile(a[1]), (a = a[2], () => a)) :
22
+ a[0] === '.' ? (obj = compile(a[1]), path = a[2], ctx => fn(obj(ctx), path, ctx)) :
20
23
  // (container, path, ctx) => container(ctx)[path(ctx)]
21
- a[0] === '[' ? fn.bind(0, compile(a[1]), compile(a[2])) :
24
+ a[0] === '[' ? (obj = compile(a[1]), path = compile(a[2]), ctx => fn(obj(ctx), path(ctx), ctx)) :
22
25
  // (src, _, ctx) => src(ctx)
23
- generic ? (a = compile(a), fn.bind(0, ctx => [a(ctx)], () => 0)) : () => err('Bad left value')
26
+ generic ? (a = compile(a), ctx => fn([a(ctx)], 0, ctx)) : () => err('Bad left value')
24
27
  )
25
28
 
26
29
  export default compile
package/subscript.min.js CHANGED
@@ -1 +1 @@
1
- let r,t,e=e=>(r=0,t=e,e=n(),t[r]?s():e||""),s=(e="Bad syntax",s=t.slice(0,r).split("\n"),a=s.pop())=>{let n=t.slice(r-108,r).split("\n").pop(),o=t.slice(r,r+108).split("\n").shift();throw EvalError(`${e} at ${s.length}:${a.length} \`${r>=108?"…":""}${n}▶${o}\``,"font-weight: bold")},a=(e=1,s=r,a)=>{if("number"==typeof e)r+=e;else for(;a=e(t.charCodeAt(r));)r+=a;return t.slice(s,r)},n=(t=0,a,n,o,p,i)=>{for(;(n=e.space())&&(p=((i=l[n])&&i(o,t))??(!o&&e.id()));)o=p;return a&&(n==a?r++:s()),o},o=r=>r>=48&&r<=57||r>=65&&r<=90||r>=97&&r<=122||36==r||95==r||r>=192&&215!=r&&247!=r,p=e.id=()=>a(o),i=e.space=e=>{for(;(e=t.charCodeAt(r))<=32;)r++;return e},l=[],c=(e,s=32,a,n=e.charCodeAt(0),p=e.length,i=l[n],c=e.toUpperCase()!==e)=>l[n]=(n,l,d=r)=>l<s&&(p<2||t.substr(r,p)==e)&&(!c||!o(t.charCodeAt(r+p)))&&(r+=p,a(n,l))||(r=d,i?.(n,l)),d=(r,t,e=!1)=>c(r,t,((s,a)=>s&&(a=n(t-(e?.5:0)))&&[r,s,a])),f=(r,t,e)=>c(r,t,(s=>e?s&&[r,s]:!s&&(s=n(t-.5))&&[r,s])),h=(r,t)=>{c(r,t,((e,s)=>(s=n(t),(!e||e[0]!==r)&&(e=[r,e]),e.push(s),e)))},b=(r,t)=>c(r[0],t,(t=>!t&&[r,n(0,r.charCodeAt(1))])),u=(r,t)=>c(r[0],t,(t=>t&&[r[0],t,n(0,r.charCodeAt(1))]));const A=r=>r?s():[,(r=+a((r=>46===r||r>=48&&r<=57||(69===r||101===r?2:0))))!=r?s():r];l[46]=r=>!r&&A();for(let r=48;r<=57;r++)l[r]=A;const C={n:"\n",r:"\r",t:"\t",b:"\b",f:"\f",v:"\v"},g=e=>(n,o,p="")=>{for(n&&s("Unexpected string"),a();(o=t.charCodeAt(r))-e;)92===o?(a(),o=a(),p+=C[o]||o):p+=a();return a()||s("Bad string"),[,p]};l[34]=g(34),l[39]=g(39);const m=r=>Array.isArray(r)?r[0]?y[r[0]](...r.slice(1)):()=>r[1]:t=>t?.[r],y={},$=(r,t,e=y[r])=>y[r]=(...r)=>t(...r)||e&&e(...r),v=(r,t,e)=>"()"===r[0]?v(r[1],t,e):"string"==typeof r?t.bind(0,(r=>r),(()=>r)):"."===r[0]?t.bind(0,m(r[1]),(r=r[2],()=>r)):"["===r[0]?t.bind(0,m(r[1]),m(r[2])):e?(r=m(r),t.bind(0,(t=>[r(t)]),(()=>0))):()=>s("Bad left value");u("()",17),$("(",((r,t,e)=>(e=t?","===t[0]?(t=t.slice(1).map((r=>r?m(r):err())),r=>t.map((t=>t(r)))):(t=m(t),r=>[t(r)]):()=>[],v(r,((r,t,s)=>r(s)[t(s)](...e(s))),!0)))),u("[]",17),$("[",((r,t)=>t?(r=m(r),t=m(t),e=>r(e)[t(e)]):err())),d(".",17),$(".",((r,t)=>(r=m(r),t=t[0]?t:t[1],e=>r(e)[t]))),b("()",17),$("()",(r=>(!r&&s("Empty ()"),m(r))));const x=(...r)=>(r=r.map(m),t=>r.map((r=>r(t))).pop());h(",",1),$(",",x),h(";",1),$(";",x),d("*",12),$("*",((r,t)=>t&&(r=m(r),t=m(t),e=>r(e)*t(e)))),d("/",12),$("/",((r,t)=>t&&(r=m(r),t=m(t),e=>r(e)/t(e)))),d("%",12),$("%",((r,t)=>t&&(r=m(r),t=m(t),e=>r(e)%t(e)))),d("*=",2,!0),$("*=",((r,t)=>(t=m(t),v(r,((r,e,s)=>r(s)[e(s)]*=t(s)))))),d("/=",2,!0),$("/=",((r,t)=>(t=m(t),v(r,((r,e,s)=>r(s)[e(s)]/=t(s)))))),d("%=",2,!0),$("%=",((r,t)=>(t=m(t),v(r,((r,e,s)=>r(s)[e(s)]%=t(s)))))),f("+",14),$("+",((r,t)=>!t&&(r=m(r),t=>+r(t)))),f("-",14),$("-",((r,t)=>!t&&(r=m(r),t=>-r(t)))),d("+",11),$("+",((r,t)=>t&&(r=m(r),t=m(t),e=>r(e)+t(e)))),d("-",11),$("-",((r,t)=>t&&(r=m(r),t=m(t),e=>r(e)-t(e)))),d("+=",2,!0),$("+=",((r,t)=>(t=m(t),v(r,((r,e,s)=>r(s)[e(s)]+=t(s)))))),d("-=",2,!0),$("-=",((r,t)=>(t=m(t),v(r,((r,e,s)=>r(s)[e(s)]-=t(s)))))),c("++",15,(r=>r?["-",["++",r],[,1]]:["++",n(14)])),$("++",(r=>v(r,((r,t,e)=>++r(e)[t(e)])))),c("--",15,(r=>r?["+",["--",r],[,1]]:["--",n(14)])),$("--",(r=>v(r,((r,t,e)=>--r(e)[t(e)])))),f("~",14),$("~",((r,t)=>!t&&(r=m(r),t=>~r(t)))),d("|",5),$("|",((r,t)=>t&&(r=m(r),t=m(t),e=>r(e)|t(e)))),d("&",7),$("&",((r,t)=>t&&(r=m(r),t=m(t),e=>r(e)&t(e)))),d("^",6),$("^",((r,t)=>t&&(r=m(r),t=m(t),e=>r(e)^t(e)))),d(">>",10),$(">>",((r,t)=>t&&(r=m(r),t=m(t),e=>r(e)>>t(e)))),d("<<",10),$("<<",((r,t)=>t&&(r=m(r),t=m(t),e=>r(e)<<t(e)))),d("==",8),$("==",((r,t)=>t&&(r=m(r),t=m(t),e=>r(e)==t(e)))),d("!=",8),$("!=",((r,t)=>t&&(r=m(r),t=m(t),e=>r(e)!=t(e)))),d(">",8),$(">",((r,t)=>t&&(r=m(r),t=m(t),e=>r(e)>t(e)))),d("<",8),$("<",((r,t)=>t&&(r=m(r),t=m(t),e=>r(e)<t(e)))),d(">=",8),$(">=",((r,t)=>t&&(r=m(r),t=m(t),e=>r(e)>=t(e)))),d("<=",8),$("<=",((r,t)=>t&&(r=m(r),t=m(t),e=>r(e)<=t(e)))),f("!",14),$("!",((r,t)=>!t&&(r=m(r),t=>!r(t)))),d("||",3),$("||",((r,t)=>(r=m(r),t=m(t),e=>r(e)||t(e)))),d("&&",4),$("&&",((r,t)=>(r=m(r),t=m(t),e=>r(e)&&t(e)))),d("=",2,!0),$("=",((r,t)=>(t=m(t),v(r,((r,e,s)=>r(s)[e(s)]=t(s))))));var B=r=>m(e(r));export{u as access,d as binary,m as compile,t as cur,B as default,s as err,n as expr,b as group,p as id,r as idx,o as isId,l as lookup,h as nary,$ as operator,y as operators,e as parse,v as prop,a as skip,i as space,c as token,f as unary};
1
+ let t,e,r=r=>(t=0,e=r,r=a(),e[t]?s():r||""),s=(r="Bad syntax",s=e.slice(0,t).split("\n"),o=s.pop())=>{let a=e.slice(t-108,t).split("\n").pop(),n=e.slice(t,t+108).split("\n").shift();throw EvalError(`${r} at ${s.length}:${o.length} \`${t>=108?"…":""}${a}▶${n}\``,"font-weight: bold")},o=(r=1,s=t,o)=>{if("number"==typeof r)t+=r;else for(;o=r(e.charCodeAt(t));)t+=o;return e.slice(s,t)},a=(e=0,o,a,n,p,c)=>{for(;(a=r.space())&&(p=((c=l[a])&&c(n,e))??(!n&&r.id()));)n=p;return o&&(a==o?t++:s()),n},n=t=>t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122||36==t||95==t||t>=192&&215!=t&&247!=t;r.id=()=>o(n);let p=r.space=r=>{for(;(r=e.charCodeAt(t))<=32;)t++;return r},l=[],c=(r,s=32,o,a=r.charCodeAt(0),p=r.length,c=l[a],i=r.toUpperCase()!==r)=>l[a]=(a,l,d=t)=>l<s&&(p<2||e.substr(t,p)==r)&&(!i||!n(e.charCodeAt(t+p)))&&(t+=p,o(a,l))||(t=d,c?.(a,l)),i=(t,e,r=!1)=>c(t,e,((s,o)=>s&&(o=a(e-(r?.5:0)))&&[t,s,o])),d=(t,e,r)=>c(t,e,(s=>r?s&&[t,s]:!s&&(s=a(e-.5))&&[t,s])),f=(t,e)=>{c(t,e,((r,s)=>(s=a(e),(!r||r[0]!==t)&&(r=[t,r]),r.push(s),r)))},h=(t,e)=>c(t[0],e,(e=>!e&&[t,a(0,t.charCodeAt(1))])),u=(t,e)=>c(t[0],e,(e=>e&&[t[0],e,a(0,t.charCodeAt(1))]));const A=t=>t?s():[,(t=+o((t=>46===t||t>=48&&t<=57||(69===t||101===t?2:0))))!=t?s():t];l[46]=t=>!t&&A();for(let t=48;t<=57;t++)l[t]=A;const C={n:"\n",r:"\r",t:"\t",b:"\b",f:"\f",v:"\v"},g=r=>(a,n,p="")=>{for(a&&s("Unexpected string"),o();(n=e.charCodeAt(t))-r;)92===n?(o(),n=o(),p+=C[n]||n):p+=o();return o()||s("Bad string"),[,p]};l[34]=g(34),l[39]=g(39);const m=t=>Array.isArray(t)?t[0]?y[t[0]](...t.slice(1)):()=>t[1]:m.id(t);m.id=t=>e=>e?.[t];const y={},$=(t,e,r=y[t])=>y[t]=(...t)=>e(...t)||r&&r(...t),b=(t,e,r,o,a)=>"()"===t[0]?b(t[1],e,r):"string"==typeof t?r=>e(r,t,r):"."===t[0]?(o=m(t[1]),a=t[2],t=>e(o(t),a,t)):"["===t[0]?(o=m(t[1]),a=m(t[2]),t=>e(o(t),a(t),t)):r?(t=m(t),r=>e([t(r)],0,r)):()=>s("Bad left value");u("()",17),$("(",((t,e,r)=>(r=e?","===e[0]?(e=e.slice(1).map((t=>t?m(t):err())),t=>e.map((e=>e(t)))):(e=m(e),t=>[e(t)]):()=>[],b(t,((t,e,s)=>t[e](...r(s))),!0)))),u("[]",17),$("[",((t,e)=>e?(t=m(t),e=m(e),r=>t(r)[e(r)]):err())),i(".",17),$(".",((t,e)=>(t=m(t),e=e[0]?e:e[1],r=>t(r)[e]))),h("()",17),$("()",(t=>(!t&&s("Empty ()"),m(t))));const v=(...t)=>(t=t.map(m),e=>t.map((t=>t(e))).pop());f(",",1),$(",",v),f(";",1),$(";",v),i("*",12),$("*",((t,e)=>e&&(t=m(t),e=m(e),r=>t(r)*e(r)))),i("/",12),$("/",((t,e)=>e&&(t=m(t),e=m(e),r=>t(r)/e(r)))),i("%",12),$("%",((t,e)=>e&&(t=m(t),e=m(e),r=>t(r)%e(r)))),i("*=",2,!0),$("*=",((t,e)=>(e=m(e),b(t,((t,r,s)=>t[r]*=e(s)))))),i("/=",2,!0),$("/=",((t,e)=>(e=m(e),b(t,((t,r,s)=>t[r]/=e(s)))))),i("%=",2,!0),$("%=",((t,e)=>(e=m(e),b(t,((t,r,s)=>t[r]%=e(s)))))),d("+",14),$("+",((t,e)=>!e&&(t=m(t),e=>+t(e)))),d("-",14),$("-",((t,e)=>!e&&(t=m(t),e=>-t(e)))),i("+",11),$("+",((t,e)=>e&&(t=m(t),e=m(e),r=>t(r)+e(r)))),i("-",11),$("-",((t,e)=>e&&(t=m(t),e=m(e),r=>t(r)-e(r)))),i("+=",2,!0),$("+=",((t,e)=>(e=m(e),b(t,((t,r,s)=>t[r]+=e(s)))))),i("-=",2,!0),$("-=",((t,e)=>(e=m(e),b(t,((t,r,s)=>t[r]-=e(s)))))),c("++",15,(t=>t?["++-",t]:["++",a(14)])),$("++",(t=>b(t,((t,e,r)=>++t[e])))),$("++-",(t=>b(t,((t,e,r)=>t[e]++)))),c("--",15,(t=>t?["--+",t]:["--",a(14)])),$("--",(t=>b(t,((t,e,r)=>--t[e])))),$("--+",(t=>b(t,((t,e,r)=>t[e]--)))),d("~",14),$("~",((t,e)=>!e&&(t=m(t),e=>~t(e)))),i("|",5),$("|",((t,e)=>e&&(t=m(t),e=m(e),r=>t(r)|e(r)))),i("&",7),$("&",((t,e)=>e&&(t=m(t),e=m(e),r=>t(r)&e(r)))),i("^",6),$("^",((t,e)=>e&&(t=m(t),e=m(e),r=>t(r)^e(r)))),i(">>",10),$(">>",((t,e)=>e&&(t=m(t),e=m(e),r=>t(r)>>e(r)))),i("<<",10),$("<<",((t,e)=>e&&(t=m(t),e=m(e),r=>t(r)<<e(r)))),i("==",8),$("==",((t,e)=>e&&(t=m(t),e=m(e),r=>t(r)==e(r)))),i("!=",8),$("!=",((t,e)=>e&&(t=m(t),e=m(e),r=>t(r)!=e(r)))),i(">",8),$(">",((t,e)=>e&&(t=m(t),e=m(e),r=>t(r)>e(r)))),i("<",8),$("<",((t,e)=>e&&(t=m(t),e=m(e),r=>t(r)<e(r)))),i(">=",8),$(">=",((t,e)=>e&&(t=m(t),e=m(e),r=>t(r)>=e(r)))),i("<=",8),$("<=",((t,e)=>e&&(t=m(t),e=m(e),r=>t(r)<=e(r)))),d("!",14),$("!",((t,e)=>!e&&(t=m(t),e=>!t(e)))),i("||",3),$("||",((t,e)=>(t=m(t),e=m(e),r=>t(r)||e(r)))),i("&&",4),$("&&",((t,e)=>(t=m(t),e=m(e),r=>t(r)&&e(r)))),i("=",2,!0),$("=",((t,e)=>(e=m(e),b(t,((t,r,s)=>t[r]=e(s))))));var x=t=>m(r(t));export{u as access,i as binary,m as compile,e as cur,x as default,s as err,a as expr,h as group,t as idx,n as isId,l as lookup,f as nary,$ as operator,y as operators,r as parse,b as prop,o as skip,p as space,c as token,d as unary};