From: Yuan Fu <casouri@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 61235@debbugs.gnu.org, Mickey Petersen <mickey@masteringemacs.org>
Subject: bug#61235: 30.0.50; tree-sit: `treesit-node-check' lacks a way to tell if a node belongs to a deleted parser
Date: Mon, 6 Feb 2023 20:55:38 -0800 [thread overview]
Message-ID: <4C7AB77E-FBB6-4F34-A73A-297243E2E3AF@gmail.com> (raw)
In-Reply-To: <83ilgep2ww.fsf@gnu.org>
[-- Attachment #1: Type: text/plain, Size: 1207 bytes --]
> On Feb 6, 2023, at 7:31 PM, Eli Zaretskii <eliz@gnu.org> wrote:
>
>> From: Yuan Fu <casouri@gmail.com>
>> Date: Mon, 6 Feb 2023 19:00:30 -0800
>> Cc: Mickey Petersen <mickey@masteringemacs.org>,
>> 61235@debbugs.gnu.org
>>
>>> Yuan, any reason not to extend treesit-node-check instead?
>>
>> I did extend treesit-node-check in the patch. But I also added a function treesit-parser-live-p, which makes the same check but directly on a parser. It just made sense to me that if we let treesit-node-check check the nodes’ parser’s status, we’d also add a function to allow directly checking the status of a parser.
>
> That additional function would signal an error in the case discussed
> here, so I'm not sure we should add it in that shape, or at all. Why
> isn't treesit-node-check enough?
Oops, it shouldn’t have. The updated patch fixes that. Treesit-node-check is enough, it just made more sense implentattion-wise, to implement that function that checks a parser, and let treesit-node-check use that function to check the node’s parser. We can choose to not expose that function, and only expose this feature through treesit-node-check, if you prefer so.
Yuan
[-- Attachment #2: livep.patch --]
[-- Type: application/octet-stream, Size: 2856 bytes --]
From 08765f4f61d63398307e3401313c45a60d65edee Mon Sep 17 00:00:00 2001
From: Yuan Fu <casouri@gmail.com>
Date: Sun, 5 Feb 2023 20:22:52 -0800
Subject: [PATCH] Demo
---
src/treesit.c | 26 +++++++++++++++++++++++---
1 file changed, 23 insertions(+), 3 deletions(-)
diff --git a/src/treesit.c b/src/treesit.c
index 8e772523cc7..f2c3e9845d1 100644
--- a/src/treesit.c
+++ b/src/treesit.c
@@ -1471,6 +1471,19 @@ DEFUN ("treesit-parser-language",
return XTS_PARSER (parser)->language_symbol;
}
+DEFUN ("treesit-parser-live-p",
+ Ftreesit_parser_live_p, Streesit_parser_live_p, 1, 1, 0,
+ doc: /* Check whether PARSER is not deleted and its buffer is live. */)
+ (Lisp_Object parser)
+{
+ if (XTS_PARSER (parser)->deleted)
+ return Qnil;
+ else if (NILP (Fbuffer_live_p (XTS_PARSER (parser)->buffer)))
+ return Qnil;
+ else
+ return Qt;
+}
+
/*** Parser API */
DEFUN ("treesit-parser-root-node",
@@ -1904,7 +1917,8 @@ DEFUN ("treesit-node-check",
Ftreesit_node_check, Streesit_node_check, 2, 2, 0,
doc: /* Return non-nil if NODE has PROPERTY, nil otherwise.
-PROPERTY could be `named', `missing', `extra', `outdated', or `has-error'.
+PROPERTY could be `named', `missing', `extra', `outdated',
+`has-error', or `live'.
Named nodes correspond to named rules in the language definition,
whereas "anonymous" nodes correspond to string literals in the
@@ -1920,7 +1934,9 @@ DEFUN ("treesit-node-check",
the node was created.
A node "has error" if itself is a syntax error or contains any syntax
-errors. */)
+errors.
+
+A node is "live" if its parser is live (i.e., not deleted). */)
(Lisp_Object node, Lisp_Object property)
{
if (NILP (node)) return Qnil;
@@ -1943,9 +1959,11 @@ DEFUN ("treesit-node-check",
result = ts_node_is_extra (treesit_node);
else if (EQ (property, Qhas_error))
result = ts_node_has_error (treesit_node);
+ else if (EQ (property, Qlive))
+ result = Ftreesit_parser_live_p (XTS_NODE (node)->parser);
else
signal_error ("Expecting `named', `missing', `extra', "
- "`outdated', or `has-error', but got",
+ "`outdated', `has-error', or `deleted', but got",
property);
return result ? Qt : Qnil;
}
@@ -3444,6 +3462,7 @@ syms_of_treesit (void)
DEFSYM (Qextra, "extra");
DEFSYM (Qoutdated, "outdated");
DEFSYM (Qhas_error, "has-error");
+ DEFSYM (Qlive, "live");
DEFSYM (QCanchor, ":anchor");
DEFSYM (QCequal, ":equal");
@@ -3577,6 +3596,7 @@ syms_of_treesit (void)
defsubr (&Streesit_parser_list);
defsubr (&Streesit_parser_buffer);
defsubr (&Streesit_parser_language);
+ defsubr (&Streesit_parser_live_p);
defsubr (&Streesit_parser_root_node);
/* defsubr (&Streesit_parse_string); */
--
2.33.1
next prev parent reply other threads:[~2023-02-07 4:55 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-02 19:46 bug#61235: 30.0.50; tree-sit: `treesit-node-check' lacks a way to tell if a node belongs to a deleted parser Mickey Petersen
2023-02-06 4:24 ` Yuan Fu
2023-02-06 12:34 ` Eli Zaretskii
2023-02-06 12:35 ` Mickey Petersen
2023-02-06 13:19 ` Eli Zaretskii
2023-02-06 13:19 ` Mickey Petersen
2023-02-06 14:05 ` Eli Zaretskii
2023-02-06 14:08 ` Mickey Petersen
2023-02-06 15:21 ` Eli Zaretskii
2023-02-07 3:00 ` Yuan Fu
2023-02-07 3:31 ` Eli Zaretskii
2023-02-07 4:55 ` Yuan Fu [this message]
2023-02-07 12:24 ` Eli Zaretskii
2023-02-08 3:54 ` Yuan Fu
2023-02-07 8:03 ` Mickey Petersen
2023-02-08 3:52 ` Yuan Fu
2023-02-08 8:41 ` Mickey Petersen
2023-02-10 1:28 ` 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=4C7AB77E-FBB6-4F34-A73A-297243E2E3AF@gmail.com \
--to=casouri@gmail.com \
--cc=61235@debbugs.gnu.org \
--cc=eliz@gnu.org \
--cc=mickey@masteringemacs.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).