use super::{Origin, Reference};
use crate::ValidationError;
use crate::interop::raw::AttrPath;
pub trait IntoNode {
fn into_node(self, origin: Origin) -> Node;
}
pub trait ReferencedExpression {
fn reference(&self) -> &Reference;
}
#[derive(Clone, Debug)]
pub struct Node {
pub origin: Origin,
pub kind: ValueKind,
}
impl Node {
pub fn validate(&self) -> Result<(), ValidationError> {
super::validation::validate_scoped(self, &[])
}
}
#[derive(Clone, Debug)]
pub enum ValueKind {
Bool(bool),
Int(i64),
Float(f64),
Null,
String(String),
List(Vec<Node>),
AttrSet(Vec<(String, Node)>),
OpaqueRecord(Vec<(String, Node)>),
Reference(Reference),
Apply(Box<Node>, Box<Node>),
AttrMerge(Box<Node>, Box<Node>),
Assert(Box<Node>, Box<Node>),
Select(Box<Node>, AttrPath),
Function {
binding: u64,
body: Box<Node>,
},
FunctionAttrs {
binding: u64,
arguments: Vec<String>,
defaults: Vec<(String, Node)>,
body: Box<Node>,
},
Parameter(u64),
If(Box<Node>, Box<Node>, Box<Node>),
Equal(Box<Node>, Box<Node>),
OptionReference(AttrPath),
ToText(Box<Node>),
StringPrefix {
prefix: String,
value: Box<Node>,
},
Divide(Box<Node>, Box<Node>),
InRange {
value: Box<Node>,
min: i64,
max: i64,
message: String,
},
}
#[derive(Clone, Debug)]
pub struct Assignment {
pub origin: Origin,
pub path: String,
pub value: Node,
pub(crate) segments: Vec<String>,
}
impl Assignment {
pub fn path_segments(&self) -> &[String] {
&self.segments
}
}