a structural diff that understands syntax 🟥🟩
 
 
 
 
 
Go to file
Wilfred Hughes 9ea12fffe6 Ignore build/ 2021-08-15 11:15:45 +07:00
.github/workflows Configuring tests on GH actions 2021-08-15 10:18:05 +07:00
bindings Generate C code with tree-sitter CLI 2021-08-14 17:52:54 +07:00
src Move comment to extras to simpify main sexp rules 2021-08-15 11:08:25 +07:00
test/corpus Add tests for numeric literals and get them passing 2021-08-14 19:30:53 +07:00
.gitignore Ignore build/ 2021-08-15 11:15:45 +07:00
CHANGELOG.md Roll version 2021-08-15 11:14:45 +07:00
Cargo.toml Generate C code with tree-sitter CLI 2021-08-14 17:52:54 +07:00
README.md Add reamde and npm run scripts 2021-08-15 11:04:34 +07:00
binding.gyp Generate C code with tree-sitter CLI 2021-08-14 17:52:54 +07:00
grammar.js Move comment to extras to simpify main sexp rules 2021-08-15 11:08:25 +07:00
package-lock.json Roll version 2021-08-15 11:14:45 +07:00
package.json Roll version 2021-08-15 11:14:45 +07:00

README.md

Tree-sitter Grammar for Emacs Lisp

A simple tree-sitter grammar for elisp.

Syntax supported:

  • Atoms (integers, floats, strings, characters, symbols)
  • Lists
  • Vectors
  • Quoting and unquoting (', #', `, ,, ,@)
  • Comments

Currently unsupported:

  • Hash table literals
  • Autoload cookies
  • Special forms (e.g. let, currently treated as symbols)
  • Definitions (e.g. defun, defvar, defmacro)

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.

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

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.

References

tree-sitter-clojure is another tree-sitter package for a lisp family. It's a useful project to compare with, and has notes discussing lisp-specific challenges.