wagon_parser/parser/
disjunct.rs

1use std::{fmt::Display, write};
2
3use crate::firstpass::{GetReqAttributes, ReqAttributes, RewriteToSynth};
4
5use super::{Parse, LexerBridge, ParseResult, Tokens, SpannableNode};
6use wagon_lexer::math::Math;
7use super::conjunct::Conjunct;
8
9use wagon_macros::new_unspanned;
10
11#[derive(PartialEq, Debug, Eq, Hash, Clone)]
12#[new_unspanned]
13/// A list of [`Conjunct`] nodes, seperated by `&&`.
14///
15/// # Grammar
16/// `Disjunct -> [Conjunct] ("&&" Disjunct)?;`
17pub struct Disjunct(pub Vec<SpannableNode<Conjunct>>);
18
19impl GetReqAttributes for Disjunct {
20    fn get_req_attributes(&self) -> ReqAttributes {
21        let mut req = ReqAttributes::new();
22        for c in &self.0 {
23            req.extend(c.get_req_attributes());
24        }
25        req
26    }
27}
28
29impl RewriteToSynth for Disjunct {
30    fn rewrite_to_synth(&mut self) -> ReqAttributes {
31        let mut req = ReqAttributes::new();
32        for c in &mut self.0 {
33            req.extend(c.rewrite_to_synth());
34        }
35        req
36    }
37}
38
39impl Parse for Disjunct {
40    
41    fn parse(lexer: &mut LexerBridge) -> ParseResult<Self> where Self: Sized {
42        Ok(Self(SpannableNode::parse_sep(lexer, Tokens::MathToken(Math::And))?))
43    }
44
45}
46
47impl Display for Disjunct {
48    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
49        write!(f, "{}", self.0.iter().map(std::string::ToString::to_string).collect::<Vec<_>>().join(" && "))
50    }
51}