vektah / parser-combinator
0.2.4
2014-02-12 06:49 UTC
Requires
- php: >=5.4.0
Requires (Dev)
- phpunit/phpunit: 3.7.21
- squizlabs/php_codesniffer: 1.4.5
- vektah/bugfree-dangerzone: 0.3.*
- vektah/psr2: *
This package is not auto-updated.
Last update: 2024-12-02 15:40:50 UTC
README
A simple parser combinator framework written in PHP.
Google protobuffer parser:
$parser = new ProtoParser();
$out = $parser->parse('
message Bar {
required MessageType type = 0;
required bytes data = 1;
enum Foo {
asdf = 0;
qwer = 1;
}
}
');
// $out will contain return a parse tree that looks like this:
[
new Message('Bar', [
new Field('required', 'MessageType', 'type', 0),
new Field('required', 'bytes', 'data', 1),
new Enum('Foo', [
new EnumValue('asdf', 0),
new EnumValue('qwer', 1)
])
])
];
Json parser:
The only reason you would use this parser is for error messages. It is much slower then the C library used by php to parse json. It could be used to automatically reparse json in failure cases and display helpful error messages.
$parser = new JsonParser();
$out = $parser->parse('{"asdf": { "foo" : "bar" }}');
// $out will contain a parse tree that looks like this:
[
'asdf' => [
'foo' => 'bar'
]
]