mirror of
https://github.com/servo/servo.git
synced 2025-08-09 23:45:35 +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
|
@ -8,7 +8,6 @@
|
|||
|
||||
<%helpers:longhand name="content" boxed="True" animation_value_type="none"
|
||||
spec="https://drafts.csswg.org/css-content/#propdef-content">
|
||||
use cssparser::Token;
|
||||
use values::computed::ComputedValueAsSpecified;
|
||||
#[cfg(feature = "gecko")]
|
||||
use values::generics::CounterStyleOrNone;
|
||||
|
@ -157,8 +156,8 @@
|
|||
// normal | none | [ <string> | <counter> | open-quote | close-quote | no-open-quote |
|
||||
// no-close-quote ]+
|
||||
// TODO: <uri>, attr(<identifier>)
|
||||
pub fn parse(context: &ParserContext, input: &mut Parser)
|
||||
-> Result<SpecifiedValue, ()> {
|
||||
pub fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
|
||||
-> Result<SpecifiedValue, ParseError<'i>> {
|
||||
if input.try(|input| input.expect_ident_matching("normal")).is_ok() {
|
||||
return Ok(SpecifiedValue::Normal)
|
||||
}
|
||||
|
@ -185,43 +184,50 @@
|
|||
content.push(ContentItem::String(value.into_owned()))
|
||||
}
|
||||
Ok(Token::Function(name)) => {
|
||||
content.push(try!(match_ignore_ascii_case! { &name,
|
||||
"counter" => input.parse_nested_block(|input| {
|
||||
let result = match_ignore_ascii_case! { &name,
|
||||
"counter" => Some(input.parse_nested_block(|input| {
|
||||
let name = try!(input.expect_ident()).into_owned();
|
||||
let style = parse_counter_style(context, input);
|
||||
Ok(ContentItem::Counter(name, style))
|
||||
}),
|
||||
"counters" => input.parse_nested_block(|input| {
|
||||
})),
|
||||
"counters" => Some(input.parse_nested_block(|input| {
|
||||
let name = try!(input.expect_ident()).into_owned();
|
||||
try!(input.expect_comma());
|
||||
let separator = try!(input.expect_string()).into_owned();
|
||||
let style = parse_counter_style(context, input);
|
||||
Ok(ContentItem::Counters(name, separator, style))
|
||||
}),
|
||||
})),
|
||||
% if product == "gecko":
|
||||
"attr" => input.parse_nested_block(|input| {
|
||||
"attr" => Some(input.parse_nested_block(|input| {
|
||||
Ok(ContentItem::Attr(Attr::parse_function(context, input)?))
|
||||
}),
|
||||
})),
|
||||
% endif
|
||||
_ => return Err(())
|
||||
}));
|
||||
_ => None
|
||||
};
|
||||
match result {
|
||||
Some(result) => content.push(try!(result)),
|
||||
None => return Err(StyleParseError::UnexpectedFunction(name).into())
|
||||
}
|
||||
}
|
||||
Ok(Token::Ident(ident)) => {
|
||||
match_ignore_ascii_case! { &ident,
|
||||
"open-quote" => content.push(ContentItem::OpenQuote),
|
||||
"close-quote" => content.push(ContentItem::CloseQuote),
|
||||
"no-open-quote" => content.push(ContentItem::NoOpenQuote),
|
||||
"no-close-quote" => content.push(ContentItem::NoCloseQuote),
|
||||
let valid = match_ignore_ascii_case! { &ident,
|
||||
"open-quote" => { content.push(ContentItem::OpenQuote); true },
|
||||
"close-quote" => { content.push(ContentItem::CloseQuote); true },
|
||||
"no-open-quote" => { content.push(ContentItem::NoOpenQuote); true },
|
||||
"no-close-quote" => { content.push(ContentItem::NoCloseQuote); true },
|
||||
|
||||
_ => return Err(())
|
||||
_ => false,
|
||||
};
|
||||
if !valid {
|
||||
return Err(SelectorParseError::UnexpectedIdent(ident).into())
|
||||
}
|
||||
}
|
||||
Err(_) => break,
|
||||
_ => return Err(())
|
||||
Ok(t) => return Err(BasicParseError::UnexpectedToken(t).into())
|
||||
}
|
||||
}
|
||||
if content.is_empty() {
|
||||
return Err(());
|
||||
return Err(StyleParseError::UnspecifiedError.into());
|
||||
}
|
||||
Ok(SpecifiedValue::Items(content))
|
||||
}
|
||||
|
@ -233,8 +239,6 @@
|
|||
use style_traits::ToCss;
|
||||
use values::CustomIdent;
|
||||
|
||||
use cssparser::Token;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct SpecifiedValue(pub Vec<(CustomIdent, specified::Integer)>);
|
||||
|
||||
|
@ -315,11 +319,13 @@
|
|||
}
|
||||
}
|
||||
|
||||
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
|
||||
pub fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
|
||||
-> Result<SpecifiedValue, ParseError<'i>> {
|
||||
parse_common(context, 1, input)
|
||||
}
|
||||
|
||||
pub fn parse_common(context: &ParserContext, default_value: i32, input: &mut Parser) -> Result<SpecifiedValue, ()> {
|
||||
pub fn parse_common<'i, 't>(context: &ParserContext, default_value: i32, input: &mut Parser<'i, 't>)
|
||||
-> Result<SpecifiedValue, ParseError<'i>> {
|
||||
if input.try(|input| input.expect_ident_matching("none")).is_ok() {
|
||||
return Ok(SpecifiedValue(Vec::new()))
|
||||
}
|
||||
|
@ -328,7 +334,7 @@
|
|||
loop {
|
||||
let counter_name = match input.next() {
|
||||
Ok(Token::Ident(ident)) => CustomIdent::from_ident(ident, &["none"])?,
|
||||
Ok(_) => return Err(()),
|
||||
Ok(t) => return Err(BasicParseError::UnexpectedToken(t).into()),
|
||||
Err(_) => break,
|
||||
};
|
||||
let counter_delta = input.try(|input| specified::parse_integer(context, input))
|
||||
|
@ -339,7 +345,7 @@
|
|||
if !counters.is_empty() {
|
||||
Ok(SpecifiedValue(counters))
|
||||
} else {
|
||||
Err(())
|
||||
Err(StyleParseError::UnspecifiedError.into())
|
||||
}
|
||||
}
|
||||
</%helpers:longhand>
|
||||
|
@ -349,7 +355,8 @@
|
|||
pub use super::counter_increment::{SpecifiedValue, computed_value, get_initial_value};
|
||||
use super::counter_increment::parse_common;
|
||||
|
||||
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue,()> {
|
||||
pub fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
|
||||
-> Result<SpecifiedValue,ParseError<'i>> {
|
||||
parse_common(context, 0, input)
|
||||
}
|
||||
</%helpers:longhand>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue