Skip to content

Commit

Permalink
add match expression indent, update keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
craynot committed May 23, 2024
1 parent ef67457 commit 523bd05
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
8 changes: 5 additions & 3 deletions php-ts-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
((parent-is "switch_block") parent-bol ,offset)
((parent-is "case_statement") parent-bol ,offset)
((parent-is "default_statement") parent-bol ,offset)
((parent-is "match_block") parent-bol ,offset)
((parent-is "assignment_expression") parent-bol ,offset)
((parent-is "return_statement") parent-bol ,offset))))
"Tree-sitter indent rules.")
Expand All @@ -99,14 +100,14 @@
"elseif" "enddeclare" "endforeach" "endif" "endswitch"
"endwhile" "enum" "extends" "final" "finally" "for" "foreach"
"fn" "function" "global" "if" "implements" "include_once"
"include" "insteadof" "interface" "namespace" "new"
"include" "insteadof" "interface" "match" "namespace" "new"
"private" "protected" "public" "readonly" "require_once" "require"
"return" "static" "switch" "throw" "trait" "try" "use"
"while" "yield")
"PHP keywords for tree-sitter font-locking.")

(defvar php-ts-mode--built-in-functions
'("die" "echo" "empty" "isset")
'("die" "empty" "isset")
"PHP built-in functions for tree-sitter font-locking.")

(defvar php-ts-mode--operators
Expand Down Expand Up @@ -266,7 +267,8 @@ see https://www.php.net/manual/language.constants.predefined.php")
(:match ,(rx-to-string
`(seq bol
(or ,@php-ts-mode--built-in-functions)
eol)) @php-keyword)))
eol)) @php-keyword))
(unset_statement "unset" @php-keyword))

:language 'php
:feature 'label
Expand Down
23 changes: 21 additions & 2 deletions tests/php-ts-mode-resources/face.erts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ Code:
(lambda ()
(php-ts-mode)
(customize-set-variable 'treesit-font-lock-level 4)
(setq mode-require-final-newline nil)
(let ((face (symbol-name (face-at-point t))))
(let ((face (symbol-name (face-at-point))))
(erase-buffer)
(insert face)))

Expand Down Expand Up @@ -40,6 +39,16 @@ class Basic {
php-keyword
=-=-=

Name: Keyword `match`
No-After-Newline: t

=-=
<?php
|match ($t){}
=-=
php-keyword
=-=-=

Name: Class name
No-After-Newline: t

Expand Down Expand Up @@ -152,6 +161,16 @@ iss|et($t)
php-keyword
=-=-=

Name: Unset statement
No-After-Newline: t

=-=
<?php
uns|et($t)
=-=
php-keyword
=-=-=

Name: Object create expression with qualified name
No-After-Newline: t

Expand Down
14 changes: 14 additions & 0 deletions tests/php-ts-mode-resources/indent.erts
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,17 @@ function test()
}
}
=-=-=

Name: Match statement

=-=
<?php
match ($t) {
1 => 1
};
=-=
<?php
match ($t) {
1 => 1
};
=-=-=

0 comments on commit 523bd05

Please sign in to comment.