From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jostein =?UTF-8?Q?Kj=C3=B8nigsen?= Newsgroups: gmane.emacs.bugs Subject: bug#65470: 29.1.50; js-ts-mode: regex pattern can cause incorrect parenthesis matching Date: Tue, 12 Sep 2023 08:29:41 +0200 Message-ID: <16E4F60E-5216-457F-A79F-F8FBB5A01D61@secure.kjonigsen.net> References: <127B5BEA-A24B-48A3-9827-85B7CDB67D10@secure.kjonigsen.net> <5f823f8f-d249-f4a1-71e6-083e47d0d123@gutov.dev> <83jztbeeh2.fsf@gnu.org> <03415a27-f082-b204-cece-19a9859e178d@gutov.dev> <8334zze5l4.fsf@gnu.org> <1363c54f-5109-f000-3333-78d291b2096d@gutov.dev> <2D516F0C-D7A8-49D2-8009-F911EFC55C78@secure.kjonigsen.net> <2f525ebe-74e5-dcbe-4403-5e9ae001795c@gutov.dev> <5e57b91b-2967-d82d-eca5-65dc206887cf@gutov.dev> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.700.6\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_F29D2F9D-B7F9-424F-8522-303783573221" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="16435"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Yuan Fu , 65470@debbugs.gnu.org, Theodor Thornhill , btuin@mailo.com, Eli Zaretskii , Jostein =?UTF-8?Q?Kj=C3=B8nigsen?= To: Dmitry Gutov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Sep 12 08:31:22 2023 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 1qfwvg-00047h-Hm for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 12 Sep 2023 08:31:22 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qfwvQ-0007Wc-Hd; Tue, 12 Sep 2023 02:31:05 -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 1qfwvN-0007WA-UJ for bug-gnu-emacs@gnu.org; Tue, 12 Sep 2023 02:31:01 -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 1qfwvK-00015E-47 for bug-gnu-emacs@gnu.org; Tue, 12 Sep 2023 02:31:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qfwvO-0004st-H1 for bug-gnu-emacs@gnu.org; Tue, 12 Sep 2023 02:31:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Jostein =?UTF-8?Q?Kj=C3=B8nigsen?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 12 Sep 2023 06:31:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 65470 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 65470-submit@debbugs.gnu.org id=B65470.169450021018707 (code B ref 65470); Tue, 12 Sep 2023 06:31:02 +0000 Original-Received: (at 65470) by debbugs.gnu.org; 12 Sep 2023 06:30:10 +0000 Original-Received: from localhost ([127.0.0.1]:55796 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qfwuY-0004rd-BL for submit@debbugs.gnu.org; Tue, 12 Sep 2023 02:30:10 -0400 Original-Received: from out3-smtp.messagingengine.com ([66.111.4.27]:34547) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qfwuV-0004q0-7R for 65470@debbugs.gnu.org; Tue, 12 Sep 2023 02:30:08 -0400 Original-Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 68A915C01BE; Tue, 12 Sep 2023 02:29:57 -0400 (EDT) Original-Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Tue, 12 Sep 2023 02:29:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= secure.kjonigsen.net; h=cc:cc:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to; s=fm3; t= 1694500197; x=1694586597; bh=diupV9epe/WAB1dSYoAveuB/NbQoKDDhp1E u5i522Pk=; b=c/gyXublDDlyh58Y21gYblpgZX6dgBROduQSThCH0RKs4uFWYpK LYiVOQQyX83yEFlgkbLqyulhnI91oQzIW5BHQh+5ZtEp8VnB7Rnk+TUE+dab/uBk gCJCwmnZMI/jZG09Ho7IpnzHNS/cfUxpsJAxEXqLFgtVvf+rlEaAO81WefqDBRfG HjV5shUsSvlAdrekyy2Xr8pYLJinf82xCG1Y7Sy1KKjV4IKu/stpQGZFuU/vlCHQ 2laRVO0WzYKTYfYYUsFlD62ewnHT9NWJWppmwDDiRyMwysxaiV2PwODC/Wy9RdkC YN6tqdIuplM6IOTP2H0P2NgU3oEF1lMqmsg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; t=1694500197; x=1694586597; bh=diupV9epe/WAB 1dSYoAveuB/NbQoKDDhp1Eu5i522Pk=; b=BVv8d3N3SBRuIQMzBIJxkyc5qOCUC 9Szek8Jjb/gQj4QUDvIlYKliD0F6ETN4m7ILRfXg8Ja2TT9ES/hC7SfvyCrkRAXz 5eVe7POyQX8sWtjDiNghM2xvZ6T+Fe/2ZdZDSvdzkmOEB0wdX8yduCxFqcCMkniV cS5/p5OXTcQyQtPaPZbRjhK9bjp/+ag2wvBYeedDNtCaJsv91uERUZt2p8iR914f jhdXxI63GV37BjjrIOAGLN3wcmt1Fl5JnAS83RVWVxeAJ7hNzhMKYgDEapgR23MB D07mBO/hqKLzP4Tm6XfgFoKr0ins40101oRu8gEL0sm6cS4vokv6HQCQw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrudeihedguddthecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhkfgtggfuffgjvefvfhfosehmtdhmrehhtdejnecuhfhrohhmpeflohhs thgvihhnucfmjhppnhhighhsvghnuceojhhoshhtvghinhesshgvtghurhgvrdhkjhhonh highhsvghnrdhnvghtqeenucggtffrrghtthgvrhhnpeejtdejffeggfeuffeuvefhveek ffdtiedtffelteeuiefgvdejheeihfehheekgfenucevlhhushhtvghrufhiiigvpedtne curfgrrhgrmhepmhgrihhlfhhrohhmpehjohhsthgvihhnsehsvggtuhhrvgdrkhhjohhn ihhgshgvnhdrnhgvth X-ME-Proxy: Feedback-ID: ib2f84088:Fastmail Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 12 Sep 2023 02:29:55 -0400 (EDT) In-Reply-To: <5e57b91b-2967-d82d-eca5-65dc206887cf@gutov.dev> X-Mailer: Apple Mail (2.3731.700.6) 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:270139 Archived-At: --Apple-Mail=_F29D2F9D-B7F9-424F-8522-303783573221 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 On 12 Sep 2023, at 00:23, Dmitry Gutov wrote: >=20 > Hi Jostein! >=20 > The patch looks good overall (though I haven't tested it). >=20 > On 11/09/2023 22:37, Jostein Kj=C3=B8nigsen wrote: >=20 > > So to fix that, I=E2=80=99ve tried to anchor the query to top-level = constructs which typically does not nest. Looking at the query for = js.el, I can only assume that you were trying to too solve the same = problem, Dmitry? >=20 > That's right. >=20 >> + ((arguments (jsx_element) @jsx)) >> + ((parenthesized_expression = (jsx_element) @jsx)))))) >=20 > These two contexts actually seem missing in my patch for js-ts-mode. = :-) >=20 > OTOH, it seems like the ones that _are_ included there, are missing = here. Don't they? >=20 > ((variable_declarator value: (jsx_element) @jsx)) >=20 > corresponds do >=20 > let v =3D
...
>=20 > ((assignment_expression right: (jsx_element) @jsx)) >=20 > corresponds do >=20 > v =3D

...

>=20 > (with variable declared previously), and >=20 > ((return_statement (jsx_element) @jsx)) >=20 > corresponds to >=20 > function f() { > return

...
; > } Good feedback. I=E2=80=99ve tested and included those as well. Attached = is a new patch. --Apple-Mail=_F29D2F9D-B7F9-424F-8522-303783573221 Content-Disposition: attachment; filename=0001-typescript-ts-mode-Fix-syntax-properties-for-regexp-.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="0001-typescript-ts-mode-Fix-syntax-properties-for-regexp-.patch" Content-Transfer-Encoding: quoted-printable =46rom=2016eb97efd5442e65eebd83bce2469aaee6d11697=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20=3D?UTF-8?q?Jostein=3D20Kj=3DC3=3DB8nigsen?=3D=20= =0ADate:=20Tue,=205=20Sep=202023=2021:29:27=20= +0200=0ASubject:=20[PATCH]=20typescript-ts-mode:=20Fix=20syntax=20= properties=20for=20regexp=0A=20expressions.=0A=0A-=20Also=20handle=20= JSX-elements=20in=20TSX-files=20as=20generic=20strings.=0A---=0A=20= lisp/progmodes/typescript-ts-mode.el=20|=2039=20= ++++++++++++++++++++++++++++=0A=201=20file=20changed,=2039=20= insertions(+)=0A=0Adiff=20--git=20a/lisp/progmodes/typescript-ts-mode.el=20= b/lisp/progmodes/typescript-ts-mode.el=0Aindex=20= 441cdc1f7aa..4bf4cf1f85f=20100644=0A---=20= a/lisp/progmodes/typescript-ts-mode.el=0A+++=20= b/lisp/progmodes/typescript-ts-mode.el=0A@@=20-473,6=20+473,7=20@@=20= typescript-ts-mode=0A=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20(keyword=20string=20escape-sequence)=0A=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20(constant=20expression=20identifier=20number=20= pattern=20property)=0A=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20(function=20bracket=20delimiter)))=0A+=20=20=20=20(setq-local=20= syntax-propertize-function=20#'ts-ts--syntax-propertize)=0A=20=0A=20=20=20= =20=20(treesit-major-mode-setup)))=0A=20=0A@@=20-529,9=20+530,47=20@@=20= tsx-ts-mode=0A=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= (keyword=20string=20escape-sequence)=0A=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20(constant=20expression=20identifier=20jsx=20number=20= pattern=20property)=0A=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20(function=20bracket=20delimiter)))=0A+=20=20=20=20(setq-local=20= syntax-propertize-function=20#'tsx-ts--syntax-propertize)=0A=20=0A=20=20=20= =20=20(treesit-major-mode-setup)))=0A=20=0A+(defvar=20ts-ts--s-p-query=0A= +=20=20(when=20(treesit-available-p)=0A+=20=20=20=20= (treesit-query-compile=20'typescript=0A+=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20'(((regex=20pattern:=20= (regex_pattern)=20@regexp))))))=0A+=0A+(defvar=20tsx-ts--s-p-query=0A+=20= =20=20=20=20=20(when=20(treesit-available-p)=0A+=20=20=20=20=20=20=20=20= (treesit-query-compile=20'tsx=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20'(((regex=20pattern:=20= (regex_pattern)=20@regexp))=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= ((variable_declarator=20value:=20(jsx_element)=20@jsx))=0A+=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20((assignment_expression=20right:=20(jsx_element)=20@jsx))=0A+=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20((arguments=20(jsx_element)=20@jsx))=0A+=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20((parenthesized_expression=20(jsx_element)=20@jsx))=0A+=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20((return_statement=20(jsx_element)=20@jsx))))))=0A+=0A= +(defun=20ts-ts--syntax-propertize=20(beg=20end)=0A+=20=20(let=20= ((captures=20(treesit-query-capture=20'typescript=20ts-ts--s-p-query=20= beg=20end)))=0A+=20=20=20=20(ts-ts--syntax-propertize-captures=20= captures)))=0A+=0A+(defun=20tsx-ts--syntax-propertize=20(beg=20end)=0A+=20= =20(let=20((captures=20(treesit-query-capture=20'tsx=20tsx-ts--s-p-query=20= beg=20end)))=0A+=20=20=20=20(ts-ts--syntax-propertize-captures=20= captures)))=0A+=0A+(defun=20ts-ts--syntax-propertize-captures=20= (captures)=0A+=20=20(pcase-dolist=20(`(,name=20.=20,node)=20captures)=0A= +=20=20=20=20(let*=20((ns=20(treesit-node-start=20node))=0A+=20=20=20=20=20= =20=20=20=20=20=20(ne=20(treesit-node-end=20node))=0A+=20=20=20=20=20=20=20= =20=20=20=20(syntax=20(pcase-exhaustive=20name=0A+=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20('regexp=0A+=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20(cl-decf=20ns)=0A+=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20(cl-incf=20ne)=0A+=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= (string-to-syntax=20"\"/"))=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20('jsx=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20(string-to-syntax=20"|")))))=0A+=20=20=20=20=20=20= (put-text-property=20ns=20(1+=20ns)=20'syntax-table=20syntax)=0A+=20=20=20= =20=20=20(put-text-property=20(1-=20ne)=20ne=20'syntax-table=20= syntax))))=0A+=0A=20(if=20(treesit-ready-p=20'tsx)=0A=20=20=20=20=20= (add-to-list=20'auto-mode-alist=20'("\\.tsx\\'"=20.=20tsx-ts-mode)))=0A=20= =0A--=20=0A2.39.2=20(Apple=20Git-143)=0A=0A= --Apple-Mail=_F29D2F9D-B7F9-424F-8522-303783573221 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 =E2=80=94 Jostein --Apple-Mail=_F29D2F9D-B7F9-424F-8522-303783573221--