Skip to content

Commit

Permalink
Fix parsing of 'subgrid' and 'none' keywords in grid-template
Browse files Browse the repository at this point in the history
  • Loading branch information
canova committed Jul 4, 2017
1 parent f7aac8d commit ba6641d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
28 changes: 25 additions & 3 deletions components/style/properties/shorthand/position.mako.rs
Expand Up @@ -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;

Expand All @@ -252,9 +252,31 @@
-> Result<(GridTemplateComponent,
GridTemplateComponent,
Either<TemplateAreas, None_>), 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) {
Expand Down
2 changes: 1 addition & 1 deletion components/style/values/generics/grid.rs
Expand Up @@ -583,7 +583,7 @@ impl<T: ToCss> ToCss for TrackList<T> {
///
/// `subgrid [ <line-names> | repeat(<positive-integer> | auto-fill, <line-names>+) ]+`
/// 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 `<line-name-list>`
Expand Down

0 comments on commit ba6641d

Please sign in to comment.