|
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('symbol.type', 0); // symbol.type[0] stands for universal type matching in arguments |
|
31
|
|
|
|
|
32
|
|
|
$this->rules->rule('keyword')->setMatcher(new WordMatcher([ |
|
33
|
|
|
'auto', 'align(?:as|of)', 'and(?:_eq)?', 'asm', 'auto', 'bit(and|or)', 'break', 'case', 'catch', 'class', |
|
34
|
|
|
'compl', 'concept', 'const(?:_cast|expr)?', 'continue', 'decltype', 'default', 'delete', 'do', 'double', |
|
35
|
|
|
'dynamic_cast', 'else', 'enum', 'explicit', 'export', 'extern', 'for', 'friend', 'goto', 'if', 'inline', |
|
36
|
|
|
'mutable', 'namespace', 'new', 'noexcept', 'not(?:_eq|ptr)', 'operator', 'or(?:_eq)?', 'private', |
|
37
|
|
|
'protected', 'public', 'register', 'reinterpret_cast', 'requires', 'return', 'sizeof', |
|
38
|
|
|
'static(?:_assert|_cast)?', 'struct', 'switch', 'template', 'thread_local', 'throw', 'try', 'typedef', |
|
39
|
|
|
'typeid', 'typename', 'union', 'using', 'virtual', 'volatile', 'while', 'xor(?:_eq)?', |
|
40
|
|
|
], ['escape' => false])); |
|
41
|
|
|
|
|
42
|
|
|
$this->rules->add('symbol.type', new Rule(new WordMatcher(['bool', 'wchar']))); |
|
43
|
|
|
$this->rules->add('constant.special', new Rule(new WordMatcher(['false', 'null', 'true']))); |
|
44
|
|
|
$this->rules->add('symbol.class', new Rule(new RegexMatcher('/(\w+)(?:\s+|\s*[*&]\s*)\w+\s*[={}();,]/'))); |
|
45
|
|
|
$this->rules->add('symbol.class.template', new Rule(new RegexMatcher('/(\w+)\s*<.*?>/'))); |
|
46
|
|
|
|
|
47
|
|
|
$this->rules->add('symbol.namespace', new Rule(new RegexMatcher('/((?::)?(\w+::)+)(\w+)/', [ |
|
48
|
|
|
1 => Token::NAME, |
|
49
|
|
|
2 => 'symbol.class' |
|
50
|
|
|
]))); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function getIdentifier() |
|
54
|
|
|
{ |
|
55
|
|
|
return 'cpp'; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
View Code Duplication |
public static function getMetadata() |
|
59
|
|
|
{ |
|
60
|
|
|
return [ |
|
61
|
|
|
'name' => ['cpp', 'c++'], |
|
62
|
|
|
'mime' => ['text/x-c++src', 'text/x-c++hdr'], |
|
63
|
|
|
'extension' => ['*.cpp', '*.hpp', '*.hxx', '*.cxx', '*.cc', '*.hh'] |
|
64
|
|
|
]; |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|