From ba6641de588fe330fc3516e07239d696aa9de0bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Naz=C4=B1m=20Can=20Alt=C4=B1nova?= Date: Mon, 3 Jul 2017 11:45:51 -0700 Subject: [PATCH] Fix parsing of 'subgrid' and 'none' keywords in grid-template --- .../properties/shorthand/position.mako.rs | 28 +++++++++++++++++-- components/style/values/generics/grid.rs | 2 +- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/components/style/properties/shorthand/position.mako.rs b/components/style/properties/shorthand/position.mako.rs index 3077e4e1d38..88d51a1a179 100644 --- a/components/style/properties/shorthand/position.mako.rs +++ b/components/style/properties/shorthand/position.mako.rs @@ -243,7 +243,7 @@ use parser::Parse; use properties::longhands::grid_template_areas::TemplateAreas; use values::{Either, None_}; - use values::generics::grid::{TrackSize, TrackList, TrackListType, concat_serialize_idents}; + use values::generics::grid::{LineNameList, TrackSize, TrackList, TrackListType, concat_serialize_idents}; use values::specified::{GridTemplateComponent, GenericGridTemplateComponent}; use values::specified::grid::parse_line_names; @@ -252,9 +252,31 @@ -> Result<(GridTemplateComponent, GridTemplateComponent, Either), ParseError<'i>> { - if input.try(|i| i.expect_ident_matching("none")).is_ok() { - return Ok((GenericGridTemplateComponent::None, GenericGridTemplateComponent::None, Either::Second(None_))) + + // 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`. + <% keywords = { + "none": "GenericGridTemplateComponent::None", + "subgrid": "GenericGridTemplateComponent::Subgrid(LineNameList::default())" } + %> + % for keyword, rust_type in keywords.items(): + if let Ok(x) = input.try(|i| { + if i.try(|i| i.expect_ident_matching("${keyword}")).is_ok() { + if i.is_exhausted() { + return Ok((${rust_type}, + ${rust_type}, + Either::Second(None_))) + } else { + return Err(()); + } + } + Err(()) + }) { + return Ok(x); + } + % endfor let first_line_names = input.try(parse_line_names).unwrap_or(vec![]); if let Ok(s) = input.try(Parser::expect_string) { diff --git a/components/style/values/generics/grid.rs b/components/style/values/generics/grid.rs index c64a7929107..f266307d7a7 100644 --- a/components/style/values/generics/grid.rs +++ b/components/style/values/generics/grid.rs @@ -583,7 +583,7 @@ impl ToCss for TrackList { /// /// `subgrid [ | repeat( | auto-fill, +) ]+` /// Old spec: https://www.w3.org/TR/2015/WD-css-grid-1-20150917/#typedef-line-name-list -#[derive(Clone, PartialEq, Debug)] +#[derive(Clone, PartialEq, Debug, Default)] #[cfg_attr(feature = "servo", derive(HeapSizeOf))] pub struct LineNameList { /// The optional ``