Completed
Push — master ( 825d10...9b831d )
by Kacper
02:51
created

Cpp   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 1
cbo 5
dl 0
loc 39
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B setupRules() 0 31 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;
17
18
19
use Kadet\Highlighter\Matcher\RegexMatcher;
20
use Kadet\Highlighter\Matcher\WordMatcher;
21
use Kadet\Highlighter\Parser\Rule;
22
use Kadet\Highlighter\Parser\Token\Token;
23
24
class Cpp extends C
25
{
26
    public function setupRules()
27
    {
28
        parent::setupRules();
29
30
        $this->rules->remove('keyword');
31
        $this->rules->remove('symbol.type', 0);
32
33
        $this->rules->add('keyword', new Rule(
34
            new WordMatcher([
35
                'auto', 'align(?:as|of)', 'and(?:_eq)?', 'asm', 'auto', 'bit(and|or)', 'break', 'case', 'catch', 'class',
36
                'compl', 'concept', 'const(?:_cast|expr)?', 'continue', 'decltype', 'default', 'delete', 'do', 'double',
37
                'dynamic_cast', 'else', 'enum', 'explicit', 'export', 'extern', 'for', 'friend', 'goto', 'if', 'inline',
38
                'mutable', 'namespace', 'new', 'noexcept', 'not(?:_eq|ptr)', 'operator', 'or(?:_eq)?', 'private',
39
                'protected', 'public', 'register', 'reinterpret_cast', 'requires', 'return', 'sizeof',
40
                'static(?:_assert|_cast)?', 'struct', 'switch', 'template', 'thread_local', 'throw', 'try', 'typedef',
41
                'typeid', 'typename', 'union', 'using', 'virtual', 'volatile', 'while', 'xor(?:_eq)?',
42
            ], ['escape' => false]), [
43
                'priority' => 2
44
            ]
45
        ));
46
47
        $this->rules->add('symbol.type', new Rule(new WordMatcher(['bool', 'wchar'])));
48
        $this->rules->add('constant.special', new Rule(new WordMatcher(['false', 'null', 'true'])));
49
        $this->rules->add('symbol.class', new Rule(new RegexMatcher('/(\w+)(?:\s+|\s*[*&]\s*)\w+\s*[={}();,]/')));
50
        $this->rules->add('symbol.class.template', new Rule(new RegexMatcher('/(\w+)\s*<.*?>/')));
51
52
        $this->rules->add('symbol.namespace', new Rule(new RegexMatcher('/((?::)?(\w+::)+)(\w+)/', [
53
            1 => Token::NAME,
54
            2 => 'symbol.class'
55
        ])));
56
    }
57
58
    public function getIdentifier()
59
    {
60
        return 'cpp';
61
    }
62
}
63