papagaio 0.39.2 → 0.41.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.
- package/README.md +50 -1
- package/dist/wasm/papagaio_wasm.js +0 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -36,7 +36,6 @@ Patterns are composed of whitespace-separated tokens. The engine uses a "flex-ma
|
|
|
36
36
|
- **Literal**: Matches exact text.
|
|
37
37
|
- **Variable**: `$name` (captures a sequence up to the next pattern match).
|
|
38
38
|
- **Optional**: `$name?` or `literal?` (marker is configurable, e.g., `MAYBE`, via `$changesymbols`).
|
|
39
|
-
- **Escaping**: Use `$$` to match a literal `$`.
|
|
40
39
|
|
|
41
40
|
### Modifiers
|
|
42
41
|
Modifiers specify the data type or constraints of a match:
|
|
@@ -147,6 +146,56 @@ This changes the sigil to `@`, delimiters to `< >`, and the optional marker to `
|
|
|
147
146
|
|
|
148
147
|
---
|
|
149
148
|
|
|
149
|
+
## Dynamic Built-in Operators
|
|
150
|
+
|
|
151
|
+
Papagaio provides several built-in operators that give you access to the engine's internal syntax configuration and allow you to precisely inject unrepresentable characters (such as whitespace and binary ASCII) directly into patterns or output text.
|
|
152
|
+
|
|
153
|
+
> [!NOTE]
|
|
154
|
+
> All built-in operators support the **trailing sigil** syntax (e.g., `$sigil$`). This allows the operator to immediately consume all following whitespace or safely concatenate with adjacent alphanumeric text, exactly like standard variables.
|
|
155
|
+
|
|
156
|
+
### Reserved Symbol Emitters
|
|
157
|
+
When generating macros or writing complex rules, you may need to emit a literal sigil without it being evaluated. Instead of complex double-escaping, you can use:
|
|
158
|
+
- **`$sigil`**: Emits the current sigil (e.g., `$`)
|
|
159
|
+
- **`$open`**: Emits the current open delimiter (e.g., `{`)
|
|
160
|
+
- **`$close`**: Emits the current close delimiter (e.g., `}`)
|
|
161
|
+
- **`$marker`**: Emits the current optional marker (e.g., `?`)
|
|
162
|
+
|
|
163
|
+
**Solving the Infinite Interpretation Problem:**
|
|
164
|
+
```text
|
|
165
|
+
$pattern {hello} {world $sigil$A$sigil$from{X}}
|
|
166
|
+
hello
|
|
167
|
+
```
|
|
168
|
+
*Output: `world $A$from{X}`* — Since `$sigil` is processed during the single initial pass, it emits a literal `$` that safely bypasses any subsequent evaluation.
|
|
169
|
+
|
|
170
|
+
### Formatting and Binary Control
|
|
171
|
+
For precise layout control, especially inside flex-matched `$pattern` rules that normally skip extra whitespace:
|
|
172
|
+
- **`$space`**: Emits a literal space character (`' '`)
|
|
173
|
+
- **`$newline`**: Emits a literal newline (`\n`)
|
|
174
|
+
- **`$tab`**: Emits a literal tab character (`\t`)
|
|
175
|
+
|
|
176
|
+
To generate specific binary characters (such as null bytes) or handle complex ASCII injection:
|
|
177
|
+
- **`$ascii$code`** (Inline): E.g., `$ascii$65` outputs `A`
|
|
178
|
+
- **`$ascii{code}`** (Block): E.g., `$ascii{0}` outputs a binary null byte (`\0`)
|
|
179
|
+
|
|
180
|
+
### Mathematical Evaluation
|
|
181
|
+
The **`$math{...}`** operator allows native numerical processing and comparison directly on the preprocessor pipeline. Powered internally by `tinyexpr`, it supports floating point arithmetic, trigonometric functions, exponents, and logical evaluations. The mathematical string is processed recursively by Papagaio before being evaluated, meaning you can easily inject your workflow variables.
|
|
182
|
+
|
|
183
|
+
```text
|
|
184
|
+
$X$from{5.5}
|
|
185
|
+
$Y$from{4.5}
|
|
186
|
+
$math{sqrt($X^2 + $Y^2 - 0.5)}
|
|
187
|
+
```
|
|
188
|
+
*Output: `7.07107`*
|
|
189
|
+
|
|
190
|
+
**Comparisons and Logic Gates**
|
|
191
|
+
Since comparison operators (`<`, `>`, `==`, `!=`) evaluate to `1` (true) or `0` (false), `$math` is perfect for chained conditionals when paired with Papagaio's flow controllers:
|
|
192
|
+
```text
|
|
193
|
+
$math{10 > 5}$compare{1}$then{ Math confirms 10 is greater than 5! }
|
|
194
|
+
```
|
|
195
|
+
*(Note: If the expression contains syntax errors like `$math{5 + *}`, the operator fails silently and emits an empty string to maintain engine stability).*
|
|
196
|
+
|
|
197
|
+
---
|
|
198
|
+
|
|
150
199
|
## Recursive Priority System
|
|
151
200
|
|
|
152
201
|
Papagaio allows you to control the order of execution and side-effects (such as pattern definitions) using the **`$priority$N`** directive.
|
|
Binary file
|