From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#73404: 30.0.50; [forward/kill/etc]-sexp commands do not behave as expected in tree-sitter modes Date: Fri, 27 Dec 2024 09:59:52 +0200 Organization: LINKOV.NET Message-ID: <87r05to7vb.fsf@mail.linkov.net> References: <87plox4mtp.fsf@masteringemacs.org> <87frpm20t7.fsf@masteringemacs.org> <8634lmbs8t.fsf@gnu.org> <87bk0a1u0o.fsf@masteringemacs.org> <86tte2a5o3.fsf@gnu.org> <877cay1lqt.fsf@masteringemacs.org> <86frpma06f.fsf@gnu.org> <86ikueiekp.fsf@mail.linkov.net> <86ed4zg1cc.fsf@mail.linkov.net> <87zflac68t.fsf@mail.linkov.net> <87jzcdlxdp.fsf@mail.linkov.net> <87o71jocgs.fsf@mail.linkov.net> <87wmfwqg7e.fsf@mail.linkov.net> <87ikr8hpdu.fsf@mail.linkov.net> <856C1B51-D9BC-4794-95CF-28E9B9B59325@gmail.com> <871pxw430m.fsf@mail.linkov.net> <8D171A7A-D565-4BEF-AE56-1308C69FE5AC@gmail.com> <87r05vznir.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="34531"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/31.0.50 (x86_64-pc-linux-gnu) Cc: Theodor Thornhill , Eli Zaretskii , Mickey Petersen , 73404@debbugs.gnu.org, Stefan Monnier To: Yuan Fu Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Dec 27 09:29:23 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 1tR5il-0008pQ-6k for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 27 Dec 2024 09:29:23 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tR5iU-0002Fh-AU; Fri, 27 Dec 2024 03:29:06 -0500 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 1tR5iQ-0002FN-JW for bug-gnu-emacs@gnu.org; Fri, 27 Dec 2024 03:29:02 -0500 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 1tR5iQ-0004dP-BL for bug-gnu-emacs@gnu.org; Fri, 27 Dec 2024 03:29:02 -0500 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:References:In-Reply-To:From:To:Subject; bh=w0rkv1xkxHIVZemwZ//vESAKL9FbJhEZXeRNQBXiipc=; b=dTurRYZIHOX6xr+k9+IxKbvmWeIlGZHXiofKqI9BE0sjuCi6ePm/Nnj4eDRg++LH3tKWXf+mu0QuYplH3WcGGM/tS3je9Ug2B+1ErOEW5khi7sJn9jBbtkInnMW56OamGxDUhBHBct0xOzbtZDpoY+WW+osvA0xmc7QyLQmKA7JqMFNiOakOo5t5mLSiBknNCxxWOQXUW5NTXTi9uyMshnRznNCOcXtIfPxxRCkyeRtKd21ZAzsu5zqxlUfZtWxcolVg2M7CYlwiZQ+7uEFLfaaTwt1RzFE3sLurxgzKdlixMUNe1y7tNAxd4nXz4rhuuZjcok1aiZ5Sc8xdX6CxwQ==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tR5iQ-00037g-2F for bug-gnu-emacs@gnu.org; Fri, 27 Dec 2024 03:29:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 27 Dec 2024 08:29:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 73404 X-GNU-PR-Package: emacs Original-Received: via spool by 73404-submit@debbugs.gnu.org id=B73404.173528808711939 (code B ref 73404); Fri, 27 Dec 2024 08:29:02 +0000 Original-Received: (at 73404) by debbugs.gnu.org; 27 Dec 2024 08:28:07 +0000 Original-Received: from localhost ([127.0.0.1]:44608 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tR5hW-00036V-Ko for submit@debbugs.gnu.org; Fri, 27 Dec 2024 03:28:06 -0500 Original-Received: from relay5-d.mail.gandi.net ([217.70.183.197]:44729) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tR5hU-00035t-JP for 73404@debbugs.gnu.org; Fri, 27 Dec 2024 03:28:05 -0500 Original-Received: by mail.gandi.net (Postfix) with ESMTPSA id 76B091C0003; Fri, 27 Dec 2024 08:27:36 +0000 (UTC) In-Reply-To: <87r05vznir.fsf@mail.linkov.net> (Juri Linkov's message of "Wed, 25 Dec 2024 19:36:48 +0200") X-GND-Sasl: juri@linkov.net 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:297814 Archived-At: >> I can’t think of an counter example other than for_statment in >> tree-sitter-c. > > Indeed, the 'for_statement' is a hard problem, and I see > no good solution. A possible solution would be to find a way to create "virtual" nodes. This means transforming the existing syntax tree by inserting addition nodes to it. For example, transforming (for_statement "for" "(" condition: (assignment_expression left: (identifier) operator: "=" right: (number_literal)) ; body: (binary_expression left: (identifier) operator: "<" right: (number_literal)) ; (update_expression operator: "++" argument: (identifier)) ")" into (for_statement "for" (for_parameters "(" condition: (assignment_expression left: (identifier) operator: "=" right: (number_literal)) ; body: (binary_expression left: (identifier) operator: "<" right: (number_literal)) ; (update_expression operator: "++" argument: (identifier)) ")" by inserting the virtual node "for_parameters". Not sure if such transformation is supported by tree-sitter. Generally, we have two problems with syntax trees created by the authors of tree-sitter grammars: 1. Insufficient structure 2. Excessive structure For insufficient structure a possible solution would be to insert virtual nodes like above. And for excessive structure we need to flatten some nodes. For example, in c-ts-mode: static -!-struct atimer *free_atimers; 'C-M-f' unexpectedly jumped not to the next symbol, but to static struct atimer-!- *free_atimers; because of too much structure built in the syntax tree: (declaration type: (storage_class_specifier "static") declarator: (struct_specifier "struct" name: (type_identifier)) (pointer_declarator "*" declarator: (identifier)) ";") So the solution could be to flatten 'struct_specifier' to move 'type_identifier' to be a sibling in the same list inside 'declaration': (declaration type: (storage_class_specifier "static") declarator: (struct_specifier "struct") (type_identifier) (pointer_declarator "*" declarator: (identifier)) ";") Also not sure if such thing is possible in tree-sitter.