[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Tree-sitter documentation
From: |
Yuan Fu |
Subject: |
Re: Tree-sitter documentation |
Date: |
Mon, 7 Nov 2022 12:47:30 -0800 |
> On Nov 7, 2022, at 4:11 AM, Eli Zaretskii <eliz@gnu.org> wrote:
>
>> From: Yuan Fu <casouri@gmail.com>
>> Date: Mon, 7 Nov 2022 02:13:20 -0800
>>
>>> This function takes a series of @var{query-spec}s, which are triplets
>>> @w{@code{@var{:keyword} @var{value} @dots{} @var{query}}}. Each
>>> @var{query} is a tree-sitter query in either the string, s-expression
>>> or compiled form.
>>>
>> Is is ok to use “triplets” here? Because there can be more than one pair of
>> :keyword and values before a query, eg,
>>
>> :keyword value
>> :keyword value
>> query
>
> 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:
(treesit-font-lock-rules
:language 'python
:override t
:feature 'string
'((string :anchor "\"" @python--treesit-fontify-string)
(string) @contextual)
:feature 'string-interpolation
:language 'python
:override t
'((interpolation (identifier) @font-lock-variable-name-face)))
With
(treesit-font-lock-rules
'((((string :anchor "\"" @python--treesit-fontify-string)
(string) @contextual)
(language . python)
(override . t)
(feature . string))
(((interpolation (identifier) @font-lock-variable-name-face))
(language . python)
(override . t)
(feature . string-interpolation))))
Yuan