diff options
| author | 夏音 / natsuoto.exe <[email protected]> | 2026-07-01 16:21:15 +0530 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-07-01 16:21:15 +0530 |
| commit | e859ce24e5ffc95653023669f9edf4d3a0344a8e (patch) | |
| tree | ea2d0971292c1a70737f1f068ec27d308974b88f /tests/pattern/classes.test.py | |
| parent | 42509f3a1d0c93c5fd43b2e2bdc42201d24a643e (diff) | |
| parent | 1860f7396e997c785d2299c421852909a0ee2070 (diff) | |
| download | edify-e859ce24e5ffc95653023669f9edf4d3a0344a8e.tar.xz edify-e859ce24e5ffc95653023669f9edf4d3a0344a8e.zip | |
feat: varargs .one_of() and .any_of(*literals) chain-level shorthand (#266)
Adds a varargs shorthand for literal alternation on both fluent surfaces
(`RegexBuilder` and `Pattern`):
- **`.any_of(*literals: str)`** — dual-mode overload. Zero args keeps
the existing frame-opener behavior
(`.any_of().string("cat").string("dog").end()`). One or more string args
skips the frame dance and appends the alternation directly.
- **`.one_of(*literals: str)`** — new method, always the varargs form.
Requires at least one literal (raises `MustBeAtLeastOneLiteralError` on
zero).
Literals go through the same escape + `CharElement`/`StringElement`
branching that `.char()` / `.string()` use, so the compile-path fusion
into `[...]` for single-character sets still applies:
```python
RegexBuilder().any_of("+", "-").to_regex_string() # [\+\-]
RegexBuilder().one_of("cat", "dog", "fish").to_regex_string() # (?:cat|dog|fish)
```
The pre-existing top-level factory `any_of(*operands: Pattern)` from
#263 stays untouched — it takes `Pattern` operands, not literal strings,
and serves the compositional (humre-style) API rather than the
chain-level shorthand this PR delivers.
Closes #131
Diffstat (limited to 'tests/pattern/classes.test.py')
0 files changed, 0 insertions, 0 deletions
