77
77
; ; "compound_statement" contains the body of many statements.
78
78
; ; For example function_definition, foreach_statement, etc.
79
79
((parent-is " compound_statement" ) parent-bol , offset )
80
+ ((parent-is " method_declaration" ) parent-bol 0 )
80
81
((parent-is " array_creation_expression" ) parent-bol , offset )
81
82
((parent-is " base_clause" ) parent-bol , offset )
82
83
((parent-is " class_interface_clause" ) parent-bol , offset )
86
87
((parent-is " binary_expression" ) parent-bol, 0 )
87
88
((parent-is " switch_block" ) parent-bol , offset )
88
89
((parent-is " case_statement" ) parent-bol , offset )
90
+ ((parent-is " default_statement" ) parent-bol , offset )
91
+ ((parent-is " match_block" ) parent-bol , offset )
89
92
((parent-is " assignment_expression" ) parent-bol , offset )
90
93
((parent-is " return_statement" ) parent-bol , offset ))))
91
94
" Tree-sitter indent rules." )
96
99
" elseif" " enddeclare" " endforeach" " endif" " endswitch"
97
100
" endwhile" " enum" " extends" " final" " finally" " for" " foreach"
98
101
" fn" " function" " global" " if" " implements" " include_once"
99
- " include" " insteadof" " interface" " namespace" " new"
102
+ " include" " instanceof " " insteadof" " interface" " match " " namespace" " new"
100
103
" private" " protected" " public" " readonly" " require_once" " require"
101
104
" return" " static" " switch" " throw" " trait" " try" " use"
102
105
" while" " yield" )
103
106
" PHP keywords for tree-sitter font-locking." )
104
107
108
+ (defvar php-ts-mode--built-in-functions
109
+ '(" die" " empty" " isset" )
110
+ " PHP built-in functions for tree-sitter font-locking." )
111
+
105
112
(defvar php-ts-mode--operators
106
113
'(" !=" " !==" " %" " %=" " &" " &&" " &=" " *" " **" " *="
107
114
" +" " ++" " +=" " ," " -" " -" " --" " -=" " ->" " ."
@@ -145,9 +152,10 @@ see https://www.php.net/manual/language.constants.predefined.php")
145
152
(named_type (name) @php-type)
146
153
(named_type (qualified_name) @php-type)
147
154
(namespace_use_clause)
148
- (namespace_name (name))]
155
+ (namespace_name (name))
156
+ (optional_type " ?" @php-type)]
149
157
@php-type
150
- (class_interface_clause (name) @php-class)
158
+ (class_interface_clause [ (name) (qualified_name)] @php-class)
151
159
(class_constant_access_expression
152
160
(name) @php-keyword
153
161
(:match ,(rx bos " class" eos)
@@ -157,16 +165,20 @@ see https://www.php.net/manual/language.constants.predefined.php")
157
165
(:match ,(rx bos (? " _" ) (in " A-Z" ) (+ (in " 0-9A-Z_" )) eos)
158
166
@php-constant))
159
167
(class_constant_access_expression
160
- (name) @php-class)
168
+ [ (name) (qualified_name)] @php-class)
161
169
[(boolean)
162
170
(null )]
163
171
@php-constant
164
172
[(integer)
165
173
(float )]
166
- @font-lock-number-face)
174
+ @font-lock-number-face
175
+ (binary_expression
176
+ operator: " instanceof"
177
+ right: [(name) (qualified_name)] @php-class))
167
178
168
179
:language 'php
169
180
:feature 'definition
181
+ :override t
170
182
`((class_declaration
171
183
name: (name) @php-class)
172
184
(interface_declaration
@@ -176,26 +188,28 @@ see https://www.php.net/manual/language.constants.predefined.php")
176
188
(trait_declaration
177
189
name: (name) @php-class)
178
190
(enum_case
179
- name: (name) @php-class))
191
+ name: (name) @php-class)
192
+ (base_clause [(name) (qualified_name)] @php-class)
193
+ (use_declaration [(name) (qualified_name)] @php-class))
180
194
181
195
:language 'php
182
196
:feature 'function
197
+ :override t
183
198
`((array_creation_expression " array" @php-builtin)
184
199
(list_literal " list" @php-builtin)
185
200
(method_declaration
186
201
name: (name) @php-function-name)
187
202
(function_call_expression
188
203
function: [(qualified_name (name)) (name)] @php-function-call)
189
204
(scoped_call_expression
190
- scope: (name) @php-class)
191
- (scoped_call_expression
205
+ scope: [(name) (qualified_name)] @php-class
192
206
name: (name) @php-static-method-call)
207
+ (scoped_property_access_expression
208
+ scope: [(name) (qualified_name)] @php-class)
193
209
(member_call_expression
194
210
name: (name) @php-method-call)
195
- (object_creation_expression (name) @php-class)
196
- (attribute (name) @php-class)
197
- (attribute (qualified_name) @php-class)
198
-
211
+ (object_creation_expression [(name) (qualified_name)] @php-class)
212
+ (attribute [(name) (qualified_name)] @php-class)
199
213
(function_definition
200
214
name: (name) @php-function-name))
201
215
@@ -207,15 +221,17 @@ see https://www.php.net/manual/language.constants.predefined.php")
207
221
208
222
; ; ((name) @constructor
209
223
; ; (:match ,(rx-to-string '(: bos (in "A-Z")))))
210
-
211
- ; ; (variable_name (name) @php-$this
212
- ; ; (:match ,(rx bos "this" eos)
213
- ; ; @php-$this))
214
224
(member_access_expression name: (name) @php-property-name)
215
225
; ;(variable_name (name) @font-lock-variable-name-face)
216
226
(variable_name (name) @php-variable-name)
217
227
(variable_name " $" @php-variable-sigil))
218
228
229
+ :language 'php
230
+ :feature 'this
231
+ :override t
232
+ `((variable_name " $" @php-this-sigil (name) @php-this
233
+ (:match ,(rx bos " this" eos) @php-this)))
234
+
219
235
:language 'php
220
236
:feature 'comment
221
237
`(((comment) @font-lock-doc-face
@@ -226,7 +242,7 @@ see https://www.php.net/manual/language.constants.predefined.php")
226
242
:language 'php
227
243
:feature 'string
228
244
`([(string )
229
- (string_value )
245
+ (string_content )
230
246
(encapsed_string)
231
247
(heredoc)
232
248
(heredoc_body)
@@ -240,10 +256,18 @@ see https://www.php.net/manual/language.constants.predefined.php")
240
256
241
257
:language 'php
242
258
:feature 'keyword
259
+ :override t
243
260
`([,@php-ts-mode--keywords ] @php-keyword
244
261
(print_intrinsic " print" @php-keyword)
245
262
(goto_statement " goto" @php-keyword)
246
- (yield_expression " from" @php-keyword))
263
+ (yield_expression " from" @php-keyword)
264
+ (function_call_expression
265
+ function: (name) @php-keyword
266
+ (:match ,(rx-to-string
267
+ `(seq bol
268
+ (or ,@php-ts-mode--built-in-functions )
269
+ eol)) @php-keyword))
270
+ (unset_statement " unset" @php-keyword))
247
271
248
272
:language 'php
249
273
:feature 'label
@@ -347,7 +371,7 @@ Currently there are `php-mode' and `php-ts-mode'."
347
371
'((comment definition preprocessor)
348
372
(keyword string type)
349
373
(function constant label)
350
- (bracket delimiter operator variables)))
374
+ (bracket delimiter operator variables this )))
351
375
352
376
; ; Imenu.
353
377
(setq-local treesit-simple-imenu-settings
0 commit comments