all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Yuan Fu <casouri@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: emacs-devel@gnu.org
Subject: Re: Tree-sitter documentation
Date: Tue, 8 Nov 2022 10:44:29 -0800	[thread overview]
Message-ID: <2A694F4A-7CC6-4B28-A4E5-2B60DCBC1AB2@gmail.com> (raw)
In-Reply-To: <83h6z9y0fa.fsf@gnu.org>



> On Nov 8, 2022, at 6:40 AM, Eli Zaretskii <eliz@gnu.org> wrote:
> 
>> From: Yuan Fu <casouri@gmail.com>
>> Date: Mon, 7 Nov 2022 12:47:30 -0800
>> Cc: emacs-devel@gnu.org
>> 
>>> In that case, "triplets" is definitely incorrect, but I had no way of
>>> understanding that this is possible.
>>> 
>>> It should be possible top describe this kind of argument list, but
>>> does it really have to be so complicated?  These are not internal
>>> functions, so Lisp programmers will have to battle with this signature
>>> all the time.  Can we make the function's signature easier to
>>> document, understand, and use?
>>> 
>>> For example, what about accepting an alist as the argument, where each
>>> alist element specifies a query and its keyword/value pairs that
>>> customize the query?
>> 
>> Alists has too much layers of parenthesizes that is verbose and easy to get wrong. Compare:
> 
> I don't share your pessimism about alists.  And the way the functions
> are defined now are also very error-prone and complicate the code,
> which needs to distinguish between several very different signatures.

Ah, I’m not saying alist per se has too much layers of parenthesizes, but if we use alists rather than keywords in treesit-font-lock-rules, there really are a lot of parenthesizes. The current signature might be harder to formally explain, but should be pretty intuitive, it’s just a series of queries, and queries can have keyword value pairs preceding it that adds meta information to the query.

I might help to think of treesit-font-lock-rules not as a function but as a macro. 

The code to handle this signature isn’t particularly error-prone, the signal forms you see are just nice type-checks that I added for developer’s aid. They check, for example, that the value of a :language keyword is a symbol, the value of an :override keyword is one of the five possible values, etc. These checks are not related to the signature.

> 
> How about making the query itself the value of a keyword/value pair?
> Like this:
> 
>   :language 'python
>   :override t
>   :feature 'string
>   :query '((string :anchor "\"" @python--treesit-fontify-string)
>            (string) @contextual)

It’s ok, but query isn’t the same as other things. Query is the subject and other keywords adds information to it. I tried to improve the documentation of treesit-font-lock-rules, so hopefully changing the signature is not needed. Is the new version ok to you?

Yuan


  parent reply	other threads:[~2022-11-08 18:44 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-07 10:13 Tree-sitter documentation Yuan Fu
2022-11-07 12:11 ` Eli Zaretskii
2022-11-07 20:47   ` Yuan Fu
2022-11-08 14:40     ` Eli Zaretskii
2022-11-08 15:36       ` Stefan Kangas
2022-11-08 18:44       ` Yuan Fu [this message]
2022-11-09 13:36         ` Eli Zaretskii

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

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

  git send-email \
    --in-reply-to=2A694F4A-7CC6-4B28-A4E5-2B60DCBC1AB2@gmail.com \
    --to=casouri@gmail.com \
    --cc=eliz@gnu.org \
    --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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.