@@ -521,58 +521,57 @@ <h4>The 'calc', 'min' and 'max' functions</h4>
521521< pre >
522522S : calc | min | max;
523523calc : "calc(" S* sum ")" S*;
524- min : "min(" S* sum [ "," S* sum ]* )"" S*;
525- max : "max(" S* sum [ "," S* sum ]* ")" S*;
526- sum : product [ S+ [ "+" | "-" ] S+ product ]*;
527- product : unit [[ "*" S* unit ] | [ "/" S* NUMBER ]] *;
528- unit : ["+"|"-"]? [ NUMBER S* | DIMENSION S* | PERCENTAGE S* |
529- min | max | "(" S* sum ")" S* ];
530- </ pre >
531-
532- <!--
533- <pre>
534- S : calc | min | max;
535- calc : "calc(" S* sum ")" S*;
536- min : "min(" S* sum [ "," S* sum ]* )"" S*;
524+ min : "min(" S* sum [ "," S* sum ]* ")" S*;
537525max : "max(" S* sum [ "," S* sum ]* ")" S*;
538526sum : product [ [ "+" | "-" ] S* product ]*;
539527product : unit [ [ "*" | "/" | "mod" ] S* unit ]*;
540528unit : ["+"|"-"]? [ NUMBER S* | DIMENSION S* | PERCENTAGE S* |
541529 min | max | "(" S* sum ")" S* ];
542530</ pre >
543- -->
544- < p > Division by zero is a parse error.
545-
546- <!--
547- <p>Values inside a calc() expression must all be either (a)
548- numbers or (b) legal values for the property, or values that
549- would be legal if it weren't for range restrictions (such
550- as the restriction that 'width' accepts only positive values).
551- -->
552-
553- < p > The semantic constraints are as follows: The context of the
554- expression imposes a < em > target type</ em > , which is one of length, frequency,
555- angle, time, or number. Any PERCENTAGE token in the expression has the
556- target type. The NUMBER tokens are of type number, and the DIMENSION
557- tokens have types of their units ('cm' is length, 'deg' is angle
558- etc.). At each operator, the types of the left and right side have to
559- be compared and, if compatible, they yield a < em > result type</ em > , roughly as
560- follows (the following ignores precedence rules on the operators for
561- simplicity):
562-
563531
532+ < p > The context of the expression imposes a target type, which is one
533+ of length, frequency, angle, time, or number. NUMBER tokens are of
534+ type number. DIMENSION tokens have types of their units ('cm' is
535+ length, 'deg' is angle etc.); any DIMENSION whose type does not match
536+ the target type is not allowed and must be a parse error. If
537+ percentages are accepted in that context and convertible to the target
538+ type, a PERCENTAGE token in the expression has the target type;
539+ otherwise percentages are not allowed and must be a parse error.
540+
541+ < p > To make expressions simpler, operators have restriction on the
542+ types they accept. At each operator, the types of the left and right
543+ side have to be checked for these restrictions. If compatible, they
544+ return roughly as follows (the following ignores precedence rules on
545+ the operators for simplicity):
564546
565547< ol >
566548< li > At ",", "+", "-":< br >
567549 check: both sides have the same type< br >
568550 return: that type
569551< li > At "*":< br >
570- check: at least one side is "number" return: the type of the other side
552+ check: at least one side is "number" < br >
553+ return: the type of the other side
571554< li > At "/":< br >
572555 check: right side is "number"< br >
573556 return: the type of the left side
574557</ ol >
575558
559+ < p > Division by zero is a parse error.
560+
561+ < p > The value resulting from an expression must be clamped to the
562+ range allowed in the target context.
563+
564+ < div class =example >
565+ These two are equivalentequivalent to 'width: 0px' since widths
566+ smaller than 0px are not allowed.
567+
568+ < pre >
569+ width: calc(5px - 10px);
570+ width: 0px;
571+ </ pre >
572+ </ div >
573+
574+
576575< p > Given the complexities of 'width' and 'height' on table cells and
577576 table elements, calc() expressions for 'width' and 'height' on table
578577 columns, table column groups, table rows, table row groups, and
0 commit comments