mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +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
|
@ -9,13 +9,14 @@
|
|||
#![deny(missing_docs)]
|
||||
|
||||
use Atom;
|
||||
pub use cssparser::{RGBA, Token, Parser, serialize_identifier};
|
||||
pub use cssparser::{RGBA, Token, Parser, serialize_identifier, BasicParseError};
|
||||
use parser::{Parse, ParserContext};
|
||||
use selectors::parser::SelectorParseError;
|
||||
use std::ascii::AsciiExt;
|
||||
use std::borrow::Cow;
|
||||
use std::fmt::{self, Debug};
|
||||
use std::hash;
|
||||
use style_traits::ToCss;
|
||||
use style_traits::{ToCss, ParseError, StyleParseError};
|
||||
|
||||
pub mod computed;
|
||||
pub mod generics;
|
||||
|
@ -54,7 +55,8 @@ impl<A: Debug, B: Debug> Debug for Either<A, B> {
|
|||
}
|
||||
|
||||
impl<A: Parse, B: Parse> Parse for Either<A, B> {
|
||||
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Either<A, B>, ()> {
|
||||
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
|
||||
-> Result<Either<A, B>, ParseError<'i>> {
|
||||
if let Ok(v) = input.try(|i| A::parse(context, i)) {
|
||||
Ok(Either::First(v))
|
||||
} else {
|
||||
|
@ -91,13 +93,16 @@ pub struct CustomIdent(pub Atom);
|
|||
|
||||
impl CustomIdent {
|
||||
/// Parse an already-tokenizer identifier
|
||||
pub fn from_ident(ident: Cow<str>, excluding: &[&str]) -> Result<Self, ()> {
|
||||
match_ignore_ascii_case! { &ident,
|
||||
"initial" | "inherit" | "unset" | "default" => return Err(()),
|
||||
_ => {}
|
||||
pub fn from_ident<'i>(ident: Cow<'i, str>, 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).into());
|
||||
}
|
||||
if excluding.iter().any(|s| ident.eq_ignore_ascii_case(s)) {
|
||||
Err(())
|
||||
Err(StyleParseError::UnspecifiedError.into())
|
||||
} else {
|
||||
Ok(CustomIdent(ident.into()))
|
||||
}
|
||||
|
@ -125,7 +130,7 @@ impl KeyframesName {
|
|||
pub fn from_ident(value: String) -> Self {
|
||||
match CustomIdent::from_ident((&*value).into(), &["none"]) {
|
||||
Ok(ident) => KeyframesName::Ident(ident),
|
||||
Err(()) => KeyframesName::QuotedString(value.into()),
|
||||
Err(_) => KeyframesName::QuotedString(value.into()),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -153,11 +158,12 @@ impl hash::Hash for KeyframesName {
|
|||
}
|
||||
|
||||
impl Parse for KeyframesName {
|
||||
fn parse(_context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
|
||||
fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
|
||||
match input.next() {
|
||||
Ok(Token::Ident(s)) => Ok(KeyframesName::Ident(CustomIdent::from_ident(s, &["none"])?)),
|
||||
Ok(Token::QuotedString(s)) => Ok(KeyframesName::QuotedString(s.into())),
|
||||
_ => Err(())
|
||||
Ok(t) => Err(BasicParseError::UnexpectedToken(t).into()),
|
||||
Err(e) => Err(e.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue