[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
SimonSapin opened this issue Aug 4, 2016 · 13 comments
Closed

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

SimonSapin opened this issue Aug 4, 2016 · 13 comments

Comments

@SimonSapin
Copy link
Contributor
SimonSapin commented Aug 4, 2016

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

@fantasai
Copy link
Collaborator
fantasai commented Aug 4, 2016

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 *?

@SimonSapin
Copy link
Contributor Author

¯_(ツ)_/¯

@SimonSapin
Copy link
Contributor Author

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.

@fantasai
Copy link
Collaborator
fantasai commented Aug 4, 2016

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...

@SimonSapin
Copy link
Contributor Author

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.)

@fantasai
Copy link
Collaborator
fantasai commented Aug 4, 2016

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

@gibson042
Copy link

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.

@SebastianZ
Copy link
Contributor
SebastianZ commented Aug 5, 2016

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

@gibson042
Copy link
gibson042 commented Aug 5, 2016

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

@gibson042
Copy link

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.

@fantasai
Copy link
Collaborator
fantasai commented Aug 8, 2016

Wow, we've been backported to IETF!

@fantasai
Copy link
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.

@tabatkins
Copy link
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.

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

No branches or pull requests

5 participants