From: Andrey Kutejko Date: Sun, 17 Mar 2019 13:06:30 +0000 (+0100) Subject: modernize code X-Git-Url: https://git.andy128k.dev/?a=commitdiff_plain;ds=sidebyside;p=pegp.git modernize code --- diff --git a/.gitignore b/.gitignore index fcac4a7..a3ce491 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ /vendor - +/coverage +.idea +*.iml +.phpunit.result.cache diff --git a/composer.json b/composer.json index 1a0f48b..c8ea009 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "andy128k/pegp", - "description": "PEG", + "description": "Library to construct PEG parsers", "license": "MIT", "authors": [ { @@ -8,16 +8,24 @@ "email": "andy128k@gmail.com" } ], + "scripts": { + "test": "phpunit test", + "coverage": "phpunit test --coverage-html coverage --whitelist src" + }, "autoload": { - "classmap" : ["src/"] + "psr-4": { + "Pegp\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "": "test/" + } + }, + "require": { + "php": ">=5.6" }, "require-dev": { - "phpunit/phpunit": "4.4.*" + "phpunit/phpunit": "~8" }, - "extra": { - "branch-alias": { - "dev-master": "0.x-dev" - } - } } - diff --git a/composer.lock b/composer.lock index 076349e..6756ed6 100644 --- a/composer.lock +++ b/composer.lock @@ -1,45 +1,45 @@ { "_readme": [ "This file locks the dependencies of your project to a known state", - "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "hash": "296bad4d032bbeaecae1e094485a34e0", + "content-hash": "dad826deb1df52fbe4e9d9c493a2710f", "packages": [], "packages-dev": [ { "name": "doctrine/instantiator", - "version": "1.0.4", + "version": "1.1.0", "source": { "type": "git", "url": "https://github.com/doctrine/instantiator.git", - "reference": "f976e5de371104877ebc89bd8fecb0019ed9c119" + "reference": "185b8868aa9bf7159f5f953ed5afb2d7fcdc3bda" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/f976e5de371104877ebc89bd8fecb0019ed9c119", - "reference": "f976e5de371104877ebc89bd8fecb0019ed9c119", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/185b8868aa9bf7159f5f953ed5afb2d7fcdc3bda", + "reference": "185b8868aa9bf7159f5f953ed5afb2d7fcdc3bda", "shasum": "" }, "require": { - "php": ">=5.3,<8.0-DEV" + "php": "^7.1" }, "require-dev": { "athletic/athletic": "~0.1.8", "ext-pdo": "*", "ext-phar": "*", - "phpunit/phpunit": "~4.0", - "squizlabs/php_codesniffer": "2.0.*@ALPHA" + "phpunit/phpunit": "^6.2.3", + "squizlabs/php_codesniffer": "^3.0.2" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "1.2.x-dev" } }, "autoload": { - "psr-0": { - "Doctrine\\Instantiator\\": "src" + "psr-4": { + "Doctrine\\Instantiator\\": "src/Doctrine/Instantiator/" } }, "notification-url": "https://packagist.org/downloads/", @@ -59,43 +59,409 @@ "constructor", "instantiate" ], - "time": "2014-10-13 12:58:55" + "time": "2017-07-22T11:58:36+00:00" + }, + { + "name": "myclabs/deep-copy", + "version": "1.8.1", + "source": { + "type": "git", + "url": "https://github.com/myclabs/DeepCopy.git", + "reference": "3e01bdad3e18354c3dce54466b7fbe33a9f9f7f8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/3e01bdad3e18354c3dce54466b7fbe33a9f9f7f8", + "reference": "3e01bdad3e18354c3dce54466b7fbe33a9f9f7f8", + "shasum": "" + }, + "require": { + "php": "^7.1" + }, + "replace": { + "myclabs/deep-copy": "self.version" + }, + "require-dev": { + "doctrine/collections": "^1.0", + "doctrine/common": "^2.6", + "phpunit/phpunit": "^7.1" + }, + "type": "library", + "autoload": { + "psr-4": { + "DeepCopy\\": "src/DeepCopy/" + }, + "files": [ + "src/DeepCopy/deep_copy.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Create deep copies (clones) of your objects", + "keywords": [ + "clone", + "copy", + "duplicate", + "object", + "object graph" + ], + "time": "2018-06-11T23:09:50+00:00" + }, + { + "name": "phar-io/manifest", + "version": "1.0.3", + "source": { + "type": "git", + "url": "https://github.com/phar-io/manifest.git", + "reference": "7761fcacf03b4d4f16e7ccb606d4879ca431fcf4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phar-io/manifest/zipball/7761fcacf03b4d4f16e7ccb606d4879ca431fcf4", + "reference": "7761fcacf03b4d4f16e7ccb606d4879ca431fcf4", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-phar": "*", + "phar-io/version": "^2.0", + "php": "^5.6 || ^7.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + }, + { + "name": "Sebastian Heuer", + "email": "sebastian@phpeople.de", + "role": "Developer" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "Developer" + } + ], + "description": "Component for reading phar.io manifest information from a PHP Archive (PHAR)", + "time": "2018-07-08T19:23:20+00:00" + }, + { + "name": "phar-io/version", + "version": "2.0.1", + "source": { + "type": "git", + "url": "https://github.com/phar-io/version.git", + "reference": "45a2ec53a73c70ce41d55cedef9063630abaf1b6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phar-io/version/zipball/45a2ec53a73c70ce41d55cedef9063630abaf1b6", + "reference": "45a2ec53a73c70ce41d55cedef9063630abaf1b6", + "shasum": "" + }, + "require": { + "php": "^5.6 || ^7.0" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + }, + { + "name": "Sebastian Heuer", + "email": "sebastian@phpeople.de", + "role": "Developer" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "Developer" + } + ], + "description": "Library for handling version information and constraints", + "time": "2018-07-08T19:19:57+00:00" + }, + { + "name": "phpdocumentor/reflection-common", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/ReflectionCommon.git", + "reference": "21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6", + "reference": "21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6", + "shasum": "" + }, + "require": { + "php": ">=5.5" + }, + "require-dev": { + "phpunit/phpunit": "^4.6" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": [ + "src" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jaap van Otterdijk", + "email": "opensource@ijaap.nl" + } + ], + "description": "Common reflection classes used by phpdocumentor to reflect the code structure", + "homepage": "http://www.phpdoc.org", + "keywords": [ + "FQSEN", + "phpDocumentor", + "phpdoc", + "reflection", + "static analysis" + ], + "time": "2017-09-11T18:02:19+00:00" + }, + { + "name": "phpdocumentor/reflection-docblock", + "version": "4.3.0", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", + "reference": "94fd0001232e47129dd3504189fa1c7225010d08" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/94fd0001232e47129dd3504189fa1c7225010d08", + "reference": "94fd0001232e47129dd3504189fa1c7225010d08", + "shasum": "" + }, + "require": { + "php": "^7.0", + "phpdocumentor/reflection-common": "^1.0.0", + "phpdocumentor/type-resolver": "^0.4.0", + "webmozart/assert": "^1.0" + }, + "require-dev": { + "doctrine/instantiator": "~1.0.5", + "mockery/mockery": "^1.0", + "phpunit/phpunit": "^6.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.x-dev" + } + }, + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mike van Riel", + "email": "me@mikevanriel.com" + } + ], + "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", + "time": "2017-11-30T07:14:17+00:00" + }, + { + "name": "phpdocumentor/type-resolver", + "version": "0.4.0", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/TypeResolver.git", + "reference": "9c977708995954784726e25d0cd1dddf4e65b0f7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/9c977708995954784726e25d0cd1dddf4e65b0f7", + "reference": "9c977708995954784726e25d0cd1dddf4e65b0f7", + "shasum": "" + }, + "require": { + "php": "^5.5 || ^7.0", + "phpdocumentor/reflection-common": "^1.0" + }, + "require-dev": { + "mockery/mockery": "^0.9.4", + "phpunit/phpunit": "^5.2||^4.8.24" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mike van Riel", + "email": "me@mikevanriel.com" + } + ], + "time": "2017-07-14T14:27:02+00:00" + }, + { + "name": "phpspec/prophecy", + "version": "1.8.0", + "source": { + "type": "git", + "url": "https://github.com/phpspec/prophecy.git", + "reference": "4ba436b55987b4bf311cb7c6ba82aa528aac0a06" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/4ba436b55987b4bf311cb7c6ba82aa528aac0a06", + "reference": "4ba436b55987b4bf311cb7c6ba82aa528aac0a06", + "shasum": "" + }, + "require": { + "doctrine/instantiator": "^1.0.2", + "php": "^5.3|^7.0", + "phpdocumentor/reflection-docblock": "^2.0|^3.0.2|^4.0", + "sebastian/comparator": "^1.1|^2.0|^3.0", + "sebastian/recursion-context": "^1.0|^2.0|^3.0" + }, + "require-dev": { + "phpspec/phpspec": "^2.5|^3.2", + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.5 || ^7.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.8.x-dev" + } + }, + "autoload": { + "psr-0": { + "Prophecy\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Konstantin Kudryashov", + "email": "ever.zet@gmail.com", + "homepage": "http://everzet.com" + }, + { + "name": "Marcello Duarte", + "email": "marcello.duarte@gmail.com" + } + ], + "description": "Highly opinionated mocking framework for PHP 5.3+", + "homepage": "https://github.com/phpspec/prophecy", + "keywords": [ + "Double", + "Dummy", + "fake", + "mock", + "spy", + "stub" + ], + "time": "2018-08-05T17:53:17+00:00" }, { "name": "phpunit/php-code-coverage", - "version": "2.0.14", + "version": "7.0.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "ca158276c1200cc27f5409a5e338486bc0b4fc94" + "reference": "0317a769a81845c390e19684d9ba25d7f6aa4707" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/ca158276c1200cc27f5409a5e338486bc0b4fc94", - "reference": "ca158276c1200cc27f5409a5e338486bc0b4fc94", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/0317a769a81845c390e19684d9ba25d7f6aa4707", + "reference": "0317a769a81845c390e19684d9ba25d7f6aa4707", "shasum": "" }, "require": { - "php": ">=5.3.3", - "phpunit/php-file-iterator": "~1.3", - "phpunit/php-text-template": "~1.2", - "phpunit/php-token-stream": "~1.3", - "sebastian/environment": "~1.0", - "sebastian/version": "~1.0" + "ext-dom": "*", + "ext-xmlwriter": "*", + "php": "^7.2", + "phpunit/php-file-iterator": "^2.0.2", + "phpunit/php-text-template": "^1.2.1", + "phpunit/php-token-stream": "^3.0.1", + "sebastian/code-unit-reverse-lookup": "^1.0.1", + "sebastian/environment": "^4.1", + "sebastian/version": "^2.0.1", + "theseer/tokenizer": "^1.1" }, "require-dev": { - "ext-xdebug": ">=2.1.4", - "phpunit/phpunit": "~4.1" + "phpunit/phpunit": "^8.0" }, "suggest": { - "ext-dom": "*", - "ext-xdebug": ">=2.2.1", - "ext-xmlwriter": "*" + "ext-xdebug": "^2.6.1" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0.x-dev" + "dev-master": "7.0-dev" } }, "autoload": { @@ -104,16 +470,13 @@ ] }, "notification-url": "https://packagist.org/downloads/", - "include-path": [ - "" - ], "license": [ "BSD-3-Clause" ], "authors": [ { "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", + "email": "sebastian@phpunit.de", "role": "lead" } ], @@ -124,42 +487,47 @@ "testing", "xunit" ], - "time": "2014-12-26 13:28:33" + "time": "2019-02-26T07:38:26+00:00" }, { "name": "phpunit/php-file-iterator", - "version": "1.3.4", + "version": "2.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-file-iterator.git", - "reference": "acd690379117b042d1c8af1fafd61bde001bf6bb" + "reference": "050bedf145a257b1ff02746c31894800e5122946" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/acd690379117b042d1c8af1fafd61bde001bf6bb", - "reference": "acd690379117b042d1c8af1fafd61bde001bf6bb", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/050bedf145a257b1ff02746c31894800e5122946", + "reference": "050bedf145a257b1ff02746c31894800e5122946", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": "^7.1" + }, + "require-dev": { + "phpunit/phpunit": "^7.1" }, "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, "autoload": { "classmap": [ - "File/" + "src/" ] }, "notification-url": "https://packagist.org/downloads/", - "include-path": [ - "" - ], "license": [ "BSD-3-Clause" ], "authors": [ { "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", + "email": "sebastian@phpunit.de", "role": "lead" } ], @@ -169,20 +537,20 @@ "filesystem", "iterator" ], - "time": "2013-10-10 15:34:57" + "time": "2018-09-13T20:33:42+00:00" }, { "name": "phpunit/php-text-template", - "version": "1.2.0", + "version": "1.2.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-text-template.git", - "reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a" + "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/206dfefc0ffe9cebf65c413e3d0e809c82fbf00a", - "reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a", + "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/31f8b717e51d9a2afca6c9f046f5d69fc27c8686", + "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686", "shasum": "" }, "require": { @@ -191,20 +559,17 @@ "type": "library", "autoload": { "classmap": [ - "Text/" + "src/" ] }, "notification-url": "https://packagist.org/downloads/", - "include-path": [ - "" - ], "license": [ "BSD-3-Clause" ], "authors": [ { "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", + "email": "sebastian@phpunit.de", "role": "lead" } ], @@ -213,42 +578,47 @@ "keywords": [ "template" ], - "time": "2014-01-30 17:20:04" + "time": "2015-06-21T13:50:34+00:00" }, { "name": "phpunit/php-timer", - "version": "1.0.5", + "version": "2.1.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-timer.git", - "reference": "19689d4354b295ee3d8c54b4f42c3efb69cbc17c" + "reference": "8b389aebe1b8b0578430bda0c7c95a829608e059" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/19689d4354b295ee3d8c54b4f42c3efb69cbc17c", - "reference": "19689d4354b295ee3d8c54b4f42c3efb69cbc17c", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/8b389aebe1b8b0578430bda0c7c95a829608e059", + "reference": "8b389aebe1b8b0578430bda0c7c95a829608e059", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": "^7.1" + }, + "require-dev": { + "phpunit/phpunit": "^7.0" }, "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.1-dev" + } + }, "autoload": { "classmap": [ - "PHP/" + "src/" ] }, "notification-url": "https://packagist.org/downloads/", - "include-path": [ - "" - ], "license": [ "BSD-3-Clause" ], "authors": [ { "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", + "email": "sebastian@phpunit.de", "role": "lead" } ], @@ -257,33 +627,33 @@ "keywords": [ "timer" ], - "time": "2013-08-02 07:42:54" + "time": "2019-02-20T10:12:59+00:00" }, { "name": "phpunit/php-token-stream", - "version": "1.3.0", + "version": "3.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-token-stream.git", - "reference": "f8d5d08c56de5cfd592b3340424a81733259a876" + "reference": "c99e3be9d3e85f60646f152f9002d46ed7770d18" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/f8d5d08c56de5cfd592b3340424a81733259a876", - "reference": "f8d5d08c56de5cfd592b3340424a81733259a876", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/c99e3be9d3e85f60646f152f9002d46ed7770d18", + "reference": "c99e3be9d3e85f60646f152f9002d46ed7770d18", "shasum": "" }, "require": { "ext-tokenizer": "*", - "php": ">=5.3.3" + "php": "^7.1" }, "require-dev": { - "phpunit/phpunit": "~4.2" + "phpunit/phpunit": "^7.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.3-dev" + "dev-master": "3.0-dev" } }, "autoload": { @@ -306,44 +676,55 @@ "keywords": [ "tokenizer" ], - "time": "2014-08-31 06:12:13" + "time": "2018-10-30T05:52:18+00:00" }, { "name": "phpunit/phpunit", - "version": "4.4.1", + "version": "8.0.5", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "6a5e49a86ce5e33b8d0657abe145057fc513543a" + "reference": "19cbed2120839772c4a00e8b28456b0c77d1a7b4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/6a5e49a86ce5e33b8d0657abe145057fc513543a", - "reference": "6a5e49a86ce5e33b8d0657abe145057fc513543a", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/19cbed2120839772c4a00e8b28456b0c77d1a7b4", + "reference": "19cbed2120839772c4a00e8b28456b0c77d1a7b4", "shasum": "" }, "require": { + "doctrine/instantiator": "^1.1", "ext-dom": "*", "ext-json": "*", - "ext-pcre": "*", - "ext-reflection": "*", - "ext-spl": "*", - "php": ">=5.3.3", - "phpunit/php-code-coverage": "~2.0", - "phpunit/php-file-iterator": "~1.3.2", - "phpunit/php-text-template": "~1.2", - "phpunit/php-timer": "~1.0.2", - "phpunit/phpunit-mock-objects": "~2.3", - "sebastian/comparator": "~1.0", - "sebastian/diff": "~1.1", - "sebastian/environment": "~1.1", - "sebastian/exporter": "~1.0", - "sebastian/global-state": "~1.0", - "sebastian/version": "~1.0", - "symfony/yaml": "~2.0" + "ext-libxml": "*", + "ext-mbstring": "*", + "ext-xml": "*", + "ext-xmlwriter": "*", + "myclabs/deep-copy": "^1.7", + "phar-io/manifest": "^1.0.2", + "phar-io/version": "^2.0", + "php": "^7.2", + "phpspec/prophecy": "^1.7", + "phpunit/php-code-coverage": "^7.0", + "phpunit/php-file-iterator": "^2.0.1", + "phpunit/php-text-template": "^1.2.1", + "phpunit/php-timer": "^2.1", + "sebastian/comparator": "^3.0", + "sebastian/diff": "^3.0", + "sebastian/environment": "^4.1", + "sebastian/exporter": "^3.1", + "sebastian/global-state": "^3.0", + "sebastian/object-enumerator": "^3.0.3", + "sebastian/resource-operations": "^2.0", + "sebastian/version": "^2.0.1" + }, + "require-dev": { + "ext-pdo": "*" }, "suggest": { - "phpunit/php-invoker": "~1.1" + "ext-soap": "*", + "ext-xdebug": "*", + "phpunit/php-invoker": "^2.0" }, "bin": [ "phpunit" @@ -351,7 +732,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.4.x-dev" + "dev-master": "8.0-dev" } }, "autoload": { @@ -377,37 +758,32 @@ "testing", "xunit" ], - "time": "2014-12-28 07:57:05" + "time": "2019-03-16T07:33:46+00:00" }, { - "name": "phpunit/phpunit-mock-objects", - "version": "2.3.0", + "name": "sebastian/code-unit-reverse-lookup", + "version": "1.0.1", "source": { "type": "git", - "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", - "reference": "c63d2367247365f688544f0d500af90a11a44c65" + "url": "https://github.com/sebastianbergmann/code-unit-reverse-lookup.git", + "reference": "4419fcdb5eabb9caa61a27c7a1db532a6b55dd18" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/c63d2367247365f688544f0d500af90a11a44c65", - "reference": "c63d2367247365f688544f0d500af90a11a44c65", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/4419fcdb5eabb9caa61a27c7a1db532a6b55dd18", + "reference": "4419fcdb5eabb9caa61a27c7a1db532a6b55dd18", "shasum": "" }, "require": { - "doctrine/instantiator": "~1.0,>=1.0.1", - "php": ">=5.3.3", - "phpunit/php-text-template": "~1.2" + "php": "^5.6 || ^7.0" }, "require-dev": { - "phpunit/phpunit": "~4.3" - }, - "suggest": { - "ext-soap": "*" + "phpunit/phpunit": "^5.7 || ^6.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.3.x-dev" + "dev-master": "1.0.x-dev" } }, "autoload": { @@ -422,44 +798,39 @@ "authors": [ { "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", - "role": "lead" + "email": "sebastian@phpunit.de" } ], - "description": "Mock Object library for PHPUnit", - "homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/", - "keywords": [ - "mock", - "xunit" - ], - "time": "2014-10-03 05:12:11" + "description": "Looks up which function or method a line of code belongs to", + "homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/", + "time": "2017-03-04T06:30:41+00:00" }, { "name": "sebastian/comparator", - "version": "1.1.0", + "version": "3.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/comparator.git", - "reference": "c484a80f97573ab934e37826dba0135a3301b26a" + "reference": "5de4fc177adf9bce8df98d8d141a7559d7ccf6da" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/c484a80f97573ab934e37826dba0135a3301b26a", - "reference": "c484a80f97573ab934e37826dba0135a3301b26a", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/5de4fc177adf9bce8df98d8d141a7559d7ccf6da", + "reference": "5de4fc177adf9bce8df98d8d141a7559d7ccf6da", "shasum": "" }, "require": { - "php": ">=5.3.3", - "sebastian/diff": "~1.1", - "sebastian/exporter": "~1.0" + "php": "^7.1", + "sebastian/diff": "^3.0", + "sebastian/exporter": "^3.1" }, "require-dev": { - "phpunit/phpunit": "~4.1" + "phpunit/phpunit": "^7.1" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.1.x-dev" + "dev-master": "3.0-dev" } }, "autoload": { @@ -490,38 +861,39 @@ } ], "description": "Provides the functionality to compare PHP values for equality", - "homepage": "http://www.github.com/sebastianbergmann/comparator", + "homepage": "https://github.com/sebastianbergmann/comparator", "keywords": [ "comparator", "compare", "equality" ], - "time": "2014-11-16 21:32:38" + "time": "2018-07-12T15:12:46+00:00" }, { "name": "sebastian/diff", - "version": "1.2.0", + "version": "3.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/diff.git", - "reference": "5843509fed39dee4b356a306401e9dd1a931fec7" + "reference": "720fcc7e9b5cf384ea68d9d930d480907a0c1a29" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/5843509fed39dee4b356a306401e9dd1a931fec7", - "reference": "5843509fed39dee4b356a306401e9dd1a931fec7", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/720fcc7e9b5cf384ea68d9d930d480907a0c1a29", + "reference": "720fcc7e9b5cf384ea68d9d930d480907a0c1a29", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": "^7.1" }, "require-dev": { - "phpunit/phpunit": "~4.2" + "phpunit/phpunit": "^7.5 || ^8.0", + "symfony/process": "^2 || ^3.3 || ^4" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.2-dev" + "dev-master": "3.0-dev" } }, "autoload": { @@ -544,36 +916,42 @@ } ], "description": "Diff implementation", - "homepage": "http://www.github.com/sebastianbergmann/diff", + "homepage": "https://github.com/sebastianbergmann/diff", "keywords": [ - "diff" + "diff", + "udiff", + "unidiff", + "unified diff" ], - "time": "2014-08-15 10:29:00" + "time": "2019-02-04T06:01:07+00:00" }, { "name": "sebastian/environment", - "version": "1.2.1", + "version": "4.1.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/environment.git", - "reference": "6e6c71d918088c251b181ba8b3088af4ac336dd7" + "reference": "6fda8ce1974b62b14935adc02a9ed38252eca656" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/6e6c71d918088c251b181ba8b3088af4ac336dd7", - "reference": "6e6c71d918088c251b181ba8b3088af4ac336dd7", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/6fda8ce1974b62b14935adc02a9ed38252eca656", + "reference": "6fda8ce1974b62b14935adc02a9ed38252eca656", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": "^7.1" }, "require-dev": { - "phpunit/phpunit": "~4.3" + "phpunit/phpunit": "^7.5" + }, + "suggest": { + "ext-posix": "*" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.2.x-dev" + "dev-master": "4.1-dev" } }, "autoload": { @@ -598,32 +976,34 @@ "environment", "hhvm" ], - "time": "2014-10-25 08:00:45" + "time": "2019-02-01T05:27:49+00:00" }, { "name": "sebastian/exporter", - "version": "1.0.2", + "version": "3.1.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "c7d59948d6e82818e1bdff7cadb6c34710eb7dc0" + "reference": "234199f4528de6d12aaa58b612e98f7d36adb937" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/c7d59948d6e82818e1bdff7cadb6c34710eb7dc0", - "reference": "c7d59948d6e82818e1bdff7cadb6c34710eb7dc0", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/234199f4528de6d12aaa58b612e98f7d36adb937", + "reference": "234199f4528de6d12aaa58b612e98f7d36adb937", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": "^7.0", + "sebastian/recursion-context": "^3.0" }, "require-dev": { - "phpunit/phpunit": "~4.0" + "ext-mbstring": "*", + "phpunit/phpunit": "^6.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "3.1.x-dev" } }, "autoload": { @@ -663,27 +1043,30 @@ "export", "exporter" ], - "time": "2014-09-10 00:51:36" + "time": "2017-04-03T13:19:02+00:00" }, { "name": "sebastian/global-state", - "version": "1.0.0", + "version": "3.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/global-state.git", - "reference": "c7428acdb62ece0a45e6306f1ae85e1c05b09c01" + "reference": "edf8a461cf1d4005f19fb0b6b8b95a9f7fa0adc4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/c7428acdb62ece0a45e6306f1ae85e1c05b09c01", - "reference": "c7428acdb62ece0a45e6306f1ae85e1c05b09c01", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/edf8a461cf1d4005f19fb0b6b8b95a9f7fa0adc4", + "reference": "edf8a461cf1d4005f19fb0b6b8b95a9f7fa0adc4", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": "^7.2", + "sebastian/object-reflector": "^1.1.1", + "sebastian/recursion-context": "^3.0" }, "require-dev": { - "phpunit/phpunit": "~4.2" + "ext-dom": "*", + "phpunit/phpunit": "^8.0" }, "suggest": { "ext-uopz": "*" @@ -691,7 +1074,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0-dev" + "dev-master": "3.0-dev" } }, "autoload": { @@ -714,23 +1097,218 @@ "keywords": [ "global state" ], - "time": "2014-10-06 09:23:50" + "time": "2019-02-01T05:30:01+00:00" + }, + { + "name": "sebastian/object-enumerator", + "version": "3.0.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/object-enumerator.git", + "reference": "7cfd9e65d11ffb5af41198476395774d4c8a84c5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/7cfd9e65d11ffb5af41198476395774d4c8a84c5", + "reference": "7cfd9e65d11ffb5af41198476395774d4c8a84c5", + "shasum": "" + }, + "require": { + "php": "^7.0", + "sebastian/object-reflector": "^1.1.1", + "sebastian/recursion-context": "^3.0" + }, + "require-dev": { + "phpunit/phpunit": "^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Traverses array structures and object graphs to enumerate all referenced objects", + "homepage": "https://github.com/sebastianbergmann/object-enumerator/", + "time": "2017-08-03T12:35:26+00:00" + }, + { + "name": "sebastian/object-reflector", + "version": "1.1.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/object-reflector.git", + "reference": "773f97c67f28de00d397be301821b06708fca0be" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/773f97c67f28de00d397be301821b06708fca0be", + "reference": "773f97c67f28de00d397be301821b06708fca0be", + "shasum": "" + }, + "require": { + "php": "^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Allows reflection of object attributes, including inherited and non-public ones", + "homepage": "https://github.com/sebastianbergmann/object-reflector/", + "time": "2017-03-29T09:07:27+00:00" + }, + { + "name": "sebastian/recursion-context", + "version": "3.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/recursion-context.git", + "reference": "5b0cd723502bac3b006cbf3dbf7a1e3fcefe4fa8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/5b0cd723502bac3b006cbf3dbf7a1e3fcefe4fa8", + "reference": "5b0cd723502bac3b006cbf3dbf7a1e3fcefe4fa8", + "shasum": "" + }, + "require": { + "php": "^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + } + ], + "description": "Provides functionality to recursively process PHP variables", + "homepage": "http://www.github.com/sebastianbergmann/recursion-context", + "time": "2017-03-03T06:23:57+00:00" + }, + { + "name": "sebastian/resource-operations", + "version": "2.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/resource-operations.git", + "reference": "4d7a795d35b889bf80a0cc04e08d77cedfa917a9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/4d7a795d35b889bf80a0cc04e08d77cedfa917a9", + "reference": "4d7a795d35b889bf80a0cc04e08d77cedfa917a9", + "shasum": "" + }, + "require": { + "php": "^7.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides a list of PHP built-in functions that operate on resources", + "homepage": "https://www.github.com/sebastianbergmann/resource-operations", + "time": "2018-10-04T04:07:39+00:00" }, { "name": "sebastian/version", - "version": "1.0.4", + "version": "2.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/version.git", - "reference": "a77d9123f8e809db3fbdea15038c27a95da4058b" + "reference": "99732be0ddb3361e16ad77b68ba41efc8e979019" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/a77d9123f8e809db3fbdea15038c27a95da4058b", - "reference": "a77d9123f8e809db3fbdea15038c27a95da4058b", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/99732be0ddb3361e16ad77b68ba41efc8e979019", + "reference": "99732be0ddb3361e16ad77b68ba41efc8e979019", "shasum": "" }, + "require": { + "php": ">=5.6" + }, "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, "autoload": { "classmap": [ "src/" @@ -749,36 +1327,41 @@ ], "description": "Library that helps with managing the version number of Git-hosted PHP projects", "homepage": "https://github.com/sebastianbergmann/version", - "time": "2014-12-15 14:25:24" + "time": "2016-10-03T07:35:21+00:00" }, { - "name": "symfony/yaml", - "version": "v2.6.3", - "target-dir": "Symfony/Component/Yaml", + "name": "symfony/polyfill-ctype", + "version": "v1.10.0", "source": { "type": "git", - "url": "https://github.com/symfony/Yaml.git", - "reference": "82462a90848a52c2533aa6b598b107d68076b018" + "url": "https://github.com/symfony/polyfill-ctype.git", + "reference": "e3d826245268269cd66f8326bd8bc066687b4a19" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Yaml/zipball/82462a90848a52c2533aa6b598b107d68076b018", - "reference": "82462a90848a52c2533aa6b598b107d68076b018", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/e3d826245268269cd66f8326bd8bc066687b4a19", + "reference": "e3d826245268269cd66f8326bd8bc066687b4a19", "shasum": "" }, "require": { "php": ">=5.3.3" }, + "suggest": { + "ext-ctype": "For best performance" + }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.6-dev" + "dev-master": "1.9-dev" } }, "autoload": { - "psr-0": { - "Symfony\\Component\\Yaml\\": "" - } + "psr-4": { + "Symfony\\Polyfill\\Ctype\\": "" + }, + "files": [ + "bootstrap.php" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -787,22 +1370,122 @@ "authors": [ { "name": "Symfony Community", - "homepage": "http://symfony.com/contributors" + "homepage": "https://symfony.com/contributors" }, { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" + "name": "Gert de Pagter", + "email": "backendtea@gmail.com" } ], - "description": "Symfony Yaml Component", - "homepage": "http://symfony.com", - "time": "2015-01-03 15:33:07" + "description": "Symfony polyfill for ctype functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "ctype", + "polyfill", + "portable" + ], + "time": "2018-08-06T14:22:27+00:00" + }, + { + "name": "theseer/tokenizer", + "version": "1.1.0", + "source": { + "type": "git", + "url": "https://github.com/theseer/tokenizer.git", + "reference": "cb2f008f3f05af2893a87208fe6a6c4985483f8b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/theseer/tokenizer/zipball/cb2f008f3f05af2893a87208fe6a6c4985483f8b", + "reference": "cb2f008f3f05af2893a87208fe6a6c4985483f8b", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": "^7.0" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + } + ], + "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", + "time": "2017-04-07T12:08:54+00:00" + }, + { + "name": "webmozart/assert", + "version": "1.4.0", + "source": { + "type": "git", + "url": "https://github.com/webmozart/assert.git", + "reference": "83e253c8e0be5b0257b881e1827274667c5c17a9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/webmozart/assert/zipball/83e253c8e0be5b0257b881e1827274667c5c17a9", + "reference": "83e253c8e0be5b0257b881e1827274667c5c17a9", + "shasum": "" + }, + "require": { + "php": "^5.3.3 || ^7.0", + "symfony/polyfill-ctype": "^1.8" + }, + "require-dev": { + "phpunit/phpunit": "^4.6", + "sebastian/version": "^1.0.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3-dev" + } + }, + "autoload": { + "psr-4": { + "Webmozart\\Assert\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Bernhard Schussek", + "email": "bschussek@gmail.com" + } + ], + "description": "Assertions to validate method input/output with nice error messages.", + "keywords": [ + "assert", + "check", + "validate" + ], + "time": "2018-12-25T11:19:39+00:00" } ], "aliases": [], "minimum-stability": "stable", "stability-flags": [], "prefer-stable": false, - "platform": [], + "prefer-lowest": false, + "platform": { + "php": ">=5.6" + }, "platform-dev": [] } diff --git a/src/Input.php b/src/Input.php new file mode 100644 index 0000000..1a1463a --- /dev/null +++ b/src/Input.php @@ -0,0 +1,49 @@ +data = $data; + $this->length = $length ? $length : strlen($data); + $this->pos = $pos; + } + + /** + * @param int $length + * @return string + */ + public function pick($length=PHP_INT_MAX) + { + $length = min($length, $this->length - $this->pos); + if ($length > 0) + return substr($this->data, $this->pos, $length); + else + return ''; + } + + /** + * @param integer $len + * @return Input + */ + public function advance($len) + { + return new self($this->data, $this->length, $this->pos + $len); + } +} diff --git a/src/Parser/Literal.php b/src/Parser/Literal.php new file mode 100644 index 0000000..b0a7c61 --- /dev/null +++ b/src/Parser/Literal.php @@ -0,0 +1,43 @@ +str = $str; + $this->caseInsensitive = $caseInsensitive; + $this->setComment('str . '>'); + } + + /** + * @param Input $input + * @return Result + */ + public function doParse(Input $input) + { + $len = strlen($this->str); + if (0 == substr_compare($input->data, $this->str, $input->pos, $len, $this->caseInsensitive)) { // ?? len + return Result::success( + $input->advance($len), + $this->str + ); + } else { + return Result::failure($input, $this); + } + } +} diff --git a/src/Parser/OneOf.php b/src/Parser/OneOf.php new file mode 100644 index 0000000..0f08545 --- /dev/null +++ b/src/Parser/OneOf.php @@ -0,0 +1,41 @@ +parsers = $parsers; + + $comment = array(); + foreach ($this->parsers as $parser) { + $comment[] = $parser->getComment(); + } + $this->setComment('one of: '.implode(', ', $comment)); + } + + /** + * @param Input $input + * @return Result + */ + public function doParse(Input $input) + { + foreach ($this->parsers as $parser) { + $r = $parser->parse($input); + if ($r->isSuccess()) { + return $r; + } + } + return Result::failure($input, $this); + } +} diff --git a/src/Parser/Optional.php b/src/Parser/Optional.php new file mode 100644 index 0000000..d9fb488 --- /dev/null +++ b/src/Parser/Optional.php @@ -0,0 +1,39 @@ +parser = $parser; + $this->emptyValue = $emptyValue; + } + + /** + * @param Input $input + * @return Result + */ + public function doParse(Input $input) + { + $r = $this->parser->parse($input); + if ($r->isSuccess()) { + return $r; + } else { + return Result::success($input, $this->emptyValue); + } + } +} diff --git a/src/Parser/Parser.php b/src/Parser/Parser.php new file mode 100644 index 0000000..8eb1774 --- /dev/null +++ b/src/Parser/Parser.php @@ -0,0 +1,107 @@ +parse($input); + if (!$result->isSuccess()) + throw new Exception('Parse failed. Expected ' . $result->result->getComment() . ' at ' . $result->input->pos); + if ($input->length != $result->input->pos) + throw new Exception('Parse failed. Unparsed tail at ' . $result->input->pos); + return $result->result; + } + + /** + * @param Input $input + * @return Result + */ + public function parse(Input $input) + { + $result = $this->doParse($input); + if ($result->isSuccess()) { + return $this->process($result); + } else { + return $result; + } + } + + /** + * @param Input $input + * @return Result + */ + public abstract function doParse(Input $input); + + /** + * @param Result $result + * @return Result + */ + protected function process($result) + { + if ($this->drop) { + return Result::success($result->input, null); + } elseif ($this->value !== null) { + return Result::success($result->input, $this->value); + } else { + return $result; + } + } + + /** + * @return string|null + */ + public function getComment() + { + return $this->comment; + } + + /** + * @param string $comment + * @return Parser + */ + public function setComment($comment) + { + $this->comment = $comment; + return $this; + } + + /** + * @return Parser + */ + public function drop() + { + $this->drop = true; + return $this; + } + + /** + * @param mixed $value + * @return Parser + */ + public function value($value) + { + $this->value = $value; + return $this; + } +} diff --git a/src/Parser/Regex.php b/src/Parser/Regex.php new file mode 100644 index 0000000..4dc92c1 --- /dev/null +++ b/src/Parser/Regex.php @@ -0,0 +1,64 @@ +expr = $delimiter . '^' . $expr . $delimiter . $flags; + $this->setComment('expr.'>'); + } + + /** + * @param Input $input + * @return Result + */ + public function doParse(Input $input) + { + if (preg_match($this->expr, $input->pick(), $m)) { + return Result::success( + $input->advance(strlen($m[0])), + $m + ); + } else { + return Result::failure($input, $this); + } + } + + /** + * @param string $groupName + * @return Regex + */ + public function group($groupName) + { + $this->groupName = $groupName; + return $this; + } + + /** + * @param Result $result + * @return Result + */ + protected function process($result) + { + if ($this->groupName !== null) { + $result = Result::success($result->input, $result->result[$this->groupName]); + } + return parent::process($result); + } +} diff --git a/src/Parser/Sequence.php b/src/Parser/Sequence.php new file mode 100644 index 0000000..d78c7aa --- /dev/null +++ b/src/Parser/Sequence.php @@ -0,0 +1,112 @@ +parsers = $parsers; + } + + /** + * @param Input $input + * @return Result + */ + public function doParse(Input $input) + { + $inp = $input; + $result = array(); + foreach ($this->parsers as $parser) { + $r = $parser->parse($inp); + if ($r->isSuccess()) { + $inp = $r->input; + if ($r->result !== null) + $result[] = $r->result; + } else { + return Result::failure($inp, $parser); + } + } + return Result::success($inp, $result); + } + + /** + * @param Result $result + * @return Result + */ + protected function process($result) + { + switch ($this->op) { + case 'join': + $result = Result::success($result->input, implode('', $result->result)); + break; + case 'bitOr': + $value = 0; + foreach ($result->result as $v) + $value |= $v; + $result = Result::success($result->input, $value); + break; + case 'sum': + $value = 0; + foreach ($result->result as $v) + $value += $v; + $result = Result::success($result->input, $value); + break; + case 'product': + $value = 1; + foreach ($result->result as $v) + $value *= $v; + $result = Result::success($result->input, $value); + break; + } + return parent::process($result); + } + + /** + * @return Sequence + */ + public function join() + { + $this->op = 'join'; + return $this; + } + + /** + * @return Sequence + */ + public function bitOr() + { + $this->op = 'bitOr'; + return $this; + } + + /** + * @return Sequence + */ + public function sum() + { + $this->op = 'sum'; + return $this; + } + + /** + * @return Sequence + */ + public function product() + { + $this->op = 'product'; + return $this; + } +} diff --git a/src/Pegp.php b/src/Pegp.php new file mode 100644 index 0000000..76281a5 --- /dev/null +++ b/src/Pegp.php @@ -0,0 +1,70 @@ +success = $success; + $this->input = $input; + $this->result = $result; + } + + /** + * @param Input $input + * @param mixed $result + * @return Result + */ + public static function success(Input $input, $result=null) + { + return new self(true, $input, $result); + } + + /** + * @param Input $input + * @param Parser $parser + * @return Result + */ + public static function failure(Input $input, $parser=null) + { + return new self(false, $input, $parser); + } + + /** + * @return boolean + */ + public function isSuccess() + { + return $this->success; + } +} diff --git a/src/input.php b/src/input.php deleted file mode 100644 index 9441af4..0000000 --- a/src/input.php +++ /dev/null @@ -1,28 +0,0 @@ -data = $data; - $this->length = $length ? $length : strlen($data); - $this->pos = $pos; - } - - public function pick($length=PHP_INT_MAX) - { - $length = min($length, $this->length - $this->pos); - if ($length > 0) - return substr($this->data, $this->pos, $length); - else - return ''; - } - - public function advance($len) - { - return new PegpInput($this->data, $this->length, $this->pos + $len); - } -} - diff --git a/src/parser.php b/src/parser.php deleted file mode 100644 index 5f2950a..0000000 --- a/src/parser.php +++ /dev/null @@ -1,260 +0,0 @@ -parse($input); - if (!$result->isSuccess()) - throw new Exception('Parse failed. Expected ' . $result->result->getComment() . ' at ' . $result->input->pos); - if ($input->length != $result->input->pos) - throw new Exception('Parse failed. Unparsed tail at ' . $result->input->pos); - return $result->result; - } - - public function parse(PegpInput $input) - { - $result = $this->doParse($input); - if ($result->isSuccess()) { - return $this->process($result); - } else { - return $result; - } - } - - public abstract function doParse(PegpInput $input); - - protected function process($result) - { - if ($this->drop) { - return PegpResult::success($result->input, null); - } elseif ($this->value !== null) { - return PegpResult::success($result->input, $this->value); - } else { - return $result; - } - } - - public function getComment() - { - return $this->comment; - } - - public function setComment($comment) - { - $this->comment = $comment; - return $this; - } - - public function drop() - { - $this->drop = true; - return $this; - } - - public function value($value) - { - $this->value = $value; - return $this; - } -} - -class PegpString extends PegpParser -{ - private $str, $caseInsensitive; - - public function __construct($str, $caseInsensitive=false) - { - $this->str = $str; - $this->caseInsensitive = $caseInsensitive; - } - - public function doParse(PegpInput $input) - { - $len = strlen($this->str); - if (0 == substr_compare($input->data, $this->str, $input->pos, $len, $this->caseInsensitive)) { // ?? len - return PegpResult::success( - $input->advance($len), - $this->str - ); - } else { - return PegpResult::failure($input, $this); - } - } - - public function getComment() - { - if ($this->comment !== null) - return $this->comment; - else - return 'str.'>'; - } -} - -class PegpRegex extends PegpParser -{ - private $expr; - - public function __construct($expr, $flags='', $delimiter='#') - { - $this->expr = $delimiter . '^' . $expr . $delimiter . $flags; - } - - public function doParse(PegpInput $input) - { - if (preg_match($this->expr, $input->pick(), $m)) { - return PegpResult::success( - $input->advance(strlen($m[0])), - $m - ); - } else { - return PegpResult::failure($input, $this); - } - } - - public function getComment() - { - if ($this->comment !== null) - return $this->comment; - else - return 'expr.'>'; - } -} - -class PegpSequence extends PegpParser -{ - private $parsers, $op = null; - - public function __construct(array $parsers) - { - $this->parsers = $parsers; - } - - public function doParse(PegpInput $input) - { - $inp = $input; - $result = array(); - foreach ($this->parsers as $parser) { - $r = $parser->parse($inp); - if ($r->isSuccess()) { - $inp = $r->input; - if ($r->result !== null) - $result[] = $r->result; - } else { - return PegpResult::failure($inp, $parser); - } - } - return PegpResult::success($inp, $result); - } - - protected function process($result) - { - switch ($this->op) { - case 'join': - $result = PegpResult::success($result->input, implode('', $result->result)); - break; - case 'bitOr': - $value = 0; - foreach ($result->result as $v) - $value |= $v; - $result = PegpResult::success($result->input, $value); - break; - case 'sum': - $value = 0; - foreach ($result->result as $v) - $value += $v; - $result = PegpResult::success($result->input, $value); - break; - case 'product': - $value = 1; - foreach ($result->result as $v) - $value *= $v; - $result = PegpResult::success($result->input, $value); - break; - } - return parent::process($result); - } - - public function join() - { - $this->op = 'join'; - return $this; - } - - public function bitOr() - { - $this->op = 'bitOr'; - return $this; - } - - public function sum() - { - $this->op = 'sum'; - return $this; - } - - public function product() - { - $this->op = 'product'; - return $this; - } -} - -class PegpOneOf extends PegpParser -{ - private $parsers; - - public function __construct(array $parsers) - { - $this->parsers = $parsers; - } - - public function doParse(PegpInput $input) - { - foreach ($this->parsers as $parser) { - $r = $parser->parse($input); - if ($r->isSuccess()) { - return $r; - } - } - return PegpResult::failure($input, $this); - } - - public function getComment() - { - if ($this->comment !== null) - return $this->comment; - $comment = array(); - foreach ($this->parsers as $parser) { - $comment[] = $parser->getComment(); - } - return 'one of: '.implode(', ', $comment); - } -} - -class PegpOptional extends PegpParser -{ - private $parser, $emptyValue; - - public function __construct(PegpParser $parser, $emptyValue='') - { - $this->parser = $parser; - $this->emptyValue = $emptyValue; - } - - public function doParse(PegpInput $input) - { - $r = $this->parser->parse($input); - if ($r->isSuccess()) { - return $r; - } else { - return PegpResult::success($input, $this->emptyValue); - } - } -} - diff --git a/src/result.php b/src/result.php deleted file mode 100644 index f2e559f..0000000 --- a/src/result.php +++ /dev/null @@ -1,30 +0,0 @@ -success = $success; - $this->input = $input; - $this->result = $result; - } - - public static function success(PegpInput $input, $result=null) - { - return new PegpResult(true, $input, $result); - } - - public static function failure(PegpInput $input, $parser=null) - { - return new PegpResult(false, $input, $parser); - } - - public function isSuccess() - { - return $this->success; - } -} - diff --git a/src/shortcuts.php b/src/shortcuts.php deleted file mode 100644 index 91efa2c..0000000 --- a/src/shortcuts.php +++ /dev/null @@ -1,35 +0,0 @@ -parse($i); - $this->assertInstanceOf('PegpResult', $r); - $inputAfter = $r->input; - $this->assertInstanceOf('PegpInput', $inputAfter); - - if (!$r->isSuccess()) { - echo 'Parse failed. Expected ' . $r->result . ' at ' . $r->input->pos . "\n"; - } - - $this->assertTrue($r->isSuccess()); - $this->assertEquals($i->data, $inputAfter->data); - $this->assertEquals($i->length, $inputAfter->length); - $this->assertEquals($i->length, $inputAfter->pos); - return $r->result; - } - - public function testString() - { - $p = Pegp::str('test'); - $this->assertParse($p, 'test'); - } - - public function testRegex() - { - $p = Pegp::re('te[xs]t'); - $this->assertParse($p, 'test'); - $this->assertParse($p, 'text'); - } - - public function testSQLStringLiteral() - { - $p = Pegp::re("'([^\\\\']*[\\\\']')*[^\\\\']*'"); - $this->assertParse($p, "''"); - $this->assertParse($p, "'Hello there'"); - $this->assertParse($p, "'Don\\'t worry. Be happy!'"); - $this->assertParse($p, "'Don''t worry. Be happy!'"); - } - - public function testDecimal() - { - $p = Pegp::re("\\d+(\\.\\d+)?"); - $r = $this->assertParse($p, '123.45'); - $this->assertEquals('.45', $r[1]); - } - - public function testSequence() - { - $word = Pegp::re('[a-z]+'); - $space = Pegp::re('\s+'); - $optSpace = Pegp::re('\s*'); - $punctuation = Pegp::re('[.!?]')->setComment('punctiation mark'); - $p = Pegp::seq($optSpace, $word, $space, $word, $space, $word, $optSpace, $punctuation, $optSpace); - - $r = $this->assertParse($p, "\thow are you \n ? "); - } -} - diff --git a/t/PropertiesTest.php b/t/PropertiesTest.php deleted file mode 100644 index 6e22b72..0000000 --- a/t/PropertiesTest.php +++ /dev/null @@ -1,53 +0,0 @@ -parse($i); - $this->assertInstanceOf('PegpResult', $r); - $inputAfter = $r->input; - $this->assertInstanceOf('PegpInput', $inputAfter); - - if (!$r->isSuccess()) { - echo 'Parse failed. Expected ' . $r->result->getComment() . ' at ' . $r->input->pos . "\n"; - } - - $this->assertTrue($r->isSuccess()); - $this->assertEquals($i->data, $inputAfter->data); - $this->assertEquals($i->length, $inputAfter->length); - $this->assertEquals($i->length, $inputAfter->pos); - $this->assertEquals($expected, $r->result); - } - - public function testProperties() - { - $p = - Pegp::oneOf( - Pegp::stri('default'), - Pegp::stri('us'), - Pegp::stri('european'), - Pegp::seq( - Pegp::optional( - Pegp::seq( - Pegp::oneOf( - Pegp::stri('big-endian'), - Pegp::stri('little-endian'), - Pegp::stri('middle-endian')), - Pegp::re('\s+')->drop())->join()), - Pegp::oneOf( - Pegp::stri('slashes')->value('/'), - Pegp::stri('dots')->value('.'), - Pegp::stri('hyphens')->value('-'), - Pegp::stri('spaces')->value(' ')))); - - $this->assertParse('us', $p, 'us'); - $this->assertParse(array('big-endian', '-'), $p, 'Big-endian hyphEns'); - $this->assertParse(array('little-endian', '.'), $p, 'little-endian dots'); - $this->assertParse(array('middle-endian', '/'), $p, 'Middle-Endian Slashes'); - $this->assertParse(array('big-endian', ' '), $p, 'big-endian spaces'); - $this->assertParse(array('', '-'), $p, 'Hyphens'); - } -} - diff --git a/test/CalculatorTest.php b/test/CalculatorTest.php new file mode 100644 index 0000000..e29bddd --- /dev/null +++ b/test/CalculatorTest.php @@ -0,0 +1,46 @@ +assertParse("test", $p, 'test'); + } + + public function testRegex() + { + $p = Pegp::re('te[xs]t'); + $this->assertParse(["test"], $p, 'test'); + $this->assertParse(["text"], $p, 'text'); + } + + public function testSQLStringLiteral() + { + $p = Pegp::re("'([^\\\\']*[\\\\']')*[^\\\\']*'"); + $this->assertParse(["''"], $p, "''"); + $this->assertParse(["'Hello there'"], $p, "'Hello there'"); + $this->assertParse(["'Don\\'test worry. Be happy!'", "Don\\'"], $p, "'Don\\'test worry. Be happy!'"); + $this->assertParse(["'Don''test worry. Be happy!'", "Don''"], $p, "'Don''test worry. Be happy!'"); + } + + public function testDecimal() + { + $p = Pegp::re("\\d+(\\.\\d+)?"); + $r = $this->assertParse(["123.45", ".45"], $p, '123.45'); + $this->assertEquals('.45', $r[1]); + } + + public function testSequence() + { + $word = Pegp::re('[a-z]+'); + $space = Pegp::re('\s+'); + $optSpace = Pegp::re('\s*'); + $punctuation = Pegp::re('[.!?]')->setComment('punctuation mark'); + $p = Pegp::seq($optSpace, $word, $space, $word, $space, $word, $optSpace, $punctuation, $optSpace); + + $this->assertParse([["\t"], ['how'], [' '], ['are'], [' '], ['you'], [" \n "], ['?'], [' ']], $p, "\thow are you \n ? "); + } +} diff --git a/test/ParserTestCase.php b/test/ParserTestCase.php new file mode 100644 index 0000000..fab646a --- /dev/null +++ b/test/ParserTestCase.php @@ -0,0 +1,65 @@ +parse($input); + + $this->assertParseResultSucceed($result); + $this->assertInputExhausted($input, $result->input); + + $this->assertEquals($expected, $result->result); + return $result->result; + } + + public function assertParseFailure(Parser $parser, $input) + { + $input = new Input($input); + $result = $parser->parse($input); + + $this->assertParseResultFailed($result); + } + + /** + * @param Result $result + */ + public function assertParseResultSucceed(Result $result) + { + $this->assertInstanceOf(Result::class, $result); + $this->assertInstanceOf(Input::class, $result->input); + if (!$result->isSuccess()) { + $this->fail(sprintf("Parse failed. Expected %s at %s.", $result->result->getComment(), $result->input->pos)); + } + } + + /** + * @param Result $result + */ + private function assertParseResultFailed(Result $result) + { + $this->assertInstanceOf(Result::class, $result); + $this->assertFalse($result->isSuccess()); + $this->assertInstanceOf(Input::class, $result->input); + } + + /** + * @param Input $inputBefore + * @param Input $inputAfter + */ + public function assertInputExhausted(Input $inputBefore, Input $inputAfter) + { + $this->assertInstanceOf(Input::class, $inputBefore); + $this->assertInstanceOf(Input::class, $inputAfter); + + $this->assertEquals($inputBefore->data, $inputAfter->data); + $this->assertEquals($inputBefore->length, $inputAfter->length); + $this->assertEquals($inputBefore->length, $inputAfter->pos); + } +} diff --git a/test/PropertiesTest.php b/test/PropertiesTest.php new file mode 100644 index 0000000..72b1b7c --- /dev/null +++ b/test/PropertiesTest.php @@ -0,0 +1,47 @@ +drop())->join()), + P::oneOf( + P::stri('slashes')->value('/'), + P::stri('dots')->value('.'), + P::stri('hyphens')->value('-'), + P::stri('spaces')->value(' ')))); + + $this->assertParse('us', $p, 'us'); + $this->assertParse(array('big-endian', '-'), $p, 'Big-endian hyphEns'); + $this->assertParse(array('little-endian', '.'), $p, 'little-endian dots'); + $this->assertParse(array('middle-endian', '/'), $p, 'Middle-Endian Slashes'); + $this->assertParse(array('big-endian', ' '), $p, 'big-endian spaces'); + $this->assertParse(array('', '-'), $p, 'Hyphens'); + } + + public function testRegexp() + { + $p = + P::seq( + P::re('\s+')->drop(), + P::re('\\d+')->group(0), + P::re('\s+')->drop())->join(); + + $this->assertParse('234', $p, ' 234 '); + $this->assertParseFailure($p, ''); + } +}