mirror of
https://github.com/servo/servo.git
synced 2025-08-07 22:45:34 +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
|
@ -33,9 +33,9 @@
|
|||
% endif
|
||||
#[allow(unused_variables)]
|
||||
#[inline]
|
||||
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 allow_quirks:
|
||||
specified::${type}::${parse_method}_quirky(context, input, AllowQuirks::Yes)
|
||||
% elif needs_context:
|
||||
|
@ -87,12 +87,16 @@
|
|||
|
||||
pub mod single_value {
|
||||
#[allow(unused_imports)]
|
||||
use cssparser::Parser;
|
||||
use cssparser::{Parser, BasicParseError};
|
||||
#[allow(unused_imports)]
|
||||
use parser::{Parse, ParserContext};
|
||||
#[allow(unused_imports)]
|
||||
use properties::ShorthandId;
|
||||
#[allow(unused_imports)]
|
||||
use selectors::parser::SelectorParseError;
|
||||
#[allow(unused_imports)]
|
||||
use style_traits::{ParseError, StyleParseError};
|
||||
#[allow(unused_imports)]
|
||||
use values::computed::{Context, ToComputedValue};
|
||||
#[allow(unused_imports)]
|
||||
use values::{computed, specified};
|
||||
|
@ -207,7 +211,8 @@
|
|||
% endif
|
||||
}
|
||||
|
||||
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>> {
|
||||
#[allow(unused_imports)]
|
||||
use parser::parse_space_or_comma_separated;
|
||||
|
||||
|
@ -266,7 +271,7 @@
|
|||
pub mod ${property.ident} {
|
||||
% if not property.derived_from:
|
||||
#[allow(unused_imports)]
|
||||
use cssparser::Parser;
|
||||
use cssparser::{Parser, BasicParseError, Token};
|
||||
#[allow(unused_imports)]
|
||||
use parser::{Parse, ParserContext};
|
||||
#[allow(unused_imports)]
|
||||
|
@ -287,8 +292,12 @@
|
|||
#[allow(unused_imports)]
|
||||
use properties::style_structs;
|
||||
#[allow(unused_imports)]
|
||||
use selectors::parser::SelectorParseError;
|
||||
#[allow(unused_imports)]
|
||||
use stylearc::Arc;
|
||||
#[allow(unused_imports)]
|
||||
use style_traits::{ParseError, StyleParseError};
|
||||
#[allow(unused_imports)]
|
||||
use values::computed::{Context, ToComputedValue};
|
||||
#[allow(unused_imports)]
|
||||
use values::{computed, generics, specified};
|
||||
|
@ -423,12 +432,12 @@
|
|||
% endif
|
||||
}
|
||||
% if not property.derived_from:
|
||||
pub fn parse_specified(context: &ParserContext, input: &mut Parser)
|
||||
pub fn parse_specified<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
|
||||
% if property.boxed:
|
||||
-> Result<Box<SpecifiedValue>, ()> {
|
||||
-> Result<Box<SpecifiedValue>, ParseError<'i>> {
|
||||
parse(context, input).map(|result| Box::new(result))
|
||||
% else:
|
||||
-> Result<SpecifiedValue, ()> {
|
||||
-> Result<SpecifiedValue, ParseError<'i>> {
|
||||
% if property.allow_quirks:
|
||||
parse_quirky(context, input, specified::AllowQuirks::Yes)
|
||||
% else:
|
||||
|
@ -436,11 +445,11 @@
|
|||
% endif
|
||||
% endif
|
||||
}
|
||||
pub fn parse_declared(context: &ParserContext, input: &mut Parser)
|
||||
-> Result<PropertyDeclaration, ()> {
|
||||
pub fn parse_declared<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
|
||||
-> Result<PropertyDeclaration, ParseError<'i>> {
|
||||
match input.try(|i| CSSWideKeyword::parse(context, i)) {
|
||||
Ok(keyword) => Ok(PropertyDeclaration::CSSWideKeyword(LonghandId::${property.camel_case}, keyword)),
|
||||
Err(()) => {
|
||||
Err(_) => {
|
||||
input.look_for_var_functions();
|
||||
let start = input.position();
|
||||
let specified = parse_specified(context, input);
|
||||
|
@ -487,7 +496,7 @@
|
|||
use cssparser::Parser;
|
||||
use parser::{Parse, ParserContext};
|
||||
|
||||
use style_traits::ToCss;
|
||||
use style_traits::{ToCss, ParseError};
|
||||
define_css_keyword_enum! { T:
|
||||
% for value in keyword.values_for(product):
|
||||
"${value}" => ${to_rust_ident(value)},
|
||||
|
@ -495,7 +504,7 @@
|
|||
}
|
||||
|
||||
impl Parse for T {
|
||||
fn parse(_: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
|
||||
fn parse<'i, 't>(_: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
|
||||
T::parse(input)
|
||||
}
|
||||
}
|
||||
|
@ -518,7 +527,7 @@
|
|||
}
|
||||
}
|
||||
|
||||
pub fn parse(_: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
|
||||
pub fn parse<'i, 't>(_: &ParserContext, input: &mut Parser<'i, 't>) -> Result<SpecifiedValue, ParseError<'i>> {
|
||||
Ok(SpecifiedValue::Keyword(computed_value::T::parse(input)?))
|
||||
}
|
||||
|
||||
|
@ -716,14 +725,14 @@
|
|||
SpecifiedValue::${to_rust_ident(values.split()[0])}
|
||||
}
|
||||
#[inline]
|
||||
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>> {
|
||||
SpecifiedValue::parse(input)
|
||||
}
|
||||
impl Parse for SpecifiedValue {
|
||||
#[inline]
|
||||
fn parse(_context: &ParserContext, input: &mut Parser)
|
||||
-> Result<SpecifiedValue, ()> {
|
||||
fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>)
|
||||
-> Result<SpecifiedValue, ParseError<'i>> {
|
||||
SpecifiedValue::parse(input)
|
||||
}
|
||||
}
|
||||
|
@ -764,9 +773,11 @@
|
|||
use parser::ParserContext;
|
||||
use properties::{PropertyDeclaration, SourcePropertyDeclaration, MaybeBoxed};
|
||||
use properties::{ShorthandId, LonghandId, UnparsedValue, longhands};
|
||||
#[allow(unused_imports)]
|
||||
use selectors::parser::SelectorParseError;
|
||||
use std::fmt;
|
||||
use stylearc::Arc;
|
||||
use style_traits::ToCss;
|
||||
use style_traits::{ToCss, ParseError, StyleParseError};
|
||||
|
||||
pub struct Longhands {
|
||||
% for sub_property in shorthand.sub_properties:
|
||||
|
@ -838,8 +849,8 @@
|
|||
|
||||
/// Parse the given shorthand and fill the result into the
|
||||
/// `declarations` vector.
|
||||
pub fn parse_into(declarations: &mut SourcePropertyDeclaration,
|
||||
context: &ParserContext, input: &mut Parser) -> Result<(), ()> {
|
||||
pub fn parse_into<'i, 't>(declarations: &mut SourcePropertyDeclaration,
|
||||
context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<(), ParseError<'i>> {
|
||||
input.look_for_var_functions();
|
||||
let start = input.position();
|
||||
let value = input.parse_entirely(|input| parse_value(context, input));
|
||||
|
@ -872,7 +883,7 @@
|
|||
% endfor
|
||||
Ok(())
|
||||
} else {
|
||||
Err(())
|
||||
Err(StyleParseError::UnspecifiedError.into())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -890,7 +901,8 @@
|
|||
use values::generics::rect::Rect;
|
||||
use values::specified;
|
||||
|
||||
pub fn parse_value(context: &ParserContext, input: &mut Parser) -> Result<Longhands, ()> {
|
||||
pub fn parse_value<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
|
||||
-> Result<Longhands, ParseError<'i>> {
|
||||
let rect = Rect::parse_with(context, input, |_c, i| {
|
||||
% if allow_quirks:
|
||||
${parser_function}_quirky(_c, i, specified::AllowQuirks::Yes)
|
||||
|
@ -1114,7 +1126,8 @@
|
|||
use values::computed::${length_type};
|
||||
${length_type}::${initial_value}
|
||||
}
|
||||
fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
|
||||
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
|
||||
-> Result<SpecifiedValue, ParseError<'i>> {
|
||||
% if logical:
|
||||
let ret = ${length_type}::parse(context, input);
|
||||
% else:
|
||||
|
@ -1123,7 +1136,7 @@
|
|||
// Keyword values don't make sense in the block direction; don't parse them
|
||||
% if "block" in name:
|
||||
if let Ok(${length_type}::ExtremumLength(..)) = ret {
|
||||
return Err(())
|
||||
return Err(StyleParseError::UnspecifiedError.into())
|
||||
}
|
||||
% endif
|
||||
ret.map(SpecifiedValue)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue