subscript 9.0.1 → 9.1.0
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 +7 -7
- package/feature/increment.js +4 -7
- package/justin.min.js +1 -1
- package/package.json +2 -2
- package/src/compile.js +1 -2
- package/src/parse.js +3 -2
- package/subscript.js +1 -1
- package/subscript.min.js +1 -1
package/README.md
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
#### Used for:
|
|
6
6
|
|
|
7
|
-
* expressions evaluators, calculators
|
|
8
|
-
* subsets of languages (eg. [
|
|
7
|
+
* expressions evaluators, calculators
|
|
8
|
+
* subsets of languages (eg. [justin](#justin)<!-- [jz](https://github.com/dy/jz) -->)
|
|
9
9
|
* sandboxes, playgrounds, safe eval (eg. [glsl-transpiler](https://github.com/stackgl/glsl-transpiler))
|
|
10
10
|
* custom DSL (eg. [piezo](https://github.com/dy/piezo)) <!-- uneural -->
|
|
11
11
|
* preprocessors (eg. [prepr](https://github.com/dy/prepr))
|
|
@@ -38,7 +38,7 @@ _Subscript_ supports [common syntax](https://en.wikipedia.org/wiki/Comparison_of
|
|
|
38
38
|
* `a < b`, `a <= b`, `a > b`, `a >= b`, `a == b`, `a != b`
|
|
39
39
|
* `~a`, `a & b`, `a ^ b`, `a | b`, `a << b`, `a >> b`
|
|
40
40
|
* `!a`, `a && b`, `a || b`
|
|
41
|
-
* `a = b`, `a += b`, `a -= b`, `a *= b`, `a /= b`, `a %= b`,
|
|
41
|
+
* `a = b`, `a += b`, `a -= b`, `a *= b`, `a /= b`, `a %= b`, `a <<= b`, `a >>= b`
|
|
42
42
|
* `(a, (b))`, `a; b;`
|
|
43
43
|
* `"abc"`, `'abc'`
|
|
44
44
|
* `0.1`, `1.2e+3`
|
|
@@ -84,7 +84,7 @@ tree // ['-', ['+', ['.', 'a', 'b'], 'c'], [,1]]
|
|
|
84
84
|
|
|
85
85
|
// compile tree to evaluable function
|
|
86
86
|
fn = compile(tree)
|
|
87
|
-
fn({ a: {b: 1}, c: 2 }) //
|
|
87
|
+
fn({ a: {b: 1}, c: 2 }) // 2
|
|
88
88
|
```
|
|
89
89
|
|
|
90
90
|
### Syntax Tree
|
|
@@ -115,10 +115,10 @@ null|empty; // placeholder
|
|
|
115
115
|
|
|
116
116
|
// eg.
|
|
117
117
|
['()', 'a'] // (a)
|
|
118
|
-
['()', 'a'
|
|
118
|
+
['()', 'a', null] // a()
|
|
119
119
|
['()', 'a', 'b'] // a(b)
|
|
120
|
-
['
|
|
121
|
-
['
|
|
120
|
+
['++', 'a'] // ++a
|
|
121
|
+
['++','a', null] // a++
|
|
122
122
|
```
|
|
123
123
|
|
|
124
124
|
### Stringify
|
package/feature/increment.js
CHANGED
|
@@ -2,13 +2,10 @@ import { token, expr } from "../src/parse.js"
|
|
|
2
2
|
import { operator, compile, prop } from "../src/compile.js"
|
|
3
3
|
import { PREC_POSTFIX } from "../src/const.js"
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
token('++', PREC_POSTFIX, a => a ? ['++-', a] : ['++', expr(PREC_POSTFIX - 1)])
|
|
5
|
+
token('++', PREC_POSTFIX, a => a ? ['++', a, null,] : ['++', expr(PREC_POSTFIX - 1)])
|
|
7
6
|
// ++a, ++((a)), ++a.b, ++a[b]
|
|
8
|
-
operator('++',
|
|
9
|
-
operator('++-', inc = (a) => prop(a, (obj, path) => obj[path]++))
|
|
7
|
+
operator('++', (a,b) => prop(a, b === null ? (obj, path) => obj[path]++ : (obj, path) => ++obj[path]))
|
|
10
8
|
|
|
11
|
-
token('--', PREC_POSTFIX, a => a ? ['
|
|
9
|
+
token('--', PREC_POSTFIX, a => a ? ['--', a, null,] : ['--', expr(PREC_POSTFIX - 1)])
|
|
12
10
|
// --a, --a.b, --a[b]
|
|
13
|
-
operator('--',
|
|
14
|
-
operator('--+', dec = (a) => (prop(a, (obj, path) => obj[path]--)))
|
|
11
|
+
operator('--', (a, b) => prop(a, b === null ? (obj, path) => obj[path]-- : (obj, path) => --obj[path]))
|
package/justin.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
let r,e
|
|
1
|
+
let r,t,e=e=>(r=0,t=e,e=a(),t[r]?l():e||""),l=(e="Bad syntax",l=t.slice(0,r).split("\n"),n=l.pop())=>{const i=t.slice(r-108,r).split("\n").pop(),a=t.slice(r,r+108).split("\n").shift();throw EvalError(`${e} at ${l.length}:${n.length} \`${r>=108?"…":""}${i}┃${a}\``,"font-weight: bold")},n=(e,l=r,n)=>{for(;n=e(t.charCodeAt(r));)r+=n;return t.slice(l,r)},i=(e=1,l=r)=>(r+=e,t.slice(l,r)),a=(t=0,i)=>{let a,p,c,d;for(;(a=o())&&(c=((d=s[a])&&d(p,t))??(!p&&n(e.id)));)p=c;return i&&(a==i?r++:l()),p},o=e=>{for(;(e=t.charCodeAt(r))<=32;)r++;return e};e.id=r=>r>=48&&r<=57||r>=65&&r<=90||r>=97&&r<=122||36==r||95==r||r>=192&&215!=r&&247!=r;let s=[],p=(n,i=32,a,o=n.charCodeAt(0),p=n.length,c=s[o],d=n.toUpperCase()!==n)=>s[o]=(o,s,u,f=r)=>(u?n==u:(p<2||t.substr(r,p)==n)&&(u=n))&&s<i&&!(d&&e.id(t.charCodeAt(r+p)))&&(r+=p,a(o)||(r=f,!c&&l()))||c?.(o,s,u),c=(r,t,e=!1)=>p(r,t,((l,n)=>l&&(n=a(t-(e?.5:0)))&&[r,l,n])),d=(r,t,e)=>p(r,t,(l=>e?l&&[r,l]:!l&&(l=a(t-.5))&&[r,l])),u=(r,t,e)=>{p(r,t,((e,l)=>(l=a(t),e?.[0]!==r&&(e=[r,e||null]),l?.[0]===r?e.push(...l.slice(1)):e.push(l||null),e)))},f=(r,t)=>p(r[0],t,(t=>!t&&[r,a(0,r.charCodeAt(1))])),h=(r,t)=>p(r[0],t,(t=>t&&[r,t,a(0,r.charCodeAt(1))||null]));const A=r=>Array.isArray(r)?r[0]?g[r[0]].call(...r):()=>r[1]:A.id(r);A.id=r=>t=>t?.[r];const g={},m=(r,t,e=g[r])=>g[r]=(...r)=>t(...r)||e?.(...r),y=(r,t,e,n,i)=>"()"===r[0]&&2==r.length?y(r[1],t,e):"string"==typeof r?e=>t(e,r,e):"."===r[0]?(n=A(r[1]),i=r[2],r=>t(n(r),i,r)):"[]"===r[0]&&3===r.length?(n=A(r[1]),i=A(r[2]),r=>t(n(r),i(r),r)):e?(r=A(r),e=>t([r(e)],0,e)):()=>l("Bad left value"),v=(r,t)=>[,(r=+n((r=>46===r||r>=48&&r<=57||(69===r||101===r?2:0))))!=r?l():r];s[46]=r=>!r&&v();for(let r=48;r<=57;r++)s[r]=r=>r?l():v();const C={n:"\n",r:"\r",t:"\t",b:"\b",f:"\f",v:"\v"},b=e=>(n,a,o="")=>{for(n&&l("Unexpected string"),i();(a=t.charCodeAt(r))-e;)92===a?(i(),a=i(),o+=C[a]||a):o+=i();return i()||l("Bad string"),[,o]};s[34]=b(34),s[39]=b(39),h("()",170),m("()",((r,t,e)=>void 0!==t&&(e=t?","===t[0]?(t=t.slice(1).map((r=>r?A(r):err())),r=>t.map((t=>t(r)))):(t=A(t),r=>[t(r)]):()=>[],y(r,((r,t,l)=>r[t](...e(l))),!0)))),h("[]",170),m("[]",((r,t)=>t?(r=A(r),t=A(t),e=>r(e)[t(e)]):err())),c(".",170),m(".",((r,t)=>(r=A(r),t=t[0]?t:t[1],e=>r(e)[t]))),f("()",170),m("()",((r,t)=>void 0===t&&(!r&&l("Empty ()"),A(r))));const $=(...r)=>(r=r.map(A),t=>r.map((r=>r(t))).pop());function N(r){if(!r)return"";if(Array.isArray(r)){const[t,...e]=r;return t?"[]"==t||"{}"==t||"()"==t?(e.length>1?N(e.shift()):"")+t[0]+N(e[0])+t[1]:1===e.length?t+N(e[0]):2===e.length?N(e[0])+("."===t?t:" "+t+" ")+N(e[1]):e.filter(Boolean).map((r=>N(r))).join(t+"\n"):JSON.stringify(e[0])}return r}u(",",10),m(",",$),u(";",5),m(";",$),c("=",20,!0),m("=",((r,t)=>(t=A(t),y(r,((r,e,l)=>r[e]=t(l)))))),c("*",120),m("*",((r,t)=>t&&(r=A(r),t=A(t),e=>r(e)*t(e)))),c("/",120),m("/",((r,t)=>t&&(r=A(r),t=A(t),e=>r(e)/t(e)))),c("%",120),m("%",((r,t)=>t&&(r=A(r),t=A(t),e=>r(e)%t(e)))),c("*=",20,!0),m("*=",((r,t)=>(t=A(t),y(r,((r,e,l)=>r[e]*=t(l)))))),c("/=",20,!0),m("/=",((r,t)=>(t=A(t),y(r,((r,e,l)=>r[e]/=t(l)))))),c("%=",20,!0),m("%=",((r,t)=>(t=A(t),y(r,((r,e,l)=>r[e]%=t(l)))))),c("+",110),m("+",((r,t)=>t&&(r=A(r),t=A(t),e=>r(e)+t(e)))),c("-",110),m("-",((r,t)=>t&&(r=A(r),t=A(t),e=>r(e)-t(e)))),d("+",140),m("+",((r,t)=>!t&&(r=A(r),t=>+r(t)))),d("-",140),m("-",((r,t)=>!t&&(r=A(r),t=>-r(t)))),c("+=",20,!0),m("+=",((r,t)=>(t=A(t),y(r,((r,e,l)=>r[e]+=t(l)))))),c("-=",20,!0),m("-=",((r,t)=>(t=A(t),y(r,((r,e,l)=>r[e]-=t(l)))))),p("++",150,(r=>r?["++",r,null]:["++",a(149)])),m("++",((r,t)=>y(r,null===t?(r,t)=>r[t]++:(r,t)=>++r[t]))),p("--",150,(r=>r?["--",r,null]:["--",a(149)])),m("--",((r,t)=>y(r,null===t?(r,t)=>r[t]--:(r,t)=>--r[t]))),d("~",140),m("~",((r,t)=>!t&&(r=A(r),t=>~r(t)))),c("|",50),m("|",((r,t)=>t&&(r=A(r),t=A(t),e=>r(e)|t(e)))),c("&",70),m("&",((r,t)=>t&&(r=A(r),t=A(t),e=>r(e)&t(e)))),c("^",60),m("^",((r,t)=>t&&(r=A(r),t=A(t),e=>r(e)^t(e)))),d("!",140),m("!",((r,t)=>!t&&(r=A(r),t=>!r(t)))),c("||",30),m("||",((r,t)=>(r=A(r),t=A(t),e=>r(e)||t(e)))),c("&&",40),m("&&",((r,t)=>(r=A(r),t=A(t),e=>r(e)&&t(e)))),c("==",80),m("==",((r,t)=>t&&(r=A(r),t=A(t),e=>r(e)==t(e)))),c("!=",80),m("!=",((r,t)=>t&&(r=A(r),t=A(t),e=>r(e)!=t(e)))),c(">",90),m(">",((r,t)=>t&&(r=A(r),t=A(t),e=>r(e)>t(e)))),c("<",90),m("<",((r,t)=>t&&(r=A(r),t=A(t),e=>r(e)<t(e)))),c(">=",90),m(">=",((r,t)=>t&&(r=A(r),t=A(t),e=>r(e)>=t(e)))),c("<=",90),m("<=",((r,t)=>t&&(r=A(r),t=A(t),e=>r(e)<=t(e)))),c(">>",100),m(">>",((r,t)=>t&&(r=A(r),t=A(t),e=>r(e)>>t(e)))),c("<<",100),m("<<",((r,t)=>t&&(r=A(r),t=A(t),e=>r(e)<<t(e)))),c(">>=",20,!0),m(">>=",((r,t)=>(t=A(t),prop(r,((r,e,l)=>r[e]>>=t(l)))))),c("<<=",20,!0),m("<<=",((r,t)=>(t=A(t),prop(r,((r,e,l)=>r[e]<<=t(l))))));var j=r=>A(e(r));p("/*",200,((e,l)=>(n((e=>42!==e&&47!==t.charCodeAt(r+1))),i(2),e||a(l)||[]))),p("//",200,((r,t)=>(n((r=>r>=32)),r||a(t)||[]))),c("**",130,!0),m("**",((r,t)=>t&&(r=A(r),t=A(t),e=>r(e)**t(e)))),p("?",20,((r,t,e)=>r&&(t=a(19))&&n((r=>58===r))&&["?",r,t,a(19)])),m("?",((r,t,e)=>(r=A(r),t=A(t),e=A(e),l=>r(l)?t(l):e(l)))),p("true",200,(r=>r?err():[,!0])),p("false",200,(r=>r?err():[,!1])),f("[]",200),m("[]",((r,t)=>void 0===t&&(r=(r=r?","===r[0]?r.slice(1):[r]:[]).map((r=>"..."===r[0]?(r=A(r[1]),t=>r(t)):(r=A(r),t=>[r(t)]))),t=>r.flatMap((r=>r(t)))))),f("{}",200),m("{}",((r,t)=>void 0===t&&(r=(r=r?","!==r[0]?[r]:r.slice(1):[]).map((r=>A("string"==typeof r?[":",r,r]:r))),t=>Object.fromEntries(r.flatMap((r=>r(t))))))),c(":",19,!0),m(":",((r,t)=>(t=A(t),Array.isArray(r)?(r=A(r),e=>[[r(e),t(e)]]):e=>[[r,t(e)]]))),c("=>",20,!0),m("=>",((r,t)=>(r=(r="()"===r[0]?r[1]:r)?r=","===r[0]?r.slice(1):[r]:[],t=A("{}"===t[0]?t[1]:t),(e=null)=>(e=Object.create(e),(...l)=>(r.map(((r,t)=>e[r]=l[t])),t(e)))))),c(""),p("?.",170,(r=>r&&["?.",r])),m("?.",(r=>(r=A(r),t=>r(t)||(()=>{})))),p("?.",170,((r,t)=>r&&!(t=a(170))?.map&&["?.",r,t])),m("?.",((r,t)=>t&&(r=A(r),e=>r(e)?.[t]))),m("()",((r,t,e,l,n,i)=>void 0!==t&&"?."===r[0]&&(r[2]||Array.isArray(r[1]))&&(l=t?","===t[0]?(t=t.slice(1).map(A),r=>t.map((t=>t(r)))):(t=A(t),r=>[t(r)]):()=>[],!r[2]&&(r=r[1]),n="[]"===r[0]&&3===r.length?A(r[2]):()=>r[2],e=A(r[1]),r=>e(r)?.[n(r)]?.(...l(r))))),d("...",140),m("...",(r=>(r=A(r),t=>Object.entries(r(t))))),c("in",90),m("in",((r,t)=>t&&(r=A(r),t=A(t),e=>r(e)in t(e)))),c("===",80),c("!==",9),m("===",((r,t)=>(r=A(r),t=A(t),e=>r(e)===t(e)))),m("!==",((r,t)=>(r=A(r),t=A(t),e=>r(e)!==t(e)))),c("??",30),m("??",((r,t)=>t&&(r=A(r),t=A(t),e=>r(e)??t(e)))),c("??=",20,!0),m("??=",((r,t)=>(t=A(t),y(r,((r,e,l)=>r[e]??=t(l)))))),c("||=",20,!0),m("||=",((r,t)=>(t=A(t),y(r,((r,e,l)=>r[e]||=t(l)))))),c("&&=",20,!0),m("&&=",((r,t)=>(t=A(t),y(r,((r,e,l)=>r[e]&&=t(l)))))),c(">>>",80),m(">>>",((r,t)=>(r=A(r),t=A(t),e=>r(e)>>>t(e)))),c(">>>=",20,!0),m(">>>=",((r,t)=>(t=A(t),y(r,((r,e,l)=>r[e]>>>=t(l)))))),p("undefined",20,(r=>r?l():[,void 0])),p("NaN",20,(r=>r?l():[,NaN])),p("null",20,(r=>r?l():[,null]));export{h as access,c as binary,A as compile,j as default,f as group,u as nary,m as operator,e as parse,N as stringify,p as token,d as unary};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "subscript",
|
|
3
|
-
"version": "9.0
|
|
3
|
+
"version": "9.1.0",
|
|
4
4
|
"description": "Fast and tiny expression evaluator with minimal syntax.",
|
|
5
5
|
"main": "subscript.js",
|
|
6
6
|
"module": "subscript.js",
|
|
@@ -83,6 +83,6 @@
|
|
|
83
83
|
"devDependencies": {
|
|
84
84
|
"rollup": "^2.60.2",
|
|
85
85
|
"terser": "^5.10.0",
|
|
86
|
-
"tst": "^
|
|
86
|
+
"tst": "^8.0.2"
|
|
87
87
|
}
|
|
88
88
|
}
|
package/src/compile.js
CHANGED
|
@@ -1,11 +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) ? compile.id(node) : !node[0] ? () => node[1] : operators[node[0]](...node
|
|
4
|
+
export const compile = (node) => !Array.isArray(node) ? compile.id(node) : !node[0] ? () => node[1] : operators[node[0]].call(...node),
|
|
5
5
|
// compile id getter
|
|
6
6
|
id = compile.id = name => ctx => ctx?.[name],
|
|
7
7
|
|
|
8
|
-
|
|
9
8
|
// registered operators
|
|
10
9
|
operators = {},
|
|
11
10
|
|
package/src/parse.js
CHANGED
|
@@ -6,12 +6,13 @@ export let idx, cur,
|
|
|
6
6
|
// no handling tagged literals since easily done on user side with cache, if needed
|
|
7
7
|
parse = s => (idx = 0, cur = s, s = expr(), cur[idx] ? err() : s || ''),
|
|
8
8
|
|
|
9
|
+
// display error
|
|
9
10
|
err = (msg = 'Bad syntax',
|
|
10
11
|
lines = cur.slice(0, idx).split('\n'),
|
|
11
12
|
last = lines.pop()
|
|
12
13
|
) => {
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
const before = cur.slice(idx - 108, idx).split('\n').pop()
|
|
15
|
+
const after = cur.slice(idx, idx + 108).split('\n').shift()
|
|
15
16
|
throw EvalError(`${msg} at ${lines.length}:${last.length} \`${idx >= 108 ? '…' : ''}${before}┃${after}\``, 'font-weight: bold')
|
|
16
17
|
},
|
|
17
18
|
|
package/subscript.js
CHANGED
|
@@ -11,9 +11,9 @@ import './feature/mult.js'
|
|
|
11
11
|
import './feature/add.js'
|
|
12
12
|
import './feature/increment.js'
|
|
13
13
|
import './feature/bitwise.js'
|
|
14
|
+
import './feature/logic.js'
|
|
14
15
|
import './feature/compare.js'
|
|
15
16
|
import './feature/shift.js'
|
|
16
|
-
import './feature/logic.js'
|
|
17
17
|
import compile from './src/compile.js'
|
|
18
18
|
import parse from './src/parse.js'
|
|
19
19
|
|
package/subscript.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
let t,r,e=e=>(t=0,r=e,e=i(),r[t]?n():e||""),n=(e="Bad syntax",n=r.slice(0,t).split("\n"),l=n.pop())=>{
|
|
1
|
+
let t,r,e=e=>(t=0,r=e,e=i(),r[t]?n():e||""),n=(e="Bad syntax",n=r.slice(0,t).split("\n"),l=n.pop())=>{const o=r.slice(t-108,t).split("\n").pop(),i=r.slice(t,t+108).split("\n").shift();throw EvalError(`${e} at ${n.length}:${l.length} \`${t>=108?"…":""}${o}┃${i}\``,"font-weight: bold")},l=(e,n=t,l)=>{for(;l=e(r.charCodeAt(t));)t+=l;return r.slice(n,t)},o=(e=1,n=t)=>(t+=e,r.slice(n,t)),i=(r=0,o)=>{let i,p,c,h;for(;(i=s())&&(c=((h=a[i])&&h(p,r))??(!p&&l(e.id)));)p=c;return o&&(i==o?t++:n()),p},s=e=>{for(;(e=r.charCodeAt(t))<=32;)t++;return e};e.id=t=>t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122||36==t||95==t||t>=192&&215!=t&&247!=t;let a=[],p=(l,o=32,i,s=l.charCodeAt(0),p=l.length,c=a[s],h=l.toUpperCase()!==l)=>a[s]=(s,a,d,u=t)=>(d?l==d:(p<2||r.substr(t,p)==l)&&(d=l))&&a<o&&!(h&&e.id(r.charCodeAt(t+p)))&&(t+=p,i(s)||(t=u,!c&&n()))||c?.(s,a,d),c=(t,r,e=!1)=>p(t,r,((n,l)=>n&&(l=i(r-(e?.5:0)))&&[t,n,l])),h=(t,r,e)=>p(t,r,(n=>e?n&&[t,n]:!n&&(n=i(r-.5))&&[t,n])),d=(t,r,e)=>{p(t,r,((e,n)=>(n=i(r),e?.[0]!==t&&(e=[t,e||null]),n?.[0]===t?e.push(...n.slice(1)):e.push(n||null),e)))},u=(t,r)=>p(t[0],r,(r=>!r&&[t,i(0,t.charCodeAt(1))])),f=(t,r)=>p(t[0],r,(r=>r&&[t,r,i(0,t.charCodeAt(1))||null]));const g=(t,r)=>[,(t=+l((t=>46===t||t>=48&&t<=57||(69===t||101===t?2:0))))!=t?n():t];a[46]=t=>!t&&g();for(let t=48;t<=57;t++)a[t]=t=>t?n():g();const A={n:"\n",r:"\r",t:"\t",b:"\b",f:"\f",v:"\v"},y=e=>(l,i,s="")=>{for(l&&n("Unexpected string"),o();(i=r.charCodeAt(t))-e;)92===i?(o(),i=o(),s+=A[i]||i):s+=o();return o()||n("Bad string"),[,s]};a[34]=y(34),a[39]=y(39);const C=t=>Array.isArray(t)?t[0]?v[t[0]].call(...t):()=>t[1]:C.id(t);C.id=t=>r=>r?.[t];const v={},m=(t,r,e=v[t])=>v[t]=(...t)=>r(...t)||e?.(...t),$=(t,r,e,l,o)=>"()"===t[0]&&2==t.length?$(t[1],r,e):"string"==typeof t?e=>r(e,t,e):"."===t[0]?(l=C(t[1]),o=t[2],t=>r(l(t),o,t)):"[]"===t[0]&&3===t.length?(l=C(t[1]),o=C(t[2]),t=>r(l(t),o(t),t)):e?(t=C(t),e=>r([t(e)],0,e)):()=>n("Bad left value");f("()",170),m("()",((t,r,e)=>void 0!==r&&(e=r?","===r[0]?(r=r.slice(1).map((t=>t?C(t):err())),t=>r.map((r=>r(t)))):(r=C(r),t=>[r(t)]):()=>[],$(t,((t,r,n)=>t[r](...e(n))),!0)))),f("[]",170),m("[]",((t,r)=>r?(t=C(t),r=C(r),e=>t(e)[r(e)]):err())),c(".",170),m(".",((t,r)=>(t=C(t),r=r[0]?r:r[1],e=>t(e)[r]))),u("()",170),m("()",((t,r)=>void 0===r&&(!t&&n("Empty ()"),C(t))));const b=(...t)=>(t=t.map(C),r=>t.map((t=>t(r))).pop());function B(t){if(!t)return"";if(Array.isArray(t)){const[r,...e]=t;return r?"[]"==r||"{}"==r||"()"==r?(e.length>1?B(e.shift()):"")+r[0]+B(e[0])+r[1]:1===e.length?r+B(e[0]):2===e.length?B(e[0])+("."===r?r:" "+r+" ")+B(e[1]):e.filter(Boolean).map((t=>B(t))).join(r+"\n"):JSON.stringify(e[0])}return t}d(",",10),m(",",b),d(";",5),m(";",b),c("=",20,!0),m("=",((t,r)=>(r=C(r),$(t,((t,e,n)=>t[e]=r(n)))))),c("*",120),m("*",((t,r)=>r&&(t=C(t),r=C(r),e=>t(e)*r(e)))),c("/",120),m("/",((t,r)=>r&&(t=C(t),r=C(r),e=>t(e)/r(e)))),c("%",120),m("%",((t,r)=>r&&(t=C(t),r=C(r),e=>t(e)%r(e)))),c("*=",20,!0),m("*=",((t,r)=>(r=C(r),$(t,((t,e,n)=>t[e]*=r(n)))))),c("/=",20,!0),m("/=",((t,r)=>(r=C(r),$(t,((t,e,n)=>t[e]/=r(n)))))),c("%=",20,!0),m("%=",((t,r)=>(r=C(r),$(t,((t,e,n)=>t[e]%=r(n)))))),c("+",110),m("+",((t,r)=>r&&(t=C(t),r=C(r),e=>t(e)+r(e)))),c("-",110),m("-",((t,r)=>r&&(t=C(t),r=C(r),e=>t(e)-r(e)))),h("+",140),m("+",((t,r)=>!r&&(t=C(t),r=>+t(r)))),h("-",140),m("-",((t,r)=>!r&&(t=C(t),r=>-t(r)))),c("+=",20,!0),m("+=",((t,r)=>(r=C(r),$(t,((t,e,n)=>t[e]+=r(n)))))),c("-=",20,!0),m("-=",((t,r)=>(r=C(r),$(t,((t,e,n)=>t[e]-=r(n)))))),p("++",150,(t=>t?["++",t,null]:["++",i(149)])),m("++",((t,r)=>$(t,null===r?(t,r)=>t[r]++:(t,r)=>++t[r]))),p("--",150,(t=>t?["--",t,null]:["--",i(149)])),m("--",((t,r)=>$(t,null===r?(t,r)=>t[r]--:(t,r)=>--t[r]))),h("~",140),m("~",((t,r)=>!r&&(t=C(t),r=>~t(r)))),c("|",50),m("|",((t,r)=>r&&(t=C(t),r=C(r),e=>t(e)|r(e)))),c("&",70),m("&",((t,r)=>r&&(t=C(t),r=C(r),e=>t(e)&r(e)))),c("^",60),m("^",((t,r)=>r&&(t=C(t),r=C(r),e=>t(e)^r(e)))),h("!",140),m("!",((t,r)=>!r&&(t=C(t),r=>!t(r)))),c("||",30),m("||",((t,r)=>(t=C(t),r=C(r),e=>t(e)||r(e)))),c("&&",40),m("&&",((t,r)=>(t=C(t),r=C(r),e=>t(e)&&r(e)))),c("==",80),m("==",((t,r)=>r&&(t=C(t),r=C(r),e=>t(e)==r(e)))),c("!=",80),m("!=",((t,r)=>r&&(t=C(t),r=C(r),e=>t(e)!=r(e)))),c(">",90),m(">",((t,r)=>r&&(t=C(t),r=C(r),e=>t(e)>r(e)))),c("<",90),m("<",((t,r)=>r&&(t=C(t),r=C(r),e=>t(e)<r(e)))),c(">=",90),m(">=",((t,r)=>r&&(t=C(t),r=C(r),e=>t(e)>=r(e)))),c("<=",90),m("<=",((t,r)=>r&&(t=C(t),r=C(r),e=>t(e)<=r(e)))),c(">>",100),m(">>",((t,r)=>r&&(t=C(t),r=C(r),e=>t(e)>>r(e)))),c("<<",100),m("<<",((t,r)=>r&&(t=C(t),r=C(r),e=>t(e)<<r(e)))),c(">>=",20,!0),m(">>=",((t,r)=>(r=C(r),prop(t,((t,e,n)=>t[e]>>=r(n)))))),c("<<=",20,!0),m("<<=",((t,r)=>(r=C(r),prop(t,((t,e,n)=>t[e]<<=r(n))))));var x=t=>C(e(t));export{f as access,c as binary,C as compile,x as default,u as group,d as nary,m as operator,e as parse,B as stringify,p as token,h as unary};
|