Skip to main content

Crate thread_language

Crate thread_language 

Source
Expand description

Language definitions and tree-sitter parsers for Thread AST analysis.

Provides unified language support through consistent Language and LanguageExt traits across 24+ programming languages. Each language can be feature-gated individually or included in groups.

§Language Categories

§Standard Languages

Languages that accept $ as a valid identifier character and use default pattern processing:

§Custom Pattern Languages

Languages requiring special metavariable handling with custom expando characters:

§Usage

use thread_language::{SupportLang, Rust};
use thread_ast_engine::{Language, LanguageExt};

// Runtime language selection
let lang = SupportLang::from_path("main.rs").unwrap();
let tree = lang.ast_grep("fn main() {}");

// Compile-time language selection
let rust = Rust;
let tree = rust.ast_grep("fn main() {}");

§Implementation Details

Languages are implemented using two macros:

  • [impl_lang!] - Standard languages accepting $ in identifiers
  • [impl_lang_expando!] - Languages requiring custom expando characters for metavariables

Modules§

constants
ext_iden
Optimized extension matching for language detection.
parsers
Tree-sitter parser initialization and caching for all supported languages.

Structs§

Bash
C
CSharp
Cpp
Css
Elixir
Go
Haskell
Hcl
Html
HTML language implementation with language injection capabilities.
Java
JavaScript
Json
Kotlin
Lua
Nix
Php
Python
Ruby
Rust
Scala
Solidity
Swift
Tsx
TypeScript
Yaml

Enums§

SupportLang
Runtime language selection enum supporting all built-in languages.
SupportLangErr

Traits§

Alias

Functions§

config_file_type
extensions
from_extension
Guess which programming language a file is written in Adapt from <https://github.com/Wilfred/difftastic/blob/master/src/parse/guess_language.rs> N.B do not confuse it with FromStr trait. This function is to guess language from file extension.
from_extension_str