1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
use crate::SpannableIdent;

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

use wagon_parser::parser::factor::Factor;

impl<U> ToTokensState<U> for Factor {
    fn to_tokens(&self, state: &mut U, label: Rc<Ident>, attr_fun: fn(&mut U, Rc<Ident>, SpannableIdent)) -> TokenStream {
        match self {
            Self::Primary(p) => p.to_tokens(state, label, attr_fun),
            Self::Power { left, right } => {
                let left_stream = left.to_tokens(state, label.clone(), attr_fun);
                let right_stream = right.to_tokens(state, label, attr_fun);
                quote!(wagon_value::Pow::pow(#left_stream, #right_stream)?)
            },
        }
    }
}