nemorize / fexpr
This package is abandoned and no longer maintained.
No replacement package was suggested.
Simple filter query language parser (originally written in go by ganigeorgiev/fexpr)
0.0.2
2023-07-16 03:44 UTC
Requires
- php: >=8.1
Requires (Dev)
- phpunit/phpunit: ^10.2
README
php-fexpr is a PHP-ported version of ganigeorgiev/fexpr that allows you to parse a filter query language and provides easy to work with AST structures.
Supports parenthesis and various conditional expression operators (see original project's Grammar)
Example usage
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" // } // } // } // ]
Using only the scanner
The tokenizer (aka. \Nemorize\Fexpr\Scanner
) could be used without the parser\s state machine
so that you can write your own custom tokens processing:
$scanner = new \Nemorize\Fexpr\Scanner(); foreach ($scanner->scan('id > 123') as $token) { var_dump($token); }