Completed
Push — master ( 6054a8...c11aa8 )
by Kacper
04:06
created

Sass::getMetadata()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 8
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
c 0
b 0
f 0
nc 1
nop 0
dl 8
loc 8
rs 9.4285
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\Rule;
20
use Kadet\Highlighter\Parser\Token\MetaToken;
21
use Kadet\Highlighter\Parser\Token\Token;
22
use Kadet\Highlighter\Parser\TokenFactory;
23
use Kadet\Highlighter\Parser\Validator\Validator;
24
25
class Sass extends Scss
26
{
27
28
    /**
29
     * Tokenization rules
30
     */
31
    public function setupRules()
32
    {
33
        parent::setupRules();
34
35
        $this->rules->remove('meta.declaration');
36
        $this->rules->remove('meta.declaration.media');
37
38
        $this->rules->add('meta.selector', new Rule(new RegexMatcher('/(?=(?:\n+|^)(\h*)([^\h].*)\n+\1\h+)/', [
39
            2 => Token::NAME
40
        ]), [
41
            'context'  => Validator::everywhere(),
42
            'priority' => 3,
43
            'factory'  => new TokenFactory(MetaToken::class)
44
        ]));
45
46
        $this->rules->add('meta.declaration', new Rule(new RegexMatcher('/\n((?:\h+.*?(?>\n|$)+)+)/'), [
47
            'context'  => Validator::everywhere(),
48
            'priority' => 2,
49
            'factory'  => new TokenFactory(MetaToken::class)
50
        ]));
51
52
        $this->rules->add('meta.declaration.media', new Rule(new RegexMatcher('/@media(.*?)\n/'), [
53
            'context' => Validator::everywhere(),
54
            'factory' => new TokenFactory(MetaToken::class)
55
        ]));
56
57
        $this->rules->add('symbol.selector.tag', new Rule(new RegexMatcher('/\b([a-z-][\w-]*)/'), [
58
            'context' => ['meta.selector', '!symbol', '!meta.declaration.media'],
59
        ]));
60
61
        $this->rules->rule('symbol.selector.class')->setContext(['meta.selector']);
62
        $this->rules->rule('keyword.at-rule')->setContext(['meta.selector']);
63
        $this->rules->rule('symbol.selector.class.pseudo')->setContext(['meta.selector']);
64
        $this->rules->rule('symbol.selector.id')->setContext(['meta.selector']);
65
    }
66
67
    public function getIdentifier()
68
    {
69
        return 'sass';
70
    }
71
72 View Code Duplication
    public static function getMetadata()
73
    {
74
        return [
75
            'name'      => ['sass'],
76
            'mime'      => ['text/x-sass'],
77
            'extension' => ['*.sass']
78
        ];
79
    }
80
}
81