nemorize / fexpr
此包已被废弃,不再维护。未建议替代包。
简单的过滤查询语言解析器(最初由 ganigeorgiev/fexpr 以 go 语言编写)
0.0.2
2023-07-16 03:44 UTC
Requires
- php: >=8.1
Requires (Dev)
- phpunit/phpunit: ^10.2
README
php-fexpr 是 ganigeorgiev/fexpr 的 PHP 版本,允许您解析过滤查询语言并提供易于工作的抽象语法树(AST)结构。
支持括号和各种条件表达式运算符(参见原始项目的语法)
示例用法
composer require nemorize/fexpr
$ast = (new \Nemorize\Fexpr\Parser())->parse('id = 123 && status = "active"'); // json_encode($ast): [ // { // "operation": { // "type": "join", // "literal": "&&" // }, // "item": { // "left": { // "type": "identifier", // "literal": "id" // }, // "operation": { // "type": "sign", // "literal": "=", // }, // "right": { // "type": "number", // "literal": "123" // } // } // }, // { // "operation": { // "type": "join", // "literal": "&&" // }, // "item": { // "left": { // "type": "identifier", // "literal": "status" // }, // "operation": { // "type": "sign", // "literal": "=", // }, // "right": { // "type": "string", // "literal": "active" // } // } // } // ]
仅使用扫描器
标记化程序(又称 \Nemorize\Fexpr\Scanner
)可以不使用解析器状态机来使用,这样您可以编写自己的自定义标记处理
$scanner = new \Nemorize\Fexpr\Scanner(); foreach ($scanner->scan('id > 123') as $token) { var_dump($token); }