vektah/parser-combinator

0.2.4 2014-02-12 06:49 UTC

This package is not auto-updated.

Last update: 2024-09-23 14:52:33 UTC


README

这是一个用PHP编写的简单的解析器组合框架。

Google Protobuf 解析器

$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 解析器

您使用此解析器的唯一原因是为了错误信息。它比PHP用于解析JSON的C库慢得多。它可以用于在失败情况下自动重新解析JSON并显示有用的错误信息。

$parser = new JsonParser();
$out = $parser->parse('{"asdf": { "foo" : "bar" }}');

// $out will contain a parse tree that looks like this:
[
  'asdf' => [
    'foo' => 'bar'
  ]
]