Skip to content

Commit 92847e7

Browse files
committed
css_ast/csskit_proc_macro: Support , literals better.
w3c/csswg-drafts#13018 changed the syntax of Cursor from using `#?` to `,]*`. This subtle change means trailing commas are always required. We didn't support this for a couple of reasons: - Punct wasn't being rendered correctly due to quoting of the char, so `T![,]` was rendering as `T![',']` which isn't a known macro. css_parse could have included quoted variants of all characters, or we could have updated csskit_proc_macro to unquote the chars, which is what this change does. - `T![,]` wasn't Visitable, meaning the `Vec<'a, (X, T![,])>` wasn't Visitable either. Both `Vec` & `(A, B)` _are_ visitable, so it's only `T![,]` that needs to be to make the whole thing work. This change makes `T![,]` Visitable.
1 parent f08affa commit 92847e7

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

crates/css_ast/src/values/ui/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,11 @@ pub enum CaretShapeStyleValue {}
163163
/// The grammar is defined as:
164164
///
165165
/// ```text,ignore
166-
/// <cursor-image>#? <cursor-predefined>
166+
/// [<cursor-image>,]* <cursor-predefined>
167167
/// ```
168168
///
169169
/// https://drafts.csswg.org/css-ui-4/#cursor
170-
#[syntax(" <cursor-image>#? <cursor-predefined> ")]
170+
#[syntax(" [<cursor-image>,]* <cursor-predefined> ")]
171171
#[derive(Parse, Peek, ToSpan, ToCursors, StyleValue, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
172172
#[style_value(
173173
initial = "auto",

crates/css_ast/src/visit/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ where
6161
}
6262
}
6363

64+
impl Visitable for token_macros::Comma {
65+
fn accept<V: Visit>(&self, _: &mut V) {}
66+
}
67+
68+
impl VisitableMut for token_macros::Comma {
69+
fn accept_mut<V: VisitMut>(&mut self, _: &mut V) {}
70+
}
71+
6472
impl Visitable for token_macros::Number {
6573
fn accept<V: Visit>(&self, _: &mut V) {}
6674
}

crates/csskit_proc_macro/src/generate.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use css_value_definition_parser::*;
22
use heck::{ToPascalCase, ToSnakeCase};
33
use itertools::Itertools;
4-
use proc_macro2::TokenStream;
4+
use proc_macro2::{Punct, Spacing, TokenStream};
55
use quote::{format_ident, quote};
66
use std::ops::{Deref, Range};
77
use syn::{Error, Generics, Ident, Visibility, parse_quote};
@@ -182,7 +182,10 @@ impl ToType for Def {
182182
}
183183
Self::IntLiteral(_) => vec![quote! { crate::CSSInt }],
184184
Self::DimensionLiteral(_, _) => vec![quote! { ::css_parse::T![Dimension] }],
185-
Self::Punct(char) => vec![quote! { ::css_parse::T![#char] }],
185+
Self::Punct(char) => {
186+
let punct = Punct::new(*char, Spacing::Alone);
187+
vec![quote! { ::css_parse::T![#punct] }]
188+
}
186189
Self::Group(inner, _) => inner.deref().to_types(),
187190
}
188191
}

0 commit comments

Comments
 (0)