@thi.ng/pointfree 3.1.54 → 3.1.55
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/CHANGELOG.md +1 -1
- package/README.md +1 -1
- package/api.js +0 -1
- package/array.js +150 -358
- package/binary.js +16 -43
- package/cond.js +38 -74
- package/context.js +7 -11
- package/dataflow.js +55 -169
- package/env.js +24 -63
- package/index.js +9 -2
- package/io.js +8 -11
- package/logic.js +30 -85
- package/loop.js +32 -81
- package/math.js +50 -145
- package/ops.js +42 -71
- package/package.json +11 -8
- package/run.js +18 -37
- package/safe.js +14 -11
- package/stack.js +163 -339
- package/string.js +22 -35
- package/word.js +40 -107
package/stack.js
CHANGED
|
@@ -2,363 +2,187 @@ import { $, $n } from "./safe.js";
|
|
|
2
2
|
const __xsp = (id) => (ctx) => (ctx[0].push(ctx[id].length), ctx);
|
|
3
3
|
const __dup = (id) => __copy(id, id);
|
|
4
4
|
const __dup2 = (id) => (ctx) => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
const stack = ctx[id];
|
|
6
|
+
let n = stack.length - 2;
|
|
7
|
+
$n(n, 0);
|
|
8
|
+
stack.push(stack[n], stack[n + 1]);
|
|
9
|
+
return ctx;
|
|
10
10
|
};
|
|
11
11
|
const __dup3 = (id) => (ctx) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
const stack = ctx[id];
|
|
13
|
+
let n = stack.length - 3;
|
|
14
|
+
$n(n, 0);
|
|
15
|
+
stack.push(stack[n], stack[n + 1], stack[n + 2]);
|
|
16
|
+
return ctx;
|
|
17
17
|
};
|
|
18
|
-
const __drop = (id, n = 1) => (ctx) => ($(ctx[id], 1),
|
|
18
|
+
const __drop = (id, n = 1) => (ctx) => ($(ctx[id], 1), ctx[id].length -= n, ctx);
|
|
19
19
|
const __swap = (i) => (ctx) => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
const stack = ctx[i];
|
|
21
|
+
const n = stack.length - 2;
|
|
22
|
+
$n(n, 0);
|
|
23
|
+
const a = stack[n];
|
|
24
|
+
stack[n] = stack[n + 1];
|
|
25
|
+
stack[n + 1] = a;
|
|
26
|
+
return ctx;
|
|
27
27
|
};
|
|
28
28
|
const __swap2 = (i) => (ctx) => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
29
|
+
const stack = ctx[i];
|
|
30
|
+
let n = stack.length - 1;
|
|
31
|
+
$n(n, 3);
|
|
32
|
+
let a = stack[n];
|
|
33
|
+
stack[n] = stack[n - 2];
|
|
34
|
+
stack[n - 2] = a;
|
|
35
|
+
n--;
|
|
36
|
+
a = stack[n];
|
|
37
|
+
stack[n] = stack[n - 2];
|
|
38
|
+
stack[n - 2] = a;
|
|
39
|
+
return ctx;
|
|
40
40
|
};
|
|
41
41
|
const __over = (id) => (ctx) => {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
const stack = ctx[id];
|
|
43
|
+
const n = stack.length - 2;
|
|
44
|
+
$n(n, 0);
|
|
45
|
+
stack.push(stack[n]);
|
|
46
|
+
return ctx;
|
|
47
47
|
};
|
|
48
48
|
const __move = (src, dest) => (ctx) => ($(ctx[src], 1), ctx[dest].push(ctx[src].pop()), ctx);
|
|
49
49
|
const __move2 = (a, b) => (ctx) => {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
const src = ctx[a];
|
|
51
|
+
$(src, 2);
|
|
52
|
+
const v = src.pop();
|
|
53
|
+
ctx[b].push(src.pop(), v);
|
|
54
|
+
return ctx;
|
|
55
55
|
};
|
|
56
56
|
const __copy = (src, dest) => (ctx) => ($(ctx[src], 1), ctx[dest].push(tos(ctx[src])), ctx);
|
|
57
57
|
const __copy2 = (a, b) => (ctx) => {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
58
|
+
const src = ctx[a];
|
|
59
|
+
const n = src.length - 2;
|
|
60
|
+
$n(n, 0);
|
|
61
|
+
ctx[b].push(src[n], src[n + 1]);
|
|
62
|
+
return ctx;
|
|
63
63
|
};
|
|
64
|
-
const __incdec = (id, n) => (ctx) => ($(ctx[id], 1),
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
export const nop = (ctx) => ctx;
|
|
76
|
-
/**
|
|
77
|
-
* Pushes current d-stack size on d-stack.
|
|
78
|
-
*
|
|
79
|
-
* ( -- n )
|
|
80
|
-
* @param ctx -
|
|
81
|
-
*/
|
|
82
|
-
export const dsp = __xsp(0);
|
|
83
|
-
/**
|
|
84
|
-
* Uses TOS as index to look up a deeper d-stack value, then places it
|
|
85
|
-
* as new TOS. Throws error if stack depth is < `x`.
|
|
86
|
-
*
|
|
87
|
-
* ( ... x -- ... stack[x] )
|
|
88
|
-
*
|
|
89
|
-
* @param ctx -
|
|
90
|
-
*/
|
|
91
|
-
export const pick = (ctx) => {
|
|
92
|
-
const stack = ctx[0];
|
|
93
|
-
let n = stack.length - 1;
|
|
94
|
-
$n(n, 0);
|
|
95
|
-
$n((n -= stack.pop() + 1), 0);
|
|
96
|
-
stack.push(stack[n]);
|
|
97
|
-
return ctx;
|
|
64
|
+
const __incdec = (id, n) => (ctx) => ($(ctx[id], 1), ctx[id][ctx[id].length - 1] += n, ctx);
|
|
65
|
+
const tos = (stack) => stack[stack.length - 1];
|
|
66
|
+
const nop = (ctx) => ctx;
|
|
67
|
+
const dsp = __xsp(0);
|
|
68
|
+
const pick = (ctx) => {
|
|
69
|
+
const stack = ctx[0];
|
|
70
|
+
let n = stack.length - 1;
|
|
71
|
+
$n(n, 0);
|
|
72
|
+
$n(n -= stack.pop() + 1, 0);
|
|
73
|
+
stack.push(stack[n]);
|
|
74
|
+
return ctx;
|
|
98
75
|
};
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
*
|
|
112
|
-
* @param ctx -
|
|
113
|
-
*/
|
|
114
|
-
export const drop2 = __drop(0, 2);
|
|
115
|
-
/**
|
|
116
|
-
* If TOS is truthy then drop it:
|
|
117
|
-
*
|
|
118
|
-
* ( x -- )
|
|
119
|
-
*
|
|
120
|
-
* Else, no effect:
|
|
121
|
-
*
|
|
122
|
-
* ( x -- x )
|
|
123
|
-
*/
|
|
124
|
-
export const dropif = (ctx) => ($(ctx[0], 1), tos(ctx[0]) && ctx[0].length--, ctx);
|
|
125
|
-
/**
|
|
126
|
-
* Higher order word. Pushes given args verbatim on d-stack.
|
|
127
|
-
*
|
|
128
|
-
* ( -- ...args )
|
|
129
|
-
*
|
|
130
|
-
* @param args -
|
|
131
|
-
*/
|
|
132
|
-
export const defPush = (...args) => (ctx) => (ctx[0].push(...args), ctx);
|
|
133
|
-
/**
|
|
134
|
-
* Duplicates TOS on d-stack.
|
|
135
|
-
*
|
|
136
|
-
* ( x -- x x )
|
|
137
|
-
*
|
|
138
|
-
* @param ctx -
|
|
139
|
-
*/
|
|
140
|
-
export const dup = __dup(0);
|
|
141
|
-
/**
|
|
142
|
-
* Duplicates top 2 vals on d-stack.
|
|
143
|
-
*
|
|
144
|
-
* ( x y -- x y x y )
|
|
145
|
-
*
|
|
146
|
-
* @param ctx -
|
|
147
|
-
*/
|
|
148
|
-
export const dup2 = __dup2(0);
|
|
149
|
-
/**
|
|
150
|
-
* Duplicates top 3 vals on d-stack.
|
|
151
|
-
*
|
|
152
|
-
* ( x y -- x y x y )
|
|
153
|
-
*
|
|
154
|
-
* @param ctx -
|
|
155
|
-
*/
|
|
156
|
-
export const dup3 = __dup3(0);
|
|
157
|
-
/**
|
|
158
|
-
* If TOS is truthy then push copy of it on d-stack:
|
|
159
|
-
*
|
|
160
|
-
* ( x -- x x )
|
|
161
|
-
*
|
|
162
|
-
* Else, no effect:
|
|
163
|
-
*
|
|
164
|
-
* ( x -- x )
|
|
165
|
-
*
|
|
166
|
-
* @param ctx -
|
|
167
|
-
*/
|
|
168
|
-
export const dupif = (ctx) => {
|
|
169
|
-
$(ctx[0], 1);
|
|
170
|
-
const x = tos(ctx[0]);
|
|
171
|
-
x && ctx[0].push(x);
|
|
172
|
-
return ctx;
|
|
76
|
+
const drop = __drop(0);
|
|
77
|
+
const drop2 = __drop(0, 2);
|
|
78
|
+
const dropif = (ctx) => ($(ctx[0], 1), tos(ctx[0]) && ctx[0].length--, ctx);
|
|
79
|
+
const defPush = (...args) => (ctx) => (ctx[0].push(...args), ctx);
|
|
80
|
+
const dup = __dup(0);
|
|
81
|
+
const dup2 = __dup2(0);
|
|
82
|
+
const dup3 = __dup3(0);
|
|
83
|
+
const dupif = (ctx) => {
|
|
84
|
+
$(ctx[0], 1);
|
|
85
|
+
const x = tos(ctx[0]);
|
|
86
|
+
x && ctx[0].push(x);
|
|
87
|
+
return ctx;
|
|
173
88
|
};
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Swaps the two topmost d-stack pairs.
|
|
184
|
-
*
|
|
185
|
-
* ( a b c d -- c d a b )
|
|
186
|
-
*
|
|
187
|
-
* @param ctx -
|
|
188
|
-
*/
|
|
189
|
-
export const swap2 = __swap2(0);
|
|
190
|
-
/**
|
|
191
|
-
* Removes second topmost item from d-stack.
|
|
192
|
-
*
|
|
193
|
-
* ( x y -- y )
|
|
194
|
-
*
|
|
195
|
-
* @param ctx -
|
|
196
|
-
*/
|
|
197
|
-
export const nip = (ctx) => {
|
|
198
|
-
const stack = ctx[0];
|
|
199
|
-
const n = stack.length - 2;
|
|
200
|
-
$n(n, 0);
|
|
201
|
-
stack[n] = stack.pop();
|
|
202
|
-
return ctx;
|
|
89
|
+
const swap = __swap(0);
|
|
90
|
+
const swap2 = __swap2(0);
|
|
91
|
+
const nip = (ctx) => {
|
|
92
|
+
const stack = ctx[0];
|
|
93
|
+
const n = stack.length - 2;
|
|
94
|
+
$n(n, 0);
|
|
95
|
+
stack[n] = stack.pop();
|
|
96
|
+
return ctx;
|
|
203
97
|
};
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
*/
|
|
211
|
-
export const tuck = (ctx) => {
|
|
212
|
-
$(ctx[0], 2);
|
|
213
|
-
const stack = ctx[0];
|
|
214
|
-
const a = stack.pop();
|
|
215
|
-
stack.push(a, stack.pop(), a);
|
|
216
|
-
return ctx;
|
|
98
|
+
const tuck = (ctx) => {
|
|
99
|
+
$(ctx[0], 2);
|
|
100
|
+
const stack = ctx[0];
|
|
101
|
+
const a = stack.pop();
|
|
102
|
+
stack.push(a, stack.pop(), a);
|
|
103
|
+
return ctx;
|
|
217
104
|
};
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
const n = stack.length - 1;
|
|
228
|
-
$n(n, 2);
|
|
229
|
-
const c = stack[n - 2];
|
|
230
|
-
stack[n - 2] = stack[n - 1];
|
|
231
|
-
stack[n - 1] = stack[n];
|
|
232
|
-
stack[n] = c;
|
|
233
|
-
return ctx;
|
|
105
|
+
const rot = (ctx) => {
|
|
106
|
+
const stack = ctx[0];
|
|
107
|
+
const n = stack.length - 1;
|
|
108
|
+
$n(n, 2);
|
|
109
|
+
const c = stack[n - 2];
|
|
110
|
+
stack[n - 2] = stack[n - 1];
|
|
111
|
+
stack[n - 1] = stack[n];
|
|
112
|
+
stack[n] = c;
|
|
113
|
+
return ctx;
|
|
234
114
|
};
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
115
|
+
const invrot = (ctx) => {
|
|
116
|
+
const stack = ctx[0];
|
|
117
|
+
const n = stack.length - 1;
|
|
118
|
+
$n(n, 2);
|
|
119
|
+
const c = stack[n];
|
|
120
|
+
stack[n] = stack[n - 1];
|
|
121
|
+
stack[n - 1] = stack[n - 2];
|
|
122
|
+
stack[n - 2] = c;
|
|
123
|
+
return ctx;
|
|
124
|
+
};
|
|
125
|
+
const over = __over(0);
|
|
126
|
+
const inc = __incdec(0, 1);
|
|
127
|
+
const dec = __incdec(0, -1);
|
|
128
|
+
const rsp = __xsp(1);
|
|
129
|
+
const rdup = __dup(1);
|
|
130
|
+
const rdup2 = __dup2(1);
|
|
131
|
+
const rdup3 = __dup3(1);
|
|
132
|
+
const rdrop = __drop(1);
|
|
133
|
+
const rdrop2 = __drop(1, 2);
|
|
134
|
+
const movdr = __move(0, 1);
|
|
135
|
+
const movrd = __move(1, 0);
|
|
136
|
+
const cpdr = __copy(0, 1);
|
|
137
|
+
const cprd = __copy(1, 0);
|
|
138
|
+
const movdr2 = __move2(0, 1);
|
|
139
|
+
const movrd2 = __move2(1, 0);
|
|
140
|
+
const cpdr2 = __copy2(0, 1);
|
|
141
|
+
const cprd2 = __copy2(1, 0);
|
|
142
|
+
const rswap = __swap(1);
|
|
143
|
+
const rswap2 = __swap2(1);
|
|
144
|
+
const rover = __over(1);
|
|
145
|
+
const rinc = __incdec(1, 1);
|
|
146
|
+
const rdec = __incdec(1, -1);
|
|
147
|
+
export {
|
|
148
|
+
cpdr,
|
|
149
|
+
cpdr2,
|
|
150
|
+
cprd,
|
|
151
|
+
cprd2,
|
|
152
|
+
dec,
|
|
153
|
+
defPush,
|
|
154
|
+
drop,
|
|
155
|
+
drop2,
|
|
156
|
+
dropif,
|
|
157
|
+
dsp,
|
|
158
|
+
dup,
|
|
159
|
+
dup2,
|
|
160
|
+
dup3,
|
|
161
|
+
dupif,
|
|
162
|
+
inc,
|
|
163
|
+
invrot,
|
|
164
|
+
movdr,
|
|
165
|
+
movdr2,
|
|
166
|
+
movrd,
|
|
167
|
+
movrd2,
|
|
168
|
+
nip,
|
|
169
|
+
nop,
|
|
170
|
+
over,
|
|
171
|
+
pick,
|
|
172
|
+
rdec,
|
|
173
|
+
rdrop,
|
|
174
|
+
rdrop2,
|
|
175
|
+
rdup,
|
|
176
|
+
rdup2,
|
|
177
|
+
rdup3,
|
|
178
|
+
rinc,
|
|
179
|
+
rot,
|
|
180
|
+
rover,
|
|
181
|
+
rsp,
|
|
182
|
+
rswap,
|
|
183
|
+
rswap2,
|
|
184
|
+
swap,
|
|
185
|
+
swap2,
|
|
186
|
+
tos,
|
|
187
|
+
tuck
|
|
251
188
|
};
|
|
252
|
-
/**
|
|
253
|
-
* Pushes copy of TOS-1 as new TOS on d-stack.
|
|
254
|
-
*
|
|
255
|
-
* ( x y -- x y x )
|
|
256
|
-
*
|
|
257
|
-
* @param ctx -
|
|
258
|
-
*/
|
|
259
|
-
export const over = __over(0);
|
|
260
|
-
/**
|
|
261
|
-
* ( x -- x+1 )
|
|
262
|
-
*
|
|
263
|
-
* @param ctx -
|
|
264
|
-
*/
|
|
265
|
-
export const inc = __incdec(0, 1);
|
|
266
|
-
/**
|
|
267
|
-
* ( x -- x-1 )
|
|
268
|
-
*
|
|
269
|
-
* @param ctx -
|
|
270
|
-
*/
|
|
271
|
-
export const dec = __incdec(0, -1);
|
|
272
|
-
//////////////////// R-Stack ops ////////////////////
|
|
273
|
-
/**
|
|
274
|
-
* Pushes current r-stack size on d-stack.
|
|
275
|
-
*
|
|
276
|
-
* ( -- n )
|
|
277
|
-
*
|
|
278
|
-
* @param ctx -
|
|
279
|
-
*/
|
|
280
|
-
export const rsp = __xsp(1);
|
|
281
|
-
/**
|
|
282
|
-
* Duplicates TOS on r-stack.
|
|
283
|
-
*
|
|
284
|
-
* ( x -- x x )
|
|
285
|
-
*
|
|
286
|
-
* @param ctx -
|
|
287
|
-
*/
|
|
288
|
-
export const rdup = __dup(1);
|
|
289
|
-
/**
|
|
290
|
-
* Duplicates top 2 vals on r-stack.
|
|
291
|
-
*
|
|
292
|
-
* ( x y -- x y x y )
|
|
293
|
-
*
|
|
294
|
-
* @param ctx -
|
|
295
|
-
*/
|
|
296
|
-
export const rdup2 = __dup2(1);
|
|
297
|
-
/**
|
|
298
|
-
* Duplicates top 3 vals on r-stack.
|
|
299
|
-
*
|
|
300
|
-
* ( x y -- x y x y )
|
|
301
|
-
*
|
|
302
|
-
* @param ctx -
|
|
303
|
-
*/
|
|
304
|
-
export const rdup3 = __dup3(1);
|
|
305
|
-
/**
|
|
306
|
-
* Removes TOS from r-stack.
|
|
307
|
-
*
|
|
308
|
-
* ( x -- )
|
|
309
|
-
*
|
|
310
|
-
* @param ctx -
|
|
311
|
-
*/
|
|
312
|
-
export const rdrop = __drop(1);
|
|
313
|
-
/**
|
|
314
|
-
* Removes top 2 vals from r-stack.
|
|
315
|
-
*
|
|
316
|
-
* ( x y -- )
|
|
317
|
-
*
|
|
318
|
-
* @param ctx -
|
|
319
|
-
*/
|
|
320
|
-
export const rdrop2 = __drop(1, 2);
|
|
321
|
-
export const movdr = __move(0, 1);
|
|
322
|
-
export const movrd = __move(1, 0);
|
|
323
|
-
export const cpdr = __copy(0, 1);
|
|
324
|
-
export const cprd = __copy(1, 0);
|
|
325
|
-
export const movdr2 = __move2(0, 1);
|
|
326
|
-
export const movrd2 = __move2(1, 0);
|
|
327
|
-
export const cpdr2 = __copy2(0, 1);
|
|
328
|
-
export const cprd2 = __copy2(1, 0);
|
|
329
|
-
/**
|
|
330
|
-
* Swaps the two topmost r-stack items.
|
|
331
|
-
*
|
|
332
|
-
* ( x y -- y x )
|
|
333
|
-
*
|
|
334
|
-
* @param ctx -
|
|
335
|
-
*/
|
|
336
|
-
export const rswap = __swap(1);
|
|
337
|
-
/**
|
|
338
|
-
* Swaps the two topmost d-stack pairs.
|
|
339
|
-
*
|
|
340
|
-
* ( a b c d -- c d a b )
|
|
341
|
-
*
|
|
342
|
-
* @param ctx -
|
|
343
|
-
*/
|
|
344
|
-
export const rswap2 = __swap2(1);
|
|
345
|
-
/**
|
|
346
|
-
* Pushes copy of TOS-1 as new TOS on r-stack.
|
|
347
|
-
*
|
|
348
|
-
* ( x y -- x y x )
|
|
349
|
-
*
|
|
350
|
-
* @param ctx -
|
|
351
|
-
*/
|
|
352
|
-
export const rover = __over(1);
|
|
353
|
-
/**
|
|
354
|
-
* Like {@link inc}, but applies to r-stack TOS.
|
|
355
|
-
*
|
|
356
|
-
* @param ctx -
|
|
357
|
-
*/
|
|
358
|
-
export const rinc = __incdec(1, 1);
|
|
359
|
-
/**
|
|
360
|
-
* Like {@link dec}, but applies to r-stack TOS.
|
|
361
|
-
*
|
|
362
|
-
* @param ctx -
|
|
363
|
-
*/
|
|
364
|
-
export const rdec = __incdec(1, -1);
|
package/string.js
CHANGED
|
@@ -1,39 +1,26 @@
|
|
|
1
1
|
import { $n, $ } from "./safe.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
*/
|
|
10
|
-
export const ismatch = (ctx) => {
|
|
11
|
-
const stack = ctx[0];
|
|
12
|
-
const n = stack.length - 2;
|
|
13
|
-
$n(n, 0);
|
|
14
|
-
stack[n] = new RegExp(stack[n + 1]).test(stack[n]);
|
|
15
|
-
stack.length--;
|
|
16
|
-
return ctx;
|
|
2
|
+
const ismatch = (ctx) => {
|
|
3
|
+
const stack = ctx[0];
|
|
4
|
+
const n = stack.length - 2;
|
|
5
|
+
$n(n, 0);
|
|
6
|
+
stack[n] = new RegExp(stack[n + 1]).test(stack[n]);
|
|
7
|
+
stack.length--;
|
|
8
|
+
return ctx;
|
|
17
9
|
};
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
export const fromjson = (ctx) => {
|
|
24
|
-
const stack = ctx[0];
|
|
25
|
-
$(stack, 1);
|
|
26
|
-
stack.push(JSON.parse(stack.pop()));
|
|
27
|
-
return ctx;
|
|
10
|
+
const fromjson = (ctx) => {
|
|
11
|
+
const stack = ctx[0];
|
|
12
|
+
$(stack, 1);
|
|
13
|
+
stack.push(JSON.parse(stack.pop()));
|
|
14
|
+
return ctx;
|
|
28
15
|
};
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
16
|
+
const tojson = (ctx) => {
|
|
17
|
+
const stack = ctx[0];
|
|
18
|
+
$(stack, 1);
|
|
19
|
+
stack.push(JSON.stringify(stack.pop(), null, 4));
|
|
20
|
+
return ctx;
|
|
21
|
+
};
|
|
22
|
+
export {
|
|
23
|
+
fromjson,
|
|
24
|
+
ismatch,
|
|
25
|
+
tojson
|
|
39
26
|
};
|