papagaio 0.5.0 → 0.6.1
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 +309 -95
- package/bin/cli.qjs +1 -1
- package/examples/simple.html +2 -2
- package/examples/wasm.papagaio +70 -0
- package/index.html +12 -3
- package/package.json +7 -3
- package/src/papagaio-bootstrap.mjs +3 -5
- package/src/papagaio.js +169 -243
- package/tests/tests.json +37 -37
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
|
-
"name": "Flexible whitespace with
|
|
12
|
-
"code": "pattern {
|
|
11
|
+
"name": "Flexible whitespace with $",
|
|
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}\
|
|
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
|
-
"name": "Optional whitespace with
|
|
84
|
-
"code": "pattern {hello
|
|
83
|
+
"name": "Optional whitespace with $ optional",
|
|
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 {
|
|
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}\
|
|
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]}\
|
|
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]}\
|
|
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
|
]
|