1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use quote::quote;

use crate::SpannableIdent;

use super::{Rc, ToTokensState};
use proc_macro2::{TokenStream, Ident};

use wagon_parser::parser::comp::{Comparison, CompOp};

impl<U> ToTokensState<U> for Comparison {
    fn to_tokens(&self, state: &mut U, label: Rc<Ident>, attr_fun: fn(&mut U, Rc<Ident>, SpannableIdent)) -> TokenStream {
        if let Some(comp_op) = &self.comp {
            let left = self.sum.to_tokens(state, label.clone(), attr_fun);
            let op  = &comp_op.op;
            let right = comp_op.right.to_tokens(state, label, attr_fun);
            if matches!(op, CompOp::In) {
                quote!(
                    wagon_value::Value::from((#left.contains(#right)))
                )
            } else {
                quote!(
                    wagon_value::Value::from((#left #op #right))
                )
            }
        } else {
            self.sum.to_tokens(state, label, attr_fun)
        }
    }
}