all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Theodor Thornhill <theo@thornhill.no>
To: Perry Smith <pedz@easesoftware.com>, emacs-devel@gnu.org
Subject: Re: Tree sitter question / problem
Date: Fri, 09 Dec 2022 15:44:08 +0100	[thread overview]
Message-ID: <87lengwsav.fsf@thornhill.no> (raw)
In-Reply-To: <F9640E20-4487-4D90-A472-7ACD1CADD08E@easesoftware.com>


Hi there, Perry

Perry Smith <pedz@easesoftware.com> writes:

> As a result of not knowing what I’m doing, this took me a half a day to figure this out.  And I fear it is going to be hard for me to explain things.  Feel free to ask me questions.
>
> I’m working on ruby-ts-mode and it is patterned mostly after c-ts-mode because I want the versatility.
>
> I have this bit of code and it is the content of the comment that is the topic of the email:
>
> ;; doc/keywords.rdoc in the Ruby git repository considers these to be
> ;; reserved keywords.  If these keywords are added to the list, it
> ;; causes the font-lock to stop working.
> ;;
> ;; "__ENCODING__" "__FILE__" "__LINE__" "false" "self" "super" "true"
> ;;
> ;; "nil" (which does not exhibit this issue) is also considered a
> ;; keyword but I removed it and added it as a constant.
> ;;
> (defun ruby-ts-mode--keywords (language)
>   "Ruby keywords for tree-sitter font-locking.
> Currently LANGUAGE is ignored but shoule be set to `ruby'."
>   (let ((common-keywords
>          '("BEGIN" "END" "alias" "and" "begin" "break" "case" "class"
>            "def" "defined?" "do" "else" "elsif" "end" "ensure" "for"
>            "if" "in" "module" "next" "not" "or" "redo" "rescue"
>            "retry" "return" "then" "undef" "unless" "until" "when"
>            "while" "yield")))
>     common-keywords))
>

If you try (treesit-query-validate 'ruby (ruby-ts-mode--keywords 'ruby))
you should get a validation error and some help.  My guess is that
'false' and 'true' are nodes in their own right, such as (true) (false).

...

Yeah, you need to use the nodes separately [0].

> I also have this in my ruby-ts-mode--font-lock-settings:
>
>    :language language
>    :feature 'keyword
>    `([,@(ruby-ts-mode--keywords language)] @font-lock-keyword-face)
>
> (I understand this is just two snippets of a more complex set up but I’m hoping that c-ts-mode can be reviewed for more context if needed.)
>
> The Ruby parser I got from git@github.com:casouri/tree-sitter-module.git and followed the instructions.
>
> As the comment states, if I add “false” into the list of keywords,
> then **none** of the keywords get highlighted.  I can understand that
> “false” doesn’t get highlighted for some reason but having the entire
> query stop working seems like it might be a bug or at least a weakness
> that should be addressed.

That may be, but this is for major mode authors, so it is likely we can
live with these difficulties, IMO.

>
> If I turn on treesit-inspect-mode and put the cursor on top of false
> in a Ruby file, it says only (false) instead of something like (while
> “while”) that other keyword nodes that do not exhibit this problem
> show and I’m jumping to the conclusion that that is part of the
> problem.

This is because it is a node, and not a keyword.


[0]: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/grammar.js#L533-L541



      reply	other threads:[~2022-12-09 14:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-09 14:20 Tree sitter question / problem Perry Smith
2022-12-09 14:44 ` Theodor Thornhill [this message]

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=87lengwsav.fsf@thornhill.no \
    --to=theo@thornhill.no \
    --cc=emacs-devel@gnu.org \
    --cc=pedz@easesoftware.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.