Completed
Push — master ( 801377...5f0e58 )
by Kacper
02:48
created

CSharp   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 1
cbo 6
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\OpenRule;
22
use Kadet\Highlighter\Parser\Rule;
23
24
class CSharp extends C
25
{
26
    public function setupRules()
27
    {
28
        parent::setupRules();
29
30
        $this->rules->remove('preprocessor');
31
        $this->rules->remove('call.preprocessor');
32
33
        $this->rules->add('preprocessor', new OpenRule(new RegexMatcher('/^\s*(#)/m')));
34
        $this->rules->add('call.preprocessor', new Rule(new RegexMatcher('/^\s*#(\w+)/m'), [
35
            'context' => ['preprocessor']
36
        ]));
37
38
        $this->rules->remove('keyword');
39
        $this->rules->remove('symbol.type', 0);
40
41
        $this->rules->add('keyword', new Rule(new WordMatcher([
42
            'abstract', 'as', 'base', 'bool', 'break', 'case', 'catch', 'char', 'checked', 'class', 'const', 'continue',
43
            'default', 'delegate', 'do', 'else', 'enum', 'event', 'explicit', 'extern', 'finally', 'fixed', 'for',
44
            'foreach', 'goto', 'if', 'implicit', 'in', 'interface', 'internal', 'is', 'lock', 'namespace', 'new',
45
            'object', 'operator', 'out', 'override', 'partial', 'params', 'private', 'protected', 'public', 'readonly', 'ref',
46
            'return', 'sealed', 'short', 'sizeof', 'stackalloc', 'static', 'string', 'struct', 'switch', 'throw', 'try',
47
            'typeof', 'unchecked', 'unsafe', 'using', 'virtual', 'volatile', 'var', 'while', 'yield',
48
            '__makeref', '__reftype', '__refvalue', '__arglist'
49
        ])));
50
51
        $this->rules->add('symbol.class', new Rule(new RegexMatcher('/(\w+)(?:\s+|\s*[*&]\s*)\w+\s*[={}();,]/')));
52
        $this->rules->add('symbol.class.template', new Rule(new RegexMatcher('/(\w+)\s*<.*?>/')));
53
54
        $this->rules->add('variable.special', new Rule(new RegexMatcher('/\b(this)\b/')));
55
        $this->rules->add('constant.special', new Rule(new WordMatcher(['true', 'false', 'null'])));
56
    }
57
58
    public function getIdentifier()
59
    {
60
        return 'csharp';
61
    }
62
}
63