unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Yuan Fu <casouri@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 60659@debbugs.gnu.org
Subject: bug#60659: 30.0.50; tree-sitter: identical nodes are not `equal'
Date: Mon, 9 Jan 2023 21:56:19 -0800	[thread overview]
Message-ID: <1B5F5D8C-8DD3-4ED1-95C2-E975461BC5FC@gmail.com> (raw)
In-Reply-To: <87lemdjctn.fsf@masteringemacs.org>

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


Mickey Petersen <mickey@masteringemacs.org> writes:

> Yuan Fu <casouri@gmail.com> writes:
>
>> Mickey Petersen <mickey@masteringemacs.org> writes:
>>
>>> In order to check for node equality, one must use `treesit-node-eq'.
>>>
>>> But I see little reason why two identical nodes in in the same tree aren't `equal'?
>>
>> Indeed. I’ll see if I can extend equal to handle tree-sitter nodes.
>>
>
> Nice one. This will allow for membership checks with `member' and
> such-like and it'll greatly cut down on custom code, particularly one
> you start writing tests!
>
>> Yuan

Eli, does this look right to you? In particular, I’m not sure if it’s ok to call a lisp function (Ftreesit_node_eq) inside internal_equal, even though it never signals. 

Yuan


[-- Attachment #2: equal.diff --]
[-- Type: application/octet-stream, Size: 878 bytes --]

diff --git a/src/fns.c b/src/fns.c
index 1aaf17914a2..c0ecc735bc5 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -38,6 +38,10 @@ Copyright (C) 1985-2023 Free Software Foundation, Inc.
 #include "puresize.h"
 #include "gnutls.h"
 
+#ifdef HAVE_TREE_SITTER
+#include "treesit.h"
+#endif
+
 enum equal_kind { EQUAL_NO_QUIT, EQUAL_PLAIN, EQUAL_INCLUDING_PROPERTIES };
 static bool internal_equal (Lisp_Object, Lisp_Object,
 			    enum equal_kind, int, Lisp_Object);
@@ -2822,6 +2826,10 @@ internal_equal (Lisp_Object o1, Lisp_Object o2, enum equal_kind equal_kind,
 		    && !memcmp (bool_vector_data (o1), bool_vector_data (o2),
 			        bool_vector_bytes (size)));
 	  }
+	if (TS_NODEP (o1))
+	  {
+	    return !NILP (Ftreesit_node_eq (o1, o2));
+	  }
 
 	/* Aside from them, only true vectors, char-tables, compiled
 	   functions, and fonts (font-spec, font-entity, font-object)

  parent reply	other threads:[~2023-01-10  5:56 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-08 14:55 bug#60659: 30.0.50; tree-sitter: identical nodes are not `equal' Mickey Petersen
2023-01-09  3:59 ` Yuan Fu
2023-01-09  8:55   ` Mickey Petersen
2023-01-10  5:56 ` Yuan Fu [this message]
2023-01-10 13:11   ` Eli Zaretskii
2023-01-11  2:57 ` Yuan Fu
2023-01-11 12:26   ` Eli Zaretskii
2023-01-13  1:08 ` Yuan Fu

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=1B5F5D8C-8DD3-4ED1-95C2-E975461BC5FC@gmail.com \
    --to=casouri@gmail.com \
    --cc=60659@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    /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).