]> git.andy128k.dev Git - pegp.git/commitdiff
version 0.1 0.1
authorAndrey Kutejko <andy128k@gmail.com>
Wed, 26 Feb 2014 22:19:47 +0000 (00:19 +0200)
committerAndrey Kutejko <andy128k@gmail.com>
Wed, 26 Feb 2014 22:19:47 +0000 (00:19 +0200)
composer.json
composer.lock
lib/input.php [deleted file]
lib/parser.php [deleted file]
lib/result.php [deleted file]
lib/shortcuts.php [deleted file]
src/input.php [new file with mode: 0644]
src/parser.php [new file with mode: 0644]
src/result.php [new file with mode: 0644]
src/shortcuts.php [new file with mode: 0644]

index 269856a4e78e2843748c39a6fd08d100baedd5bb..955208ceea4cf42a7fd756464f63e49ef9119826 100644 (file)
@@ -9,10 +9,15 @@
     }
   ],
   "autoload": {
-    "classmap" : ["lib"]
+    "classmap" : ["src/"]
   },
   "require-dev": {
     "phpunit/phpunit": "3.7.*"
+  },
+  "extra": {
+    "branch-alias": {
+      "dev-master": "0.x-dev"
+    }
   }
 }
 
index 2b4d50af05f41a333b96e96208a0fa8a7a85315a..fc6fa554b207957d4b7332dbac477bb222f4ac5f 100644 (file)
@@ -3,29 +3,29 @@
         "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"
     ],
-    "hash": "3e9668f4e1ddee877ae96c3d3e4cd05f",
+    "hash": "eb85076530a748960ba58f2d2d0e852b",
     "packages": [
 
     ],
     "packages-dev": [
         {
             "name": "phpunit/php-code-coverage",
-            "version": "1.2.12",
+            "version": "1.2.16",
             "source": {
                 "type": "git",
                 "url": "https://github.com/sebastianbergmann/php-code-coverage.git",
-                "reference": "1.2.12"
+                "reference": "69e55e68481cf708a6db43aff0b504e31402fe27"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/1.2.12",
-                "reference": "1.2.12",
+                "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/69e55e68481cf708a6db43aff0b504e31402fe27",
+                "reference": "69e55e68481cf708a6db43aff0b504e31402fe27",
                 "shasum": ""
             },
             "require": {
                 "php": ">=5.3.3",
                 "phpunit/php-file-iterator": ">=1.3.0@stable",
-                "phpunit/php-text-template": ">=1.1.1@stable",
+                "phpunit/php-text-template": ">=1.2.0@stable",
                 "phpunit/php-token-stream": ">=1.1.3@stable"
             },
             "require-dev": {
                 "testing",
                 "xunit"
             ],
-            "time": "2013-07-06 06:26:16"
+            "time": "2014-02-25 03:34:05"
         },
         {
             "name": "phpunit/php-file-iterator",
-            "version": "1.3.3",
+            "version": "1.3.4",
             "source": {
                 "type": "git",
-                "url": "git://github.com/sebastianbergmann/php-file-iterator.git",
-                "reference": "1.3.3"
+                "url": "https://github.com/sebastianbergmann/php-file-iterator.git",
+                "reference": "acd690379117b042d1c8af1fafd61bde001bf6bb"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://github.com/sebastianbergmann/php-file-iterator/zipball/1.3.3",
-                "reference": "1.3.3",
+                "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/acd690379117b042d1c8af1fafd61bde001bf6bb",
+                "reference": "acd690379117b042d1c8af1fafd61bde001bf6bb",
                 "shasum": ""
             },
             "require": {
                 }
             ],
             "description": "FilterIterator implementation that filters files based on a list of suffixes.",
-            "homepage": "http://www.phpunit.de/",
+            "homepage": "https://github.com/sebastianbergmann/php-file-iterator/",
             "keywords": [
                 "filesystem",
                 "iterator"
             ],
-            "time": "2012-10-11 04:44:38"
+            "time": "2013-10-10 15:34:57"
         },
         {
             "name": "phpunit/php-text-template",
-            "version": "1.1.4",
+            "version": "1.2.0",
             "source": {
                 "type": "git",
-                "url": "git://github.com/sebastianbergmann/php-text-template.git",
-                "reference": "1.1.4"
+                "url": "https://github.com/sebastianbergmann/php-text-template.git",
+                "reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://github.com/sebastianbergmann/php-text-template/zipball/1.1.4",
-                "reference": "1.1.4",
+                "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/206dfefc0ffe9cebf65c413e3d0e809c82fbf00a",
+                "reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a",
                 "shasum": ""
             },
             "require": {
             "keywords": [
                 "template"
             ],
-            "time": "2012-10-31 11:15:28"
+            "time": "2014-01-30 17:20:04"
         },
         {
             "name": "phpunit/php-timer",
         },
         {
             "name": "phpunit/php-token-stream",
-            "version": "1.2.0",
+            "version": "1.2.1",
             "source": {
                 "type": "git",
                 "url": "https://github.com/sebastianbergmann/php-token-stream.git",
-                "reference": "1.2.0"
+                "reference": "5220af2a7929aa35cf663d97c89ad3d50cf5fa3e"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/1.2.0",
-                "reference": "1.2.0",
+                "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/5220af2a7929aa35cf663d97c89ad3d50cf5fa3e",
+                "reference": "5220af2a7929aa35cf663d97c89ad3d50cf5fa3e",
                 "shasum": ""
             },
             "require": {
             "keywords": [
                 "tokenizer"
             ],
-            "time": "2013-08-04 05:57:48"
+            "time": "2013-09-13 04:58:23"
         },
         {
             "name": "phpunit/phpunit",
-            "version": "3.7.23",
+            "version": "3.7.32",
             "source": {
                 "type": "git",
                 "url": "https://github.com/sebastianbergmann/phpunit.git",
-                "reference": "3.7.23"
+                "reference": "2752cbb9ea5bd84c2811b34b6953f76965ec7a2f"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/3.7.23",
-                "reference": "3.7.23",
+                "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/2752cbb9ea5bd84c2811b34b6953f76965ec7a2f",
+                "reference": "2752cbb9ea5bd84c2811b34b6953f76965ec7a2f",
                 "shasum": ""
             },
             "require": {
                 "symfony/yaml": "~2.0"
             },
             "require-dev": {
-                "pear-pear/pear": "1.9.4"
+                "pear-pear.php.net/pear": "1.9.4"
             },
             "suggest": {
                 "ext-json": "*",
                 "testing",
                 "xunit"
             ],
-            "time": "2013-08-02 19:14:44"
+            "time": "2014-02-25 03:47:29"
         },
         {
             "name": "phpunit/phpunit-mock-objects",
         },
         {
             "name": "symfony/yaml",
-            "version": "v2.3.2",
+            "version": "v2.4.2",
             "target-dir": "Symfony/Component/Yaml",
             "source": {
                 "type": "git",
                 "url": "https://github.com/symfony/Yaml.git",
-                "reference": "v2.3.2"
+                "reference": "bb6ddaf8956139d1b8c360b4b713ed0138e876b3"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/symfony/Yaml/zipball/v2.3.2",
-                "reference": "v2.3.2",
+                "url": "https://api.github.com/repos/symfony/Yaml/zipball/bb6ddaf8956139d1b8c360b4b713ed0138e876b3",
+                "reference": "bb6ddaf8956139d1b8c360b4b713ed0138e876b3",
                 "shasum": ""
             },
             "require": {
             "type": "library",
             "extra": {
                 "branch-alias": {
-                    "dev-master": "2.3-dev"
+                    "dev-master": "2.4-dev"
                 }
             },
             "autoload": {
             "authors": [
                 {
                     "name": "Fabien Potencier",
-                    "email": "fabien@symfony.com"
+                    "email": "fabien@symfony.com",
+                    "homepage": "http://fabien.potencier.org",
+                    "role": "Lead Developer"
                 },
                 {
                     "name": "Symfony Community",
             ],
             "description": "Symfony Yaml Component",
             "homepage": "http://symfony.com",
-            "time": "2013-07-11 19:36:36"
+            "time": "2014-01-07 13:28:54"
         }
     ],
     "aliases": [
diff --git a/lib/input.php b/lib/input.php
deleted file mode 100644 (file)
index 9441af4..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-<?php
-
-class PegpInput
-{
-    public $data, $length, $pos;
-
-    public function __construct($data, $length=null, $pos=0)
-    {
-        $this->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/lib/parser.php b/lib/parser.php
deleted file mode 100644 (file)
index 5f2950a..0000000
+++ /dev/null
@@ -1,260 +0,0 @@
-<?php
-
-abstract class PegpParser
-{
-    public $comment = null;
-    private $drop = false;
-    private $value = null;
-
-    public function parseString($string)
-    {
-        $input = new PegpInput($string);
-        $result = $this->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 '<string '.$this->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 '<regexp '.$this->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/lib/result.php b/lib/result.php
deleted file mode 100644 (file)
index f2e559f..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-<?php
-
-class PegpResult
-{
-    private $success;
-    public $input, $result;
-
-    public function __construct($success, PegpInput $input, $result=null)
-    {
-        $this->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/lib/shortcuts.php b/lib/shortcuts.php
deleted file mode 100644 (file)
index 91efa2c..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-<?php
-
-final class Pegp
-{
-    public static function str($str)
-    {
-        return new PegpString($str);
-    }
-
-    public static function stri($str)
-    {
-        return new PegpString($str, true);
-    }
-
-    public static function re($expr, $flags='', $delimiter='#')
-    {
-        return new PegpRegex($expr, $flags, $delimiter);
-    }
-
-    public static function seq()
-    {
-        return new PegpSequence(func_get_args());
-    }
-
-    public static function oneOf()
-    {
-        return new PegpOneOf(func_get_args());
-    }
-
-    public static function optional($parser, $emptyValue='')
-    {
-        return new PegpOptional($parser, $emptyValue);
-    }
-}
-
diff --git a/src/input.php b/src/input.php
new file mode 100644 (file)
index 0000000..9441af4
--- /dev/null
@@ -0,0 +1,28 @@
+<?php
+
+class PegpInput
+{
+    public $data, $length, $pos;
+
+    public function __construct($data, $length=null, $pos=0)
+    {
+        $this->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
new file mode 100644 (file)
index 0000000..5f2950a
--- /dev/null
@@ -0,0 +1,260 @@
+<?php
+
+abstract class PegpParser
+{
+    public $comment = null;
+    private $drop = false;
+    private $value = null;
+
+    public function parseString($string)
+    {
+        $input = new PegpInput($string);
+        $result = $this->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 '<string '.$this->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 '<regexp '.$this->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
new file mode 100644 (file)
index 0000000..f2e559f
--- /dev/null
@@ -0,0 +1,30 @@
+<?php
+
+class PegpResult
+{
+    private $success;
+    public $input, $result;
+
+    public function __construct($success, PegpInput $input, $result=null)
+    {
+        $this->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
new file mode 100644 (file)
index 0000000..91efa2c
--- /dev/null
@@ -0,0 +1,35 @@
+<?php
+
+final class Pegp
+{
+    public static function str($str)
+    {
+        return new PegpString($str);
+    }
+
+    public static function stri($str)
+    {
+        return new PegpString($str, true);
+    }
+
+    public static function re($expr, $flags='', $delimiter='#')
+    {
+        return new PegpRegex($expr, $flags, $delimiter);
+    }
+
+    public static function seq()
+    {
+        return new PegpSequence(func_get_args());
+    }
+
+    public static function oneOf()
+    {
+        return new PegpOneOf(func_get_args());
+    }
+
+    public static function optional($parser, $emptyValue='')
+    {
+        return new PegpOptional($parser, $emptyValue);
+    }
+}
+