定制 getsky/royal-stag 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

getsky/royal-stag

Composer 安装命令:

composer require getsky/royal-stag

包简介

PEG for PHP

README 文档

README

Build Status Scrutinizer Code Quality Code Coverage

RoyalStag is a PHP library for parsing text realizes the strengths of parsing expression grammar, or PEG. The main feature is the grammar, which is set directly in the code of PHP. This means that you do not need to learn any third-party formats to start using the library, and you do not lose the opportunities that gives you your favorite IDE (syntax highlighting, refactoring, etc.).

Easy integration into your projects

To integrate the library into your project, you will not have to spend a lot of time and effort. The open and flexible architecture easily integrates into any architectural solution, as there is no need for third-party tools to generate a parser. The only thing you have to do is add one line composer.json:

"getsky/royal-stag": "0.9.1@dev"

Why not regular expressions?

In many cases, it also lacks the ability to parse the text, such as embedded designs that require a recursive definition of the rules. They also do not provide appropriate error messages, and it can save a lot of time both during development and in support of software. And of course the ease of learning.

Why not ANTLR and other enterprise?

ANTLR and others like it may all libraries that can RoyalStag and even more, but not always appropriate to use such a large library, which require much more time to study, develop with them and their continued support of software products.

Simple example

The following example shows operating principle:

<?php

use GetSky\ParserExpressions\Rules\FirstOf;
use GetSky\ParserExpressions\Rules\Optional;
use GetSky\ParserExpressions\Rules\Sequence;
use GetSky\ParserExpressions\Runner;
use GetSky\ParserExpressions\Context;
use GetSky\ParserExpressions\Error;

require_once '../vendor/autoload.php';

$rule = new Sequence([new FirstOf(['Hello', 'Hi']), new Optional(' '), 'world']);
$runner = new Runner($rule);

$result = $runner->run('Hi world!');

$tree = $result->toArray();

The variable contains:

Array
(
    [name] => Sequence
    [value] => Hi world
    [start] => 0
    [end] => 8
    [children] => Array
        (
            [0] => Array
                (
                    [name] => FirstOf
                    [value] => Hi
                    [start] => 0
                    [end] => 2
                    [children] => Array
                        (
                            [0] => Array
                                (
                                    [name] => Row
                                    [value] => Hi
                                    [start] => 0
                                    [end] => 2
                                )

                        )

                )

            [1] => Array
                (
                    [name] => Optional
                    [value] =>
                    [start] => 2
                    [end] => 3
                    [children] => Array
                        (
                            [0] => Array
                                (
                                    [name] => Row
                                    [value] =>
                                    [start] => 2
                                    [end] => 3
                                )

                        )

                )

            [2] => Array
                (
                    [name] => Row
                    [value] => world
                    [start] => 3
                    [end] => 8
                )

        )

)

More example

See more examples in this folder.

统计信息

  • 总下载量: 4.34k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 2
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-05-06