forked from EnlighterJS/EnlighterJS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphp.js
executable file
·126 lines (98 loc) · 3.63 KB
/
php.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// ----------------------------------------------------------------------
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
// --
// Copyright 2016-2018 Andi Dittrich <https://andidittrich.de>
// ----------------------------------------------------------------------
// Generic Rules/Regex
import _language_common_rules from './rulesets/generic';
import {generic} from './generic';
// PHP
// Author: [Andi Dittrich]
// --
export class php extends generic {
setupLanguage() {
this.rules = [
// strings
_language_common_rules.sqStrings,
_language_common_rules.dqStrings,
// heredoc / nowdoc
_language_common_rules.heredoc,
_language_common_rules.boolean,
// null expression
_language_common_rules.null,
// method call on instances (before keywords!)
{
regex: /(->)([\w]+)/gim,
type: ['k3', 'm1']
},
// static calls (before keywords!)
{
regex: /(::)([\w]+)/gim,
type: ['k3', 'm2']
},
// inheritance
{
regex: /(self|parent|\$this)/gi,
type: 'k9'
},
// control keywords
{
regex: /\b(as|break|case|catch|do|else|elseif|enddeclare|endfor|endforeach|endif|endswitch|endwhile|finally|for|foreach|goto|if|switch|throw|try|while)\b/g,
type: 'k1'
},
// magic constants
{
regex: /\b__[A-Z][A-Z0-9_]+__\b/g,
type: 'e3'
},
// keywords
// http://php.net/manual/en/reserved.keywords.php
// http://php.net/manual/en/reserved.other-reserved-words.php
{
regex: /\b(__halt_compiler|abstract|array|callable|class|const|continue|declare|default|die|echo|empty|eval|exit|extends|final|function|global|implements|include|include_once|instanceof|insteadof|interface|isset|list|namespace|print|private|protected|public|require|require_once|return|static|trait|use|var|yield)\b/g,
type: 'k0'
},
// operator
{
regex: /\b(and|or|xor|clone|new|unset)\b/g,
type: 'k3'
},
// reserved
// http://php.net/manual/en/reserved.other-reserved-words.php
{
regex: /\b(int|float|bool|string|resource|object|mixed|numeric)\b/g,
type: 'k5'
},
// slash style comments
_language_common_rules.slashComments,
// pound style comments
_language_common_rules.poundComments,
// multi line comments
_language_common_rules.blockComments,
// variables
{
regex: /\$[^\s=;()'">:-]+/gim,
type: 'k7'
},
// global function calls
{
regex: /\b(\w[^\s('"]+)\s*\(/gm,
type: 'm0'
},
// octal
_language_common_rules.octal,
// bin
_language_common_rules.bin,
// hex
_language_common_rules.hex,
// floats numbers
_language_common_rules.floats,
// integer numbers
_language_common_rules.int,
// brackets
_language_common_rules.brackets
]
}
}