-
Notifications
You must be signed in to change notification settings - Fork 714
[css-color-5] Grammar for parsing relative colors? #7721
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
Comments
[accidentally submitted original post early] |
A value definition does not always represent the full production's grammar: it may be completed with some rules written in prose, like the channel keywords and the legacy I hope it helps and that I'm not mistaken. |
Ah, I hadn't registered that. You're right.
It seems to me that this approach would actually make things more complex to implement, as one has to interpolate the prose instructions into the grammar parsing. I suspect the dividing line actually more closely approaches author instructions vs. implementer requirements, an issue that is significantly more complex for areas having longer-standing legacy behavior (like what e.g. HTML has to handle). Still, I would argue that all parsing requirements (as opposed to, say, implementation details) should be defined in a formal grammar somewhere rather than in prose, even if that means having a separate definition of the legacy rules, à la many mature IETF RFCs. |
That is a fair point, it is indeed a replacement, but maybe I should still link to the previous definition in CSS Color 4. |
The thing is that for real usage, it would not be a simple "use 100% of this channel" but instead, a big |
Well, depends somewhat on your parsing strategy. Reproducing the entirety of the math-function grammar inline in the RCS syntax, duplicated for each different set of valid channel keywords, would technically work, but if you're not using the grammar directly it makes noticing the parsing differences more difficult. The prose outlines the changes very straightforwardly, so adapting one's existing parsing code to match shouldn't be too odd. But importantly, we write specs for several purposes and several audiences, and doing that sort of giant grammar duplication (and keeping it in sync with future math-function additions, ugh) would be a massive hit to readability. This not only harms our "web developer" audience, but can potentially harm our "implementor" audience as well, if they're not just literally dropping in our grammar to their system (as mentioned above). I don't believe any of the browsers do so, for instance; they all have parsing code that spans the spectrum from "grammar-driven" to "completely custom" depending on the property/value, and when it's grammar-driven it's not literally the CSS Value Definition Syntax grammar but some other parsing tool's grammar, necessitating rewrites anyway. |
Oh, I see. I'm not sure the spec makes that obvious.
Rereading the relevant sections of the spec with the new context presented in this thread, I think I would propose a different approach. The use of The problem lies in that the parameters to Incidentally, as far as making parsing differences more difficult to notice, on the way to filing this issue, I encountered code that was a little overzealously combining the definitions of |
This is true for every property: you can use I guess the place to make that explicit is in the CSS Custom Properties spec, and then with well-chosen examples for those values which are especially likely to be used with custom properties. On the other hand I see your point; the impact of CSS Custom Properties is extensive, and we need to communicate this better.
Agreed.
Forbidding someone from using, say, the |
The only thing which is the same with those two is the hue channel, which has identical definitions in both. What was the code doing? |
Hmm. I think I was thinking of it more from the perspective of naming the part of grammar in its definition, rather than restricting the use of these keywords elsewhere. But I do think I am beginning to get a better picture of the design of these keywords: They're not so much part of the grammar as they are defined as part of the concept the grammar represents. As in, "once you have this color, these keywords are defined to represent certain characteristics of it". I think that was the part I was struggling with, and is perhaps the part that needs to be most clarified. In particular, I get the sense that the Relative Color Syntax section has some circular definitions and/or is conflating the syntactic definitions with the concepts behind them. Separately (and I don't understand colorspaces enough to know if this is a nonsense question): Does it make sense to define these relative color keywords separately/independently from the function definitions? If you define a color using
|
I see this conflation already led to servo/rust-cssparser@bf31c1d which then led to #6911. |
Not a nonsense question.
We considered that and decided against it, so you only get the channels of the colorspace in use. This avoids having to coerce colors to the sRGB gamut (for So it would have made sense, but introduced complexity with no obvious value, so the answer to your earlier question is "no". |
That is precisely what it is doing. I will take a look over the break and see if that can be more clearly expressed. |
Now fixed; clarifies that it is extending the modern (not the legacy) syntax, and uses tokens like |
@GPHemsley does the current text satisfy your concern, now, or is more clarification needed?
|
I'm far removed from this now, but a cursory reread seems to indicate that things are much clearer now, thank you. |
Is it just me, or is the grammar for parsing relative colors missing?
https://drafts.csswg.org/css-color-5/#relative-colors
Channel keywords are defined for each color function, and example usage is provided, but none of the channel keywords appear in the grammar for them.
For example, 3.1. Relative sRGB Colors defines the allowed channel keywords of
rgb()
asr
,g
,b
, andalpha
.And Example 13 shows:
rgb(from indianred 255 g b)
But the grammar is listed as:
Which makes no mention of
r
,g
,b
, oralpha
.It also describes the grammar for the functions like
rgb()
as being "extended", but it doesn't link to what it's extending, and indeed appears to be completely replacing the syntax from css-color-4, at least from a grammar definition standpoint.The text was updated successfully, but these errors were encountered: