1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Hoa |
7
|
|
|
* |
8
|
|
|
* |
9
|
|
|
* |
10
|
|
|
* |
11
|
|
|
* BSD 3-Clause License |
12
|
|
|
* |
13
|
|
|
* Copyright © 2007-2017, Hoa community. All rights reserved. |
14
|
|
|
* |
15
|
|
|
* Redistribution and use in source and binary forms, with or without |
16
|
|
|
* modification, are permitted provided that the following conditions are met: |
17
|
|
|
* |
18
|
|
|
* 1. Redistributions of source code must retain the above copyright notice, this |
19
|
|
|
* list of conditions and the following disclaimer. |
20
|
|
|
* |
21
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice, |
22
|
|
|
* this list of conditions and the following disclaimer in the documentation |
23
|
|
|
* and/or other materials provided with the distribution. |
24
|
|
|
* |
25
|
|
|
* 3. Neither the name of the copyright holder nor the names of its |
26
|
|
|
* contributors may be used to endorse or promote products derived from |
27
|
|
|
* this software without specific prior written permission. |
28
|
|
|
* |
29
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
30
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
31
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
32
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
33
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
34
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
35
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
36
|
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
37
|
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
38
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
39
|
|
|
*/ |
40
|
|
|
|
41
|
|
|
namespace JMS\Serializer\Type\Compiler\Llk\Rule; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Class \JMS\Serializer\Type\Compiler\Llk\Rule\Invocation. |
45
|
|
|
* |
46
|
|
|
* Parent of entry and ekzit rules. |
47
|
|
|
*/ |
48
|
|
|
abstract class Invocation |
49
|
|
|
{ |
50
|
|
|
/** |
51
|
|
|
* Rule. |
52
|
|
|
* |
53
|
|
|
* @var string|null |
54
|
|
|
*/ |
55
|
|
|
protected $_rule = null; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Data. |
59
|
|
|
* |
60
|
|
|
* @var mixed |
61
|
|
|
*/ |
62
|
|
|
protected $_data = null; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Piece of todo sequence. |
66
|
|
|
* |
67
|
|
|
* @var array|null |
68
|
|
|
*/ |
69
|
|
|
protected $_todo = null; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Depth in the trace. |
73
|
|
|
* |
74
|
|
|
* @var int |
75
|
|
|
*/ |
76
|
|
|
protected $_depth = -1; |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Whether the rule is transitional or not (i.e. not declared in the grammar |
80
|
|
|
* but created by the analyzer). |
81
|
|
|
* |
82
|
|
|
* @var bool |
83
|
|
|
*/ |
84
|
|
|
protected $_transitional = false; |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @param string|int $rule Rule name. |
88
|
|
|
* @param mixed $data Data. |
89
|
|
|
* @param array $todo Todo. |
90
|
|
|
* @param int $depth Depth. |
91
|
|
|
*/ |
92
|
|
|
public function __construct( |
93
|
|
|
$rule, |
94
|
|
|
$data, |
95
|
|
|
?array $todo = null, |
96
|
|
|
$depth = -1 |
97
|
|
|
) { |
98
|
|
|
$this->_rule = $rule; |
99
|
|
|
$this->_data = $data; |
100
|
|
|
$this->_todo = $todo; |
101
|
|
|
$this->_depth = $depth; |
102
|
|
|
$this->_transitional = \is_int($rule); |
103
|
|
|
|
104
|
|
|
return; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Get rule name. |
109
|
|
|
* |
110
|
|
|
* @return string|int |
111
|
|
|
*/ |
112
|
|
|
public function getRule() |
113
|
|
|
{ |
114
|
|
|
return $this->_rule; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Get data. |
119
|
|
|
* |
120
|
|
|
* @return mixed |
121
|
|
|
*/ |
122
|
|
|
public function getData() |
123
|
|
|
{ |
124
|
|
|
return $this->_data; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Get todo sequence. |
129
|
|
|
* |
130
|
|
|
* @return array |
131
|
|
|
*/ |
132
|
|
|
public function getTodo(): array |
133
|
|
|
{ |
134
|
|
|
return $this->_todo; |
|
|
|
|
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Set depth in trace. |
139
|
|
|
* |
140
|
|
|
* @param int $depth Depth. |
141
|
|
|
*/ |
142
|
|
|
public function setDepth(int $depth): int |
143
|
|
|
{ |
144
|
|
|
$old = $this->_depth; |
145
|
|
|
$this->_depth = $depth; |
146
|
|
|
|
147
|
|
|
return $old; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* Get depth in trace. |
152
|
|
|
*/ |
153
|
|
|
public function getDepth(): int |
154
|
|
|
{ |
155
|
|
|
return $this->_depth; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* Check whether the rule is transitional or not. |
160
|
|
|
*/ |
161
|
|
|
public function isTransitional(): bool |
162
|
|
|
{ |
163
|
|
|
return $this->_transitional; |
164
|
|
|
} |
165
|
|
|
} |
166
|
|
|
|