Skip to content
This repository was archived by the owner on Feb 14, 2024. It is now read-only.
/ php-fexpr Public archive

PHP library for parsing simple filter query language inspired by ganigeorgiev/fexpr.

License

Notifications You must be signed in to change notification settings

nemorize/php-fexpr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

php-fexpr

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);
}

About

PHP library for parsing simple filter query language inspired by ganigeorgiev/fexpr.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages