8000 adding Bert's new grammar with some examples · w3c/csswg-drafts@f54bad7 · GitHub
Skip to content

Commit f54bad7

Browse files
committed
adding Bert's new grammar with some examples
1 parent 1f4f871 commit f54bad7

1 file changed

Lines changed: 61 additions & 17 deletions

File tree

css3-values/Overview.src.html

Lines changed: 61 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -475,14 +475,10 @@ <h5>The 'vm' unit</h5>
475475
units. When the height or width of the viewport is changed, lengths
476476
specified in the 'vm' unit are scaled proportionally.
477477

478-
<h4>The 'calc' function</h4>
478+
<h4>The 'calc', 'min' and 'max' functions</h4>
479479

480-
<p>The <dfn>calc(&lt;expression&gt;)</dfn> function can be used wherever length values are allowed, with the syntax given below.
480+
<p>The <dfn>calc()</dfn>, <dfn>min()</dfn>, and <dfn>max()</dfn> functions can be used wherever length values are allowed.
481481

482-
<!--
483-
The expression within the parethesis is computed at the same time as 'em' lengths are
484-
computed
485-
-->
486482

487483
<div class="example">
488484
<pre>
@@ -498,16 +494,64 @@ <h4>The 'calc' function</h4>
498494
<pre>
499495
p {
500496
margin: calc(1rem - 2px) calc(1rem - 1px);
501-
border: solid transparent; border-width: 2px 1px;
502497
}
503498
</pre>
504499
</div>
505500

501+
<div class="example">
502+
<pre>
503+
p { font-size: min(10px, 3em) }
504+
blockquote { font-size: max(30px, 3em) }
505+
</pre>
506+
</div>
507+
508+
<div class="example">
509+
<pre>
510+
.box { width: min(10% + 20px, 300px) }
511+
</pre>
512+
</div>
506513

507-
<p>The simple expression language of the 'calc()' function supports
508-
five arithmetic operators (+ and - have lowest precedence, *, /, and
509-
'mod' have highest precedence) and parentheses.
510514

515+
<p>The expression language of these functions is described by
516+
the grammar and prose below.
517+
518+
<pre>
519+
S : calc | min | max;
520+
calc : "calc(" S* sum ")" S*;
521+
min : "min(" S* sum [ "," S* sum ]* )"" S*;
522+
max : "max(" S* sum [ "," S* sum ]* ")" S*;
523+
sum : product [ [ "+" | "-" ] S* product ]*;
524+
product : unit [ [ "*" | "/" | "mod" ] S* unit ]*;
525+
unit : ["+"|"-"]? [ NUMBER S* | DIMENSION S* | PERCENTAGE S* |
526+
min | max | "(" S* sum ")" S* ];
527+
</pre>
528+
529+
<p>The semantic constraints are as follows: The context of the
530+
expression imposes a target type, which is one of length, frequency,
531+
angle, time, or number. Any PERCENTAGE token in the expression also
532+
has that type. The NUMBER tokens obviously are of type number, and the
533+
DIMENSION tokens have types that depend on their units (cm, px, deg,
534+
etc.). At each operator, the types of the left and right side have to
535+
be compared and, if compatible, they yield a result type, roughly as
536+
follows (the following ignores precedence rules on the operators for
537+
simplicity):
538+
539+
<ol>
540+
<li>At ",", "+", "-":<br>
541+
check: both sides have the same type<br>
542+
return: that type
543+
<li>At "*":<br>
544+
check: at least one side is "number" return: the type of the other side
545+
<li>At "/":<br>
546+
check: either right side is "number," or both have the same type<br>
547+
return: if the former, type of left side; otherwise "number"
548+
<li>At "mod": <br>
549+
check: both sides have the same type<br>
550+
return: "number"
551+
</ol>
552+
553+
554+
<!--
511555
<p>A value is ignored if a division by zero or other mathematical
512556
errors occur in the calculation.
513557
@@ -522,7 +566,6 @@ <h4>The 'calc' function</h4>
522566
</pre>
523567
</div>
524568
525-
526569
<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.
527570
528571
@@ -531,7 +574,7 @@ <h4>The 'calc' function</h4>
531574
<pre>
532575
&lt;length> := calc( &lt;length-expression> ) | &lt;atomic-length>
533576
534-
&lt;length-expression> := &lt;length-additive-expression>
577+
&lt;length-expression> := S* &lt;length-additive-expression> S*
535578
536579
&lt;length-additive-expression> :=
537580
&lt;length-multiplicative-expression> |
@@ -557,7 +600,7 @@ <h4>The 'calc' function</h4>
557600
&lt;length-multiplicative-expression> S* '/' S* &lt;length-term> |
558601
&lt;length-multiplicative-expression> S+ 'mod' S+ &lt;length-term>
559602
560-
&lt;number-term> := '(' &lt;number-additive-expression> ')' | &lt;number>
603+
&lt;number-term> := '(' *S &lt;number-additive-expression> *S ')' | &lt;number>
561604
562605
&lt;atomic-length> := &lt;number>&lt;length-unit>
563606
</pre>
@@ -567,6 +610,7 @@ <h4>The 'calc' function</h4>
567610
least with 'mod' it always causes a parse error &mdash; invalid unit &mdash; in the
568611
otherwise ambiguous cases.
569612
</div>
613+
-->
570614

571615

572616
<h3>&lt;string&gt;</h3>
@@ -1086,13 +1130,13 @@ <h4>Font families</h4>
10861130
<h2>Specified, computed, used, and actual values</h2>
10871131

10881132
<p>The final value of a CSS3 property for a given element is the
1089-
result of a three-step calculation. First, cascading and inheritance
1133+
result of a four-step calculation. First, cascading and inheritance
10901134
yields the <em>specified value</em> [[!CSS3CASCADE]]. Second, relative
10911135
values are computed into absolute values as far as possible without
10921136
formatting the document, thereby yielding the <em>computed value</em>.
1093-
Finally, the computed value is transformed to the <em>actual
1094-
value</em> in the layout process.</p>
1095-
1137+
The computed value is tranformed into the <em>used value</em> in the
1138+
formatting process. Finally, the computed value is transformed to
1139+
the <em>actual value</em> based on constraints in the user agent.</p>
10961140

10971141
<h3>Finding the <dfn>specified value</dfn></h3>
10981142

0 commit comments

Comments
 (0)