Re: [css3-values] proposal for handling division and units in calc() [ACTION-205]

On Monday 2010-08-09 20:26 +0200, Håkon Wium Lie wrote:
> Also sprach L. David Baron:
> 
>  > Therefore, I propose that:
>  > 
>  >  1. We drop the 'mod' operator since it only makes sense when
>  >     both operands have the same units.
> 
> Right. Removed from:
> 
>   http://dev.w3.org/csswg/css3-values/
> 
>  >  2. The right operand to the '/' operator be required to be unitless
>  >     (that is, a number or an expression composed of numbers).
> 
> I've changed the formal grammar to be:
> 
>    product : unit [[ "*" S* unit ] | [ "/" S* NUMBER ]] *;

This is a little different from what I'd been thinking.  This change
would mean that:
  calc(3em / (3 + 2))
is an error while:
  calc(3em * (3 + 2))
is valid.  I would prefer changing NUMBER in your proposed change
back to unit to avoid that; the change in the constraints is
sufficient to do what I was proposing.

This also led me to reread the whole formal grammar in order to
understand the change.  I noticed that there's a typo (misplaced
quote mark) that requires the following change to fix:
-min     : "min(" S* sum [ "," S* sum ]* )"" S*;
+min     : "min(" S* sum [ "," S* sum ]* ")" S*;

> and the pseudo-semantic constraints to be:
> 
>   <ol>
>   <li>At ",", "+", "-":<br>
>      check: both sides have the same type<br>
>      return: that type
>   <li>At "*":<br>
>     check: at least one side is "number" return: the type of the other side
>   <li>At "/":<br> 
>      check: right side is "number"<br>
>      return: the type of the left side
>   </ol>
> 
> Does this look right?

Yes.

>  >  3. Division by zero be a parse error (as I think it was in earlier
>  >     drafts of the specification, perhaps?).
> 
> I've added:
> 
>    Division by zero is a parse error.
> 
>  >  4. Leaf values inside a calc() expression must all be either (a)
>  >     numbers or (b) legal values for the property, or things that
>  >     would be legal values if it weren't for range restrictions (such
>  >     as the restriction that 'width' accepts only positive values).
> 
> How about percentages?

Percentages should be accepted when they are allowed values for the
property, just like any other units.  We have some properties that
accept lengths but do not accept percentages (border-*-width,
column-rule-width, letter-spacing, word-spacing, marker-offset,
outline-offset, border-spacing).  And I think properties that take
units other than length (such as times) generally do not accept
percentages.

-David

-- 
L. David Baron                                 http://dbaron.org/
Mozilla Corporation                       http://www.mozilla.com/

Received on Monday, 9 August 2010 20:48:07 UTC