From d2b528cb4e8d41654b2e2498bf942107f09b7a7c Mon Sep 17 00:00:00 2001 From: Nikita Alekseev Date: Tue, 21 May 2024 14:40:08 +0300 Subject: [PATCH 01/13] update font rules, indention, faces and readme --- .gitignore | 4 ++++ README.md | 21 ++++++++++++++++++++- php-ts-face.el | 44 ++++++++++++++++++++++++++++++++++++++++++++ php-ts-mode.el | 22 ++++++++++++++-------- 4 files changed, 82 insertions(+), 9 deletions(-) create mode 100644 php-ts-face.el diff --git a/.gitignore b/.gitignore index 0d51897..b0a7e33 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,8 @@ *.elc php-ts-mode-autoloads.el +php-ts-mode-pkg.el /.eask /dist +# emacs tmp files +*~ +*# diff --git a/README.md b/README.md index ee2129f..1d2bd8b 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,25 @@ If you haven't installed Tree-sitter yet, please read [How to Get Started with T [How to Get Started with Tree-Sitter - Mastering Emacs]: https://www.masteringemacs.org/article/how-to-get-started-tree-sitter +Package can be installed by running the following command. + +``` +M-x package-vc-install [RET] https://github.com/emacs-php/php-ts-mode +``` + +### Configuration + +Example configuration that you can put in your `.emacs` file + +``` +;; Enable variables highlighting +(customize-set-variable 'treesit-font-lock-level 4) + +(add-hook 'php-ts-mode-hook (lambda () + ;; Use spaces for indent + (setq-local indent-tabs-mode nil))) +``` + ### Grammer installation If you don't already have `php-ts-mode` installed, please evaluate the Lisp code below. @@ -36,7 +55,7 @@ In `php-ts-mode`, syntax elements are classified as follows. * **Level 1**: `comment` `definition` `preprocessor` * **Level 2**: `keyword` `string` `type` * **Level 3**: `function` `constant` `label` - * **Level 4**: `bracket` `delimiter` `operator` `variables` + * **Level 4**: `bracket` `delimiter` `operator` `variables` `this` By default, up to **Level 3** will be highlighted. diff --git a/php-ts-face.el b/php-ts-face.el new file mode 100644 index 0000000..cd5fb6f --- /dev/null +++ b/php-ts-face.el @@ -0,0 +1,44 @@ +;;; php-ts-face.el --- Face definitions for PHP script -*- lexical-binding: t; -*- + +;; Copyright (C) 2023 Friends of Emacs-PHP development + +;; Author: USAMI Kenta +;; Created: 5 May 2019 +;; Version: 1.25.0 +;; Keywords: faces, php +;; Homepage: https://github.com/emacs-php/php-mode +;; License: GPL-3.0-or-later + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Commentary: + +;; Face definitions for PHP script. + +;;; Code: + +;;;###autoload + +(defface php-this '((t (:inherit php-constant))) + "PHP Mode face used to highlight $this variables." + :group 'php-faces + :tag "PHP $this") + +(defface php-this-sigil '((t (:inherit php-constant))) + "PHP Mode face used to highlight sigils($) of $this variable." + :group 'php-faces + :tag "PHP $this Sigil") + +(provide 'php-ts-face) +;;; php-ts-face.el ends here diff --git a/php-ts-mode.el b/php-ts-mode.el index 99028ab..ea8ffc6 100644 --- a/php-ts-mode.el +++ b/php-ts-mode.el @@ -36,6 +36,7 @@ (require 'c-ts-common) (require 'php nil t) (require 'php-face nil t) +(require 'php-ts-face nil t) (declare-function php-base-mode "ext:php") (declare-function treesit-parser-create "treesit.c") @@ -77,6 +78,7 @@ ;; "compound_statement" contains the body of many statements. ;; For example function_definition, foreach_statement, etc. ((parent-is "compound_statement") parent-bol ,offset) + ((parent-is "method_declaration") parent-bol 0) ((parent-is "array_creation_expression") parent-bol ,offset) ((parent-is "base_clause") parent-bol ,offset) ((parent-is "class_interface_clause") parent-bol ,offset) @@ -145,7 +147,8 @@ see https://www.php.net/manual/language.constants.predefined.php") (named_type (name) @php-type) (named_type (qualified_name) @php-type) (namespace_use_clause) - (namespace_name (name))] + (namespace_name (name)) + (optional_type "?" @php-type)] @php-type (class_interface_clause (name) @php-class) (class_constant_access_expression @@ -176,7 +179,8 @@ see https://www.php.net/manual/language.constants.predefined.php") (trait_declaration name: (name) @php-class) (enum_case - name: (name) @php-class)) + name: (name) @php-class) + (base_clause (name) @php-class)) :language 'php :feature 'function @@ -207,15 +211,17 @@ see https://www.php.net/manual/language.constants.predefined.php") ;; ((name) @constructor ;; (:match ,(rx-to-string '(: bos (in "A-Z"))))) - - ;; (variable_name (name) @php-$this - ;; (:match ,(rx bos "this" eos) - ;; @php-$this)) (member_access_expression name: (name) @php-property-name) ;;(variable_name (name) @font-lock-variable-name-face) (variable_name (name) @php-variable-name) (variable_name "$" @php-variable-sigil)) + :language 'php + :feature 'this + :override t + `((variable_name "$" @php-this-sigil (name) @php-this + (:match ,(rx bos "this" eos) @php-this))) + :language 'php :feature 'comment `(((comment) @font-lock-doc-face @@ -226,7 +232,7 @@ see https://www.php.net/manual/language.constants.predefined.php") :language 'php :feature 'string `([(string) - (string_value) + (string_content) (encapsed_string) (heredoc) (heredoc_body) @@ -347,7 +353,7 @@ Currently there are `php-mode' and `php-ts-mode'." '((comment definition preprocessor) (keyword string type) (function constant label) - (bracket delimiter operator variables))) + (bracket delimiter operator variables this))) ;; Imenu. (setq-local treesit-simple-imenu-settings From 2da0cf398246c14a043faaff0269b3b619b37c25 Mon Sep 17 00:00:00 2001 From: Nikita Alekseev Date: Tue, 21 May 2024 16:51:26 +0300 Subject: [PATCH 02/13] add test --- tests/php-ts-mode-resources/indent.erts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/php-ts-mode-resources/indent.erts b/tests/php-ts-mode-resources/indent.erts index 986c2ed..d3533fe 100644 --- a/tests/php-ts-mode-resources/indent.erts +++ b/tests/php-ts-mode-resources/indent.erts @@ -91,3 +91,17 @@ function with_two_attrs(): void { return; } =-=-= + +Name: Opening bracket on new line + +=-= + Date: Tue, 21 May 2024 18:07:43 +0300 Subject: [PATCH 03/13] default statement indent + font rules --- php-ts-mode.el | 10 +++++++++- tests/php-ts-mode-resources/indent.erts | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/php-ts-mode.el b/php-ts-mode.el index ea8ffc6..ef9ba63 100644 --- a/php-ts-mode.el +++ b/php-ts-mode.el @@ -88,6 +88,7 @@ ((parent-is "binary_expression") parent-bol, 0) ((parent-is "switch_block") parent-bol ,offset) ((parent-is "case_statement") parent-bol ,offset) + ((parent-is "default_statement") parent-bol ,offset) ((parent-is "assignment_expression") parent-bol ,offset) ((parent-is "return_statement") parent-bol ,offset)))) "Tree-sitter indent rules.") @@ -161,6 +162,10 @@ see https://www.php.net/manual/language.constants.predefined.php") @php-constant)) (class_constant_access_expression (name) @php-class) + (class_constant_access_expression + (qualified_name + (namespace_name_as_prefix) @php-class + (name) @php-class)) [(boolean) (null)] @php-constant @@ -180,7 +185,8 @@ see https://www.php.net/manual/language.constants.predefined.php") name: (name) @php-class) (enum_case name: (name) @php-class) - (base_clause (name) @php-class)) + (base_clause (name) @php-class) + (use_declaration (name) @php-class)) :language 'php :feature 'function @@ -194,6 +200,8 @@ see https://www.php.net/manual/language.constants.predefined.php") scope: (name) @php-class) (scoped_call_expression name: (name) @php-static-method-call) + (scoped_property_access_expression + scope: (name) @php-class) (member_call_expression name: (name) @php-method-call) (object_creation_expression (name) @php-class) diff --git a/tests/php-ts-mode-resources/indent.erts b/tests/php-ts-mode-resources/indent.erts index d3533fe..7e1c23e 100644 --- a/tests/php-ts-mode-resources/indent.erts +++ b/tests/php-ts-mode-resources/indent.erts @@ -105,3 +105,19 @@ class Test } } =-=-= + +Name: Switch + +=-= + Date: Tue, 21 May 2024 21:32:57 +0300 Subject: [PATCH 04/13] built-in functions highlight --- README.md | 2 +- php-ts-mode.el | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1d2bd8b..04b3e62 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ Running `M-x treesit-install-language-grammar [RET] php` will compile and instal In `php-ts-mode`, syntax elements are classified as follows. * **Level 1**: `comment` `definition` `preprocessor` - * **Level 2**: `keyword` `string` `type` + * **Level 2**: `keyword` `string` `type` `built-in` * **Level 3**: `function` `constant` `label` * **Level 4**: `bracket` `delimiter` `operator` `variables` `this` diff --git a/php-ts-mode.el b/php-ts-mode.el index ef9ba63..e62c595 100644 --- a/php-ts-mode.el +++ b/php-ts-mode.el @@ -105,6 +105,10 @@ "while" "yield") "PHP keywords for tree-sitter font-locking.") +(defvar php-ts-mode--built-in-functions + '("die" "echo" "empty" "isset") + "PHP built-in functions for tree-sitter font-locking.") + (defvar php-ts-mode--operators '("!=" "!==" "%" "%=" "&" "&&" "&=" "*" "**" "*=" "+" "++" "+=" "," "-" "-" "--" "-=" "->" "." @@ -259,6 +263,16 @@ see https://www.php.net/manual/language.constants.predefined.php") (goto_statement "goto" @php-keyword) (yield_expression "from" @php-keyword)) + :language 'php + :feature 'built-in + :override t + `((function_call_expression + function: (name) @php-keyword + (:match ,(rx-to-string + `(seq bol + (or ,@php-ts-mode--built-in-functions) + eol)) @php-keyword))) + :language 'php :feature 'label `((goto_statement (name) @php-keyword) @@ -359,7 +373,7 @@ Currently there are `php-mode' and `php-ts-mode'." (setq-local treesit-font-lock-settings php-ts-mode--font-lock-settings) (setq-local treesit-font-lock-feature-list '((comment definition preprocessor) - (keyword string type) + (keyword string type built-in) (function constant label) (bracket delimiter operator variables this))) From bf1dadec5c09ff7de4f5d4846503a52ea07724b6 Mon Sep 17 00:00:00 2001 From: Nikita Alekseev Date: Tue, 21 May 2024 23:46:26 +0300 Subject: [PATCH 05/13] object_creation_expression qualified_name highlight --- php-ts-mode.el | 3 +++ 1 file changed, 3 insertions(+) diff --git a/php-ts-mode.el b/php-ts-mode.el index e62c595..a943ed3 100644 --- a/php-ts-mode.el +++ b/php-ts-mode.el @@ -209,6 +209,9 @@ see https://www.php.net/manual/language.constants.predefined.php") (member_call_expression name: (name) @php-method-call) (object_creation_expression (name) @php-class) + (object_creation_expression + (qualified_name (namespace_name_as_prefix) @php-class + (name) @php-class)) (attribute (name) @php-class) (attribute (qualified_name) @php-class) From 8128af1279fd3593b8da13b5c7386845e8025cfa Mon Sep 17 00:00:00 2001 From: Nikita Alekseev Date: Wed, 22 May 2024 00:48:11 +0300 Subject: [PATCH 06/13] face tests --- tests/php-ts-mode-resources/face.erts | 51 +++++++++++++++++++++++++++ tests/php-ts-mode-tests.el | 6 +++- 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 tests/php-ts-mode-resources/face.erts diff --git a/tests/php-ts-mode-resources/face.erts b/tests/php-ts-mode-resources/face.erts new file mode 100644 index 0000000..43eb865 --- /dev/null +++ b/tests/php-ts-mode-resources/face.erts @@ -0,0 +1,51 @@ +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)))) + (erase-buffer) + (insert face))) + +Name: Open php tag +Point-Char: | +No-After-Newline: t + +=-= + Date: Wed, 22 May 2024 21:52:48 +0300 Subject: [PATCH 07/13] add tests --- tests/php-ts-mode-resources/face.erts | 92 +++++++++++++++++++++++++ tests/php-ts-mode-resources/indent.erts | 33 +++++++-- 2 files changed, 120 insertions(+), 5 deletions(-) diff --git a/tests/php-ts-mode-resources/face.erts b/tests/php-ts-mode-resources/face.erts index 43eb865..c067440 100644 --- a/tests/php-ts-mode-resources/face.erts +++ b/tests/php-ts-mode-resources/face.erts @@ -49,3 +49,95 @@ class Ba|sic {} =-= php-class =-=-= + +Name: Class base clause +No-After-Newline: t + +=-= + Date: Wed, 22 May 2024 23:11:42 +0300 Subject: [PATCH 08/13] update rules and tests --- php-ts-mode.el | 24 ++++-------- tests/php-ts-mode-resources/face.erts | 54 ++++++++++++++++++++++++++- 2 files changed, 61 insertions(+), 17 deletions(-) diff --git a/php-ts-mode.el b/php-ts-mode.el index a943ed3..76dc6e1 100644 --- a/php-ts-mode.el +++ b/php-ts-mode.el @@ -165,11 +165,7 @@ see https://www.php.net/manual/language.constants.predefined.php") (:match ,(rx bos (? "_") (in "A-Z") (+ (in "0-9A-Z_")) eos) @php-constant)) (class_constant_access_expression - (name) @php-class) - (class_constant_access_expression - (qualified_name - (namespace_name_as_prefix) @php-class - (name) @php-class)) + [(name) (qualified_name)] @php-class) [(boolean) (null)] @php-constant @@ -179,6 +175,7 @@ see https://www.php.net/manual/language.constants.predefined.php") :language 'php :feature 'definition + :override t `((class_declaration name: (name) @php-class) (interface_declaration @@ -189,11 +186,12 @@ see https://www.php.net/manual/language.constants.predefined.php") name: (name) @php-class) (enum_case name: (name) @php-class) - (base_clause (name) @php-class) + (base_clause [(name) (qualified_name)] @php-class) (use_declaration (name) @php-class)) :language 'php :feature 'function + :override t `((array_creation_expression "array" @php-builtin) (list_literal "list" @php-builtin) (method_declaration @@ -201,20 +199,14 @@ see https://www.php.net/manual/language.constants.predefined.php") (function_call_expression function: [(qualified_name (name)) (name)] @php-function-call) (scoped_call_expression - scope: (name) @php-class) - (scoped_call_expression + scope: [(name) (qualified_name)] @php-class name: (name) @php-static-method-call) (scoped_property_access_expression - scope: (name) @php-class) + scope: [(name) (qualified_name)] @php-class) (member_call_expression name: (name) @php-method-call) - (object_creation_expression (name) @php-class) - (object_creation_expression - (qualified_name (namespace_name_as_prefix) @php-class - (name) @php-class)) - (attribute (name) @php-class) - (attribute (qualified_name) @php-class) - + (object_creation_expression [(name) (qualified_name)] @php-class) + (attribute [(name) (qualified_name)] @php-class) (function_definition name: (name) @php-function-name)) diff --git a/tests/php-ts-mode-resources/face.erts b/tests/php-ts-mode-resources/face.erts index c067440..4ea3db9 100644 --- a/tests/php-ts-mode-resources/face.erts +++ b/tests/php-ts-mode-resources/face.erts @@ -50,7 +50,7 @@ class Ba|sic {} php-class =-=-= -Name: Class base clause +Name: Base clause No-After-Newline: t =-= @@ -60,6 +60,16 @@ class Basic extends Par|ent{} php-class =-=-= +Name: Base clause with qualified name +No-After-Newline: t + +=-= + Date: Thu, 23 May 2024 18:44:54 +0300 Subject: [PATCH 09/13] add match expression indent, update keywords --- php-ts-mode.el | 8 +++++--- tests/php-ts-mode-resources/face.erts | 23 +++++++++++++++++++++-- tests/php-ts-mode-resources/indent.erts | 14 ++++++++++++++ 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/php-ts-mode.el b/php-ts-mode.el index 76dc6e1..36ed0d0 100644 --- a/php-ts-mode.el +++ b/php-ts-mode.el @@ -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.") @@ -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 @@ -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 diff --git a/tests/php-ts-mode-resources/face.erts b/tests/php-ts-mode-resources/face.erts index 4ea3db9..9dea923 100644 --- a/tests/php-ts-mode-resources/face.erts +++ b/tests/php-ts-mode-resources/face.erts @@ -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))) @@ -40,6 +39,16 @@ class Basic { php-keyword =-=-= +Name: Keyword `match` +No-After-Newline: t + +=-= + 1 +}; +=-= + 1 +}; +=-=-= From 27ae09ee6afc790425bde6d88ba8a71401f5e615 Mon Sep 17 00:00:00 2001 From: Nikita Alekseev Date: Sun, 26 May 2024 17:26:36 +0300 Subject: [PATCH 10/13] instanceof keyword and class highlight --- php-ts-mode.el | 7 +++++-- tests/php-ts-mode-resources/face.erts | 10 ++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/php-ts-mode.el b/php-ts-mode.el index 36ed0d0..15fed4d 100644 --- a/php-ts-mode.el +++ b/php-ts-mode.el @@ -100,7 +100,7 @@ "elseif" "enddeclare" "endforeach" "endif" "endswitch" "endwhile" "enum" "extends" "final" "finally" "for" "foreach" "fn" "function" "global" "if" "implements" "include_once" - "include" "insteadof" "interface" "match" "namespace" "new" + "include" "instanceof" "insteadof" "interface" "match" "namespace" "new" "private" "protected" "public" "readonly" "require_once" "require" "return" "static" "switch" "throw" "trait" "try" "use" "while" "yield") @@ -172,7 +172,10 @@ see https://www.php.net/manual/language.constants.predefined.php") @php-constant [(integer) (float)] - @font-lock-number-face) + @font-lock-number-face + (binary_expression + operator: "instanceof" + right: [(name) (qualified_name)] @php-class)) :language 'php :feature 'definition diff --git a/tests/php-ts-mode-resources/face.erts b/tests/php-ts-mode-resources/face.erts index 9dea923..329d0e2 100644 --- a/tests/php-ts-mode-resources/face.erts +++ b/tests/php-ts-mode-resources/face.erts @@ -212,3 +212,13 @@ class Test {} =-= php-class =-=-= + +Name: Instanceof class +No-After-Newline: t + +=-= + Date: Mon, 27 May 2024 22:23:10 +0300 Subject: [PATCH 11/13] remove php-ts-face --- php-ts-face.el | 44 -------------------------------------------- php-ts-mode.el | 1 - 2 files changed, 45 deletions(-) delete mode 100644 php-ts-face.el diff --git a/php-ts-face.el b/php-ts-face.el deleted file mode 100644 index cd5fb6f..0000000 --- a/php-ts-face.el +++ /dev/null @@ -1,44 +0,0 @@ -;;; php-ts-face.el --- Face definitions for PHP script -*- lexical-binding: t; -*- - -;; Copyright (C) 2023 Friends of Emacs-PHP development - -;; Author: USAMI Kenta -;; Created: 5 May 2019 -;; Version: 1.25.0 -;; Keywords: faces, php -;; Homepage: https://github.com/emacs-php/php-mode -;; License: GPL-3.0-or-later - -;; This program is free software; you can redistribute it and/or modify -;; it under the terms of the GNU General Public License as published by -;; the Free Software Foundation, either version 3 of the License, or -;; (at your option) any later version. - -;; This program is distributed in the hope that it will be useful, -;; but WITHOUT ANY WARRANTY; without even the implied warranty of -;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -;; GNU General Public License for more details. - -;; You should have received a copy of the GNU General Public License -;; along with this program. If not, see . - -;;; Commentary: - -;; Face definitions for PHP script. - -;;; Code: - -;;;###autoload - -(defface php-this '((t (:inherit php-constant))) - "PHP Mode face used to highlight $this variables." - :group 'php-faces - :tag "PHP $this") - -(defface php-this-sigil '((t (:inherit php-constant))) - "PHP Mode face used to highlight sigils($) of $this variable." - :group 'php-faces - :tag "PHP $this Sigil") - -(provide 'php-ts-face) -;;; php-ts-face.el ends here diff --git a/php-ts-mode.el b/php-ts-mode.el index 15fed4d..5590451 100644 --- a/php-ts-mode.el +++ b/php-ts-mode.el @@ -36,7 +36,6 @@ (require 'c-ts-common) (require 'php nil t) (require 'php-face nil t) -(require 'php-ts-face nil t) (declare-function php-base-mode "ext:php") (declare-function treesit-parser-create "treesit.c") From b7eb35243281480e0c0bc8ba1650d4981c898e04 Mon Sep 17 00:00:00 2001 From: Nikita Alekseev Date: Mon, 27 May 2024 23:03:57 +0300 Subject: [PATCH 12/13] remove built-in feature --- README.md | 2 +- php-ts-mode.el | 11 ++++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 04b3e62..1d2bd8b 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ Running `M-x treesit-install-language-grammar [RET] php` will compile and instal In `php-ts-mode`, syntax elements are classified as follows. * **Level 1**: `comment` `definition` `preprocessor` - * **Level 2**: `keyword` `string` `type` `built-in` + * **Level 2**: `keyword` `string` `type` * **Level 3**: `function` `constant` `label` * **Level 4**: `bracket` `delimiter` `operator` `variables` `this` diff --git a/php-ts-mode.el b/php-ts-mode.el index 5590451..f22a3fa 100644 --- a/php-ts-mode.el +++ b/php-ts-mode.el @@ -256,15 +256,12 @@ see https://www.php.net/manual/language.constants.predefined.php") :language 'php :feature 'keyword + :override t `([,@php-ts-mode--keywords] @php-keyword (print_intrinsic "print" @php-keyword) (goto_statement "goto" @php-keyword) - (yield_expression "from" @php-keyword)) - - :language 'php - :feature 'built-in - :override t - `((function_call_expression + (yield_expression "from" @php-keyword) + (function_call_expression function: (name) @php-keyword (:match ,(rx-to-string `(seq bol @@ -372,7 +369,7 @@ Currently there are `php-mode' and `php-ts-mode'." (setq-local treesit-font-lock-settings php-ts-mode--font-lock-settings) (setq-local treesit-font-lock-feature-list '((comment definition preprocessor) - (keyword string type built-in) + (keyword string type) (function constant label) (bracket delimiter operator variables this))) From e59eeb3eea09e88879aa7e617432953a4c40d984 Mon Sep 17 00:00:00 2001 From: Nikita Alekseev Date: Tue, 28 May 2024 18:15:13 +0300 Subject: [PATCH 13/13] update use_declaration and class_interface_clause rules --- php-ts-mode.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/php-ts-mode.el b/php-ts-mode.el index f22a3fa..35016b8 100644 --- a/php-ts-mode.el +++ b/php-ts-mode.el @@ -155,7 +155,7 @@ see https://www.php.net/manual/language.constants.predefined.php") (namespace_name (name)) (optional_type "?" @php-type)] @php-type - (class_interface_clause (name) @php-class) + (class_interface_clause [(name) (qualified_name)] @php-class) (class_constant_access_expression (name) @php-keyword (:match ,(rx bos "class" eos) @@ -190,7 +190,7 @@ see https://www.php.net/manual/language.constants.predefined.php") (enum_case name: (name) @php-class) (base_clause [(name) (qualified_name)] @php-class) - (use_declaration (name) @php-class)) + (use_declaration [(name) (qualified_name)] @php-class)) :language 'php :feature 'function