Skip to content

Commit 3b96cae

Browse files
committed
[css-values] Switch calc() away from 2.1 grammars.
1 parent 718ffea commit 3b96cae

2 files changed

Lines changed: 24 additions & 44 deletions

File tree

css-values/Overview.bs

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,32 +1006,19 @@ Mathematical Expressions: ''calc()''</h3>
10061006
<h4 id='calc-syntax'>
10071007
Syntax</h4>
10081008

1009-
The expression language of these functions is described by
1010-
the grammar and prose below.
1009+
The syntax of a ''calc()'' function is:
10111010

1012-
<pre>
1013-
math : calc S*;
1014-
calc : "calc(" S* sum S* ")";
1015-
sum : product [ S+ [ "+" | "-" ] S+ product ]*;
1016-
product : unit [ S* [ "*" S* unit | "/" S* NUMBER ] ]*;
1017-
attr : "attr(" S* qname [ S+ type-keyword ]? S* [ "," [ unit | calc ] S* ]? ")";
1018-
unit : [ NUMBER | DIMENSION | PERCENTAGE | "(" S* sum S* ")" | calc | attr ];
1011+
<pre class='prod'>
1012+
<<calc()>> = calc( <<calc-sum>> )
1013+
<dfn>&lt;calc-sum></dfn> = <<calc-product>> [ [ '+' | '-' ] <<calc-product>> ]*
1014+
<dfn>&lt;calc-product></dfn> = <<calc-value>> [ '*' <<calc-value>> | '/' <<number>> ]*
1015+
<dfn>&lt;calc-value></dfn> = <<number>> | <<dimension>> | <<percentage>> | ( <<calc-sum>> )
10191016
</pre>
10201017

1021-
Note: Note that the grammar requires spaces around binary ''+'' and ''-'' operators.
1022-
The ''*'' and ''/'' operators do not require spaces.
1023-
1024-
Additionally, the following redefinition is made to the informative grammar appearing in
1025-
<a href="http://www.w3.org/TR/CSS2/grammar.html">CSS 2.1 Appendix G</a>:
1018+
<p noexport>Where a <dfn>&lt;dimension></dfn> is a <a>dimension</a>.
10261019

1027-
<pre>
1028-
term
1029-
: unary_operator?
1030-
[ NUMBER S* | PERCENTAGE S* | LENGTH S* | EMS S* | EXS S* | ANGLE S* |
1031-
TIME S* | FREQ S* ]
1032-
| STRING S* | IDENT S* | URI S* | hexcolor | function<ins> | math</ins>
1033-
;
1034-
</pre>
1020+
In addition, whitespace is required on both sides of the ''+'' and ''-'' operators.
1021+
(The ''*'' and ''/'' operaters can be used without whitespace around them.)
10351022

10361023
UAs must support ''calc()'' expressions of at least 20 terms,
10371024
where each <code>NUMBER</code>, <code>DIMENSION</code>, or <code>PERCENTAGE</code> is a term.

css-values/Overview.html

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,29 +1126,18 @@ <h3 class="heading settled heading" data-level=8.1 id=calc-notation><span class=
11261126
<h4 class="heading settled heading" data-level=8.1.1 id=calc-syntax><span class=secno>8.1.1 </span><span class=content>
11271127
Syntax</span><a class=self-link href=#calc-syntax></a></h4>
11281128

1129-
<p> The expression language of these functions is described by
1130-
the grammar and prose below.
1131-
1132-
<pre>math : calc S*;
1133-
calc : "calc(" S* sum S* ")";
1134-
sum : product [ S+ [ "+" | "-" ] S+ product ]*;
1135-
product : unit [ S* [ "*" S* unit | "/" S* NUMBER ] ]*;
1136-
attr : "attr(" S* qname [ S+ type-keyword ]? S* [ "," [ unit | calc ] S* ]? ")";
1137-
unit : [ NUMBER | DIMENSION | PERCENTAGE | "(" S* sum S* ")" | calc | attr ];
1138-
</pre>
1139-
<p class=note> Note: Note that the grammar requires spaces around binary <span class=css data-link-type=maybe title=+>+</span> and <span class=css data-link-type=maybe title=->-</span> operators.
1140-
The <span class=css data-link-type=maybe title=*>*</span> and <span class=css data-link-type=maybe title=/>/</span> operators do not require spaces.
1141-
1142-
<p> Additionally, the following redefinition is made to the informative grammar appearing in
1143-
<a href=http://www.w3.org/TR/CSS2/grammar.html>CSS 2.1 Appendix G</a>:
1144-
1145-
<pre>term
1146-
: unary_operator?
1147-
[ NUMBER S* | PERCENTAGE S* | LENGTH S* | EMS S* | EXS S* | ANGLE S* |
1148-
TIME S* | FREQ S* ]
1149-
| STRING S* | IDENT S* | URI S* | hexcolor | function<ins> | math</ins>
1150-
;
1129+
<p> The syntax of a <a class=css data-link-type=maybe href=#funcdef-calc title=calc()>calc()</a> function is:
1130+
1131+
<pre class=prod><a class="production css-code" data-link-type=function href=#funcdef-calc title=calc()>&lt;calc()&gt;</a> = calc( <a class="production css-code" data-link-type=type href=#typedef-calc-sum title="<calc-sum>">&lt;calc-sum&gt;</a> )
1132+
<dfn class=css-code data-dfn-type=type data-export="" id=typedef-calc-sum>&lt;calc-sum&gt;<a class=self-link href=#typedef-calc-sum></a></dfn> = <a class="production css-code" data-link-type=type href=#typedef-calc-product title="<calc-product>">&lt;calc-product&gt;</a> [ [ '+' | '-' ] <a class="production css-code" data-link-type=type href=#typedef-calc-product title="<calc-product>">&lt;calc-product&gt;</a> ]*
1133+
<dfn class=css-code data-dfn-type=type data-export="" id=typedef-calc-product>&lt;calc-product&gt;<a class=self-link href=#typedef-calc-product></a></dfn> = <a class="production css-code" data-link-type=type href=#typedef-calc-value title="<calc-value>">&lt;calc-value&gt;</a> [ '*' <a class="production css-code" data-link-type=type href=#typedef-calc-value title="<calc-value>">&lt;calc-value&gt;</a> | '/' <a class="production css-code" data-link-type=type href=#number-value title="<number>">&lt;number&gt;</a> ]*
1134+
<dfn class=css-code data-dfn-type=type data-export="" id=typedef-calc-value>&lt;calc-value&gt;<a class=self-link href=#typedef-calc-value></a></dfn> = <a class="production css-code" data-link-type=type href=#number-value title="<number>">&lt;number&gt;</a> | <a class="production css-code" data-link-type=type href=#typedef-dimension title="<dimension>">&lt;dimension&gt;</a> | <a class="production css-code" data-link-type=type href=#percentage-value title="<percentage>">&lt;percentage&gt;</a> | ( <a class="production css-code" data-link-type=type href=#typedef-calc-sum title="<calc-sum>">&lt;calc-sum&gt;</a> )
11511135
</pre>
1136+
<p data-noexport="">Where a <dfn class=css-code data-dfn-type=type data-noexport="" id=typedef-dimension>&lt;dimension&gt;<a class=self-link href=#typedef-dimension></a></dfn> is a <a data-link-type=dfn href=#dimension title=dimension>dimension</a>.
1137+
1138+
<p> In addition, whitespace is required on both sides of the <span class=css data-link-type=maybe title=+>+</span> and <span class=css data-link-type=maybe title=->-</span> operators.
1139+
(The <span class=css data-link-type=maybe title=*>*</span> and <span class=css data-link-type=maybe title=/>/</span> operaters can be used without whitespace around them.)
1140+
11521141
<p> UAs must support <a class=css data-link-type=maybe href=#funcdef-calc title=calc()>calc()</a> expressions of at least 20 terms,
11531142
where each <code>NUMBER</code>, <code>DIMENSION</code>, or <code>PERCENTAGE</code> is a term.
11541143
If a <a class=css data-link-type=maybe href=#funcdef-calc title=calc()>calc()</a> expression contains more than the supported number of terms,
@@ -1853,11 +1842,15 @@ <h2 class="no-num no-ref heading settled heading" id=index><span class=content>
18531842
<li>&lt;attr-fallback&gt;, <a href=#typedef-attr-fallback title="section 8.3">8.3</a>
18541843
<li>&lt;attr-name&gt;, <a href=#typedef-attr-name title="section 8.3">8.3</a>
18551844
<li>calc(), <a href=#funcdef-calc title="section 8.1">8.1</a>
1845+
<li>&lt;calc-product&gt;, <a href=#typedef-calc-product title="section 8.1.1">8.1.1</a>
1846+
<li>&lt;calc-sum&gt;, <a href=#typedef-calc-sum title="section 8.1.1">8.1.1</a>
1847+
<li>&lt;calc-value&gt;, <a href=#typedef-calc-value title="section 8.1.1">8.1.1</a>
18561848
<li>ch, <a href=#ch title="section 5.1.1">5.1.1</a>
18571849
<li>cm, <a href=#cm title="section 5.2">5.2</a>
18581850
<li>CSS-wide keywords, <a href=#css-wide-keywords title="section 3.1.1">3.1.1</a>
18591851
<li>&lt;custom-ident&gt;, <a href=#identifier-value title="section 3.2">3.2</a>
18601852
<li>deg, <a href=#deg title="section 6.1">6.1</a>
1853+
<li>&lt;dimension&gt;, <a href=#typedef-dimension title="section 8.1.1">8.1.1</a>
18611854
<li>dimension, <a href=#dimension title="section 4.4">4.4</a>
18621855
<li>dpcm, <a href=#dpcm title="section 6.4">6.4</a>
18631856
<li>dpi, <a href=#dpi title="section 6.4">6.4</a>

0 commit comments

Comments
 (0)