From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Vincenzo Pupillo Newsgroups: gmane.emacs.bugs Subject: bug#73516: 30.0.91; [PATCH] php-ts-mode: add support for the latest grammar version. Date: Fri, 27 Sep 2024 15:00:40 +0200 Message-ID: <2626895.XAFRqVoOGU@3-191.divsi.unimi.it> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="nextPart3688908.dWV9SEqChM" Content-Transfer-Encoding: 7Bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="4716"; mail-complaints-to="usenet@ciao.gmane.io" To: 73516@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Sep 27 15:32:54 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1suB5a-00012D-Cw for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 27 Sep 2024 15:32:54 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1suB5K-0000g1-0b; Fri, 27 Sep 2024 09:32:38 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1suB5H-0000Wm-DF for bug-gnu-emacs@gnu.org; Fri, 27 Sep 2024 09:32:35 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1suB5H-00072G-21 for bug-gnu-emacs@gnu.org; Fri, 27 Sep 2024 09:32:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:From:To:Subject; bh=76CTqJtcY5zqHwuM1YmQgJY8OltbfhNIl3UDhaXT69o=; b=R+Nz/biNvXBhKhizFm5tdk1+98bSURlujGVyr3Hw7HGYSUzCeIv5PBp371b1wheMcBht+SjkA9/hlzR2BO3VW8YJaTjrLgmEByaTPrxeynk6Uf8a2HDS3HXXMfqZnw0w5ox7gitS7MaOYXSPsrgjsV2ZrN+J6GYTeVS6Z9geNWkFjpsH/saEYQ43vDv2L7oxF40d7qtw6Rard9jLpIAl32ZWQqZE6jnTQ3GzNWNh1X9QOzicwwt4KbPudVANaNWXz+qe80FGx8evS0D3KbJFAOARMquXXBUPRx9RCLgE4HnvMWuZU4JzGUCBMVS6of3s81IatoEi0B0T4kXRLuIwBg==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1suB5i-0003ky-Fe for bug-gnu-emacs@gnu.org; Fri, 27 Sep 2024 09:33:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Vincenzo Pupillo Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 27 Sep 2024 13:33:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 73516 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: Bug Emacs Original-Received: via spool by submit@debbugs.gnu.org id=B.172744396614393 (code B ref -1); Fri, 27 Sep 2024 13:33:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 27 Sep 2024 13:32:46 +0000 Original-Received: from localhost ([127.0.0.1]:33717 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1suB5R-0003k0-RI for submit@debbugs.gnu.org; Fri, 27 Sep 2024 09:32:46 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:38766) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1suB5P-0003jq-ST for submit@debbugs.gnu.org; Fri, 27 Sep 2024 09:32:44 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1suAaX-0001qh-IA for bug-gnu-emacs@gnu.org; Fri, 27 Sep 2024 09:00:50 -0400 Original-Received: from mail-ed1-x529.google.com ([2a00:1450:4864:20::529]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1suAaT-0001N6-P0 for bug-gnu-emacs@gnu.org; Fri, 27 Sep 2024 09:00:48 -0400 Original-Received: by mail-ed1-x529.google.com with SMTP id 4fb4d7f45d1cf-5c5cc65a8abso2160276a12.3 for ; Fri, 27 Sep 2024 06:00:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727442043; x=1728046843; darn=gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=76CTqJtcY5zqHwuM1YmQgJY8OltbfhNIl3UDhaXT69o=; b=hfSBZfkoSd23fsmFtRhQQWeiuoLzKLUINS14kwls4iUGf3Zr3kfd6rRiETwFSWLrD0 53DcOat73nAf90PYKqSH8kuIK6+N9kvsvFCRFDFgzgqKHhzsEegIORFsG+dlzvEwa8kl q3u/rBZK0L3Q7BdmQ+45fkopD3S9Y7tUVY0VuQjDsSi7i/sAQ5bY+Oa7V+U0T9H0gE6M RAwRXfOAJ6x7UM/ZdLSI3p4QipEOspvd6ZuH5S1wUn2UGeYOKaAZTLoOsyzTXxuM5mWw cSasYJaP5+ZLZgpM/FZhrisBxJoTfPf+w7fasKsdwUDMOBOFp8HzY3h5iEm0yEAjkcRB 372g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727442043; x=1728046843; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=76CTqJtcY5zqHwuM1YmQgJY8OltbfhNIl3UDhaXT69o=; b=dglozDXhXUQbpIFxNkoBI38KFgKjTOf09pIdMGHV9rK2V5kCt0vd9sN+JdTOdGNAFm YLFm5n4dGOD+X5+4KJGmxFSPkhm22ilhuWLe7tjMS22x8vQonNo/yBhXZ/Hkg+HUNNHm usS1oiT3DZd9MRHFrBKOrdaxBEAR4NV2tStL/sRZZnhOZAsHMPfDpXJpdE3MEbUfzSrr zxLz7594w2L1c+U2UiJUSXR9gHERipG0YpJz+5t1v6nklN9coK4ANBznAChiNZNX1cFj mDv3RqqGrNk1t8Sw7VrQxA2+GD3tN21xA6nRmpJj4BpZnI2mvedjtwKgL5Pr+tbnJsxq C+Qw== X-Gm-Message-State: AOJu0Yxjk+WC75dCKMMcOg1qYHIj+TCfD28K6lqMkblkmsdUyN4pxiat sgqcufdBNQsdIigl2iMHXfTihBZ3BvfPp4b+IYCwoF4GSaLaeY9Zt1CzDw== X-Google-Smtp-Source: AGHT+IEDxO7NJEaQnQWlu5lyykeQ87ptU/tK7bC3aulPuKzrIEUhlktlOkqxIzqFprRu1p1yBFY9Fg== X-Received: by 2002:a17:907:748:b0:a86:a30f:4aef with SMTP id a640c23a62f3a-a93c49199b6mr256773266b.22.1727442042477; Fri, 27 Sep 2024 06:00:42 -0700 (PDT) Original-Received: from 3-191.divsi.unimi.it (3-191.divsi.unimi.it. [159.149.3.191]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a93c27c5b7fsm132144066b.66.2024.09.27.06.00.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Sep 2024 06:00:41 -0700 (PDT) Received-SPF: pass client-ip=2a00:1450:4864:20::529; envelope-from=v.pupillo@gmail.com; helo=mail-ed1-x529.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:292516 Archived-At: This is a multi-part message in MIME format. --nextPart3688908.dWV9SEqChM Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="utf-8" 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 --nextPart3688908.dWV9SEqChM Content-Disposition: attachment; filename="0001-Fix-php-ts-mode-font-lock-for-latest-PHP-grammar.patch" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="UTF-8"; name="0001-Fix-php-ts-mode-font-lock-for-latest-PHP-grammar.patch" >From 669090265e653f457c7876461238c3898e4f3696 Mon Sep 17 00:00:00 2001 From: Vincenzo Pupillo 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 , 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 --nextPart3688908.dWV9SEqChM--