From: Simon Pugnet <simon@polaris64.net>
To: Yuan Fu <casouri@gmail.com>
Cc: Emacs developers <emacs-devel@gnu.org>
Subject: Re: Tree sitter: issue embedding HTML, CSS, JavaScript within a new php-ts-mode
Date: Fri, 10 Feb 2023 11:40:32 +0000 [thread overview]
Message-ID: <87y1p53fqv.fsf@polaris64.net> (raw)
In-Reply-To: <494661C8-02BC-4A22-9217-B2110A8D0668@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 2657 bytes --]
Yuan Fu <casouri@gmail.com> writes:
> Hey Simon,
>
> Thanks for trying this out! Feedbacks like this are very welcome.
Hi Yuan, you're very welcome! I'm glad to be able to help.
>> On Feb 9, 2023, at 4:45 AM, Simon Pugnet <simon@polaris64.net>
>> wrote:
>>
>> 1. Based on my rules for embedding ='html= within ='php= above,
>> should I expect ~(treesit-language-at (point))~ to return ='php=
>> when the point is within a PHP region?
>
> Because we don’t have much experience with tree-sitter and its
> interfaces, I made treesit-language-at simply delegate work to
> treesit-language-at-point-function, which can be an arbitrary
> function, giving developers maximum flexibility. You need to set
> that
> variables to a function, otherwise treesit-language-at simply
> returns
> the first parser in the parser list.
Ah, that makes sense, thank you. I must have missed that in the
documentation as I thought this was just used when overriding the
default behaviour.
I've added the following implementation and this appears to work
nicely: -
(defun php-ts--language-at-point (point)
"Return the language at POINT, used to determine which tree sitter
parser to use."
(let* ((php-node-at-point (treesit-node-at point 'php))
(parent-node (treesit-node-parent php-node-at-point)))
(if (and (string-equal "text" (treesit-node-type
php-node-at-point))
(or (string-equal "program" (treesit-node-type
parent-node))
(string-equal "text_interpolation"
(treesit-node-type parent-node))))
'html
'php)))
The next step will be to run further tests on the current node in
cases where the language is 'html in order to determine if the actual
language is 'css or 'javascript.
>> 2. Is my goal of embedding HTML within PHP, then embedding CSS and
>> JavaScript/TypeScript within HTML feasible and if so am I going
>> about this in the right way?
>
> It should be. Although I didn’t thought of having multiple layers of
> embedded language (in this case PHP embedding HTML embedding
> CSS/Javascript), if you order the entries in treesit-range-rules
> like
> you do now (outer most host language, then embedded language, then
> embedded embedded language), it should work. Try setting
> treesit-language-at-point-function and it should work right. If not…
> then we need to look into it.
I'll try this next and I'll be sure to let you know how it goes.
Thanks for your advice, and kind regards,
--
Simon Pugnet
https://www.polaris64.net/
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 861 bytes --]
prev parent reply other threads:[~2023-02-10 11:40 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-09 12:45 Tree sitter: issue embedding HTML, CSS, JavaScript within a new php-ts-mode Simon Pugnet
2023-02-10 5:45 ` Yuan Fu
2023-02-10 11:40 ` Simon Pugnet [this message]
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=87y1p53fqv.fsf@polaris64.net \
--to=simon@polaris64.net \
--cc=casouri@gmail.com \
--cc=emacs-devel@gnu.org \
/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).