Skip to content

Commit 36ad646

Browse files
committed
Grammar fixes to allow attr() inside calc(), and to fix unary operator issue.
1 parent 64afff8 commit 36ad646

2 files changed

Lines changed: 23 additions & 9 deletions

File tree

css3-values/Overview.html

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,6 +1334,11 @@ <h3 id=calc-notation><span class=secno>8.1. </span> Mathematical
13341334
href="#time-value"><var>&lt;time></var></a>, <a
13351335
href="#number-value"><var>&lt;number></var></a>, or <a
13361336
href="#integer-value"><var>&lt;integer></var></a> values are allowed.
1337+
Components of a ‘<a href="#calc"><code class=css>calc()</code></a>
1338+
expression can be literal values, ‘<a href="#attr"><code
1339+
class=css>attr()</code></a>’ expressions, or <a
1340+
href="#percentage-value"><var>&lt;percentage></var></a> values that
1341+
resolve to one of the preceding types.
13371342

13381343
<p> The computed value of a calc() expression is the expression with all
13391344
components computed, with all multiplication/division subexpressions
@@ -1420,8 +1425,9 @@ <h4 id=calc-syntax><span class=secno>8.1.1. </span> Syntax</h4>
14201425
math : calc S*;
14211426
calc : "calc(" S* sum S* ")";
14221427
sum : product [ S+ [ "+" | "-" ] S+ product ]*;
1423-
product : unit [ S* [ "*" | "/" ] S* unit ]*;
1424-
unit : ["+"|"-"]? [ NUMBER | DIMENSION | PERCENTAGE | "(" S* sum S* ")" ];</pre>
1428+
product : unit [ S* [ "*" S* unit | "/" S* NUMBER ] ]*;
1429+
attr : "attr(" S* wqname [ S+ type-keyword ]? S* [ "," [ unit | calc ] S* ]? ")";
1430+
unit : [ NUMBER | DIMENSION | PERCENTAGE | "(" S* sum S* ")" | attr ];</pre>
14251431

14261432
<p class=note>Note that the grammar requires spaces around binary ‘<code
14271433
class=css>+</code>’ and ‘<code class=css>-</code>’ operators. The
@@ -1463,12 +1469,15 @@ <h4 id=calc-type-checking><span class=secno>8.1.2. </span> Type Checking</h4>
14631469
href="#resolved-type"><i>resolved type</i></a> of the expression is
14641470
determined by the types of the values it contains. <a
14651471
href="#number"><code>NUMBER</code></a> tokens are of type <a
1466-
href="#number-value"><var>&lt;number></var></a>. A <a
1472+
href="#number-value"><var>&lt;number></var></a> or <a
1473+
href="#integer-value"><var>&lt;integer></var></a>. A <a
14671474
href="#dimension"><code>DIMENSION</code></a> token's type is given by its
14681475
unit (‘<code class=css>cm</code>’ is <a
14691476
href="#length-value"><var>&lt;length></var></a>, ‘<a href="#deg"><code
14701477
class=css>deg</code></a>’ is <a
1471-
href="#angle-value"><var>&lt;angle></var></a>, etc.). If percentages are
1478+
href="#angle-value"><var>&lt;angle></var></a>, etc.). An ‘<a
1479+
href="#attr"><code class=css>attr()</code></a>’ expression's type is
1480+
given by its <var>&lt;type-or-unit></var> argument. If percentages are
14721481
accepted in the context in which the expression is placed, a <a
14731482
href="#percentage"><code>PERCENTAGE</code></a> token has the type of the
14741483
value that percentages are relative to; otherwise, a math expression

css3-values/Overview.src.html

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,10 @@ <h3 id="calc-notation">
892892
<var>&lt;time></var>,
893893
<var>&lt;number></var>, or
894894
<var>&lt;integer></var>
895-
values are allowed.</p>
895+
values are allowed.
896+
Components of a ''calc()'' expression can be literal values,
897+
''attr()'' expressions, or <var>&lt;percentage></var> values
898+
that resolve to one of the preceding types.
896899

897900
<p>
898901
The computed value of a calc() expression is the expression
@@ -982,8 +985,9 @@ <h4 id='calc-syntax'>
982985
math : calc S*;
983986
calc : "calc(" S* sum S* ")";
984987
sum : product [ S+ [ "+" | "-" ] S+ product ]*;
985-
product : unit [ S* [ "*" | "/" ] S* unit ]*;
986-
unit : ["+"|"-"]? [ NUMBER | DIMENSION | PERCENTAGE | "(" S* sum S* ")" ];</pre>
988+
product : unit [ S* [ "*" S* unit | "/" S* NUMBER ] ]*;
989+
attr : "attr(" S* wqname [ S+ type-keyword ]? S* [ "," [ unit | calc ] S* ]? ")";
990+
unit : [ NUMBER | DIMENSION | PERCENTAGE | "(" S* sum S* ")" | attr ];</pre>
987991

988992
<p class='note'>Note that the grammar requires spaces around binary ''+''
989993
and ''-'' operators. The ''*'' and ''/'' operators do not require
@@ -1021,9 +1025,10 @@ <h4 id='calc-type-checking'>
10211025
The <i>resolved type</i> must be valid for where the expression is placed;
10221026
otherwise, the expression is invalid.
10231027
The <i>resolved type</i> of the expression is determined by the types of the values it contains.
1024-
<code>NUMBER</code> tokens are of type <var>&lt;number></var>.
1028+
<code>NUMBER</code> tokens are of type <var>&lt;number></var> or <var>&lt;integer></var>.
10251029
A <code>DIMENSION</code> token's type is given by its unit
1026-
(''cm'' is <var>&lt;length></var>, ''deg'' is <var>&lt;angle></var>, etc.).
1030+
(''cm'' is <var>&lt;length></var>, ''deg'' is <var>&lt;angle></var>, etc.).
1031+
An ''attr()'' expression's type is given by its <var>&lt;type-or-unit></var> argument.
10271032
If percentages are accepted in the context in which the expression is placed,
10281033
a <code>PERCENTAGE</code> token has the type of the value that percentages are relative to;
10291034
otherwise,

0 commit comments

Comments
 (0)