GitXplorerGitXplorer
W

tree-sitter-elisp

public
67 stars
7 forks
3 issues

Commits

List of commits on branch main.
Unverified
12b547b470a4213dc63a20c7bd2db988d85c7693

Fix npm warning

WWilfred committed 7 months ago
Unverified
4de98b20113d951dadab9afb5caa6ac18b9ae63c

Release is done!

WWilfred committed 7 months ago
Unverified
6c90728516072d3f2172ffd390317d34bf0e4b47

Ignore Cargo.lock

WWilfred committed 7 months ago
Unverified
015c3c8b86657e0865ecadfe0a08f3ad344e950f

Update tree-sitter version for Rust library

WWilfred committed 7 months ago
Unverified
fb85092c63f475fd25cf32e77db351c0563068f7

Fix syntax highlighting test for doc comments

WWilfred committed 7 months ago
Unverified
1cba8137a48197c68e5264b3baeb4502e72fe087

Silence warning about highlights path

WWilfred committed 7 months ago

README

The README file for this repository.

Tree-sitter Grammar for Emacs Lisp

crates.io npm

A tree-sitter grammar for elisp.

Syntax supported:

  • Atoms (integers, floats, strings, characters, symbols)
  • Lists (normal syntax (a b) and dotted (a . b))
  • Vectors
  • Quoting and unquoting (', #', `, ,, ,@)
  • Some special read syntax ($#, ##, #("foo" 1 2 x))
  • Bytecode literals (#[1 2 3 4])
  • Special forms (let etc)
  • Comments

Limitations:

  • Autoload cookies are treated as plain comments

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.

Developing

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

Why?

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.

Related Projects

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.