Skip to content

tree-sitter-grammars/tree-sitter-commonlisp

Repository files navigation

tree-sitter-commonlisp

CI discord matrix npm crates pypi

WIP. Goal is to have a better syntax highlighting for Neovim and some semantic refactoring https://github.com/nvim-treesitter/nvim-treesitter-refactor/.

All praise goes to https://github.com/sogaiu/tree-sitter-clojure which is extended by this grammar.

TODOs:

  • support number literals that are different from clojure (e.g. .9)

Macros with special respresentation in syntax tree (when written with lowercase letters):

  • defun and friends (e.g. defmethod)
  • loop macro

This grammar is used in https://github.com/Wilfred/difftastic to generate syntax-ware diffs for Common Lisp.

Usage

  • C/C++

    ts_parser_set_language(parser, tree_sitter_commonlisp());
  • Python (pip install tree-sitter-commonlisp tree-sitter)

    lang = tree_sitter.Language(tree_sitter_commonlisp.language())
    parser = tree_sitter.Parser(lang)
    tree = parser.parse(
    bytes(
    """
    (+ 1 1)
    """,
    "utf8"
    )

  • Rust cargo add tree-sitter tree-sitter-grammars

    let mut parser = tree_sitter::Parser::new();
    parser
    .set_language(&LANGUAGE_COMMONLISP.into())
    .expect("Error loading commonlisp language");

  • Swift

    import SwiftTreeSitter
    import TreeSitterCommonlisp
    final class TreeSitterCommonLispTests: XCTestCase {
    func testCanLoadGrammar() throws {
    let parser = Parser()
    let language = Language(language: tree_sitter_commonlisp())
    XCTAssertNoThrow(try parser.setLanguage(language),
    "Error loading CommonLisp grammar")
    }
    }

  • Go

    package tree_sitter_commonlisp_test
    import (
    "testing"
    tree_sitter "github.com/smacker/go-tree-sitter"
    "github.com/tree-sitter/tree-sitter-commonlisp"
    )
    func TestCanLoadGrammar(t *testing.T) {
    language := tree_sitter.NewLanguage(tree_sitter_commonlisp.Language())
    if language == nil {
    t.Errorf("Error loading Commonlisp grammar")
    }
    }