Skip to main content

ParserTrait

Trait ParserTrait 

Source
pub trait ParserTrait {
    type Checker: Alterator + Checker;
    type Getter: Getter;

    // Required methods
    fn new(code: Vec<u8>, path: &Path, pr: Option<Arc<PreprocResults>>) -> Self;
    fn root(&self) -> Node<'_>;
    fn code(&self) -> &[u8] ⓘ;
    fn filters(&self, requested: &[String]) -> Filter<'_>;
}
Expand description

A parsed source in one language: the tree, its bytes, and the Checker / Getter classifiers that read it.

Implemented once, generically, by Parser<T> for every *Code tag; the per-language *Parser aliases in langs are its concrete forms. This is the parse half of a language: big-code-analysis layers the per-metric implementations on top through its own supertrait, so nothing here depends on a metric (#1376). Not an extension contract — implement nothing; match on AnyParser to reach one.

Required Associated Types§

Source

type Checker: Alterator + Checker

The language’s classification predicates.

Source

type Getter: Getter

The language’s naming / space-kind / Halstead-class accessors.

Required Methods§

Source

fn new(code: Vec<u8>, path: &Path, pr: Option<Arc<PreprocResults>>) -> Self

Parses code read from path. pr carries the C-family preprocessor results whose #defines are expanded before parsing; every other language ignores it.

§Panics

When the language’s Cargo feature is disabled in this build — there is no grammar to parse with and the signature is infallible. Check LANG::is_enabled first, or reach a parser through AnyParser::parse, which returns Err(MetricsError::LanguageDisabled) instead.

Source

fn root(&self) -> Node<'_>

The root node of the parsed tree.

Source

fn code(&self) -> &[u8] ⓘ

The bytes the tree was parsed from (after macro expansion, for the C family).

Source

fn filters(&self, requested: &[String]) -> Filter<'_>

The returned Filter borrows self — the "function" and "string" predicates read the source bytes (#1162, #1381).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<T: 'static + LanguageInfo + Alterator + Checker + Getter> ParserTrait for Parser<T>