-
Notifications
You must be signed in to change notification settings - Fork 193
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
Incorrect value for rgb and rgba functions #341
Comments
It appears that my original assessment is incorrect due to the rules for handling combining commas: However, can you point me to the spec that defines the comma-separated alpha value? |
CSS Color L4 introduces new syntaxes for
However, spec claims:
So, the syntax of Spec also claims:
That's why Following syntaxes are similar:
They work the same: exactly 3 comma separated numbers and optional alpha value. In case alpha value is used it must be preceded by a comma. First syntax is valid due to the rule that commas are implicitly omissible (as you pointed up in your second comment – https://drafts.csswg.org/css-values-4/#comb-comma). So, no mistake in those syntaxes. It's not clear to me what do you mean: "spec that defines the comma-separated alpha value"? Could you clarify? |
@pyoor the format with the @lahmatiy I have a browser testing project that I'm working on (https://github.com/kanaka/bartender) and part of is translating HTML and CSS standards data into EBNF grammars (https://github.com/kanaka/html5-css3-ebnf). The comma combining rule is a pain when doing this translation because it is contextual and requires backtracking or lookahead. The rgb and rgba definitions seem like they might be the only use of that construct within this repo. What do you think of the idea of updating the rgb and rgba syntax definitions so that they are easier to parse with the comma and alpha value wrapped in brackets? It actually makes it more consistent with the --- a/css/syntaxes.json
+++ b/css/syntaxes.json
@@ -564,10 +564,10 @@
"syntax": "repeating-radial-gradient( [ <ending-shape> || <size> ]? [ at <position> ]? , <color-stop-list> )"
},
"rgb()": {
- "syntax": "rgb( <percentage>{3} [ / <alpha-value> ]? ) | rgb( <number>{3} [ / <alpha-value> ]? ) | rgb( <percentage>#{3} , <alpha-value>? ) | rgb( <number>#{3} , <alpha-value>? )"
+ "syntax": "rgb( <percentage>{3} [ / <alpha-value> ]? ) | rgb( <number>{3} [ / <alpha-value> ]? ) | rgb( <percentage>#{3} [ , <alpha-value> ]? ) | rgb( <number>#{3} [ , <alpha-value> ]? )"
},
"rgba()": {
- "syntax": "rgba( <percentage>{3} [ / <alpha-value> ]? ) | rgba( <number>{3} [ / <alpha-value> ]? ) | rgba( <percentage>#{3} , <alpha-value>? ) | rgba( <number>#{3} , <alpha-value>? )"
+ "syntax": "rgba( <percentage>{3} [ / <alpha-value> ]? ) | rgba( <number>{3} [ / <alpha-value> ]? ) | rgba( <percentage>#{3} [ , <alpha-value> ]? ) | rgba( <number>#{3} [ , <alpha-value> ]? )"
},
"rotate()": {
"syntax": "rotate( <angle> )" |
First of all,
Nope, there are much more syntaxes with such case. Moreover, patterns
Delimiter |
Btw, I'm not sure it's possible to express CSS syntax definition in EBNF. Because it has rules much complicated than optional omissible comma, for example low priority matching (see some notes about it here) or |
The VDS syntax allows a non-context free mode of automatic comma removal (requires at least some sort of lookahead/backtracking). So workaround the main two grammars where we encounter this: rgb/rgba. We group the comma and the following alpha value and make the whole group optional. Add to ticket mdn/data#341. However, looks like the workaround is unlikely to be incorporated since the contextual comma removal appears desired for ease of specifying those cases.
It appears that both the rgb and rgba value definitions are incorrect.
data/css/syntaxes.json
Line 531 in a2e2d7a
rgb( <percentage>{3} [ / <alpha-value> ]? ) | rgb( <number>{3} [ / <alpha-value> ]? ) | rgb( <percentage>#{3} , <alpha-value>? ) | rgb( <number>#{3} , <alpha-value>? )
From https://drafts.csswg.org/css-color/#rgb-functions:
rgb() = rgb( <percentage>{3} [ / <alpha-value> ]? ) | rgb( <number>{3} [ / <alpha-value> ]? )
I'm not sure if the
rgb( <number>#{3} , <alpha-value>? )
format is listed in another spec but if so, it likely should be the following so as not to allow for a trailing comma.rgb( <number>#{3} [, <alpha-value>]? )
The text was updated successfully, but these errors were encountered: