From: Yuan Fu <casouri@gmail.com>
To: "Mattias Engdegård" <mattias.engdegard@gmail.com>
Cc: contovob@tcd.ie, 64017@debbugs.gnu.org
Subject: bug#64017: Wrong conversion from Emacs to Tree-sitter S-expression syntax
Date: Thu, 15 Jun 2023 15:08:26 -0700 [thread overview]
Message-ID: <C921E626-2783-48D6-A161-C45F016FA634@gmail.com> (raw)
In-Reply-To: <43D49A55-2C3F-4EA4-8DF8-0CD9A516573E@gmail.com>
Thanks for catching this.
> On Jun 12, 2023, at 7:14 AM, Mattias Engdegård <mattias.engdegard@gmail.com> wrote:
>
> `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?)
Because I wasn't sure if it’s ok for C functions to rely on Lisp functions, plus the function is simple enough. Right now if one doesn’t load treesit.el, all the C functions work fine.
>
> 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?
>
It shouldn’t hurt to expose the tree-sitter sexp. Other editors mainly use the string syntax.
Yuan
next prev parent reply other threads:[~2023-06-15 22:08 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
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=C921E626-2783-48D6-A161-C45F016FA634@gmail.com \
--to=casouri@gmail.com \
--cc=64017@debbugs.gnu.org \
--cc=contovob@tcd.ie \
--cc=mattias.engdegard@gmail.com \
/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.