unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Treesitter injection support
@ 2025-01-02 14:48 Pranshu Sharma via Emacs development discussions.
  2025-01-04  8:21 ` Yuan Fu
  0 siblings, 1 reply; 4+ messages in thread
From: Pranshu Sharma via Emacs development discussions. @ 2025-01-02 14:48 UTC (permalink / raw)
  To: emacs-devel; +Cc: casouri


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 <https://p.bauherren.ovh>



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-01-04 19:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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.
2025-01-04 19:23     ` Yuan Fu

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).