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::{NumberLiteral, StringLiteral};
#[cfg(feature = "walker")]
use crate::walker::{Visitor, Walkable, Walker};

/// [Literal](crate::ast::Literal) ::= [NumberLiteral](crate::ast::NumberLiteral) | [StringLiteral](crate::ast::StringLiteral)
///
/// Note: This is not part of the fluent EBNF.
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "hash", derive(Eq, PartialOrd, Ord, Hash))]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
pub enum Literal {
    Number(NumberLiteral),
    String(StringLiteral),
}

impl From<NumberLiteral> for Literal {
    fn from(value: NumberLiteral) -> Self {
        Self::Number(value)
    }
}

impl From<StringLiteral> for Literal {
    fn from(value: StringLiteral) -> Self {
        Self::String(value)
    }
}

#[cfg(feature = "walker")]
impl Walkable for Literal {
    fn walk(&self, visitor: &mut dyn Visitor) {
        match self {
            Self::Number(literal) => Walker::walk(literal, visitor),
            Self::String(literal) => Walker::walk(literal, visitor),
        }
    }
}

impl std::fmt::Display for Literal {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        let value = match self {
            Self::Number(literal) => literal.to_string(),
            Self::String(literal) => literal.to_string(),
        };
        write!(f, "{value}")
    }
}