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
|
|
|
} |