2017 © Pedro Peláez
 

library parser

A generator parser to make streaming parsers simple.

image

amphp/parser

A generator parser to make streaming parsers simple.

  • Wednesday, May 16, 2018
  • by kelunik
  • Repository
  • 3 Watchers
  • 12 Stars
  • 55,154 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 2 Versions
  • 28 % Grown

The README.md

amphp/parser

AMPHP is a collection of event-driven libraries for PHP designed with fibers and concurrency in mind. amphp/parser allows easily building streaming generator parsers., (*1)

Installation

This package can be installed as a Composer dependency., (*2)

composer require amphp/parser

Requirements

  • PHP 7.4+

Usage

PHP's generators are a great way for building incremental parsers., (*3)

Example

This 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., (*4)

$parser = new Parser((function () {
    while (true) {
        $line = yield "\r\n";

        if (trim($line) === "") {
            continue;
        }

        print "New item: {$line}" . PHP_EOL;
    }
})());

for ($i = 0; $i < 100; $i++) {
    $parser->push("bar\r");
    $parser->push("\nfoo");
}

Furthere examples can be found in other AMPHP packages which this library to build streaming parsers. - ChannelParser in amphp/byte-stream - RespParser in amphp/redis, (*5)

Yield Behavior

You 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()., (*6)

Versioning

amphp/parser follows the semver semantic versioning specification like all other amphp packages., (*7)

Security

If you discover any security related issues, please email me@kelunik.com instead of using the issue tracker., (*8)

License

The MIT License (MIT). Please see LICENSE for more information., (*9)

The Versions

16/05 2018

dev-master

9999999-dev https://github.com/amphp/parser

A generator parser to make streaming parsers simple.

  Sources   Download

MIT

The Requires

  • php >=7

 

The Development Requires

by Aaron Piotrowski

parser async non-blocking stream

06/06 2017

v1.0.0

1.0.0.0 https://github.com/amphp/parser

A generator parser to make streaming parsers simple.

  Sources   Download

MIT

The Requires

  • php >=7

 

The Development Requires

by Aaron Piotrowski

parser async non-blocking stream