gleam-lang / tree-sitter-gleam

🌳 A tree-sitter grammar for the Gleam programming language
Apache License 2.0
66 stars 13 forks source link
gleam parser tree-sitter

tree-sitter-gleam

A tree-sitter grammar for the Gleam programming language

This grammar is able to parse the entire Gleam language. It is largely based on the Gleam parser itself, and deviations from that are noted throughout the codebase.

Usage

tree-sitter-gleam, as with all tree-sitter grammars, is of limited utility on its own. Instead, tree-sitter-gleam is best used as a Gleam parser that can be embedded in other projects. An example of such a project is tree-sitter-gleam-rust-example.

However, tree-sitter-cli can be used with this grammar to show generated parse trees and syntax highlighting for a given Gleam file.

  1. Install tree-sitter-cli
  2. Create a tree-sitters directory in your home directory.
  3. Clone this repository (or symlink it) into the new ~/tree-sitters/ directory.
  4. Run tree-sitter parse path/to/file.gleam to be shown the parse tree for the file.
  5. Run tree-sitter highlight path/to/file.gleam to be shown the file with syntax highlighting applied.

Various Gotchas

There are a few nodes in the generated AST that may be confusing at first:

This is not a comprehensive list. If you find a node confusing, search for it in grammar.js, as it might have an explanatory comment. Either way, feel free to add it to this list and send a PR! ✨

To-do List

Contributing

  1. Change files such as grammar.js and queries/highlight.scm.
  2. The grammar needs to be generated from the grammar.js file by running npm run generate.
  3. Add parser feature tests to the relevant file(s) in test/corpus/, or make a new one.
  4. Run npm run test and fix any failing tests.

Policies

Backwards-Compatibility Policy

Per the conversation in #55, we have decided that from v0.28.0 forward, tree-sitter-gleam will maintain backwards compatibility with the previous two minor versions; meaning that each release will support three versions:

e.g. The v0.30.0 release of tree-sitter gleam will support the following version of the Gleam language:

Style

To prevent headaches from stylistic differences, I request that you please follow these style suggestions. 🙏