Metadata-Version: 2.4
Name: rector
Version: 0.1.6
Summary: Regex generator that derives optimized patterns from example strings.
Project-URL: Homepage, https://github.com/yaccob/rector
Project-URL: Issues, https://github.com/yaccob/rector/issues
Author: yaccob
License: MIT License
        
        Copyright (c) 2024 yaccob
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: bdd,generator,pattern,pytest-bdd,regex,regular expressions
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Software Development :: Testing
Requires-Python: >=3.10
Provides-Extra: dev
Requires-Dist: black>=23.9; extra == 'dev'
Requires-Dist: build>=1.0; extra == 'dev'
Requires-Dist: coverage>=7.3; extra == 'dev'
Requires-Dist: hatch>=1.9; extra == 'dev'
Requires-Dist: pytest-bdd>=6.1; extra == 'dev'
Requires-Dist: pytest>=7.4; extra == 'dev'
Requires-Dist: ruff>=0.1.6; extra == 'dev'
Requires-Dist: tomli>=2.0; (python_version < '3.11') and extra == 'dev'
Requires-Dist: twine>=4.0; extra == 'dev'
Description-Content-Type: text/markdown

# rector — Regex Generator

Rector turns example strings into optimized regular expressions you can reuse in search, validation, or routing rules. It ships with a trie-based engine that produces compact, deterministic patterns (also used by the CLI).

## Installation
```bash
pip install rector
```

## Library usage
```python
from rector import TrieRegexGenerator

# Build a minimal trie-based pattern for larger sets or ranges
numbers = TrieRegexGenerator().generate([str(n) for n in range(10, 1000)])
assert numbers.pattern == "^[1-9][0-9]{1,2}$"

# Generate from small fixed-length samples
words = TrieRegexGenerator().generate(["cat", "car", "cap"])
assert words.pattern == r"^ca[prt]$"
```

## CLI
Pipe examples to `rector` and it prints the generated pattern to stdout:
```bash
printf "cat\ncar\ncap\n" | rector
# -> ^ca[prt]$
```
The CLI anchors patterns by default and exits with status 1 if no stdin input is provided.
Use `--dense-threshold` to adjust when near-contiguous character sets are collapsed into ranges
(accepts `fractions.Fraction` strings like `3/4` or `0.6`; default when flag is present without a value:
`8/10`).

## Behavior notes
- Patterns anchor to start/end unless you pass `anchor_start=False` or `anchor_end=False`.
- Examples must be strings; `TrieRegexGenerator` raises `TypeError` otherwise.
- `TrieRegexGenerator` builds a trie, minimizes it, and compacts ranges/quantifiers (using the density threshold for near-contiguous classes); it also accepts empty lines as valid examples.
