papagaio 0.5.2 → 0.6.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.
@@ -0,0 +1,70 @@
1
+ // generic ts-like to wasm compiler
2
+
3
+ // util patterns
4
+ $pattern {// $comment $regex newline{[^\n]*}} {}
5
+ $pattern {$regex spaces{\s\s}}{ }
6
+
7
+ $eval{
8
+ papagaio.exit = function()
9
+ {
10
+ papagaio.content = "(module\n" + papagaio.content + "\n)";
11
+ papagaio.exit = null;
12
+ };
13
+ return ""
14
+ }
15
+
16
+ $pattern {export function $name $block params{(}{)}:$rets $block content{}{}} {
17
+ $pattern {parametrize}
18
+ {
19
+ $eval {
20
+ let str = "$params".replace("(", "").replace(")", "");
21
+ let params = str.split(",").map(p => p.trim()).filter(p => p);
22
+ let new_stuff = "";
23
+ for (const param of params) {
24
+ if (!param.includes(":")) continue; // Pula se não tem ':'
25
+ const [name, type] = param.split(":");
26
+ if (name && type) { // Verifica se ambos existem
27
+ new_stuff += ` (param $${name.trim()} ${type.trim()}) `;
28
+ }
29
+ }
30
+ return new_stuff;
31
+ }
32
+ }
33
+
34
+ (func (export "$name") parametrize (result $rets)
35
+ $content
36
+ )
37
+ }
38
+
39
+ $pattern {function $name $block params{(}{)}:$rets $block content{}{}} {
40
+ $pattern {parametrize}
41
+ {
42
+ $eval {
43
+ let str = "$params".replace("(", "").replace(")", "");
44
+ let params = str.split(",").map(p => p.trim()).filter(p => p);
45
+ let new_stuff = "";
46
+ for (const param of params) {
47
+ if (!param.includes(":")) continue; // Pula se não tem ':'
48
+ const [name, type] = param.split(":");
49
+ if (name && type) { // Verifica se ambos existem
50
+ new_stuff += ` (param $${name.trim()} ${type.trim()}) `;
51
+ }
52
+ }
53
+ return new_stuff;
54
+ }
55
+ }
56
+
57
+ (func $$name parametrize (result $rets)
58
+ $content
59
+ )
60
+ }
61
+
62
+ function name(a:i32, b:i32):i64 i64
63
+ {
64
+ contentnans
65
+ }
66
+
67
+ export function funcao_exportada(a:f32, b:f32, c:f32):i64 i64 i64 i64
68
+ {
69
+ fução expoortada1
70
+ }
package/index.html CHANGED
@@ -7,13 +7,16 @@
7
7
  </head>
8
8
  <body>
9
9
 
10
- <h1>🦜 papagaio</h1>
10
+ <h1>🦜 papagaio </h1>
11
11
  <p>
12
12
  easy yet powerful text preprocessor.
13
13
  </p>
14
14
  <hr>
15
15
  <div>
16
- <label for="sketchSelect">Current Sketch:</label>
16
+ <strong>
17
+ <label for="sketchSelect">Current Sketch:</label>
18
+ </strong>
19
+
17
20
  <select id="sketchSelect" onchange="switchSketch()">
18
21
  <option value="">-- Select Sketch --</option>
19
22
  </select>
@@ -24,7 +27,9 @@
24
27
  </div>
25
28
  <hr>
26
29
  <div>
30
+ <strong>
27
31
  <label for="sketchSelect">Sketches:</label>
32
+ </strong>
28
33
  <button onclick="exportSketches()">Export</button>
29
34
  <input type="file" id="importFileInput" onchange="importSketches(this.files[0])" accept=".json">
30
35
  </div>
@@ -270,7 +275,8 @@
270
275
  function exportSketches() {
271
276
  const data = {
272
277
  papagaio_sketches: localStorage.getItem('papagaio_sketches'),
273
- papagaio_current_sketch: localStorage.getItem('papagaio_current_sketch')
278
+ papagaio_current_sketch: localStorage.getItem('papagaio_current_sketch'),
279
+ papagaio_config: localStorage.getItem('papagaio_config')
274
280
  };
275
281
 
276
282
  const blob = new Blob([JSON.stringify(data, null, 2)], {
@@ -297,6 +303,9 @@
297
303
  if (data.papagaio_current_sketch) {
298
304
  localStorage.setItem('papagaio_current_sketch', data.papagaio_current_sketch);
299
305
  }
306
+ if (data.papagaio_config) {
307
+ localStorage.setItem('papagaio_config', data.papagaio_config);
308
+ }
300
309
  location.reload();
301
310
  } catch (err) {
302
311
  alert('Error importing file: ' + err.message);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "papagaio",
3
- "version": "0.5.2",
3
+ "version": "0.6.2",
4
4
  "description": "easy yet powerful preprocessor",
5
5
  "main": "src/papagaio.js",
6
6
  "type": "module",
@@ -16,7 +16,11 @@
16
16
  "macro",
17
17
  "pattern",
18
18
  "eval",
19
- "parser"
19
+ "parser",
20
+ "codegen",
21
+ "regex",
22
+ "syntax",
23
+ "easy"
20
24
  ],
21
25
  "author": "jardimdanificado",
22
26
  "bugs": {
@@ -24,6 +28,6 @@
24
28
  },
25
29
  "homepage": "https://github.com/jardimdanificado/papagaio#readme",
26
30
  "bin": {
27
- "papagaio": "./bin/cli.js"
31
+ "papagaio": "bin/cli.mjs"
28
32
  }
29
33
  }
@@ -1,4 +1,5 @@
1
1
  // papagaio-bootstrap.js
2
+ // only needed if using <script type="papagaio"> in browser
2
3
  import { Papagaio } from "./papagaio.js";
3
4
 
4
5
  (async () => {
@@ -15,11 +16,8 @@ import { Papagaio } from "./papagaio.js";
15
16
 
16
17
  const out = p.process(src);
17
18
 
18
- const s = document.createElement("script");
19
- s.type = "module";
19
+ const s = document.createElement("div");
20
20
  s.textContent = out;
21
-
22
- // executa no mesmo ponto onde script estava
23
- el.replaceWith(s);
21
+ window.document.body.appendChild(s);
24
22
  }
25
23
  })();
package/src/papagaio.js CHANGED
@@ -1,7 +1,7 @@
1
+ // papagaio - https://github.com/jardimdanificado/papagaio
1
2
  function parsePattern(p, pat) {
2
3
  const t = [], S = p.symbols.sigil, O = p.symbols.open;
3
4
  let i = 0;
4
-
5
5
  while (i < pat.length) {
6
6
  if (pat.startsWith(S + p.symbols.regex, i)) {
7
7
  let j = i + S.length + p.symbols.regex.length;
@@ -46,8 +46,7 @@ function parsePattern(p, pat) {
46
46
  const optional = pat[j] === '?';
47
47
  if (optional) j++;
48
48
  t.push({ type: 'var', varName: v, optional });
49
- i = j;
50
- continue;
49
+ i = j; continue;
51
50
  }
52
51
  t.push({ type: 'lit', value: S }); i += S.length; continue;
53
52
  }
@@ -62,47 +61,42 @@ function parsePattern(p, pat) {
62
61
  return t;
63
62
  }
64
63
 
65
- function matchPattern(p, src, tokens, pos = 0) {
64
+ function matchPattern(p, src, tok, pos = 0) {
66
65
  let cap = {};
67
- for (let ti = 0; ti < tokens.length; ti++) {
68
- const tok = tokens[ti];
69
- if (tok.type === 'ws') { while (pos < src.length && /\s/.test(src[pos])) pos++; continue; }
70
- if (tok.type === 'lit') { if (!src.startsWith(tok.value, pos)) return null; pos += tok.value.length; continue; }
71
- if (tok.type === 'regex') {
66
+ for (let ti = 0; ti < tok.length; ti++) {
67
+ const t = tok[ti];
68
+ if (t.type === 'ws') { while (pos < src.length && /\s/.test(src[pos])) pos++; continue; }
69
+ if (t.type === 'lit') { if (!src.startsWith(t.value, pos)) return null; pos += t.value.length; continue; }
70
+ if (t.type === 'regex') {
72
71
  try {
73
- let regex = p._regexCache.get(tok.regex);
74
- if (!regex) {
75
- regex = new RegExp(tok.regex);
76
- p._regexCache.set(tok.regex, regex);
77
- }
78
- const m = src.slice(pos).match(regex);
72
+ const rx = new RegExp(t.regex), m = src.slice(pos).match(rx);
79
73
  if (!m || m.index !== 0) return null;
80
- cap[p.symbols.sigil + tok.varName] = m[0];
74
+ cap[p.symbols.sigil + t.varName] = m[0];
81
75
  pos += m[0].length;
82
- } catch { return null; }
76
+ } catch (e) { return null; }
83
77
  continue;
84
78
  }
85
- if (tok.type === 'var') {
79
+ if (t.type === 'var') {
86
80
  while (pos < src.length && /\s/.test(src[pos])) pos++;
87
- const nx = findNext(tokens, ti);
81
+ const nx = findNext(tok, ti);
88
82
  let v = '';
89
- if (nx?.type === 'block') {
83
+ if (nx && nx.type === 'block') {
90
84
  while (pos < src.length && !src.startsWith(nx.open, pos) && src[pos] !== '\n') v += src[pos++];
91
85
  v = v.trimEnd();
92
- } else if (nx?.type === 'lit') {
86
+ } else if (nx && nx.type === 'lit') {
93
87
  while (pos < src.length && !src.startsWith(nx.value, pos) && src[pos] !== '\n') v += src[pos++];
94
88
  v = v.trimEnd();
95
89
  } else {
96
90
  while (pos < src.length && !/\s/.test(src[pos])) v += src[pos++];
97
91
  }
98
- if (!v && !tok.optional) return null;
99
- cap[p.symbols.sigil + tok.varName] = v;
92
+ if (!v && !t.optional) return null;
93
+ cap[p.symbols.sigil + t.varName] = v;
100
94
  continue;
101
95
  }
102
- if (tok.type === 'block') {
103
- if (!src.startsWith(tok.open, pos)) return null;
104
- const [c, e] = extractBlock(p, src, pos, tok.open, tok.close);
105
- cap[p.symbols.sigil + tok.varName] = c; pos = e; continue;
96
+ if (t.type === 'block') {
97
+ if (!src.startsWith(t.open, pos)) return null;
98
+ const [c, e] = extractBlock(p, src, pos, t.open, t.close);
99
+ cap[p.symbols.sigil + t.varName] = c; pos = e; continue;
106
100
  }
107
101
  }
108
102
  return { captures: cap, endPos: pos };
@@ -134,58 +128,41 @@ function extractBlock(p, src, i, od = p.symbols.open, cd = p.symbols.close) {
134
128
  return ['', i];
135
129
  }
136
130
 
137
- function collectPats(p, src) {
138
- const arr = [];
139
- const rx = new RegExp(`(?:^|\\b)${esc(p.symbols.pattern)}\\s*${esc(p.symbols.open)}`, "g");
140
- let out = src;
141
- while (1) {
142
- rx.lastIndex = 0; const m = rx.exec(out); if (!m) break;
143
- const s = m.index, o = m.index + m[0].length - p.symbols.open.length;
144
- const [mp, em] = extractBlock(p, out, o); let k = em;
145
- while (k < out.length && /\s/.test(out[k])) k++;
146
- if (k < out.length && out.substring(k, k + p.symbols.open.length) === p.symbols.open) {
147
- const [rp, er] = extractBlock(p, out, k);
148
- arr.push({ m: mp.trim(), r: rp.trim() });
149
- out = out.slice(0, s) + out.slice(er); continue;
150
- }
151
- out = out.slice(0, s) + out.slice(em);
152
- }
153
- return [arr, out];
154
- }
155
-
156
131
  function extractNested(p, txt) {
157
- const n = [];
158
- const rx = new RegExp(`${esc(p.symbols.sigil)}${esc(p.symbols.pattern)}\\s*${esc(p.symbols.open)}`, "g");
132
+ const loc = [], S = p.symbols.sigil, O = p.symbols.open;
159
133
  let out = txt;
134
+ const rx = new RegExp(`${esc(S)}${esc(p.symbols.pattern)}\\s*${esc(O)}`, "g");
160
135
  while (1) {
161
136
  rx.lastIndex = 0; const m = rx.exec(out); if (!m) break;
162
- const s = m.index, o = m.index + m[0].length - p.symbols.open.length;
137
+ const s = m.index, o = m.index + m[0].length - O.length;
163
138
  const [mp, em] = extractBlock(p, out, o); let k = em;
164
139
  while (k < out.length && /\s/.test(out[k])) k++;
165
- if (k < out.length && out.substring(k, k + p.symbols.open.length) === p.symbols.open) {
140
+ if (k < out.length && out.substring(k, k + O.length) === O) {
166
141
  const [rp, er] = extractBlock(p, out, k);
167
- n.push({ m: mp.trim(), r: rp.trim() });
142
+ loc.push({ m: mp.trim(), r: rp.trim() });
168
143
  out = out.slice(0, s) + out.slice(er); continue;
169
144
  }
170
145
  out = out.slice(0, s) + out.slice(em);
171
146
  }
172
- return [n, out];
147
+ return [loc, out];
173
148
  }
174
149
 
175
150
  function extractEvals(p, txt) {
176
151
  const ev = [], S = p.symbols.sigil, O = p.symbols.open;
177
152
  let i = 0, out = txt, off = 0;
178
153
  while (i < txt.length) {
179
- if (txt.substring(i, i + S.length) === S && txt.substring(i + S.length, i + S.length + p.symbols.eval.length) === p.symbols.eval) {
180
- let j = i + S.length + p.symbols.eval.length;
181
- while (j < txt.length && /\s/.test(txt[j])) j++;
182
- if (j < txt.length && txt.substring(j, j + O.length) === O) {
183
- const sp = i, bp = j;
184
- const [c, ep] = extractBlock(p, txt, bp);
185
- ev.push({ code: c, sp: sp - off, ep: ep - off });
186
- const ph = `__E${ev.length - 1}__`;
187
- out = out.substring(0, sp - off) + ph + out.substring(ep - off);
188
- off += (ep - sp) - ph.length; i = ep; continue;
154
+ if (txt.substring(i, i + S.length) === S) {
155
+ const rest = txt.substring(i + S.length);
156
+ if (rest.startsWith(p.symbols.eval)) {
157
+ let j = i + S.length + p.symbols.eval.length;
158
+ while (j < txt.length && /\s/.test(txt[j])) j++;
159
+ if (j < txt.length && txt.substring(j, j + O.length) === O) {
160
+ const sp = i, bp = j, [c, ep] = extractBlock(p, txt, bp);
161
+ ev.push({ code: c, sp: sp - off, ep: ep - off });
162
+ const ph = `__E${ev.length - 1}__`;
163
+ out = out.substring(0, sp - off) + ph + out.substring(ep - off);
164
+ off += (ep - sp) - ph.length; i = ep; continue;
165
+ }
189
166
  }
190
167
  }
191
168
  i++;
@@ -206,7 +183,6 @@ function applyEvals(p, txt, ev) {
206
183
  }
207
184
 
208
185
  function applyPats(p, src, pats) {
209
- let last = "", S = p.symbols.sigil;
210
186
  for (const pat of pats) {
211
187
  const tok = parsePattern(p, pat.m);
212
188
  let n = '', pos = 0, ok = false;
@@ -215,16 +191,16 @@ function applyPats(p, src, pats) {
215
191
  if (m) {
216
192
  ok = true;
217
193
  let r = pat.r;
218
- const [nested, clean] = extractNested(p, r);
219
- r = clean;
220
- for (const [k, v] of Object.entries(m.captures)) {
221
- r = r.replace(new RegExp(esc(k) + '(?![A-Za-z0-9_])', 'g'), v);
222
- }
223
- if (nested.length) r = applyPats(p, r, nested);
194
+ const [loc, cln] = extractNested(p, r);
195
+ r = cln;
196
+ Object.keys(m.captures).forEach(k => {
197
+ r = r.replace(new RegExp(esc(k) + '(?![A-Za-z0-9_])', 'g'), m.captures[k]);
198
+ });
199
+ if (loc.length) r = applyPats(p, r, loc);
224
200
  p.match = src.slice(pos, m.endPos);
225
201
  const [ev, ct] = extractEvals(p, r);
226
202
  if (ev.length) r = applyEvals(p, ct, ev);
227
- n += r; last = r; pos = m.endPos;
203
+ n += r; pos = m.endPos;
228
204
  } else { n += src[pos]; pos++; }
229
205
  }
230
206
  if (ok) src = n;
@@ -243,23 +219,28 @@ function unescapeDelim(s) {
243
219
  }
244
220
 
245
221
  export class Papagaio {
246
- constructor(sigil = '$', open = '{', close = '}', pattern = 'pattern', evalKeyword = 'eval', blockKeyword = 'block', regexKeyword = 'regex') {
247
- this.recursion_limit = 512;
248
- this.symbols = { pattern, open, close, sigil, eval: evalKeyword, block: blockKeyword, regex: regexKeyword };
222
+ constructor(sigil = '$', open = '{', close = '}', pattern = 'pattern', evalKw = 'eval', blockKw = 'block', regexKw = 'regex') {
223
+ this.symbols = { pattern, open, close, sigil, eval: evalKw, block: blockKw, regex: regexKw };
249
224
  this.content = "";
250
225
  this.match = "";
251
- this._regexCache = new Map();
252
226
  }
253
227
  process(input) {
254
- this.content = input;
255
- let src = input, last = null, it = 0;
256
- const pending = () => new RegExp(`(?:^|\\b)${esc(this.symbols.pattern)}\\s*${esc(this.symbols.open)}`, "g").test(src);
257
- while (src !== last && it < this.recursion_limit) {
258
- it++; last = src;
259
- const [p, s2] = collectPats(this, src);
260
- src = applyPats(this, s2, p);
261
- if (!pending()) break;
228
+ const [loc, cln] = extractNested(this, input);
229
+ const [evals, ph] = extractEvals(this, cln);
230
+ let proc = applyEvals(this, ph, evals);
231
+ if (loc.length === 0) {
232
+ this.content = proc;
233
+ return proc;
234
+ }
235
+ let src = proc, last = null;
236
+ while (src !== last) {
237
+ last = src;
238
+ src = applyPats(this, src, loc);
239
+ const [nested] = extractNested(this, src);
240
+ if (nested.length === 0) break;
262
241
  }
263
- return this.content = src, src;
242
+ this.content = src;
243
+ if (typeof this.exit == "function") this.exit();
244
+ return this.content;
264
245
  }
265
246
  }
package/tests/tests.json CHANGED
@@ -3,211 +3,211 @@
3
3
  {
4
4
  "id": 1,
5
5
  "name": "Basic variable substitution",
6
- "code": "pattern {$x $y} {$y, $x}\nhello world",
6
+ "code": "$pattern {$x $y} {$y, $x}\nhello world",
7
7
  "expected": "world, hello"
8
8
  },
9
9
  {
10
10
  "id": 2,
11
11
  "name": "Flexible whitespace with $",
12
- "code": "pattern {$x and $y} {$x & $y}\nhello and world",
12
+ "code": "$pattern {$x and $y} {$x & $y}\nhello and world",
13
13
  "expected": "hello & world"
14
14
  },
15
15
  {
16
16
  "id": 3,
17
17
  "name": "Block with custom delimiters",
18
- "code": "pattern {$block content {(}{)}} {[$content]}\ndata (hello world)",
18
+ "code": "$pattern {$block content {(}{)}} {[$content]}\ndata (hello world)",
19
19
  "expected": "data [hello world]"
20
20
  },
21
21
  {
22
22
  "id": 4,
23
23
  "name": "Block with multi-char delimiters",
24
- "code": "pattern {$block code {<<}{>>}} {CODE[$code]}\n<<console.log()>>",
24
+ "code": "$pattern {$block code {<<}{>>}} {CODE[$code]}\n<<console.log()>>",
25
25
  "expected": "CODE[console.log()]"
26
26
  },
27
27
  {
28
28
  "id": 5,
29
29
  "name": "Block with nested delimiters",
30
- "code": "pattern {$block txt {<}{>}} {[$txt]}\nouter <middle <inner> content>",
30
+ "code": "$pattern {$block txt {<}{>}} {[$txt]}\nouter <middle <inner> content>",
31
31
  "expected": "outer [middle <inner> content]"
32
32
  },
33
33
  {
34
34
  "id": 6,
35
35
  "name": "Eval expression with arithmetic",
36
- "code": "pattern {sum $a $b} {$eval{return parseInt($a) + parseInt($b)}}\nsum 5 3",
36
+ "code": "$pattern {sum $a $b} {$eval{return parseInt($a) + parseInt($b)}}\nsum 5 3",
37
37
  "expected": "8"
38
38
  },
39
39
  {
40
40
  "id": 7,
41
41
  "name": "Eval with arithmetic and variable",
42
- "code": "pattern {multiply $n} {Result: $eval{return $n * 3}}\nmultiply 5",
42
+ "code": "$pattern {multiply $n} {Result: $eval{return $n * 3}}\nmultiply 5",
43
43
  "expected": "Result: 15"
44
44
  },
45
45
  {
46
46
  "id": 8,
47
47
  "name": "Multiple patterns cascade",
48
- "code": "pattern {a} {b}\npattern {b} {c}\na",
48
+ "code": "$pattern {a} {b}\n$pattern {b} {c}\na",
49
49
  "expected": "c"
50
50
  },
51
51
  {
52
52
  "id": 9,
53
53
  "name": "Global pattern matching",
54
- "code": "pattern {x} {X}\nx y x z x",
54
+ "code": "$pattern {x} {X}\nx y x z x",
55
55
  "expected": "X y X z X"
56
56
  },
57
57
  {
58
58
  "id": 10,
59
59
  "name": "Pattern with special regex characters",
60
- "code": "pattern {a.*b} {MATCHED}\na.*b",
60
+ "code": "$pattern {a.*b} {MATCHED}\na.*b",
61
61
  "expected": "MATCHED"
62
62
  },
63
63
  {
64
64
  "id": 11,
65
65
  "name": "Multiple blocks in one pattern",
66
- "code": "pattern {$block a {(}{)} and $block b {[}{]}} {$a|$b}\n(first) and [second]",
66
+ "code": "$pattern {$block a {(}{)} and $block b {[}{]}} {$a|$b}\n(first) and [second]",
67
67
  "expected": "first|second"
68
68
  },
69
69
  {
70
70
  "id": 12,
71
71
  "name": "Variable reuse in replacement",
72
- "code": "pattern {$x} {$x:$x}\ndata",
72
+ "code": "$pattern {$x} {$x:$x}\ndata",
73
73
  "expected": "data:data"
74
74
  },
75
75
  {
76
76
  "id": 13,
77
77
  "name": "Literal dollar sign in replacement",
78
- "code": "pattern {price} {$50}\nprice",
78
+ "code": "$pattern {price} {$50}\nprice",
79
79
  "expected": "$50"
80
80
  },
81
81
  {
82
82
  "id": 14,
83
83
  "name": "Optional whitespace with $ optional",
84
- "code": "pattern {hello$world} {HI}\nhello\n\nworld",
84
+ "code": "$pattern {hello$world} {HI}\nhello\n\nworld",
85
85
  "expected": "HI"
86
86
  },
87
87
  {
88
88
  "id": 15,
89
89
  "name": "Block with angle brackets",
90
- "code": "pattern {$block inner {<}{>}} {WRAPPED[$inner]}\n<content>",
90
+ "code": "$pattern {$block inner {<}{>}} {WRAPPED[$inner]}\n<content>",
91
91
  "expected": "WRAPPED[content]"
92
92
  },
93
93
  {
94
94
  "id": 16,
95
95
  "name": "Pattern with literal characters",
96
- "code": "pattern {Mr. $name} {Hello $name}\nMr. Smith",
96
+ "code": "$pattern {Mr. $name} {Hello $name}\nMr. Smith",
97
97
  "expected": "Hello Smith"
98
98
  },
99
99
  {
100
100
  "id": 17,
101
101
  "name": "Eval with division and decimals",
102
- "code": "pattern {div $a $b} {$eval{return $a / $b}}\ndiv 7 2",
102
+ "code": "$pattern {div $a $b} {$eval{return $a / $b}}\ndiv 7 2",
103
103
  "expected": "3.5"
104
104
  },
105
105
  {
106
106
  "id": 18,
107
107
  "name": "Block capturing with square brackets",
108
- "code": "pattern {$block arr {[}{]}} {ARRAY[$arr]}\n[1, 2, 3]",
108
+ "code": "$pattern {$block arr {[}{]}} {ARRAY[$arr]}\n[1, 2, 3]",
109
109
  "expected": "ARRAY[1, 2, 3]"
110
110
  },
111
111
  {
112
112
  "id": 19,
113
113
  "name": "Pattern without whitespace matching",
114
- "code": "pattern {$a,$b} {$b,$a} one,two",
114
+ "code": "$pattern {$a,$b} {$b,$a} one,two",
115
115
  "expected": "two,one"
116
116
  },
117
117
  {
118
118
  "id": 20,
119
119
  "name": "Nested pattern in replacement",
120
- "code": "pattern {$x} {->$x<-}\ntext",
120
+ "code": "$pattern {$x} {->$x<-}\ntext",
121
121
  "expected": "->text<-"
122
122
  },
123
123
  {
124
124
  "id": 21,
125
125
  "name": "First pattern applies, second doesn't match",
126
- "code": "pattern {hello} {goodbye}\npattern {goodbye} {hi}\nhello",
126
+ "code": "$pattern {hello} {goodbye}\n$pattern {goodbye} {hi}\nhello",
127
127
  "expected": "hi"
128
128
  },
129
129
  {
130
130
  "id": 22,
131
131
  "name": "Block delimiter balancing - parentheses",
132
- "code": "pattern {$block code {(}{)}} {RESULT[$code]}\n(a (b (c) d) e)",
132
+ "code": "$pattern {$block code {(}{)}} {RESULT[$code]}\n(a (b (c) d) e)",
133
133
  "expected": "RESULT[a (b (c) d) e]"
134
134
  },
135
135
  {
136
136
  "id": 23,
137
137
  "name": "Block delimiter balancing - angle brackets",
138
- "code": "pattern {$block inner {<}{>}} {X[$inner]}\n<outer <middle <deep>> more>",
138
+ "code": "$pattern {$block inner {<}{>}} {X[$inner]}\n<outer <middle <deep>> more>",
139
139
  "expected": "X[outer <middle <deep>> more]"
140
140
  },
141
141
  {
142
142
  "id": 24,
143
143
  "name": "Block delimiter balancing - square brackets",
144
- "code": "pattern {$block data {[}{]}} {DATA[$data]}\n[outer [inner [deep]] more]",
144
+ "code": "$pattern {$block data {[}{]}} {DATA[$data]}\n[outer [inner [deep]] more]",
145
145
  "expected": "DATA[outer [inner [deep]] more]"
146
146
  },
147
147
  {
148
148
  "id": 25,
149
149
  "name": "Block delimiter balancing - curly braces",
150
- "code": "pattern {$block obj {}{}} {OBJ[$obj]}\n{key: {nested: {value}}}",
150
+ "code": "$pattern {$block obj {}{}} {OBJ[$obj]}\n{key: {nested: {value}}}",
151
151
  "expected": "OBJ[key: {nested: {value}}]"
152
152
  },
153
153
  {
154
154
  "id": 26,
155
155
  "name": "Multiple nested delimiters in same pattern",
156
- "code": "pattern {$block a {(}{)} $block b {[}{]}} {[$a|$b]}\n(test1) [test2]",
156
+ "code": "$pattern {$block a {(}{)} $block b {[}{]}} {[$a|$b]}\n(test1) [test2]",
157
157
  "expected": "[test1|test2]"
158
158
  },
159
159
  {
160
160
  "id": 27,
161
161
  "name": "Simple pattern cascade",
162
- "code": "pattern {START $x END} {RESULT[$x]}\nSTART data END",
162
+ "code": "$pattern {START $x END} {RESULT[$x]}\nSTART data END",
163
163
  "expected": "RESULT[data]"
164
164
  },
165
165
  {
166
166
  "id": 28,
167
167
  "name": "Block with quotes as delimiters",
168
- "code": "pattern {$block str {\"}{\"}} {STRING[$str]}\n\"hello world\"",
168
+ "code": "$pattern {$block str {\"}{\"}} {STRING[$str]}\n\"hello world\"",
169
169
  "expected": "STRING[hello world]"
170
170
  },
171
171
  {
172
172
  "id": 29,
173
173
  "name": "Block with pipe delimiters",
174
- "code": "pattern {$block val {|}{|}} {PIPE[$val]}\n|content here|",
174
+ "code": "$pattern {$block val {|}{|}} {PIPE[$val]}\n|content here|",
175
175
  "expected": "PIPE[content here]"
176
176
  },
177
177
  {
178
178
  "id": 30,
179
179
  "name": "Deeply nested block delimiters",
180
- "code": "pattern {$block deep {<}{>}} {[$deep]}\n<a <b <c <d> c> b> a>",
180
+ "code": "$pattern {$block deep {<}{>}} {[$deep]}\n<a <b <c <d> c> b> a>",
181
181
  "expected": "[a <b <c <d> c> b> a]"
182
182
  },
183
183
  {
184
184
  "id": 31,
185
185
  "name": "Two sequential patterns",
186
- "code": "pattern {$block content {(}{)}} {BLOCK [$content]}\npattern {BLOCK $x} {RESULT: $x}\n(inner data)",
186
+ "code": "$pattern {$block content {(}{)}} {BLOCK [$content]}\n$pattern {BLOCK $x} {RESULT: $x}\n(inner data)",
187
187
  "expected": "RESULT: [inner data]"
188
188
  },
189
189
  {
190
190
  "id": 32,
191
191
  "name": "Multiple eval operations in sequence",
192
- "code": "pattern {calc $x} {$eval{return parseInt($x) * 2}}\ncalc 3",
192
+ "code": "$pattern {calc $x} {$eval{return parseInt($x) * 2}}\ncalc 3",
193
193
  "expected": "6"
194
194
  },
195
195
  {
196
196
  "id": 33,
197
197
  "name": "Block delimiter edge case - empty content",
198
- "code": "pattern {$block empty {(}{)}} {EMPTY[$empty]}\n()",
198
+ "code": "$pattern {$block empty {(}{)}} {EMPTY[$empty]}\n()",
199
199
  "expected": "EMPTY[]"
200
200
  },
201
201
  {
202
202
  "id": 34,
203
203
  "name": "Multi-char delimiters with nesting",
204
- "code": "pattern {$block code {<<}{>>}} {CODE[$code]}\n<<outer <<inner>> more>>",
204
+ "code": "$pattern {$block code {<<}{>>}} {CODE[$code]}\n<<outer <<inner>> more>>",
205
205
  "expected": "CODE[outer <<inner>> more]"
206
206
  },
207
207
  {
208
208
  "id": 35,
209
209
  "name": "Cascading pattern transformations",
210
- "code": "pattern {START $x END} {STEP1[$x]}\npattern {STEP1 $y} {STEP2[$y]}\npattern {STEP2 $z} {FINAL[$z]}\nSTART test END",
210
+ "code": "$pattern {START $x END} {STEP1[$x]}\n$pattern {STEP1 $y} {STEP2[$y]}\n$pattern {STEP2 $z} {FINAL[$z]}\nSTART test END",
211
211
  "expected": "FINAL[[[test]]]"
212
212
  }
213
213
  ]