Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/third_party/rust/fluent-bundle/src/resolver/   (Firefox Browser Version 153.0.1©)  Datei vom 27.6.2026 mit Größe 3 kB image not shown  

Quelle  errors.rs   Sprache: Rust

 

use fluent_syntax::ast::InlineExpression;
use std::error::Error;

/// Maps an [`InlineExpression`] into the kind of reference, with owned strings
/// that identify the expression. This makes it so that the [`InlineExpression`] can
/// be used to generate an error string.
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum ReferenceKind {
    Function {
        id: String,
    },
    Message {
        id: String,
        attribute: Option<String>,
    },
    Term {
        id: String,
        attribute: Option<String>,
    },
    Variable {
        id: String,
    },
}

impl<T> From<&InlineExpression<T>> for ReferenceKind
where
    T: ToString,
{
    fn from(exp: &InlineExpression<T>) -> Self {
        match exp {
            InlineExpression::FunctionReference { id, .. } => Self::Function {
                id: id.name.to_string(),
            },
            InlineExpression::MessageReference { id, attribute } => Self::Message {
                id: id.name.to_string(),
                attribute: attribute.as_ref().map(|i| i.name.to_string()),
            },
            InlineExpression::TermReference { id, attribute, .. } => Self::Term {
                id: id.name.to_string(),
                attribute: attribute.as_ref().map(|i| i.name.to_string()),
            },
            InlineExpression::VariableReference { id, .. } => Self::Variable {
                id: id.name.to_string(),
            },
            _ => unreachable!(),
        }
    }
}

/// Errors generated during the process of resolving a fluent message into a string.
/// This process takes place in the `write` method of the `WriteValue` trait.
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum ResolverError {
    Reference(ReferenceKind),
    NoValue(String),
    MissingDefault,
    Cyclic,
    TooManyPlaceables,
}

impl std::fmt::Display for ResolverError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::Reference(exp) => match exp {
                ReferenceKind::Function { id } => write!(f, "Unknown function: {}()", id),
                ReferenceKind::Message {
                    id,
                    attribute: None,
                } => write!(f, "Unknown message: {}", id),
                ReferenceKind::Message {
                    id,
                    attribute: Some(attribute),
                } => write!(f, "Unknown attribute: {}.{}", id, attribute),
                ReferenceKind::Term {
                    id,
                    attribute: None,
                } => write!(f, "Unknown term: -{}", id),
                ReferenceKind::Term {
                    id,
                    attribute: Some(attribute),
                } => write!(f, "Unknown attribute: -{}.{}", id, attribute),
                ReferenceKind::Variable { id } => write!(f, "Unknown variable: ${}", id),
            },
            Self::NoValue(id) => write!(f, "No value: {}", id),
            Self::MissingDefault => f.write_str("No default"),
            Self::Cyclic => f.write_str("Cyclical dependency detected"),
            Self::TooManyPlaceables => f.write_str("Too many placeables"),
        }
    }
}

impl<T> From<&InlineExpression<T>> for ResolverError
where
    T: ToString,
{
    fn from(exp: &InlineExpression<T>) -> Self {
        Self::Reference(exp.into())
    }
}

impl Error for ResolverError {}

Messung V0.5 in Prozent
C=96 H=100 G=97

¤ Dauer der Verarbeitung: 0.9 Sekunden  (vorverarbeitet am  2026-09-29) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.