You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[css-values] Define value syntax that limits <integer>, <number>, <length>, etc. to ranges #355
Many properties only accept positive values. Negative values are illegal, and are parse errors. This is currently only defined in prose for the relevant property. Examples: width, height, line-height.
In contrast, other properties have logical bounds, but values outside these bounds are parsed as normal and only clamped at used value time. Examples: opacity, numeric parameters in color functions.
I'm sure it would be useful for both authors and implementers if the property value syntax explicitly indicated whether negative values would be a parse error or not. That requires new value types in CSS Values & Units.
I'm not sure if there are any other common "illegal value" restrictions currently defined in prose, but it's worth looking around to see if there are, and if they can also be standardized into the value definition syntax.
Well, "positive" is only allowed for integers, not numbers or dimensions, because it constitutes an open range otherwise, which is informally disallowed. We do use non-negative (sometimes paired with prose that floors it at some non-zero value), but that's harder to express easily.
Mathematically, "positive" usually means zero or greater, which is what I was thinking of, although depending on how the CSS parser handles -0, you might need some extra text in there.
"non-zero positive integer" would be another possible type, if that's actually required anywhere.
Mathematically, "positive" usually means zero or greater, which is what I was thinking of, although depending on how the CSS parser handles -0, you might need some extra text in there.
That's not really true in my experience? Zero is neither positive nor negative, and there's a lot of stuff backing that up: the relatively common usage of "non-negative" in precise technical contexts, the implementations of sign() functions in various languages, the fact that +0 and -0 are mathematically equivalent, etc. CSS has been pretty precise about this, because we've gotten bug reports about "why isn't 0 valid?" when we were imprecise and just used "positive". At best, whether 0 is considered "positive" or not is ambiguous and context-sensitive.
At best, whether 0 is considered "positive" or not is ambiguous and context-sensitive.
OK, I agree that a completely unambiguous terminology would be better. But the rest of my suggestion still stands: can we define <non-negative-integer>, <non-negative-length>, etc., data types, so that these restrictions do not have to be defined in prose?
I don't have a problem with this in theory, but in practice <non-negative-integer> eats up a much larger part of the measure. For grammars with more than a handful of possible value components, it triggers more wrapping and makes them harder to read. So while defining these limits in prose is maybe not ideal, I'm less than enthusiastic about adopting these new types. :(
Yes, I'm certainly not stuck on the syntax. I just want the full parsing requirements to be unambiguously defined by the grammar.
Another approach would be to express it numerically, something like <length >= 0>, <integer > 0>, except without > characters! <length gte 0> and <integer gt 0>?
Thinking @AmeliaBR's latest idea further, <length min 0>, <length max 100% abs>, <integer 0..255> show different syntax that should be readable instantly for many people.
The discussion on clamping column width values (#1741) made me think of this again.
One final option for terminology: Take a cue from WebIDL, and use "unsigned" for values that cannot be negative. So it would be <unsigned-integer>, <unsigned-number>, <unsigned-length-percentage>, etc. For the rare cases: <non-zero-unsigned-integer>.
That said, I still think I prefer an explicit constraints syntax, like <length min 0>, as it is easier to understand on its own.
Regardless of the syntax, I still would very strongly like to add this option to the CSS grammar, so that all parser constraints on values can be expressed in the grammar.
So, I'm requesting this for the WG agenda, with the following questions for discussion:
Should the CSS Value Definition Grammar be expanded to allow it to express all parser-level constraints on allowed values?
If so, how should the constraints be expressed?
By adding new data type names for all existing constrained types (non-negative numbers, non-negative lengths, strictly positive integers, etc.)?
Or, by adding a generic way of indicating maximum and minimum values for any numeric type?
If we can get a resolution on those points, then we can bikeshed the exact syntax in a more focused way.
The Working Group just discussed Define <positive-integer>, <positive-number>, <positive-length>, etc. sub-types, and agreed to the following resolutions:
RESOLVED: Extend value definition syntax to handle value ranges and possibly other syntactic restrictions, syntax TBD
The full IRC log of that discussion
<dael> Topic: Define <positive-integer>, <positive-number>, <positive-length>, etc. sub-types
<dael> github: https://github.com//issues/355
<dael> AmeliaBR: A couple years ago there was discussion and it got lost in bikeshedding syntax. I wanted to at least get a clear opinion from the group if the idea is good.
<dael> AmeliaBR: I'd like to see if that when we have properties with constraints enforced by the parser, most common is no negative values, there is a way to explain that in the grammar rather then only prose.
<dael> AmeliaBR: It would be convenient for people impl parsers if the grammar covered everything esp now that Houdini is exposing the value syntax. Might be time to be more strict about value definition language.
<florian> +1, makes total sense to me
<dael> AmeliaBR: I was hoping to get a resolution that it would be a good idea to extend value definition lang to cover all constraints from the parser.
<dbaron> "all constraints that can be enforced by the parser" sounds like it might be a little much
<dael> AmeliaBR: I had a second question on narrowing down approaches.
<astearns> +1 from me as well
<dael> fantasai: I don't think we'll be able to put in all parsing restrictions because I remember there are restrictions not in the grammar that aren't just about limiting range of numbers. We won't get to 100% but it should be possible to put range restrictions. If this is author exposed syntax that might be important.
<TabAtkins> positive-int, and gez-int and gez-number seem very fine, along with gez-length/etc
<astearns> define gez?
<dael> florian: I think we could take somewhere between...in V&U we define non-negative ranges and houdini relies on that. If it's not the case already in indiviual specs we have something that looks like int but with constraints we deinfe anew type. Doesn't have to be shared in V&U. That's not actionable, that's how to write. The actionable part I'm all for it.
<TabAtkins> greater-equal-zero
<TabAtkins> p-integer, nn-integer
<dael> astearns: I'm all for having this defined in the grammar and not lost in the prose. I don't care what names we use particularly.
<dael> fantasai: I'd like the syntax to be reasonably readable and not so long that the grammar is hard to read. non-negative-integrer is really long.
<dael> fantasai: Every time we throw in one of these it wraps and it's hard to read. It seems like a great idea but I haven't seen a proposal for yes we should do it this way. If this is exposed in Houdini we should put thought in understandable and usable like we do for other property values we define.
<fantasai> s/one/one or four/
<dael> astearns: I think consensus is this is a good direction to take. Second question?
<fantasai> s/wraps/gets long and maybe wraps/
<dael> AmeliaBR: My initial idea was new name types but in the discussion there was a suggestion of introducing it more as a modifying constraint within the type. Syntax that looked readable was make it look like a HTML attribute.
<dael> AmeliaBR: It's very nice and readable. Other aspect is it's open ended. Could be a benefit, could be a negative. Do people like the idea of adding a general way of adding constraints or is it something we want to keep to named types?
<dael> TabAtkins: I hadn't seen that comment, I'll have to think about that.
<florian> I am not sure, but I am intrigued
<dael_> astearns: prop: we will add more terms tot he grammar to describe value ranges and such, but approach is in the air.
<dael_> astearns: Objections?
<fantasai> proposed resolution: Extend value definition syntax to handle value ranges and possibly other syntactic restrictions, syntax TBD
<dael_> RESOLVED: Extend value definition syntax to handle value ranges and possibly other syntactic restrictions, syntax TBD
<dbaron> I need to head out now, but I'll see you next week...
Ok, change of plans. I decided it's just as easy to make the edits as to make a few dozen issues. But I came up with a stylistic question:
Should I only be adding the bracket range notation to the blue-box definition, or also to prose references to syntax parts? I'm currently adding it in where there is a definition list that breaks out the syntax pieces, but am not otherwise adding it to prose.
I'm also leaving in all the prose restrictions (e.g. "negative values are invalid" or "negative values are not allowed").
Should I only be adding the bracket range notation to the blue-box definition, or also to prose references to syntax parts? I'm currently adding it in where there is a definition list that breaks out the syntax pieces, but am not otherwise adding it to prose.
I'm copying it to the dts defining individual grammar chunks; it's a relevant piece of information, and readers are well-served by surfacing it right at its actual point of definition.
I am removing prose restrictions that are entirely obviated by the grammar change, tho; we don't say in prose that a value "must be a length, or else it's invalid", etc., so when the grammar expresses that it's non-negative, no need to say that explicitly again in prose.
Activity
tabatkins commentedon Jul 28, 2016
Well, "positive" is only allowed for integers, not numbers or dimensions, because it constitutes an open range otherwise, which is informally disallowed. We do use non-negative (sometimes paired with prose that floors it at some non-zero value), but that's harder to express easily.
AmeliaBR commentedon Jul 28, 2016
Mathematically, "positive" usually means zero or greater, which is what I was thinking of, although depending on how the CSS parser handles -0, you might need some extra text in there.
"non-zero positive integer" would be another possible type, if that's actually required anywhere.
frivoal commentedon Jul 29, 2016
It is: #341 (comment)
tabatkins commentedon Aug 3, 2016
That's not really true in my experience? Zero is neither positive nor negative, and there's a lot of stuff backing that up: the relatively common usage of "non-negative" in precise technical contexts, the implementations of sign() functions in various languages, the fact that +0 and -0 are mathematically equivalent, etc. CSS has been pretty precise about this, because we've gotten bug reports about "why isn't 0 valid?" when we were imprecise and just used "positive". At best, whether 0 is considered "positive" or not is ambiguous and context-sensitive.
AmeliaBR commentedon Aug 3, 2016
OK, I agree that a completely unambiguous terminology would be better. But the rest of my suggestion still stands: can we define
<non-negative-integer>,<non-negative-length>, etc., data types, so that these restrictions do not have to be defined in prose?fantasai commentedon Oct 24, 2017
I don't have a problem with this in theory, but in practice
<non-negative-integer>eats up a much larger part of the measure. For grammars with more than a handful of possible value components, it triggers more wrapping and makes them harder to read. So while defining these limits in prose is maybe not ideal, I'm less than enthusiastic about adopting these new types. :(tabatkins commentedon Oct 24, 2017
We can go with shorter names;
<p-integer>,<nn-integer>, etc. Unsure if that's worthwhile.AmeliaBR commentedon Oct 25, 2017
Yes, I'm certainly not stuck on the syntax. I just want the full parsing requirements to be unambiguously defined by the grammar.
Another approach would be to express it numerically, something like
<length >= 0>,<integer > 0>, except without>characters!<length gte 0>and<integer gt 0>?Crissov commentedon Oct 25, 2017
You could use more vulgar terms. They come with varying definitions outside CSS, but would of course have an unambiguous one inside:
<whole-number>,<integer><natural-number>,<natural-integer>– either positive or non-negative<ordinal>,<ordinal-number>,<ordinal-integer>,<rank-integer>… – positive<cardinal>,<cardinal-number>,<cardinal-integer>,<size-integer>,<set-integer>,<counting-number>,<count-integer>… – non-negativeThinking @AmeliaBR's latest idea further,
<length min 0>,<length max 100% abs>,<integer 0..255>show different syntax that should be readable instantly for many people.AmeliaBR commentedon Mar 16, 2018
The discussion on clamping column width values (#1741) made me think of this again.
One final option for terminology: Take a cue from WebIDL, and use "unsigned" for values that cannot be negative. So it would be
<unsigned-integer>,<unsigned-number>,<unsigned-length-percentage>, etc. For the rare cases:<non-zero-unsigned-integer>.That said, I still think I prefer an explicit constraints syntax, like
<length min 0>, as it is easier to understand on its own.Regardless of the syntax, I still would very strongly like to add this option to the CSS grammar, so that all parser constraints on values can be expressed in the grammar.
So, I'm requesting this for the WG agenda, with the following questions for discussion:
Should the CSS Value Definition Grammar be expanded to allow it to express all parser-level constraints on allowed values?
If so, how should the constraints be expressed?
If we can get a resolution on those points, then we can bikeshed the exact syntax in a more focused way.
css-meeting-bot commentedon Apr 4, 2018
The Working Group just discussed
Define <positive-integer>, <positive-number>, <positive-length>, etc. sub-types, and agreed to the following resolutions:RESOLVED: Extend value definition syntax to handle value ranges and possibly other syntactic restrictions, syntax TBDThe full IRC log of that discussion
<dael> Topic: Define <positive-integer>, <positive-number>, <positive-length>, etc. sub-types<dael> github: https://github.com//issues/355
<dael> AmeliaBR: A couple years ago there was discussion and it got lost in bikeshedding syntax. I wanted to at least get a clear opinion from the group if the idea is good.
<dael> AmeliaBR: I'd like to see if that when we have properties with constraints enforced by the parser, most common is no negative values, there is a way to explain that in the grammar rather then only prose.
<dael> AmeliaBR: It would be convenient for people impl parsers if the grammar covered everything esp now that Houdini is exposing the value syntax. Might be time to be more strict about value definition language.
<florian> +1, makes total sense to me
<dael> AmeliaBR: I was hoping to get a resolution that it would be a good idea to extend value definition lang to cover all constraints from the parser.
<dbaron> "all constraints that can be enforced by the parser" sounds like it might be a little much
<dael> AmeliaBR: I had a second question on narrowing down approaches.
<astearns> +1 from me as well
<dael> fantasai: I don't think we'll be able to put in all parsing restrictions because I remember there are restrictions not in the grammar that aren't just about limiting range of numbers. We won't get to 100% but it should be possible to put range restrictions. If this is author exposed syntax that might be important.
<TabAtkins> positive-int, and gez-int and gez-number seem very fine, along with gez-length/etc
<astearns> define gez?
<dael> florian: I think we could take somewhere between...in V&U we define non-negative ranges and houdini relies on that. If it's not the case already in indiviual specs we have something that looks like int but with constraints we deinfe anew type. Doesn't have to be shared in V&U. That's not actionable, that's how to write. The actionable part I'm all for it.
<TabAtkins> greater-equal-zero
<TabAtkins> p-integer, nn-integer
<dael> astearns: I'm all for having this defined in the grammar and not lost in the prose. I don't care what names we use particularly.
<dael> fantasai: I'd like the syntax to be reasonably readable and not so long that the grammar is hard to read. non-negative-integrer is really long.
<dael> fantasai: Every time we throw in one of these it wraps and it's hard to read. It seems like a great idea but I haven't seen a proposal for yes we should do it this way. If this is exposed in Houdini we should put thought in understandable and usable like we do for other property values we define.
<fantasai> s/one/one or four/
<dael> astearns: I think consensus is this is a good direction to take. Second question?
<fantasai> s/wraps/gets long and maybe wraps/
<dael> AmeliaBR: My initial idea was new name types but in the discussion there was a suggestion of introducing it more as a modifying constraint within the type. Syntax that looked readable was make it look like a HTML attribute.
<dael> AmeliaBR: It's very nice and readable. Other aspect is it's open ended. Could be a benefit, could be a negative. Do people like the idea of adding a general way of adding constraints or is it something we want to keep to named types?
<dael> TabAtkins: I hadn't seen that comment, I'll have to think about that.
<florian> I am not sure, but I am intrigued
<dael_> astearns: prop: we will add more terms tot he grammar to describe value ranges and such, but approach is in the air.
<dael_> astearns: Objections?
<fantasai> proposed resolution: Extend value definition syntax to handle value ranges and possibly other syntactic restrictions, syntax TBD
<dael_> RESOLVED: Extend value definition syntax to handle value ranges and possibly other syntactic restrictions, syntax TBD
<dbaron> I need to head out now, but I'll see you next week...
11 remaining items
AmeliaBR commentedon Feb 25, 2019
Bikeshed issue: speced/bikeshed#1441
I'll make the tracking issue for the edits once that is resolved.
[css-value-3] Define new bracketed range notation for the CSS value d…
tabatkins commentedon Apr 25, 2019
Bikeshed's updated, plz make tracking issues @AmeliaBR ^_^
AmeliaBR commentedon Apr 25, 2019
Darnit. I had such a good excuse for not working on this. Ok, I'll tackle that this weekend.
AmeliaBR commentedon May 5, 2019
Ok, change of plans. I decided it's just as easy to make the edits as to make a few dozen issues. But I came up with a stylistic question:
Should I only be adding the bracket range notation to the blue-box definition, or also to prose references to syntax parts? I'm currently adding it in where there is a definition list that breaks out the syntax pieces, but am not otherwise adding it to prose.
I'm also leaving in all the prose restrictions (e.g. "negative values are invalid" or "negative values are not allowed").
tabatkins commentedon Oct 3, 2019
I'm copying it to the
dts defining individual grammar chunks; it's a relevant piece of information, and readers are well-served by surfacing it right at its actual point of definition.I am removing prose restrictions that are entirely obviated by the grammar change, tho; we don't say in prose that a value "must be a length, or else it's invalid", etc., so when the grammar expresses that it's non-negative, no need to say that explicitly again in prose.
Merge pull request #355 from saschanaz/patch-1