From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Pranshu Sharma via "Emacs development discussions." Newsgroups: gmane.emacs.devel Subject: Re: Treesitter injection support Date: Sun, 05 Jan 2025 02:33:42 +1000 Message-ID: <87sepyv8rd.fsf@bauherren.ovh> References: <87ed1lb7bw.fsf@bauherren.ovh> <30BA6520-0862-40A7-89BB-5AB020ADC7F9@gmail.com> Reply-To: Pranshu Sharma Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="21494"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: emacs-devel@gnu.org To: Yuan Fu Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Jan 04 18:38:39 2025 Return-path: Envelope-to: ged-emacs-devel@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 1tU86g-0005Q6-C8 for ged-emacs-devel@m.gmane-mx.org; Sat, 04 Jan 2025 18:38:38 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tU85s-0003pN-B4; Sat, 04 Jan 2025 12:37:48 -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 1tU76L-0006ZV-PY for emacs-devel@gnu.org; Sat, 04 Jan 2025 11:34:15 -0500 Original-Received: from [2001:19f0:7400:14e3:5400:5ff:fe30:b63e] (helo=mail.bauherren.ovh) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tU76I-0004YE-UE for emacs-devel@gnu.org; Sat, 04 Jan 2025 11:34:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=bauherren.ovh; s=mail; t=1736008445; bh=b98A/QRdzOdGhGeAArB4w8ESeVPU/Tz/8sLaMNp7q0w=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=UTZ3UTKh5WhKvpTPE5bbnyuC7A1AiwT0xXQ4i2QY9IzBQkqBW5RSeVAJEOZir9I8/ FyFFwbbT4uOFb9ofTbxe7vRENQG8WP9iEXW5q3fzLMVFcrpIFLacxOjqpyhLQM+GAr 38hKGK6sNJH42zuClJ2hhsDogLud4jwjBxyRbvzYUZh1utDrFjfGCUHEiYjLNAOZDr b84UPJtXH/hLwPkf/2x3tkJuDdiN3e+r8qRT3QLPDgX7cCsxC+hlHV1FgBfaDqBb2o QV79Hah2JuIK5OyfryEENSn2RsM8C2KFO0iBAbQen3OETGmA1qdWp9XjlzaFFx4XTm aK9J1d0nOLgMQ== In-Reply-To: <30BA6520-0862-40A7-89BB-5AB020ADC7F9@gmail.com> (Yuan Fu's message of "Sat, 4 Jan 2025 00:21:06 -0800") X-Host-Lookup-Failed: Reverse DNS lookup failed for 2001:19f0:7400:14e3:5400:5ff:fe30:b63e (failed) Received-SPF: pass client-ip=2001:19f0:7400:14e3:5400:5ff:fe30:b63e; envelope-from=pranshu@bauherren.ovh; helo=mail.bauherren.ovh X-Spam_score_int: 16 X-Spam_score: 1.6 X-Spam_bar: + X-Spam_report: (1.6 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_DBL_SPAM=2.5 autolearn=no autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Sat, 04 Jan 2025 12:37:46 -0500 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:327674 Archived-At: Yuan Fu writes: >> On Jan 2, 2025, at 6:48=E2=80=AFAM, Pranshu Sharma wrote: >>=20 >>=20 >> I'm making cperl clone using treesitter, and have done all of >> highlighting apart from regex and pod. >>=20 >> For regexp, I need different grammer to highlight it, and using the >> treesit-parser-set-included-ranges doesn't work. An example: >>=20 >> preq knowledge: >>=20 >> 's/bi?g/small/' replaces instances of 'bg' and 'big' with 'small', and >> 's/([0-9]+)/$1 + 1/e' incrimental all number (the 'e' at the end tells >> perl to evaluate the code). >>=20 >> the parse tree of 's/([0-9]+)/$1 + 1/e' is: >> (substitution_regexp operator: s ' >> content: (regexp_content not-interpolated not-interpolated) ' >> (replacement >> (scalar $ (varname))) >> ' modifiers: (substitution_regexp_modifiers)) >>=20 >> (replacement) needs to be conditionally parsed as perl over here because >> of the 'e' modifier. Now I cannot use range for this, because say if I >> had: >>=20 >> 's/(([0-9]+),)+/s#([0-9]+)#$1 + 1#e/e;' >> ^^^^^^ Perl code >> ^^^^^^^^^^^^^^^^^^^ Perl code >>=20 >>=20 >> The replacement contains another replacment which contains perl code, so >> it overlaps >>=20 >> So I won't have any way to highlight. It seems making this work could >> be possible using nested parsers with their own setting each using own >> local treesit-range-settings, but this seems really hard with >> treesit-range-settings being a buffer local variable. >>=20 > > Ok, so the problem is nested parsers. I don=E2=80=99t think the overlap w= ould > cause any problem. Right now treesit-range-settings can only give you > one nested layer. I=E2=80=99ll need to make it support nesting a parser i= nside > a local parser of the same language. I=E2=80=99ll work on that once I wra= p up > the thing I=E2=80=99m working on right now :-) Thanks, this definetly seems like the problem. Also the treesit-range-settings seems kind of unstable, example when I purposly leave closed string before it, and close the string, it doesn't reparse. --=20 Pranshu Sharma