papagaio 0.37.3 → 0.38.2
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 +55 -25
- package/dist/wasm/papagaio.js +0 -2
- package/dist/wasm/papagaio_wasm.js +0 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -218,25 +218,29 @@ Any variable can be treated as a list by accessing it through the `$list` modifi
|
|
|
218
218
|
### Syntax
|
|
219
219
|
|
|
220
220
|
```
|
|
221
|
-
$VARNAME$list
|
|
221
|
+
$VARNAME$list{separator}$OPERATION{...arguments}
|
|
222
222
|
```
|
|
223
223
|
|
|
224
224
|
### Operations
|
|
225
225
|
|
|
226
226
|
| Operation | Signature | Emits | Mutates |
|
|
227
227
|
|---|---|---|---|
|
|
228
|
-
| `get` | `$V$list
|
|
229
|
-
| `set` | `$V$list
|
|
230
|
-
| `push` | `$V$list
|
|
231
|
-
| `pop` | `$V$list
|
|
232
|
-
| `shift` | `$V$list
|
|
233
|
-
| `unshift` | `$V$list
|
|
234
|
-
| `insert` | `$V$list
|
|
235
|
-
| `remove` | `$V$list
|
|
236
|
-
| `swap` | `$V$list
|
|
237
|
-
| `reverse` | `$V$list
|
|
238
|
-
| `count` | `$V$list
|
|
239
|
-
| `join` | `$V$list
|
|
228
|
+
| `get` | `$V$list{sep}$get{idx}` | Element at index | No |
|
|
229
|
+
| `set` | `$V$list{sep}$set{idx}{content}` | Nothing | Yes |
|
|
230
|
+
| `push` | `$V$list{sep}$push{content}` | Nothing | Yes |
|
|
231
|
+
| `pop` | `$V$list{sep}$pop` | Last element | Yes |
|
|
232
|
+
| `shift` | `$V$list{sep}$shift` | First element | Yes |
|
|
233
|
+
| `unshift` | `$V$list{sep}$unshift{content}` | Nothing | Yes |
|
|
234
|
+
| `insert` | `$V$list{sep}$insert{idx}{content}` | Nothing | Yes |
|
|
235
|
+
| `remove` | `$V$list{sep}$remove{idx}` | Nothing | Yes |
|
|
236
|
+
| `swap` | `$V$list{sep}$swap{idx_a}{idx_b}` | Nothing | Yes |
|
|
237
|
+
| `reverse` | `$V$list{sep}$reverse` | Nothing | Yes |
|
|
238
|
+
| `count` | `$V$list{sep}$count` | Number of elements | No |
|
|
239
|
+
| `join` | `$V$list{sep_orig}$join{sep_new}` | List with new separator | No |
|
|
240
|
+
| `slice` | `$V$list{sep}$slice{start}{end}` | Sub-list from start to end | No |
|
|
241
|
+
| `find` | `$V$list{sep}$find{pat}` | First **whole element** matching `pat` | No |
|
|
242
|
+
| `contains` | `$V$list{sep}$contains{pat}` | Index of `pat` **within** matching element | No |
|
|
243
|
+
| `replace` | `$V$list{sep}$replace{pat}{rep}` | First match found; updates the **whole element** | Yes |
|
|
240
244
|
|
|
241
245
|
**Index rules**: zero-based; negative indices count from the end (`-1` = last); out-of-range access emits `""` silently.
|
|
242
246
|
|
|
@@ -245,39 +249,42 @@ $VARNAME$list$OPERATION{separator}{...arguments}
|
|
|
245
249
|
```text
|
|
246
250
|
$FRUITS$from{apple,banana,orange}
|
|
247
251
|
|
|
248
|
-
$FRUITS$list
|
|
249
|
-
$FRUITS$list
|
|
250
|
-
$FRUITS$list
|
|
252
|
+
$FRUITS$list{,}$get{0} → apple
|
|
253
|
+
$FRUITS$list{,}$get{-1} → orange
|
|
254
|
+
$FRUITS$list{,}$count → 3
|
|
251
255
|
```
|
|
252
256
|
|
|
253
257
|
```text
|
|
254
258
|
$L$from{a,b,c}
|
|
255
|
-
$L$list
|
|
256
|
-
$L$list
|
|
259
|
+
$L$list{,}$push{d}
|
|
260
|
+
$L$list{,}$set{1}{B}
|
|
257
261
|
$L → a,B,c,d
|
|
258
262
|
```
|
|
259
263
|
|
|
260
264
|
```text
|
|
261
265
|
$STACK$from{x,y,z}
|
|
262
|
-
Popped: $STACK$list
|
|
266
|
+
Popped: $STACK$list{,}$pop
|
|
263
267
|
Rest: $STACK → Popped: z / Rest: x,y
|
|
264
268
|
```
|
|
265
269
|
|
|
266
270
|
```text
|
|
267
271
|
$CSV$from{one,two,three}
|
|
268
|
-
$CSV$list
|
|
272
|
+
$CSV$list{,}$join{ | } → one | two | three
|
|
269
273
|
```
|
|
270
274
|
|
|
271
275
|
```text
|
|
272
276
|
$PATH$from{/usr/local/bin}
|
|
273
|
-
$PATH$list
|
|
277
|
+
$PATH$list{/}$get{-1} → bin
|
|
274
278
|
```
|
|
275
279
|
|
|
276
280
|
```text
|
|
277
281
|
/* Dynamic separator from variable */
|
|
278
282
|
$SEP$from{,}
|
|
279
283
|
$L$from{x,y,z}
|
|
280
|
-
$L$list
|
|
284
|
+
$L$list{$SEP}$get{2} → z
|
|
285
|
+
|
|
286
|
+
$L$from{a,b,c,d,e}
|
|
287
|
+
$L$list{,}$slice{1}{4} → b,c,d
|
|
281
288
|
```
|
|
282
289
|
|
|
283
290
|
---
|
|
@@ -290,6 +297,10 @@ Papagaio provides operators for conditional logic and value chaining. These are
|
|
|
290
297
|
|
|
291
298
|
```
|
|
292
299
|
$VAL$compare{target}
|
|
300
|
+
$VAL$find{pattern}
|
|
301
|
+
$VAL$contains{pattern}
|
|
302
|
+
$VAL$replace{pattern}{replacement}
|
|
303
|
+
$VAL$slice{start}{end}
|
|
293
304
|
$VAL$then{content}
|
|
294
305
|
$VAL$else{content}
|
|
295
306
|
```
|
|
@@ -297,8 +308,12 @@ $VAL$else{content}
|
|
|
297
308
|
| Operator | Behavior |
|
|
298
309
|
|---|---|
|
|
299
310
|
| **`compare`** | If `$VAL` matches `target`, emits `$VAL`. Otherwise, emits `""`. |
|
|
300
|
-
| **`
|
|
301
|
-
| **`
|
|
311
|
+
| **`find`** | Performs a non-anchored search for `pattern` in `$VAL`. Emits the matched substring. |
|
|
312
|
+
| **`contains`** | Performs a non-anchored search. Emits the character index of the first match (or `""`). |
|
|
313
|
+
| **`replace`** | Replaces the first match of `pattern` with `replacement`. Emits the OLD match. |
|
|
314
|
+
| **`slice`** | Returns a substring from `start` to `end`. Supports negative indices. |
|
|
315
|
+
| **`then`** | If `$VAL` is **not empty**, processes and emits `content`. Otherwise, emits `""`. |
|
|
316
|
+
| **`else`** | If `$VAL` **is empty**, processes and emits `content`. Otherwise, passes `$VAL` through. |
|
|
302
317
|
| **`repeat`** | `$repeat{N}{code}` | Executes `code` N times. Emits nothing; used for side effects. |
|
|
303
318
|
| **`while`** | `$while{pat}{code}` | Executes `code` while its result matches `pat`. Emits the last successful result. |
|
|
304
319
|
| **`until`** | `$until{pat}{code}` | Executes `code` until its result matches `pat`. Emits the match that caused the break. |
|
|
@@ -320,6 +335,21 @@ $A$compare{world}$then{Matched!} → (empty)
|
|
|
320
335
|
$A$from{abc}
|
|
321
336
|
$A$compare{abc}$then{YES}$else{NO} → YES
|
|
322
337
|
$A$compare{xyz}$then{YES}$else{NO} → NO
|
|
338
|
+
|
|
339
|
+
#### Search and Extract:
|
|
340
|
+
```text
|
|
341
|
+
$A$from{user_id: 12345}
|
|
342
|
+
$A$find{$d+}$ → 12345
|
|
343
|
+
$A$contains{id} → 5
|
|
344
|
+
$A$replace{$d+}{HIDDEN} $A → 12345 user_id: HIDDEN
|
|
345
|
+
|
|
346
|
+
#### Slicing:
|
|
347
|
+
```text
|
|
348
|
+
$A$from{hello world}
|
|
349
|
+
$A$slice{0}{5} → hello
|
|
350
|
+
$A$slice{-5} → world
|
|
351
|
+
```
|
|
352
|
+
```
|
|
323
353
|
```
|
|
324
354
|
|
|
325
355
|
### Standalone and Braced Usage
|
|
@@ -330,7 +360,7 @@ $A$compare{xyz}$then{YES}$else{NO} → NO
|
|
|
330
360
|
#### Example:
|
|
331
361
|
```text
|
|
332
362
|
$L$from{a,b,c}
|
|
333
|
-
$R$from{$L$list
|
|
363
|
+
$R$from{$L$list{,}$get{0}}
|
|
334
364
|
$R$compare{a}$then{Is A}$else{Not A} → Is A
|
|
335
365
|
```
|
|
336
366
|
|
package/dist/wasm/papagaio.js
CHANGED
|
@@ -20,8 +20,6 @@ class Papagaio {
|
|
|
20
20
|
|
|
21
21
|
registerCommand(name, handler) {
|
|
22
22
|
// Note: Implementing JS->C callbacks requires addFunction and extra glue.
|
|
23
|
-
// For now, we warn that this is not yet supported in the pure WASM wrapper.
|
|
24
|
-
console.warn(`[WASM] Warning: registerCommand('${name}') is not supported in JS wrapper yet.`);
|
|
25
23
|
}
|
|
26
24
|
|
|
27
25
|
setArgs(argv) {
|
|
Binary file
|