1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Per-language metric and AST modules deliberately consume the macro-
// generated tree-sitter token enums via `use crate::*` and `use Foo::*`
// inside match expressions — explicit imports would list dozens of
// variants per arm and obscure the per-language token sets that are the
// point of these files. Allowed at the module level rather than per
// function so the per-language impl blocks stay readable.
#![allow(clippy::wildcard_imports, clippy::enum_glob_use)]
use std::path::Path;
use std::sync::Arc;
use crate::abc::Abc;
use crate::alterator::Alterator;
use crate::checker::Checker;
use crate::cognitive::Cognitive;
use crate::cyclomatic::Cyclomatic;
use crate::getter::Getter;
use crate::halstead::Halstead;
use crate::langs::*;
use crate::loc::Loc;
use crate::mi::Mi;
use crate::nargs::NArgs;
use crate::nexits::Exit;
use crate::node::Ancestors;
use crate::node::Node;
use crate::nom::Nom;
use crate::npa::Npa;
use crate::npm::Npm;
use crate::parser::Filter;
use crate::preproc::PreprocResults;
use crate::tokens::Tokens;
use crate::wmc::Wmc;
/// Static identification of a language code tag.
///
/// Implemented by every `XxxCode` type generated by the internal
/// `mk_code!` macro. Crate-internal: reached only through the
/// `pub(crate)` `Parser<T>` plumbing behind the [`crate::Ast`] seam.
pub(crate) trait LanguageInfo {
/// Tree-sitter base language enum carried by this code tag.
type BaseLang;
/// Returns the workspace-level [`LANG`] variant for this code tag.
fn lang() -> LANG;
}
// Internal language-dispatch trait reached only by the macro-generated
// `Parser<T>` impls in `src/parser.rs` and the `AstInner` dispatch in
// `src/macros/mod.rs`. The 15 associated types are not part of any
// documented extension contract — metric extraction is driven through
// the public [`crate::Ast`] / [`crate::analyze`] seam, not by
// implementing this trait. See STABILITY.md.
pub(crate) trait ParserTrait {
type Checker: Alterator + Checker;
type Getter: Getter;
type Cognitive: Cognitive;
type Cyclomatic: Cyclomatic;
type Halstead: Halstead;
type Loc: Loc;
type Nom: Nom;
type Mi: Mi;
type NArgs: NArgs;
type Exit: Exit;
type Wmc: Wmc;
type Abc: Abc;
type Npm: Npm;
type Npa: Npa;
type Tokens: Tokens;
fn new(code: Vec<u8>, path: &Path, pr: Option<Arc<PreprocResults>>) -> Self;
fn root(&self) -> Node<'_>;
fn code(&self) -> &[u8];
/// The returned [`Filter`] borrows `self` — the `"function"`
/// predicate reads the source bytes (#1162).
fn filters(&self, requested: &[String]) -> Filter<'_>;
}
pub(crate) trait Search<'a> {
/// Visits every node of the subtree in source order, handing the
/// action each node's ancestor chain alongside it so a predicate it
/// applies stays off `Node::parent` (#1088).
fn act_on_node(&self, action: &mut dyn FnMut(&Node<'a>, Ancestors<'a, '_>));
fn first_child(&self, pred: fn(u16) -> bool) -> Option<Node<'a>>;
fn act_on_child(&self, action: &mut dyn FnMut(&Node<'a>));
}