Passed
Push — master ( 1ee19c...3e5a10 )
by Kacper
02:56
created

PreProcessor::getRules()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 21
rs 9.3142
cc 1
eloc 14
nc 1
nop 0
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
}