normalize_languages/
ninja.rs1use crate::{Import, Language, LanguageSymbols};
4use tree_sitter::Node;
5
6pub struct Ninja;
8
9impl Language for Ninja {
10 fn name(&self) -> &'static str {
11 "Ninja"
12 }
13 fn extensions(&self) -> &'static [&'static str] {
14 &["ninja"]
15 }
16 fn grammar_name(&self) -> &'static str {
17 "ninja"
18 }
19
20 fn as_symbols(&self) -> Option<&dyn LanguageSymbols> {
21 Some(self)
22 }
23
24 fn extract_imports(&self, node: &Node, content: &str) -> Vec<Import> {
25 match node.kind() {
26 "include" | "subninja" => {
27 let text = &content[node.byte_range()];
28 vec![Import {
29 module: text.trim().to_string(),
30 names: Vec::new(),
31 alias: None,
32 is_wildcard: false,
33 is_relative: false,
34 line: node.start_position().row + 1,
35 }]
36 }
37 _ => Vec::new(),
38 }
39 }
40
41 fn format_import(&self, import: &Import, _names: Option<&[&str]>) -> String {
42 format!("include {}", import.module)
44 }
45}
46
47impl LanguageSymbols for Ninja {}
48
49#[cfg(test)]
50mod tests {
51 use super::*;
52 use crate::validate_unused_kinds_audit;
53
54 #[test]
55 fn unused_node_kinds_audit() {
56 #[rustfmt::skip]
57 let documented_unused: &[&str] = &[
58 "manifest", "identifier", "body",
59 ];
60 validate_unused_kinds_audit(&Ninja, documented_unused)
61 .expect("Ninja unused node kinds audit failed");
62 }
63}