1 | <?php |
||
26 | class Lexer |
||
27 | { |
||
28 | /** @var ParallelRegex[] */ |
||
29 | protected $regexes; |
||
30 | /** @var \Doku_Handler */ |
||
31 | protected $handler; |
||
32 | /** @var StateStack */ |
||
33 | protected $modeStack; |
||
34 | /** @var array mode "rewrites" */ |
||
35 | protected $mode_handlers; |
||
36 | /** @var bool case sensitive? */ |
||
37 | protected $case; |
||
38 | |||
39 | /** |
||
40 | * Sets up the lexer in case insensitive matching by default. |
||
41 | * |
||
42 | * @param \Doku_Handler $handler Handling strategy by reference. |
||
43 | * @param string $start Starting handler. |
||
44 | * @param boolean $case True for case sensitive. |
||
45 | */ |
||
46 | public function __construct($handler, $start = "accept", $case = false) |
||
54 | |||
55 | /** |
||
56 | * Adds a token search pattern for a particular parsing mode. |
||
57 | * |
||
58 | * The pattern does not change the current mode. |
||
59 | * |
||
60 | * @param string $pattern Perl style regex, but ( and ) |
||
61 | * lose the usual meaning. |
||
62 | * @param string $mode Should only apply this |
||
63 | * pattern when dealing with |
||
64 | * this type of input. |
||
65 | */ |
||
66 | public function addPattern($pattern, $mode = "accept") |
||
73 | |||
74 | /** |
||
75 | * Adds a pattern that will enter a new parsing mode. |
||
76 | * |
||
77 | * Useful for entering parenthesis, strings, tags, etc. |
||
78 | * |
||
79 | * @param string $pattern Perl style regex, but ( and ) lose the usual meaning. |
||
80 | * @param string $mode Should only apply this pattern when dealing with this type of input. |
||
81 | * @param string $new_mode Change parsing to this new nested mode. |
||
82 | */ |
||
83 | public function addEntryPattern($pattern, $mode, $new_mode) |
||
90 | |||
91 | /** |
||
92 | * Adds a pattern that will exit the current mode and re-enter the previous one. |
||
93 | * |
||
94 | * @param string $pattern Perl style regex, but ( and ) lose the usual meaning. |
||
95 | * @param string $mode Mode to leave. |
||
96 | */ |
||
97 | public function addExitPattern($pattern, $mode) |
||
104 | |||
105 | /** |
||
106 | * Adds a pattern that has a special mode. |
||
107 | * |
||
108 | * Acts as an entry and exit pattern in one go, effectively calling a special |
||
109 | * parser handler for this token only. |
||
110 | * |
||
111 | * @param string $pattern Perl style regex, but ( and ) lose the usual meaning. |
||
112 | * @param string $mode Should only apply this pattern when dealing with this type of input. |
||
113 | * @param string $special Use this mode for this one token. |
||
114 | */ |
||
115 | public function addSpecialPattern($pattern, $mode, $special) |
||
122 | |||
123 | /** |
||
124 | * Adds a mapping from a mode to another handler. |
||
125 | * |
||
126 | * @param string $mode Mode to be remapped. |
||
127 | * @param string $handler New target handler. |
||
128 | */ |
||
129 | public function mapHandler($mode, $handler) |
||
133 | |||
134 | /** |
||
135 | * Splits the page text into tokens. |
||
136 | * |
||
137 | * Will fail if the handlers report an error or if no content is consumed. If successful then each |
||
138 | * unparsed and parsed token invokes a call to the held listener. |
||
139 | * |
||
140 | * @param string $raw Raw HTML text. |
||
141 | * @return boolean True on success, else false. |
||
142 | */ |
||
143 | public function parse($raw) |
||
169 | |||
170 | /** |
||
171 | * Sends the matched token and any leading unmatched |
||
172 | * text to the parser changing the lexer to a new |
||
173 | * mode if one is listed. |
||
174 | * |
||
175 | * @param string $unmatched Unmatched leading portion. |
||
176 | * @param string $matched Actual token match. |
||
177 | * @param bool|string $mode Mode after match. A boolean false mode causes no change. |
||
178 | * @param int $initialPos |
||
179 | * @param int $matchPos Current byte index location in raw doc thats being parsed |
||
180 | * @return boolean False if there was any error from the parser. |
||
181 | */ |
||
182 | protected function dispatchTokens($unmatched, $matched, $mode, $initialPos, $matchPos) |
||
206 | |||
207 | /** |
||
208 | * Tests to see if the new mode is actually to leave the current mode and pop an item from the matching |
||
209 | * mode stack. |
||
210 | * |
||
211 | * @param string $mode Mode to test. |
||
212 | * @return boolean True if this is the exit mode. |
||
213 | */ |
||
214 | protected function isModeEnd($mode) |
||
218 | |||
219 | /** |
||
220 | * Test to see if the mode is one where this mode is entered for this token only and automatically |
||
221 | * leaves immediately afterwoods. |
||
222 | * |
||
223 | * @param string $mode Mode to test. |
||
224 | * @return boolean True if this is the exit mode. |
||
225 | */ |
||
226 | protected function isSpecialMode($mode) |
||
230 | |||
231 | /** |
||
232 | * Strips the magic underscore marking single token modes. |
||
233 | * |
||
234 | * @param string $mode Mode to decode. |
||
235 | * @return string Underlying mode name. |
||
236 | */ |
||
237 | protected function decodeSpecial($mode) |
||
241 | |||
242 | /** |
||
243 | * Calls the parser method named after the current mode. |
||
244 | * |
||
245 | * Empty content will be ignored. The lexer has a parser handler for each mode in the lexer. |
||
246 | * |
||
247 | * @param string $content Text parsed. |
||
248 | * @param boolean $is_match Token is recognised rather |
||
249 | * than unparsed data. |
||
250 | * @param int $pos Current byte index location in raw doc |
||
251 | * thats being parsed |
||
252 | * @return bool |
||
253 | */ |
||
254 | protected function invokeHandler($content, $is_match, $pos) |
||
273 | |||
274 | /** |
||
275 | * Tries to match a chunk of text and if successful removes the recognised chunk and any leading |
||
276 | * unparsed data. Empty strings will not be matched. |
||
277 | * |
||
278 | * @param string $raw The subject to parse. This is the content that will be eaten. |
||
279 | * @return array|bool Three item list of unparsed content followed by the |
||
280 | * recognised token and finally the action the parser is to take. |
||
281 | * True if no match, false if there is a parsing error. |
||
282 | */ |
||
283 | protected function reduce(&$raw) |
||
297 | |||
298 | /** |
||
299 | * Escapes regex characters other than (, ) and / |
||
300 | * |
||
301 | * @param string $str |
||
302 | * @return string |
||
303 | */ |
||
304 | public static function escape($str) |
||
347 | } |
||
348 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: