@@ -518,6 +518,18 @@ <h4>The 'calc', 'min' and 'max' functions</h4>
518518< p > The expression language of these functions is described by
519519the grammar and prose below.
520520
521+ < pre >
522+ S : calc | min | max;
523+ calc : "calc(" S* sum ")" S*;
524+ min : "min(" S* sum [ "," S* sum ]* )"" S*;
525+ max : "max(" S* sum [ "," S* sum ]* ")" S*;
526+ sum : product [ [ "+" | "-" ] 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+ <!--
521533<pre>
522534S : calc | min | max;
523535calc : "calc(" S* sum ")" S*;
@@ -528,6 +540,8 @@ <h4>The 'calc', 'min' and 'max' functions</h4>
528540unit : ["+"|"-"]? [ NUMBER S* | DIMENSION S* | PERCENTAGE S* |
529541 min | max | "(" S* sum ")" S* ];
530542</pre>
543+ -->
544+
531545
532546< p > The semantic constraints are as follows: The context of the
533547expression imposes a target type, which is one of length, frequency,
@@ -546,75 +560,11 @@ <h4>The 'calc', 'min' and 'max' functions</h4>
546560< li > At "*":< br >
547561 check: at least one side is "number" return: the type of the other side
548562< li > At "/":< br >
549- check: either right side is "number," or both have the same type< br >
550- return: if the former, type of left side; otherwise "number"
551- < li > At "mod": < br >
552- check: both sides have the same type< br >
553- return: "number"
563+ check: right side is "number"< br >
564+ return: the type of the left side
554565</ ol >
555566
556567
557- <!--
558- <p>A value is ignored if a division by zero or other mathematical
559- errors occur in the calculation.
560-
561- <div class="example">
562- <p>In this example, the second declaration will be ignored due to a
563- division by zero.
564- <pre>
565- p {
566- margin: 1em;
567- margin: calc(1em-2px) calc(1em/0)
568- }
569- </pre>
570- </div>
571-
572- <p class=issue>Issue: At a later date new operators such as min/max, conditionals, new constants, division by length units etc. may be added.
573-
574-
575- <p>The expression language is defined by 'length-expression' below:
576-
577- <pre>
578- <length> := calc( <length-expression> ) | <atomic-length>
579-
580- <length-expression> := S* <length-additive-expression> S*
581-
582- <length-additive-expression> :=
583- <length-multiplicative-expression> |
584- <length-additive-expression> S+ '+' S+ <length-multiplicative-expression> |
585- <length-additive-expression> S+ '-' S+ <length-multiplicative-expression>
586-
587- <length-multiplicative-expression>
588- <length-term> |
589- <length-multiplicative-expression> S* '*' S* <number-term> |
590- <number-multiplicative-expression> S* '*' S* <length-term> |
591- <length-multiplicative-expression> S* '/' S* <number-term> |
592- <length-multiplicative-expression> S+ 'mod' S+ <number-term>
593-
594- <length-term> := '(' <length-expression> ')' | <atomic-length>
595-
596- <number-additive-expression> :=
597- <number-multiplicative-expression> |
598- <number-additive-expression> S+ '+' S+ <number-multiplicative-expression> |
599- <number-additive-expression> S+ '-' S+ <number-multiplicative-expression>
600-
601- <number-multiplicative-expression> :=
602- <number-term> |
603- <length-multiplicative-expression> S* '/' S* <length-term> |
604- <length-multiplicative-expression> S+ 'mod' S+ <length-term>
605-
606- <number-term> := '(' *S <number-additive-expression> *S ')' | <number>
607-
608- <atomic-length> := <number><length-unit>
609- </pre>
610-
611- <div class="note">Note that 'mod' is used instead of '%' for modulus since it is very easy to
612- get confused about whether '%' is acting as a unit or an operator. At
613- least with 'mod' it always causes a parse error — invalid unit — in the
614- otherwise ambiguous cases.
615- </div>
616- -->
617-
618568
619569< h3 > <string></ h3 >
620570
0 commit comments