1 | <?php |
||
16 | class Symbol { |
||
17 | /** |
||
18 | * @var string |
||
19 | */ |
||
20 | protected $regexp; |
||
21 | |||
22 | /** |
||
23 | * @var int |
||
24 | */ |
||
25 | protected $binding_power; |
||
26 | |||
27 | /** |
||
28 | * This defines what a token means when appearing in the initial position |
||
29 | * of an expression. |
||
30 | * |
||
31 | * @var \Closure |
||
32 | */ |
||
33 | protected $null_denotation = null; |
||
34 | |||
35 | /** |
||
36 | * This defines what a token means when appearing inside an expression |
||
37 | * to the left of the rest. |
||
38 | * |
||
39 | * @var \Closure |
||
40 | */ |
||
41 | protected $left_denotation = null; |
||
42 | |||
43 | 51 | public function __construct($regexp, $binding_power) { |
|
44 | 51 | assert('is_string($regexp)'); |
|
45 | 51 | if (!is_string($regexp) || @preg_match("%$regexp%", "") === false) { |
|
46 | 1 | throw new \InvalidArgumentException("Invalid regexp: '%$regexp%'"); |
|
47 | } |
||
48 | 50 | assert('is_int($binding_power)'); |
|
49 | 50 | assert('$binding_power >= 0'); |
|
50 | 50 | $this->regexp = $regexp; |
|
51 | 50 | $this->binding_power = $binding_power; |
|
52 | 50 | } |
|
53 | |||
54 | /** |
||
55 | * @return string |
||
56 | */ |
||
57 | 43 | public function regexp() { |
|
60 | |||
61 | /** |
||
62 | * @return int |
||
63 | */ |
||
64 | 31 | public function binding_power() { |
|
67 | |||
68 | /** |
||
69 | * @param \Closure $led |
||
70 | * @return self |
||
71 | */ |
||
72 | 38 | public function null_denotation_is(\Closure $led) { |
|
77 | |||
78 | /** |
||
79 | * @param array $matches |
||
80 | * @return mixed |
||
81 | */ |
||
82 | 33 | public function null_denotation(array &$matches) { |
|
86 | |||
87 | /** |
||
88 | * @param \Closure $led |
||
89 | * @return self |
||
90 | */ |
||
91 | 38 | public function left_denotation_is(\Closure $led) { |
|
96 | |||
97 | /** |
||
98 | * @param mixed $left |
||
99 | * @param array $matches |
||
100 | * @return mixed |
||
101 | */ |
||
102 | 22 | public function left_denotation($left, array &$matches) { |
|
106 | |||
107 | // HELPER |
||
108 | |||
109 | 35 | protected function denotation($which, array &$matches) { |
|
118 | } |
||
119 |