Skip to main content

lang_parsing_substrate/
lib.rs

1//! A shared language-parsing substrate for static-analysis tools:
2//! tree-sitter grammar dispatch, language detection ([`registry`]), and a
3//! growing set of language-agnostic analysis primitives — import/call
4//! graphs, control-flow graphs, structural fingerprinting, suppression
5//! comments — built on top of a unified [`registry::LanguageInfo`] table
6//! across 16 languages, compiled in at build time via Cargo feature flags.
7//! Consumers include knots, moldy, and aurora-lint; see this crate's README
8//! for the full module-to-purpose table.
9
10#![warn(missing_docs)]
11
12pub mod c_standard;
13pub mod calls;
14pub mod cfg;
15pub mod classify;
16#[cfg(all(feature = "lang-c", feature = "lang-cpp"))]
17pub mod cpp_header;
18#[cfg(any(feature = "lang-c", feature = "lang-cpp", feature = "lang-csharp"))]
19pub mod dead_code;
20#[cfg(feature = "lang-csharp")]
21pub mod dead_code_csharp;
22#[cfg(feature = "lang-swift")]
23pub mod dead_code_swift;
24pub mod fingerprint;
25pub mod flat;
26pub mod imports;
27#[cfg(any(feature = "lang-c", feature = "lang-cpp"))]
28pub mod isr;
29#[cfg(feature = "lang-markdown")]
30pub mod markdown;
31pub mod parse_budget;
32pub mod path_ignore;
33#[cfg(feature = "pyo3")]
34mod py;
35pub mod query;
36pub mod regions;
37pub mod registry;
38#[cfg(test)]
39mod scaling_check;
40pub mod suppressions;
41pub mod tsquery;
42
43pub use c_standard::{detect_min_c_standard, CStandard};
44pub use calls::{call_edges, collect_local_names, get_function_name, is_function_kind, CallEdge};
45pub use cfg::{build_function_cfg, BasicBlock, BlockId, CfgEdge, FunctionCfg};
46pub use classify::{
47    classify, classify_file, BinaryKind, ClassifyLimits, FileClass, SourceText, TextEncoding,
48    DEFAULT_PREFIX_LEN,
49};
50#[cfg(all(feature = "lang-c", feature = "lang-cpp"))]
51pub use cpp_header::{looks_like_cpp, sniff_header, sniff_header_with_budget, HeaderSniff};
52#[cfg(any(feature = "lang-c", feature = "lang-cpp", feature = "lang-csharp"))]
53pub use dead_code::{
54    dead_code_ranges, dead_code_ranges_with_assumptions, posix_default_assumptions, DeadCodeReason,
55    DeadCodeRegion, PlatformAssumptions,
56};
57#[cfg(feature = "lang-csharp")]
58pub use dead_code_csharp::{csharp_dead_code_regions, CSharpDeadCodeRegion};
59#[cfg(feature = "lang-swift")]
60pub use dead_code_swift::{swift_dead_code_regions, SwiftDeadCodeRegion};
61pub use fingerprint::{
62    block_fingerprints, duplicate_groups, function_fingerprints, is_block_kind, structural_hash,
63    CorpusFingerprint, Fingerprint, FingerprintTier,
64};
65pub use flat::{flatten, FlatTree};
66pub use imports::{distinct_import_count, import_sources};
67#[cfg(any(feature = "lang-c", feature = "lang-cpp"))]
68pub use isr::{interrupt_handlers, InterruptEvidence, InterruptHandler};
69#[cfg(feature = "lang-markdown")]
70pub use markdown::{front_matter, sections, ContentMap, FrontMatter, FrontMatterKind, Section};
71pub use parse_budget::{parse_within_budget, BudgetExceeded, ParseBudget};
72pub use path_ignore::PathIgnore;
73pub use query::{
74    ancestors, child_nodes, find_ancestor, find_ancestor_from_root, find_descendants,
75    find_descendants_of_kind, find_descendants_of_kinds, find_first_descendant, named_child_nodes,
76    nearest_ancestor_of_kind, nearest_ancestor_of_kind_from_root, nearest_ancestor_of_kinds,
77    nearest_ancestor_of_kinds_from_root, node_text, walk_preorder, Walk,
78};
79pub use regions::{ignored_regions, IgnoredRegion};
80#[cfg(all(feature = "lang-c", feature = "lang-cpp"))]
81pub use registry::language_for_header_content;
82pub use registry::{
83    is_discoverable_file, is_extension_for_language, is_parseable_extension, is_source_extension,
84    language_for_file, language_for_key, language_info_for_file, languages, sloc_mode_for_file,
85    supported_languages_report, LanguageInfo, SlocMode,
86};
87pub use suppressions::{suppressions, Suppression};
88pub use tsquery::{run_query, tags_query, Capture};
89
90// Grammar re-exports — gated by feature so consumers reach grammars without
91// adding their own direct tree-sitter-* dependencies.
92#[cfg(feature = "lang-ada")]
93pub use tree_sitter_ada;
94#[cfg(feature = "lang-bash")]
95pub use tree_sitter_bash;
96#[cfg(feature = "lang-c")]
97pub use tree_sitter_c;
98#[cfg(feature = "lang-csharp")]
99pub use tree_sitter_c_sharp;
100#[cfg(feature = "lang-cmake")]
101pub use tree_sitter_cmake;
102#[cfg(feature = "lang-cpp")]
103pub use tree_sitter_cpp;
104#[cfg(feature = "lang-fortran")]
105pub use tree_sitter_fortran;
106#[cfg(feature = "lang-go")]
107pub use tree_sitter_go;
108#[cfg(feature = "lang-java")]
109pub use tree_sitter_java;
110#[cfg(feature = "lang-javascript")]
111pub use tree_sitter_javascript;
112#[cfg(feature = "lang-json")]
113pub use tree_sitter_json;
114#[cfg(feature = "lang-kotlin")]
115pub use tree_sitter_kotlin_ng;
116#[cfg(feature = "lang-lua")]
117pub use tree_sitter_lua;
118#[cfg(feature = "lang-markdown")]
119pub use tree_sitter_md;
120#[cfg(feature = "lang-php")]
121pub use tree_sitter_php;
122#[cfg(feature = "lang-python")]
123pub use tree_sitter_python;
124#[cfg(feature = "lang-rst")]
125pub use tree_sitter_rst;
126#[cfg(feature = "lang-rust")]
127pub use tree_sitter_rust;
128#[cfg(feature = "lang-scala")]
129pub use tree_sitter_scala;
130#[cfg(feature = "lang-swift")]
131pub use tree_sitter_swift;
132#[cfg(feature = "lang-typescript")]
133pub use tree_sitter_typescript;
134#[cfg(feature = "lang-yaml")]
135pub use tree_sitter_yaml;