mirror of
https://github.com/servo/servo.git
synced 2025-08-04 05:00:08 +01:00
style: Reduce some code duplication and ugliness when parsing identifiers.
This commit is contained in:
parent
ddfe8b0468
commit
e3c4d03bde
12 changed files with 104 additions and 134 deletions
|
@ -295,8 +295,7 @@ pub enum System {
|
||||||
|
|
||||||
impl Parse for System {
|
impl Parse for System {
|
||||||
fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
|
fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
|
||||||
let ident = input.expect_ident()?;
|
try_match_ident_ignore_ascii_case! { input.expect_ident()?,
|
||||||
(match_ignore_ascii_case! { &ident,
|
|
||||||
"cyclic" => Ok(System::Cyclic),
|
"cyclic" => Ok(System::Cyclic),
|
||||||
"numeric" => Ok(System::Numeric),
|
"numeric" => Ok(System::Numeric),
|
||||||
"alphabetic" => Ok(System::Alphabetic),
|
"alphabetic" => Ok(System::Alphabetic),
|
||||||
|
@ -310,8 +309,7 @@ impl Parse for System {
|
||||||
let other = parse_counter_style_name(input)?;
|
let other = parse_counter_style_name(input)?;
|
||||||
Ok(System::Extends(other))
|
Ok(System::Extends(other))
|
||||||
}
|
}
|
||||||
_ => Err(())
|
}
|
||||||
}).map_err(|()| SelectorParseError::UnexpectedIdent(ident).into())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -617,9 +615,9 @@ pub enum SpeakAs {
|
||||||
impl Parse for SpeakAs {
|
impl Parse for SpeakAs {
|
||||||
fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
|
fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
|
||||||
let mut is_spell_out = false;
|
let mut is_spell_out = false;
|
||||||
let result: Result<_, ParseError> = input.try(|input| {
|
let result = input.try(|input| {
|
||||||
let ident = input.expect_ident()?;
|
let ident = input.expect_ident().map_err(|_| ())?;
|
||||||
(match_ignore_ascii_case! { &ident,
|
match_ignore_ascii_case! { &*ident,
|
||||||
"auto" => Ok(SpeakAs::Auto),
|
"auto" => Ok(SpeakAs::Auto),
|
||||||
"bullets" => Ok(SpeakAs::Bullets),
|
"bullets" => Ok(SpeakAs::Bullets),
|
||||||
"numbers" => Ok(SpeakAs::Numbers),
|
"numbers" => Ok(SpeakAs::Numbers),
|
||||||
|
@ -628,8 +626,8 @@ impl Parse for SpeakAs {
|
||||||
is_spell_out = true;
|
is_spell_out = true;
|
||||||
Err(())
|
Err(())
|
||||||
}
|
}
|
||||||
_ => Err(())
|
_ => Err(()),
|
||||||
}).map_err(|()| SelectorParseError::UnexpectedIdent(ident).into())
|
}
|
||||||
});
|
});
|
||||||
if is_spell_out {
|
if is_spell_out {
|
||||||
// spell-out is not supported, but don’t parse it as a <counter-style-name>.
|
// spell-out is not supported, but don’t parse it as a <counter-style-name>.
|
||||||
|
|
|
@ -4,6 +4,24 @@
|
||||||
|
|
||||||
//! Various macro helpers.
|
//! Various macro helpers.
|
||||||
|
|
||||||
|
/// A macro to parse an identifier, or return an `UnexpectedIndent` error
|
||||||
|
/// otherwise.
|
||||||
|
///
|
||||||
|
/// FIXME(emilio): The fact that `UnexpectedIdent` is a `SelectorParseError`
|
||||||
|
/// doesn't make a lot of sense to me.
|
||||||
|
macro_rules! try_match_ident_ignore_ascii_case {
|
||||||
|
($ident:expr, $( $match_body:tt )*) => {
|
||||||
|
let __ident = $ident;
|
||||||
|
(match_ignore_ascii_case! { &*__ident,
|
||||||
|
$( $match_body )*
|
||||||
|
_ => Err(()),
|
||||||
|
})
|
||||||
|
.map_err(|()| {
|
||||||
|
::selectors::parser::SelectorParseError::UnexpectedIdent(__ident).into()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
macro_rules! define_numbered_css_keyword_enum {
|
macro_rules! define_numbered_css_keyword_enum {
|
||||||
($name: ident: $( $css: expr => $variant: ident = $value: expr ),+,) => {
|
($name: ident: $( $css: expr => $variant: ident = $value: expr ),+,) => {
|
||||||
define_numbered_css_keyword_enum!($name: $( $css => $variant = $value ),+);
|
define_numbered_css_keyword_enum!($name: $( $css => $variant = $value ),+);
|
||||||
|
@ -21,11 +39,9 @@ macro_rules! define_numbered_css_keyword_enum {
|
||||||
fn parse<'i, 't>(_context: &$crate::parser::ParserContext,
|
fn parse<'i, 't>(_context: &$crate::parser::ParserContext,
|
||||||
input: &mut ::cssparser::Parser<'i, 't>)
|
input: &mut ::cssparser::Parser<'i, 't>)
|
||||||
-> Result<$name, ::style_traits::ParseError<'i>> {
|
-> Result<$name, ::style_traits::ParseError<'i>> {
|
||||||
let ident = try!(input.expect_ident());
|
try_match_ident_ignore_ascii_case! { input.expect_ident()?,
|
||||||
(match_ignore_ascii_case! { &ident,
|
|
||||||
$( $css => Ok($name::$variant), )+
|
$( $css => Ok($name::$variant), )+
|
||||||
_ => Err(())
|
}
|
||||||
}).map_err(|()| ::selectors::parser::SelectorParseError::UnexpectedIdent(ident).into())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -115,15 +115,13 @@
|
||||||
/// Parse a display value.
|
/// Parse a display value.
|
||||||
pub fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>)
|
pub fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>)
|
||||||
-> Result<SpecifiedValue, ParseError<'i>> {
|
-> Result<SpecifiedValue, ParseError<'i>> {
|
||||||
let ident = try!(input.expect_ident());
|
try_match_ident_ignore_ascii_case! { input.expect_ident()?,
|
||||||
(match_ignore_ascii_case! { &ident,
|
|
||||||
% for value in values:
|
% for value in values:
|
||||||
"${value}" => {
|
"${value}" => {
|
||||||
Ok(computed_value::T::${to_rust_ident(value)})
|
Ok(computed_value::T::${to_rust_ident(value)})
|
||||||
},
|
},
|
||||||
% endfor
|
% endfor
|
||||||
_ => Err(())
|
}
|
||||||
}).map_err(|()| SelectorParseError::UnexpectedIdent(ident).into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ComputedValueAsSpecified for SpecifiedValue {}
|
impl ComputedValueAsSpecified for SpecifiedValue {}
|
||||||
|
@ -295,17 +293,15 @@ ${helpers.single_keyword("position", "static absolute relative fixed",
|
||||||
/// | <percentage> | <length>
|
/// | <percentage> | <length>
|
||||||
pub fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
|
pub fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
|
||||||
-> Result<SpecifiedValue, ParseError<'i>> {
|
-> Result<SpecifiedValue, ParseError<'i>> {
|
||||||
input.try(|i| specified::LengthOrPercentage::parse_quirky(context, i, AllowQuirks::Yes))
|
if let Ok(lop) = input.try(|i| specified::LengthOrPercentage::parse_quirky(context, i, AllowQuirks::Yes)) {
|
||||||
.map(SpecifiedValue::LengthOrPercentage)
|
return Ok(SpecifiedValue::LengthOrPercentage(lop));
|
||||||
.or_else(|_| {
|
}
|
||||||
let ident = try!(input.expect_ident());
|
|
||||||
(match_ignore_ascii_case! { &ident,
|
try_match_ident_ignore_ascii_case! { input.expect_ident()?,
|
||||||
% for keyword in vertical_align_keywords:
|
% for keyword in vertical_align_keywords:
|
||||||
"${keyword}" => Ok(SpecifiedValue::${to_rust_ident(keyword)}),
|
"${keyword}" => Ok(SpecifiedValue::${to_rust_ident(keyword)}),
|
||||||
% endfor
|
% endfor
|
||||||
_ => Err(())
|
}
|
||||||
}).map_err(|()| SelectorParseError::UnexpectedIdent(ident).into())
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The computed value for `vertical-align`.
|
/// The computed value for `vertical-align`.
|
||||||
|
@ -1997,8 +1993,7 @@ ${helpers.predefined_type("shape-outside", "basic_shape::FloatAreaShape",
|
||||||
|
|
||||||
pub fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>)
|
pub fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>)
|
||||||
-> Result<SpecifiedValue, ParseError<'i>> {
|
-> Result<SpecifiedValue, ParseError<'i>> {
|
||||||
let ident = input.expect_ident()?;
|
try_match_ident_ignore_ascii_case! { input.expect_ident()?,
|
||||||
(match_ignore_ascii_case! { &ident,
|
|
||||||
"auto" => Ok(TOUCH_ACTION_AUTO),
|
"auto" => Ok(TOUCH_ACTION_AUTO),
|
||||||
"none" => Ok(TOUCH_ACTION_NONE),
|
"none" => Ok(TOUCH_ACTION_NONE),
|
||||||
"manipulation" => Ok(TOUCH_ACTION_MANIPULATION),
|
"manipulation" => Ok(TOUCH_ACTION_MANIPULATION),
|
||||||
|
@ -2016,8 +2011,7 @@ ${helpers.predefined_type("shape-outside", "basic_shape::FloatAreaShape",
|
||||||
Ok(TOUCH_ACTION_PAN_Y)
|
Ok(TOUCH_ACTION_PAN_Y)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_ => Err(()),
|
}
|
||||||
}).map_err(|()| SelectorParseError::UnexpectedIdent(ident).into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
|
|
|
@ -5,8 +5,7 @@
|
||||||
<%namespace name="helpers" file="/helpers.mako.rs" />
|
<%namespace name="helpers" file="/helpers.mako.rs" />
|
||||||
<% from data import Method, to_camel_case, to_rust_ident, to_camel_case_lower, SYSTEM_FONT_LONGHANDS %>
|
<% from data import Method, to_camel_case, to_rust_ident, to_camel_case_lower, SYSTEM_FONT_LONGHANDS %>
|
||||||
|
|
||||||
<% data.new_style_struct("Font",
|
<% data.new_style_struct("Font", inherited=True) %>
|
||||||
inherited=True) %>
|
|
||||||
|
|
||||||
<%def name="nongecko_unreachable()">
|
<%def name="nongecko_unreachable()">
|
||||||
%if product == "gecko":
|
%if product == "gecko":
|
||||||
|
@ -447,15 +446,15 @@ ${helpers.single_keyword_system("font-variant-caps",
|
||||||
/// normal | bold | bolder | lighter | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900
|
/// normal | bold | bolder | lighter | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900
|
||||||
pub fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>)
|
pub fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>)
|
||||||
-> Result<SpecifiedValue, ParseError<'i>> {
|
-> Result<SpecifiedValue, ParseError<'i>> {
|
||||||
let result: Result<_, ParseError> = input.try(|input| {
|
let result = input.try(|input| {
|
||||||
let ident = try!(input.expect_ident());
|
let ident = input.expect_ident().map_err(|_| ())?;
|
||||||
(match_ignore_ascii_case! { &ident,
|
match_ignore_ascii_case! { &ident,
|
||||||
"normal" => Ok(SpecifiedValue::Normal),
|
"normal" => Ok(SpecifiedValue::Normal),
|
||||||
"bold" => Ok(SpecifiedValue::Bold),
|
"bold" => Ok(SpecifiedValue::Bold),
|
||||||
"bolder" => Ok(SpecifiedValue::Bolder),
|
"bolder" => Ok(SpecifiedValue::Bolder),
|
||||||
"lighter" => Ok(SpecifiedValue::Lighter),
|
"lighter" => Ok(SpecifiedValue::Lighter),
|
||||||
_ => Err(())
|
_ => Err(())
|
||||||
}).map_err(|()| SelectorParseError::UnexpectedIdent(ident).into())
|
}
|
||||||
});
|
});
|
||||||
result.or_else(|_| {
|
result.or_else(|_| {
|
||||||
SpecifiedValue::from_int(input.expect_integer()?)
|
SpecifiedValue::from_int(input.expect_integer()?)
|
||||||
|
@ -689,8 +688,7 @@ ${helpers.single_keyword_system("font-variant-caps",
|
||||||
|
|
||||||
impl KeywordSize {
|
impl KeywordSize {
|
||||||
pub fn parse<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
|
pub fn parse<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
|
||||||
let ident = input.expect_ident()?;
|
try_match_ident_ignore_ascii_case! { input.expect_ident()?,
|
||||||
(match_ignore_ascii_case! {&*ident,
|
|
||||||
"xx-small" => Ok(XXSmall),
|
"xx-small" => Ok(XXSmall),
|
||||||
"x-small" => Ok(XSmall),
|
"x-small" => Ok(XSmall),
|
||||||
"small" => Ok(Small),
|
"small" => Ok(Small),
|
||||||
|
@ -698,8 +696,7 @@ ${helpers.single_keyword_system("font-variant-caps",
|
||||||
"large" => Ok(Large),
|
"large" => Ok(Large),
|
||||||
"x-large" => Ok(XLarge),
|
"x-large" => Ok(XLarge),
|
||||||
"xx-large" => Ok(XXLarge),
|
"xx-large" => Ok(XXLarge),
|
||||||
_ => Err(())
|
}
|
||||||
}).map_err(|()| SelectorParseError::UnexpectedIdent(ident).into())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -931,12 +928,10 @@ ${helpers.single_keyword_system("font-variant-caps",
|
||||||
return Ok(SpecifiedValue::Keyword(kw, 1.))
|
return Ok(SpecifiedValue::Keyword(kw, 1.))
|
||||||
}
|
}
|
||||||
|
|
||||||
let ident = input.expect_ident()?;
|
try_match_ident_ignore_ascii_case! { input.expect_ident()?,
|
||||||
(match_ignore_ascii_case! {&*ident,
|
|
||||||
"smaller" => Ok(SpecifiedValue::Smaller),
|
"smaller" => Ok(SpecifiedValue::Smaller),
|
||||||
"larger" => Ok(SpecifiedValue::Larger),
|
"larger" => Ok(SpecifiedValue::Larger),
|
||||||
_ => Err(())
|
}
|
||||||
}).map_err(|()| SelectorParseError::UnexpectedIdent(ident).into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SpecifiedValue {
|
impl SpecifiedValue {
|
||||||
|
@ -1212,8 +1207,7 @@ ${helpers.single_keyword_system("font-variant-caps",
|
||||||
pub fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>)
|
pub fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>)
|
||||||
-> Result<SpecifiedValue, ParseError<'i>> {
|
-> Result<SpecifiedValue, ParseError<'i>> {
|
||||||
let mut result = SpecifiedValue { weight: false, style: false };
|
let mut result = SpecifiedValue { weight: false, style: false };
|
||||||
let ident = try!(input.expect_ident());
|
try_match_ident_ignore_ascii_case! { input.expect_ident()?,
|
||||||
(match_ignore_ascii_case! { &ident,
|
|
||||||
"none" => Ok(result),
|
"none" => Ok(result),
|
||||||
"weight" => {
|
"weight" => {
|
||||||
result.weight = true;
|
result.weight = true;
|
||||||
|
@ -1229,8 +1223,7 @@ ${helpers.single_keyword_system("font-variant-caps",
|
||||||
}
|
}
|
||||||
Ok(result)
|
Ok(result)
|
||||||
},
|
},
|
||||||
_ => Err(())
|
}
|
||||||
}).map_err(|()| SelectorParseError::UnexpectedIdent(ident).into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
|
@ -2343,7 +2336,6 @@ ${helpers.single_keyword("-moz-math-variant",
|
||||||
use app_units::Au;
|
use app_units::Au;
|
||||||
use cssparser::Parser;
|
use cssparser::Parser;
|
||||||
use properties::longhands;
|
use properties::longhands;
|
||||||
use selectors::parser::SelectorParseError;
|
|
||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
use style_traits::ParseError;
|
use style_traits::ParseError;
|
||||||
use values::computed::{ToComputedValue, Context};
|
use values::computed::{ToComputedValue, Context};
|
||||||
|
@ -2465,13 +2457,11 @@ ${helpers.single_keyword("-moz-math-variant",
|
||||||
|
|
||||||
impl SystemFont {
|
impl SystemFont {
|
||||||
pub fn parse<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
|
pub fn parse<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
|
||||||
let ident = input.expect_ident()?;
|
try_match_ident_ignore_ascii_case! { input.expect_ident()?,
|
||||||
(match_ignore_ascii_case! { &*ident,
|
|
||||||
% for font in system_fonts:
|
% for font in system_fonts:
|
||||||
"${font}" => Ok(SystemFont::${to_camel_case(font)}),
|
"${font}" => Ok(SystemFont::${to_camel_case(font)}),
|
||||||
% endfor
|
% endfor
|
||||||
_ => Err(())
|
}
|
||||||
}).map_err(|()| SelectorParseError::UnexpectedIdent(ident).into())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -195,15 +195,12 @@ ${helpers.predefined_type("marker-end", "UrlOrNone", "Either::Second(None_)",
|
||||||
let mut pos = 0;
|
let mut pos = 0;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
|
|
||||||
let result: Result<_, ParseError> = input.try(|i| {
|
let result: Result<_, ParseError> = input.try(|i| {
|
||||||
let ident = i.expect_ident()?;
|
try_match_ident_ignore_ascii_case! { i.expect_ident()?,
|
||||||
(match_ignore_ascii_case! { &ident,
|
|
||||||
"fill" => Ok(FILL),
|
"fill" => Ok(FILL),
|
||||||
"stroke" => Ok(STROKE),
|
"stroke" => Ok(STROKE),
|
||||||
"markers" => Ok(MARKERS),
|
"markers" => Ok(MARKERS),
|
||||||
_ => Err(())
|
}
|
||||||
}).map_err(|()| SelectorParseError::UnexpectedIdent(ident.into()).into())
|
|
||||||
});
|
});
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
|
|
|
@ -106,7 +106,7 @@
|
||||||
}
|
}
|
||||||
pub fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
|
pub fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
|
||||||
-> Result<SpecifiedValue, ParseError<'i>> {
|
-> Result<SpecifiedValue, ParseError<'i>> {
|
||||||
let first = try!(Side::parse(context, input));
|
let first = Side::parse(context, input)?;
|
||||||
let second = input.try(|input| Side::parse(context, input)).ok();
|
let second = input.try(|input| Side::parse(context, input)).ok();
|
||||||
Ok(SpecifiedValue {
|
Ok(SpecifiedValue {
|
||||||
first: first,
|
first: first,
|
||||||
|
@ -116,14 +116,17 @@
|
||||||
impl Parse for Side {
|
impl Parse for Side {
|
||||||
fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>)
|
fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>)
|
||||||
-> Result<Side, ParseError<'i>> {
|
-> Result<Side, ParseError<'i>> {
|
||||||
if let Ok(ident) = input.try(|input| input.expect_ident()) {
|
match input.next()? {
|
||||||
(match_ignore_ascii_case! { &ident,
|
Token::Ident(ident) => {
|
||||||
|
try_match_ident_ignore_ascii_case! { ident,
|
||||||
"clip" => Ok(Side::Clip),
|
"clip" => Ok(Side::Clip),
|
||||||
"ellipsis" => Ok(Side::Ellipsis),
|
"ellipsis" => Ok(Side::Ellipsis),
|
||||||
_ => Err(())
|
}
|
||||||
}).map_err(|()| SelectorParseError::UnexpectedIdent(ident).into())
|
}
|
||||||
} else {
|
Token::QuotedString(v) => {
|
||||||
Ok(Side::String(try!(input.expect_string()).into_owned().into_boxed_str()))
|
Ok(Side::String(v.into_owned().into_boxed_str()))
|
||||||
|
}
|
||||||
|
other => Err(BasicParseError::UnexpectedToken(other).into()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,9 +15,7 @@
|
||||||
-> Result<Longhands, ParseError<'i>> {
|
-> Result<Longhands, ParseError<'i>> {
|
||||||
% if product == "gecko":
|
% if product == "gecko":
|
||||||
let moz_kw_found = input.try(|i| {
|
let moz_kw_found = input.try(|i| {
|
||||||
let ident = i.expect_ident()?;
|
try_match_ident_ignore_ascii_case! { i.expect_ident()?,
|
||||||
(match_ignore_ascii_case! {
|
|
||||||
&ident,
|
|
||||||
"-moz-scrollbars-horizontal" => {
|
"-moz-scrollbars-horizontal" => {
|
||||||
Ok(expanded! {
|
Ok(expanded! {
|
||||||
overflow_x: SpecifiedValue::scroll,
|
overflow_x: SpecifiedValue::scroll,
|
||||||
|
@ -36,14 +34,13 @@
|
||||||
overflow_y: SpecifiedValue::hidden,
|
overflow_y: SpecifiedValue::hidden,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
_ => Err(())
|
}
|
||||||
}).map_err(|()| SelectorParseError::UnexpectedIdent(ident).into())
|
|
||||||
});
|
});
|
||||||
if moz_kw_found.is_ok() {
|
if moz_kw_found.is_ok() {
|
||||||
return moz_kw_found
|
return moz_kw_found
|
||||||
}
|
}
|
||||||
% endif
|
% endif
|
||||||
let overflow = try!(parse_overflow(context, input));
|
let overflow = parse_overflow(context, input)?;
|
||||||
Ok(expanded! {
|
Ok(expanded! {
|
||||||
overflow_x: overflow,
|
overflow_x: overflow,
|
||||||
overflow_y: overflow,
|
overflow_y: overflow,
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
|
|
||||||
use cssparser::{Parser, serialize_identifier};
|
use cssparser::{Parser, serialize_identifier};
|
||||||
use parser::{Parse, ParserContext};
|
use parser::{Parse, ParserContext};
|
||||||
use selectors::parser::SelectorParseError;
|
|
||||||
use std::{fmt, mem, usize};
|
use std::{fmt, mem, usize};
|
||||||
use style_traits::{ToCss, ParseError, StyleParseError};
|
use style_traits::{ToCss, ParseError, StyleParseError};
|
||||||
use values::{CSSFloat, CustomIdent};
|
use values::{CSSFloat, CustomIdent};
|
||||||
|
@ -350,12 +349,10 @@ impl Parse for RepeatCount {
|
||||||
Err(StyleParseError::UnspecifiedError.into())
|
Err(StyleParseError::UnspecifiedError.into())
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let ident = input.expect_ident()?;
|
try_match_ident_ignore_ascii_case! { input.expect_ident()?,
|
||||||
(match_ignore_ascii_case! { &ident,
|
|
||||||
"auto-fill" => Ok(RepeatCount::AutoFill),
|
"auto-fill" => Ok(RepeatCount::AutoFill),
|
||||||
"auto-fit" => Ok(RepeatCount::AutoFit),
|
"auto-fit" => Ok(RepeatCount::AutoFit),
|
||||||
_ => Err(()),
|
}
|
||||||
}).map_err(|()| SelectorParseError::UnexpectedIdent(ident).into())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
use counter_style::{Symbols, parse_counter_style_name};
|
use counter_style::{Symbols, parse_counter_style_name};
|
||||||
use cssparser::Parser;
|
use cssparser::Parser;
|
||||||
use parser::{Parse, ParserContext};
|
use parser::{Parse, ParserContext};
|
||||||
use selectors::parser::SelectorParseError;
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use style_traits::{OneOrMoreCommaSeparated, ToCss, ParseError, StyleParseError};
|
use style_traits::{OneOrMoreCommaSeparated, ToCss, ParseError, StyleParseError};
|
||||||
use super::CustomIdent;
|
use super::CustomIdent;
|
||||||
|
@ -328,13 +327,11 @@ impl<ColorType> SVGPaint<ColorType> {
|
||||||
impl<ColorType> SVGPaintKind<ColorType> {
|
impl<ColorType> SVGPaintKind<ColorType> {
|
||||||
/// Parse a keyword value only
|
/// Parse a keyword value only
|
||||||
fn parse_ident<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
|
fn parse_ident<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
|
||||||
let ident = input.expect_ident()?;
|
try_match_ident_ignore_ascii_case! { input.expect_ident()?,
|
||||||
(match_ignore_ascii_case! { &ident,
|
|
||||||
"none" => Ok(SVGPaintKind::None),
|
"none" => Ok(SVGPaintKind::None),
|
||||||
"context-fill" => Ok(SVGPaintKind::ContextFill),
|
"context-fill" => Ok(SVGPaintKind::ContextFill),
|
||||||
"context-stroke" => Ok(SVGPaintKind::ContextStroke),
|
"context-stroke" => Ok(SVGPaintKind::ContextStroke),
|
||||||
_ => Err(())
|
}
|
||||||
}).map_err(|()| SelectorParseError::UnexpectedIdent(ident).into())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -343,13 +343,11 @@ fn parse_auto_normal_stretch_baseline<'i, 't>(input: &mut Parser<'i, 't>)
|
||||||
return Ok(baseline);
|
return Ok(baseline);
|
||||||
}
|
}
|
||||||
|
|
||||||
let ident = input.expect_ident()?;
|
try_match_ident_ignore_ascii_case! { input.expect_ident()?,
|
||||||
(match_ignore_ascii_case! { &ident,
|
|
||||||
"auto" => Ok(ALIGN_AUTO),
|
"auto" => Ok(ALIGN_AUTO),
|
||||||
"normal" => Ok(ALIGN_NORMAL),
|
"normal" => Ok(ALIGN_NORMAL),
|
||||||
"stretch" => Ok(ALIGN_STRETCH),
|
"stretch" => Ok(ALIGN_STRETCH),
|
||||||
_ => Err(())
|
}
|
||||||
}).map_err(|()| SelectorParseError::UnexpectedIdent(ident).into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// normal | stretch | <baseline-position>
|
// normal | stretch | <baseline-position>
|
||||||
|
@ -358,12 +356,10 @@ fn parse_normal_stretch_baseline<'i, 't>(input: &mut Parser<'i, 't>) -> Result<A
|
||||||
return Ok(baseline);
|
return Ok(baseline);
|
||||||
}
|
}
|
||||||
|
|
||||||
let ident = input.expect_ident()?;
|
try_match_ident_ignore_ascii_case! { input.expect_ident()?,
|
||||||
(match_ignore_ascii_case! { &ident,
|
|
||||||
"normal" => Ok(ALIGN_NORMAL),
|
"normal" => Ok(ALIGN_NORMAL),
|
||||||
"stretch" => Ok(ALIGN_STRETCH),
|
"stretch" => Ok(ALIGN_STRETCH),
|
||||||
_ => Err(())
|
}
|
||||||
}).map_err(|()| SelectorParseError::UnexpectedIdent(ident).into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// normal | <baseline-position>
|
// normal | <baseline-position>
|
||||||
|
@ -372,34 +368,33 @@ fn parse_normal_or_baseline<'i, 't>(input: &mut Parser<'i, 't>) -> Result<AlignF
|
||||||
return Ok(baseline);
|
return Ok(baseline);
|
||||||
}
|
}
|
||||||
|
|
||||||
let ident = input.expect_ident()?;
|
input.expect_ident_matching("normal")?;
|
||||||
(match_ignore_ascii_case! { &ident,
|
Ok(ALIGN_NORMAL)
|
||||||
"normal" => Ok(ALIGN_NORMAL),
|
|
||||||
_ => Err(())
|
|
||||||
}).map_err(|()| SelectorParseError::UnexpectedIdent(ident).into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// <baseline-position>
|
// <baseline-position>
|
||||||
fn parse_baseline<'i, 't>(input: &mut Parser<'i, 't>) -> Result<AlignFlags, ParseError<'i>> {
|
fn parse_baseline<'i, 't>(input: &mut Parser<'i, 't>) -> Result<AlignFlags, ParseError<'i>> {
|
||||||
let ident = input.expect_ident()?;
|
try_match_ident_ignore_ascii_case! { input.expect_ident()?,
|
||||||
(match_ignore_ascii_case! { &ident,
|
|
||||||
"baseline" => Ok(ALIGN_BASELINE),
|
"baseline" => Ok(ALIGN_BASELINE),
|
||||||
"first" => return input.expect_ident_matching("baseline").map(|_| ALIGN_BASELINE).map_err(|e| e.into()),
|
"first" => {
|
||||||
"last" => return input.expect_ident_matching("baseline").map(|_| ALIGN_LAST_BASELINE).map_err(|e| e.into()),
|
input.expect_ident_matching("baseline")?;
|
||||||
_ => Err(())
|
Ok(ALIGN_BASELINE)
|
||||||
}).map_err(|()| SelectorParseError::UnexpectedIdent(ident).into())
|
}
|
||||||
|
"last" => {
|
||||||
|
input.expect_ident_matching("baseline")?;
|
||||||
|
Ok(ALIGN_LAST_BASELINE)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// <content-distribution>
|
// <content-distribution>
|
||||||
fn parse_content_distribution<'i, 't>(input: &mut Parser<'i, 't>) -> Result<AlignFlags, ParseError<'i>> {
|
fn parse_content_distribution<'i, 't>(input: &mut Parser<'i, 't>) -> Result<AlignFlags, ParseError<'i>> {
|
||||||
let ident = input.expect_ident()?;
|
try_match_ident_ignore_ascii_case! { input.expect_ident()?,
|
||||||
(match_ignore_ascii_case! { &ident,
|
|
||||||
"stretch" => Ok(ALIGN_STRETCH),
|
"stretch" => Ok(ALIGN_STRETCH),
|
||||||
"space-between" => Ok(ALIGN_SPACE_BETWEEN),
|
"space-between" => Ok(ALIGN_SPACE_BETWEEN),
|
||||||
"space-around" => Ok(ALIGN_SPACE_AROUND),
|
"space-around" => Ok(ALIGN_SPACE_AROUND),
|
||||||
"space-evenly" => Ok(ALIGN_SPACE_EVENLY),
|
"space-evenly" => Ok(ALIGN_SPACE_EVENLY),
|
||||||
_ => Err(())
|
}
|
||||||
}).map_err(|()| SelectorParseError::UnexpectedIdent(ident).into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// [ <overflow-position>? && <content-position> ]
|
// [ <overflow-position>? && <content-position> ]
|
||||||
|
@ -422,8 +417,7 @@ fn parse_overflow_content_position<'i, 't>(input: &mut Parser<'i, 't>) -> Result
|
||||||
|
|
||||||
// <content-position>
|
// <content-position>
|
||||||
fn parse_content_position<'i, 't>(input: &mut Parser<'i, 't>) -> Result<AlignFlags, ParseError<'i>> {
|
fn parse_content_position<'i, 't>(input: &mut Parser<'i, 't>) -> Result<AlignFlags, ParseError<'i>> {
|
||||||
let ident = input.expect_ident()?;
|
try_match_ident_ignore_ascii_case! { input.expect_ident()?,
|
||||||
(match_ignore_ascii_case! { &ident,
|
|
||||||
"start" => Ok(ALIGN_START),
|
"start" => Ok(ALIGN_START),
|
||||||
"end" => Ok(ALIGN_END),
|
"end" => Ok(ALIGN_END),
|
||||||
"flex-start" => Ok(ALIGN_FLEX_START),
|
"flex-start" => Ok(ALIGN_FLEX_START),
|
||||||
|
@ -431,18 +425,15 @@ fn parse_content_position<'i, 't>(input: &mut Parser<'i, 't>) -> Result<AlignFla
|
||||||
"center" => Ok(ALIGN_CENTER),
|
"center" => Ok(ALIGN_CENTER),
|
||||||
"left" => Ok(ALIGN_LEFT),
|
"left" => Ok(ALIGN_LEFT),
|
||||||
"right" => Ok(ALIGN_RIGHT),
|
"right" => Ok(ALIGN_RIGHT),
|
||||||
_ => Err(())
|
}
|
||||||
}).map_err(|()| SelectorParseError::UnexpectedIdent(ident).into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// <overflow-position>
|
// <overflow-position>
|
||||||
fn parse_overflow_position<'i, 't>(input: &mut Parser<'i, 't>) -> Result<AlignFlags, ParseError<'i>> {
|
fn parse_overflow_position<'i, 't>(input: &mut Parser<'i, 't>) -> Result<AlignFlags, ParseError<'i>> {
|
||||||
let ident = input.expect_ident()?;
|
try_match_ident_ignore_ascii_case! { input.expect_ident()?,
|
||||||
(match_ignore_ascii_case! { &ident,
|
|
||||||
"safe" => Ok(ALIGN_SAFE),
|
"safe" => Ok(ALIGN_SAFE),
|
||||||
"unsafe" => Ok(ALIGN_UNSAFE),
|
"unsafe" => Ok(ALIGN_UNSAFE),
|
||||||
_ => Err(())
|
}
|
||||||
}).map_err(|()| SelectorParseError::UnexpectedIdent(ident).into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// [ <overflow-position>? && <self-position> ]
|
// [ <overflow-position>? && <self-position> ]
|
||||||
|
@ -465,8 +456,7 @@ fn parse_overflow_self_position<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Al
|
||||||
|
|
||||||
// <self-position>
|
// <self-position>
|
||||||
fn parse_self_position<'i, 't>(input: &mut Parser<'i, 't>) -> Result<AlignFlags, ParseError<'i>> {
|
fn parse_self_position<'i, 't>(input: &mut Parser<'i, 't>) -> Result<AlignFlags, ParseError<'i>> {
|
||||||
let ident = input.expect_ident()?;
|
try_match_ident_ignore_ascii_case! { input.expect_ident()?,
|
||||||
(match_ignore_ascii_case! { &ident,
|
|
||||||
"start" => Ok(ALIGN_START),
|
"start" => Ok(ALIGN_START),
|
||||||
"end" => Ok(ALIGN_END),
|
"end" => Ok(ALIGN_END),
|
||||||
"flex-start" => Ok(ALIGN_FLEX_START),
|
"flex-start" => Ok(ALIGN_FLEX_START),
|
||||||
|
@ -476,8 +466,7 @@ fn parse_self_position<'i, 't>(input: &mut Parser<'i, 't>) -> Result<AlignFlags,
|
||||||
"right" => Ok(ALIGN_RIGHT),
|
"right" => Ok(ALIGN_RIGHT),
|
||||||
"self-start" => Ok(ALIGN_SELF_START),
|
"self-start" => Ok(ALIGN_SELF_START),
|
||||||
"self-end" => Ok(ALIGN_SELF_END),
|
"self-end" => Ok(ALIGN_SELF_END),
|
||||||
_ => Err(())
|
}
|
||||||
}).map_err(|()| SelectorParseError::UnexpectedIdent(ident).into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// [ legacy && [ left | right | center ] ]
|
// [ legacy && [ left | right | center ] ]
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
|
|
||||||
use cssparser::Parser;
|
use cssparser::Parser;
|
||||||
use parser::{Parse, ParserContext};
|
use parser::{Parse, ParserContext};
|
||||||
use selectors::parser::SelectorParseError;
|
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use style_traits::{ToCss, ParseError, StyleParseError};
|
use style_traits::{ToCss, ParseError, StyleParseError};
|
||||||
|
@ -91,13 +90,11 @@ impl Parse for GeometryBox {
|
||||||
return Ok(GeometryBox::ShapeBox(shape_box))
|
return Ok(GeometryBox::ShapeBox(shape_box))
|
||||||
}
|
}
|
||||||
|
|
||||||
let ident = input.expect_ident()?;
|
try_match_ident_ignore_ascii_case! { input.expect_ident()?,
|
||||||
(match_ignore_ascii_case! { &ident,
|
|
||||||
"fill-box" => Ok(GeometryBox::FillBox),
|
"fill-box" => Ok(GeometryBox::FillBox),
|
||||||
"stroke-box" => Ok(GeometryBox::StrokeBox),
|
"stroke-box" => Ok(GeometryBox::StrokeBox),
|
||||||
"view-box" => Ok(GeometryBox::ViewBox),
|
"view-box" => Ok(GeometryBox::ViewBox),
|
||||||
_ => Err(())
|
}
|
||||||
}).map_err(|()| SelectorParseError::UnexpectedIdent(ident).into())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -231,12 +228,10 @@ impl Parse for ShapeRadius {
|
||||||
return Ok(GenericShapeRadius::Length(lop))
|
return Ok(GenericShapeRadius::Length(lop))
|
||||||
}
|
}
|
||||||
|
|
||||||
let ident = input.expect_ident()?;
|
try_match_ident_ignore_ascii_case! { input.expect_ident()?,
|
||||||
(match_ignore_ascii_case! { &ident,
|
|
||||||
"closest-side" => Ok(GenericShapeRadius::ClosestSide),
|
"closest-side" => Ok(GenericShapeRadius::ClosestSide),
|
||||||
"farthest-side" => Ok(GenericShapeRadius::FarthestSide),
|
"farthest-side" => Ok(GenericShapeRadius::FarthestSide),
|
||||||
_ => Err(())
|
}
|
||||||
}).map_err(|()| SelectorParseError::UnexpectedIdent(ident).into())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
use app_units::Au;
|
use app_units::Au;
|
||||||
use cssparser::Parser;
|
use cssparser::Parser;
|
||||||
use parser::{Parse, ParserContext};
|
use parser::{Parse, ParserContext};
|
||||||
use selectors::parser::SelectorParseError;
|
|
||||||
use style_traits::ParseError;
|
use style_traits::ParseError;
|
||||||
use values::computed::{Context, ToComputedValue};
|
use values::computed::{Context, ToComputedValue};
|
||||||
use values::generics::border::BorderCornerRadius as GenericBorderCornerRadius;
|
use values::generics::border::BorderCornerRadius as GenericBorderCornerRadius;
|
||||||
|
@ -58,13 +57,11 @@ impl BorderSideWidth {
|
||||||
if let Ok(length) = input.try(|i| Length::parse_non_negative_quirky(context, i, allow_quirks)) {
|
if let Ok(length) = input.try(|i| Length::parse_non_negative_quirky(context, i, allow_quirks)) {
|
||||||
return Ok(BorderSideWidth::Length(length));
|
return Ok(BorderSideWidth::Length(length));
|
||||||
}
|
}
|
||||||
let ident = input.expect_ident()?;
|
try_match_ident_ignore_ascii_case! { input.expect_ident()?,
|
||||||
(match_ignore_ascii_case! { &ident,
|
|
||||||
"thin" => Ok(BorderSideWidth::Thin),
|
"thin" => Ok(BorderSideWidth::Thin),
|
||||||
"medium" => Ok(BorderSideWidth::Medium),
|
"medium" => Ok(BorderSideWidth::Medium),
|
||||||
"thick" => Ok(BorderSideWidth::Thick),
|
"thick" => Ok(BorderSideWidth::Thick),
|
||||||
_ => Err(())
|
}
|
||||||
}).map_err(|()| SelectorParseError::UnexpectedIdent(ident).into())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue