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: Mon, 11 Sep 2023 21:37:33 +0200 Message-ID: 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> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.700.6\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_534169EB-EDC4-4502-8530-9ADE1A4AB4EE" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="29838"; 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 Mon Sep 11 21:38:13 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 1qfmjc-0007TL-8V for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 11 Sep 2023 21:38:13 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qfmjQ-00038o-F6; Mon, 11 Sep 2023 15:38:00 -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 1qfmjP-00038U-1N for bug-gnu-emacs@gnu.org; Mon, 11 Sep 2023 15:37:59 -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 1qfmjO-00047L-Ky for bug-gnu-emacs@gnu.org; Mon, 11 Sep 2023 15:37:58 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qfmjS-0002sy-Dz for bug-gnu-emacs@gnu.org; Mon, 11 Sep 2023 15:38: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: Mon, 11 Sep 2023 19:38: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.169446108111086 (code B ref 65470); Mon, 11 Sep 2023 19:38:02 +0000 Original-Received: (at 65470) by debbugs.gnu.org; 11 Sep 2023 19:38:01 +0000 Original-Received: from localhost ([127.0.0.1]:54904 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qfmjR-0002sj-BM for submit@debbugs.gnu.org; Mon, 11 Sep 2023 15:38:01 -0400 Original-Received: from out1-smtp.messagingengine.com ([66.111.4.25]:35823) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qfmjM-0002sB-Ms for 65470@debbugs.gnu.org; Mon, 11 Sep 2023 15:37:59 -0400 Original-Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id EF3875C00AC; Mon, 11 Sep 2023 15:37:46 -0400 (EDT) Original-Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Mon, 11 Sep 2023 15:37:46 -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= 1694461066; x=1694547466; bh=0UTxWWHdmRxm5u1MqTag9sl4H7p8RaK9gkF R6o6Djic=; b=sIzypUQRnHQdvK7R29AUnWc0df3XPdXO3Us9ViRvhm4yXjsl82o x/BSGdH+mKwk7+E7V7UwVL8OLC2teKZOlxACmeUZ4GOCQVNh9rI/nnsy9aFF288t uoMSDOLnuBJklHOF2ejnskDU16kccT/FoWo7Ll5Yvii4D6mmgT4k8EejGBcQRzF7 Y8YxCxdvPJQRbT1hXf0XB24rnT0B1n4AgQvk9nezU34OJ13+gQf8Jv/f7xElLjig AxRjfNGDu83i9LlBLOwn9lZd+JgSg6k0IJnoqRTzzaDS0uOx2BBC+h4t8Osg2vIA BPO8oIi2MfbqJW7iB2xTmxkG9LIxbUT+0Fw== 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=1694461066; x=1694547466; bh=0UTxWWHdmRxm5 u1MqTag9sl4H7p8RaK9gkFR6o6Djic=; b=iyq2fv41yL2JDUQQg5n/qpEVAmmd2 Au9EQCkSHYwV+dgM/lwJZ7O8PCrXa9V5fGbAEQLRHWnIDttDHZJZJFOR2M4QPDQY rquXGSJTreD8BPpd4PH+cNDgzm1FEYnuyyZt2eUfuhAMCDMwjXKHauS+rHlKpkv9 p87OGdyVaOo4DPuVzSbeSFn2Dhw+FX9tzPcUlx09zmTYY2ikyLoRy+uDhiiYPZgs +N8qI5XPp4mmKd/s3vYeB2XCcJSjLoK/YMh9SKF33NFmOa9QtpDlau19eVUCXbKS cRGg/qssArBbGLC5O4a+IzhaT5bJCkWWRpEaFGaB3enjecmNDWWfamlGg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrudeigedgudefjecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhkfgtggfuffgjvefvfhfosehmtdhmrehhtdejnecuhfhrohhmpeflohhs thgvihhnucfmjhppnhhighhsvghnuceojhhoshhtvghinhesshgvtghurhgvrdhkjhhonh highhsvghnrdhnvghtqeenucggtffrrghtthgvrhhnpeejtdejffeggfeuffeuvefhveek ffdtiedtffelteeuiefgvdejheeihfehheekgfenucevlhhushhtvghrufhiiigvpedtne curfgrrhgrmhepmhgrihhlfhhrohhmpehjohhsthgvihhnsehsvggtuhhrvgdrkhhjohhn ihhgshgvnhdrnhgvth X-ME-Proxy: Feedback-ID: ib2f84088:Fastmail Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 11 Sep 2023 15:37:44 -0400 (EDT) In-Reply-To: <2f525ebe-74e5-dcbe-4403-5e9ae001795c@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:270080 Archived-At: --Apple-Mail=_534169EB-EDC4-4502-8530-9ADE1A4AB4EE Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On 7 Sep 2023, at 14:09, Dmitry Gutov wrote: >=20 > On 05/09/2023 22:31, Jostein Kj=C3=B8nigsen wrote: > > The patch so far is attached. It=E2=80=99s intentionally -not- = optimized to leave room for TSX cases which may arise, so hopefully no = need to nitpick this yet. >=20 > I was going to nitpick it, but then read the rest of your message ;-( >=20 >> However the patch for js-ts-mode has lots of =E2=80=A6 interesting = stuff about jsx I have not included, for no other reason than not = understanding what type of use-cases they are meant to support. >> If someone can provide me some examples for the JSX use-cases, I can = try to make room for TSX-variants of the same code. >=20 > The idea was to "enclose" every TSX in "generic string" syntax so that = whatever unpaired characters are inside (such as (, ", ...), won't = affect syntax-ppss status on the outside. I'm not sure how critical that = is, but I guess some users might encounter such situations. >=20 > Examples like: >=20 > ReactDOM.render( >
>

Hello, Welcome to React and TypeScript ;-(

>
, > // type closing paren here and see that it's matched to opener = above > document.getElementById("root") > ); >=20 Ok. That makes sense, and explains everything. I=E2=80=99ve tried = implementing the same thing for tsx-ts-mode too in the attached patch. = (You may start nitpicking now). I first tried using a more naive and wide approach only trying to = capture full (jsx_element) blocks without any further constraints. What I found was that when having nested elements (which one tend to = have all the time), the syntax-propertizing would cancel itself for = every second nesting. 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? But without further ado=E2=80=A6 Here=E2=80=99s the patch. Do your = worst, gentlemen :D --Apple-Mail=_534169EB-EDC4-4502-8530-9ADE1A4AB4EE 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=202f08456a4aa6a093cbda4359af31edcd5864a44c=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|=2036=20= ++++++++++++++++++++++++++++=0A=201=20file=20changed,=2036=20= insertions(+)=0A=0Adiff=20--git=20a/lisp/progmodes/typescript-ts-mode.el=20= b/lisp/progmodes/typescript-ts-mode.el=0Aindex=20= 441cdc1f7aa..dd61baf5e3c=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,44=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(when=20(treesit-available-p)=0A+=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'(((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((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= ((parenthesized_expression=20(jsx_element)=20@jsx))))))=0A+=0A+(defun=20= ts-ts--syntax-propertize=20(beg=20end)=0A+=20=20(let=20((captures=20= (treesit-query-capture=20'typescript=20ts-ts--s-p-query=20beg=20end)))=0A= +=20=20=20=20(ts-ts--syntax-propertize-captures=20captures)))=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=20beg=20= end)))=0A+=20=20=20=20(ts-ts--syntax-propertize-captures=20captures)))=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=20= ns=20(1+=20ns)=20'syntax-table=20syntax)=0A+=20=20=20=20=20=20= (put-text-property=20(1-=20ne)=20ne=20'syntax-table=20syntax))))=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=0A= 2.39.2=20(Apple=20Git-143)=0A=0A= --Apple-Mail=_534169EB-EDC4-4502-8530-9ADE1A4AB4EE Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 =E2=80=94 Jostein= --Apple-Mail=_534169EB-EDC4-4502-8530-9ADE1A4AB4EE--