Skip to main content

normalize_languages/
asm.rs

1//! Assembly language support.
2
3use crate::{Import, Language, LanguageSymbols};
4use tree_sitter::Node;
5
6/// Assembly language support.
7pub struct Asm;
8
9impl Language for Asm {
10    fn name(&self) -> &'static str {
11        "Assembly"
12    }
13    fn extensions(&self) -> &'static [&'static str] {
14        &["asm", "s", "S"]
15    }
16    fn grammar_name(&self) -> &'static str {
17        "asm"
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        Vec::new() // asm grammar doesn't have imports
26    }
27
28    fn node_name<'a>(&self, node: &Node, content: &'a str) -> Option<&'a str> {
29        // Labels end with ':'
30        let text = &content[node.byte_range()];
31        let name = text.trim().trim_end_matches(':');
32        if !name.is_empty() { Some(name) } else { None }
33    }
34}
35
36impl LanguageSymbols for Asm {}
37
38#[cfg(test)]
39mod tests {
40    use super::*;
41    use crate::validate_unused_kinds_audit;
42
43    #[test]
44    fn unused_node_kinds_audit() {
45        #[rustfmt::skip]
46        let documented_unused: &[&str] = &[
47            // Asm instructions are too granular for symbol extraction
48            "instruction",
49            // Comments
50            "block_comment",
51        ];
52        validate_unused_kinds_audit(&Asm, documented_unused)
53            .expect("Assembly unused node kinds audit failed");
54    }
55}