vanderlee /comprehend
构建 BNF LR(1) 解析器的框架
1.0.2
2018-10-02 22:17 UTC
Requires
- php: >=7.0.0
Requires (Dev)
- codacy/coverage: dev-master
- phpmd/phpmd: 2.6.0
- phpunit/phpunit: 6.*
This package is auto-updated.
Last update: 2024-09-11 11:33:57 UTC
README
在 PHP 中使用基于 BNF 的语法构建面向对象的 LR(1) 词法分析器、标记化和解析器。
版权所有 © 2011-2024 Martijn W. van der Lee Toyls.com,适用 MIT 许可证。
特性
- 紧密遵循 BNF 语法,使用对象作为操作数。
- 包含各种预定义的 RFC 语法规则。
- 跳过空白。
- 支持标记化。
- 添加您自己的自定义解析器。
- 创建完整的规则集。
- 可选的大小写(不)敏感。
示例
ABNF
word = [A-Za-z]+
list = word *[ ',' word ]
Comprehend,使用对象
$word = new Repeat(new Regex('/[a-z][A-Z]/'), 1);
$list = new Sequence($word, new Repeat(new Sequence(',', $word)));
Comprehend,使用对象和数组表示法
$word = new Repeat(new Regex('/[a-z][A-Z]/'), 1);
$list = new Sequence($word, new Repeat([',', $word]));
Comprehend,使用库函数
$word = plus(regex('/[a-z][A-Z]/'));
$list = s($word, star([',', $word]));
Comprehend,使用规则集构造函数
$list = new Ruleset([
'word' => plus(regex('/[a-z][A-Z]/')),
Ruleset::ROOT => s($word, star([',', $word])),
]);