GNU bug report logs - #64017
Wrong conversion from Emacs to Tree-sitter S-expression syntax

Previous Next

Package: emacs;

Reported by: Mattias Engdegård <mattias.engdegard <at> gmail.com>

Date: Mon, 12 Jun 2023 14:15:01 UTC

Severity: normal

Done: Mattias Engdegård <mattias.engdegard <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Mattias Engdegård <mattias.engdegard <at> gmail.com>
Cc: tracker <at> debbugs.gnu.org
Subject: bug#64017: closed (Wrong conversion from Emacs to Tree-sitter
 S-expression syntax)
Date: Sun, 18 Jun 2023 08:48:02 +0000
[Message part 1 (text/plain, inline)]
Your message dated Sun, 18 Jun 2023 10:47:01 +0200
with message-id <731A0E4C-3775-4202-98FD-E1C1ACD4D3EF <at> gmail.com>
and subject line Re: bug#64017: Wrong conversion from Emacs to Tree-sitter S-expression syntax
has caused the debbugs.gnu.org bug report #64017,
regarding Wrong conversion from Emacs to Tree-sitter S-expression syntax
to be marked as done.

(If you believe you have received this mail in error, please contact
help-debbugs <at> gnu.org.)


-- 
64017: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=64017
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Mattias Engdegård <mattias.engdegard <at> gmail.com>
To: Emacs Bug Report <bug-gnu-emacs <at> gnu.org>
Cc: Basil Contovounesios <contovob <at> tcd.ie>, Yuan Fu <casouri <at> gmail.com>
Subject: Wrong conversion from Emacs to Tree-sitter S-expression syntax
Date: Mon, 12 Jun 2023 16:14:01 +0200
`treesit-pattern-expand` converts a query pattern into tree-sitter S-expression syntax, as a string. The conversion mainly converts certain keywords but the main problem is that it prints strings in Emacs syntax which differs from that of tree-sitter.

As a consequence, :match regexps cannot contain newlines:

(treesit-query-capture
 'java
 '(((identifier) @font-lock-constant-face
    (:match "hello\n" @font-lock-constant-face))))

signals a syntax error.

As far as I can tell the tree-sitter string syntax allows for the escape sequences:

\n = LF
\r = CR
\t = TAB
\0 = NUL  (only a single 0 -- no octal escapes!)
\X = the character X itself

Unescape newlines result in a syntax error as seen in the example above. NULs don't seem to go well either.

At the very least, the conversion should avoid literal newlines and NULs in the result (and probably CR and TAB). This cannot be done with a straight prin1-to-string.

(By the way, why is the conversion written in C? Was Lisp too slow?)

Ideally we should not need to expose the tree-sitter s-exp query syntax at all. Surely Emacs s-exps should be preferable in every case?



[Message part 3 (message/rfc822, inline)]
From: Mattias Engdegård <mattias.engdegard <at> gmail.com>
To: Yuan Fu <casouri <at> gmail.com>
Cc: Basil Contovounesios <contovob <at> tcd.ie>, Eli Zaretskii <eliz <at> gnu.org>,
 64017-done <at> debbugs.gnu.org
Subject: Re: bug#64017: Wrong conversion from Emacs to Tree-sitter
 S-expression syntax
Date: Sun, 18 Jun 2023 10:47:01 +0200
18 juni 2023 kl. 00.55 skrev Yuan Fu <casouri <at> gmail.com>:

> LGTM!

Thank you, these changes are now in emacs-29.

And we are done, closing the bug.



This bug report was last modified 2 years and 33 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.