将ABNF语法转换为Python正则表达式。
项目描述
程序abnf-to-regexp将增强Backus-Naur形式(ABNF)转换为正则表达式。
动机
对于许多字符串匹配问题,维护ABNF语法比维护正则表达式更容易。然而,许多编程语言的库中没有提供对ABNF的解析和匹配。这个工具允许您使用ABNF编写您的语法,并将其转换为正则表达式,然后将其包含在您的源代码中。
它基于abnf Python模块,该模块用于解析ABNF。
解析后,我们应用一系列优化来使正则表达式更易于阅读。例如,字符类的选择被合并成一个单一的字符类。
--帮助
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
示例转换
请参阅test_data/nested-python/rfc3987/grammar.abnf以获取示例语法。
相应的生成代码,例如,在Python中,存储在test_data/nested-python/rfc3987/expected.py。
安装
您可以在虚拟环境中使用pip安装此工具
pip3 install abnf-to-regexp
开发
查看仓库。
在存储库根目录下创建虚拟环境
python3 -m venv venv3
激活虚拟环境(在这种情况下,在Linux上)
source venv3/bin/activate
安装开发依赖项
pip3 install -e .[dev]
运行预提交检查
python precommit.py
版本管理
我们遵循语义版本控制。版本X.Y.Z表示
X是主版本(向下不兼容),
Y是次版本(向下兼容),
Z是修订版本(向下兼容的修复)。
项目详情
关闭
abnf-to-regexp-1.1.3.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 380a5f0fab52e6588446f6417419df90088eaffe1ce4267e829eb0d9168573de |
|
MD5 | 1cdc722bca4b05d907b5a9105ecc1461 |
|
BLAKE2b-256 | af392dd99d67cfcc7956847bb897872b7f2d1d73ffb0a1d3dc2867d0ecd5acf8 |