fluent4rs 2.3.1

Parser / codec for [Fluent FTL files](https://github.com/projectfluent/fluent/blob/master/spec/fluent.ebnf), written for [lingora](https://github.com/nigeleke/lingora) (a localization management program), and may be found to be useful outside of that context. It is not intended to replace any aspects of the [fluent-rs](https://github.com/projectfluent/fluent-rs) crate implemented by [Project Fluent](https://projectfluent.org/), and, for the majority of language translation needs, the reader is referred back to that crate.
Documentation
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

use super::{BlockPlaceable, BlockText, InlinePlaceable, InlineText};
#[cfg(feature = "walker")]
use crate::walker::{Visitor, Walkable, Walker};

/// [PatternElement](crate::ast::PatternElement) ::= [inline_text](crate::ast::InlineText)
///  | [block_text](crate::ast::BlockText)
///  | inline_placeable
///  | block_placeable
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "hash", derive(Eq, PartialOrd, Ord, Hash))]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
pub enum PatternElement {
    #[doc(hidden)]
    InlineText(InlineText),

    #[doc(hidden)]
    BlockText(BlockText),

    #[doc(hidden)]
    InlinePlaceable(InlinePlaceable),

    #[doc(hidden)]
    BlockPlaceable(BlockPlaceable),
}

#[cfg(feature = "walker")]
impl Walkable for PatternElement {
    fn walk(&self, visitor: &mut dyn Visitor) {
        visitor.visit_pattern_element(self);
        match self {
            Self::InlineText(_text) => {}
            Self::BlockText(_block) => {}
            Self::InlinePlaceable(text) => Walker::walk(text, visitor),
            Self::BlockPlaceable(block) => Walker::walk(block, visitor),
        }
    }
}

impl std::fmt::Display for PatternElement {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        let value = match self {
            Self::InlineText(text) => text.to_string(),
            Self::BlockText(block) => block.to_string(),
            Self::InlinePlaceable(text) => text.to_string(),
            Self::BlockPlaceable(block) => block.to_string(),
        };
        write!(f, "{value}")
    }
}