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: Treesitter injection support Date: Fri, 03 Jan 2025 00:48:03 +1000 Message-ID: <87ed1lb7bw.fsf@bauherren.ovh> Reply-To: Pranshu Sharma Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="3364"; mail-complaints-to="usenet@ciao.gmane.io" Cc: casouri@gmail.com To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Jan 02 16:17:36 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 1tTMx6-0000lq-4E for ged-emacs-devel@m.gmane-mx.org; Thu, 02 Jan 2025 16:17:36 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tTMvS-0003WE-UJ; Thu, 02 Jan 2025 10:15:55 -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 1tTMUr-0002mE-6x for emacs-devel@gnu.org; Thu, 02 Jan 2025 09:48:25 -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 1tTMUp-000305-Ad for emacs-devel@gnu.org; Thu, 02 Jan 2025 09:48:24 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=bauherren.ovh; s=mail; t=1735829293; bh=BQEvPxzH4yPOhJ4WlTZSVFuNPkBzLBXKYiOIOxl8DBU=; h=From:To:Cc:Subject:Date:From; b=FSy6iBeGMLAiNoTCEYWF1DwEE7uX0VSq9IEZv1Uwg3h+a40OwkPJ4azLoldy60K94 UuiKqzsaWfyEwjhNoJfII6damS3oh1B97b/WP3kBs2kn2ylOi2XqE6wZp9utKszWrZ Htqkb0WBHIXmcLM+HOKD+6kyIAyHLSbsP/4lo2ENY4mwTWhOVsxRCwh2l4Myihrmag s+7VtAIqqoLegyEHT96UvBEApOtKnncnwZBfQjmuQNB7h0XPg83BsK8n2SXw3dWLHx DzIpv7TlvXr3MjxknAwN3Tevs1uUvAqMY+PUPhCOuEd1MdLAvf0aVEngppLNugPvGh jmNXaTad8mSVQ== 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: Thu, 02 Jan 2025 10:15:32 -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:327567 Archived-At: I'm making cperl clone using treesitter, and have done all of highlighting apart from regex and pod. For regexp, I need different grammer to highlight it, and using the treesit-parser-set-included-ranges doesn't work. An example: preq knowledge: '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). 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)) (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: 's/(([0-9]+),)+/s#([0-9]+)#$1 + 1#e/e;' ^^^^^^ Perl code ^^^^^^^^^^^^^^^^^^^ Perl code The replacement contains another replacment which contains perl code, so it overlaps 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. -- Pranshu Sharma