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

/// [VariableReference](crate::ast::VariableReference) ::= "$" [Identifier](crate::ast::Identifier)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "hash", derive(Eq, PartialOrd, Ord, Hash))]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
pub struct VariableReference(Identifier);

impl VariableReference {
    /// Returns a reference to the underlying identifier of this variable reference.
    ///
    /// The identifier is the name without the leading `$` sigil.
    pub fn identifier(&self) -> &Identifier {
        &self.0
    }

    /// Returns the string representation of this variable reference as it appears in Fluent source,
    /// including the leading dollar sign (e.g., `$count`, `$userName`).
    ///
    /// This is useful when serializing, pretty-printing, or displaying the reference.
    pub fn identifier_name(&self) -> String {
        format!("${}", self.0)
    }
}

impl From<Identifier> for VariableReference {
    fn from(value: Identifier) -> Self {
        Self(value)
    }
}

#[cfg(feature = "walker")]
impl Walkable for VariableReference {
    fn walk(&self, visitor: &mut dyn Visitor) {
        visitor.visit_variable_reference(self);
        Walker::walk(&self.0, visitor);
    }
}

impl std::fmt::Display for VariableReference {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "${}", self.0)
    }
}