Expand description
The parse and classification layer behind
big-code-analysis.
This crate turns source bytes into a tree_sitter tree and
answers structural questions about it: which LANG a file is in,
what a Node is (is_func, is_call, is_string, … through
[Checker]), what it is called and which Halstead class or
SpaceKind it opens (Getter), and how it should be rendered
as an AstNode (Alterator). It also owns the C-family
preprocessor pass (preproc), comment stripping, node counting and
finding, and language detection (guess_language). It computes no
metric.
§Stability
This crate is internal plumbing. It exists so the metric walk in
big-code-analysis and any future structural consumer (a linter, a
call-graph builder, a language server) can share one classification
layer without the metric machinery. big-code-analysis pins it at
an exact =X.Y.Z version, the two are released together, and no
item here carries a stability promise of its own: names, signatures
and module paths may change in any release. Depend on
big-code-analysis and reach what it re-exports; depend on this
crate directly only when you accept re-pinning on every release.
The one contract that does hold is the one big-code-analysis
documents in its STABILITY.md for the items it re-exports from
here (LANG, Node, MetricsError, SpaceKind, the AST dump
types, the preprocessor types, the file readers). Those are stable
through that crate.
§Layout
languages: one generated enum per grammar, one variant per tree-sitter kind id.langs: theLANGenum, extension / emacs-mode lookup, the per-language*Codetags and*Parseraliases, andAnyParser, the runtime-dispatched parser every consumer matches on withwith_any_parser!.node,traits,parser: the tree-sitter wrappers and theParserTrait/Search/LanguageInfocontracts.checker,getter,alterator,lang_helpers: the per-language classifiers and the byte-level identity helpers they share with the metrics.preproc,c_macro,c_declarator: the C-family pipeline.comment_rm,ast,count,find,tools: the per-file operations reached throughbig_code_analysis::Ast.
The unlinked names above are crate-private modules, reached only
through the AnyParser methods mk_action! generates.
Re-exports§
pub use crate::alterator::Alterator;pub use crate::ast::AstCfg;pub use crate::ast::AstNode;pub use crate::ast::AstPayload;pub use crate::ast::AstResponse;pub use crate::ast::MAX_AST_SERIALIZE_DEPTH;pub use crate::ast::Span;pub use crate::count::Count;pub use crate::count::CountCollector;pub use crate::error::MetricsError;pub use crate::getter::Getter;pub use crate::macros::ParseLangError;pub use crate::node::Ancestors;pub use crate::node::FoldCache;pub use crate::node::Node;pub use crate::node::SiblingCache;pub use crate::parser::Parser;pub use crate::preproc::PreprocDiagnostic;pub use crate::preproc::PreprocFile;pub use crate::preproc::PreprocResults;pub use crate::preproc::fix_includes;pub use crate::preproc::get_macros;pub use crate::preproc::preprocess;pub use crate::space_kind::SpaceKind;pub use crate::token_role::TokenRole;pub use crate::tools::SkipReason;pub use crate::tools::get_language_for_file;pub use crate::tools::guess_language;pub use crate::tools::is_generated;pub use crate::tools::normalize_eol;pub use crate::tools::read_file;pub use crate::tools::read_file_with_eol;pub use crate::tools::read_file_with_eol_classified;pub use crate::tools::write_file;pub use crate::traits::LanguageInfo;pub use crate::traits::ParserTrait;pub use crate::traits::Search;pub use ::tree_sitter;pub use crate::checker::*;pub use crate::langs::*;pub use crate::languages::*;
Modules§
- alterator
- Per-language AST simplification for the dump: the
Alteratorhook a language implements to reshape a node before it is rendered as anAstNode. - ast
- The AST dump:
AstNode,Span,AstCfg,AstResponse, and the walk that builds them. - c_
declarator - The C-family declarator-chain walk, shared by the two surfaces that need it.
- checker
- The [
Checker] classification predicates and their per-language impls. - count
- Node counting by kind or category, and the shared
CountCollector. - error
- Error type returned from the library’s top-level entry points.
- getter
- The
Getteraccessors — names, space kinds, Halstead classes — and their per-language impls. - lang_
helpers - Byte-level identity helpers shared by the classifiers and the metrics.
- langs
- The
LANGenum, extension and emacs-mode lookup, the per-language*Codetags and*Parseraliases, andAnyParser. - languages
- Per-language tree-sitter token enums.
- macros
- The
mk_langs!family that generateslangs, thewith_any_parser!dispatch macro, and the kind-set aliases. - node
- Tree-sitter wrappers:
Tree,Node,Ancestors, and the cursors. - observation
- Thread-local counters that make an invisible optimization testable.
- parser
Parser<T>and the nodeFilterscount/findaccept.- preproc
- The C-family preprocessor pass: the include graph, macro collection,
and the
PreprocResultsdocument. - recursion
- Stack-depth bounds for the crate’s recursive types.
- space_
kind - The kinds of space the walk opens: functions and the containers (class, struct, trait, impl, namespace, interface) plus the file unit.
- token_
role - The role a node plays in an expression: operator, operand, or neither.
- tools
- Language detection and the file readers.
- traits
ParserTrait,LanguageInfo, andSearch.
Macros§
- with_
any_ parser - Dispatches over every
AnyParservariant, binding the concreteParser<XCode>to$pand evaluating$bodyonce per arm.