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
30
31
32
33
34
35
36
37
38
39
40
41
//! Contains types related to parsing adjuncts.

use crate::{
    category::Stress,
    gloss::{GlossFlags, GlossStatic},
    prelude::{IntoTokens, IntoTokensFlags, TokenList},
    romanize::{
        flags::FromTokenFlags,
        stream::{ParseError, TokenStream},
        token::GlottalStop,
        traits::FromTokens,
    },
};

/// A parsing adjunct.
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub struct ParsingAdjunct {
    /// The stress indicated by this adjunct.
    pub stress: Stress,
}

impl GlossStatic for ParsingAdjunct {
    fn gloss_static(&self, flags: GlossFlags) -> &'static str {
        self.stress.gloss_static(flags)
    }
}

impl FromTokens for ParsingAdjunct {
    fn parse_volatile(stream: &mut TokenStream, flags: FromTokenFlags) -> Result<Self, ParseError> {
        let stress = stream.parse(flags)?;
        let _: GlottalStop = stream.next().ok_or(ParseError::ExpectedGlottalStop)?;
        Ok(ParsingAdjunct { stress })
    }
}

impl IntoTokens for ParsingAdjunct {
    fn append_to(&self, list: &mut TokenList, _flags: IntoTokensFlags) {
        list.push(self.stress);
        list.push(GlottalStop);
    }
}