pub enum AnyParser {
Show 25 variants
Javascript(JavascriptParser),
Mozjs(MozjsParser),
Java(JavaParser),
Go(GoParser),
Kotlin(KotlinParser),
Lua(LuaParser),
Rust(RustParser),
Tcl(TclParser),
Irules(IrulesParser),
C(CParser),
Cpp(CppParser),
Mozcpp(MozcppParser),
Objc(ObjcParser),
Csharp(CsharpParser),
Elixir(ElixirParser),
Python(PythonParser),
Tsx(TsxParser),
Typescript(TypescriptParser),
Bash(BashParser),
Ccomment(CcommentParser),
Preproc(PreprocParser),
Perl(PerlParser),
Php(PhpParser),
Ruby(RubyParser),
Groovy(GroovyParser),
}Expand description
A parsed tree plus its source bytes for a language chosen at
runtime — one variant per LANG, each holding that
language’s Parser<XCode>. The public seam is
big_code_analysis::Ast; this enum is the language-dispatched carrier
it wraps, and the value a caller matches on to reach a
concrete parser (with_any_parser!).
Every variant exists regardless of the Cargo feature set: a
Parser<XCode> type needs no grammar crate, only
Self::parse / Self::from_tree do, and those are the
arms that are feature-gated. A disabled language is therefore
never constructed — the constructors return
Err(LanguageDisabled) for it — but it can always be named,
which is what lets with_any_parser! be written once without
any cfg of its own (#1376).
The cost is real and was priced: because the match is total
over all 25 variants, every generic walk is monomorphised for
every language whatever features were selected. Measured on a
--no-default-features --features rust build, metrics_inner
and ops_inner each get 25 instantiations where the
pre-split crate got one.
DECIDED (#1376): it stays. Reversing it means moving the
dispatch macro into big-code-analysis, so the cfgs are
evaluated in the crate whose features they name — a
#[cfg] inside a #[macro_export] macro is evaluated in the
invoking crate, which is the whole reason this shape exists
— and that buys an eighth site enumerating every language,
permanently. A visitor trait does not help: one defined here
can only bound its type parameter by traits this crate can
name, so it hands back a ParserTrait where the metric walks
need the root’s MetricSuite, and Rust cannot let a caller
supply that bound. Nothing in this workspace pays the cost —
the CLI, the server and the Python bindings all build
all-languages — and what it costs is compile time and rlib
size, not shipped binary size, since unreferenced
instantiations are dropped at link time. Revisit only if a
consumer of the narrow feature set actually appears.
Variants§
Javascript(JavascriptParser)
The Javascript parser.
Mozjs(MozjsParser)
The Mozjs parser.
Java(JavaParser)
The Java parser.
Go(GoParser)
The Go parser.
Kotlin(KotlinParser)
The Kotlin parser.
Lua(LuaParser)
The Lua parser.
Rust(RustParser)
The Rust parser.
Tcl(TclParser)
The Tcl parser.
Irules(IrulesParser)
The Irules parser.
C(CParser)
The C parser.
Cpp(CppParser)
The Cpp parser.
Mozcpp(MozcppParser)
The Mozcpp parser.
Objc(ObjcParser)
The Objc parser.
Csharp(CsharpParser)
The Csharp parser.
Elixir(ElixirParser)
The Elixir parser.
Python(PythonParser)
The Python parser.
Tsx(TsxParser)
The Tsx parser.
Typescript(TypescriptParser)
The Typescript parser.
Bash(BashParser)
The Bash parser.
Ccomment(CcommentParser)
The Ccomment parser.
Preproc(PreprocParser)
The Preproc parser.
Perl(PerlParser)
The Perl parser.
Php(PhpParser)
The Php parser.
Ruby(RubyParser)
The Ruby parser.
Groovy(GroovyParser)
The Groovy parser.
Implementations§
Source§impl AnyParser
impl AnyParser
Sourcepub fn parse(
lang: LANG,
source: Vec<u8>,
preproc_path: Option<&Path>,
preproc: Option<Arc<PreprocResults>>,
) -> Result<Self, MetricsError>
pub fn parse( lang: LANG, source: Vec<u8>, preproc_path: Option<&Path>, preproc: Option<Arc<PreprocResults>>, ) -> Result<Self, MetricsError>
Parse source as lang.
Parser::new keys the C-family macro-expansion lookup off
the caller-supplied path; callers analysing in-memory
snippets pass None and get the empty Path (""),
which the lookup ignores. That path never leaks into a
display name — Ast carries the name separately.
source is taken by value so an owned buffer moves
straight into the parser instead of being copied.
§Errors
MetricsError::LanguageDisabled when lang’s Cargo
feature is not enabled in this build.
Sourcepub fn from_tree(
lang: LANG,
tree: Tree,
source: Vec<u8>,
) -> Result<Self, MetricsError>
pub fn from_tree( lang: LANG, tree: Tree, source: Vec<u8>, ) -> Result<Self, MetricsError>
Adopt a caller-built tree_sitter::Tree produced from
source with lang’s grammar.
§Errors
MetricsError::LanguageDisabled when lang’s Cargo
feature is not enabled in this build.
Sourcepub fn code(&self) -> &[u8] ⓘ
pub fn code(&self) -> &[u8] ⓘ
The bytes the tree was parsed from — after #define
expansion for the C family, so not necessarily the bytes
handed to Self::parse.
Sourcepub fn ts_tree(&self) -> &Tree
pub fn ts_tree(&self) -> &Tree
The held tree_sitter::Tree.
Sourcepub fn strip_comments(&self) -> Option<Vec<u8>>
pub fn strip_comments(&self) -> Option<Vec<u8>>
The source with non-doc comments removed, or None when
there was nothing to strip.
Sourcepub fn dump(&self, cfg: AstCfg) -> AstResponse
pub fn dump(&self, cfg: AstCfg) -> AstResponse
The AST dump under cfg.