From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Yuan Fu Newsgroups: gmane.emacs.devel Subject: Re: Treesitter injection support Date: Sat, 4 Jan 2025 11:23:55 -0800 Message-ID: <847D011B-65B8-4A41-9010-20BD529CE627@gmail.com> References: <87ed1lb7bw.fsf@bauherren.ovh> <30BA6520-0862-40A7-89BB-5AB020ADC7F9@gmail.com> <87sepyv8rd.fsf@bauherren.ovh> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3776.700.51\)) 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="26357"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Pranshu Sharma Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Jan 04 20:24:56 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 1tU9lX-0006gx-0H for ged-emacs-devel@m.gmane-mx.org; Sat, 04 Jan 2025 20:24:55 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tU9kr-00071I-Lh; Sat, 04 Jan 2025 14:24:14 -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 1tU9ko-000710-Ny for emacs-devel@gnu.org; Sat, 04 Jan 2025 14:24:11 -0500 Original-Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tU9km-0001tW-In for emacs-devel@gnu.org; Sat, 04 Jan 2025 14:24:10 -0500 Original-Received: by mail-pl1-x643.google.com with SMTP id d9443c01a7336-216281bc30fso215493085ad.0 for ; Sat, 04 Jan 2025 11:24:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736018647; x=1736623447; darn=gnu.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=Rz9F94SeVkYXdDPfv4seyGn2z/2xuBKCFFiT52ZuvTk=; b=kL1cRAGzLITpi8eLnA+Whq0Hj/KOuOW9LR+2qyX994oYLgvePsp5ms3Jo0cTqKj0k8 dBpKy86JN9ejCPXuGfyPNDWC4TbT1O18ecWVu3zBn9Qt9BfXdRfjwqvOfuxsKTjhSA8o zxczTOa1AS7eO/3bIq6seLxWJ05mgvDJIZGt6qFs/XhQ/y/c4n2c9sFloZgB9YMuoV9I i0mn/o+wz3BWYj2wk8K5x2XNwEDEI8J7NCTbwIRJFm2hnwm+nKURX6Lz3JfGiUTE8qCD r1b87mBpW3k9XGTMhXjr7u6djTX29WfFklmsrnGWpfjXMee0JGZeJrY932Puk7pVSxAd hLlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736018647; x=1736623447; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Rz9F94SeVkYXdDPfv4seyGn2z/2xuBKCFFiT52ZuvTk=; b=ZoM1tHcCyUVycSw18IZNG8kswee1f8+Oxh+ajti/05s7jMprQbHYhMSVU7bIpjNxsp g0tRslVDAvgh+FzSnzczWk2ygjId2PDzBtgitIqvtWNac0W/JBBT4drOUyqDi1i4ubW6 Gbd8CVxEnwWEkIsz5VVM5sozdGYexSDNb2d6NcUd+pKkC5S6bqz5Prin2DhknZrwwVWe YtnLgQTeV7ix/qRQiswombkPpHwlyU7XhkO10Lz5+lP+/GNT/n0qLI6j5gQ3Qlf8Q3Lq K9h8Kil125Ostvlp1ZiwHv4gjI7pFvdLQm/N+D8Mkc7fn+2Ket1D1cHBiCqS3cYEUc5u bkTg== X-Gm-Message-State: AOJu0YyZaglfIFFNKrxMZ10w8MdwG1ROGy1BkchSWRUGLBO5kNhtauGy SFJ8DbNgGPm+qvhu6lZ75lAXBWMOOuKKJH92YmkRDbJFN6N5XzWSl1j24G+v X-Gm-Gg: ASbGncuaID2fDyVWCrL2UIyiVKPmkIxpC6YYeRsjPlhNvb0EZbzM3dRLLi6+eLlucV6 qdHVUBVqrBj54snjj58zLZA+jHiN7dF5VOnhDGI5DjNPLFMp439z2oksHyMWE8pB7UrMGt4pfff /ZeFwirKURJa/OO/mLbRjShoBHLiJgoCW0kgbjdzDcY8fB67TRJhxnZpThmu+v2T30prQLbiuEp ViKEu1M7A4itAZyHNvbwZsyn+V8/BXK3Zc0DdKPMMeEDTIO9fBqpPfI/jAcgGY7Ft22bD2kH4FO oC2+ X-Google-Smtp-Source: AGHT+IHcpGsPWrzM9PIK75ARCwOHQzHkrh7N8unGpu/Rs7bhCJRDqoP2Pca6U+RqZ+sD94BiAmvIIg== X-Received: by 2002:a05:6a21:398:b0:1e3:e77d:1460 with SMTP id adf61e73a8af0-1e5e0482083mr102571971637.22.1736018647087; Sat, 04 Jan 2025 11:24:07 -0800 (PST) Original-Received: from smtpclient.apple ([2601:646:8f81:6120:c496:8cdf:4c5d:3617]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72aad831148sm28337884b3a.53.2025.01.04.11.24.05 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 04 Jan 2025 11:24:06 -0800 (PST) In-Reply-To: <87sepyv8rd.fsf@bauherren.ovh> X-Mailer: Apple Mail (2.3776.700.51) Received-SPF: pass client-ip=2607:f8b0:4864:20::643; envelope-from=casouri@gmail.com; helo=mail-pl1-x643.google.com X-Spam_score_int: 4 X-Spam_score: 0.4 X-Spam_bar: / X-Spam_report: (0.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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-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:327679 Archived-At: > On Jan 4, 2025, at 8:33=E2=80=AFAM, Pranshu Sharma = wrote: >=20 > Yuan Fu writes: >=20 >>> 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 >>=20 >> Ok, so the problem is nested parsers. I don=E2=80=99t think the = overlap would >> 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 inside >> a local parser of the same language. I=E2=80=99ll work on that once I = wrap up >> the thing I=E2=80=99m working on right now :-) >=20 > 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 > --=20 > Pranshu Sharma Can you show me a concrete example (reproduce recipe)? I can look into = it. Yuan