wagon_parser/parser/
conjunct.rs

1use std::fmt::Display;
2use crate::firstpass::{GetReqAttributes, ReqAttributes, RewriteToSynth};
3
4use super::{Parse, LexerBridge, ParseResult, Tokens, SpannableNode};
5use wagon_lexer::math::Math;
6
7use super::inverse::Inverse;
8
9use wagon_macros::new_unspanned;
10
11#[derive(PartialEq, Debug, Eq, Hash, Clone)]
12#[new_unspanned]
13/// A list of [`Inverse`] nodes. Separated by `||`.
14///
15/// # Grammar
16/// `Conjunct -> [Inverse] ("||" Conjunct)?;`
17pub struct Conjunct(pub Vec<SpannableNode<Inverse>>);
18
19impl GetReqAttributes for Conjunct {
20    fn get_req_attributes(&self) -> ReqAttributes {
21        let mut req = ReqAttributes::new();
22        for i in &self.0 {
23            req.extend(i.get_req_attributes());
24        }
25        req
26    }
27}
28
29impl RewriteToSynth for Conjunct {
30    fn rewrite_to_synth(&mut self) -> ReqAttributes {
31        let mut req = ReqAttributes::new();
32        for i in &mut self.0 {
33            req.extend(i.rewrite_to_synth());
34        }
35        req
36    }
37}
38
39impl Parse for Conjunct {
40    
41    fn parse(lexer: &mut LexerBridge) -> ParseResult<Self> where Self: Sized {
42        Ok(Self(SpannableNode::parse_sep(lexer, Tokens::MathToken(Math::Or))?))
43    }
44
45}
46
47impl Display for Conjunct {
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}