|
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\Language\Css; |
|
17
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
use Kadet\Highlighter\Language\Css; |
|
20
|
|
|
use Kadet\Highlighter\Matcher\CommentMatcher; |
|
21
|
|
|
use Kadet\Highlighter\Matcher\SubStringMatcher; |
|
22
|
|
|
use Kadet\Highlighter\Parser\Rule; |
|
23
|
|
|
|
|
24
|
|
|
abstract class PreProcessor extends Css |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* Tokenization rules |
|
28
|
|
|
* |
|
29
|
|
|
* @return \Kadet\Highlighter\Parser\Rule[]|\Kadet\Highlighter\Parser\Rule[][] |
|
30
|
|
|
*/ |
|
31
|
|
|
public function getRules() |
|
32
|
|
|
{ |
|
33
|
|
|
$rules = parent::getRules(); |
|
34
|
|
|
|
|
35
|
|
|
$rules['symbol.selector.class']->setContext(['!symbol', '!string', '!number', '!comment']); |
|
36
|
|
|
$rules['symbol.selector.tag']->setContext(['!symbol', '!string', '!number', '!comment']); |
|
37
|
|
|
$rules['symbol.selector.class.pseudo']->setContext(['!symbol', '!string', '!number', '!comment']); |
|
38
|
|
|
$rules['symbol.selector.id']->setContext(['!symbol', '!string', '!constant', '!comment']); |
|
39
|
|
|
$rules['constant.color']->setContext(['!string', '!symbol', '!comment']); |
|
40
|
|
|
|
|
41
|
|
|
$rules['operator.self'] = new Rule(new SubStringMatcher('&'), ['context' => $this->everywhere()]); |
|
42
|
|
|
$rules['number']->setContext(['!comment', '!symbol', '!constant', '!string', '!variable']); |
|
43
|
|
|
$rules['call'] ->setContext(['!comment', '!symbol', '!constant', '!string']); |
|
44
|
|
|
|
|
45
|
|
|
$rules['comment'] = [ |
|
46
|
|
|
$rules['comment'], |
|
47
|
|
|
new Rule(new CommentMatcher(['//'], []), ['context' => $rules['comment']->validator]) |
|
48
|
|
|
]; |
|
49
|
|
|
|
|
50
|
|
|
return $rules; |
|
51
|
|
|
} |
|
52
|
|
|
} |