Skip to main content

Module parsers

Module parsers 

Source
Expand description

Tree-sitter parser initialization and caching for all supported languages.

Provides cached, zero-cost access to tree-sitter language parsers. Each parser is initialized once and cached using std::sync::OnceLock for thread-safe, lazy initialization.

§Feature Flags

§all-parsers

When enabled (default), imports all tree-sitter parser crates and provides full parser functionality. Disable for WebAssembly builds where tree-sitter cannot be compiled.

§Individual Language Features

Each language has its own feature flag, so you can enable whichever ones you need.

§napi-environment

Disables tree-sitter parsing functionality because tree-sitter cannot build in a NAPI environment. NAPI (Node.js API) is used for building WASM modules for Node.js. (note: WASM builds for browser or other environments can support tree-sitter)

§Napi-compatible Languages

You can use these languages in a NAPI environment:

  • You can use the napi-compatible flag as a shortcut to enable all napi-compatible languages.
  • css
  • html
  • javascript
  • typescript
  • tsx

§Parser Functions

Each language has a corresponding language_*() function that returns a cached TSLanguage instance:

use thread_language::parsers::{language_rust, language_javascript};

let rust_lang = language_rust();
let js_lang = language_javascript();

§Caching Strategy

Parsers use std::sync::LazyLock for optimal performance:

  • First call initializes the parser
  • Subsequent calls return the cached instance
  • Thread-safe with no synchronization overhead after initialization

Functions§

language_bash
language_c
language_c_sharp
language_cpp
language_css
language_elixir
language_go
language_haskell
language_hcl
language_html
language_java
language_javascript
language_json
language_kotlin
language_lua
language_nix
language_php
language_python
language_ruby
language_rust
language_scala
language_solidity
language_swift
language_tsx
language_typescript
language_yaml