Skip to main content

Crate big_code_analysis_ast

Crate big_code_analysis_ast 

Source
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

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 Alterator hook a language implements to reshape a node before it is rendered as an AstNode.
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 Getter accessors — 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 LANG enum, extension and emacs-mode lookup, the per-language *Code tags and *Parser aliases, and AnyParser.
languages
Per-language tree-sitter token enums.
macros
The mk_langs! family that generates langs, the with_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 node Filters count / find accept.
preproc
The C-family preprocessor pass: the include graph, macro collection, and the PreprocResults document.
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, and Search.

Macros§

with_any_parser
Dispatches over every AnyParser variant, binding the concrete Parser<XCode> to $p and evaluating $body once per arm.