1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Highlighter |
5
|
|
|
* |
6
|
|
|
* Copyright (C) 2016, Some right reserved. |
7
|
|
|
* |
8
|
|
|
* @author Kacper "Kadet" Donat <[email protected]> |
9
|
|
|
* |
10
|
|
|
* Contact with author: |
11
|
|
|
* Xmpp: [email protected] |
12
|
|
|
* E-mail: [email protected] |
13
|
|
|
* |
14
|
|
|
* From Kadet with love. |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
namespace Kadet\Highlighter\Language; |
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 Java extends CSharp // evil |
25
|
|
|
{ |
26
|
|
|
public function setupRules() |
27
|
|
|
{ |
28
|
|
|
parent::setupRules(); |
29
|
|
|
|
30
|
|
|
$this->rules->rule('keyword')->setMatcher(new WordMatcher([ |
31
|
|
|
'abstract', 'continue', 'for', 'new', 'switch', 'assert', 'default', 'goto', 'package', 'synchronized', |
32
|
|
|
'do', 'if', 'private', 'this', 'break', 'double', 'implements', 'protected', 'throw', 'else', 'import', |
33
|
|
|
'public', 'throws', 'case', 'enum', 'instanceof', 'return', 'transient', 'catch', 'extends', 'try', 'final', |
34
|
|
|
'interface', 'static', 'class', 'finally', 'strictfp', 'volatile', 'const', 'native', 'super', 'while' |
35
|
|
|
])); |
36
|
|
|
|
37
|
|
|
$this->rules->rule('symbol.type', 'builtin')->priority = 3; |
38
|
|
|
$this->rules->rule('symbol.type', 'builtin')->setMatcher(new WordMatcher([ |
39
|
|
|
'boolean', 'byte', 'char', 'short', 'int', 'long', 'float', 'double', 'void' |
40
|
|
|
])); |
41
|
|
|
|
42
|
|
|
$this->rules->rule('symbol.annotation')->setMatcher(new RegexMatcher('/(@[\w\.]+)\s*(?:(?P<arguments>\((?>[^()]+|(?&arguments))*\))?)/si', [ |
43
|
|
|
1 => Token::NAME |
44
|
|
|
])); |
45
|
|
|
|
46
|
|
|
$this->rules->add('symbol.class', new Rule(new RegexMatcher('/\W(?>(?:public|protected|private|static|final|transient|volatile)\s+)+\s*([a-z][\w\_]+)(?><.*?>)?(?>\[\d*\])?\s+[a-z][\w_$]+[;,=]/si'), [ |
47
|
|
|
'priority' => 2, |
48
|
|
|
])); |
49
|
|
|
$this->rules->add('symbol.namespace', new Rule(new RegexMatcher('/(?:import|package)\s+([a-z][\w\.]+)\s*/si'))); |
50
|
|
|
} |
51
|
|
|
|
52
|
1 |
|
public function getIdentifier() |
53
|
|
|
{ |
54
|
1 |
|
return 'java'; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public static function getMetadata() |
58
|
|
|
{ |
59
|
|
|
return [ |
60
|
|
|
'name' => ['java'], |
61
|
|
|
'mime' => ['text/x-java'], |
62
|
|
|
'extension' => ['*.java'] |
63
|
|
|
]; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|