abnf-to-regexp
The program abnf-to-regexp converts augmented Backus-Naur form (ABNF) to a regular expression.
Motivation
For a lot of string matching problems, it is easier to maintain an ABNF grammar instead of a regular expression. However, many programming languages do not provide parsing and matching of ABNFs in their standard libraries. This tool allows you to write your grammars in ABNF and convert it to a regular expression which you then include in your source code.
It is based on abnf Python module, which is used to parse the ABNFs.
After the parsing, we apply a series of optimizations to make the regular expression a bit more readable. For example, the alternations of character classes are taken together to form a single character class.
--help
usage: abnf-to-regexp [-h] -i INPUT [-o OUTPUT]
[--format {single-regexp,python-nested}]
Convert ABNF grammars to Python regular expressions.
optional arguments:
-h, --help show this help message and exit
-i INPUT, --input INPUT
path to the ABNF file
-o OUTPUT, --output OUTPUT
path to the file where regular expression is stored;
if not specified, writes to STDOUT
--format {single-regexp,python-nested}
Output format; for example a single regular expression
or a code snippet
Example Conversion
Please see test_data/nested-python/rfc3987/grammar.abnf for an example grammar.
The corresponding generated code, e.g., in Python, is stored at test_data/nested-python/rfc3987/expected.py.
Installation
You can install the tool with pip in your virtual environment:
pip3 install abnf-to-regexp
Development
Check out the repository.
In the repository root, create the virtual environment:
python3 -m venv venv3
Activate the virtual environment (in this case, on Linux):
source venv3/bin/activate
Install the development dependencies:
pip3 install -e .[dev]
Run the pre-commit checks:
python continuous_integration/precommit.py
Versioning
We follow Semantic Versioning. The version X.Y.Z indicates:
X is the major version (backward-incompatible),
Y is the minor version (backward-compatible), and
Z is the patch version (backward-compatible bug fix).
Metadata
Release files for abnf-to-regexp 1.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| abnf_to_regexp-1.2.0.tar.gz | 25.9 kB | Without provenance | Details for abnf_to_regexp-1.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| abnf_to_regexp-1.2.0-py3-none-any.whl | Python 3 | none | any | Details for abnf_to_regexp-1.2.0-py3-none-any.whl |
Total release size: 50.3 kB
Release files / abnf_to_regexp-1.2.0.tar.gz
| Download URL | abnf_to_regexp-1.2.0.tar.gz |
|---|---|
| Size | 25.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c3b51771e8015adeedfcd15857ee2a9a4d0595355b672571ab1b0f2adb535a0a
|
|
BLAKE2b-256 checksum How to use checksums |
02236f3e11413bfac92688555c972a008f04cbc86b5e2e1a74649c919f2999a6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.0
|
Release files / abnf_to_regexp-1.2.0-py3-none-any.whl
| Download URL | abnf_to_regexp-1.2.0-py3-none-any.whl |
|---|---|
| Size | 24.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
63d330ebe080d4e68c252033449b0ea03be35847abf8fb17f52cd9afbed25b4d
|
|
BLAKE2b-256 checksum How to use checksums |
6f8eca543f8ba7b89a632f059c19fdbcb24a640847b3603856f0cce2de45da91
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.0
|
Security for abnf-to-regexp 1.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.