Passed
Push — master ( f247da...c8939d )
by Kacper
02:56
created

Sass   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 2
c 2
b 0
f 0
lcom 0
cbo 4
dl 0
loc 42
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B getRules() 0 33 1
A getIdentifier() 0 4 1
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
use Kadet\Highlighter\Matcher\RegexMatcher;
19
use Kadet\Highlighter\Parser\MetaToken;
20
use Kadet\Highlighter\Parser\Rule;
21
use Kadet\Highlighter\Parser\Token;
22
use Kadet\Highlighter\Parser\TokenFactory;
23
24
class Sass extends Scss
25
{
26
    
27
    public function getRules()
28
    {
29
        $rules                  = parent::getRules();
30
        $rules['meta.selector'] = new Rule(new RegexMatcher('/(?=(?:\n+|^)(\h*)([^\h].*)\n+\1\h+)/', [
31
            2 => Token::NAME
32
        ]), [
33
            'context'  => Rule::everywhere(),
34
            'priority' => 3,
35
            'factory'  => new TokenFactory(MetaToken::class)
36
        ]);
37
38
        $rules['meta.declaration'] = new Rule(new RegexMatcher('/\n((?:\h+.*?(?>\n|$)+)+)/'), [
39
            'context'  => Rule::everywhere(),
40
            'priority' => 2,
41
            'factory'  => new TokenFactory(MetaToken::class)
42
        ]);
43
44
        $rules['meta.declaration.media'] = new Rule(new RegexMatcher('/@media(.*?)/'), [
45
            'context' => Rule::everywhere(),
46
            'factory' => new TokenFactory(MetaToken::class)
47
        ]);
48
49
        $rules['symbol.selector.tag'] = new Rule(new RegexMatcher('/([\w-]+)/'), [
50
            'context' => ['meta.selector', '!symbol', '!meta.declaration.media'],
51
        ]);
52
        $rules['symbol.selector.class']->setContext(['meta.selector']);
53
        $rules['symbol.selector.class.pseudo']->setContext(['meta.selector']);
54
        $rules['symbol.selector.id']->setContext(['meta.selector']);
55
        $rules['number']->setContext(['!meta.selector', '!symbol', '!constant', '!comment']);
56
        $rules['keyword.special']->setContext(['meta.selector']);
57
58
        return $rules;
59
    }
60
61
    public function getIdentifier()
62
    {
63
        return 'sass';
64
    }
65
}
66