unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Pranshu Sharma via "Emacs development discussions." <emacs-devel@gnu.org>
To: Yuan Fu <casouri@gmail.com>
Cc: emacs-devel@gnu.org
Subject: Re: Treesitter injection support
Date: Sun, 05 Jan 2025 02:33:42 +1000	[thread overview]
Message-ID: <87sepyv8rd.fsf@bauherren.ovh> (raw)
In-Reply-To: <30BA6520-0862-40A7-89BB-5AB020ADC7F9@gmail.com> (Yuan Fu's message of "Sat, 4 Jan 2025 00:21:06 -0800")

Yuan Fu <casouri@gmail.com> writes:

>> On Jan 2, 2025, at 6:48 AM, Pranshu Sharma <pranshu@bauherren.ovh> wrote:
>> 
>> 
>> 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.
>> 
>
> Ok, so the problem is nested parsers. I don’t think the overlap would
> cause any problem. Right now treesit-range-settings can only give you
> one nested layer. I’ll need to make it support nesting a parser inside
> a local parser of the same language. I’ll work on that once I wrap up
> the thing I’m 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.

-- 
Pranshu Sharma <https://p.bauherren.ovh>



  reply	other threads:[~2025-01-04 16:33 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-02 14:48 Treesitter injection support Pranshu Sharma via Emacs development discussions.
2025-01-04  8:21 ` Yuan Fu
2025-01-04 16:33   ` Pranshu Sharma via Emacs development discussions. [this message]
2025-01-04 19:23     ` Yuan Fu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87sepyv8rd.fsf@bauherren.ovh \
    --to=emacs-devel@gnu.org \
    --cc=casouri@gmail.com \
    --cc=pranshu@bauherren.ovh \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).