unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Clarification about treesit-font-lock-settings
@ 2023-02-25 15:33 Vincenzo Pupillo
  2023-02-25 22:18 ` Vincenzo Pupillo
  0 siblings, 1 reply; 4+ messages in thread
From: Vincenzo Pupillo @ 2023-02-25 15:33 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 1238 bytes --]

Hi,
I'm trying to understand how treesit-font-lock-settings works.
PHP supports annotations for classes, methods, functions, parameters,
properties and class constants, for e.g (this test come from php-mode):

<?php

#[
 Deprecated
]
function f($arg1,
 #[Deprecated] $arg2){}
#Deprecated <-- this is a comment

I would like to highlight the "Deprecated" annotation.
"treesit-query-validation" says that this query is valid:
(treesit-query-validate 'php
'((attribute (name (:match "Deprecated"))
@font-lock-comment-delimiter-face))

This is the rule I wrote:
   :language 'php
   :feature 'attribute
   '((attribute (name (:match "Deprecated"))) @font-lock-comment-delimiter-
face)


When I use my "php-ts-mode" on that code snippet, emacs reports the
following
errors:
Error during display: (jit-lock-function 1) reported (treesit-query-error
"Predicate `equal' requires two arguments but only given" 1)
Error during display: (jit-lock-function 6) reported (treesit-query-error
"Predicate `equal' requires two arguments but only given" 1)
Set report [2 times]

Is this a bug or am I doing something wrong?
My "php-ts-mode" works quite well. Except for the annotations the syntax
highlighting is as good as php-mode.

Thank you.

Vincenzo

[-- Attachment #2: Type: text/html, Size: 1514 bytes --]

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

* Re: Clarification about treesit-font-lock-settings
  2023-02-25 15:33 Clarification about treesit-font-lock-settings Vincenzo Pupillo
@ 2023-02-25 22:18 ` Vincenzo Pupillo
  2023-02-26  9:15   ` Yuan Fu
  0 siblings, 1 reply; 4+ messages in thread
From: Vincenzo Pupillo @ 2023-02-25 22:18 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 1723 bytes --]

Okay, I figured out how to do it:
   :language 'php
   :feature 'attribute
   '((((attribute (_) @attribute_name) @font-lock-preprocessor-face)
(:match "Deprecated" @attribute_name)))

However, I cannot understand why "treesit-query-validate" says the query is
correct, but I get an error.

Thank you.
Vincenzo

Il giorno sab 25 feb 2023 alle ore 16:33 Vincenzo Pupillo <
v.pupillo@gmail.com> ha scritto:

> Hi,
> I'm trying to understand how treesit-font-lock-settings works.
> PHP supports annotations for classes, methods, functions, parameters,
> properties and class constants, for e.g (this test come from php-mode):
>
> <?php
>
> #[
>  Deprecated
> ]
> function f($arg1,
>  #[Deprecated] $arg2){}
> #Deprecated <-- this is a comment
>
> I would like to highlight the "Deprecated" annotation.
> "treesit-query-validation" says that this query is valid:
> (treesit-query-validate 'php
> '((attribute (name (:match "Deprecated"))
> @font-lock-comment-delimiter-face))
>
> This is the rule I wrote:
>    :language 'php
>    :feature 'attribute
>    '((attribute (name (:match "Deprecated"))) @font-lock-comment-delimiter-
> face)
>
>
> When I use my "php-ts-mode" on that code snippet, emacs reports the
> following
> errors:
> Error during display: (jit-lock-function 1) reported (treesit-query-error
> "Predicate `equal' requires two arguments but only given" 1)
> Error during display: (jit-lock-function 6) reported (treesit-query-error
> "Predicate `equal' requires two arguments but only given" 1)
> Set report [2 times]
>
> Is this a bug or am I doing something wrong?
> My "php-ts-mode" works quite well. Except for the annotations the syntax
> highlighting is as good as php-mode.
>
> Thank you.
>
> Vincenzo
>

[-- Attachment #2: Type: text/html, Size: 2325 bytes --]

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

* Re: Clarification about treesit-font-lock-settings
  2023-02-25 22:18 ` Vincenzo Pupillo
@ 2023-02-26  9:15   ` Yuan Fu
  2023-02-27 11:06     ` vp
  0 siblings, 1 reply; 4+ messages in thread
From: Yuan Fu @ 2023-02-26  9:15 UTC (permalink / raw)
  To: Vincenzo Pupillo; +Cc: emacs-devel



> On Feb 25, 2023, at 2:18 PM, Vincenzo Pupillo <v.pupillo@gmail.com> wrote:
> 
> Okay, I figured out how to do it:
>    :language 'php
>    :feature 'attribute
>    '((((attribute (_) @attribute_name) @font-lock-preprocessor-face) (:match "Deprecated" @attribute_name)))
> 
> However, I cannot understand why "treesit-query-validate" says the query is correct, but I get an error.
> 
> Thank you.
> Vincenzo

Sorry that I missed your message! treesit-query-validate simply compiles the query and rely on tree-sitter to report any potential error. But predicates like #match and #equal are delegated to Emacs to handle, so tree-sitter doesn’t check for their arity and there is no error during compilation. Also, the error message should say “#match” instead of “#equal”, I fixed that typo.

Yuan


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

* Re: Clarification about treesit-font-lock-settings
  2023-02-26  9:15   ` Yuan Fu
@ 2023-02-27 11:06     ` vp
  0 siblings, 0 replies; 4+ messages in thread
From: vp @ 2023-02-27 11:06 UTC (permalink / raw)
  To: Yuan Fu; +Cc: emacs-devel

Thank you Yuan!

Vincenzo

In data domenica 26 febbraio 2023 10:15:41 CET, Yuan Fu ha scritto:
> 
> > On Feb 25, 2023, at 2:18 PM, Vincenzo Pupillo <v.pupillo@gmail.com> wrote:
> > 
> > Okay, I figured out how to do it:
> >    :language 'php
> >    :feature 'attribute
> >    '((((attribute (_) @attribute_name) @font-lock-preprocessor-face) (:match "Deprecated" @attribute_name)))
> > 
> > However, I cannot understand why "treesit-query-validate" says the query is correct, but I get an error.
> > 
> > Thank you.
> > Vincenzo
> 
> Sorry that I missed your message! treesit-query-validate simply compiles the query and rely on tree-sitter to report any potential error. But predicates like #match and #equal are delegated to Emacs to handle, so tree-sitter doesn’t check for their arity and there is no error during compilation. Also, the error message should say “#match” instead of “#equal”, I fixed that typo.
> 
> Yuan
> 






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

end of thread, other threads:[~2023-02-27 11:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-25 15:33 Clarification about treesit-font-lock-settings Vincenzo Pupillo
2023-02-25 22:18 ` Vincenzo Pupillo
2023-02-26  9:15   ` Yuan Fu
2023-02-27 11:06     ` vp

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