refactor(xatu): rename binding AST node
This commit is contained in:
@@ -29,7 +29,7 @@ impl std::fmt::Display for SourceRange {
|
|||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub enum NodeData {
|
pub enum NodeData {
|
||||||
Apply(Apply),
|
Apply(Apply),
|
||||||
AttrpathValue(AttrpathValue),
|
Binding(Binding),
|
||||||
LetIn(LetIn),
|
LetIn(LetIn),
|
||||||
Inherit(Inherit),
|
Inherit(Inherit),
|
||||||
}
|
}
|
||||||
@@ -40,7 +40,7 @@ pub struct Apply {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct AttrpathValue {
|
pub struct Binding {
|
||||||
pub key: Ident,
|
pub key: Ident,
|
||||||
pub value: Ident,
|
pub value: Ident,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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> {
|
fn convert_node(node: rnix::SyntaxNode) -> Option<ast::Node> {
|
||||||
match node.kind() {
|
match node.kind() {
|
||||||
rnix::SyntaxKind::NODE_APPLY => convert_apply(node),
|
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_LET_IN => convert_let_in(node),
|
||||||
rnix::SyntaxKind::NODE_INHERIT => convert_inherit(node),
|
rnix::SyntaxKind::NODE_INHERIT => convert_inherit(node),
|
||||||
_ => None,
|
_ => None,
|
||||||
@@ -66,22 +66,22 @@ impl TryFrom<rnix::ast::Apply> for ast::Apply {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn convert_attrpath_value(node: rnix::SyntaxNode) -> Option<ast::Node> {
|
fn convert_binding(node: rnix::SyntaxNode) -> Option<ast::Node> {
|
||||||
let attrpath_value = rnix::ast::AttrpathValue::cast(node)?;
|
let binding = rnix::ast::AttrpathValue::cast(node)?;
|
||||||
let range = attrpath_value.syntax().text_range().into();
|
let range = binding.syntax().text_range().into();
|
||||||
let data = attrpath_value.try_into().ok()?;
|
let data = binding.try_into().ok()?;
|
||||||
|
|
||||||
Some(ast::Node {
|
Some(ast::Node {
|
||||||
range,
|
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 = ();
|
type Error = ();
|
||||||
|
|
||||||
fn try_from(attrpath_value: rnix::ast::AttrpathValue) -> Result<Self, Self::Error> {
|
fn try_from(binding: rnix::ast::AttrpathValue) -> Result<Self, Self::Error> {
|
||||||
let mut attrs = attrpath_value.attrpath().ok_or(())?.attrs();
|
let mut attrs = binding.attrpath().ok_or(())?.attrs();
|
||||||
let key = match attrs.next().ok_or(())? {
|
let key = match attrs.next().ok_or(())? {
|
||||||
Attr::Ident(ident) => ident.into(),
|
Attr::Ident(ident) => ident.into(),
|
||||||
_ => return Err(()),
|
_ => return Err(()),
|
||||||
@@ -91,7 +91,7 @@ impl TryFrom<rnix::ast::AttrpathValue> for ast::AttrpathValue {
|
|||||||
return Err(());
|
return Err(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let value = match attrpath_value.value().ok_or(())? {
|
let value = match binding.value().ok_or(())? {
|
||||||
rnix::ast::Expr::Ident(ident) => ident.into(),
|
rnix::ast::Expr::Ident(ident) => ident.into(),
|
||||||
_ => return Err(()),
|
_ => return Err(()),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,13 +3,13 @@ use crate::{ast, rules::NodeRule};
|
|||||||
pub struct ManualInherit;
|
pub struct ManualInherit;
|
||||||
|
|
||||||
impl NodeRule for ManualInherit {
|
impl NodeRule for ManualInherit {
|
||||||
type Node = ast::AttrpathValue;
|
type Node = ast::Binding;
|
||||||
|
|
||||||
const ID: &'static str = "manual_inherit";
|
const ID: &'static str = "manual_inherit";
|
||||||
|
|
||||||
fn select(data: &ast::NodeData) -> Option<&Self::Node> {
|
fn select(data: &ast::NodeData) -> Option<&Self::Node> {
|
||||||
match data {
|
match data {
|
||||||
ast::NodeData::AttrpathValue(attrpath_value) => Some(attrpath_value),
|
ast::NodeData::Binding(binding) => Some(binding),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user