Crates.io | tree-sitter-elisp |
lib.rs | tree-sitter-elisp |
version | 1.5.0 |
source | src |
created_at | 2021-09-27 07:16:44.525135 |
updated_at | 2024-06-18 15:42:38.828595 |
description | elisp grammar for the tree-sitter parsing library |
homepage | |
repository | https://github.com/tree-sitter/tree-sitter-elisp |
max_upload_size | |
id | 456833 |
size | 293,958 |
A tree-sitter grammar for elisp.
Syntax supported:
(a b)
and dotted (a . b)
)'
, #'
, `
, ,
, ,@
)$#
, ##
, #("foo" 1 2 x)
)#[1 2 3 4]
)let
etc)Limitations:
Elisp is a lisp-2 with user-defined macros. A simple parser cannot
detect if e.g. (foo (let ...))
is a function call with a let
expression argument, or a macro call where let
means something else.
Currently tree-sitter-elisp treats everything as an s-expression. This is accurate, but makes this package less useful for generating a summary of file contents, or for syntax highlighting.
Emacs itself has more information that it can use. Emacs will
highlight macro calls based on which macros are defined in the current
instance. Some elisp packages also offer custom highlighting logic,
such as dash-fontify-mode
in
dash.el.
Check out the repo, then use npm
to install dependencies.
$ npm install
You can then parse your favourite elisp files.
$ npm run parse ~/.emacs.d/init.el
The grammar itself is in grammar.js. You'll need to regenerate the code after editing the grammar.
$ npm run generate
This project also contains a few tests.
$ npm test
You can also run this parser against your .emacs.d
to confirm it can
parse everything.
$ npm run parse -- '/home/wilfred/.emacs.d/**/*.el' --quiet --stat
The best place to read and write elisp is of course Emacs.
However, there is a growing ecosystem of tools built on top of tree-sitter, such as GitHub. This project should allow them to support emacs lisp too.
tree-sitter-clojure is another tree-sitter package for the lisp family. It's a useful project to compare with, and has notes discussing lisp-specific challenges.
language-emacs-lisp is a textmate grammar for elisp that's used for Atom and GitHub.