feat(xatu): add manual inherit rules
This commit is contained in:
@@ -38,6 +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_assignment(node),
|
||||
rnix::SyntaxKind::NODE_LET_IN => convert_let_in(node),
|
||||
rnix::SyntaxKind::NODE_INHERIT => convert_inherit(node),
|
||||
_ => None,
|
||||
@@ -65,6 +66,41 @@ impl TryFrom<rnix::ast::Apply> for ast::Apply {
|
||||
}
|
||||
}
|
||||
|
||||
fn convert_assignment(node: rnix::SyntaxNode) -> Option<ast::Node> {
|
||||
let assignment = rnix::ast::AttrpathValue::cast(node)?;
|
||||
let range = assignment.syntax().text_range().into();
|
||||
let data = assignment.try_into().ok()?;
|
||||
|
||||
Some(ast::Node {
|
||||
range,
|
||||
data: ast::NodeData::Assignment(data),
|
||||
})
|
||||
}
|
||||
|
||||
impl TryFrom<rnix::ast::AttrpathValue> for ast::Assignment {
|
||||
type Error = ();
|
||||
|
||||
fn try_from(assignment: rnix::ast::AttrpathValue) -> Result<Self, Self::Error> {
|
||||
let mut attrs = assignment.attrpath().ok_or(())?.attrs();
|
||||
let rnix::ast::Attr::Ident(name) = attrs.next().ok_or(())? else {
|
||||
return Err(());
|
||||
};
|
||||
if attrs.next().is_some() {
|
||||
return Err(());
|
||||
}
|
||||
|
||||
let value = assignment.value().ok_or(())?;
|
||||
if matches!(&value, rnix::ast::Expr::Select(select) if select.or_token().is_some()) {
|
||||
return Err(());
|
||||
}
|
||||
|
||||
Ok(Self {
|
||||
name: name.into(),
|
||||
value: value.try_into()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<rnix::ast::Expr> for ast::Expr {
|
||||
type Error = ();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user