tree-sitter-scala

A tree-sitter grammar for parsing Scala source code into a concrete syntax tree.

Library
Cargo
v0.26.2
196stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
83/100Excellent
Development Activity100
Maintenance72
Community80
Maturity60
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
77/100Good
Architecture80
Code Quality82
Innovation70
Learning Curve75

tree-sitter-scala is a tree-sitter grammar package that teaches the tree-sitter incremental parsing engine how to parse Scala 2 and Scala 3 source code into a concrete syntax tree. It’s consumed as a Rust crate (or via its C, Python, Go, Node, and Swift bindings) by editors, linters, and static-analysis tools that need fast, error-tolerant, incremental parsing of Scala files.

Because tree-sitter parsers are designed for editor-speed reparsing on every keystroke, tree-sitter-scala underpins Scala syntax highlighting, code folding, and structural navigation in tools like Neovim, Helix, and Zed, as well as any custom tooling built on the tree-sitter Rust bindings.

What You Get

  • A generated C parser (src/parser.c) plus scanner for Scala 2/3 syntax, compiled via the tree-sitter-language crate binding
  • Highlight, tag, and injection query files (queries/) for syntax highlighting and code-navigation integrations
  • Bindings for Rust, C, Node.js, Python, Go, and Swift so the same grammar can be embedded in tools written in any of those languages
  • A test corpus (test/corpus, test/highlight, test/tags) validating parser correctness against real Scala syntax

Common Use Cases

  • Powering Scala syntax highlighting and code folding in editors built on tree-sitter (Neovim, Helix, Zed)
  • Building static-analysis, linting, or code-search tools that need a fast incremental Scala parser
  • Embedding Scala-aware structural navigation (jump-to-definition-style queries) in custom developer tooling
  • Generating syntax trees for Scala source as part of a documentation or refactoring pipeline

Under The Hood

Architecture: The grammar is defined declaratively in grammar.js using tree-sitter’s DSL, then compiled offline into a generated src/parser.c (a table-driven GLR-style parser) plus a hand-written src/scanner.c for context-sensitive tokens (e.g. Scala’s significant indentation and string interpolation); the Rust crate (bindings/rust/lib.rs) links this C code via a build script and exposes the LANGUAGE constant consumed by the tree-sitter crate. Tech Stack: Core grammar logic is C (generated) plus a JS grammar-definition file; the Rust binding depends only on tree-sitter-language and a C build (cc crate) at build time, keeping the runtime dependency surface minimal; parallel bindings exist for Node (npm), Python (setup.py/pyproject.toml), Go (go.mod), and Swift (Package.swift). Code Quality: The test/corpus directory contains extensive example-based grammar tests exercising Scala 2 and Scala 3 syntax edge cases, plus separate test/highlight and test/tags suites verifying the query files produce correct highlighting/tagging output; grammar changes are validated via tree-sitter test in CI across all bindings. API Design: Consumers interact with a single exported LANGUAGE (Rust) or equivalent per-binding export, following tree-sitter’s standard cross-language convention, so switching from one tree-sitter grammar crate to another requires no API relearning.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search