all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "João Paulo Labegalini de Carvalho" <jaopaulolc@gmail.com>
To: Po Lu <luangruo@yahoo.com>
Cc: emacs-devel@gnu.org, Yuan Fu <casouri@gmail.com>,
	 Theodor Thornhill <theo@thornhill.no>,
	Eli Zaretskii <eliz@gnu.org>
Subject: Re: Implementation direction for shell-script-mode with tree-sitter
Date: Wed, 26 Oct 2022 09:48:10 -0600	[thread overview]
Message-ID: <CAGjvy28NW1HNHKmjQPvF9BeXkBSLLoFuLCYY+cOiEmXQdF36ig@mail.gmail.com> (raw)
In-Reply-To: <87mt9j1k50.fsf@yahoo.com>

[-- Attachment #1: Type: text/plain, Size: 2543 bytes --]

N.B that shell-script-mode supports shells other than bash, so maybe a
> tree-sitter-bash based variant should be spun off into its own
> `bash-mode', as opposed to possibly interfering with the support for all
> of rest?
>

That is a very good point and that is the reason why I am pursuing an
implementation that reuses the work from the existing fontification code.

My goal is to use the `sh-feature' function to retrieve everything that
needs to be fontified for the buffer's shell variant.

It has worked well for most built-in commands (e.g. alias & source) but not
as great for reserved words like "time" and "coproc". As Stefen pointed
out, some reserved words complicate the grammar, so I believe that is the
reason why the tree-sitter-bash folks decided to keep them out of the
grammar.

This becomes a nuisance because then I have to use two queries to match
keywords. One simple query to match the recognized keywords and another
that matches all commands but only fontifies the ones that belong to the
un-recognized list. To build such a list I have to explicitly construct a
list of recognized keywords using literals and that goes against my goal of
reusing pre-existing functionality by relying on `sh-feature'.

Built-in commands are a lesser nuisance as some of them (e.g. local,
declare, and typeset) are not commands but declaration_commands in
tree-sitter-bash grammar. But for those I just have two queries and I don't
need to create a variable per shell variant.

Aside from that, I am trying to extract the keywords in `sh-font-lock-{var,
var-1, var-2}' variables to replicate the fontification based on the level
selected by the user. But parsing those is more intricate as the return is
a list where each element is either a list of the form:

   - (regex level font-face), or
   - (regex list [list]), where list is of the form (level face) or (level
   function function-args).

The logic to parse those I believe exists within font-lock-mode or
font-core, but I am not sure if I would be able to use the forms above as
they use functions that depend on variables that the user might tweak. I
don't know if the compiled queries in *-treesit-settings would be
recompiled to achieve the same flexibility as the existing fontification
code.

-- 
João Paulo L. de Carvalho
Ph.D Computer Science |  IC-UNICAMP | Campinas , SP - Brazil
Postdoctoral Research Fellow | University of Alberta | Edmonton, AB - Canada
joao.carvalho@ic.unicamp.br
joao.carvalho@ualberta.ca

[-- Attachment #2: Type: text/html, Size: 3168 bytes --]

  reply	other threads:[~2022-10-26 15:48 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-25 15:05 Implementation direction for shell-script-mode with tree-sitter João Paulo Labegalini de Carvalho
2022-10-25 15:46 ` Stefan Monnier
2022-10-25 16:26   ` João Paulo Labegalini de Carvalho
2022-10-26  0:52 ` Po Lu
2022-10-26 15:48   ` João Paulo Labegalini de Carvalho [this message]
2022-10-27  0:54     ` Po Lu
2022-10-27  6:06       ` Eli Zaretskii
2022-10-27 14:23         ` João Paulo Labegalini de Carvalho
2022-10-27 15:53           ` Eli Zaretskii
2022-10-27 14:22       ` João Paulo Labegalini de Carvalho

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=CAGjvy28NW1HNHKmjQPvF9BeXkBSLLoFuLCYY+cOiEmXQdF36ig@mail.gmail.com \
    --to=jaopaulolc@gmail.com \
    --cc=casouri@gmail.com \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=luangruo@yahoo.com \
    --cc=theo@thornhill.no \
    /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.