Passed
Push — master ( ad0973...f9c297 )
by Kacper
02:48
created

PreProcessor::outside()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
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
use Kadet\Highlighter\Parser\Validator\Validator;
24
25
abstract class PreProcessor extends Css
26
{
27
    /**
28
     * Tokenization rules
29
     *
30
     * @return \Kadet\Highlighter\Parser\Rule[]|\Kadet\Highlighter\Parser\Rule[][]
31
     */
32
    public function setupRules()
33
    {
34
        parent::setupRules();
35
36
        $this->rules->rule('symbol.selector.class')->setContext($this->outside());
37
        $this->rules->rule('symbol.selector.tag')->setContext($this->outside());
38
        $this->rules->rule('symbol.selector.class.pseudo')->setContext($this->outside());
39
        $this->rules->rule('symbol.selector.id')->setContext($this->outside());
40
41
        $this->rules->rule('constant.color')->setContext(['!string', '!symbol', '!comment']);
42
        $this->rules->rule('number')->setContext(['!comment', '!symbol', '!constant', '!string', '!variable']);
43
        $this->rules->rule('call')->setContext(['!comment', '!symbol', '!constant', '!string']);
44
45
        $this->rules->add('operator.self', new Rule(new SubStringMatcher('&'), ['context' => $this->everywhere()]));
46
47
        $this->rules->add(
48
            'comment.multiline',
49
            new Rule(new CommentMatcher(['//'], []), ['context' => $this->rules->rule('comment')->validator])
50
        );
51
    }
52
53
    protected function outside() {
54
        return new Validator(['!symbol', '!string', '!number', '!comment', '!constant']);
55
    }
56
}