tytanic_filter/ast/
atom.rs1use super::Id;
2use super::Num;
3use super::Pat;
4use super::Str;
5use crate::eval::Context;
6use crate::eval::Error;
7use crate::eval::Eval;
8use crate::eval::Test;
9use crate::eval::Value;
10
11#[derive(Debug, Clone, PartialEq, Eq, Hash)]
13pub enum Atom {
14 Id(Id),
16
17 Num(Num),
19
20 Str(Str),
22
23 Pat(Pat),
25}
26
27impl<T: Test> Eval<T> for Atom {
28 fn eval(&self, ctx: &Context<T>) -> Result<Value<T>, Error> {
29 Ok(match self {
30 Self::Id(id) => id.eval(ctx)?,
31 Self::Num(n) => Value::Num(*n),
32 Self::Str(s) => Value::Str(s.clone()),
33 Self::Pat(pat) => pat.eval(ctx)?,
34 })
35 }
36}