mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Thread ParseError return values through CSS parsing.
This commit is contained in:
parent
58e39bfffa
commit
27ae1ef2e7
121 changed files with 2133 additions and 1505 deletions
|
@ -7,8 +7,9 @@
|
|||
|
||||
use cssparser::{Parser, serialize_identifier};
|
||||
use parser::{Parse, ParserContext};
|
||||
use selectors::parser::SelectorParseError;
|
||||
use std::{fmt, mem, usize};
|
||||
use style_traits::ToCss;
|
||||
use style_traits::{ToCss, ParseError, StyleParseError};
|
||||
use values::{CSSFloat, CustomIdent};
|
||||
use values::computed::{self, ComputedValueAsSpecified, Context, ToComputedValue};
|
||||
use values::specified::Integer;
|
||||
|
@ -70,7 +71,7 @@ impl ToCss for GridLine {
|
|||
}
|
||||
|
||||
impl Parse for GridLine {
|
||||
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
|
||||
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
|
||||
let mut grid_line = Default::default();
|
||||
if input.try(|i| i.expect_ident_matching("auto")).is_ok() {
|
||||
return Ok(grid_line)
|
||||
|
@ -85,7 +86,7 @@ impl Parse for GridLine {
|
|||
for _ in 0..3 { // Maximum possible entities for <grid-line>
|
||||
if input.try(|i| i.expect_ident_matching("span")).is_ok() {
|
||||
if grid_line.is_span {
|
||||
return Err(())
|
||||
return Err(StyleParseError::UnspecifiedError.into())
|
||||
}
|
||||
|
||||
if grid_line.line_num.is_some() || grid_line.ident.is_some() {
|
||||
|
@ -95,14 +96,14 @@ impl Parse for GridLine {
|
|||
grid_line.is_span = true;
|
||||
} else if let Ok(i) = input.try(|i| Integer::parse(context, i)) {
|
||||
if i.value() == 0 || val_before_span || grid_line.line_num.is_some() {
|
||||
return Err(())
|
||||
return Err(StyleParseError::UnspecifiedError.into())
|
||||
}
|
||||
|
||||
grid_line.line_num = Some(i);
|
||||
} else if let Ok(name) = input.try(|i| i.expect_ident()) {
|
||||
if val_before_span || grid_line.ident.is_some() ||
|
||||
CustomIdent::from_ident((&*name).into(), &[]).is_err() {
|
||||
return Err(())
|
||||
return Err(StyleParseError::UnspecifiedError.into())
|
||||
}
|
||||
|
||||
grid_line.ident = Some(name.into_owned());
|
||||
|
@ -112,18 +113,18 @@ impl Parse for GridLine {
|
|||
}
|
||||
|
||||
if grid_line.is_auto() {
|
||||
return Err(())
|
||||
return Err(StyleParseError::UnspecifiedError.into())
|
||||
}
|
||||
|
||||
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(())
|
||||
return Err(StyleParseError::UnspecifiedError.into())
|
||||
}
|
||||
} else if grid_line.ident.is_some() { // integer could be omitted
|
||||
grid_line.line_num = Some(Integer::new(1));
|
||||
} else {
|
||||
return Err(())
|
||||
return Err(StyleParseError::UnspecifiedError.into())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -341,19 +342,20 @@ pub enum RepeatCount {
|
|||
}
|
||||
|
||||
impl Parse for RepeatCount {
|
||||
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
|
||||
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
|
||||
if let Ok(i) = input.try(|i| Integer::parse(context, i)) {
|
||||
if i.value() > 0 {
|
||||
Ok(RepeatCount::Number(i))
|
||||
} else {
|
||||
Err(())
|
||||
Err(StyleParseError::UnspecifiedError.into())
|
||||
}
|
||||
} else {
|
||||
match_ignore_ascii_case! { &input.expect_ident()?,
|
||||
let ident = input.expect_ident()?;
|
||||
(match_ignore_ascii_case! { &ident,
|
||||
"auto-fill" => Ok(RepeatCount::AutoFill),
|
||||
"auto-fit" => Ok(RepeatCount::AutoFit),
|
||||
_ => Err(()),
|
||||
}
|
||||
}).map_err(|()| SelectorParseError::UnexpectedIdent(ident).into())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue