Completed
Push — master ( dc4b6d...04cf1c )
by Kacper
04:06
created

CSharp::getIdentifier()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 2
cts 2
cp 1
crap 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 CSharp extends C
25
{
26
    public function setupRules()
27
    {
28
        parent::setupRules();
29
30
        $this->rules->rule('preprocessor')->setMatcher(new RegexMatcher('/^\s*(#)/m'));
31
        $this->rules->rule('call.preprocessor')->setMatcher(new RegexMatcher('/^\s*#(\w+)/m'));
32
33
        $this->rules->remove('operator'); // & and *
34
        $this->rules->remove('symbol.type', 'universal');
35
36
        $this->rules->rule('keyword')->setMatcher(new WordMatcher([
37
            'abstract', 'as', 'base', 'break', 'case', 'catch', 'char', 'checked', 'class', 'const', 'continue',
38
            'default', 'delegate', 'do', 'else', 'enum', 'event', 'explicit', 'extern', 'finally', 'fixed', 'for',
39
            'foreach', 'goto', 'if', 'implicit', 'in', 'interface', 'internal', 'is', 'lock', 'namespace', 'new',
40
            'object', 'operator', 'out', 'override', 'partial', 'params', 'private', 'protected', 'public', 'readonly', 'ref',
41
            'return', 'sealed', 'short', 'sizeof', 'stackalloc', 'static', 'string', 'struct', 'switch', 'throw', 'try',
42
            'typeof', 'unchecked', 'unsafe', 'using', 'virtual', 'volatile', 'var', 'while', 'yield',
43
            '__makeref', '__reftype', '__refvalue', '__arglist', 'get', 'set'
44
        ]));
45
46
        $this->rules->addMany([
47
            'symbol.class'          => [
48
                new Rule(new RegexMatcher('/(\w+)(?:\s+)\w+\s*[={}();,]/')),
49
                new Rule(new RegexMatcher('/new\s+([a-z][\w\_]+)(?><.*?>)?(?>\[\d*\])?\s*[;\(]/si'), [
50
                    'priority' => 2,
51
                ])
52
            ],
53
            'symbol.class.template' => new Rule(new RegexMatcher('/(\w+)\s*<.*?>/')),
54
            'variable.special'      => new Rule(new RegexMatcher('/\b(this)\b/')),
55
            'constant.special'      => new Rule(new WordMatcher(['true', 'false', 'null'])),
56
            'operator'              => new Rule(new RegexMatcher('/([!+-\/*&|^<>=]{1,2}=?)/')),
57
            'operator.scope'        => new Rule(new RegexMatcher('/\w(\??\.)\w/')),
58
59
            'symbol.annotation' => new Rule(
60
                new RegexMatcher('/\[([\w\.]+)\s*(?P<arguments>\((?>[^()]+|(?&arguments))*\))\s*\]/si', [
61
                    1           => Token::NAME,
62
                    'arguments' => '$.arguments'
63
                ])
64
            ),
65
        ]);
66
    }
67
68 1
    public function getIdentifier()
69
    {
70 1
        return 'csharp';
71
    }
72
73
    public static function getMetadata()
74
    {
75
        return [
76
            'name'      => ['CSharp', 'C#'],
77
            'mime'      => ['text/x-csharp'],
78
            'extension' => ['*.cs']
79
        ];
80
    }
81
}
82