papagaio 0.2.4 → 0.2.7
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 +25 -15
- package/package.json +1 -1
- package/src/papagaio.js +263 -260
- package/tests/test.js +7 -5
- package/tests/tests.json +371 -71
package/tests/tests.json
CHANGED
|
@@ -4,415 +4,715 @@
|
|
|
4
4
|
"id": 1,
|
|
5
5
|
"name": "Basic pattern with 3 variables",
|
|
6
6
|
"code": "pattern {$x $y $z} {$z, $y, $x}\napple banana cherry",
|
|
7
|
-
"
|
|
7
|
+
"expected": "cherry, banana, apple"
|
|
8
8
|
},
|
|
9
9
|
{
|
|
10
10
|
"id": 2,
|
|
11
11
|
"name": "Flexible whitespace ($)",
|
|
12
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 delimiters ( )",
|
|
18
18
|
"code": "pattern {$block content {(}{)}} {[$content]}\ndata (hello world)",
|
|
19
|
-
"
|
|
19
|
+
"expected": "[hello world]"
|
|
20
20
|
},
|
|
21
21
|
{
|
|
22
22
|
"id": 4,
|
|
23
23
|
"name": "Multiple patterns - reorder",
|
|
24
24
|
"code": "pattern {$a $b} {$b:$a}\nfoo bar",
|
|
25
|
-
"
|
|
25
|
+
"expected": "bar:foo"
|
|
26
26
|
},
|
|
27
27
|
{
|
|
28
28
|
"id": 5,
|
|
29
29
|
"name": "Unique IDs incremental",
|
|
30
|
-
"code": "pattern {item} {item#$unique}
|
|
31
|
-
"
|
|
30
|
+
"code": "pattern {item} {item#$unique} item item item",
|
|
31
|
+
"expected": "item#0 item#1 item#2"
|
|
32
32
|
},
|
|
33
33
|
{
|
|
34
34
|
"id": 6,
|
|
35
35
|
"name": "Block with brackets [ ]",
|
|
36
36
|
"code": "pattern {$block arr {[}{]}} {ARRAY($arr)}\n[1, 2, 3]",
|
|
37
|
-
"
|
|
37
|
+
"expected": "ARRAY(1, 2, 3)"
|
|
38
38
|
},
|
|
39
39
|
{
|
|
40
40
|
"id": 7,
|
|
41
41
|
"name": "Pattern with special characters",
|
|
42
42
|
"code": "pattern {$a + $b} {$a PLUS $b}\n5 + 3",
|
|
43
|
-
"
|
|
43
|
+
"expected": "5 PLUS 3"
|
|
44
44
|
},
|
|
45
45
|
{
|
|
46
46
|
"id": 8,
|
|
47
47
|
"name": "Match with prefix and suffix",
|
|
48
48
|
"code": "pattern {Hello $name} {>> $name <<}\nHello Alice",
|
|
49
|
-
"
|
|
49
|
+
"expected": ">> Alice <<"
|
|
50
50
|
},
|
|
51
51
|
{
|
|
52
52
|
"id": 9,
|
|
53
53
|
"name": "Pattern repetition (global)",
|
|
54
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": "Block with parentheses ( )",
|
|
60
60
|
"code": "pattern {$block params {(}{)}} {FUNC[$params]}\ncalcular(a, b, c)",
|
|
61
|
-
"
|
|
61
|
+
"expected": "FUNC[a, b, c]"
|
|
62
62
|
},
|
|
63
63
|
{
|
|
64
64
|
"id": 11,
|
|
65
65
|
"name": "Pattern with $eval - arithmetic operation",
|
|
66
66
|
"code": "pattern {sum $a $b} {result: $eval{return $a + $b}}\nsum 10 20",
|
|
67
|
-
"
|
|
67
|
+
"expected": "result: 30"
|
|
68
68
|
},
|
|
69
69
|
{
|
|
70
70
|
"id": 12,
|
|
71
71
|
"name": "Nested block with multiple levels",
|
|
72
72
|
"code": "pattern {$block inner {<}{>}} {INNER{$inner}}\nouter <inner content here>",
|
|
73
|
-
"
|
|
73
|
+
"expected": "INNER{inner content here}"
|
|
74
74
|
},
|
|
75
75
|
{
|
|
76
76
|
"id": 13,
|
|
77
77
|
"name": "Pattern with flexible whitespace in middle",
|
|
78
78
|
"code": "pattern {from$$to} {path: from -> to}\nfrom to\nfrom to\nfrom to",
|
|
79
|
-
"
|
|
79
|
+
"expected": "path: from -> to"
|
|
80
80
|
},
|
|
81
81
|
{
|
|
82
82
|
"id": 14,
|
|
83
83
|
"name": "Multiple $unique in one pattern",
|
|
84
84
|
"code": "pattern {log $msg} {[$unique] LOG: $msg [$unique]}\nlog error",
|
|
85
|
-
"
|
|
85
|
+
"expected": "[0] LOG: error"
|
|
86
86
|
},
|
|
87
87
|
{
|
|
88
88
|
"id": 15,
|
|
89
89
|
"name": "Block with quotes as delimiter",
|
|
90
90
|
"code": "pattern {$block str {\"}{\"}} {STRING: $str}\n\"hello world\"",
|
|
91
|
-
"
|
|
91
|
+
"expected": "STRING: hello world"
|
|
92
92
|
},
|
|
93
93
|
{
|
|
94
94
|
"id": 16,
|
|
95
95
|
"name": "Pattern with 4+ variables",
|
|
96
96
|
"code": "pattern {$a $b $c $d $e} {$e-$d-$c-$b-$a}\n1 2 3 4 5",
|
|
97
|
-
"
|
|
97
|
+
"expected": "5-4-3-2-1"
|
|
98
98
|
},
|
|
99
99
|
{
|
|
100
100
|
"id": 17,
|
|
101
101
|
"name": "Block with empty delimiter (special)",
|
|
102
102
|
"code": "pattern {start $a middle $b end} {($a|$b)}\nstart foo middle bar end",
|
|
103
|
-
"
|
|
103
|
+
"expected": "(foo|bar)"
|
|
104
104
|
},
|
|
105
105
|
{
|
|
106
106
|
"id": 18,
|
|
107
107
|
"name": "Pattern generates HTML",
|
|
108
108
|
"code": "pattern {$tag $word} {<$tag>$word</$tag>}\ndiv Hello",
|
|
109
|
-
"
|
|
109
|
+
"expected": "<div>Hello</div>"
|
|
110
110
|
},
|
|
111
111
|
{
|
|
112
112
|
"id": 19,
|
|
113
113
|
"name": "Block with numeric delimiters",
|
|
114
114
|
"code": "pattern {$block data {<<}{>>}} {DATA[$data]}\n<<json: {x: 1}>>",
|
|
115
|
-
"
|
|
115
|
+
"expected": "DATA[json: {x: 1}]"
|
|
116
116
|
},
|
|
117
117
|
{
|
|
118
118
|
"id": 20,
|
|
119
119
|
"name": "Multiple sequential patterns complex",
|
|
120
120
|
"code": "pattern {Mr. $name} {Senhor $name}\npattern {Senhor $n} {Sir $n (formal)}\nMr. Smith",
|
|
121
|
-
"
|
|
121
|
+
"expected": "Sir Smith"
|
|
122
122
|
},
|
|
123
123
|
{
|
|
124
124
|
"id": 21,
|
|
125
125
|
"name": "Block with operator symbol",
|
|
126
126
|
"code": "pattern {$block op {**}{**}} {OPERATION: $op}\n**a + b + c**",
|
|
127
|
-
"
|
|
127
|
+
"expected": "OPERATION: a + b + c"
|
|
128
128
|
},
|
|
129
129
|
{
|
|
130
130
|
"id": 22,
|
|
131
131
|
"name": "Flexible whitespace with semicolon",
|
|
132
132
|
"code": "pattern {$$$a$$;$$$b$$} {$a AND $b}\nx ; y\nx; y\nx ; y",
|
|
133
|
-
"
|
|
133
|
+
"expected": "x AND y"
|
|
134
134
|
},
|
|
135
135
|
{
|
|
136
136
|
"id": 23,
|
|
137
137
|
"name": "Context with nested pattern",
|
|
138
138
|
"code": "context {\npattern {$x} {<$x>}\napple\nbanana\ncherry\n}",
|
|
139
|
-
"
|
|
139
|
+
"expected": "<apple>"
|
|
140
140
|
},
|
|
141
141
|
{
|
|
142
142
|
"id": 24,
|
|
143
143
|
"name": "Markdown bold to HTML",
|
|
144
144
|
"code": "pattern {**$text**} {<strong>$text</strong>}\nThis is **important** text",
|
|
145
|
-
"
|
|
145
|
+
"expected": "<strong>important</strong>"
|
|
146
146
|
},
|
|
147
147
|
{
|
|
148
148
|
"id": 25,
|
|
149
149
|
"name": "Markdown italic to HTML",
|
|
150
150
|
"code": "pattern {*$text*} {<em>$text</em>}\nThis is *italic* text",
|
|
151
|
-
"
|
|
151
|
+
"expected": "<em>italic</em>"
|
|
152
152
|
},
|
|
153
153
|
{
|
|
154
154
|
"id": 26,
|
|
155
155
|
"name": "Configuration key=value",
|
|
156
156
|
"code": "pattern {$key = $value} {const $key = '$value';}\nserver_host = localhost\ndb_port = 3000",
|
|
157
|
-
"
|
|
157
|
+
"expected": "const server_host = 'localhost';"
|
|
158
158
|
},
|
|
159
159
|
{
|
|
160
160
|
"id": 27,
|
|
161
161
|
"name": "Full name transformation",
|
|
162
162
|
"code": "pattern {$first $last} {{ name: '$last, $first' }}\nJohn Doe",
|
|
163
|
-
"
|
|
163
|
+
"expected": "{ name: 'Doe, John' }"
|
|
164
164
|
},
|
|
165
165
|
{
|
|
166
166
|
"id": 28,
|
|
167
167
|
"name": "CSV to JSON simple",
|
|
168
168
|
"code": "pattern {$a,$b,$c} {{ field1: '$a', field2: '$b', field3: '$c' }}\nAlice,30,Engineer",
|
|
169
|
-
"
|
|
169
|
+
"expected": "{ field1: 'Alice', field2: '30', field3: 'Engineer' }"
|
|
170
170
|
},
|
|
171
171
|
{
|
|
172
172
|
"id": 29,
|
|
173
173
|
"name": "Pattern with dictionary",
|
|
174
174
|
"code": "pattern {$a and $b} {$b and $a}\ncats and dogs",
|
|
175
|
-
"
|
|
175
|
+
"expected": "dogs and cats"
|
|
176
176
|
},
|
|
177
177
|
{
|
|
178
178
|
"id": 30,
|
|
179
179
|
"name": "Multiple patterns in cascade",
|
|
180
180
|
"code": "pattern {a} {b}\npattern {b} {c}\npattern {c} {d}\na",
|
|
181
|
-
"
|
|
181
|
+
"expected": "d"
|
|
182
182
|
},
|
|
183
183
|
{
|
|
184
184
|
"id": 31,
|
|
185
185
|
"name": "Block with empty delimiter (default)",
|
|
186
186
|
"code": "pattern {$block data {}{}} {DATA:$data}\ndata { hello world }",
|
|
187
|
-
"
|
|
187
|
+
"expected": "DATA: hello world"
|
|
188
188
|
},
|
|
189
189
|
{
|
|
190
190
|
"id": 32,
|
|
191
191
|
"name": "Pattern with special character dot",
|
|
192
192
|
"code": "pattern {$x.txt} {file: $x}\ndocument.txt",
|
|
193
|
-
"
|
|
193
|
+
"expected": "file: document"
|
|
194
194
|
},
|
|
195
195
|
{
|
|
196
196
|
"id": 33,
|
|
197
197
|
"name": "Block captures multiple nested levels",
|
|
198
198
|
"code": "pattern {$block inner {<}{>}} {INNER{$inner}}\nouter <middle <deep> more>",
|
|
199
|
-
"
|
|
199
|
+
"expected": "INNER{middle <deep> more}"
|
|
200
200
|
},
|
|
201
201
|
{
|
|
202
202
|
"id": 34,
|
|
203
203
|
"name": "Pattern with numbers and special chars",
|
|
204
204
|
"code": "pattern {$x + $y = $z} {$z is sum of $x and $y}\n5 + 3 = 8",
|
|
205
|
-
"
|
|
205
|
+
"expected": "8 is sum of 5 and 3"
|
|
206
206
|
},
|
|
207
207
|
{
|
|
208
208
|
"id": 35,
|
|
209
209
|
"name": "Empty context is removed",
|
|
210
210
|
"code": "Start\ncontext {\n \n}\nEnd",
|
|
211
|
-
"
|
|
211
|
+
"expected": "Start"
|
|
212
212
|
},
|
|
213
213
|
{
|
|
214
214
|
"id": 36,
|
|
215
215
|
"name": "Pattern HTML generator function",
|
|
216
216
|
"code": "pattern {$tag $content} {<$tag>$content</$tag>}\ndiv HelloWorld",
|
|
217
|
-
"
|
|
217
|
+
"expected": "<div>HelloWorld</div>"
|
|
218
218
|
},
|
|
219
219
|
{
|
|
220
220
|
"id": 37,
|
|
221
221
|
"name": "Block with multi-char delimiter",
|
|
222
222
|
"code": "pattern {$block code {<<}{>>}} {CODE[$code]}\n<<console.log('test')>>",
|
|
223
|
-
"
|
|
223
|
+
"expected": "CODE[console.log('test')]"
|
|
224
224
|
},
|
|
225
225
|
{
|
|
226
226
|
"id": 38,
|
|
227
227
|
"name": "Markdown list to HTML",
|
|
228
228
|
"code": "pattern {- $item} {<li>$item</li>}\n- Apple\n- Banana",
|
|
229
|
-
"
|
|
229
|
+
"expected": "<li>Apple</li>"
|
|
230
230
|
},
|
|
231
231
|
{
|
|
232
232
|
"id": 39,
|
|
233
233
|
"name": "Pattern with literal $ ($)",
|
|
234
234
|
"code": "pattern {price} {Price: $50}\nprice",
|
|
235
|
-
"
|
|
235
|
+
"expected": "Price: $50"
|
|
236
236
|
},
|
|
237
237
|
{
|
|
238
238
|
"id": 40,
|
|
239
239
|
"name": "Markdown heading h1",
|
|
240
240
|
"code": "pattern {# $title} {<h1>$title</h1>}\n# Welcome",
|
|
241
|
-
"
|
|
241
|
+
"expected": "<h1>Welcome</h1>"
|
|
242
242
|
},
|
|
243
243
|
{
|
|
244
244
|
"id": 41,
|
|
245
245
|
"name": "Markdown heading h2",
|
|
246
246
|
"code": "pattern {## $title} {<h2>$title</h2>}\n## Section",
|
|
247
|
-
"
|
|
247
|
+
"expected": "<h2>Section</h2>"
|
|
248
248
|
},
|
|
249
249
|
{
|
|
250
250
|
"id": 42,
|
|
251
251
|
"name": "Variables with underscore names",
|
|
252
252
|
"code": "pattern {$var_name $other_var} {$other_var:$var_name}\nfirst second",
|
|
253
|
-
"
|
|
253
|
+
"expected": "second:first"
|
|
254
254
|
},
|
|
255
255
|
{
|
|
256
256
|
"id": 43,
|
|
257
257
|
"name": "Pattern with variable reuse",
|
|
258
258
|
"code": "pattern {$x} {$x-$x-$x}\ndata",
|
|
259
|
-
"
|
|
259
|
+
"expected": "data-data-data"
|
|
260
260
|
},
|
|
261
261
|
{
|
|
262
262
|
"id": 44,
|
|
263
263
|
"name": "Block with double quotes",
|
|
264
264
|
"code": "pattern {$block str {\"}{\"}} {STR[$str]}\n\"hello\"",
|
|
265
|
-
"
|
|
265
|
+
"expected": "STR[hello]"
|
|
266
266
|
},
|
|
267
267
|
{
|
|
268
268
|
"id": 45,
|
|
269
269
|
"name": "Pattern with flexible space before and after",
|
|
270
270
|
"code": "pattern {$$hello$$} {FOUND}\n hello ",
|
|
271
|
-
"
|
|
271
|
+
"expected": "FOUND"
|
|
272
272
|
},
|
|
273
273
|
{
|
|
274
274
|
"id": 46,
|
|
275
275
|
"name": "Multiple blocks in one pattern",
|
|
276
276
|
"code": "pattern {$block a {(}{)}, $block b {[}{]}} {PAIR: $a and $b}\n(first), [second]",
|
|
277
|
-
"
|
|
277
|
+
"expected": "PAIR: first and second"
|
|
278
278
|
},
|
|
279
279
|
{
|
|
280
280
|
"id": 47,
|
|
281
281
|
"name": "Pattern with math symbols",
|
|
282
282
|
"code": "pattern {$x * $y} {multiplication: $x * $y}\n5 * 3",
|
|
283
|
-
"
|
|
283
|
+
"expected": "multiplication: 5 * 3"
|
|
284
284
|
},
|
|
285
285
|
{
|
|
286
286
|
"id": 48,
|
|
287
287
|
"name": "Eval with division and decimals",
|
|
288
288
|
"code": "pattern {div $a $b} {quotient: $eval{return $a / $b}}\ndiv 7 2",
|
|
289
|
-
"
|
|
289
|
+
"expected": "quotient: 3.5"
|
|
290
290
|
},
|
|
291
291
|
{
|
|
292
292
|
"id": 49,
|
|
293
293
|
"name": "Negative numbers in $eval",
|
|
294
294
|
"code": "pattern {calc $a $b} {result: $eval{return $a - $b}}\ncalc -5 -10",
|
|
295
|
-
"
|
|
295
|
+
"expected": "result: 5"
|
|
296
296
|
},
|
|
297
297
|
{
|
|
298
298
|
"id": 50,
|
|
299
299
|
"name": "Tabs as flexible whitespace",
|
|
300
300
|
"code": "pattern {from$$to} {path: from -> to}\nfrom\tto",
|
|
301
|
-
"
|
|
301
|
+
"expected": "path: from -> to"
|
|
302
302
|
},
|
|
303
303
|
{
|
|
304
304
|
"id": 51,
|
|
305
305
|
"name": "Unicode characters in variables",
|
|
306
306
|
"code": "pattern {greet $name} {Olá $name}\ngreet 世界",
|
|
307
|
-
"
|
|
307
|
+
"expected": "Olá 世界"
|
|
308
308
|
},
|
|
309
309
|
{
|
|
310
310
|
"id": 52,
|
|
311
311
|
"name": "Emoji support",
|
|
312
312
|
"code": "pattern {say $emoji} {You said: $emoji}\nsay 😊",
|
|
313
|
-
"
|
|
313
|
+
"expected": "You said: 😊"
|
|
314
314
|
},
|
|
315
315
|
{
|
|
316
316
|
"id": 53,
|
|
317
317
|
"name": "Trim multiple surrounding spaces",
|
|
318
318
|
"code": "pattern {$$$word$$} {FOUND: $word}\n word ",
|
|
319
|
-
"
|
|
319
|
+
"expected": "FOUND: word"
|
|
320
320
|
},
|
|
321
321
|
{
|
|
322
322
|
"id": 54,
|
|
323
323
|
"name": "No match leaves input intact",
|
|
324
324
|
"code": "pattern {nomatch $x} {X}\nnothing matches here",
|
|
325
|
-
"
|
|
325
|
+
"expected": "nothing matches here"
|
|
326
326
|
},
|
|
327
327
|
{
|
|
328
328
|
"id": 55,
|
|
329
329
|
"name": "Block captures first simple angle block",
|
|
330
330
|
"code": "pattern {$block txt {<}{>}} {CAP[$txt]}\nstart <one> middle <two> end",
|
|
331
|
-
"
|
|
331
|
+
"expected": "CAP[one]"
|
|
332
332
|
},
|
|
333
333
|
{
|
|
334
334
|
"id": 56,
|
|
335
335
|
"name": "Overlapping patterns cascade",
|
|
336
336
|
"code": "pattern {a} {A}\npattern {A} {B}\na",
|
|
337
|
-
"
|
|
337
|
+
"expected": "B"
|
|
338
338
|
},
|
|
339
339
|
{
|
|
340
340
|
"id": 57,
|
|
341
341
|
"name": "Literal dollar in replacement",
|
|
342
342
|
"code": "pattern {price} {Price: $50}\nprice",
|
|
343
|
-
"
|
|
343
|
+
"expected": "Price: $50"
|
|
344
344
|
},
|
|
345
345
|
{
|
|
346
346
|
"id": 58,
|
|
347
347
|
"name": "Simple Test",
|
|
348
348
|
"code": "pattern {$file.$ext} {file: $file}\nphoto.png",
|
|
349
|
-
"
|
|
349
|
+
"expected": "file: photo"
|
|
350
350
|
},
|
|
351
351
|
{
|
|
352
352
|
"id": 59,
|
|
353
353
|
"name": "Repeated global replacements",
|
|
354
354
|
"code": "pattern {x} {X}\nxxxxx",
|
|
355
|
-
"
|
|
355
|
+
"expected": "XXXXX"
|
|
356
356
|
},
|
|
357
357
|
{
|
|
358
358
|
"id": 60,
|
|
359
359
|
"name": "Context preserves inner pattern output",
|
|
360
360
|
"code": "context {\npattern {$x} {<$x>}\ninner\n}\ninner\nouter",
|
|
361
|
-
"
|
|
361
|
+
"expected": "<inner>"
|
|
362
362
|
},
|
|
363
363
|
{
|
|
364
364
|
"id": 61,
|
|
365
365
|
"name": "Block with pipe delimiters",
|
|
366
366
|
"code": "pattern {$block mid {|}{|}} {PIPE[$mid]}\n|a| and |b|",
|
|
367
|
-
"
|
|
367
|
+
"expected": "PIPE[a]"
|
|
368
368
|
},
|
|
369
369
|
{
|
|
370
370
|
"id": 62,
|
|
371
371
|
"name": "Trailing comma punctuation handling",
|
|
372
372
|
"code": "pattern {$w,} {$w!}\nhello,",
|
|
373
|
-
"
|
|
373
|
+
"expected": "hello!"
|
|
374
374
|
},
|
|
375
375
|
{
|
|
376
376
|
"id": 63,
|
|
377
377
|
"name": "Comma-separated two variables",
|
|
378
378
|
"code": "pattern {$a,$b} {[$a][$b]}\none,two",
|
|
379
|
-
"
|
|
379
|
+
"expected": "[one][two]"
|
|
380
380
|
},
|
|
381
381
|
{
|
|
382
382
|
"id": 64,
|
|
383
383
|
"name": "Apostrophe in pattern literal",
|
|
384
384
|
"code": "pattern {It's $name} {Hello $name}\nIt's John",
|
|
385
|
-
"
|
|
385
|
+
"expected": "Hello John"
|
|
386
386
|
},
|
|
387
387
|
{
|
|
388
388
|
"id": 65,
|
|
389
389
|
"name": "Arithmetic increment with large number",
|
|
390
390
|
"code": "pattern {num $a} {$eval{return parseInt($a) + 1}}\nnum 999",
|
|
391
|
-
"
|
|
391
|
+
"expected": "1000"
|
|
392
392
|
},
|
|
393
393
|
{
|
|
394
394
|
"id": 66,
|
|
395
395
|
"name": "Parentheses block capture with nesting",
|
|
396
396
|
"code": "pattern {$block txt {(}{)}} {B[$txt]}\n(a(b)c)",
|
|
397
|
-
"
|
|
397
|
+
"expected": "B[a(b)c]"
|
|
398
398
|
},
|
|
399
399
|
{
|
|
400
400
|
"id": 67,
|
|
401
401
|
"name": "Literal special regex characters in pattern",
|
|
402
402
|
"code": "pattern {a.*b} {PAT}\na.*b",
|
|
403
|
-
"
|
|
403
|
+
"expected": "PAT"
|
|
404
404
|
},
|
|
405
405
|
{
|
|
406
406
|
"id": 68,
|
|
407
|
-
"name": "Block with multi-character delimiters containing double quotes
|
|
407
|
+
"name": "(known issue) Block with multi-character delimiters containing double quotes",
|
|
408
408
|
"code": "pattern {$block str {\"k}{\"k}} {STR[$str]}\n\"khello\"k",
|
|
409
|
-
"
|
|
409
|
+
"expected": "STR[hello]"
|
|
410
410
|
},
|
|
411
411
|
{
|
|
412
412
|
"id": 69,
|
|
413
413
|
"name": "Block with multi-character delimiters",
|
|
414
414
|
"code": "pattern {$block str {open}{close}} {$str World!}\nopenHelloclose",
|
|
415
|
-
"
|
|
415
|
+
"expected": "Hello World!"
|
|
416
|
+
},
|
|
417
|
+
{
|
|
418
|
+
"id": 70,
|
|
419
|
+
"name": "Clear and keep",
|
|
420
|
+
"code": "pattern {SKIP $x} {$clear KEEP: $x} IGNORE_THIS SKIP keep_this",
|
|
421
|
+
"expected": "KEEP: keep_this"
|
|
422
|
+
},
|
|
423
|
+
{
|
|
424
|
+
"id": 71,
|
|
425
|
+
"name": "README: Simple Variables",
|
|
426
|
+
"code": "pattern {$x} {$x}\nhello",
|
|
427
|
+
"expected": "hello"
|
|
428
|
+
},
|
|
429
|
+
{
|
|
430
|
+
"id": 72,
|
|
431
|
+
"name": "README: Multiple Variables",
|
|
432
|
+
"code": "pattern {$x $y $z} {$z, $y, $x}\napple banana cherry",
|
|
433
|
+
"expected": "cherry, banana, apple"
|
|
434
|
+
},
|
|
435
|
+
{
|
|
436
|
+
"id": 73,
|
|
437
|
+
"name": "README: Flexible Whitespace",
|
|
438
|
+
"code": "pattern {$x$$and$$$y} {$x & $y}\nhello and world",
|
|
439
|
+
"expected": "hello & world"
|
|
440
|
+
},
|
|
441
|
+
{
|
|
442
|
+
"id": 74,
|
|
443
|
+
"name": "README: Flexible Whitespace (compact)",
|
|
444
|
+
"code": "pattern {$x$$and$$$y} {$x & $y}\nhello and world",
|
|
445
|
+
"expected": "hello & world"
|
|
446
|
+
},
|
|
447
|
+
{
|
|
448
|
+
"id": 75,
|
|
449
|
+
"name": "README: Block with parentheses",
|
|
450
|
+
"code": "pattern {$block content {(}{)}} {[$content]}\ndata ( hello world )",
|
|
451
|
+
"expected": "[hello world]"
|
|
452
|
+
},
|
|
453
|
+
{
|
|
454
|
+
"id": 76,
|
|
455
|
+
"name": "README: Block with custom delimiters <<>>",
|
|
456
|
+
"code": "pattern {$block data {<<}{>>}} {DATA: $data}\n<<json stuff>>",
|
|
457
|
+
"expected": "DATA: json stuff"
|
|
458
|
+
},
|
|
459
|
+
{
|
|
460
|
+
"id": 77,
|
|
461
|
+
"name": "README: Multiple Blocks in pattern",
|
|
462
|
+
"code": "pattern {$block a {(}{)}, $block b {[}{]}} {$a|$b}\n(first), [second]",
|
|
463
|
+
"expected": "first|second"
|
|
464
|
+
},
|
|
465
|
+
{
|
|
466
|
+
"id": 78,
|
|
467
|
+
"name": "README: Basic pattern with literals",
|
|
468
|
+
"code": "pattern {match} {replace}\nmatch",
|
|
469
|
+
"expected": "replace"
|
|
470
|
+
},
|
|
471
|
+
{
|
|
472
|
+
"id": 79,
|
|
473
|
+
"name": "README: Markdown heading example",
|
|
474
|
+
"code": "pattern {# $title} {<h1>$title</h1>}\n# Welcome",
|
|
475
|
+
"expected": "<h1>Welcome</h1>"
|
|
476
|
+
},
|
|
477
|
+
{
|
|
478
|
+
"id": 80,
|
|
479
|
+
"name": "README: Multiple patterns cascade",
|
|
480
|
+
"code": "pattern {a} {b}\npattern {b} {c}\npattern {c} {d}\na",
|
|
481
|
+
"expected": "d"
|
|
482
|
+
},
|
|
483
|
+
{
|
|
484
|
+
"id": 81,
|
|
485
|
+
"name": "README: Context basic",
|
|
486
|
+
"code": "context {\n pattern {$x} {<$x>}\n \n apple\n banana\n}",
|
|
487
|
+
"expected": "<apple>\n<banana>"
|
|
488
|
+
},
|
|
489
|
+
{
|
|
490
|
+
"id": 82,
|
|
491
|
+
"name": "README: $unique incremental",
|
|
492
|
+
"code": "pattern {item} {[$unique]item_$unique}\nitem\nitem\nitem",
|
|
493
|
+
"expected": "[0]item_0\n[1]item_1\n[2]item_2"
|
|
494
|
+
},
|
|
495
|
+
{
|
|
496
|
+
"id": 83,
|
|
497
|
+
"name": "README: $unique same ID in replacement",
|
|
498
|
+
"code": "pattern {a} {$unique $unique}\na",
|
|
499
|
+
"expected": "0 0"
|
|
500
|
+
},
|
|
501
|
+
{
|
|
502
|
+
"id": 84,
|
|
503
|
+
"name": "README: $match full match",
|
|
504
|
+
"code": "pattern {[$x]} {FOUND: $match}\n[data]",
|
|
505
|
+
"expected": "FOUND: [data]"
|
|
506
|
+
},
|
|
507
|
+
{
|
|
508
|
+
"id": 85,
|
|
509
|
+
"name": "README: $prefix e $suffix",
|
|
510
|
+
"code": "pattern {world} {$prefix$suffix}hello world test",
|
|
511
|
+
"expected": "hello hello test test"
|
|
512
|
+
},
|
|
513
|
+
{
|
|
514
|
+
"id": 86,
|
|
515
|
+
"name": "README: $clear remove before match",
|
|
516
|
+
"code": "pattern {SKIP $x} {$clear KEEP: $x}\nIGNORE_THIS SKIP keep_this",
|
|
517
|
+
"expected": "KEEP: keep_this"
|
|
518
|
+
},
|
|
519
|
+
{
|
|
520
|
+
"id": 87,
|
|
521
|
+
"name": "README: $eval arithmetic multiplication",
|
|
522
|
+
"code": "pattern {$x} {$eval{return parseInt($x) * 2;}}\n5",
|
|
523
|
+
"expected": "10"
|
|
524
|
+
},
|
|
525
|
+
{
|
|
526
|
+
"id": 88,
|
|
527
|
+
"name": "README: Markdown h1 and h2",
|
|
528
|
+
"code": "pattern {## $t} {<h2>$t</h2>}\npattern {# $t} {<h1>$t</h1>}\n# Title\n## Subtitle",
|
|
529
|
+
"expected": "<h1>Title</h1>\n<h2>Subtitle</h2>"
|
|
530
|
+
},
|
|
531
|
+
{
|
|
532
|
+
"id": 89,
|
|
533
|
+
"name": "README: Markdown bold and italic",
|
|
534
|
+
"code": "pattern {**$t**} {<strong>$t</strong>}\npattern {*$t*} {<em>$t</em>}\n**bold** and *italic*",
|
|
535
|
+
"expected": "<strong>bold</strong> and <em>italic</em>"
|
|
536
|
+
},
|
|
537
|
+
{
|
|
538
|
+
"id": 90,
|
|
539
|
+
"name": "README: Markdown list",
|
|
540
|
+
"code": "pattern {- $i} {<li>$i</li>}\n- item1\n- item2",
|
|
541
|
+
"expected": "<li>item1</li>\n<li>item2</li>"
|
|
542
|
+
},
|
|
543
|
+
{
|
|
544
|
+
"id": 91,
|
|
545
|
+
"name": "README: CSV to JSON",
|
|
546
|
+
"code": "pattern {$a,$b,$c} {{ id: '$a', name: '$b', role: '$c' }}\n1,Alice,Engineer\n2,Bob,Designer",
|
|
547
|
+
"expected": "{ id: '1', name: 'Alice', role: 'Engineer' }\n{ id: '2', name: 'Bob', role: 'Designer' }"
|
|
548
|
+
},
|
|
549
|
+
{
|
|
550
|
+
"id": 92,
|
|
551
|
+
"name": "README: Config parser",
|
|
552
|
+
"code": "pattern {$key = $value} {const $key = '$value';}\nhost = localhost\nport = 3000",
|
|
553
|
+
"expected": "const host = 'localhost';\nconst port = '3000';"
|
|
554
|
+
},
|
|
555
|
+
{
|
|
556
|
+
"id": 93,
|
|
557
|
+
"name": "README: HTML generator",
|
|
558
|
+
"code": "pattern {$tag $content} {<$tag>$content</$tag>}\ndiv HelloWorld\nspan Test",
|
|
559
|
+
"expected": "<div>HelloWorld</div>\n<span>Test</span>"
|
|
560
|
+
},
|
|
561
|
+
{
|
|
562
|
+
"id": 94,
|
|
563
|
+
"name": "BONUS: Variable reuse in replacement",
|
|
564
|
+
"code": "pattern {$x} {$x:$x:$x}\ndata",
|
|
565
|
+
"expected": "data:data:data"
|
|
566
|
+
},
|
|
567
|
+
{
|
|
568
|
+
"id": 95,
|
|
569
|
+
"name": "BONUS: Literal dollar sign in replacement",
|
|
570
|
+
"code": "pattern {price} {Price: $50}\nprice",
|
|
571
|
+
"expected": "Price: $50"
|
|
572
|
+
},
|
|
573
|
+
{
|
|
574
|
+
"id": 96,
|
|
575
|
+
"name": "BONUS: Block with angle brackets nesting",
|
|
576
|
+
"code": "pattern {$block content {<}{>}} {CONTENT:$content}\nouter <inner <deep> more>",
|
|
577
|
+
"expected": "CONTENT:inner <deep> more"
|
|
578
|
+
},
|
|
579
|
+
{
|
|
580
|
+
"id": 97,
|
|
581
|
+
"name": "BONUS: Pattern with special regex characters",
|
|
582
|
+
"code": "pattern {a.*b} {MATCHED}\na.*b",
|
|
583
|
+
"expected": "MATCHED"
|
|
584
|
+
},
|
|
585
|
+
{
|
|
586
|
+
"id": 98,
|
|
587
|
+
"name": "BONUS: Multiple $eval operations",
|
|
588
|
+
"code": "pattern {add $a $b} {$eval{return parseInt($a) + parseInt($b)}}\nadd 15 25",
|
|
589
|
+
"expected": "40"
|
|
590
|
+
},
|
|
591
|
+
{
|
|
592
|
+
"id": 99,
|
|
593
|
+
"name": "BONUS: $eval with division and decimals",
|
|
594
|
+
"code": "pattern {div $a $b} {$eval{return $a / $b}}\ndiv 7 2",
|
|
595
|
+
"expected": "3.5"
|
|
596
|
+
},
|
|
597
|
+
{
|
|
598
|
+
"id": 100,
|
|
599
|
+
"name": "BONUS: Unicode characters support",
|
|
600
|
+
"code": "pattern {oi $name} {Olá $name!}\noi Mundo",
|
|
601
|
+
"expected": "Olá Mundo!"
|
|
602
|
+
},
|
|
603
|
+
{
|
|
604
|
+
"id": 101,
|
|
605
|
+
"name": "BONUS: Emoji support",
|
|
606
|
+
"code": "pattern {react $emoji} {Você reagiu: $emoji}\nreact 😊",
|
|
607
|
+
"expected": "Você reagiu: 😊"
|
|
608
|
+
},
|
|
609
|
+
{
|
|
610
|
+
"id": 102,
|
|
611
|
+
"name": "BONUS: Tab as flexible whitespace",
|
|
612
|
+
"code": "pattern {from$$to} {path: from -> to}\nfrom\tto",
|
|
613
|
+
"expected": "path: from -> to"
|
|
614
|
+
},
|
|
615
|
+
{
|
|
616
|
+
"id": 103,
|
|
617
|
+
"name": "BONUS: No match leaves input intact",
|
|
618
|
+
"code": "pattern {nomatch $x} {REPLACED}\nnothing matches here",
|
|
619
|
+
"expected": "nothing matches here"
|
|
620
|
+
},
|
|
621
|
+
{
|
|
622
|
+
"id": 104,
|
|
623
|
+
"name": "BONUS: Empty context is removed",
|
|
624
|
+
"code": "Start\ncontext {}End",
|
|
625
|
+
"expected": "Start\nEnd"
|
|
626
|
+
},
|
|
627
|
+
{
|
|
628
|
+
"id": 105,
|
|
629
|
+
"name": "BONUS: Block with pipe delimiters",
|
|
630
|
+
"code": "pattern {$block content {|}{|}} {PIPE[$content]}\n|value|",
|
|
631
|
+
"expected": "PIPE[value]"
|
|
632
|
+
},
|
|
633
|
+
{
|
|
634
|
+
"id": 106,
|
|
635
|
+
"name": "BONUS: Block with double quotes delimiter",
|
|
636
|
+
"code": "pattern {$block str {\"}{\"}} {STR[$str]}\n\"hello world\"",
|
|
637
|
+
"expected": "STR[hello world]"
|
|
638
|
+
},
|
|
639
|
+
{
|
|
640
|
+
"id": 107,
|
|
641
|
+
"name": "BONUS: Comma-separated pattern matching",
|
|
642
|
+
"code": "pattern {$a,$b,$c} {[$a] [$b] [$c]}\none,two,three",
|
|
643
|
+
"expected": "[one] [two] [three]"
|
|
644
|
+
},
|
|
645
|
+
{
|
|
646
|
+
"id": 108,
|
|
647
|
+
"name": "BONUS: Apostrophe in pattern literal",
|
|
648
|
+
"code": "pattern {It's $name} {Hello $name}\nIt's John",
|
|
649
|
+
"expected": "Hello John"
|
|
650
|
+
},
|
|
651
|
+
{
|
|
652
|
+
"id": 109,
|
|
653
|
+
"name": "BONUS: Math operation with $eval",
|
|
654
|
+
"code": "pattern {num $a} {$eval{return parseInt($a) + 1}}\nnum 999",
|
|
655
|
+
"expected": "1000"
|
|
656
|
+
},
|
|
657
|
+
{
|
|
658
|
+
"id": 110,
|
|
659
|
+
"name": "BONUS: Multi-character block delimiters",
|
|
660
|
+
"code": "pattern {$block code {open}{close}} {CODE[$code]}\nopenFunction()close",
|
|
661
|
+
"expected": "CODE[Function()]"
|
|
662
|
+
},
|
|
663
|
+
{
|
|
664
|
+
"id": 111,
|
|
665
|
+
"name": "BONUS: Pattern with dot literal",
|
|
666
|
+
"code": "pattern {$file.txt} {File: $file}\ndocument.txt",
|
|
667
|
+
"expected": "File: document"
|
|
668
|
+
},
|
|
669
|
+
{
|
|
670
|
+
"id": 112,
|
|
671
|
+
"name": "BONUS: Repeated global pattern matching",
|
|
672
|
+
"code": "pattern {x} {X}\nxxxxx",
|
|
673
|
+
"expected": "XXXXX"
|
|
674
|
+
},
|
|
675
|
+
{
|
|
676
|
+
"id": 113,
|
|
677
|
+
"name": "BONUS: Overlapping patterns cascade",
|
|
678
|
+
"code": "pattern {a} {A}\npattern {A} {B}\npattern {B} {C}\na",
|
|
679
|
+
"expected": "C"
|
|
680
|
+
},
|
|
681
|
+
{
|
|
682
|
+
"id": 114,
|
|
683
|
+
"name": "BONUS: Context with nested patterns",
|
|
684
|
+
"code": "context {\n pattern {$x} {\n<$x>}\napple\nbanana\ncherry\n}",
|
|
685
|
+
"expected": "<apple>\n<banana>\n<cherry>"
|
|
686
|
+
},
|
|
687
|
+
{
|
|
688
|
+
"id": 115,
|
|
689
|
+
"name": "BONUS: $eval with subtraction (negatives)",
|
|
690
|
+
"code": "pattern {calc $a $b} {$eval{return $a - $b}}\ncalc -5 -10",
|
|
691
|
+
"expected": "5"
|
|
692
|
+
},
|
|
693
|
+
{
|
|
694
|
+
"id": 116,
|
|
695
|
+
"name": "BONUS: Multiple spaces trim with flexible whitespace",
|
|
696
|
+
"code": "pattern {$$$word$$} {FOUND: $word}\n word ",
|
|
697
|
+
"expected": "FOUND: word"
|
|
698
|
+
},
|
|
699
|
+
{
|
|
700
|
+
"id": 117,
|
|
701
|
+
"name": "BONUS: Block captures parentheses with nesting",
|
|
702
|
+
"code": "pattern {$block content {(}{)}} {B[$content]}\n(a(b)c)",
|
|
703
|
+
"expected": "B[a(b)c]"
|
|
704
|
+
},
|
|
705
|
+
{
|
|
706
|
+
"id": 118,
|
|
707
|
+
"name": "BONUS: Arithmetic in config pattern",
|
|
708
|
+
"code": "pattern {$x + $y = $z} {$z is sum of $x and $y}\n5 + 3 = 8",
|
|
709
|
+
"expected": "8 is sum of 5 and 3"
|
|
710
|
+
},
|
|
711
|
+
{
|
|
712
|
+
"id": 119,
|
|
713
|
+
"name": "BONUS: Trailing punctuation in pattern",
|
|
714
|
+
"code": "pattern {$w,} {$w!}\nhello,",
|
|
715
|
+
"expected": "hello!"
|
|
416
716
|
}
|
|
417
717
|
]
|
|
418
718
|
}
|