<commit_before>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

//! Types used to report parsing errors.

#![deny(missing_docs)]

use cssparser::{Parser, SourcePosition};
use log;
use stylesheets::UrlExtraData;

/// Errors that can be encountered while parsing CSS.
pub enum ParseError<'a> {
    /// A property declaration was not recognized.
    UnsupportedPropertyDeclaration(&'a str),
    /// A font face descriptor was not recognized.
    UnsupportedFontFaceDescriptor(&'a str),
    /// A keyframe rule was not valid.
    InvalidKeyframeRule(&'a str),
    /// A keyframe property declaration was not recognized.
    UnsupportedKeyframePropertyDeclaration(&'a str),
    /// A rule was invalid for some reason.
    InvalidRule(&'a str),
    /// A rule was not recognized.
    UnsupportedRule(&'a str),
    /// A viewport descriptor declaration was not recognized.
    UnsupportedViewportDescriptorDeclaration(&'a str),
    /// A counter style descriptor declaration was not recognized.
    UnsupportedCounterStyleDescriptorDeclaration(&'a str),
    /// A counter style rule had no symbols.
    InvalidCounterStyleWithoutSymbols(String),
    /// A counter style rule had less than two symbols.
    InvalidCounterStyleNotEnoughSymbols(String),
    /// A counter style rule did not have additive-symbols.
    InvalidCounterStyleWithoutAdditiveSymbols,
    /// A counter style rule had extends with symbols.
    InvalidCounterStyleExtendsWithSymbols,
    /// A counter style rule had extends with additive-symbols.
    InvalidCounterStyleExtendsWithAdditiveSymbols
}

impl<'a> ParseError<'a> {
    /// Turn a parse error into a string representation.
    pub fn to_string(&self) -> String {
        match *self {
            ParseError::UnsupportedPropertyDeclaration(decl) =>
                format!("Unsupported property declaration: '{}'", decl),
            ParseError::UnsupportedFontFaceDescriptor(decl) =>
                format!("Unsupported @font-face descriptor declaration: '{}'", decl),
            ParseError::InvalidKeyframeRule(rule) =>
                format!("Invalid keyframe rule: '{}'", rule),
            ParseError::UnsupportedKeyframePropertyDeclaration(decl) =>
                format!("Unsupported keyframe property declaration: '{}'", decl),
            ParseError::InvalidRule(rule) =>
                format!("Invalid rule: '{}'", rule),
            ParseError::UnsupportedRule(rule) =>
                format!("Unsupported rule: '{}'", rule),
            ParseError::UnsupportedViewportDescriptorDeclaration(decl) =>
                format!("Unsupported @viewport descriptor declaration: '{}'", decl),
            ParseError::UnsupportedCounterStyleDescriptorDeclaration(decl) =>
                format!("Unsupported @counter-style descriptor declaration: '{}'", decl),
            ParseError::InvalidCounterStyleWithoutSymbols(ref system) =>
                format!("Invalid @counter-style rule: 'system: {}' without 'symbols'", system),
            ParseError::InvalidCounterStyleNotEnoughSymbols(ref system) =>
                format!("Invalid @counter-style rule: 'system: {}' less than two 'symbols'", system),
            ParseError::InvalidCounterStyleWithoutAdditiveSymbols =>
                "Invalid @counter-style rule: 'system: additive' without 'additive-symbols'".into(),
            ParseError::InvalidCounterStyleExtendsWithSymbols =>
                "Invalid @counter-style rule: 'system: extends …' with 'symbols'".into(),
            ParseError::InvalidCounterStyleExtendsWithAdditiveSymbols =>
                "Invalid @counter-style rule: 'system: extends …' with 'additive-symbols'".into(),
        }
    }
}

/// A generic trait for an error reporter.
pub trait ParseErrorReporter : Sync + Send {
    /// Called when the style engine detects an error.
    ///
    /// Returns the current input being parsed, the source position it was
    /// reported from, and a message.
    fn report_error<'a>(&self,
                        input: &mut Parser,
                        position: SourcePosition,<commit_msg>The ParseErrorReporter trait no longer needs to be Send.<commit_after>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

//! Types used to report parsing errors.

#![deny(missing_docs)]

use cssparser::{Parser, SourcePosition};
use log;
use stylesheets::UrlExtraData;

/// Errors that can be encountered while parsing CSS.
pub enum ParseError<'a> {
    /// A property declaration was not recognized.
    UnsupportedPropertyDeclaration(&'a str),
    /// A font face descriptor was not recognized.
    UnsupportedFontFaceDescriptor(&'a str),
    /// A keyframe rule was not valid.
    InvalidKeyframeRule(&'a str),
    /// A keyframe property declaration was not recognized.
    UnsupportedKeyframePropertyDeclaration(&'a str),
    /// A rule was invalid for some reason.
    InvalidRule(&'a str),
    /// A rule was not recognized.
    UnsupportedRule(&'a str),
    /// A viewport descriptor declaration was not recognized.
    UnsupportedViewportDescriptorDeclaration(&'a str),
    /// A counter style descriptor declaration was not recognized.
    UnsupportedCounterStyleDescriptorDeclaration(&'a str),
    /// A counter style rule had no symbols.
    InvalidCounterStyleWithoutSymbols(String),
    /// A counter style rule had less than two symbols.
    InvalidCounterStyleNotEnoughSymbols(String),
    /// A counter style rule did not have additive-symbols.
    InvalidCounterStyleWithoutAdditiveSymbols,
    /// A counter style rule had extends with symbols.
    InvalidCounterStyleExtendsWithSymbols,
    /// A counter style rule had extends with additive-symbols.
    InvalidCounterStyleExtendsWithAdditiveSymbols
}

impl<'a> ParseError<'a> {
    /// Turn a parse error into a string representation.
    pub fn to_string(&self) -> String {
        match *self {
            ParseError::UnsupportedPropertyDeclaration(decl) =>
                format!("Unsupported property declaration: '{}'", decl),
            ParseError::UnsupportedFontFaceDescriptor(decl) =>
                format!("Unsupported @font-face descriptor declaration: '{}'", decl),
            ParseError::InvalidKeyframeRule(rule) =>
                format!("Invalid keyframe rule: '{}'", rule),
            ParseError::UnsupportedKeyframePropertyDeclaration(decl) =>
                format!("Unsupported keyframe property declaration: '{}'", decl),
            ParseError::InvalidRule(rule) =>
                format!("Invalid rule: '{}'", rule),
            ParseError::UnsupportedRule(rule) =>
                format!("Unsupported rule: '{}'", rule),
            ParseError::UnsupportedViewportDescriptorDeclaration(decl) =>
                format!("Unsupported @viewport descriptor declaration: '{}'", decl),
            ParseError::UnsupportedCounterStyleDescriptorDeclaration(decl) =>
                format!("Unsupported @counter-style descriptor declaration: '{}'", decl),
            ParseError::InvalidCounterStyleWithoutSymbols(ref system) =>
                format!("Invalid @counter-style rule: 'system: {}' without 'symbols'", system),
            ParseError::InvalidCounterStyleNotEnoughSymbols(ref system) =>
                format!("Invalid @counter-style rule: 'system: {}' less than two 'symbols'", system),
            ParseError::InvalidCounterStyleWithoutAdditiveSymbols =>
                "Invalid @counter-style rule: 'system: additive' without 'additive-symbols'".into(),
            ParseError::InvalidCounterStyleExtendsWithSymbols =>
                "Invalid @counter-style rule: 'system: extends …' with 'symbols'".into(),
            ParseError::InvalidCounterStyleExtendsWithAdditiveSymbols =>
                "Invalid @counter-style rule: 'system: extends …' with 'additive-symbols'".into(),
        }
    }
}

/// A generic trait for an error reporter.
pub trait ParseErrorReporter : Sync {
    /// Called when the style engine detects an error.
    ///
    /// Returns the current input being parsed, the source position it was
    /// reported from, and a message.
    fn report_error<'a>(&self,
                        input: &mut Parser,
                        position: SourcePosition,
{'fraction_non_alphanumeric': 0.10935285781766652, 'fraction_numerical': 0.000944733112895607, 'mean_word_length': 2.979793233082707, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6869404', 'n_tokens_mistral': 2096, 'n_tokens_neox': 2125, 'n_words': 648}