style: Use a more consistent style for parsing functions.

This commit is contained in:
Emilio Cobos Álvarez 2018-04-02 02:19:59 +02:00
parent 39018f9339
commit 15c416b133
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
14 changed files with 126 additions and 69 deletions

View file

@ -139,8 +139,10 @@ ${helpers.single_keyword("mask-origin",
background_size::get_initial_value() background_size::get_initial_value()
} }
pub fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) pub fn parse<'i, 't>(
-> Result<SpecifiedValue,ParseError<'i>> { context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<SpecifiedValue, ParseError<'i>> {
background_size::parse(context, input) background_size::parse(context, input)
} }
</%helpers:longhand> </%helpers:longhand>

View file

@ -33,8 +33,10 @@
} }
} }
pub fn parse_value<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) pub fn parse_value<'i, 't>(
-> Result<Longhands, ParseError<'i>> { context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Longhands, ParseError<'i>> {
let mut background_color = None; let mut background_color = None;
% for name in "image position_x position_y repeat size attachment origin clip".split(): % for name in "image position_x position_y repeat size attachment origin clip".split():
@ -200,8 +202,10 @@
use values::specified::AllowQuirks; use values::specified::AllowQuirks;
use values::specified::position::Position; use values::specified::position::Position;
pub fn parse_value<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) pub fn parse_value<'i, 't>(
-> Result<Longhands, ParseError<'i>> { context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Longhands, ParseError<'i>> {
// Vec grows from 0 to 4 by default on first push(). So allocate with // Vec grows from 0 to 4 by default on first push(). So allocate with
// capacity 1, so in the common case of only one item we don't way // capacity 1, so in the common case of only one item we don't way
// overallocate. Note that we always push at least one item if parsing // overallocate. Note that we always push at least one item if parsing

View file

@ -24,8 +24,10 @@ ${helpers.four_sides_shorthand(
use values::generics::rect::Rect; use values::generics::rect::Rect;
use values::specified::{AllowQuirks, BorderSideWidth}; use values::specified::{AllowQuirks, BorderSideWidth};
pub fn parse_value<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) pub fn parse_value<'i, 't>(
-> Result<Longhands, ParseError<'i>> { context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Longhands, ParseError<'i>> {
let rect = Rect::parse_with(context, input, |_, i| { let rect = Rect::parse_with(context, input, |_, i| {
BorderSideWidth::parse_quirky(context, i, AllowQuirks::Yes) BorderSideWidth::parse_quirky(context, i, AllowQuirks::Yes)
})?; })?;
@ -48,10 +50,10 @@ ${helpers.four_sides_shorthand(
</%helpers:shorthand> </%helpers:shorthand>
pub fn parse_border<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) pub fn parse_border<'i, 't>(
-> Result<(specified::Color, context: &ParserContext,
specified::BorderStyle, input: &mut Parser<'i, 't>,
specified::BorderSideWidth), ParseError<'i>> { ) -> Result<(specified::Color, specified::BorderStyle, specified::BorderSideWidth), ParseError<'i>> {
use values::specified::{Color, BorderStyle, BorderSideWidth}; use values::specified::{Color, BorderStyle, BorderSideWidth};
let _unused = context; let _unused = context;
let mut color = None; let mut color = None;
@ -106,8 +108,10 @@ pub fn parse_border<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
alias="${maybe_moz_logical_alias(product, (side, logical), '-moz-border-%s')}" alias="${maybe_moz_logical_alias(product, (side, logical), '-moz-border-%s')}"
spec="${spec}"> spec="${spec}">
pub fn parse_value<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) pub fn parse_value<'i, 't>(
-> Result<Longhands, ParseError<'i>> { context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Longhands, ParseError<'i>> {
let (color, style, width) = super::parse_border(context, input)?; let (color, style, width) = super::parse_border(context, input)?;
Ok(expanded! { Ok(expanded! {
border_${to_rust_ident(side)}_color: color, border_${to_rust_ident(side)}_color: color,
@ -138,8 +142,10 @@ pub fn parse_border<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
for name in ['outset', 'repeat', 'slice', 'source', 'width'])}" for name in ['outset', 'repeat', 'slice', 'source', 'width'])}"
spec="https://drafts.csswg.org/css-backgrounds/#border"> spec="https://drafts.csswg.org/css-backgrounds/#border">
pub fn parse_value<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) pub fn parse_value<'i, 't>(
-> Result<Longhands, ParseError<'i>> { context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Longhands, ParseError<'i>> {
use properties::longhands::{border_image_outset, border_image_repeat, border_image_slice}; use properties::longhands::{border_image_outset, border_image_repeat, border_image_slice};
use properties::longhands::{border_image_source, border_image_width}; use properties::longhands::{border_image_source, border_image_width};
@ -207,8 +213,10 @@ pub fn parse_border<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
use values::specified::border::BorderRadius; use values::specified::border::BorderRadius;
use parser::Parse; use parser::Parse;
pub fn parse_value<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) pub fn parse_value<'i, 't>(
-> Result<Longhands, ParseError<'i>> { context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Longhands, ParseError<'i>> {
let radii = BorderRadius::parse(context, input)?; let radii = BorderRadius::parse(context, input)?;
Ok(expanded! { Ok(expanded! {
border_top_left_radius: radii.top_left, border_top_left_radius: radii.top_left,
@ -242,8 +250,10 @@ pub fn parse_border<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
use properties::longhands::{border_image_outset, border_image_repeat, border_image_slice}; use properties::longhands::{border_image_outset, border_image_repeat, border_image_slice};
use properties::longhands::{border_image_source, border_image_width}; use properties::longhands::{border_image_source, border_image_width};
pub fn parse_value<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) pub fn parse_value<'i, 't>(
-> Result<Longhands, ParseError<'i>> { context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Longhands, ParseError<'i>> {
% for name in "outset repeat slice source width".split(): % for name in "outset repeat slice source width".split():
let mut border_image_${name} = border_image_${name}::get_initial_specified_value(); let mut border_image_${name} = border_image_${name}::get_initial_specified_value();
% endfor % endfor

View file

@ -11,8 +11,10 @@
use properties::longhands::overflow_x::SpecifiedValue; use properties::longhands::overflow_x::SpecifiedValue;
% endif % endif
pub fn parse_value<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) pub fn parse_value<'i, 't>(
-> Result<Longhands, ParseError<'i>> { context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Longhands, ParseError<'i>> {
% if product == "gecko": % if product == "gecko":
let moz_kw_found = input.try(|input| { let moz_kw_found = input.try(|input| {
try_match_ident_ignore_ascii_case! { input, try_match_ident_ignore_ascii_case! { input,
@ -118,8 +120,10 @@ macro_rules! try_parse_one {
use properties::longhands::transition_${prop}; use properties::longhands::transition_${prop};
% endfor % endfor
pub fn parse_value<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) pub fn parse_value<'i, 't>(
-> Result<Longhands, ParseError<'i>> { context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Longhands, ParseError<'i>> {
struct SingleTransition { struct SingleTransition {
% for prop in "duration timing_function delay".split(): % for prop in "duration timing_function delay".split():
transition_${prop}: transition_${prop}::SingleSpecifiedValue, transition_${prop}: transition_${prop}::SingleSpecifiedValue,
@ -129,8 +133,10 @@ macro_rules! try_parse_one {
transition_property: Option<transition_property::SingleSpecifiedValue>, transition_property: Option<transition_property::SingleSpecifiedValue>,
} }
fn parse_one_transition<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) fn parse_one_transition<'i, 't>(
-> Result<SingleTransition,ParseError<'i>> { context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<SingleTransition,ParseError<'i>> {
% for prop in "property duration timing_function delay".split(): % for prop in "property duration timing_function delay".split():
let mut ${prop} = None; let mut ${prop} = None;
% endfor % endfor
@ -260,16 +266,20 @@ macro_rules! try_parse_one {
use properties::longhands::animation_${prop}; use properties::longhands::animation_${prop};
% endfor % endfor
pub fn parse_value<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) pub fn parse_value<'i, 't>(
-> Result<Longhands, ParseError<'i>> { context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Longhands, ParseError<'i>> {
struct SingleAnimation { struct SingleAnimation {
% for prop in props: % for prop in props:
animation_${prop}: animation_${prop}::SingleSpecifiedValue, animation_${prop}: animation_${prop}::SingleSpecifiedValue,
% endfor % endfor
} }
fn parse_one_animation<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) fn parse_one_animation<'i, 't>(
-> Result<SingleAnimation,ParseError<'i>> { context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<SingleAnimation, ParseError<'i>> {
% for prop in props: % for prop in props:
let mut ${prop} = None; let mut ${prop} = None;
% endfor % endfor
@ -364,8 +374,10 @@ macro_rules! try_parse_one {
spec="https://drafts.csswg.org/css-scroll-snap/#propdef-scroll-snap-type"> spec="https://drafts.csswg.org/css-scroll-snap/#propdef-scroll-snap-type">
use properties::longhands::scroll_snap_type_x; use properties::longhands::scroll_snap_type_x;
pub fn parse_value<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) pub fn parse_value<'i, 't>(
-> Result<Longhands, ParseError<'i>> { context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Longhands, ParseError<'i>> {
let result = scroll_snap_type_x::parse(context, input)?; let result = scroll_snap_type_x::parse(context, input)?;
Ok(expanded! { Ok(expanded! {
scroll_snap_type_x: result, scroll_snap_type_x: result,

View file

@ -11,9 +11,10 @@
extra_prefixes="moz" spec="https://drafts.csswg.org/css-multicol/#propdef-columns"> extra_prefixes="moz" spec="https://drafts.csswg.org/css-multicol/#propdef-columns">
use properties::longhands::{column_count, column_width}; use properties::longhands::{column_count, column_width};
pub fn parse_value<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) pub fn parse_value<'i, 't>(
-> Result<Longhands, ParseError<'i>> { context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Longhands, ParseError<'i>> {
let mut column_count = None; let mut column_count = None;
let mut column_width = None; let mut column_width = None;
let mut autos = 0; let mut autos = 0;
@ -61,8 +62,10 @@
use properties::longhands::{column_rule_width, column_rule_style}; use properties::longhands::{column_rule_width, column_rule_style};
use properties::longhands::column_rule_color; use properties::longhands::column_rule_color;
pub fn parse_value<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) pub fn parse_value<'i, 't>(
-> Result<Longhands, ParseError<'i>> { context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Longhands, ParseError<'i>> {
% for name in "width style color".split(): % for name in "width style color".split():
let mut column_rule_${name} = None; let mut column_rule_${name} = None;
% endfor % endfor

View file

@ -42,8 +42,10 @@
% endif % endif
use self::font_family::SpecifiedValue as FontFamily; use self::font_family::SpecifiedValue as FontFamily;
pub fn parse_value<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) pub fn parse_value<'i, 't>(
-> Result<Longhands, ParseError<'i>> { context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Longhands, ParseError<'i>> {
let mut nb_normals = 0; let mut nb_normals = 0;
let mut style = None; let mut style = None;
let mut variant_caps = None; let mut variant_caps = None;
@ -262,8 +264,10 @@
#[allow(unused_imports)] #[allow(unused_imports)]
use values::specified::FontVariantLigatures; use values::specified::FontVariantLigatures;
pub fn parse_value<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) pub fn parse_value<'i, 't>(
-> Result<Longhands, ParseError<'i>> { context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Longhands, ParseError<'i>> {
% for prop in sub_properties: % for prop in sub_properties:
let mut ${prop} = None; let mut ${prop} = None;
% endfor % endfor

View file

@ -9,8 +9,10 @@
spec="https://www.w3.org/TR/SVG2/painting.html#MarkerShorthand"> spec="https://www.w3.org/TR/SVG2/painting.html#MarkerShorthand">
use values::specified::UrlOrNone; use values::specified::UrlOrNone;
pub fn parse_value<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) pub fn parse_value<'i, 't>(
-> Result<Longhands, ParseError<'i>> { context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Longhands, ParseError<'i>> {
use parser::Parse; use parser::Parse;
let url = UrlOrNone::parse(context, input)?; let url = UrlOrNone::parse(context, input)?;

View file

@ -10,8 +10,10 @@
spec="https://drafts.csswg.org/css-text-decor-3/#text-emphasis-property"> spec="https://drafts.csswg.org/css-text-decor-3/#text-emphasis-property">
use properties::longhands::{text_emphasis_color, text_emphasis_style}; use properties::longhands::{text_emphasis_color, text_emphasis_style};
pub fn parse_value<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) pub fn parse_value<'i, 't>(
-> Result<Longhands, ParseError<'i>> { context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Longhands, ParseError<'i>> {
let mut color = None; let mut color = None;
let mut style = None; let mut style = None;
@ -52,8 +54,10 @@
spec="https://compat.spec.whatwg.org/#the-webkit-text-stroke"> spec="https://compat.spec.whatwg.org/#the-webkit-text-stroke">
use properties::longhands::{_webkit_text_stroke_color, _webkit_text_stroke_width}; use properties::longhands::{_webkit_text_stroke_color, _webkit_text_stroke_width};
pub fn parse_value<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) pub fn parse_value<'i, 't>(
-> Result<Longhands, ParseError<'i>> { context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Longhands, ParseError<'i>> {
let mut color = None; let mut color = None;
let mut width = None; let mut width = None;
loop { loop {

View file

@ -11,8 +11,10 @@
use properties::longhands::{list_style_image, list_style_position, list_style_type}; use properties::longhands::{list_style_image, list_style_position, list_style_type};
use values::{Either, None_}; use values::{Either, None_};
pub fn parse_value<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) pub fn parse_value<'i, 't>(
-> Result<Longhands, ParseError<'i>> { context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Longhands, ParseError<'i>> {
// `none` is ambiguous until we've finished parsing the shorthands, so we count the number // `none` is ambiguous until we've finished parsing the shorthands, so we count the number
// of times we see it. // of times we see it.
let mut nones = 0u8; let mut nones = 0u8;

View file

@ -36,8 +36,10 @@
} }
} }
pub fn parse_value<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) pub fn parse_value<'i, 't>(
-> Result<Longhands, ParseError<'i>> { context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Longhands, ParseError<'i>> {
% for name in "image mode position_x position_y size repeat origin clip composite".split(): % for name in "image mode position_x position_y size repeat origin clip composite".split():
// Vec grows from 0 to 4 by default on first push(). So allocate // Vec grows from 0 to 4 by default on first push(). So allocate
// with capacity 1, so in the common case of only one item we don't // with capacity 1, so in the common case of only one item we don't

View file

@ -12,8 +12,10 @@
use values::specified; use values::specified;
use parser::Parse; use parser::Parse;
pub fn parse_value<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) pub fn parse_value<'i, 't>(
-> Result<Longhands, ParseError<'i>> { context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Longhands, ParseError<'i>> {
let _unused = context; let _unused = context;
let mut color = None; let mut color = None;
let mut style = None; let mut style = None;
@ -64,8 +66,10 @@
use values::specified::border::BorderRadius; use values::specified::border::BorderRadius;
use parser::Parse; use parser::Parse;
pub fn parse_value<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) pub fn parse_value<'i, 't>(
-> Result<Longhands, ParseError<'i>> { context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Longhands, ParseError<'i>> {
let radii = BorderRadius::parse(context, input)?; let radii = BorderRadius::parse(context, input)?;
Ok(expanded! { Ok(expanded! {
_moz_outline_radius_topleft: radii.top_left, _moz_outline_radius_topleft: radii.top_left,

View file

@ -11,8 +11,10 @@
spec="https://drafts.csswg.org/css-flexbox/#flex-flow-property"> spec="https://drafts.csswg.org/css-flexbox/#flex-flow-property">
use properties::longhands::{flex_direction, flex_wrap}; use properties::longhands::{flex_direction, flex_wrap};
pub fn parse_value<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) pub fn parse_value<'i, 't>(
-> Result<Longhands, ParseError<'i>> { context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Longhands, ParseError<'i>> {
let mut direction = None; let mut direction = None;
let mut wrap = None; let mut wrap = None;
loop { loop {

View file

@ -16,8 +16,10 @@
use properties::longhands::text_decoration_line; use properties::longhands::text_decoration_line;
% endif % endif
pub fn parse_value<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) pub fn parse_value<'i, 't>(
-> Result<Longhands, ParseError<'i>> { context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Longhands, ParseError<'i>> {
% if product == "gecko": % if product == "gecko":
let (mut line, mut style, mut color, mut any) = (None, None, None, false); let (mut line, mut style, mut color, mut any) = (None, None, None, false);
% else: % else:

View file

@ -601,17 +601,20 @@ impl Length {
/// Parse a non-negative length /// Parse a non-negative length
#[inline] #[inline]
pub fn parse_non_negative<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) pub fn parse_non_negative<'i, 't>(
-> Result<Length, ParseError<'i>> { context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
Self::parse_non_negative_quirky(context, input, AllowQuirks::No) Self::parse_non_negative_quirky(context, input, AllowQuirks::No)
} }
/// Parse a non-negative length, allowing quirks. /// Parse a non-negative length, allowing quirks.
#[inline] #[inline]
pub fn parse_non_negative_quirky<'i, 't>(context: &ParserContext, pub fn parse_non_negative_quirky<'i, 't>(
input: &mut Parser<'i, 't>, context: &ParserContext,
allow_quirks: AllowQuirks) input: &mut Parser<'i, 't>,
-> Result<Length, ParseError<'i>> { allow_quirks: AllowQuirks,
) -> Result<Self, ParseError<'i>> {
Self::parse_internal(context, input, AllowedNumericType::NonNegative, allow_quirks) Self::parse_internal(context, input, AllowedNumericType::NonNegative, allow_quirks)
} }
@ -630,10 +633,11 @@ impl Parse for Length {
impl Length { impl Length {
/// Parses a length, with quirks. /// Parses a length, with quirks.
pub fn parse_quirky<'i, 't>(context: &ParserContext, pub fn parse_quirky<'i, 't>(
input: &mut Parser<'i, 't>, context: &ParserContext,
allow_quirks: AllowQuirks) input: &mut Parser<'i, 't>,
-> Result<Self, ParseError<'i>> { allow_quirks: AllowQuirks,
) -> Result<Self, ParseError<'i>> {
Self::parse_internal(context, input, AllowedNumericType::All, allow_quirks) Self::parse_internal(context, input, AllowedNumericType::All, allow_quirks)
} }
} }