Skip to content

Commit 523bd05

Browse files
committed
add match expression indent, update keywords
1 parent ef67457 commit 523bd05

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed

php-ts-mode.el

+5-3
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
((parent-is "switch_block") parent-bol ,offset)
9090
((parent-is "case_statement") parent-bol ,offset)
9191
((parent-is "default_statement") parent-bol ,offset)
92+
((parent-is "match_block") parent-bol ,offset)
9293
((parent-is "assignment_expression") parent-bol ,offset)
9394
((parent-is "return_statement") parent-bol ,offset))))
9495
"Tree-sitter indent rules.")
@@ -99,14 +100,14 @@
99100
"elseif" "enddeclare" "endforeach" "endif" "endswitch"
100101
"endwhile" "enum" "extends" "final" "finally" "for" "foreach"
101102
"fn" "function" "global" "if" "implements" "include_once"
102-
"include" "insteadof" "interface" "namespace" "new"
103+
"include" "insteadof" "interface" "match" "namespace" "new"
103104
"private" "protected" "public" "readonly" "require_once" "require"
104105
"return" "static" "switch" "throw" "trait" "try" "use"
105106
"while" "yield")
106107
"PHP keywords for tree-sitter font-locking.")
107108

108109
(defvar php-ts-mode--built-in-functions
109-
'("die" "echo" "empty" "isset")
110+
'("die" "empty" "isset")
110111
"PHP built-in functions for tree-sitter font-locking.")
111112

112113
(defvar php-ts-mode--operators
@@ -266,7 +267,8 @@ see https://www.php.net/manual/language.constants.predefined.php")
266267
(:match ,(rx-to-string
267268
`(seq bol
268269
(or ,@php-ts-mode--built-in-functions)
269-
eol)) @php-keyword)))
270+
eol)) @php-keyword))
271+
(unset_statement "unset" @php-keyword))
270272

271273
:language 'php
272274
:feature 'label

tests/php-ts-mode-resources/face.erts

+21-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ Code:
22
(lambda ()
33
(php-ts-mode)
44
(customize-set-variable 'treesit-font-lock-level 4)
5-
(setq mode-require-final-newline nil)
6-
(let ((face (symbol-name (face-at-point t))))
5+
(let ((face (symbol-name (face-at-point))))
76
(erase-buffer)
87
(insert face)))
98

@@ -40,6 +39,16 @@ class Basic {
4039
php-keyword
4140
=-=-=
4241

42+
Name: Keyword `match`
43+
No-After-Newline: t
44+
45+
=-=
46+
<?php
47+
|match ($t){}
48+
=-=
49+
php-keyword
50+
=-=-=
51+
4352
Name: Class name
4453
No-After-Newline: t
4554

@@ -152,6 +161,16 @@ iss|et($t)
152161
php-keyword
153162
=-=-=
154163

164+
Name: Unset statement
165+
No-After-Newline: t
166+
167+
=-=
168+
<?php
169+
uns|et($t)
170+
=-=
171+
php-keyword
172+
=-=-=
173+
155174
Name: Object create expression with qualified name
156175
No-After-Newline: t
157176

tests/php-ts-mode-resources/indent.erts

+14
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,17 @@ function test()
144144
}
145145
}
146146
=-=-=
147+
148+
Name: Match statement
149+
150+
=-=
151+
<?php
152+
match ($t) {
153+
1 => 1
154+
};
155+
=-=
156+
<?php
157+
match ($t) {
158+
1 => 1
159+
};
160+
=-=-=

0 commit comments

Comments
 (0)