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

/// [FunctionReference](crate::ast::FunctionReference) ::= [Identifier](crate::ast::Identifier) [CallArguments](crate::ast::CallArguments)
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "hash", derive(Eq, PartialOrd, Ord, Hash))]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
pub struct FunctionReference {
    identifier: Identifier,
    call_arguments: CallArguments,
}

impl FunctionReference {
    /// Constructs a new `FunctionReference` representing a built-in or custom function call in Fluent.
    /// Functions are used for advanced formatting, such as `NUMBER(value, style: "percent")`
    /// or `DATETIME(date, month: "long")`.
    ///
    /// # Arguments
    /// * `identifier` - The name of the function (e.g., `NUMBER`, `PLATFORM`, or a custom function).
    /// * `call_arguments` - The arguments passed to the function, which may include positional
    ///   and/or named arguments.
    pub fn new(identifier: Identifier, call_arguments: CallArguments) -> Self {
        Self {
            identifier,
            call_arguments,
        }
    }

    /// Returns a reference to the function identifier.
    pub fn identifier(&self) -> &Identifier {
        &self.identifier
    }

    /// Returns the string name of the function identifier.
    ///
    /// This is equivalent to `self.identifier.to_string()` and is useful when serializing
    /// or displaying the function call.
    pub fn identifier_name(&self) -> String {
        self.identifier.to_string()
    }

    /// Returns a reference to the call arguments of this function reference.
    pub fn call_arguments(&self) -> &CallArguments {
        &self.call_arguments
    }
}

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

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