Skip to content

Commit 867cf58

Browse files
committed
[css-variables] Tweak grammar, per dbaron's comments.
--HG-- extra : rebase_source : 6fa9f4bd4ca6d0e97f47478d5de31c308a840c5b
1 parent 439c359 commit 867cf58

2 files changed

Lines changed: 54 additions & 18 deletions

File tree

css-variables/Overview.html

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,9 @@ <h2 id=defining-variables><span class=secno>2. </span> Defining Custom
261261
<tr>
262262
<th>Values:
263263

264-
<td><var>&lt;value></var>
264+
<td><a href="#ltvalue"><var>&lt;value></var></a> | <a
265+
href="#ltcdo"><var>&lt;CDO></var></a> | <a
266+
href="#ltcdc"><var>&lt;CDC></var></a>
265267

266268
<tr>
267269
<th>Initial:
@@ -313,20 +315,32 @@ <h2 id=defining-variables><span class=secno>2. </span> Defining Custom
313315
</div>
314316

315317
<p> <a href="#custom-property"><i>Custom properties</i></a> have an
316-
extremely permissive value grammar, defined as the "value" production in
317-
<a href="http://www.w3.org/TR/CSS2/syndata.html#tokenization">CSS 2.1
318-
Chapter 4.1</a> <a href="#CSS21"
319-
rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a>. This implies that any valid
320-
CSS value can be used, but it's much wider than that. Roughly, anything
321-
can be used except for unclosed quotes, parens, braces, or square
322-
brackets, or any character that would normally end a declaration (a
323-
top-level semicolon or close brace).
318+
extremely permissive value grammar. The <dfn id=ltvalue>&lt;value></dfn>
319+
in its grammar corresponds to the "value" production in <a
320+
href="http://www.w3.org/TR/CSS2/syndata.html#tokenization">CSS 2.1 Chapter
321+
4.1</a> <a href="#CSS21" rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a>,
322+
while <dfn id=ltcdo>&lt;CDO></dfn> and <dfn id=ltcdc>&lt;CDC></dfn>
323+
correspond to the tokens of the same name from the same chapter (they
324+
represent HTML comments showing up in CSS text - "&lt;!--" and "--&gt;").
325+
This is a very technical way of saying that nearly anything can be used in
326+
the value of a custom property, save unmatched closing brackets ("]", ")",
327+
or "}"), a top-level semicolon (as it will end the property), a
328+
"!important" that's not at the end, or invalid tokens (such as BAD_STRING
329+
and BAD_URL).
324330

325331
<p class=note> Note: Custom properties can contain a trailing ‘<code
326332
class=css>!important</code>’, but this is automatically removed from the
327333
property's value by the CSS parser, and makes the custom property
328334
"important" in the CSS cascade.
329335

336+
<div class=example> For example, the following is a valid custom property:
337+
<pre>var-foo: if(x > 5) this.width = 10;</pre>
338+
339+
<p> While this value is obviously useless as a <a
340+
href="#cascading-variable"><em>variable</em></a>, as it would be invalid
341+
in any normal property, it might be read and acted on by JavaScript.
342+
</div>
343+
330344
<p> There are an infinity of <a href="#custom-property"><i>custom
331345
properties</i></a>, but the initial value of a <a
332346
href="#custom-property"><i>custom property</i></a> is an empty invalid
@@ -1029,6 +1043,10 @@ <h2 class=no-num id=index>Index</h2>
10291043
<li>cascading variable, <a href="#cascading-variable"
10301044
title="section 2."><strong>2.</strong></a>
10311045

1046+
<li>&lt;CDC>, <a href="#ltcdc" title="section 2."><strong>2.</strong></a>
1047+
1048+
<li>&lt;CDO>, <a href="#ltcdo" title="section 2."><strong>2.</strong></a>
1049+
10321050
<li>creator, <a href="#cssvariablesdeclaration-creator"
10331051
title="section 4.2."><strong>4.2.</strong></a>
10341052

@@ -1072,6 +1090,9 @@ <h2 class=no-num id=index>Index</h2>
10721090
title="section 5.2."><strong>5.2.</strong></a>
10731091
</ul>
10741092

1093+
<li>&lt;value>, <a href="#ltvalue"
1094+
title="section 2."><strong>2.</strong></a>
1095+
10751096
<li>var-*, <a href="#var-" title="section 2."><strong>2.</strong></a>
10761097

10771098
<li>variable, <a href="#cascading-variable"
@@ -1106,7 +1127,7 @@ <h2 class=no-num id=property-index>Property index</h2>
11061127
<tr>
11071128
<th><a class=property href="#var-">var-*</a>
11081129

1109-
<td>&lt;value>
1130+
<td>&lt;value> | &lt;CDO> | &lt;CDC>
11101131

11111132
<td>(nothing, see prose)
11121133

css-variables/Overview.src.html

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ <h2 id="defining-variables">
124124
<td><dfn>var-*</dfn>
125125
<tr>
126126
<th>Values:
127-
<td><var>&lt;value></var>
127+
<td><var>&lt;value></var> | <var>&lt;CDO></var> | <var>&lt;CDC></var>
128128
<tr>
129129
<th>Initial:
130130
<td>(nothing, see prose)
@@ -165,19 +165,34 @@ <h2 id="defining-variables">
165165
</div>
166166

167167
<p>
168-
<i>Custom properties</i> have an extremely permissive value grammar,
169-
defined as the "value" production in <a href="http://www.w3.org/TR/CSS2/syndata.html#tokenization">CSS 2.1 Chapter 4.1</a> [[!CSS21]].
170-
This implies that any valid CSS value can be used,
171-
but it's much wider than that.
172-
Roughly, anything can be used except for unclosed quotes, parens, braces, or square brackets,
173-
or any character that would normally end a declaration
174-
(a top-level semicolon or close brace).
168+
<i>Custom properties</i> have an extremely permissive value grammar.
169+
The <dfn>&lt;value></dfn> in its grammar corresponds to the "value" production
170+
in <a href="http://www.w3.org/TR/CSS2/syndata.html#tokenization">CSS 2.1 Chapter 4.1</a> [[!CSS21]],
171+
while <dfn>&lt;CDO></dfn> and <dfn>&lt;CDC></dfn> correspond to the tokens of the same name
172+
from the same chapter
173+
(they represent HTML comments showing up in CSS text - "&lt;!--" and "--&gt;").
174+
This is a very technical way of saying that nearly anything can be used in the value of a custom property,
175+
save unmatched closing brackets ("]", ")", or "}"),
176+
a top-level semicolon (as it will end the property),
177+
a "!important" that's not at the end,
178+
or invalid tokens (such as BAD_STRING and BAD_URL).
175179

176180
<p class='note'>
177181
Note: Custom properties can contain a trailing ''!important'',
178182
but this is automatically removed from the property's value by the CSS parser,
179183
and makes the custom property "important" in the CSS cascade.
180184

185+
<div class='example'>
186+
For example, the following is a valid custom property:
187+
188+
<pre>var-foo: if(x > 5) this.width = 10;</pre>
189+
190+
<p>
191+
While this value is obviously useless as a <em>variable</em>,
192+
as it would be invalid in any normal property,
193+
it might be read and acted on by JavaScript.
194+
</div>
195+
181196
<p>
182197
There are an infinity of <i>custom properties</i>,
183198
but the initial value of a <i>custom property</i> is an empty invalid value.

0 commit comments

Comments
 (0)