Skip to content

[css-values] # is easy to confuse with * #381

Closed

Description

@SimonSapin

https://drafts.csswg.org/css-values/#mult-comma introduces for grammars a # repetition which is like * but with comma separators. Terse grammars are nice, but in this case in this case this important difference seems easy to miss.

A couple times now I’ve reviewed a pull request from someone (not necessarily a new contributor) implementing CSS parsing from grammar in a spec like https://drafts.csswg.org/css-shapes-1/#funcdef-polygon . They do write a loop but don’t seem to realize that commas are required.

(Servo’s doesn’t use a parser generator for CSS. It’s manually-written recursive descent with one function or method for roughly each grammar term.)

In some specs (not css-shapes, which may be a bug) the # itself is a link to its definition in css-values, but even that is easy to miss.

I don’t know what to do about this, but it seems to be a recurring issue.

CC @tabatkins

Activity

  1. fantasai commented on Aug 4, 2016

    @fantasai
    Collaborator

    I don't really understand the confusion, given that # is not a multiplier in any other language that I've heard of. Why would someone just randomly decide it means *?

  2. SimonSapin commented on Aug 4, 2016

    @SimonSapin
    ContributorAuthor

    ¯_(ツ)_/¯

  3. SimonSapin commented on Aug 4, 2016

    @SimonSapin
    ContributorAuthor

    Wild guess: it’s a combination of

    • Prior knowledge tells you that a polygon is defined by multiple points so repetition is obvious
    • The grammar is vaguely BNF-like
    • No other grammar syntax that one has seen elsewhere has syntax that implies that some input characters are required, without using these characters (For what it’s worth, for example Rust macros use $( foo )* for repetition and $( foo ),* for comma-separated repetition.)
    • The "This specification follows the CSS property definition conventions from [CSS21]" bit is in a boilerplate section that no-one reads, far from the grammar definitions. And it doesn’t even associate grammar syntax with css-values.
  4. fantasai commented on Aug 4, 2016

    @fantasai
    Collaborator

    We should probably improve the boilerplate reference to V&U. Other than that, I don't really know what to do here. Comma is a literal in CSS, ,* would mean repeat lots of commas...

  5. SimonSapin commented on Aug 4, 2016

    @SimonSapin
    ContributorAuthor

    Yeah, unfortunately I don’t have a solution to propose. But it still seems to be a problem.

    Perhaps I should write "So you want to add something CSS in Servo" documentation and advertise it to contributors (new and not) somehow. (Both on how to read specs in general and on Servo code in particular.)

  6. fantasai commented on Aug 4, 2016

    @fantasai
    Collaborator

    I should maybe update https://www.w3.org/Style/CSS/read.en.html but it's a good place to start. :)

  7. gibson042 commented on Aug 5, 2016

    @gibson042

    We should probably improve the boilerplate reference to V&U. Other than that, I don't really know what to do here. Comma is a literal in CSS, ,* would mean repeat lots of commas...

    Don't the comma omission rules mean that top-level and argument-list value# and [ , value ]* are equivalent? It seems like # is just sugar, or at least resolvably close to it.

  8. SebastianZ commented on Aug 5, 2016

    @SebastianZ
    Contributor

    Don't the comma omission rules mean that top-level and argument-list value# and [ , value ]* are equivalent? It seems like # is just sugar, or at least resolvably close to it.

    Yes. For what it's worth, I've just changed the syntaxes in CSS Backgrounds lately to use #. In my opinion value# looks much nicer than value [ , value ]* and I don't see why people should be confused about that.

    Sebastian

  9. gibson042 commented on Aug 5, 2016

    @gibson042

    Not value [ , value ]*, just [ , value ]*. That's why I referenced comma omission rules.

  10. gibson042 commented on Aug 5, 2016

    @gibson042

    That said, I did find another example of indicating comma-separated sequences with # in RFC 7230 (though it might well have been inspired by e811c7f), and also prior art in an early draft of RFC 2234 from 1997 that didn't make it into the final version. So there's definitely a leg to stand on in keeping and using it.

  11. fantasai commented on Aug 8, 2016

    @fantasai
    Collaborator

    Wow, we've been backported to IETF!

  12. fantasai commented on May 17, 2017

    @fantasai
    Collaborator

    So... I'm closing this as no change, given that

    • If you can't distinguish between different multipliers, that's a problem whether it's + and * or * and #, you should figure this thing out.
    • We've deployed this across CSS for awhile now.
    • We've got prior art from IETF.
  13. tabatkins commented on Aug 1, 2017

    @tabatkins
    Member

    Not value [ , value ]*, just [ , value ]*. That's why I referenced comma omission rules.

    That's only equivalent to <value># if there's no terms preceding it in the grammar; if so, a preceding comma is actually required. Like, foo [, bar]* matches foo, bar, bar, while foo bar# matches foo bar, bar.

    Also, it's significantly less readable / less obvious.

  14. added a commit that references this issue on Dec 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions