#nickel #parser #incremental

tree-sitter-nickel

Nickel grammar for the tree-sitter parsing library

1 unstable release

0.1.0 Sep 14, 2023

#291 in Text editors

36 downloads per month

MIT license

1MB
45K SLoC

C 44K SLoC JavaScript 399 SLoC // 0.2% comments C++ 278 SLoC // 0.2% comments Scheme 65 SLoC // 0.0% comments Rust 43 SLoC // 0.1% comments

tree-sitter-nickel

Nickel grammar for tree-sitter.

Overview

Tree sitter is a parser framework for use in development tools. In particular it enable semantically aware highlighting, indentation, folding, etc. This project provides such a grammar for Nickel.

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

Neovim

To use these queries with neovim, it is best to clone this repository locally. From there, one can can configure tree-sitter to use this grammar using the following example configuration.

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.cc"},
    branch = "main",
    generate_requires_npm = false,
    requires_generate_from_grammar = false,
  },
}

However, keep in mind these queries will eventually be upstreamed to the neovim tree-sitter repository, so the above should probably only be done during development of the grammar.

Structure

grammar.js is the main grammar file of this project, with a custom scanner in src/scanner.cc. The corpus/ directory contains a multitude of tests.

Building the new grammar is done with tree-sitter generate. Testing against the corpus is done with tree-sitter test. Finally, parsing a specified file is done with tree-sitter parse FILENAME, and testing highlight queries is done with tree-sitter highlight FILENAME.

shell.nix

The project comes with a shell.nix containing everything needed to work on the grammar itself.

Node and Rust bindings

As with other tree-sitter grammars, this repository comes with Node and Rust bindings. These will eventually be uploaded to crates.io for use with cargo, and npm.

Dependencies

~2.8–4MB
~72K SLoC