Lines Matching refs:mode

27     /** @var array mode "rewrites" */
47 * Adds a token search pattern for a particular parsing mode.
49 * The pattern does not change the current mode.
53 * @param string $mode Should only apply this
57 public function addPattern($pattern, $mode = "accept")
59 if (! isset($this->regexes[$mode])) {
60 $this->regexes[$mode] = new ParallelRegex($this->case);
62 $this->regexes[$mode]->addPattern($pattern);
66 * Adds a pattern that will enter a new parsing mode.
71 * @param string $mode Should only apply this pattern when dealing with this type of input.
72 * @param string $new_mode Change parsing to this new nested mode.
74 public function addEntryPattern($pattern, $mode, $new_mode)
76 if (! isset($this->regexes[$mode])) {
77 $this->regexes[$mode] = new ParallelRegex($this->case);
79 $this->regexes[$mode]->addPattern($pattern, $new_mode);
83 * Adds a pattern that will exit the current mode and re-enter the previous one.
86 * @param string $mode Mode to leave.
88 public function addExitPattern($pattern, $mode)
90 if (! isset($this->regexes[$mode])) {
91 $this->regexes[$mode] = new ParallelRegex($this->case);
93 $this->regexes[$mode]->addPattern($pattern, "__exit");
97 * Adds a pattern that has a special mode.
103 * @param string $mode Should only apply this pattern when dealing with this type of input.
104 * @param string $special Use this mode for this one token.
106 public function addSpecialPattern($pattern, $mode, $special)
108 if (! isset($this->regexes[$mode])) {
109 $this->regexes[$mode] = new ParallelRegex($this->case);
111 $this->regexes[$mode]->addPattern($pattern, "_$special");
115 * Adds a mapping from a mode to another handler.
117 * @param string $mode Mode to be remapped.
120 public function mapHandler($mode, $handler)
122 $this->mode_handlers[$mode] = $handler;
143 [$unmatched, $matched, $mode] = $parsed;
146 if (! $this->dispatchTokens($unmatched, $matched, $mode, $pos, $matchPos)) {
162 * Gives plugins access to the mode stack
174 * mode if one is listed.
178 * @param bool|string $mode Mode after match. A boolean false mode causes no change.
183 protected function dispatchTokens($unmatched, $matched, $mode, $initialPos, $matchPos)
188 if ($this->isModeEnd($mode)) {
194 if ($this->isSpecialMode($mode)) {
195 $this->modeStack->enter($this->decodeSpecial($mode));
201 if (is_string($mode)) {
202 $this->modeStack->enter($mode);
209 * Tests to see if the new mode is actually to leave the current mode and pop an item from the matching
210 * mode stack.
212 * @param string $mode Mode to test.
213 * @return boolean True if this is the exit mode.
215 protected function isModeEnd($mode)
217 return ($mode === "__exit");
221 * Test to see if the mode is one where this mode is entered for this token only and automatically
224 * @param string $mode Mode to test.
225 * @return boolean True if this is the exit mode.
227 protected function isSpecialMode($mode)
229 return str_starts_with($mode, '_');
235 * @param string $mode Mode to decode.
236 * @return string Underlying mode name.
238 protected function decodeSpecial($mode)
240 return substr($mode, 1);
244 * Calls the parser method named after the current mode.
246 * Empty content will be ignored. The lexer has a parser handler for each mode in the lexer.