From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Theodor Thornhill Newsgroups: gmane.emacs.devel Subject: Re: Tree sitter question / problem Date: Fri, 09 Dec 2022 15:44:08 +0100 Message-ID: <87lengwsav.fsf@thornhill.no> References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="34018"; mail-complaints-to="usenet@ciao.gmane.io" To: Perry Smith , emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Dec 09 15:44:58 2022 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p3ecT-0008d6-Rp for ged-emacs-devel@m.gmane-mx.org; Fri, 09 Dec 2022 15:44:58 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p3eby-0000oS-OP; Fri, 09 Dec 2022 09:44:26 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p3ebw-0000mc-9Q for emacs-devel@gnu.org; Fri, 09 Dec 2022 09:44:24 -0500 Original-Received: from out-246.mta0.migadu.com ([91.218.175.246]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p3ebj-00036I-Rl for emacs-devel@gnu.org; Fri, 09 Dec 2022 09:44:13 -0500 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thornhill.no; s=key1; t=1670597049; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lYFcSJeMXYL3IWw/W68AihINZNQB4g7sYOte4bYSCWw=; b=uskxtz9hJW/ppNJX2PGC3VMnicWdkP0sAnC+por8TU1WuNvvK/786A+Bm6CebEAJt2/Cp1 GSG0VvYroNcP8ZjoVfhx/F0GTVqEEtLB6k2eu4Z2vg68CrFLG0E9ZfxS+DPMWVD1ODPk4n CqUnZnJSDpXZej3WRWQ3fXa+uIeXqVA9KxsmqGo1Ps6ayGWYVkzbCjBKRuI5oxQD6LdByG 19L8ePntnmlUlckIIqa86GojH2yW2GLmuHR+gf66HZxSklu+CGXXt8iO9H7M/qYNOkJIaC FIBK6nf3xUOH/Dpm0108iitEzxsOubO5G6e5pGLUGuKKEJdkQtw1t5IzmVzg7g== In-Reply-To: X-Migadu-Flow: FLOW_OUT Received-SPF: pass client-ip=91.218.175.246; envelope-from=theo@thornhill.no; helo=out-246.mta0.migadu.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:301071 Archived-At: Hi there, Perry Perry Smith writes: > As a result of not knowing what I=E2=80=99m doing, this took me a half a = day to figure this out. And I fear it is going to be hard for me to explai= n things. Feel free to ask me questions. > > I=E2=80=99m 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=E2= =80=99m 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 =E2=80=9Cfalse=E2=80=9D into the list of = keywords, > then **none** of the keywords get highlighted. I can understand that > =E2=80=9Cfalse=E2=80=9D doesn=E2=80=99t get highlighted for some reason b= ut 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 > =E2=80=9Cwhile=E2=80=9D) that other keyword nodes that do not exhibit thi= s problem > show and I=E2=80=99m 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