Skip to main content

normalize_languages/
dot.rs

1//! DOT/Graphviz language support.
2
3use crate::{ContainerBody, Language, LanguageSymbols};
4use tree_sitter::Node;
5
6/// DOT (Graphviz) language support.
7pub struct Dot;
8
9impl Language for Dot {
10    fn name(&self) -> &'static str {
11        "DOT"
12    }
13    fn extensions(&self) -> &'static [&'static str] {
14        &["dot", "gv"]
15    }
16    fn grammar_name(&self) -> &'static str {
17        "dot"
18    }
19
20    fn as_symbols(&self) -> Option<&dyn LanguageSymbols> {
21        Some(self)
22    }
23
24    fn container_body<'a>(&self, node: &'a Node<'a>) -> Option<Node<'a>> {
25        node.child_by_field_name("body")
26    }
27
28    fn analyze_container_body(
29        &self,
30        body_node: &Node,
31        content: &str,
32        inner_indent: &str,
33    ) -> Option<ContainerBody> {
34        crate::body::analyze_brace_body(body_node, content, inner_indent)
35    }
36
37    fn node_name<'a>(&self, node: &Node, content: &'a str) -> Option<&'a str> {
38        node.child_by_field_name("name")
39            .or_else(|| node.child_by_field_name("id"))
40            .map(|n| &content[n.byte_range()])
41    }
42}
43
44impl LanguageSymbols for Dot {}
45
46#[cfg(test)]
47mod tests {
48    use super::*;
49    use crate::validate_unused_kinds_audit;
50
51    #[test]
52    fn unused_node_kinds_audit() {
53        #[rustfmt::skip]
54        let documented_unused: &[&str] = &[
55            "block",      // Statement block (body)
56            "identifier", // Node/edge identifiers
57            "operator",   // Edge operators (-> or --)
58        ];
59        validate_unused_kinds_audit(&Dot, documented_unused)
60            .expect("DOT unused node kinds audit failed");
61    }
62}