#tree-sitter #nickel #programming-language #incremental

tree-sitter-nickel

Nickel grammar for the tree-sitter parsing library

3 releases (breaking)

0.3.0 Oct 1, 2024
0.2.0 Jun 5, 2024
0.1.0 Sep 14, 2023

#148 in Text editors

Download history 22/week @ 2024-08-19 25/week @ 2024-08-26 25/week @ 2024-09-02 124/week @ 2024-09-09 84/week @ 2024-09-16 73/week @ 2024-09-23 208/week @ 2024-09-30 81/week @ 2024-10-07 50/week @ 2024-10-14 70/week @ 2024-10-21 56/week @ 2024-10-28 29/week @ 2024-11-04 120/week @ 2024-11-11 84/week @ 2024-11-18 73/week @ 2024-11-25 70/week @ 2024-12-02

353 downloads per month
Used in 3 crates (via nickel-lang-core)

MIT license

1.5MB
52K SLoC

C 52K SLoC // 0.0% comments JavaScript 500 SLoC // 0.2% comments Scheme 65 SLoC // 0.0% comments Rust 37 SLoC // 0.1% comments

tree-sitter-nickel

Nickel grammar for tree-sitter.

Overview

Tree sitter is a parser framework for programming language tooling. Tree sitter enables semantically aware highlighting, indentation, folding, and much more. This project provides a tree sitter grammar definition for Nickel.

Every editor has to provide specific queries for its own use. Currently, we provide example highlighting queries in the style of Neovim.

With Neovim

The Nickel language has been added to nvim-treesitter. Please refer to nvim-treesitter's installation guide there to get Nickel highlighting out of the box. Note that while nvim-treesitter uses the latest grammar definition from this repository automatically, the highlighting queries are hosted directly by nvim-treesitter. They were copied at some point in time from this repository, but they might not always be up to date.

With Neovim locally

You can use a local version of those queries with Neovim for developing, testing or customization purpose:

  1. Clone this repository

  2. Configure tree-sitter to use this grammar:

    local parser_config = require("nvim-treesitter.parsers").get_parser_configs()
    parser_config.nickel = {
      install_info = {
        url = "PATH_TO_WHERE_YOU_CLONED_IT",
        files = {"src/parser.c", "src/scanner.c"},
        branch = "main",
        generate_requires_npm = false,
        requires_generate_from_grammar = false,
      },
    }
    

Hacking

Structure

  • grammar.js is the main grammar definition. Most other files are generated from grammar.js and this is most probably the file you want to modify when updating the grammar
  • src/scanner.c contains a custom scanner required by the Nickel grammar
  • src/* most other files in src are auto-generated and shouldn't be modified directly
  • corpus/ contains a test suite
  • bindings/ contains the bindings to this parser for various languages.

Requirements

The project comes with a flake.nix containing everything needed to work on the grammar itself via Nix. With a flake-enabled Nix, Just run nix develop at the root of this repository to be dropped in a shell with all the needed commands available.

Without Nix, you have to install tree-sitter and other dependencies manually. You should be able to deduce a list of requirements easily by reading flake.nix.

Actions

  • tree-sitter generate will build the grammar from the current definition
  • tree-sitter test tests the built grammar against corpus
  • tree-sitter parse <FILE> parses the given file.
  • tree-sitter highlight <FILE> tests highlighting of the given file

Bindings

As with other tree-sitter grammars, this repository comes with bindings for the following languages:

  • C
  • Go
  • Node
  • Python
  • Rust
  • Swift

Dependencies

~2.8–4MB
~79K SLoC