|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Highlighter |
|
4
|
|
|
* |
|
5
|
|
|
* Copyright (C) 2016, Some right reserved. |
|
6
|
|
|
* |
|
7
|
|
|
* @author Kacper "Kadet" Donat <[email protected]> |
|
8
|
|
|
* |
|
9
|
|
|
* Contact with author: |
|
10
|
|
|
* Xmpp: [email protected] |
|
11
|
|
|
* E-mail: [email protected] |
|
12
|
|
|
* |
|
13
|
|
|
* From Kadet with love. |
|
14
|
|
|
*/ |
|
15
|
|
|
|
|
16
|
|
|
namespace Kadet\Highlighter\Parser\Token; |
|
17
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
use Kadet\Highlighter\Language\Language; |
|
20
|
|
|
use Kadet\Highlighter\Parser\Context; |
|
21
|
|
|
use Kadet\Highlighter\Parser\Result; |
|
22
|
|
|
use Kadet\Highlighter\Parser\TokenIterator; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Class TerminatorToken |
|
26
|
|
|
* |
|
27
|
|
|
* @package Kadet\Highlighter\Parser\Token |
|
28
|
|
|
* |
|
29
|
|
|
* @property array $closes |
|
30
|
|
|
*/ |
|
31
|
|
|
class TerminatorToken extends MetaToken |
|
32
|
|
|
{ |
|
33
|
2 |
|
protected function validate(Context $context) |
|
34
|
|
|
{ |
|
35
|
2 |
|
$this->setValid( |
|
36
|
2 |
|
$context->language === $this->rule->language && |
|
37
|
1 |
|
$this->rule->validator->validate($context) |
|
38
|
2 |
|
); |
|
39
|
2 |
|
} |
|
40
|
|
|
|
|
41
|
1 |
|
protected function processStart(Context $context, Language $language, Result $result, TokenIterator $tokens) |
|
42
|
|
|
{ |
|
43
|
1 |
|
return true; // That type of token makes no sense as start, just omit it. |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
protected function processEnd(Context $context, Language $language, Result $result, TokenIterator $tokens) |
|
47
|
|
|
{ |
|
48
|
1 |
|
foreach(array_filter($context->stack, function ($name) { |
|
49
|
1 |
|
return in_array($name, $this->closes); |
|
50
|
1 |
|
}) as $hash => $name) { |
|
51
|
1 |
|
$end = new Token($name, ['pos' => $this->pos]); |
|
52
|
1 |
|
$tokens[$hash]->setEnd($end); |
|
53
|
1 |
|
$result->append($end); |
|
54
|
|
|
|
|
55
|
1 |
|
unset($context->stack[$hash]); |
|
56
|
1 |
|
} |
|
57
|
|
|
|
|
58
|
1 |
|
return true; |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|