1 | <?php |
||
21 | class Highlighter |
||
22 | { |
||
23 | /** |
||
24 | * @var int |
||
25 | */ |
||
26 | private const CODE_SECTION_SIZE = 5; |
||
27 | |||
28 | /** |
||
29 | * @var array|LanguageInterface[] |
||
30 | */ |
||
31 | private $languages = []; |
||
32 | |||
33 | /** |
||
34 | * Highlighter constructor. |
||
35 | * @throws \InvalidArgumentException |
||
36 | * @throws \Railt\Lexer\Exception\BadLexemeException |
||
37 | */ |
||
38 | public function __construct() |
||
42 | |||
43 | /** |
||
44 | * @param LanguageInterface $language |
||
45 | */ |
||
46 | public function add(LanguageInterface $language): void |
||
50 | |||
51 | /** |
||
52 | * @param Readable $file |
||
53 | * @param int $line |
||
54 | * @return string |
||
55 | */ |
||
56 | public function highlight(Readable $file, int $line): string |
||
66 | |||
67 | /** |
||
68 | * @param LanguageInterface $language |
||
69 | * @param Readable $file |
||
70 | * @param int $errorLine |
||
71 | * @return string |
||
72 | */ |
||
73 | private function renderLanguage(LanguageInterface $language, Readable $file, int $errorLine): string |
||
96 | |||
97 | /** |
||
98 | * @param TokenInterface $token |
||
99 | * @return iterable|TokenInterface[] |
||
100 | */ |
||
101 | private function splitToken(TokenInterface $token): iterable |
||
119 | |||
120 | /** |
||
121 | * @param int $errorLine |
||
122 | * @param int $current |
||
123 | * @return bool |
||
124 | */ |
||
125 | private function isRenderable(int $errorLine, int $current): bool |
||
131 | |||
132 | /** |
||
133 | * @param TokenInterface $token |
||
134 | * @param int $line |
||
135 | * @param bool $start |
||
136 | * @return string |
||
137 | */ |
||
138 | private function renderErrorToken(TokenInterface $token, int $line, bool $start): string |
||
144 | |||
145 | /** |
||
146 | * @param LanguageInterface $language |
||
147 | * @param TokenInterface $token |
||
148 | * @param int $line |
||
149 | * @param bool $start |
||
150 | * @return string |
||
151 | */ |
||
152 | private function renderBasicToken(LanguageInterface $language, TokenInterface $token, int $line, bool $start): string |
||
158 | } |
||
159 |