phase_rs/normal_syntax/
mod.rs1pub mod term;
7pub use term::TermN;
8
9pub mod pattern;
10pub use pattern::PatternN;
11
12use crate::{
13 normal_syntax::term::AtomN,
14 typed_syntax::{PatternType, TermType},
15};
16
17pub trait Buildable {
19 fn comp(iter: impl DoubleEndedIterator<Item = Self>, ty: &TermType) -> Self;
22 fn tensor(iter: impl Iterator<Item = Self>) -> Self;
24 fn atom(atom: AtomN) -> Self;
26}
27
28impl Buildable for TermN {
29 fn comp(iter: impl DoubleEndedIterator<Item = Self>, ty: &TermType) -> Self {
30 TermN::Comp(iter.collect(), *ty)
31 }
32
33 fn tensor(iter: impl Iterator<Item = Self>) -> Self {
34 TermN::Tensor(iter.collect())
35 }
36
37 fn atom(atom: AtomN) -> Self {
38 TermN::Atom(atom)
39 }
40}
41
42impl Buildable for PatternN {
43 fn comp(iter: impl DoubleEndedIterator<Item = Self>, ty: &TermType) -> Self {
44 PatternN::Comp(iter.rev().collect(), PatternType(ty.0, ty.0))
45 }
46
47 fn tensor(iter: impl Iterator<Item = Self>) -> Self {
48 PatternN::Tensor(iter.collect())
49 }
50
51 fn atom(atom: AtomN) -> Self {
52 PatternN::Unitary(Box::new(atom))
53 }
54}