unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#64017: Wrong conversion from Emacs to Tree-sitter S-expression syntax
@ 2023-06-12 14:14 Mattias Engdegård
       [not found] ` <handler.64017.B.168657924917612.ack@debbugs.gnu.org>
  2023-06-15 22:08 ` Yuan Fu
  0 siblings, 2 replies; 13+ messages in thread
From: Mattias Engdegård @ 2023-06-12 14:14 UTC (permalink / raw)
  To: 64017; +Cc: Basil Contovounesios, Yuan Fu

`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?






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

end of thread, other threads:[~2023-06-18  8:47 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-12 14:14 bug#64017: Wrong conversion from Emacs to Tree-sitter S-expression syntax Mattias Engdegård
     [not found] ` <handler.64017.B.168657924917612.ack@debbugs.gnu.org>
2023-06-15 10:45   ` Mattias Engdegård
2023-06-15 22:13     ` Yuan Fu
2023-06-15 22:08 ` Yuan Fu
2023-06-16 11:25   ` Mattias Engdegård
2023-06-16 17:02     ` Mattias Engdegård
2023-06-16 17:33       ` Basil Contovounesios via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-06-17 10:47         ` Mattias Engdegård
2023-06-17 12:57           ` Eli Zaretskii
2023-06-17 13:30             ` Mattias Engdegård
2023-06-17 22:55               ` Yuan Fu
2023-06-18  8:47                 ` Mattias Engdegård
2023-06-17 23:02     ` Yuan Fu

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