Completed
Push — master ( 606ca4...edcce7 )
by Kacper
05:58
created

TypeScript   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 8%

Importance

Changes 0
Metric Value
dl 0
loc 43
rs 10
c 0
b 0
f 0
ccs 2
cts 25
cp 0.08
wmc 3
lcom 1
cbo 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setupRules() 0 25 1
A getIdentifier() 0 4 1
A getMetadata() 0 8 1
1
<?php
2
3
4
namespace Kadet\Highlighter\Language;
5
6
7
use Kadet\Highlighter\Matcher\RegexMatcher;
8
use Kadet\Highlighter\Parser\Rule;
9
use Kadet\Highlighter\Parser\Token\Token;
10
11
class TypeScript extends JavaScript
12
{
13
    public function setupRules()
14
    {
15
        parent::setupRules();
16
17
        $this->rules->addMany([
18
            'symbol.type' => [
19
                new Rule(new RegexMatcher('/(?:[)\w]\??:|\bas\b)\s*(\w+)/si'), [
20
                    'context' => ['!meta.json', '!string', '!comment']
21
                ]),
22
                new Rule(new RegexMatcher('/(?:(?=(<\w+(?1)?>))|\G)<(\w+)/six', [ 2 => Token::NAME ]), [
23
                    'context' => ['!meta.json', '!string', '!comment']
24
                ]),
25
            ],
26
        ]);
27
28
        $this->rules
29
            ->rule('symbol.function')
30
            ->setMatcher(new RegexMatcher('/function\s+([a-z_]\w+)\s*(?>(<(?>(?2)|[^<>])+>)\s*)?\(/i'));
31
32
        /** @var \Kadet\Highlighter\Matcher\WordMatcher $keywords */
33
        $keywords = $this->rules->rule('keyword')->getMatcher();
34
        $keywords = $keywords->merge(['as']);
35
36
        $this->rules->rule('keyword')->setMatcher($keywords);
37
    }
38
39
40 1
    public function getIdentifier()
41
    {
42 1
        return 'typescript';
43
    }
44
45
    public static function getMetadata()
46
    {
47
        return [
48
            'name'      => ['ts', 'typescript'],
49
            'mime'      => ['application/typescript', 'application/x-typescript', 'text/x-typescript', 'text/typescript'],
50
            'extension' => ['*.ts', '*.tsx'],
51
        ];
52
    }
53
}