From: Danny Freeman <danny@dfreeman.email>
To: emacs-devel@gnu.org
Subject: Treesitter query question, matching only substring of a node
Date: Sun, 04 Dec 2022 13:27:07 -0500 [thread overview]
Message-ID: <87sfhvdn6k.fsf@dfreeman.email> (raw)
Hello,
I am currently seeing what it will look like to add treesitter support
for clojure-mode. I am using this grammer:
https://github.com/sogaiu/tree-sitter-clojure
and it is working great so far.
It has definitions for nodes that match full namespaced keywords and
symbols, such that
:plain-keyword matches (kwd_lit) node
:namespace/keyword matches (kwd_lit) node
and similarly for symbols
'plain-symbol matches (sym_lit) node
'namespaced/symbol matches (sym_lit) node
In clojure, the part before the / character is the NAMESPACE, and the
part after the / character is the NAME.
The current clojure-mode highlights the namespaced part with a different
face than the name part.
I am trying to use this existing grammer to apply different faces to the
namespaced and named part. I can write a query that matches the whole
keyword easily, using `treesit-font-lock-rules`
```
(treesit-font-lock-rules
...
:feature 'keyword
:language 'clojure
'((kwd_lit) @clojure-keyword-face)
...
)
```
This works fine.
What I'm trying to do now is capture a substring of that node, the
namespaced part.
I can use the `:match` predicate to identify the namespace part, but the
matched group doesn't get captured by anything
```
(defvar kw-query
`((((kwd_lit) @kw)
(:match "^:.*/" @kw) ;; Can I capture this??
)))
(treesit-query-string ":namespaced/keyword" kw-query 'clojure)
```
Is something like this possible with the treesitter query engine in
Emacs? Or do I need to handle this at the grammer level? Perhaps with a
field?
There is an issue that was closed in the grammer's repository asking
about this, but their advise was to do some substring matching in the
editor, so here I am
https://github.com/sogaiu/tree-sitter-clojure/issues/28
--
Danny Freeman
next reply other threads:[~2022-12-04 18:27 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-04 18:27 Danny Freeman [this message]
2022-12-05 4:05 ` Treesitter query question, matching only substring of a node Yuan Fu
2022-12-05 15:25 ` Danny Freeman
2022-12-05 20:45 ` Yuan Fu
2022-12-06 15:13 ` Danny Freeman
2022-12-08 0:52 ` 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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87sfhvdn6k.fsf@dfreeman.email \
--to=danny@dfreeman.email \
--cc=emacs-devel@gnu.org \
/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 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).