Update to cssparser 0.22 (source location in error types)

This commit is contained in:
Simon Sapin 2017-09-29 21:18:35 +02:00
parent 056e599562
commit c0f8f15f39
90 changed files with 974 additions and 790 deletions

View file

@ -8,7 +8,7 @@
use cssparser::Parser;
use parser::{Parse, ParserContext};
use std::{fmt, mem, usize};
use style_traits::{ToCss, ParseError, StyleParseError};
use style_traits::{ToCss, ParseError, StyleParseErrorKind};
use values::{CSSFloat, CustomIdent, serialize_dimension};
use values::computed::{Context, ToComputedValue};
use values::specified;
@ -88,9 +88,10 @@ impl Parse for GridLine<specified::Integer> {
let mut val_before_span = false;
for _ in 0..3 { // Maximum possible entities for <grid-line>
let location = input.current_source_location();
if input.try(|i| i.expect_ident_matching("span")).is_ok() {
if grid_line.is_span {
return Err(StyleParseError::UnspecifiedError.into())
return Err(location.new_custom_error(StyleParseErrorKind::UnspecifiedError))
}
if grid_line.line_num.is_some() || grid_line.ident.is_some() {
@ -101,31 +102,31 @@ impl Parse for GridLine<specified::Integer> {
} else if let Ok(i) = input.try(|i| specified::Integer::parse(context, i)) {
// FIXME(emilio): Probably shouldn't reject if it's calc()...
if i.value() == 0 || val_before_span || grid_line.line_num.is_some() {
return Err(StyleParseError::UnspecifiedError.into())
return Err(location.new_custom_error(StyleParseErrorKind::UnspecifiedError))
}
grid_line.line_num = Some(i);
} else if let Ok(name) = input.try(|i| i.expect_ident_cloned()) {
if val_before_span || grid_line.ident.is_some() {
return Err(StyleParseError::UnspecifiedError.into());
return Err(location.new_custom_error(StyleParseErrorKind::UnspecifiedError));
}
grid_line.ident = Some(CustomIdent::from_ident(&name, &[])?);
grid_line.ident = Some(CustomIdent::from_ident(location, &name, &[])?);
} else {
break
}
}
if grid_line.is_auto() {
return Err(StyleParseError::UnspecifiedError.into())
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
}
if grid_line.is_span {
if let Some(i) = grid_line.line_num {
if i.value() <= 0 { // disallow negative integers for grid spans
return Err(StyleParseError::UnspecifiedError.into())
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
}
} else if grid_line.ident.is_none() { // integer could be omitted
return Err(StyleParseError::UnspecifiedError.into())
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
}
}
@ -369,7 +370,7 @@ impl Parse for RepeatCount<specified::Integer> {
}
Ok(RepeatCount::Number(i))
} else {
try_match_ident_ignore_ascii_case! { input.expect_ident()?,
try_match_ident_ignore_ascii_case! { input,
"auto-fill" => Ok(RepeatCount::AutoFill),
"auto-fit" => Ok(RepeatCount::AutoFit),
}
@ -612,14 +613,14 @@ impl Parse for LineNameList {
RepeatCount::AutoFill if fill_idx.is_none() => {
// `repeat(autof-fill, ..)` should have just one line name.
if names_list.len() != 1 {
return Err(StyleParseError::UnspecifiedError.into());
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError));
}
let names = names_list.pop().unwrap();
line_names.push(names);
fill_idx = Some(line_names.len() as u32 - 1);
},
_ => return Err(StyleParseError::UnspecifiedError.into()),
_ => return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError)),
}
} else if let Ok(names) = input.try(parse_line_names) {
line_names.push(names);

View file

@ -9,7 +9,7 @@ use counter_style::{Symbols, parse_counter_style_name};
use cssparser::Parser;
use parser::{Parse, ParserContext};
use std::fmt;
use style_traits::{Comma, OneOrMoreSeparated, ParseError, StyleParseError, ToCss};
use style_traits::{Comma, OneOrMoreSeparated, ParseError, StyleParseErrorKind, ToCss};
use super::CustomIdent;
pub mod background;
@ -114,16 +114,16 @@ impl Parse for CounterStyleOrNone {
// numeric system.
if (symbols_type == SymbolsType::Alphabetic ||
symbols_type == SymbolsType::Numeric) && symbols.0.len() < 2 {
return Err(StyleParseError::UnspecifiedError.into());
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError));
}
// Identifier is not allowed in symbols() function.
if symbols.0.iter().any(|sym| !sym.is_allowed_in_symbols()) {
return Err(StyleParseError::UnspecifiedError.into());
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError));
}
Ok(CounterStyleOrNone::Symbols(symbols_type, symbols))
});
}
Err(StyleParseError::UnspecifiedError.into())
Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
}
}
@ -170,13 +170,14 @@ impl<T: Parse> Parse for FontSettingTag<T> {
let u_tag;
{
let location = input.current_source_location();
let tag = input.expect_string()?;
// allowed strings of length 4 containing chars: <U+20, U+7E>
if tag.len() != 4 ||
tag.chars().any(|c| c < ' ' || c > '~')
{
return Err(StyleParseError::UnspecifiedError.into())
return Err(location.new_custom_error(StyleParseErrorKind::UnspecifiedError))
}
let mut raw = Cursor::new(tag.as_bytes());
@ -248,7 +249,7 @@ impl Parse for FontSettingTagInt {
if value >= 0 {
Ok(FontSettingTagInt(value as u32))
} else {
Err(StyleParseError::UnspecifiedError.into())
Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
}
} else if let Ok(_) = input.try(|input| input.expect_ident_matching("on")) {
// on is an alias for '1'

View file

@ -7,7 +7,7 @@
use cssparser::Parser;
use parser::{Parse, ParserContext};
use std::fmt;
use style_traits::{ParseError, StyleParseError, ToCss};
use style_traits::{ParseError, StyleParseErrorKind, ToCss};
use values::{Either, None_};
use values::computed::NumberOrPercentage;
use values::computed::length::LengthOrPercentage;
@ -54,7 +54,7 @@ pub enum SVGPaintKind<ColorType, UrlPaintServer> {
impl<ColorType, UrlPaintServer> SVGPaintKind<ColorType, UrlPaintServer> {
/// Parse a keyword value only
fn parse_ident<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
try_match_ident_ignore_ascii_case! { input.expect_ident()?,
try_match_ident_ignore_ascii_case! { input,
"none" => Ok(SVGPaintKind::None),
"context-fill" => Ok(SVGPaintKind::ContextFill),
"context-stroke" => Ok(SVGPaintKind::ContextStroke),
@ -104,7 +104,7 @@ impl<ColorType: Parse, UrlPaintServer: Parse> Parse for SVGPaint<ColorType, UrlP
fallback: None,
})
} else {
Err(StyleParseError::UnspecifiedError.into())
Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
}
}
}
@ -189,7 +189,7 @@ impl <LengthOrPercentageType: Parse, NumberType: Parse> Parse for
if let Ok(lop) = input.try(|i| LengthOrPercentageType::parse(context, i)) {
return Ok(SvgLengthOrPercentageOrNumber::LengthOrPercentage(lop));
}
Err(StyleParseError::UnspecifiedError.into())
Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
}
}

View file

@ -9,13 +9,13 @@
#![deny(missing_docs)]
use Atom;
pub use cssparser::{RGBA, Token, Parser, serialize_identifier, BasicParseError, CowRcStr};
pub use cssparser::{RGBA, Token, Parser, serialize_identifier, CowRcStr, SourceLocation};
use parser::{Parse, ParserContext};
use selectors::parser::SelectorParseError;
use selectors::parser::SelectorParseErrorKind;
use std::ascii::AsciiExt;
use std::fmt::{self, Debug};
use std::hash;
use style_traits::{ToCss, ParseError, StyleParseError};
use style_traits::{ToCss, ParseError, StyleParseErrorKind};
pub mod animated;
pub mod computed;
@ -57,9 +57,9 @@ pub enum Impossible {}
impl Parse for Impossible {
fn parse<'i, 't>(
_context: &ParserContext,
_input: &mut Parser<'i, 't>)
input: &mut Parser<'i, 't>)
-> Result<Self, ParseError<'i>> {
Err(StyleParseError::UnspecifiedError.into())
Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
}
}
@ -103,16 +103,17 @@ pub struct CustomIdent(pub Atom);
impl CustomIdent {
/// Parse an already-tokenizer identifier
pub fn from_ident<'i>(ident: &CowRcStr<'i>, excluding: &[&str]) -> Result<Self, ParseError<'i>> {
pub fn from_ident<'i>(location: SourceLocation, ident: &CowRcStr<'i>, excluding: &[&str])
-> Result<Self, ParseError<'i>> {
let valid = match_ignore_ascii_case! { ident,
"initial" | "inherit" | "unset" | "default" => false,
_ => true
};
if !valid {
return Err(SelectorParseError::UnexpectedIdent(ident.clone()).into());
return Err(location.new_custom_error(SelectorParseErrorKind::UnexpectedIdent(ident.clone())));
}
if excluding.iter().any(|s| ident.eq_ignore_ascii_case(s)) {
Err(StyleParseError::UnspecifiedError.into())
Err(location.new_custom_error(StyleParseErrorKind::UnspecifiedError))
} else {
Ok(CustomIdent(Atom::from(ident.as_ref())))
}
@ -139,7 +140,8 @@ pub enum KeyframesName {
impl KeyframesName {
/// https://drafts.csswg.org/css-animations/#dom-csskeyframesrule-name
pub fn from_ident(value: &str) -> Self {
let custom_ident = CustomIdent::from_ident(&value.into(), &["none"]).ok();
let location = SourceLocation { line: 0, column: 0 };
let custom_ident = CustomIdent::from_ident(location, &value.into(), &["none"]).ok();
match custom_ident {
Some(ident) => KeyframesName::Ident(ident),
None => KeyframesName::QuotedString(value.into()),
@ -182,10 +184,11 @@ impl hash::Hash for KeyframesName {
impl Parse for KeyframesName {
fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
let location = input.current_source_location();
match input.next() {
Ok(&Token::Ident(ref s)) => Ok(KeyframesName::Ident(CustomIdent::from_ident(s, &["none"])?)),
Ok(&Token::Ident(ref s)) => Ok(KeyframesName::Ident(CustomIdent::from_ident(location, s, &["none"])?)),
Ok(&Token::QuotedString(ref s)) => Ok(KeyframesName::QuotedString(Atom::from(s.as_ref()))),
Ok(t) => Err(BasicParseError::UnexpectedToken(t.clone()).into()),
Ok(t) => Err(location.new_unexpected_token_error(t.clone())),
Err(e) => Err(e.into()),
}
}

View file

@ -9,10 +9,10 @@
use cssparser::Parser;
use gecko_bindings::structs;
use parser::{Parse, ParserContext};
use selectors::parser::SelectorParseError;
use selectors::parser::SelectorParseErrorKind;
use std::ascii::AsciiExt;
use std::fmt;
use style_traits::{ToCss, ParseError, StyleParseError};
use style_traits::{ToCss, ParseError, StyleParseErrorKind};
bitflags! {
/// Constants shared by multiple CSS Box Alignment properties
@ -201,7 +201,7 @@ impl Parse for AlignJustifyContent {
}
return Ok(AlignJustifyContent::new(fallback))
}
Err(StyleParseError::UnspecifiedError.into())
Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
}
}
@ -239,7 +239,7 @@ impl Parse for AlignJustifySelf {
if let Ok(value) = input.try(parse_overflow_self_position) {
return Ok(AlignJustifySelf(value))
}
Err(StyleParseError::UnspecifiedError.into())
Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
}
}
@ -277,7 +277,7 @@ impl Parse for AlignItems {
if let Ok(value) = input.try(parse_overflow_self_position) {
return Ok(AlignItems(value))
}
Err(StyleParseError::UnspecifiedError.into())
Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
}
}
@ -326,7 +326,7 @@ impl Parse for JustifyItems {
if let Ok(value) = parse_overflow_self_position(input) {
return Ok(JustifyItems(value))
}
Err(StyleParseError::UnspecifiedError.into())
Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
}
}
@ -351,7 +351,7 @@ fn parse_auto_normal_stretch_baseline<'i, 't>(input: &mut Parser<'i, 't>)
return Ok(baseline);
}
try_match_ident_ignore_ascii_case! { input.expect_ident()?,
try_match_ident_ignore_ascii_case! { input,
"auto" => Ok(ALIGN_AUTO),
"normal" => Ok(ALIGN_NORMAL),
"stretch" => Ok(ALIGN_STRETCH),
@ -364,7 +364,7 @@ fn parse_normal_stretch_baseline<'i, 't>(input: &mut Parser<'i, 't>) -> Result<A
return Ok(baseline);
}
try_match_ident_ignore_ascii_case! { input.expect_ident()?,
try_match_ident_ignore_ascii_case! { input,
"normal" => Ok(ALIGN_NORMAL),
"stretch" => Ok(ALIGN_STRETCH),
}
@ -383,7 +383,7 @@ fn parse_normal_or_baseline<'i, 't>(input: &mut Parser<'i, 't>) -> Result<AlignF
// <baseline-position>
fn parse_baseline<'i, 't>(input: &mut Parser<'i, 't>) -> Result<AlignFlags, ParseError<'i>> {
// FIXME: remove clone() when lifetimes are non-lexical
try_match_ident_ignore_ascii_case! { input.expect_ident()?.clone(),
try_match_ident_ignore_ascii_case! { input,
"baseline" => Ok(ALIGN_BASELINE),
"first" => {
input.expect_ident_matching("baseline")?;
@ -398,7 +398,7 @@ fn parse_baseline<'i, 't>(input: &mut Parser<'i, 't>) -> Result<AlignFlags, Pars
// <content-distribution>
fn parse_content_distribution<'i, 't>(input: &mut Parser<'i, 't>) -> Result<AlignFlags, ParseError<'i>> {
try_match_ident_ignore_ascii_case! { input.expect_ident()?,
try_match_ident_ignore_ascii_case! { input,
"stretch" => Ok(ALIGN_STRETCH),
"space-between" => Ok(ALIGN_SPACE_BETWEEN),
"space-around" => Ok(ALIGN_SPACE_AROUND),
@ -421,12 +421,12 @@ fn parse_overflow_content_position<'i, 't>(input: &mut Parser<'i, 't>) -> Result
return Ok(overflow | content)
}
}
return Err(StyleParseError::UnspecifiedError.into())
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
}
// <content-position>
fn parse_content_position<'i, 't>(input: &mut Parser<'i, 't>) -> Result<AlignFlags, ParseError<'i>> {
try_match_ident_ignore_ascii_case! { input.expect_ident()?,
try_match_ident_ignore_ascii_case! { input,
"start" => Ok(ALIGN_START),
"end" => Ok(ALIGN_END),
"flex-start" => Ok(ALIGN_FLEX_START),
@ -439,7 +439,7 @@ fn parse_content_position<'i, 't>(input: &mut Parser<'i, 't>) -> Result<AlignFla
// <overflow-position>
fn parse_overflow_position<'i, 't>(input: &mut Parser<'i, 't>) -> Result<AlignFlags, ParseError<'i>> {
try_match_ident_ignore_ascii_case! { input.expect_ident()?,
try_match_ident_ignore_ascii_case! { input,
"safe" => Ok(ALIGN_SAFE),
"unsafe" => Ok(ALIGN_UNSAFE),
}
@ -460,12 +460,12 @@ fn parse_overflow_self_position<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Al
return Ok(overflow | self_position)
}
}
return Err(StyleParseError::UnspecifiedError.into())
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
}
// <self-position>
fn parse_self_position<'i, 't>(input: &mut Parser<'i, 't>) -> Result<AlignFlags, ParseError<'i>> {
try_match_ident_ignore_ascii_case! { input.expect_ident()?,
try_match_ident_ignore_ascii_case! { input,
"start" => Ok(ALIGN_START),
"end" => Ok(ALIGN_END),
"flex-start" => Ok(ALIGN_FLEX_START),
@ -480,7 +480,9 @@ fn parse_self_position<'i, 't>(input: &mut Parser<'i, 't>) -> Result<AlignFlags,
// [ legacy && [ left | right | center ] ]
fn parse_legacy<'i, 't>(input: &mut Parser<'i, 't>) -> Result<AlignFlags, ParseError<'i>> {
let a_location = input.current_source_location();
let a = input.expect_ident()?.clone();
let b_location = input.current_source_location();
let b = input.expect_ident()?;
if a.eq_ignore_ascii_case("legacy") {
(match_ignore_ascii_case! { &b,
@ -488,15 +490,15 @@ fn parse_legacy<'i, 't>(input: &mut Parser<'i, 't>) -> Result<AlignFlags, ParseE
"right" => Ok(ALIGN_LEGACY | ALIGN_RIGHT),
"center" => Ok(ALIGN_LEGACY | ALIGN_CENTER),
_ => Err(())
}).map_err(|()| SelectorParseError::UnexpectedIdent(b.clone()).into())
}).map_err(|()| b_location.new_custom_error(SelectorParseErrorKind::UnexpectedIdent(b.clone())))
} else if b.eq_ignore_ascii_case("legacy") {
(match_ignore_ascii_case! { &a,
"left" => Ok(ALIGN_LEGACY | ALIGN_LEFT),
"right" => Ok(ALIGN_LEGACY | ALIGN_RIGHT),
"center" => Ok(ALIGN_LEGACY | ALIGN_CENTER),
_ => Err(())
}).map_err(|()| SelectorParseError::UnexpectedIdent(a).into())
}).map_err(|()| a_location.new_custom_error(SelectorParseErrorKind::UnexpectedIdent(a)))
} else {
Err(StyleParseError::UnspecifiedError.into())
Err(a_location.new_custom_error(StyleParseErrorKind::UnspecifiedError))
}
}

View file

@ -4,7 +4,7 @@
//! Specified angles.
use cssparser::{Parser, Token, BasicParseError};
use cssparser::{Parser, Token};
use parser::{ParserContext, Parse};
use std::ascii::AsciiExt;
use std::fmt;
@ -112,7 +112,7 @@ impl Parse for Angle {
return input.parse_nested_block(|i| CalcNode::parse_angle(context, i))
}
_ => Err(())
}.map_err(|()| BasicParseError::UnexpectedToken(token.clone()).into())
}.map_err(|()| input.new_unexpected_token_error(token.clone()))
}
}
@ -155,6 +155,6 @@ impl Angle {
return input.parse_nested_block(|i| CalcNode::parse_angle(context, i))
}
_ => Err(())
}.map_err(|()| BasicParseError::UnexpectedToken(token.clone()).into())
}.map_err(|()| input.new_unexpected_token_error(token.clone()))
}
}

View file

@ -6,7 +6,7 @@
use cssparser::Parser;
use parser::{Parse, ParserContext};
use selectors::parser::SelectorParseError;
use selectors::parser::SelectorParseErrorKind;
use style_traits::ParseError;
use values::generics::background::BackgroundSize as GenericBackgroundSize;
use values::specified::length::LengthOrPercentageOrAuto;
@ -22,12 +22,13 @@ impl Parse for BackgroundSize {
.unwrap_or(LengthOrPercentageOrAuto::Auto);
return Ok(GenericBackgroundSize::Explicit { width, height });
}
let location = input.current_source_location();
let ident = input.expect_ident()?;
(match_ignore_ascii_case! { &ident,
"cover" => Ok(GenericBackgroundSize::Cover),
"contain" => Ok(GenericBackgroundSize::Contain),
_ => Err(()),
}).map_err(|()| SelectorParseError::UnexpectedIdent(ident.clone()).into())
}).map_err(|()| location.new_custom_error(SelectorParseErrorKind::UnexpectedIdent(ident.clone())))
}
}

View file

@ -11,7 +11,7 @@ use cssparser::Parser;
use parser::{Parse, ParserContext};
use std::borrow::Cow;
use std::fmt;
use style_traits::{ToCss, ParseError, StyleParseError};
use style_traits::{ToCss, ParseError, StyleParseErrorKind};
use values::computed::Percentage;
use values::generics::basic_shape::{Circle as GenericCircle};
use values::generics::basic_shape::{ClippingShape as GenericClippingShape, Ellipse as GenericEllipse};
@ -81,7 +81,7 @@ impl<ReferenceBox: Parse> Parse for ShapeSource<BasicShape, ReferenceBox, Specif
return Ok(ShapeSource::Shape(shp, ref_box))
}
ref_box.map(|v| ShapeSource::Box(v)).ok_or(StyleParseError::UnspecifiedError.into())
ref_box.map(|v| ShapeSource::Box(v)).ok_or(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
}
}
@ -91,7 +91,7 @@ impl Parse for GeometryBox {
return Ok(GeometryBox::ShapeBox(shape_box))
}
try_match_ident_ignore_ascii_case! { input.expect_ident()?,
try_match_ident_ignore_ascii_case! { input,
"fill-box" => Ok(GeometryBox::FillBox),
"stroke-box" => Ok(GeometryBox::StrokeBox),
"view-box" => Ok(GeometryBox::ViewBox),
@ -101,6 +101,7 @@ impl Parse for GeometryBox {
impl Parse for BasicShape {
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
let location = input.current_source_location();
let function = input.expect_function()?.clone();
input.parse_nested_block(move |i| {
(match_ignore_ascii_case! { &function,
@ -109,7 +110,7 @@ impl Parse for BasicShape {
"ellipse" => return Ellipse::parse_function_arguments(context, i).map(GenericBasicShape::Ellipse),
"polygon" => return Polygon::parse_function_arguments(context, i).map(GenericBasicShape::Polygon),
_ => Err(())
}).map_err(|()| StyleParseError::UnexpectedFunction(function.clone()).into())
}).map_err(|()| location.new_custom_error(StyleParseErrorKind::UnexpectedFunction(function.clone())))
})
}
}
@ -229,7 +230,7 @@ impl Parse for ShapeRadius {
return Ok(GenericShapeRadius::Length(lop))
}
try_match_ident_ignore_ascii_case! { input.expect_ident()?,
try_match_ident_ignore_ascii_case! { input,
"closest-side" => Ok(GenericShapeRadius::ClosestSide),
"farthest-side" => Ok(GenericShapeRadius::FarthestSide),
}

View file

@ -62,7 +62,7 @@ impl BorderSideWidth {
if let Ok(length) = input.try(|i| Length::parse_non_negative_quirky(context, i, allow_quirks)) {
return Ok(BorderSideWidth::Length(length));
}
try_match_ident_ignore_ascii_case! { input.expect_ident()?,
try_match_ident_ignore_ascii_case! { input,
"thin" => Ok(BorderSideWidth::Thin),
"medium" => Ok(BorderSideWidth::Medium),
"thick" => Ok(BorderSideWidth::Thick),

View file

@ -23,7 +23,7 @@ impl Parse for VerticalAlign {
return Ok(GenericVerticalAlign::Length(lop));
}
try_match_ident_ignore_ascii_case! { input.expect_ident()?,
try_match_ident_ignore_ascii_case! { input,
"baseline" => Ok(GenericVerticalAlign::Baseline),
"sub" => Ok(GenericVerticalAlign::Sub),
"super" => Ok(GenericVerticalAlign::Super),

View file

@ -6,11 +6,11 @@
//!
//! [calc]: https://drafts.csswg.org/css-values/#calc-notation
use cssparser::{Parser, Token, BasicParseError};
use cssparser::{Parser, Token};
use parser::ParserContext;
use std::ascii::AsciiExt;
use std::fmt;
use style_traits::{ToCss, ParseError, StyleParseError};
use style_traits::{ToCss, ParseError, StyleParseErrorKind};
use style_traits::values::specified::AllowedNumericType;
use values::{CSSInteger, CSSFloat};
use values::computed;
@ -170,6 +170,7 @@ impl CalcNode {
input: &mut Parser<'i, 't>,
expected_unit: CalcUnit
) -> Result<Self, ParseError<'i>> {
let location = input.current_source_location();
// FIXME: remove early returns when lifetimes are non-lexical
match (input.next()?, expected_unit) {
(&Token::Number { value, .. }, _) => return Ok(CalcNode::Number(value)),
@ -177,17 +178,17 @@ impl CalcNode {
(&Token::Dimension { value, ref unit, .. }, CalcUnit::LengthOrPercentage) => {
return NoCalcLength::parse_dimension(context, value, unit)
.map(CalcNode::Length)
.map_err(|()| StyleParseError::UnspecifiedError.into())
.map_err(|()| location.new_custom_error(StyleParseErrorKind::UnspecifiedError))
}
(&Token::Dimension { value, ref unit, .. }, CalcUnit::Angle) => {
return Angle::parse_dimension(value, unit, /* from_calc = */ true)
.map(CalcNode::Angle)
.map_err(|()| StyleParseError::UnspecifiedError.into())
.map_err(|()| location.new_custom_error(StyleParseErrorKind::UnspecifiedError))
}
(&Token::Dimension { value, ref unit, .. }, CalcUnit::Time) => {
return Time::parse_dimension(value, unit, /* from_calc = */ true)
.map(CalcNode::Time)
.map_err(|()| StyleParseError::UnspecifiedError.into())
.map_err(|()| location.new_custom_error(StyleParseErrorKind::UnspecifiedError))
}
(&Token::Percentage { unit_value, .. }, CalcUnit::LengthOrPercentage) |
(&Token::Percentage { unit_value, .. }, CalcUnit::Percentage) => {
@ -195,7 +196,7 @@ impl CalcNode {
}
(&Token::ParenthesisBlock, _) => {}
(&Token::Function(ref name), _) if name.eq_ignore_ascii_case("calc") => {}
(t, _) => return Err(BasicParseError::UnexpectedToken(t.clone()).into())
(t, _) => return Err(location.new_unexpected_token_error(t.clone()))
}
input.parse_nested_block(|i| {
CalcNode::parse(context, i, expected_unit)
@ -236,7 +237,7 @@ impl CalcNode {
CalcNode::Sub(Box::new(root), Box::new(rhs));
root = new_root;
}
t => return Err(BasicParseError::UnexpectedToken(t).into()),
t => return Err(input.new_unexpected_token_error(t)),
}
}
_ => {
@ -559,7 +560,7 @@ impl CalcNode {
Self::parse(context, input, CalcUnit::Integer)?
.to_number()
.map(|n| n as CSSInteger)
.map_err(|()| StyleParseError::UnspecifiedError.into())
.map_err(|()| input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
}
/// Convenience parsing function for `<length> | <percentage>`.
@ -570,7 +571,7 @@ impl CalcNode {
) -> Result<CalcLengthOrPercentage, ParseError<'i>> {
Self::parse(context, input, CalcUnit::LengthOrPercentage)?
.to_length_or_percentage(clamping_mode)
.map_err(|()| StyleParseError::UnspecifiedError.into())
.map_err(|()| input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
}
/// Convenience parsing function for percentages.
@ -580,7 +581,7 @@ impl CalcNode {
) -> Result<CSSFloat, ParseError<'i>> {
Self::parse(context, input, CalcUnit::Percentage)?
.to_percentage()
.map_err(|()| StyleParseError::UnspecifiedError.into())
.map_err(|()| input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
}
/// Convenience parsing function for `<length>`.
@ -591,7 +592,7 @@ impl CalcNode {
) -> Result<CalcLengthOrPercentage, ParseError<'i>> {
Self::parse(context, input, CalcUnit::Length)?
.to_length_or_percentage(clamping_mode)
.map_err(|()| StyleParseError::UnspecifiedError.into())
.map_err(|()| input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
}
/// Convenience parsing function for `<number>`.
@ -601,7 +602,7 @@ impl CalcNode {
) -> Result<CSSFloat, ParseError<'i>> {
Self::parse(context, input, CalcUnit::Number)?
.to_number()
.map_err(|()| StyleParseError::UnspecifiedError.into())
.map_err(|()| input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
}
/// Convenience parsing function for `<angle>`.
@ -611,7 +612,7 @@ impl CalcNode {
) -> Result<Angle, ParseError<'i>> {
Self::parse(context, input, CalcUnit::Angle)?
.to_angle()
.map_err(|()| StyleParseError::UnspecifiedError.into())
.map_err(|()| input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
}
/// Convenience parsing function for `<time>`.
@ -621,6 +622,6 @@ impl CalcNode {
) -> Result<Time, ParseError<'i>> {
Self::parse(context, input, CalcUnit::Time)?
.to_time()
.map_err(|()| StyleParseError::UnspecifiedError.into())
.map_err(|()| input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
}
}

View file

@ -4,7 +4,7 @@
//! Specified color values.
use cssparser::{Color as CSSParserColor, Parser, RGBA, Token, BasicParseError};
use cssparser::{Color as CSSParserColor, Parser, RGBA, Token, BasicParseError, BasicParseErrorKind};
#[cfg(feature = "gecko")]
use gecko_bindings::structs::nscolor;
use itoa;
@ -13,7 +13,7 @@ use parser::{ParserContext, Parse};
use properties::longhands::system_colors::SystemColor;
use std::fmt;
use std::io::Write;
use style_traits::{ToCss, ParseError, StyleParseError, ValueParseError};
use style_traits::{ToCss, ParseError, StyleParseErrorKind, ValueParseErrorKind};
use super::AllowQuirks;
use values::computed::{Color as ComputedColor, Context, ToComputedValue};
@ -94,8 +94,11 @@ impl Parse for Color {
}
}
match e {
BasicParseError::UnexpectedToken(t) =>
Err(StyleParseError::ValueError(ValueParseError::InvalidColor(t)).into()),
BasicParseError { kind: BasicParseErrorKind::UnexpectedToken(t), location } => {
Err(location.new_custom_error(
StyleParseErrorKind::ValueError(ValueParseErrorKind::InvalidColor(t))
))
}
e => Err(e.into())
}
}
@ -179,6 +182,7 @@ impl Color {
///
/// https://quirks.spec.whatwg.org/#the-hashless-hex-color-quirk
fn parse_quirky_color<'i, 't>(input: &mut Parser<'i, 't>) -> Result<RGBA, ParseError<'i>> {
let location = input.current_source_location();
let (value, unit) = match *input.next()? {
Token::Number { int_value: Some(integer), .. } => {
(integer, None)
@ -188,17 +192,17 @@ impl Color {
},
Token::Ident(ref ident) => {
if ident.len() != 3 && ident.len() != 6 {
return Err(StyleParseError::UnspecifiedError.into());
return Err(location.new_custom_error(StyleParseErrorKind::UnspecifiedError));
}
return parse_hash_color(ident.as_bytes())
.map_err(|()| StyleParseError::UnspecifiedError.into());
.map_err(|()| location.new_custom_error(StyleParseErrorKind::UnspecifiedError));
}
ref t => {
return Err(BasicParseError::UnexpectedToken(t.clone()).into());
return Err(location.new_unexpected_token_error(t.clone()));
},
};
if value < 0 {
return Err(StyleParseError::UnspecifiedError.into());
return Err(location.new_custom_error(StyleParseErrorKind::UnspecifiedError));
}
let length = if value <= 9 {
1
@ -213,11 +217,11 @@ impl Color {
} else if value <= 999999 {
6
} else {
return Err(StyleParseError::UnspecifiedError.into())
return Err(location.new_custom_error(StyleParseErrorKind::UnspecifiedError))
};
let total = length + unit.as_ref().map_or(0, |d| d.len());
if total > 6 {
return Err(StyleParseError::UnspecifiedError.into());
return Err(location.new_custom_error(StyleParseErrorKind::UnspecifiedError));
}
let mut serialization = [b'0'; 6];
let space_padding = 6 - total;
@ -227,7 +231,9 @@ impl Color {
written += (&mut serialization[written..]).write(unit.as_bytes()).unwrap();
}
debug_assert!(written == 6);
parse_hash_color(&serialization).map_err(|()| StyleParseError::UnspecifiedError.into())
parse_hash_color(&serialization).map_err(|()| {
location.new_custom_error(StyleParseErrorKind::UnspecifiedError)
})
}
/// Returns false if the color is completely transparent, and

View file

@ -4,9 +4,9 @@
//! Specified types for CSS values related to effects.
use cssparser::{Parser, Token, BasicParseError};
use cssparser::{self, Parser, Token, BasicParseErrorKind};
use parser::{Parse, ParserContext};
use style_traits::{ParseError, StyleParseError, ValueParseError};
use style_traits::{ParseError, StyleParseErrorKind, ValueParseErrorKind};
#[cfg(not(feature = "gecko"))]
use values::Impossible;
use values::computed::{Context, NonNegativeNumber as ComputedNonNegativeNumber, ToComputedValue};
@ -138,7 +138,7 @@ impl Parse for BoxShadow {
break;
}
let lengths = lengths.ok_or(StyleParseError::UnspecifiedError)?;
let lengths = lengths.ok_or(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))?;
Ok(BoxShadow {
base: SimpleShadow {
color: color,
@ -186,10 +186,15 @@ impl Parse for Filter {
return Ok(GenericFilter::Url(url));
}
}
let location = input.current_source_location();
let function = match input.expect_function() {
Ok(f) => f.clone(),
Err(BasicParseError::UnexpectedToken(t)) =>
return Err(ValueParseError::InvalidFilter(t.clone()).into()),
Err(cssparser::BasicParseError {
kind: BasicParseErrorKind::UnexpectedToken(t),
location,
}) => {
return Err(location.new_custom_error(ValueParseErrorKind::InvalidFilter(t)))
}
Err(e) => return Err(e.into()),
};
input.parse_nested_block(|i| {
@ -220,7 +225,9 @@ impl Parse for Filter {
Ok(GenericFilter::Sepia(Factor::parse_with_clamping_to_one(context, i)?))
},
"drop-shadow" => Ok(GenericFilter::DropShadow(Parse::parse(context, i)?)),
_ => Err(ValueParseError::InvalidFilter(Token::Function(function.clone())).into()),
_ => Err(location.new_custom_error(
ValueParseErrorKind::InvalidFilter(Token::Function(function.clone()))
)),
}
})
}

View file

@ -21,7 +21,7 @@ impl Parse for FlexBasis {
if let Ok(length) = input.try(|i| LengthOrPercentage::parse_non_negative(context, i)) {
return Ok(GenericFlexBasis::Length(length));
}
try_match_ident_ignore_ascii_case! { input.expect_ident()?,
try_match_ident_ignore_ascii_case! { input,
"auto" => Ok(GenericFlexBasis::Auto),
"content" => Ok(GenericFlexBasis::Content),
}

View file

@ -83,7 +83,7 @@ pub enum KeywordSize {
impl KeywordSize {
/// Parse a keyword size
pub fn parse<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
try_match_ident_ignore_ascii_case! { input.expect_ident()?,
try_match_ident_ignore_ascii_case! { input,
"xx-small" => Ok(KeywordSize::XXSmall),
"x-small" => Ok(KeywordSize::XSmall),
"small" => Ok(KeywordSize::Small),

View file

@ -5,11 +5,11 @@
//! CSS handling for the computed value of
//! [grids](https://drafts.csswg.org/css-grid/)
use cssparser::{Parser, Token, BasicParseError};
use cssparser::{Parser, Token, ParseError as CssParseError};
use parser::{Parse, ParserContext};
use std::ascii::AsciiExt;
use std::mem;
use style_traits::{ParseError, StyleParseError};
use style_traits::{ParseError, StyleParseErrorKind};
use values::{CSSFloat, CustomIdent};
use values::computed::{self, Context, ToComputedValue};
use values::generics::grid::{GridTemplateComponent, RepeatCount, TrackBreadth, TrackKeyword, TrackRepeat};
@ -18,10 +18,11 @@ use values::specified::{LengthOrPercentage, Integer};
/// Parse a single flexible length.
pub fn parse_flex<'i, 't>(input: &mut Parser<'i, 't>) -> Result<CSSFloat, ParseError<'i>> {
let location = input.current_source_location();
match *input.next()? {
Token::Dimension { value, ref unit, .. } if unit.eq_ignore_ascii_case("fr") && value.is_sign_positive()
=> Ok(value),
ref t => Err(BasicParseError::UnexpectedToken(t.clone()).into()),
ref t => Err(location.new_unexpected_token_error(t.clone())),
}
}
@ -74,8 +75,10 @@ pub fn parse_line_names<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Box<[Custo
input.expect_square_bracket_block()?;
input.parse_nested_block(|input| {
let mut values = vec![];
while let Ok(ident) = input.try(|i| i.expect_ident_cloned()) {
let ident = CustomIdent::from_ident(&ident, &["span"])?;
while let Ok((loc, ident)) = input.try(|i| -> Result<_, CssParseError<()>> {
Ok((i.current_source_location(), i.expect_ident_cloned()?))
}) {
let ident = CustomIdent::from_ident(loc, &ident, &["span"])?;
values.push(ident);
}
@ -124,7 +127,7 @@ impl TrackRepeat<LengthOrPercentage, Integer> {
if !track_size.is_fixed() {
if is_auto {
// should be <fixed-size> for <auto-repeat>
return Err(StyleParseError::UnspecifiedError.into())
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
}
if repeat_type == RepeatType::Fixed {
@ -147,7 +150,7 @@ impl TrackRepeat<LengthOrPercentage, Integer> {
} else {
if values.is_empty() {
// expecting at least one <track-size>
return Err(StyleParseError::UnspecifiedError.into())
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
}
names.push(current_names); // final `<line-names>`
@ -191,7 +194,7 @@ impl Parse for TrackList<LengthOrPercentage, Integer> {
atleast_one_not_fixed = true;
if auto_repeat.is_some() {
// <auto-track-list> only accepts <fixed-size> and <fixed-repeat>
return Err(StyleParseError::UnspecifiedError.into())
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
}
}
@ -207,13 +210,13 @@ impl Parse for TrackList<LengthOrPercentage, Integer> {
RepeatType::Normal => {
atleast_one_not_fixed = true;
if auto_repeat.is_some() { // only <fixed-repeat>
return Err(StyleParseError::UnspecifiedError.into())
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
}
},
RepeatType::Auto => {
if auto_repeat.is_some() || atleast_one_not_fixed {
// We've either seen <auto-repeat> earlier, or there's at least one non-fixed value
return Err(StyleParseError::UnspecifiedError.into())
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
}
list_type = TrackListType::Auto(values.len() as u16 + auto_offset);
@ -233,7 +236,7 @@ impl Parse for TrackList<LengthOrPercentage, Integer> {
values.push(TrackListValue::TrackRepeat(repeat));
} else {
if values.is_empty() && auto_repeat.is_none() {
return Err(StyleParseError::UnspecifiedError.into())
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
}
names.push(current_names.into_boxed_slice());

View file

@ -8,16 +8,16 @@
//! [image]: https://drafts.csswg.org/css-images/#image-values
use Atom;
use cssparser::{Parser, Token, BasicParseError};
use cssparser::{Parser, Token};
use custom_properties::SpecifiedValue;
use parser::{Parse, ParserContext};
use selectors::parser::SelectorParseError;
use selectors::parser::SelectorParseErrorKind;
#[cfg(feature = "servo")]
use servo_url::ServoUrl;
use std::cmp::Ordering;
use std::f32::consts::PI;
use std::fmt;
use style_traits::{ToCss, ParseError, StyleParseError};
use style_traits::{ToCss, ParseError, StyleParseErrorKind};
use values::{Either, None_};
#[cfg(feature = "gecko")]
use values::computed::{Context, Position as ComputedPosition, ToComputedValue};
@ -169,10 +169,11 @@ impl Image {
/// Parses a `-moz-element(# <element-id>)`.
fn parse_element<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Atom, ParseError<'i>> {
input.try(|i| i.expect_function_matching("-moz-element"))?;
let location = input.current_source_location();
input.parse_nested_block(|i| {
match *i.next()? {
Token::IDHash(ref id) => Ok(Atom::from(id.as_ref())),
ref t => Err(BasicParseError::UnexpectedToken(t.clone()).into()),
ref t => Err(location.new_unexpected_token_error(t.clone())),
}
})
}
@ -236,7 +237,7 @@ impl Parse for Gradient {
let (shape, repeating, mut compat_mode) = match result {
Some(result) => result,
None => return Err(StyleParseError::UnexpectedFunction(func.clone()).into()),
None => return Err(input.new_custom_error(StyleParseErrorKind::UnexpectedFunction(func.clone()))),
};
let (kind, items) = input.parse_nested_block(|i| {
@ -249,7 +250,7 @@ impl Parse for Gradient {
})?;
if items.len() < 2 {
return Err(StyleParseError::UnspecifiedError.into());
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError));
}
Ok(Gradient {
@ -435,7 +436,7 @@ impl Gradient {
(kind, reverse_stops)
}
},
_ => return Err(SelectorParseError::UnexpectedIdent(ident.clone()).into()),
_ => return Err(input.new_custom_error(SelectorParseErrorKind::UnexpectedIdent(ident.clone()))),
};
let mut items = input.try(|i| {
@ -454,11 +455,11 @@ impl Gradient {
},
"from" => Percentage::zero(),
"to" => Percentage::hundred(),
_ => return Err(StyleParseError::UnexpectedFunction(function.clone()).into()),
_ => return Err(i.new_custom_error(StyleParseErrorKind::UnexpectedFunction(function.clone()))),
};
let color = Color::parse(context, i)?;
if color == Color::CurrentColor {
return Err(StyleParseError::UnspecifiedError.into());
return Err(i.new_custom_error(StyleParseErrorKind::UnspecifiedError));
}
Ok((color.into(), p))
})?;
@ -728,7 +729,7 @@ impl LineDirection {
// There is no `to` keyword in webkit prefixed syntax. If it's consumed,
// parsing should throw an error.
CompatMode::WebKit if to_ident.is_ok() => {
return Err(SelectorParseError::UnexpectedIdent("to".into()).into())
return Err(i.new_custom_error(SelectorParseErrorKind::UnexpectedIdent("to".into())))
},
_ => {},
}
@ -743,7 +744,7 @@ impl LineDirection {
};
if _angle.is_none() && position.is_none() {
return Err(StyleParseError::UnspecifiedError.into());
return Err(i.new_custom_error(StyleParseErrorKind::UnspecifiedError));
}
return Ok(LineDirection::MozPosition(position, _angle));
}
@ -867,7 +868,7 @@ impl ShapeExtent {
-> Result<Self, ParseError<'i>> {
match Self::parse(input)? {
ShapeExtent::Contain | ShapeExtent::Cover if compat_mode == CompatMode::Modern => {
Err(StyleParseError::UnspecifiedError.into())
Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
},
ShapeExtent::Contain => Ok(ShapeExtent::ClosestSide),
ShapeExtent::Cover => Ok(ShapeExtent::FarthestCorner),
@ -891,7 +892,7 @@ impl GradientItem {
ColorStop::parse(context, input).map(GenericGradientItem::ColorStop)
})?;
if !seen_stop || items.len() < 2 {
return Err(StyleParseError::UnspecifiedError.into());
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError));
}
Ok(items)
}

View file

@ -7,14 +7,14 @@
//! [length]: https://drafts.csswg.org/css-values/#lengths
use app_units::Au;
use cssparser::{Parser, Token, BasicParseError};
use cssparser::{Parser, Token};
use euclid::Size2D;
use font_metrics::FontMetricsQueryResult;
use parser::{Parse, ParserContext};
use std::{cmp, fmt, mem};
use std::ascii::AsciiExt;
use std::ops::{Add, Mul};
use style_traits::{ToCss, ParseError, StyleParseError};
use style_traits::{ToCss, ParseError, StyleParseErrorKind};
use style_traits::values::specified::AllowedNumericType;
use stylesheets::CssRuleType;
use super::{AllowQuirks, Number, ToComputedValue, Percentage};
@ -662,22 +662,23 @@ impl Length {
-> Result<Length, ParseError<'i>> {
// FIXME: remove early returns when lifetimes are non-lexical
{
let location = input.current_source_location();
let token = input.next()?;
match *token {
Token::Dimension { value, ref unit, .. } if num_context.is_ok(context.parsing_mode, value) => {
return Length::parse_dimension(context, value, unit)
.map_err(|()| BasicParseError::UnexpectedToken(token.clone()).into())
.map_err(|()| location.new_unexpected_token_error(token.clone()))
}
Token::Number { value, .. } if num_context.is_ok(context.parsing_mode, value) => {
if value != 0. &&
!context.parsing_mode.allows_unitless_lengths() &&
!allow_quirks.allowed(context.quirks_mode) {
return Err(StyleParseError::UnspecifiedError.into())
return Err(location.new_custom_error(StyleParseErrorKind::UnspecifiedError))
}
return Ok(Length::NoCalc(NoCalcLength::Absolute(AbsoluteLength::Px(value))))
},
Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => {}
ref token => return Err(BasicParseError::UnexpectedToken(token.clone()).into())
ref token => return Err(location.new_unexpected_token_error(token.clone()))
}
}
input.parse_nested_block(|input| {
@ -858,12 +859,13 @@ impl LengthOrPercentage {
{
// FIXME: remove early returns when lifetimes are non-lexical
{
let location = input.current_source_location();
let token = input.next()?;
match *token {
Token::Dimension { value, ref unit, .. } if num_context.is_ok(context.parsing_mode, value) => {
return NoCalcLength::parse_dimension(context, value, unit)
.map(LengthOrPercentage::Length)
.map_err(|()| BasicParseError::UnexpectedToken(token.clone()).into())
.map_err(|()| location.new_unexpected_token_error(token.clone()))
}
Token::Percentage { unit_value, .. } if num_context.is_ok(context.parsing_mode, unit_value) => {
return Ok(LengthOrPercentage::Percentage(computed::Percentage(unit_value)))
@ -872,13 +874,13 @@ impl LengthOrPercentage {
if value != 0. &&
!context.parsing_mode.allows_unitless_lengths() &&
!allow_quirks.allowed(context.quirks_mode) {
return Err(BasicParseError::UnexpectedToken(token.clone()).into())
return Err(location.new_unexpected_token_error(token.clone()))
} else {
return Ok(LengthOrPercentage::Length(NoCalcLength::from_px(value)))
}
}
Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => {}
_ => return Err(BasicParseError::UnexpectedToken(token.clone()).into())
_ => return Err(location.new_unexpected_token_error(token.clone()))
}
}
@ -935,7 +937,7 @@ impl LengthOrPercentage {
if num >= 0. {
Ok(LengthOrPercentage::Length(NoCalcLength::Absolute(AbsoluteLength::Px(num))))
} else {
Err(StyleParseError::UnspecifiedError.into())
Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
}
}
@ -1000,12 +1002,13 @@ impl LengthOrPercentageOrAuto {
-> Result<Self, ParseError<'i>> {
// FIXME: remove early returns when lifetimes are non-lexical
{
let location = input.current_source_location();
let token = input.next()?;
match *token {
Token::Dimension { value, ref unit, .. } if num_context.is_ok(context.parsing_mode, value) => {
return NoCalcLength::parse_dimension(context, value, unit)
.map(LengthOrPercentageOrAuto::Length)
.map_err(|()| BasicParseError::UnexpectedToken(token.clone()).into())
.map_err(|()| location.new_unexpected_token_error(token.clone()))
}
Token::Percentage { unit_value, .. } if num_context.is_ok(context.parsing_mode, unit_value) => {
return Ok(LengthOrPercentageOrAuto::Percentage(computed::Percentage(unit_value)))
@ -1014,7 +1017,7 @@ impl LengthOrPercentageOrAuto {
if value != 0. &&
!context.parsing_mode.allows_unitless_lengths() &&
!allow_quirks.allowed(context.quirks_mode) {
return Err(StyleParseError::UnspecifiedError.into())
return Err(location.new_custom_error(StyleParseErrorKind::UnspecifiedError))
}
return Ok(LengthOrPercentageOrAuto::Length(
NoCalcLength::Absolute(AbsoluteLength::Px(value))
@ -1024,7 +1027,7 @@ impl LengthOrPercentageOrAuto {
return Ok(LengthOrPercentageOrAuto::Auto)
}
Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => {}
_ => return Err(BasicParseError::UnexpectedToken(token.clone()).into())
_ => return Err(location.new_unexpected_token_error(token.clone()))
}
}
@ -1105,12 +1108,13 @@ impl LengthOrPercentageOrNone {
{
// FIXME: remove early returns when lifetimes are non-lexical
{
let location = input.current_source_location();
let token = input.next()?;
match *token {
Token::Dimension { value, ref unit, .. } if num_context.is_ok(context.parsing_mode, value) => {
return NoCalcLength::parse_dimension(context, value, unit)
.map(LengthOrPercentageOrNone::Length)
.map_err(|()| BasicParseError::UnexpectedToken(token.clone()).into())
.map_err(|()| location.new_unexpected_token_error(token.clone()))
}
Token::Percentage { unit_value, .. } if num_context.is_ok(context.parsing_mode, unit_value) => {
return Ok(LengthOrPercentageOrNone::Percentage(computed::Percentage(unit_value)))
@ -1118,7 +1122,7 @@ impl LengthOrPercentageOrNone {
Token::Number { value, .. } if num_context.is_ok(context.parsing_mode, value) => {
if value != 0. && !context.parsing_mode.allows_unitless_lengths() &&
!allow_quirks.allowed(context.quirks_mode) {
return Err(StyleParseError::UnspecifiedError.into())
return Err(location.new_custom_error(StyleParseErrorKind::UnspecifiedError))
}
return Ok(LengthOrPercentageOrNone::Length(
NoCalcLength::Absolute(AbsoluteLength::Px(value))
@ -1128,7 +1132,7 @@ impl LengthOrPercentageOrNone {
Token::Ident(ref value) if value.eq_ignore_ascii_case("none") => {
return Ok(LengthOrPercentageOrNone::None)
}
_ => return Err(BasicParseError::UnexpectedToken(token.clone()).into())
_ => return Err(location.new_unexpected_token_error(token.clone()))
}
}

View file

@ -8,13 +8,13 @@
use Namespace;
use context::QuirksMode;
use cssparser::{Parser, Token, serialize_identifier, BasicParseError};
use cssparser::{Parser, Token, serialize_identifier};
use parser::{ParserContext, Parse};
use self::url::SpecifiedUrl;
use std::ascii::AsciiExt;
use std::f32;
use std::fmt;
use style_traits::{ToCss, ParseError, StyleParseError};
use style_traits::{ToCss, ParseError, StyleParseErrorKind};
use style_traits::values::specified::AllowedNumericType;
use super::{Auto, CSSFloat, CSSInteger, Either, None_};
use super::computed::{Context, ToComputedValue};
@ -103,11 +103,12 @@ impl Eq for SpecifiedUrl {}
/// Parse an `<integer>` value, handling `calc()` correctly.
pub fn parse_integer<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<Integer, ParseError<'i>> {
let location = input.current_source_location();
// FIXME: remove early returns when lifetimes are non-lexical
match *input.next()? {
Token::Number { int_value: Some(v), .. } => return Ok(Integer::new(v)),
Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => {}
ref t => return Err(BasicParseError::UnexpectedToken(t.clone()).into())
ref t => return Err(location.new_unexpected_token_error(t.clone()))
}
let result = input.parse_nested_block(|i| {
@ -129,6 +130,7 @@ pub fn parse_number_with_clamping_mode<'i, 't>(context: &ParserContext,
input: &mut Parser<'i, 't>,
clamping_mode: AllowedNumericType)
-> Result<Number, ParseError<'i>> {
let location = input.current_source_location();
// FIXME: remove early returns when lifetimes are non-lexical
match *input.next()? {
Token::Number { value, .. } if clamping_mode.is_ok(context.parsing_mode, value) => {
@ -138,7 +140,7 @@ pub fn parse_number_with_clamping_mode<'i, 't>(context: &ParserContext,
})
}
Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => {}
ref t => return Err(BasicParseError::UnexpectedToken(t.clone()).into())
ref t => return Err(location.new_unexpected_token_error(t.clone()))
}
let result = input.parse_nested_block(|i| {
@ -415,7 +417,7 @@ impl Integer {
// It's not totally clear it's worth it though, and no other browser
// does this.
Ok(value) if value.value() >= min => Ok(value),
Ok(_value) => Err(StyleParseError::UnspecifiedError.into()),
Ok(_value) => Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError)),
Err(e) => Err(e),
}
}
@ -473,7 +475,9 @@ impl IntegerOrAuto {
input: &mut Parser<'i, 't>)
-> Result<IntegerOrAuto, ParseError<'i>> {
match IntegerOrAuto::parse(context, input) {
Ok(Either::First(integer)) if integer.value() <= 0 => Err(StyleParseError::UnspecifiedError.into()),
Ok(Either::First(integer)) if integer.value() <= 0 => {
Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
}
result => result,
}
}
@ -741,17 +745,18 @@ impl Attr {
if let Ok(token) = input.try(|i| i.next_including_whitespace().map(|t| t.clone())) {
match token {
Token::Delim('|') => {
let location = input.current_source_location();
// must be followed by an ident
let second_token = match *input.next_including_whitespace()? {
Token::Ident(ref second) => second,
ref t => return Err(BasicParseError::UnexpectedToken(t.clone()).into()),
ref t => return Err(location.new_unexpected_token_error(t.clone())),
};
let ns_with_id = if let Some(ns) = first {
let ns = Namespace::from(ns.as_ref());
let id: Result<_, ParseError> =
get_id_for_namespace(&ns, context)
.map_err(|()| StyleParseError::UnspecifiedError.into());
.map_err(|()| location.new_custom_error(StyleParseErrorKind::UnspecifiedError));
Some((ns, id?))
} else {
None
@ -764,7 +769,7 @@ impl Attr {
// In the case of attr(foobar ) we don't want to error out
// because of the trailing whitespace
Token::WhiteSpace(_) => (),
ref t => return Err(BasicParseError::UnexpectedToken(t.clone()).into()),
ref t => return Err(input.new_unexpected_token_error(t.clone())),
}
}
@ -774,7 +779,7 @@ impl Attr {
attribute: first.as_ref().to_owned(),
})
} else {
Err(StyleParseError::UnspecifiedError.into())
Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
}
}
}

View file

@ -4,7 +4,7 @@
//! Specified percentages.
use cssparser::{BasicParseError, Parser, Token};
use cssparser::{Parser, Token};
use parser::{Parse, ParserContext};
use std::ascii::AsciiExt;
use std::fmt;
@ -97,13 +97,14 @@ impl Percentage {
input: &mut Parser<'i, 't>,
num_context: AllowedNumericType,
) -> Result<Self, ParseError<'i>> {
let location = input.current_source_location();
// FIXME: remove early returns when lifetimes are non-lexical
match *input.next()? {
Token::Percentage { unit_value, .. } if num_context.is_ok(context.parsing_mode, unit_value) => {
return Ok(Percentage::new(unit_value));
}
Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => {},
ref t => return Err(BasicParseError::UnexpectedToken(t.clone()).into()),
ref t => return Err(location.new_unexpected_token_error(t.clone())),
}
let result = input.parse_nested_block(|i| {

View file

@ -6,7 +6,7 @@
use cssparser::Parser;
use parser::{Parse, ParserContext};
use style_traits::{CommaWithSpace, ParseError, Separator, StyleParseError};
use style_traits::{CommaWithSpace, ParseError, Separator, StyleParseErrorKind};
use values::generics::svg as generic;
use values::specified::{LengthOrPercentage, NonNegativeLengthOrPercentage, NonNegativeNumber};
use values::specified::{Number, Opacity, SpecifiedUrl};
@ -39,7 +39,7 @@ fn parse_context_value<'i, 't, T>(input: &mut Parser<'i, 't>, value: T)
return Ok(value);
}
}
Err(StyleParseError::UnspecifiedError.into())
Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
}
/// A value of <length> | <percentage> | <number> for stroke-dashoffset.
@ -115,12 +115,12 @@ impl Parse for SVGOpacity {
if let Ok(opacity) = input.try(|i| Opacity::parse(context, i)) {
Ok(generic::SVGOpacity::Opacity(opacity))
} else if is_context_value_enabled() {
try_match_ident_ignore_ascii_case! { input.expect_ident()?,
try_match_ident_ignore_ascii_case! { input,
"context-fill-opacity" => Ok(generic::SVGOpacity::ContextFillOpacity),
"context-stroke-opacity" => Ok(generic::SVGOpacity::ContextStrokeOpacity),
}
} else {
Err(StyleParseError::UnspecifiedError.into())
Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
}
}
}

View file

@ -6,7 +6,7 @@
use cssparser::Parser;
use parser::{Parse, ParserContext};
use selectors::parser::SelectorParseError;
use selectors::parser::SelectorParseErrorKind;
use std::ascii::AsciiExt;
use style_traits::ParseError;
use values::computed::{Context, ToComputedValue};
@ -65,6 +65,7 @@ impl Parse for LineHeight {
if let Ok(nlop) = input.try(|i| NonNegativeLengthOrPercentage::parse(context, i)) {
return Ok(GenericLineHeight::Length(nlop))
}
let location = input.current_source_location();
let ident = input.expect_ident()?;
match ident {
ref ident if ident.eq_ignore_ascii_case("normal") => {
@ -74,7 +75,7 @@ impl Parse for LineHeight {
ref ident if ident.eq_ignore_ascii_case("-moz-block-height") => {
Ok(GenericLineHeight::MozBlockHeight)
},
ident => Err(SelectorParseError::UnexpectedIdent(ident.clone()).into()),
ident => Err(location.new_custom_error(SelectorParseErrorKind::UnexpectedIdent(ident.clone()))),
}
}
}

View file

@ -4,11 +4,11 @@
//! Specified time values.
use cssparser::{Parser, Token, BasicParseError};
use cssparser::{Parser, Token};
use parser::{ParserContext, Parse};
use std::ascii::AsciiExt;
use std::fmt;
use style_traits::{ToCss, ParseError, StyleParseError};
use style_traits::{ToCss, ParseError, StyleParseErrorKind};
use style_traits::values::specified::AllowedNumericType;
use values::CSSFloat;
use values::computed::{Context, ToComputedValue};
@ -83,6 +83,7 @@ impl Time {
) -> Result<Self, ParseError<'i>> {
use style_traits::PARSING_MODE_DEFAULT;
let location = input.current_source_location();
// FIXME: remove early returns when lifetimes are non-lexical
match input.next() {
// Note that we generally pass ParserContext to is_ok() to check
@ -92,15 +93,15 @@ impl Time {
// PARSING_MODE_DEFAULT directly.
Ok(&Token::Dimension { value, ref unit, .. }) if clamping_mode.is_ok(PARSING_MODE_DEFAULT, value) => {
return Time::parse_dimension(value, unit, /* from_calc = */ false)
.map_err(|()| StyleParseError::UnspecifiedError.into())
.map_err(|()| location.new_custom_error(StyleParseErrorKind::UnspecifiedError))
}
Ok(&Token::Function(ref name)) if name.eq_ignore_ascii_case("calc") => {}
Ok(t) => return Err(BasicParseError::UnexpectedToken(t.clone()).into()),
Ok(t) => return Err(location.new_unexpected_token_error(t.clone())),
Err(e) => return Err(e.into())
}
match input.parse_nested_block(|i| CalcNode::parse_time(context, i)) {
Ok(time) if clamping_mode.is_ok(PARSING_MODE_DEFAULT, time.seconds) => Ok(time),
_ => Err(StyleParseError::UnspecifiedError.into()),
_ => Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError)),
}
}

View file

@ -6,8 +6,8 @@
use cssparser::Parser;
use parser::{Parse, ParserContext};
use selectors::parser::SelectorParseError;
use style_traits::{ParseError, StyleParseError};
use selectors::parser::SelectorParseErrorKind;
use style_traits::{ParseError, StyleParseErrorKind};
use values::computed::{Context, LengthOrPercentage as ComputedLengthOrPercentage};
use values::computed::{Percentage as ComputedPercentage, ToComputedValue};
use values::computed::transform::TimingFunction as ComputedTimingFunction;
@ -152,10 +152,11 @@ impl Parse for TimingFunction {
let position = match_ignore_ascii_case! { &ident,
"step-start" => StepPosition::Start,
"step-end" => StepPosition::End,
_ => return Err(SelectorParseError::UnexpectedIdent(ident.clone()).into()),
_ => return Err(input.new_custom_error(SelectorParseErrorKind::UnexpectedIdent(ident.clone()))),
};
return Ok(GenericTimingFunction::Steps(Integer::new(1), position));
}
let location = input.current_source_location();
let function = input.expect_function()?.clone();
input.parse_nested_block(move |i| {
(match_ignore_ascii_case! { &function,
@ -169,7 +170,7 @@ impl Parse for TimingFunction {
let y2 = Number::parse(context, i)?;
if x1.get() < 0.0 || x1.get() > 1.0 || x2.get() < 0.0 || x2.get() > 1.0 {
return Err(StyleParseError::UnspecifiedError.into());
return Err(i.new_custom_error(StyleParseErrorKind::UnspecifiedError));
}
Ok(GenericTimingFunction::CubicBezier { x1, y1, x2, y2 })
@ -191,7 +192,7 @@ impl Parse for TimingFunction {
}
},
_ => Err(()),
}).map_err(|()| StyleParseError::UnexpectedFunction(function.clone()).into())
}).map_err(|()| location.new_custom_error(StyleParseErrorKind::UnexpectedFunction(function.clone())))
})
}
}