vectorgraphics / asymptote

2D & 3D TeX-Aware Vector Graphics Language
https://asymptote.sourceforge.io/
GNU General Public License v3.0
542 stars 90 forks source link

Tree-sitter grammar #469

Closed kiryph closed 1 month ago

kiryph commented 1 month ago

I have searched (Google, Github) for a tree-sitter grammar for asymptote. But I did not find one (July 2024).

Does a tree-sitter grammar already exist?

If not, is there a plan to write one?

For reference: the repository of asymptote contains for vim a syntax file and for emacs as well. There is a current PR for vim to distribute it with vim: https://github.com/vim/vim/pull/15252

However, neovim moves to/uses tree-sitter. It already ships with grammars for C, Lua, Markdown, Vimscript, Vimdoc and Treesitter query files. And supports many more via nvim-treesitter.

Emacs v29 has now builtin support for tree-sitter with dedicated plugins such as (combobulate) exploiting it.

Recent text editors such as Zed and Helix also use tree-sitter for syntax highlighting.

For classic vim is an ongoing discussion to move away from the existing syntax system (afaik, textmate grammar or also tree-sitter are under consideration).

It seems to me providing a tree-sitter grammar for asymptote would be a worthwhile addition.

And has already been requested in the latex grammar: https://github.com/latex-lsp/tree-sitter-latex/issues/81

and the nvim-treesitter injection "abuses" the C grammar: https://github.com/nvim-treesitter/nvim-treesitter/blob/master/queries/latex/injections.scm :

((generic_environment
  (begin
    name: (curly_group_text
      (text) @_env))) @injection.content
  (#set! injection.language "c")
  (#any-of? @_env "asy" "asydef"))
johncbowman commented 1 month ago

A tree-sitter grammer for Asymptote hasn't been written, as far as I know. Asymptote uses the perl script asy-list.pl to build asy-keywords.el for Emacs. Perhaps something can be done similar to this. Contributions are welcome! In the meantime, since Asymptote is very close to C and C++, using a grammar for those languages might be reasonabble.