refactor(xatu): rename binding AST node

This commit is contained in:
2026-09-19 21:11:46 -04:00
parent b8961c1d37
commit f496993440
3 changed files with 14 additions and 14 deletions

View File

@@ -29,7 +29,7 @@ impl std::fmt::Display for SourceRange {
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum NodeData {
Apply(Apply),
AttrpathValue(AttrpathValue),
Binding(Binding),
LetIn(LetIn),
Inherit(Inherit),
}
@@ -40,7 +40,7 @@ pub struct Apply {
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct AttrpathValue {
pub struct Binding {
pub key: Ident,
pub value: Ident,
}

View File

@@ -38,7 +38,7 @@ fn convert_syntax(syntax: rnix::SyntaxNode) -> (Vec<ast::Node>, Vec<ast::Token>)
fn convert_node(node: rnix::SyntaxNode) -> Option<ast::Node> {
match node.kind() {
rnix::SyntaxKind::NODE_APPLY => convert_apply(node),
rnix::SyntaxKind::NODE_ATTRPATH_VALUE => convert_attrpath_value(node),
rnix::SyntaxKind::NODE_ATTRPATH_VALUE => convert_binding(node),
rnix::SyntaxKind::NODE_LET_IN => convert_let_in(node),
rnix::SyntaxKind::NODE_INHERIT => convert_inherit(node),
_ => None,
@@ -66,22 +66,22 @@ impl TryFrom<rnix::ast::Apply> for ast::Apply {
}
}
fn convert_attrpath_value(node: rnix::SyntaxNode) -> Option<ast::Node> {
let attrpath_value = rnix::ast::AttrpathValue::cast(node)?;
let range = attrpath_value.syntax().text_range().into();
let data = attrpath_value.try_into().ok()?;
fn convert_binding(node: rnix::SyntaxNode) -> Option<ast::Node> {
let binding = rnix::ast::AttrpathValue::cast(node)?;
let range = binding.syntax().text_range().into();
let data = binding.try_into().ok()?;
Some(ast::Node {
range,
data: ast::NodeData::AttrpathValue(data),
data: ast::NodeData::Binding(data),
})
}
impl TryFrom<rnix::ast::AttrpathValue> for ast::AttrpathValue {
impl TryFrom<rnix::ast::AttrpathValue> for ast::Binding {
type Error = ();
fn try_from(attrpath_value: rnix::ast::AttrpathValue) -> Result<Self, Self::Error> {
let mut attrs = attrpath_value.attrpath().ok_or(())?.attrs();
fn try_from(binding: rnix::ast::AttrpathValue) -> Result<Self, Self::Error> {
let mut attrs = binding.attrpath().ok_or(())?.attrs();
let key = match attrs.next().ok_or(())? {
Attr::Ident(ident) => ident.into(),
_ => return Err(()),
@@ -91,7 +91,7 @@ impl TryFrom<rnix::ast::AttrpathValue> for ast::AttrpathValue {
return Err(());
}
let value = match attrpath_value.value().ok_or(())? {
let value = match binding.value().ok_or(())? {
rnix::ast::Expr::Ident(ident) => ident.into(),
_ => return Err(()),
};

View File

@@ -3,13 +3,13 @@ use crate::{ast, rules::NodeRule};
pub struct ManualInherit;
impl NodeRule for ManualInherit {
type Node = ast::AttrpathValue;
type Node = ast::Binding;
const ID: &'static str = "manual_inherit";
fn select(data: &ast::NodeData) -> Option<&Self::Node> {
match data {
ast::NodeData::AttrpathValue(attrpath_value) => Some(attrpath_value),
ast::NodeData::Binding(binding) => Some(binding),
_ => None,
}
}