unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Basil Contovounesios via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Dmitry Gutov <dmitry@gutov.dev>
Cc: Randy Taylor <dev@rjt.dev>, Yuan Fu <casouri@gmail.com>,
	64019@debbugs.gnu.org, Theodor Thornhill <theo@thornhill.no>,
	Daniel Colascione <dancol@dancol.org>
Subject: bug#64019: 29.0.91; Fix some tree-sitter :match regexps
Date: Tue, 13 Jun 2023 15:08:01 +0100	[thread overview]
Message-ID: <87fs6vbgla.fsf@epfl.ch> (raw)
In-Reply-To: <1959ea93-0ca3-59cd-3abb-e841bd337c57@gutov.dev> (Dmitry Gutov's message of "Tue, 13 Jun 2023 00:33:08 +0300")

[-- Attachment #1: Type: text/plain, Size: 1313 bytes --]

Dmitry Gutov [2023-06-13 00:33 +0300] wrote:

> On 12/06/2023 17:25, Basil L. Contovounesios via Bug reports for GNU Emacs, the
> Swiss army knife of text editors wrote:
>> -      (:match "^DEFUN$" @fn))
>> +      (:match "\\`DEFUN\\'" @fn))
>
> FWIW, most of these changes are superfluous, practically speaking

I'm less concerned about the trivial bol/bos conversions in the patch
and more about the corrections to incorrect regexps, such as:
- the more benign \(:?...\) -> \(?:...\)
- and the less benign [\d] -> [0-9].

> because node text for these node types (like 'identifier', in this
> example) cannot include newlines.
>
> So we mostly gain some theoretical increase in strictness, 

We also gain the fact that the next one looking at these regexps doesn't
need to figure out whether newlines can appear in this context: the
regexp immediately says it's intended to match the whole given text
rather than a line of text.

> at the expense of a few extra chars in the code.

That's not really an expense, but a symptom of our regexp syntax, so it
can't be helped.

> So I think we could wait until 29.1's release, for example, and then apply this
> on master.

Those parts that will end up applied on master don't need to wait for
29.1, do they?  If so, why?

Here's the updated patch against emacs-29:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fix-some-tree-sitter-match-regexps.patch --]
[-- Type: text/x-diff, Size: 5755 bytes --]

From fd04e8b781634a0c193435d3d3f175dc9a60975f Mon Sep 17 00:00:00 2001
From: "Basil L. Contovounesios" <contovob@tcd.ie>
Date: Tue, 13 Jun 2023 13:53:31 +0100
Subject: [PATCH] Fix some tree-sitter :match regexps

The shy groups were caught by modified versions of the GNU ELPA
packages xr and relint:
- https://github.com/mattiase/xr/pull/6
- https://github.com/mattiase/relint/pull/14

* lisp/progmodes/java-ts-mode.el (java-ts-mode--font-lock-settings):
* lisp/progmodes/js.el (js--plain-method-re):
(js--treesit-font-lock-settings):
* lisp/progmodes/rust-ts-mode.el (rust-ts-mode--font-lock-settings):
* lisp/progmodes/typescript-ts-mode.el
(typescript-ts-mode--font-lock-settings): Replace character
alternative [\\d], which matches '\' or 'd', with the most likely
intention [0-9].  Fix shy groups mistyped as optional colons.
Remove unneeded numbered :match group in rust-ts-mode (bug#64019).
---
 lisp/progmodes/java-ts-mode.el       |  2 +-
 lisp/progmodes/js.el                 |  6 +++---
 lisp/progmodes/rust-ts-mode.el       | 13 ++++++++-----
 lisp/progmodes/typescript-ts-mode.el |  4 ++--
 4 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/lisp/progmodes/java-ts-mode.el b/lisp/progmodes/java-ts-mode.el
index 463872dcbc8..7f2fc4188a3 100644
--- a/lisp/progmodes/java-ts-mode.el
+++ b/lisp/progmodes/java-ts-mode.el
@@ -168,7 +168,7 @@ java-ts-mode--font-lock-settings
    :override t
    :feature 'constant
    `(((identifier) @font-lock-constant-face
-      (:match "\\`[A-Z_][A-Z_\\d]*\\'" @font-lock-constant-face))
+      (:match "\\`[A-Z_][0-9A-Z_]*\\'" @font-lock-constant-face))
      [(true) (false)] @font-lock-constant-face)
    :language 'java
    :override t
diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index 414b6eb2baf..48fecf69537 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -106,7 +106,7 @@ js--opt-cpp-start
 
 (defconst js--plain-method-re
   (concat "^\\s-*?\\(" js--dotted-name-re "\\)\\.prototype"
-          "\\.\\(" js--name-re "\\)\\s-*?=\\s-*?\\(\\(:?async[ \t\n]+\\)function\\)\\_>")
+          "\\.\\(" js--name-re "\\)\\s-*?=\\s-*?\\(\\(?:async[ \t\n]+\\)function\\)\\_>")
   "Regexp matching an explicit JavaScript prototype \"method\" declaration.
 Group 1 is a (possibly-dotted) class name, group 2 is a method name,
 and group 3 is the `function' keyword.")
@@ -3493,7 +3493,7 @@ js--treesit-font-lock-settings
    :language 'javascript
    :feature 'constant
    '(((identifier) @font-lock-constant-face
-      (:match "\\`[A-Z_][A-Z_\\d]*\\'" @font-lock-constant-face))
+      (:match "\\`[A-Z_][0-9A-Z_]*\\'" @font-lock-constant-face))
 
      [(true) (false) (null)] @font-lock-constant-face)
 
@@ -3612,7 +3612,7 @@ js--treesit-font-lock-settings
    :feature 'number
    '((number) @font-lock-number-face
      ((identifier) @font-lock-number-face
-      (:match "\\`\\(:?NaN\\|Infinity\\)\\'" @font-lock-number-face)))
+      (:match "\\`\\(?:NaN\\|Infinity\\)\\'" @font-lock-number-face)))
 
    :language 'javascript
    :feature 'operator
diff --git a/lisp/progmodes/rust-ts-mode.el b/lisp/progmodes/rust-ts-mode.el
index b55af0b49e3..999c1d7ae96 100644
--- a/lisp/progmodes/rust-ts-mode.el
+++ b/lisp/progmodes/rust-ts-mode.el
@@ -143,7 +143,7 @@ rust-ts-mode--font-lock-settings
                               eol))
                       @font-lock-builtin-face)))
      ((identifier) @font-lock-type-face
-      (:match "\\`\\(:?Err\\|Ok\\|None\\|Some\\)\\'" @font-lock-type-face)))
+      (:match "\\`\\(?:Err\\|Ok\\|None\\|Some\\)\\'" @font-lock-type-face)))
 
    :language 'rust
    :feature 'comment
@@ -232,9 +232,12 @@ rust-ts-mode--font-lock-settings
      (type_identifier) @font-lock-type-face
      ((scoped_identifier name: (identifier) @rust-ts-mode--fontify-tail))
      ((scoped_identifier path: (identifier) @font-lock-type-face)
-      (:match
-       "\\`\\(u8\\|u16\\|u32\\|u64\\|u128\\|usize\\|i8\\|i16\\|i32\\|i64\\|i128\\|isize\\|char\\|str\\)\\'"
-       @font-lock-type-face))
+      (:match ,(rx bos
+                   (or "u8" "u16" "u32" "u64" "u128" "usize"
+                       "i8" "i16" "i32" "i64" "i128" "isize"
+                       "char" "str")
+                   eos)
+              @font-lock-type-face))
      ((scoped_identifier path: (identifier) @rust-ts-mode--fontify-scope))
      ((scoped_type_identifier path: (identifier) @rust-ts-mode--fontify-scope))
      (type_identifier) @font-lock-type-face)
@@ -249,7 +252,7 @@ rust-ts-mode--font-lock-settings
    :feature 'constant
    `((boolean_literal) @font-lock-constant-face
      ((identifier) @font-lock-constant-face
-      (:match "\\`[A-Z][A-Z\\d_]*\\'" @font-lock-constant-face)))
+      (:match "\\`[A-Z][0-9A-Z_]*\\'" @font-lock-constant-face)))
 
    :language 'rust
    :feature 'variable
diff --git a/lisp/progmodes/typescript-ts-mode.el b/lisp/progmodes/typescript-ts-mode.el
index 5df34de0472..68aefd90f92 100644
--- a/lisp/progmodes/typescript-ts-mode.el
+++ b/lisp/progmodes/typescript-ts-mode.el
@@ -153,7 +153,7 @@ typescript-ts-mode--font-lock-settings
    :language language
    :feature 'constant
    `(((identifier) @font-lock-constant-face
-      (:match "\\`[A-Z_][A-Z_\\d]*\\'" @font-lock-constant-face))
+      (:match "\\`[A-Z_][0-9A-Z_]*\\'" @font-lock-constant-face))
      [(true) (false) (null)] @font-lock-constant-face)
 
    :language language
@@ -311,7 +311,7 @@ typescript-ts-mode--font-lock-settings
    :feature 'number
    `((number) @font-lock-number-face
      ((identifier) @font-lock-number-face
-      (:match "\\`\\(:?NaN\\|Infinity\\)\\'" @font-lock-number-face)))
+      (:match "\\`\\(?:NaN\\|Infinity\\)\\'" @font-lock-number-face)))
 
    :language language
    :feature 'operator
-- 
2.34.1


[-- Attachment #3: Type: text/plain, Size: 27 bytes --]


WDYT?

Thanks,

-- 
Basil

  parent reply	other threads:[~2023-06-13 14:08 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-12 14:25 bug#64019: 29.0.91; Fix some tree-sitter :match regexps Basil L. Contovounesios via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-06-12 14:48 ` Mattias Engdegård
2023-06-12 15:10   ` Basil Contovounesios via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-06-12 15:37     ` Eli Zaretskii
2023-06-12 20:22       ` Basil Contovounesios via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-06-13  2:36         ` Eli Zaretskii
2023-06-13 13:51           ` Basil Contovounesios via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-06-12 16:07     ` Mattias Engdegård
2023-06-12 21:39       ` Dmitry Gutov
2023-06-13  7:47         ` Mattias Engdegård
2023-06-13 17:06           ` Dmitry Gutov
2023-06-12 21:33 ` Dmitry Gutov
2023-06-13  2:37   ` Eli Zaretskii
2023-06-13 14:08   ` Basil Contovounesios via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2023-06-13 17:06     ` Dmitry Gutov
2023-06-15 17:17     ` Basil Contovounesios via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-06-17  2:00       ` Dmitry Gutov
2023-06-17  6:48         ` Andreas Schwab
2023-06-17  8:39           ` Mattias Engdegård
2023-06-17 12:21             ` Mattias Engdegård
2023-06-17 15:44             ` Dmitry Gutov
2023-06-17 16:13               ` Basil Contovounesios via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-06-17 16:34                 ` Eli Zaretskii
2023-06-17 16:56                   ` Basil Contovounesios via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-06-17 17:35                     ` Eli Zaretskii
2023-06-17 19:54                       ` Basil Contovounesios via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-30 12:46                       ` Basil L. Contovounesios via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-30 12:59                         ` Eli Zaretskii
2023-07-30 16:04                           ` Basil L. Contovounesios via Bug reports for GNU Emacs, the Swiss army knife of text editors

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=87fs6vbgla.fsf@epfl.ch \
    --to=bug-gnu-emacs@gnu.org \
    --cc=64019@debbugs.gnu.org \
    --cc=casouri@gmail.com \
    --cc=contovob@tcd.ie \
    --cc=dancol@dancol.org \
    --cc=dev@rjt.dev \
    --cc=dmitry@gutov.dev \
    --cc=theo@thornhill.no \
    /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).