papagaio 0.2.3 → 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 CHANGED
@@ -13,10 +13,15 @@ const result = p.process(input);
13
13
  ## Configuration
14
14
 
15
15
  ```javascript
16
- p.open = "{"; // opening delimiter
17
- p.close = "}"; // closing delimiter
18
- p.sigil = "$"; // variable marker
19
- p.maxRecursion = 512; // iteration limit
16
+ p.symbols = {
17
+ pattern: "pattern", // pattern keyword
18
+ context: "context", // context keyword
19
+ open: "{", // opening delimiter
20
+ close: "}", // closing delimiter
21
+ sigil: "$" // variable marker
22
+ };
23
+ p.recursion_limit = 512; // iteration limit
24
+ p.unique_id = 0; // unique ID counter
20
25
  ```
21
26
 
22
27
  ---
@@ -52,17 +57,6 @@ Output: `hello & world` (both)
52
57
 
53
58
  `$$` = zero or more spaces/tabs/newlines.
54
59
 
55
- ### 4. Literal Output (`$$`)
56
-
57
- ```
58
- Price: $$50
59
- ```
60
- Output: `Price: $50`
61
-
62
- Use `$$` for literal `$` output.
63
-
64
- ---
65
-
66
60
  ## Blocks
67
61
 
68
62
  Capture content between delimiters.
@@ -76,8 +70,8 @@ $block name {open}{close}
76
70
  ### Example
77
71
 
78
72
  ```
79
- pattern {$block content {(}{)}} {[$content]}
80
- data ( hello world )
73
+ pattern {$name $block content {(}{)}} {[$content]}
74
+ data (hello world)
81
75
  ```
82
76
  Output: `[hello world]`
83
77
 
@@ -152,15 +146,21 @@ Output:
152
146
  ## Special Keywords
153
147
 
154
148
  ### $unique
155
- Generate unique incremental IDs.
149
+ Generate unique incremental IDs for each pattern call. All occurrences of `$unique` within the same pattern replacement share the same ID.
156
150
 
157
151
  ```
158
- pattern {item} {item_$unique}
152
+ pattern {item} {[$unique]item_$unique}
159
153
  item
160
154
  item
161
155
  item
162
156
  ```
163
- Output: `item_u0`, `item_u1`, `item_u2`
157
+ Output: `[0]item_0`, `[1]item_1`, `[2]item_2`
158
+
159
+ ```
160
+ pattern {a} {$unique $unique}
161
+ a
162
+ ```
163
+ Output: `0 0` (same ID for both occurrences)
164
164
 
165
165
  ### $match
166
166
  Return the full match.
@@ -175,10 +175,9 @@ Output: `FOUND: [data]`
175
175
  Text before and after the match.
176
176
 
177
177
  ```
178
- pattern {$x} {BEFORE:$prefix | AFTER:$suffix}
179
- hello world test
178
+ pattern {world} {$prefix$suffix}hello world test
180
179
  ```
181
- Output: `BEFORE: | AFTER: world test`
180
+ Output: `hello hello test test`
182
181
 
183
182
  ### $clear
184
183
  Remove everything before the match.
@@ -206,8 +205,8 @@ Output: `10`
206
205
 
207
206
  ```
208
207
  context {
209
- pattern {# $t} {<h1>$t</h1>}
210
208
  pattern {## $t} {<h2>$t</h2>}
209
+ pattern {# $t} {<h1>$t</h1>}
211
210
  pattern {**$t**} {<strong>$t</strong>}
212
211
  pattern {*$t*} {<em>$t</em>}
213
212
  pattern {- $i} {<li>$i</li>}
@@ -281,6 +280,9 @@ Output:
281
280
  - Reuse: `$x` appears multiple times in replace
282
281
  - Undefined: becomes empty string
283
282
 
283
+ ### Sigil
284
+ - You cannot match words containing the sigil character.
285
+
284
286
  ---
285
287
 
286
288
  ## Troubleshooting
@@ -290,29 +292,23 @@ Output:
290
292
  | Pattern doesn't match | Use `$$` between elements for flexible whitespace |
291
293
  | Variable not captured | Check space between variables |
292
294
  | Block not working | Verify balanced delimiters `{` `}` |
293
- | Infinite recursion | Use `$clear` or reduce `maxRecursion` |
295
+ | Infinite recursion | Use `$clear` or reduce `recursion_limit` |
294
296
  | $eval not working | Errors return empty string, use try-catch |
295
297
 
296
- ---
297
-
298
- ## Performance
298
+ ## Known Bugs
299
299
 
300
- - Simple patterns > complex patterns
301
- - Blocks have minor overhead
302
- - Avoid unlimited recursion
303
- - For large inputs, use multiple contexts
300
+ - Multi-character block delimiters that contains double quotes doesnt match properly.
304
301
 
305
302
  ---
306
303
 
307
304
  ## Syntax Reference
308
305
 
309
306
  ```
310
- pattern {$x $y} {$y, $x} # basic pattern
311
- pattern {$x$$y} {$x-$y} # flexible whitespace
312
- pattern {$block n {o}{c}} {$n} # block
307
+ pattern {$x $y} {$y, $x} # basic pattern
308
+ pattern {$x$$y} {$x-$y} # flexible whitespace
309
+ pattern {$block n {o}{c}} {$n} # block
313
310
  context { ... } # recursive scope
314
- $$literal # output literal $
315
- $unique # unique ID
311
+ $unique # unique ID per pattern
316
312
  $match # full match
317
313
  $prefix / $suffix # before/after
318
314
  $clear # clear before
@@ -327,7 +323,6 @@ $eval{code} # execute JS
327
323
  context {
328
324
  # Markdown headers
329
325
  pattern {# $title} {<h1>$title</h1>}
330
- pattern {## $title} {<h2>$title</h2>}
331
326
 
332
327
  # Lists
333
328
  pattern {- $item} {<li>$item</li>}
@@ -338,7 +333,7 @@ context {
338
333
 
339
334
  # Process content
340
335
  # Welcome
341
- ## Getting Started
336
+ # Getting Started
342
337
  This is **important** and *italic*
343
338
  - First item
344
339
  - Second item
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "papagaio",
3
- "version": "0.2.3",
3
+ "version": "0.2.7",
4
4
  "description": "easy yet powerful preprocessor",
5
5
  "main": "src/papagaio.js",
6
6
  "type": "module",