tree-sitter grammar for emacs lisp

Overview

Tree-sitter Grammar for Emacs Lisp

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

Currently unsupported:

  • Autoload cookies
  • 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.

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.

You might also like...
Common Lisp editor/IDE with high expansibility
Common Lisp editor/IDE with high expansibility

Lem is the editor/IDE well-tuned for Common Lisp. After installing lem, you can start developing in Common Lisp at once. You can skip over writing tid

CAAR is an attempt at writing a modern Lisp machine.
CAAR is an attempt at writing a modern Lisp machine.

CAAR - The modern lisp machine CAAR is an attempt at writing a modern Lisp machine. The goal of this project is to be able to run a somewhat functiona

Probabilistic Risk Analysis Tool (fault tree analysis, event tree analysis, etc.)

SCRAM SCRAM is a Command-line Risk Analysis Multi-tool. This project aims to build a command line tool for probabilistic risk analysis. SCRAM is capab

Parsing Expression Grammar Template Library
Parsing Expression Grammar Template Library

Welcome to the PEGTL The Parsing Expression Grammar Template Library (PEGTL) is a zero-dependency C++ header-only parser combinator library for creati

BNFLite is a C++ template library for lightweight flexible grammar parsers

BNFLite is a C++ template library for lightweight flexible grammar parsers. BNFLite offers creative approach when the developer can specify a language for further parsing directly in the C++ code. Moreover, such "specifications" are executable now!

Radical kernel source tree
Radical kernel source tree

Radical kernel source tree

Inoki's NB1 kernel source tree based on Nokia official tarball

Inoki's NB1 kernel source tree based on Nokia official tarball

Caffeecoin Core integration/staging tree

Caffeecoin Core integration/staging tree https://caffeecoin.com What is Caffeecoin? Caffeecoin is an experimental digital currency that enables instan

TWRP device tree for the LG Q7
TWRP device tree for the LG Q7

Device Tree for LG Q7 (mcv5a) The LG Q7 (codenamed "mcv5a") is a low-range smartphone from LG. It was released in May 2018. Basic Spec Sheet OS Androi

Owner
Wilfred Hughes
PL enthusiast, Emacs addict, and Hacklang contributor.
Wilfred Hughes
Coverage-guided grammar aware fuzzer that uses grammar automatons

Gramatron Gramatron is a coverage-guided fuzzer that uses grammar automatons to perform grammar-aware fuzzing. Technical details about our framework a

HexHive 44 Dec 28, 2022
A light lisp written in C++

wisp A light lisp written in C++ Why write a lisp? Lisp is one of those niche, beautiful languages that people only really use to either Write a lisp

adam mcdaniel 168 Dec 22, 2022
C/C++ language server supporting multi-million line code base, powered by libclang. Emacs, Vim, VSCode, and others with language server protocol support. Cross references, completion, diagnostics, semantic highlighting and more

Archived cquery is no longer under development. clangd and ccls are both good replacements. cquery cquery is a highly-scalable, low-latency language s

Jacob Dufault 2.3k Jan 2, 2023
A C/C++ minor mode for Emacs powered by libclang

Irony-Mode A C/C++ minor mode powered by libclang irony-mode is an Emacs minor-mode that aims at improving the editing experience for the C, C++ and O

Guillaume Papin 897 Dec 22, 2022
C++ font-lock for Emacs

Syntax highlighting support for "Modern C++" - until C++20 and Technical Specification. This package aims to provide a simple highlight of the C++ lan

Ludwig PACIFICI 167 Dec 1, 2022
Common Lisp and CXX interoperation with JIT

CL-CXX-JIT - Common Lisp C++ JIT for exposing C++ functions This library provides an interface to C++ from lisp. It compiles C++ code, then loads it i

Islam Omar 39 Dec 19, 2022
MINCE is an Emacs-like text editor from Mark of the Unicorn, Inc.

MINCE Is Not Complete[ly] EMACS Overview MINCE is an Emacs-like text editor from Mark of the Unicorn, Inc. Versions were available for many oper

Jeffrey H. Johnson 20 Nov 5, 2022
aLisp - a custom Lisp in C

aLisp aims to become a hackable, embeddable, reasonably fast interpreted custom Lisp implemented in portable C.

Andreas Nilsson 7 Jan 10, 2022
Clio is an embryonic experiment in UI for Common Lisp programs.

Clio Clio is an embryonic experiment in UI for Common Lisp programs. Building and running Clio Make sure you have the prerequisites: Visual Studio 201

mikel evins 0 Feb 26, 2022
te is a small text editor with emacs keybindings.

te - a tiny emacs te is a small text editor with emacs keybindings. Here are söme Ümlautß! Oh no. Come, you spirits That tend on mortal thoughts, unse

Leah Neukirchen 21 Nov 5, 2022