Skip to content

css_ast: Implement gap rule list#878

Open
cijiugechu wants to merge 4 commits intocsskit:mainfrom
cijiugechu:gap-rule-list
Open

css_ast: Implement gap rule list#878
cijiugechu wants to merge 4 commits intocsskit:mainfrom
cijiugechu:gap-rule-list

Conversation

@cijiugechu
Copy link
Contributor

@cijiugechu cijiugechu commented Feb 12, 2026

Related issue: #157

Copy link
Member

@keithamus keithamus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work on this so far! Amazing to see!

I've got some early feedback which hopefully you'll find useful. I think the feedback largely applies to both gap_rule_list/gap_auto_rule_list so I haven't repeated it for each.

Generally speaking, I think you should look at RepeatFunction and see if we can extend into that, here.

@cijiugechu
Copy link
Contributor Author

cijiugechu commented Feb 13, 2026

Great work on this so far! Amazing to see!

I've got some early feedback which hopefully you'll find useful. I think the feedback largely applies to both gap_rule_list/gap_auto_rule_list so I haven't repeated it for each.

Generally speaking, I think you should look at RepeatFunction and see if we can extend into that, here.

Thanks a lot for the thorough review — really appreciate the time and the clear suggestions!
I have applied patches in latest revision.

@cijiugechu cijiugechu marked this pull request as ready for review February 13, 2026 16:30
// https://drafts.csswg.org/css-gaps-1/#typedef-gap-auto-rule-list
// <gap-auto-rule-list> = <gap-rule-or-repeat>#? , <gap-auto-repeat-rule> , <gap-rule-or-repeat>#?
pub type GapAutoRuleList = Todo;
//
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit:

Suggested change
//

// <gap-rule-or-repeat> = <gap-rule> | <gap-repeat-rule>
#[derive(Parse, Peek, ToCursors, ToSpan, SemanticEq, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())]
#[cfg_attr(feature = "visitable", derive(csskit_derives::Visitable), visit(self))]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These still need to visit children I believe. Same for many others:

Suggested change
#[cfg_attr(feature = "visitable", derive(csskit_derives::Visitable), visit(self))]
#[cfg_attr(feature = "visitable", derive(csskit_derives::Visitable), visit)]

The general rule is "if a type just holds cursors, it should be visit(self). If it is just a delegate type (like a generic) it should be visit(children), otherwise visit."

let close = p.parse::<T![')']>()?;
Ok(Self { name, count, comma, rules, close })
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks fairly straightforward (nothing surprising). I'm quite sure GapRepeatRule can derive(Parse) if you add #[atom(CssAtomSet::Repeat)] to the name field.

Comment on lines +5 to +21
impl<'a> Parse<'a> for ColumnRuleStyleValue<'a> {
fn parse<I>(p: &mut Parser<'a, I>) -> ParseResult<Self>
where
I: Iterator<Item = Cursor> + Clone,
{
p.parse::<GapRuleList<'a>>().map(Self::GapRuleList)
}
}

impl<'a> Parse<'a> for RowRuleStyleValue<'a> {
fn parse<I>(p: &mut Parser<'a, I>) -> ParseResult<Self>
where
I: Iterator<Item = Cursor> + Clone,
{
p.parse::<GapRuleList<'a>>().map(Self::GapRuleList)
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These aren't quite right I think.

This will cause the RowRuleStyleValue to be:

enum RowRuleStyleValue {
	GapRuleList(GapRuleList<'a>),
  GapAutoRuleList(GapAutoRuleList<'a>),
}

But Parse will only ever return the GapRuleList() variant, rendering the other variant useless.

There are two options here:

  1. Play around with the syntax optimisation phase to flatten these (take a look at https://github.com/csskit/csskit/blob/main/crates/css_value_definition_parser/src/lib.rs#L356-L520). This will mean that RowRuleStyleValue will become a struct over GapRuleList. I think this is probably want we want.
  2. Figure out after parse if GapRuleList fits the auto part by interrogating its members and see if it belongs in GapRuleList or GapAutoRuleList (probably not what we want).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants