Re: [csswg-drafts] [css-color-5] Grammar for parsing relative colors? (#7721)

> > Which makes no mention of r, g, b, or alpha.
> 
> The thing is that for real usage, it would not be a simple "use 100% of this channel" but instead, a big `calc()` and those `r`, `g`, `b` and `alpha` are going to be used inside a `calc()`, which will evaluate to a `<number>`

Oh, I see. I'm not sure the spec makes that obvious.

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

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 `calc()` and other math functions should already be subsumed into the definitions of `<number>` and `<percentage>` (and if they're not, that's a different conversation anyway).

The problem lies in that the parameters to `rgb()` and its ilk are not defined individually, but using `{3}`. And while I recognize that this simplifies the definitions that require all three parameters to be of the same type, it does sort of relegate the channel keywords to something of an afterthought. (And to the extent that that affects "extending" the existing definitions, we've already established that this spec is actually replacing them wholesale.)

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 `hsl()` and `hwb()` (based on definitions in earlier specs), so I would certainly support an approach that makes those differences clearer. The fact that channel keywords are only mentioned in prose IMO makes it easier to overlook that the definitions of these two functions are not entirely the same.

-- 
GitHub Notification of comment by GPHemsley
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/7721#issuecomment-1250129449 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Saturday, 17 September 2022 19:36:49 UTC