Skip to content

Commit 811d2a0

Browse files
committed
[css-values-5] Rewrite the comma/semicolon rules a little for clarity.
1 parent 1e46385 commit 811d2a0

1 file changed

Lines changed: 38 additions & 15 deletions

File tree

css-values-5/Overview.bs

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,16 @@ Commas and Semicolons in Functions</h4>
8989
This is all-or-nothing:
9090
either every comma in the [=functional notation=] must be written as a semicolon,
9191
or none of them must be.
92-
When the [=functional notation=]’s arguments are parsed,
93-
initially commas in the grammar match only <<comma-token>>s;
94-
if a <<semicolon-token>> is encountered,
95-
then the [=functional notation=] is re-interpreted
96-
with all commas in the grammar replaced by <<semicolon-token>>s.
92+
93+
When a [=functional notation=] is parsed,
94+
initially commas (<css>,</css>) and comma-multipliers (<css>#</css>)
95+
in the grammar match only <<comma-token>>s in the value,
96+
and any [=comma-containing productions=] are not allowed to contain <<comma-token>>s
97+
(the productions must be interpreted as ending before the comma).
98+
If a <<semicolon-token>> is encountered while parsing the [=functional notation=],
99+
the contents must be <em>re-interpreted</em>,
100+
with commas and comma-multipliers in the grammar matching only <<semicolon-token>>s in the value,
101+
and [=comma-containing productions=] being allowed to contain <<comma-token>>s.
97102

98103
Commas contained in productions defined as <dfn>comma-containing productions</dfn>
99104
(such as <<any-value>> or <<whole-value>>)
@@ -102,29 +107,47 @@ Commas and Semicolons in Functions</h4>
102107
these productions end when a <<semicolon-token>> is encountered.
103108

104109
<div class="example">
105-
The following examples are both equivalent declarations:
110+
For example, the grammar of the ''random-item()'' function is:
111+
112+
<pre>
113+
random-item( <<random-caching-options>>, [<<declaration-value>>?]# )
114+
</pre>
115+
116+
The ''#'' indicates comma-separated repetitions,
117+
so randomly choosing between three keywords
118+
would be written as normal for functions,
119+
like:
120+
121+
<pre>
122+
list-style: random-item(--x, disc, circle, square);
123+
</pre>
124+
125+
It is <em>allowed</em>, however,
126+
to "upgrade" the commas to semicolons,
127+
like:
106128

107129
<pre>
108-
list-style: toggle(disc, circle, square);
109-
list-style: toggle(disc; circle; square);
130+
list-style: random-item(--x; disc; circle; square);
110131
</pre>
111132

112-
however, this is different (and invalid):
133+
Both of the above mean the exact same thing.
134+
However, mixing commas and semicolons does not work;
135+
the following can produce an invalid value after substitution:
113136

114137
<pre>
115-
list-style: toggle(disc, circle; square);
138+
list-style: random-item(--x; disc, circle; square);
116139
</pre>
117140

118-
because it represents toggling between two values
141+
because it represents choosing between two values
119142
(<css>disc, circle</css> and <css>square</css>)
120143
and <css>disc, circle</css> is not a valid 'list-style' value.
121144

122-
This ability is important,
123-
because sometimes [=functional notation=] arguments need to include commas.
145+
However, sometimes the values you want to choose between
146+
need to include commas.
124147
For example, in 'font-family':
125148

126149
<pre>
127-
font-family: random-item(Times, serif; Arial, sans-serif; Courier, monospace);
150+
font-family: random-item(--x; Times, serif; Arial, sans-serif; Courier, monospace);
128151
</pre>
129152

130153
This randomly chooses one of three font-family lists:
@@ -133,7 +156,7 @@ Commas and Semicolons in Functions</h4>
133156
commas <em>could</em> have been used to separate them:
134157

135158
<pre>
136-
font-family: random-item(serif, sans-serif, monospace);
159+
font-family: random-item(--x, serif, sans-serif, monospace);
137160
</pre>
138161

139162
</div>

0 commit comments

Comments
 (0)