1: <?php
2: // Parco
3: // Copyright (c) 2015 Niels Sonnich Poulsen (http://nielssp.dk)
4: // Licensed under the MIT license.
5: // See the LICENSE file or http://opensource.org/licenses/MIT for more information.
6: namespace Parco;
7:
8: /**
9: * A parser constructed from a parse function.
10: */
11: class FuncParser extends Parser
12: {
13:
14: /**
15: * @var callable
16: */
17: private $func;
18:
19: /**
20: * Construct parser from parse function.
21: *
22: * @param callable $func
23: * Parse function, see {@see parse} for expected function
24: * signature.
25: */
26: public function __construct(callable $func)
27: {
28: $this->func = $func;
29: }
30:
31: /**
32: * {@inheritdoc}
33: */
34: public function parse($input, array $pos)
35: {
36: return call_user_func($this->func, $input, $pos);
37: }
38: }
39: