Skip to content

Commit

Permalink
style: Use a consistent style for position shorthand parsing.
Browse files Browse the repository at this point in the history
  • Loading branch information
emilio committed Apr 6, 2018
1 parent 725943f commit 0a87a15
Showing 1 changed file with 32 additions and 18 deletions.
50 changes: 32 additions & 18 deletions components/style/properties/shorthand/position.mako.rs
Expand Up @@ -52,15 +52,19 @@
use values::specified::NonNegativeNumber;
use properties::longhands::flex_basis::SpecifiedValue as FlexBasis;

fn parse_flexibility<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<(NonNegativeNumber, Option<NonNegativeNumber>),ParseError<'i>> {
fn parse_flexibility<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<(NonNegativeNumber, Option<NonNegativeNumber>),ParseError<'i>> {
let grow = NonNegativeNumber::parse(context, input)?;
let shrink = input.try(|i| NonNegativeNumber::parse(context, i)).ok();
Ok((grow, shrink))
}

pub fn parse_value<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<Longhands, ParseError<'i>> {
pub fn parse_value<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Longhands, ParseError<'i>> {
let mut grow = None;
let mut shrink = None;
let mut basis = None;
Expand Down Expand Up @@ -144,8 +148,10 @@
// NOTE: Since both the shorthands have the same code, we should (re-)use code from one to implement
// the other. This might not be a big deal for now, but we should consider looking into this in the future
// to limit the amount of code generated.
pub fn parse_value<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<Longhands, ParseError<'i>> {
pub fn parse_value<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Longhands, ParseError<'i>> {
let start = input.try(|i| GridLine::parse(context, i))?;
let end = if input.try(|i| i.expect_delim('/')).is_ok() {
GridLine::parse(context, input)?
Expand Down Expand Up @@ -182,8 +188,10 @@
use parser::Parse;

// The code is the same as `grid-{row,column}` except that this can have four values at most.
pub fn parse_value<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<Longhands, ParseError<'i>> {
pub fn parse_value<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Longhands, ParseError<'i>> {
fn line_with_ident_from(other: &GridLine) -> GridLine {
let mut this = GridLine::auto();
if other.line_num.is_none() && !other.is_span {
Expand Down Expand Up @@ -253,10 +261,10 @@
use values::specified::position::{TemplateAreas, TemplateAreasArc};

/// Parsing for `<grid-template>` shorthand (also used by `grid` shorthand).
pub fn parse_grid_template<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<(GridTemplateComponent,
GridTemplateComponent,
Either<TemplateAreasArc, None_>), ParseError<'i>> {
pub fn parse_grid_template<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<(GridTemplateComponent, GridTemplateComponent, Either<TemplateAreasArc, None_>), ParseError<'i>> {
// Other shorthand sub properties also parse `none` and `subgrid` keywords and this
// shorthand should know after these keywords there is nothing to parse. Otherwise it
// gets confused and rejects the sub properties that contains `none` or `subgrid`.
Expand Down Expand Up @@ -354,8 +362,10 @@
}

#[inline]
pub fn parse_value<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<Longhands, ParseError<'i>> {
pub fn parse_value<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Longhands, ParseError<'i>> {
let (rows, columns, areas) = parse_grid_template(context, input)?;
Ok(expanded! {
grid_template_rows: rows,
Expand Down Expand Up @@ -481,17 +491,21 @@
use values::specified::{GenericGridTemplateComponent, TrackSize};
use values::specified::position::{AutoFlow, GridAutoFlow};

pub fn parse_value<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<Longhands, ParseError<'i>> {
pub fn parse_value<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Longhands, ParseError<'i>> {
let mut temp_rows = GridTemplateComponent::None;
let mut temp_cols = GridTemplateComponent::None;
let mut temp_areas = Either::Second(None_);
let mut auto_rows = TrackSize::default();
let mut auto_cols = TrackSize::default();
let mut flow = grid_auto_flow::get_initial_value();

fn parse_auto_flow<'i, 't>(input: &mut Parser<'i, 't>, is_row: bool)
-> Result<GridAutoFlow, ParseError<'i>> {
fn parse_auto_flow<'i, 't>(
input: &mut Parser<'i, 't>,
is_row: bool,
) -> Result<GridAutoFlow, ParseError<'i>> {
let mut auto_flow = None;
let mut dense = false;
for _ in 0..2 {
Expand Down

0 comments on commit 0a87a15

Please sign in to comment.