From: Yuan Fu <casouri@gmail.com>
To: Vincenzo Pupillo <v.pupillo@gmail.com>
Cc: 73516-done@debbugs.gnu.org
Subject: bug#73516: 30.0.91; [PATCH] php-ts-mode: add support for the latest grammar version.
Date: Sat, 28 Sep 2024 01:07:56 -0700 [thread overview]
Message-ID: <46C10E7C-C98F-4FA6-887A-EFD7EB306FC4@gmail.com> (raw)
In-Reply-To: <2626895.XAFRqVoOGU@3-191.divsi.unimi.it>
[-- Attachment #1: Type: text/plain, Size: 332 bytes --]
> On Sep 27, 2024, at 6:00 AM, Vincenzo Pupillo <v.pupillo@gmail.com> wrote:
>
> Ciao,
> as usual the latest version of PHP grammar breaks the font lock.
> This patch supports both the old and the latest grammar.
> Version 0.23 supports the new features of PHP 8.4 (in release candidate).
>
> Thank you.
> Vincenzo
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fix-php-ts-mode-font-lock-for-latest-PHP-grammar.patch --]
[-- Type: text/x-patch; x-unix-mode=0644; name="0001-Fix-php-ts-mode-font-lock-for-latest-PHP-grammar.patch", Size: 5649 bytes --]
From 669090265e653f457c7876461238c3898e4f3696 Mon Sep 17 00:00:00 2001
From: Vincenzo Pupillo <v.pupillo@gmail.com>
Date: Fri, 27 Sep 2024 13:07:06 +0200
Subject: [PATCH] Fix php-ts-mode font-lock for latest PHP grammar.
Version 0.23 of the PHP grammar introduced some changes that affect the
font lock.
* lisp/progmodes/php-ts-mode.el
(php-ts-mode--language-source-alist): Update php, html, js and css
grammars version.
(php-ts-mode--parent-html-heuristic): Fix docstring
(php-ts-mode--test-namespace-name-as-prefix-p): New function.
(php-ts-mode--test-namespace-aliasing-clause-p): New function.
(php-ts-mode--test-namespace-use-group-clause-p): New function.
(php-ts-mode--font-lock-settings): Use the new functions.
---
lisp/progmodes/php-ts-mode.el | 47 ++++++++++++++++++++++++++---------
1 file changed, 35 insertions(+), 12 deletions(-)
diff --git a/lisp/progmodes/php-ts-mode.el b/lisp/progmodes/php-ts-mode.el
index 3f89de14075..87aefaf451f 100644
--- a/lisp/progmodes/php-ts-mode.el
+++ b/lisp/progmodes/php-ts-mode.el
@@ -83,12 +83,12 @@
;;; Install treesitter language parsers
(defvar php-ts-mode--language-source-alist
- '((php . ("https://github.com/tree-sitter/tree-sitter-php" "v0.22.8" "php/src"))
+ '((php . ("https://github.com/tree-sitter/tree-sitter-php" "v0.23.0" "php/src"))
(phpdoc . ("https://github.com/claytonrcarter/tree-sitter-phpdoc"))
- (html . ("https://github.com/tree-sitter/tree-sitter-html" "v0.20.3"))
- (javascript . ("https://github.com/tree-sitter/tree-sitter-javascript" "v0.21.2"))
- (jsdoc . ("https://github.com/tree-sitter/tree-sitter-jsdoc" "v0.21.0"))
- (css . ("https://github.com/tree-sitter/tree-sitter-css" "v0.21.0")))
+ (html . ("https://github.com/tree-sitter/tree-sitter-html" "v0.23.0"))
+ (javascript . ("https://github.com/tree-sitter/tree-sitter-javascript" "v0.23.0"))
+ (jsdoc . ("https://github.com/tree-sitter/tree-sitter-jsdoc" "v0.23.0"))
+ (css . ("https://github.com/tree-sitter/tree-sitter-css" "v0.23.0")))
"Treesitter language parsers required by `php-ts-mode'.
You can customize this variable if you want to stick to a specific
commit and/or use different parsers.")
@@ -490,7 +490,7 @@ php-ts-mode--parent-html-bol
(treesit-node-start parent)))))
(defun php-ts-mode--parent-html-heuristic (node parent _bol &rest _)
- "Returns position based on html indentation.
+ "Return position based on html indentation.
Returns 0 if the NODE is after the </html>, otherwise returns the
indentation point of the last word before the NODE, plus the
@@ -773,6 +773,21 @@ php-ts-mode--predefined-constant
"__FUNCTION__" "__LINE__" "__METHOD__" "__NAMESPACE__" "__TRAIT__")
"PHP predefined constant.")
+(defun php-ts-mode--test-namespace-name-as-prefix-p ()
+ "Return t if the namespace_name_as_prefix keyword is a namded node, nil otherwise."
+ (ignore-errors
+ (progn (treesit-query-compile 'php "(namespace_name_as_prefix)" t) t)))
+
+(defun php-ts-mode--test-namespace-aliasing-clause-p ()
+ "Return t if the namespace_name_as_prefix keyword is a namded node, nil otherwise."
+ (ignore-errors
+ (progn (treesit-query-compile 'php "(namespace_name_as_prefix)" t) t)))
+
+(defun php-ts-mode--test-namespace-use-group-clause-p ()
+ "Return t if the namespace_use_group_clause keyword is a namded node, nil otherwise."
+ (ignore-errors
+ (progn (treesit-query-compile 'php "(namespace_use_group_clause)" t) t)))
+
(defun php-ts-mode--font-lock-settings ()
"Tree-sitter font-lock settings."
(treesit-font-lock-rules
@@ -866,7 +881,7 @@ php-ts-mode--font-lock-settings
:language 'php
:feature 'definition
:override t
- '((php_tag) @font-lock-preprocessor-face
+ `((php_tag) @font-lock-preprocessor-face
("?>") @font-lock-preprocessor-face
;; Highlights identifiers in declarations.
(class_declaration
@@ -889,10 +904,16 @@ php-ts-mode--font-lock-settings
("=>") @font-lock-keyword-face
(object_creation_expression
(name) @font-lock-type-face)
- (namespace_name_as_prefix "\\" @font-lock-delimiter-face)
- (namespace_name_as_prefix (namespace_name (name)) @font-lock-type-face)
- (namespace_use_clause (name) @font-lock-property-use-face)
- (namespace_aliasing_clause (name) @font-lock-type-face)
+ ,@(when (php-ts-mode--test-namespace-name-as-prefix-p)
+ '((namespace_name_as_prefix "\\" @font-lock-delimiter-face)
+ (namespace_name_as_prefix
+ (namespace_name (name)) @font-lock-type-face)))
+ ,@(if (php-ts-mode--test-namespace-aliasing-clause-p)
+ '((namespace_aliasing_clause (name) @font-lock-type-face))
+ '((namespace_use_clause alias: (name) @font-lock-type-face)))
+ ,@(when (not (php-ts-mode--test-namespace-use-group-clause-p))
+ '((namespace_use_group
+ (namespace_use_clause (name) @font-lock-type-face))))
(namespace_name "\\" @font-lock-delimiter-face)
(namespace_name (name) @font-lock-type-face)
(use_declaration (name) @font-lock-property-use-face))
@@ -931,8 +952,10 @@ php-ts-mode--font-lock-settings
:language 'php
:feature 'base-clause
:override t
- '((base_clause (name) @font-lock-type-face)
+ `((base_clause (name) @font-lock-type-face)
(use_as_clause (name) @font-lock-property-use-face)
+ ,@(when (not (php-ts-mode--test-namespace-name-as-prefix-p))
+ '((qualified_name prefix: "\\" @font-lock-delimiter-face)))
(qualified_name (name) @font-lock-constant-face))
:language 'php
--
2.46.1
[-- Attachment #3: Type: text/plain, Size: 34 bytes --]
Thanks! Merged to emacs-30.
Yuan
prev parent reply other threads:[~2024-09-28 8:07 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-27 13:00 bug#73516: 30.0.91; [PATCH] php-ts-mode: add support for the latest grammar version Vincenzo Pupillo
2024-09-28 8:07 ` Yuan Fu [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=46C10E7C-C98F-4FA6-887A-EFD7EB306FC4@gmail.com \
--to=casouri@gmail.com \
--cc=73516-done@debbugs.gnu.org \
--cc=v.pupillo@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).