Skip to content

aidanmontare-fed/tree-sitter-coconut

 
 

Repository files navigation

tree-sitter-coconut

A tree-sitter grammar for Coconut.

This is very much a work in progress.

Coconut Features

https://coconut.readthedocs.io/en/latest/DOCS.html

Below are Coconut features and their implementation status in this grammar.

  • Operators

    • lambda syntax
    • partial application
    • pipes
      • in-place pipes
      • lambda as last argument of pipes
        • for backwards pipes
      • piping into (<name> := .) to assign to a <name>
    • function composition
      • basic implementation
      • in-place operators
      • finish tests
      • highlight queries
    • iterator slicing
      • implementation
      • tests
      • highlights
  • Keywords

    • where statements
  • Expressions

  • Function Definition

    • assignment functions
      • basic implementation
      • finish tests
  • Statements

  • Built-Ins

  • highlights

  • tests for highlights

Development

cargo install tree-sitter-cli

helix

You can see how the grammar works for syntax highlighting by trying it out in the helix editor.

Add the following to your language.toml file:

[[language]]
name = "coconut"
scope = "source.coconut"
injection-regex = "coconut"
file-types = ["coco"]
shebangs = ["coconut"]
roots = ["pyproject.toml", "setup.py", "poetry.lock", "pyrightconfig.json"]
comment-token = "#"
# language-servers = [ "pylsp" ]
# TODO: pyls needs utf-8 offsets
indent = { tab-width = 4, unit = "    " }

[[grammar]]
name = "coconut"
# source = { git = "https://github.com/tree-sitter/tree-sitter-python", rev = "4bfdd9033a2225cc95032ce77066b7aeca9e2efc" }
source = { path = "/PATH/TO/THIS/REPO"}

Helix uses syntax highlighting and indentation queries from it's own runtime directory, not from the tree-sitter package (because Helix uses some of its own names in the queries). So, for now we can do something like this:

$ ln -s $PWD/queries/helix ~/.config/helix/runtime/queries/coconut

Later, the queries/helix folder should probably become a pull request into helix's source.

$ hx --grammar fetch
$ hx --grammar build
$ hx --health coconut

Now try opening a coconut file in helix, and you should have syntax highlighting!

About

tree-sitter grammar for Coconut (https://coconut-lang.org/)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 54.1%
  • C 25.4%
  • Scheme 20.5%