{"id":19665917,"url":"https://github.com/amphp/parser","last_synced_at":"2025-05-16T12:10:51.928Z","repository":{"id":56947329,"uuid":"93432167","full_name":"amphp/parser","owner":"amphp","description":"A generator parser to make streaming parsers simple.","archived":false,"fork":false,"pushed_at":"2024-03-21T19:18:20.000Z","size":45,"stargazers_count":135,"open_issues_count":1,"forks_count":4,"subscribers_count":7,"default_branch":"1.x","last_synced_at":"2025-05-09T23:19:38.410Z","etag":null,"topics":["parser","php","stream"],"latest_commit_sha":null,"homepage":"https://amphp.org/parser","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/amphp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-06-05T17:59:24.000Z","updated_at":"2025-05-06T08:31:31.000Z","dependencies_parsed_at":"2024-06-18T13:43:19.015Z","dependency_job_id":"29b6cb06-2b94-4a52-ab7b-cab152b85b11","html_url":"https://github.com/amphp/parser","commit_stats":{"total_commits":43,"total_committers":3,"mean_commits":"14.333333333333334","dds":"0.32558139534883723","last_synced_commit":"ff1de4144726c5dad5fab97f66692ebe8de3e151"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amphp%2Fparser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amphp%2Fparser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amphp%2Fparser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amphp%2Fparser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/amphp","download_url":"https://codeload.github.com/amphp/parser/tar.gz/refs/heads/1.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254527099,"owners_count":22085919,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["parser","php","stream"],"created_at":"2024-11-11T16:25:27.688Z","updated_at":"2025-05-16T12:10:51.869Z","avatar_url":"https://github.com/amphp.png","language":"PHP","readme":"# amphp/parser\n\nAMPHP is a collection of event-driven libraries for PHP designed with fibers and concurrency in mind.\n`amphp/parser` allows easily building streaming generator parsers.\n\n## Installation\n\nThis package can be installed as a [Composer](https://getcomposer.org/) dependency.\n\n```bash\ncomposer require amphp/parser\n```\n\n## Requirements\n\n- PHP 7.4+\n\n## Usage\n\nPHP's generators are a great way for building incremental parsers.\n\n## Example\n\nThis simple parser parses a line delimited protocol and prints a message for each line. Instead of printing a message, you could also invoke a data callback.\n\n```php\n$parser = new Parser((function () {\n    while (true) {\n        $line = yield \"\\r\\n\";\n\n        if (trim($line) === \"\") {\n            continue;\n        }\n\n        print \"New item: {$line}\" . PHP_EOL;\n    }\n})());\n\nfor ($i = 0; $i \u003c 100; $i++) {\n    $parser-\u003epush(\"bar\\r\");\n    $parser-\u003epush(\"\\nfoo\");\n}\n```\n\nFurthere examples can be found in other AMPHP packages which this library to build streaming parsers.\n- [`ChannelParser`](https://github.com/amphp/byte-stream/blob/5c7eb399b746a582e9598935b26483b214250c34/src/Internal/ChannelParser.php#L28) in [`amphp/byte-stream`](https://github.com/amphp/byte-stream)\n- [`RespParser`](https://github.com/amphp/redis/blob/649cff6d5e6b4c579dcab1a20511a437cbe3d62a/src/Connection/RespParser.php#L31) in [`amphp/redis`](https://github.com/amphp/redis)\n\n## Yield Behavior\n\nYou can either `yield` a `string` that's used as delimiter, an `integer` that's used as length, or `null` to flush any remaining buffer in the parser (if any) or await the next call to `Parser::push()`.\n\n## Versioning\n\n`amphp/parser` follows the [semver](http://semver.org/) semantic versioning specification like all other `amphp` packages.\n\n## Security\n\nIf you discover any security related issues, please email [`me@kelunik.com`](mailto:me@kelunik.com) instead of using the issue tracker.\n\n## License\n\nThe MIT License (MIT). Please see [`LICENSE`](./LICENSE) for more information.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famphp%2Fparser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famphp%2Fparser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famphp%2Fparser/lists"}