Thread ParseError return values through CSS parsing.

This commit is contained in:
Josh Matthews 2017-04-28 00:35:22 -04:00
parent 58e39bfffa
commit 27ae1ef2e7
121 changed files with 2133 additions and 1505 deletions

View file

@ -13,13 +13,15 @@ use computed_values::{font_feature_settings, font_stretch, font_style, font_weig
use computed_values::font_family::FamilyName;
use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser, Parser};
use cssparser::SourceLocation;
use error_reporting::ParseError;
use error_reporting::ContextualParseError;
#[cfg(feature = "gecko")] use gecko_bindings::structs::CSSFontFaceDescriptors;
#[cfg(feature = "gecko")] use cssparser::UnicodeRange;
use parser::{ParserContext, log_css_error, Parse};
use selectors::parser::SelectorParseError;
use shared_lock::{SharedRwLockReadGuard, ToCssWithGuard};
use std::borrow::Cow;
use std::fmt;
use style_traits::{ToCss, OneOrMoreCommaSeparated};
use style_traits::{ToCss, OneOrMoreCommaSeparated, ParseError, StyleParseError};
use values::specified::url::SpecifiedUrl;
/// A source for a font-face rule.
@ -98,9 +100,10 @@ pub fn parse_font_face_block(context: &ParserContext, input: &mut Parser, locati
};
let mut iter = DeclarationListParser::new(input, parser);
while let Some(declaration) = iter.next() {
if let Err(range) = declaration {
let pos = range.start;
let error = ParseError::UnsupportedFontFaceDescriptor(iter.input.slice(range));
if let Err(err) = declaration {
let pos = err.span.start;
let error = ContextualParseError::UnsupportedFontFaceDescriptor(
iter.input.slice(err.span), err.error);
log_css_error(iter.input, pos, error, context);
}
}
@ -154,13 +157,15 @@ struct FontFaceRuleParser<'a, 'b: 'a> {
}
/// Default methods reject all at rules.
impl<'a, 'b> AtRuleParser for FontFaceRuleParser<'a, 'b> {
impl<'a, 'b, 'i> AtRuleParser<'i> for FontFaceRuleParser<'a, 'b> {
type Prelude = ();
type AtRule = ();
type Error = SelectorParseError<'i, StyleParseError<'i>>;
}
impl Parse for Source {
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Source, ()> {
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<Source, ParseError<'i>> {
if input.try(|input| input.expect_function_matching("local")).is_ok() {
return input.parse_nested_block(|input| {
FamilyName::parse(context, input)
@ -247,11 +252,13 @@ macro_rules! font_face_descriptors_common {
}
}
impl<'a, 'b> DeclarationParser for FontFaceRuleParser<'a, 'b> {
type Declaration = ();
impl<'a, 'b, 'i> DeclarationParser<'i> for FontFaceRuleParser<'a, 'b> {
type Declaration = ();
type Error = SelectorParseError<'i, StyleParseError<'i>>;
fn parse_value(&mut self, name: &str, input: &mut Parser) -> Result<(), ()> {
match_ignore_ascii_case! { name,
fn parse_value<'t>(&mut self, name: Cow<'i, str>, input: &mut Parser<'i, 't>)
-> Result<(), ParseError<'i>> {
match_ignore_ascii_case! { &*name,
$(
$name => {
// DeclarationParser also calls parse_entirely
@ -262,7 +269,7 @@ macro_rules! font_face_descriptors_common {
self.rule.$ident = Some(value)
}
)*
_ => return Err(())
_ => return Err(SelectorParseError::UnexpectedIdent(name.clone()).into())
}
Ok(())
}