emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Call for volunteers: add tree-sitter support to major modes


From: João Paulo Labegalini de Carvalho
Subject: Re: Call for volunteers: add tree-sitter support to major modes
Date: Mon, 24 Oct 2022 09:41:19 -0600

Thanks for pointing that out. I am still getting familiar with tree-sitter thus the message sounded very generic.

According to the GNU Bash Reference Manual, "time" is a reserved word. But tree-sitter does not include it in the grammar.

Should I submit a PR for tree-sitter-bash to add "time", and possibly other missing reserved word/keywords, or should I just fontify those recognized by tree-sitter-bash in shell-script-mode?

I believe the best course of action is to make tree-sitter-bash as complete as possible. That way the regex and tree-sitter fontification will fontify exactly the same things.

What do you guys think?  

On Sun, Oct 23, 2022 at 10:20 PM Yuan Fu <casouri@gmail.com> wrote:


> On Oct 22, 2022, at 8:51 AM, João Paulo Labegalini de Carvalho <jaopaulolc@gmail.com> wrote:
>
> I am getting a query error but I don't understand why.
>
> The following query is fine:
>
> (defvar sh-script--treesit-bash-keywords
>   '("case" "do" "done" "elif" "else" "esac" "export" "fi" "for"
>     "function" "if" "in" "unset" "while" "then"))
>
> (treesit-validate-query 'bash `([ ,@sh-script--treesit-bash-keywords ] @font-lock-keyword-face))
>
> However the following query is said INVALID by `treesit-validate-query':
> (treesit-validate-query 'bash `([ ,@(sh-feature sh-leading-keywords) ] @font-lock-keyword-face))
> Node type error at: 3
> ["time" "!" "do" "done" ...] @font-lock-keyword-face
>
> time" is highlighted in the *tree-sitter check query* buffer.
>
> Even though the forms below evaluate to equivalent forms:
> `([ ,@sh-script--treesit-bash-keywords] @font-lock-keyword-face)
> evaluates to:
> ([ "case" "do" "done" "elif" ... ] @font-lock-keyword-face)
>
> `([ ,@(sh-feature sh-leading-keywords) ] @font-lock-keyword-face)
> evaluates to:
> (["time" "!" "do" "done" ...] @font-lock-keyword-face)
>
>
> Any clues to what I am doing wrong?

It is saying that there is no “time” node in bash grammar. You probably need to consult the grammar file of tree-sitter-bash to see what are the keywords it recognizes.

For example, running the following snippet

(let (collection)
  (goto-char (point-min))
  (while (re-search-forward "'[^ ][^ ]+?'" nil t)
    (push (match-string 0) collection))
  (pop-to-buffer "*result*")
  (dolist (keyword (cl-remove-duplicates collection :test #'equal))
    (insert keyword "\n")))

in the grammar.js gives me

'\\\\'
'>('
'<('
'$('
':-'
':?'
'${'
')*'
'([^'
'[^'
'--'
'++'
'alternative'
'consequence'
'right'
'>='
'<='
'-='
'!='
'operator'
'left'
'<<<'
'destination'
'>|'
'>&'
'<&'
'&>>'
'&>'
'>>'
'descriptor'
'index'
'=='
'=~'
'argument'
'unsetenv'
'unset'
'local'
'readonly'
'export'
'typeset'
'declare'
']]'
'[['
'||'
'&&'
'|&'
'name'
'function'
';;&'
';&'
'fallthrough'
';;'
'termination'
'esac'
'case'
'else'
'elif'
'fi'
'then'
'if'
'done'
'do'
'until'
'while'
'))'
'update'
'condition'
'initializer'
'(('
'value'
'in'
'variable'
'select'
'for'
'redirect'
'body'
'\n'
'<<-'
'<<'
'+='
'bash'
'\\s'
'\\'
'\\]'
'\\['


Yuan


--
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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]