3 pygments.lexers.php |
3 pygments.lexers.php |
4 ~~~~~~~~~~~~~~~~~~~ |
4 ~~~~~~~~~~~~~~~~~~~ |
5 |
5 |
6 Lexers for PHP and related languages. |
6 Lexers for PHP and related languages. |
7 |
7 |
8 :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. |
8 :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. |
9 :license: BSD, see LICENSE for details. |
9 :license: BSD, see LICENSE for details. |
10 """ |
10 """ |
11 |
11 |
12 import re |
12 import re |
13 |
13 |
14 from pygments.lexer import RegexLexer, include, bygroups, default, using, this |
14 from pygments.lexer import RegexLexer, include, bygroups, default, using, \ |
|
15 this, words |
15 from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ |
16 from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ |
16 Number, Punctuation, Other |
17 Number, Punctuation, Other |
17 from pygments.util import get_bool_opt, get_list_opt, iteritems |
18 from pygments.util import get_bool_opt, get_list_opt, iteritems |
18 |
19 |
19 __all__ = ['ZephirLexer', 'PhpLexer'] |
20 __all__ = ['ZephirLexer', 'PhpLexer'] |
135 (r'[^<]+', Other), |
136 (r'[^<]+', Other), |
136 (r'<', Other) |
137 (r'<', Other) |
137 ], |
138 ], |
138 'php': [ |
139 'php': [ |
139 (r'\?>', Comment.Preproc, '#pop'), |
140 (r'\?>', Comment.Preproc, '#pop'), |
140 (r'<<<([\'"]?)(' + _ident_inner + r')\1\n.*?\n\s*\2;?\n', String), |
141 (r'(<<<)([\'"]?)(' + _ident_inner + r')(\2\n.*?\n\s*)(\3)(;?)(\n)', |
|
142 bygroups(String, String, String.Delimiter, String, String.Delimiter, |
|
143 Punctuation, Text)), |
141 (r'\s+', Text), |
144 (r'\s+', Text), |
142 (r'#.*?\n', Comment.Single), |
145 (r'#.*?\n', Comment.Single), |
143 (r'//.*?\n', Comment.Single), |
146 (r'//.*?\n', Comment.Single), |
144 # put the empty comment here, it is otherwise seen as |
147 # put the empty comment here, it is otherwise seen as |
145 # the start of a docstring |
148 # the start of a docstring |
160 (r'(and|E_PARSE|old_function|E_ERROR|or|as|E_WARNING|parent|' |
163 (r'(and|E_PARSE|old_function|E_ERROR|or|as|E_WARNING|parent|' |
161 r'eval|PHP_OS|break|exit|case|extends|PHP_VERSION|cfunction|' |
164 r'eval|PHP_OS|break|exit|case|extends|PHP_VERSION|cfunction|' |
162 r'FALSE|print|for|require|continue|foreach|require_once|' |
165 r'FALSE|print|for|require|continue|foreach|require_once|' |
163 r'declare|return|default|static|do|switch|die|stdClass|' |
166 r'declare|return|default|static|do|switch|die|stdClass|' |
164 r'echo|else|TRUE|elseif|var|empty|if|xor|enddeclare|include|' |
167 r'echo|else|TRUE|elseif|var|empty|if|xor|enddeclare|include|' |
165 r'virtual|endfor|include_once|while|endforeach|global|__FILE__|' |
168 r'virtual|endfor|include_once|while|endforeach|global|' |
166 r'endif|list|__LINE__|endswitch|new|__sleep|endwhile|not|' |
169 r'endif|list|endswitch|new|endwhile|not|' |
167 r'array|__wakeup|E_ALL|NULL|final|php_user_filter|interface|' |
170 r'array|E_ALL|NULL|final|php_user_filter|interface|' |
168 r'implements|public|private|protected|abstract|clone|try|' |
171 r'implements|public|private|protected|abstract|clone|try|' |
169 r'catch|throw|this|use|namespace|trait|yield|' |
172 r'catch|throw|this|use|namespace|trait|yield|' |
170 r'finally)\b', Keyword), |
173 r'finally)\b', Keyword), |
171 (r'(true|false|null)\b', Keyword.Constant), |
174 (r'(true|false|null)\b', Keyword.Constant), |
|
175 include('magicconstants'), |
172 (r'\$\{\$+' + _ident_inner + '\}', Name.Variable), |
176 (r'\$\{\$+' + _ident_inner + '\}', Name.Variable), |
173 (r'\$+' + _ident_inner, Name.Variable), |
177 (r'\$+' + _ident_inner, Name.Variable), |
174 (_ident_inner, Name.Other), |
178 (_ident_inner, Name.Other), |
175 (r'(\d+\.\d*|\d*\.\d+)(e[+-]?[0-9]+)?', Number.Float), |
179 (r'(\d+\.\d*|\d*\.\d+)(e[+-]?[0-9]+)?', Number.Float), |
176 (r'\d+e[+-]?[0-9]+', Number.Float), |
180 (r'\d+e[+-]?[0-9]+', Number.Float), |
180 (r'0b[01]+', Number.Bin), |
184 (r'0b[01]+', Number.Bin), |
181 (r"'([^'\\]*(?:\\.[^'\\]*)*)'", String.Single), |
185 (r"'([^'\\]*(?:\\.[^'\\]*)*)'", String.Single), |
182 (r'`([^`\\]*(?:\\.[^`\\]*)*)`', String.Backtick), |
186 (r'`([^`\\]*(?:\\.[^`\\]*)*)`', String.Backtick), |
183 (r'"', String.Double, 'string'), |
187 (r'"', String.Double, 'string'), |
184 ], |
188 ], |
|
189 'magicfuncs': [ |
|
190 # source: http://php.net/manual/en/language.oop5.magic.php |
|
191 (words(( |
|
192 '__construct', '__destruct', '__call', '__callStatic', '__get', '__set', |
|
193 '__isset', '__unset', '__sleep', '__wakeup', '__toString', '__invoke', |
|
194 '__set_state', '__clone', '__debugInfo',), suffix=r'\b'), |
|
195 Name.Function.Magic), |
|
196 ], |
|
197 'magicconstants': [ |
|
198 # source: http://php.net/manual/en/language.constants.predefined.php |
|
199 (words(( |
|
200 '__LINE__', '__FILE__', '__DIR__', '__FUNCTION__', '__CLASS__', |
|
201 '__TRAIT__', '__METHOD__', '__NAMESPACE__',), |
|
202 suffix=r'\b'), |
|
203 Name.Constant), |
|
204 ], |
185 'classname': [ |
205 'classname': [ |
186 (_ident_inner, Name.Class, '#pop') |
206 (_ident_inner, Name.Class, '#pop') |
187 ], |
207 ], |
188 'functionname': [ |
208 'functionname': [ |
189 (_ident_inner, Name.Function, '#pop') |
209 include('magicfuncs'), |
|
210 (_ident_inner, Name.Function, '#pop'), |
|
211 default('#pop') |
190 ], |
212 ], |
191 'string': [ |
213 'string': [ |
192 (r'"', String.Double, '#pop'), |
214 (r'"', String.Double, '#pop'), |
193 (r'[^{$"\\]+', String.Double), |
215 (r'[^{$"\\]+', String.Double), |
194 (r'\\([nrt"$\\]|[0-7]{1,3}|x[0-9a-f]{1,2})', String.Escape), |
216 (r'\\([nrt"$\\]|[0-7]{1,3}|x[0-9a-f]{1,2})', String.Escape), |
200 (r'(\{)(\$.*?)(\})', |
222 (r'(\{)(\$.*?)(\})', |
201 bygroups(String.Interpol, using(this, _startinline=True), |
223 bygroups(String.Interpol, using(this, _startinline=True), |
202 String.Interpol)), |
224 String.Interpol)), |
203 (r'(\$\{)(\S+)(\})', |
225 (r'(\$\{)(\S+)(\})', |
204 bygroups(String.Interpol, Name.Variable, String.Interpol)), |
226 bygroups(String.Interpol, Name.Variable, String.Interpol)), |
205 (r'[${\\]+', String.Double) |
227 (r'[${\\]', String.Double) |
206 ], |
228 ], |
207 } |
229 } |
208 |
230 |
209 def __init__(self, **options): |
231 def __init__(self, **options): |
210 self.funcnamehighlighting = get_bool_opt( |
232 self.funcnamehighlighting = get_bool_opt( |