Skip to content

rtbs-dev/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/rtbs-dev/tree-sitter-coconut", rev="master" }

Now you need to fetch and build the C headers for the parser.

$ hx --grammar fetch
$ hx --grammar build

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 $HELIX_RUNTIME/runtime/grammars/sources/coconut/queries $HELIX_RUNTIME/queries/coconut

Helix should now recognize the queries for syntax highlighting, which you can confirm with $ hx --health coconut

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

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

 
 
 

Contributors

Languages

  • JavaScript 56.3%
  • C 26.4%
  • Tree-sitter Query 17.3%