@rip-lang/script 0.1.4 → 0.1.5

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.
Files changed (3) hide show
  1. package/README.md +24 -16
  2. package/package.json +2 -2
  3. package/script.rip +8 -25
package/README.md CHANGED
@@ -151,20 +151,20 @@ chat! [
151
151
  ]
152
152
  ```
153
153
 
154
- ### Regex-Keyed Multiplexing with `mux()`
154
+ ### Map Literal Multiplexing
155
155
 
156
- When you need regex keys, use `mux()` to build a Map:
156
+ When you need regex keys or mixed key types, use a map literal (`*{ }`):
157
157
 
158
158
  ```coffee
159
- import { mux, ELSE } from '@rip-lang/script'
159
+ import { ELSE } from '@rip-lang/script'
160
160
 
161
161
  chat! [
162
162
  "Enter name:", "SMITH,JOHN"
163
- mux(
164
- /^NAME:/, [""] # regex key
165
- "CHOOSE 1", [1] # string key
166
- ELSE, null # fallback — nothing matched
167
- )
163
+ *{
164
+ /^NAME:/: [""] # regex key
165
+ "CHOOSE 1": [1] # string key
166
+ ELSE: null # fallback — nothing matched
167
+ }
168
168
  ]
169
169
  ```
170
170
 
@@ -256,16 +256,24 @@ import { REDO, SKIP, ELSE, THIS, PURE } from '@rip-lang/script'
256
256
 
257
257
  ## Helper Functions
258
258
 
259
- ### `mux(...args)` — Mixed-Key Multiplexer
259
+ ### Map Literals (`*{ }`) — Mixed-Key Multiplexers
260
+
261
+ Use map literals for multiplexers with regex keys or mixed key types:
262
+
263
+ ```coffee
264
+ *{
265
+ /^NAME:/: [""]
266
+ "CHOOSE 1": [1]
267
+ ELSE: null
268
+ }
269
+ ```
260
270
 
261
- Build a Map from alternating key/value arguments:
271
+ Map literals compile to `new Map(...)` and support all key types: strings,
272
+ regexes, numbers, booleans, symbols, and expressions via `(expr)`.
273
+ Spread (`...expr`) merges entries from other Maps or iterables:
262
274
 
263
275
  ```coffee
264
- mux(
265
- /^NAME:/, [""]
266
- "CHOOSE 1", [1]
267
- ELSE, null
268
- )
276
+ *{ "Are you adding": ["Y"], ...extra }
269
277
  ```
270
278
 
271
279
  ### `replace(value)` — Replace/Edit Handler
@@ -361,7 +369,7 @@ chat = Script.ssh! 'user@host',
361
369
  | `true` | Continue | No-op pass-through. |
362
370
  | `false` / `Symbol` | Control Signal | `REDO`, `SKIP`, etc. — flow control. |
363
371
  | `Object` | Multiplexer | Try each string key against buffer. First match wins. |
364
- | `Map` | Multiplexer | Like Object but supports regex keys. Use `mux()`. |
372
+ | `Map` | Multiplexer | Like Object but supports regex keys. Use `*{ }` map literals. |
365
373
  | `Array` | Sub-script | Nest a conversation. Boolean first element = conditional. |
366
374
  | `Function` | Callback | Execute, return value becomes next item to process. |
367
375
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rip-lang/script",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Homoiconic interaction engine — automate stateful conversations with remote systems using nested data structures",
5
5
  "type": "module",
6
6
  "main": "script.rip",
@@ -29,7 +29,7 @@
29
29
  "author": "Steve Shreeve <steve.shreeve@gmail.com>",
30
30
  "license": "MIT",
31
31
  "dependencies": {
32
- "rip-lang": ">=3.13.129"
32
+ "rip-lang": ">=3.13.130"
33
33
  },
34
34
  "files": [
35
35
  "script.rip",
package/script.rip CHANGED
@@ -471,15 +471,6 @@ export class Script
471
471
 
472
472
  # ==[ Helper Functions ]==
473
473
 
474
- # Build a Map from alternating key/value arguments (supports regex keys)
475
- export def mux(...args)
476
- pairs = []
477
- i = 0
478
- while i < args.length
479
- pairs.push [args[i], args[i + 1]]
480
- i += 2
481
- new Map pairs
482
-
483
474
  # Sugar for common prompt/response patterns (string keys only)
484
475
  export def prompts(obj)
485
476
  result = {}
@@ -489,28 +480,20 @@ export def prompts(obj)
489
480
 
490
481
  # Handle "Replace ... With ..." editing dance
491
482
  export def replace(value)
492
- mux(
493
- "Replace ", ["...", " With ", value, " Replace ", ""]
494
- "// ", value
495
- ELSE, value
496
- )
483
+ *{
484
+ "Replace ": ["...", " With ", value, " Replace ", ""]
485
+ "// ": value
486
+ ELSE: value
487
+ }
497
488
 
498
489
  # Force exact match with double quotes
499
490
  export def quote(value)
500
491
  "\"#{value}\""
501
492
 
502
493
  # Handle entering a value that may trigger "Are you adding?" confirmation
503
- export def enter(value, ...rest)
504
- items = if Array.isArray(value) then value else [value]
505
- extra = {}
506
- if rest.length is 1 and typeof rest[0] is 'object' and not Array.isArray(rest[0]) and rest[0] not instanceof RegExp
507
- extra = rest[0]
508
- rest = []
509
- mux(
510
- "Are you adding", ["Y"]
511
- ...Object.entries(extra).flat()
512
- ...rest
513
- )
494
+ export def enter(value, extra)
495
+ entries = if extra instanceof Map then [...extra] else if extra? then Object.entries(extra) else []
496
+ *{ "Are you adding": ["Y"], ...entries }
514
497
 
515
498
  # ==[ Default Export ]==
516
499