use crate::{ContainerBody, Language, LanguageSymbols};
use tree_sitter::Node;
pub struct Kdl;
impl Language for Kdl {
fn name(&self) -> &'static str {
"KDL"
}
fn extensions(&self) -> &'static [&'static str] {
&["kdl"]
}
fn grammar_name(&self) -> &'static str {
"kdl"
}
fn as_symbols(&self) -> Option<&dyn LanguageSymbols> {
Some(self)
}
fn container_body<'a>(&self, node: &'a Node<'a>) -> Option<Node<'a>> {
let mut c = node.walk();
for child in node.children(&mut c) {
if child.kind() == "node_no_terminator" {
return child.child_by_field_name("children");
}
}
None
}
fn analyze_container_body(
&self,
body_node: &Node,
content: &str,
inner_indent: &str,
) -> Option<ContainerBody> {
crate::body::analyze_brace_body(body_node, content, inner_indent)
}
fn node_name<'a>(&self, node: &Node, content: &'a str) -> Option<&'a str> {
let mut cursor = node.walk();
for child in node.children(&mut cursor) {
if child.kind() == "identifier" || child.kind() == "string" {
return Some(&content[child.byte_range()]);
}
}
None
}
}
impl LanguageSymbols for Kdl {}
#[cfg(test)]
mod tests {
use super::*;
use crate::validate_unused_kinds_audit;
#[test]
fn unused_node_kinds_audit() {
#[rustfmt::skip]
let documented_unused: &[&str] = &[
"annotation_type", "identifier_string", "multi_line_string_body", "type", ];
validate_unused_kinds_audit(&Kdl, documented_unused)
.expect("KDL unused node kinds audit failed");
}
}