Skip to content

Commit fdd5d08

Browse files
committed
[css-mixins-1][css-values-5] Move the definition of <syntax> to V&U 5, since we'll be using it in multiple places.
1 parent 83a5d07 commit fdd5d08

File tree

1 file changed

+92
-4
lines changed

1 file changed

+92
-4
lines changed

css-values-5/Overview.bs

Lines changed: 92 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,18 @@ Inline Github Issues: no
1717
Default Highlight: css
1818
</pre>
1919
<pre class='link-defaults'>
20-
spec:css-values-4; type: dfn; text: determine the type of a calculation
20+
spec:css-values-4; type: dfn;
21+
text: determine the type of a calculation
22+
text: keyword
23+
text: identifier
2124
spec:selectors-4; type: dfn; text: selector
2225
spec:css-conditional-5; type:type; text:<size-feature>
2326
spec:css-conditional-5; type:dfn; text:container feature
2427
spec:css-conditional-5; type:type; text:<container-name>
28+
spec:css-mixins-1; type:dfn; text:custom function
29+
spec:css-properties-values-api; type:dfn; text: supported syntax component names
2530
spec:html; type:element; text:link
31+
spec:infra; type:dfn; text:list
2632
</pre>
2733
<style>
2834
code, small { white-space: nowrap }
@@ -94,7 +100,7 @@ Commas in Function Arguments</h4>
94100
Specifically:
95101

96102
* A [=comma-containing production=] can either start with a "{" token, or not.
97-
* If it does not start with a "{" token,
103+
* If it does not start with a "{" token,
98104
then it cannot contain commas or {} blocks,
99105
in addition to whatever specific restrictions it defines for itself.
100106
(The production stops parsing at that point,
@@ -127,7 +133,7 @@ Commas in Function Arguments</h4>
127133
need to include commas.
128134
When this is the case,
129135
wrapping the values in {}
130-
allows their commas to be distinguished
136+
allows their commas to be distinguished
131137
from the function's argument-separating commas:
132138

133139
<pre>
@@ -169,7 +175,7 @@ Commas in Function Arguments</h4>
169175
due to [=arbitrary-substitution functions=] like ''var()''.
170176
For example, ''font-family: random-item(--x, {var(--list1)}, monospace)''
171177
will work correctly
172-
regardless of whether the ''--list1'' custom property
178+
regardless of whether the ''--list1'' custom property
173179
contains a comma-separated list or not.
174180

175181
[=Functional notations=] are serialized without {} wrappers whenever possible.
@@ -194,6 +200,88 @@ Commas in Function Arguments</h4>
194200
Other contexts <em>may</em> define that they use [=non-strict comma-containing productions=],
195201
but it <em>should</em> be avoided unless necessary.
196202

203+
<h3 id=css-syntax>
204+
Specifying CSS Syntax in CSS: the <<syntax>> type</h3>
205+
206+
Some features in CSS,
207+
such as the ''attr()'' function,
208+
[=registered custom properties=],
209+
or [=custom function parameters=],
210+
allow you to specify how <em>another</em> value is meant to be parsed.
211+
This is declared via the <<syntax>> production,
212+
which resembles a limited form of the CSS [=value definition syntax=]
213+
used in specifications to define CSS features,
214+
and which represents a [=syntax definition=]:
215+
216+
<pre class="prod def" nohighlight>
217+
<dfn><<syntax>></dfn> = '*' | <<syntax-component>> [ <<syntax-combinator>> <<syntax-component>> ]+
218+
<dfn><<syntax-component>></dfn> = <<syntax-single-component>> <<syntax-multiplier>>?
219+
| '<' transform-list '>'
220+
<dfn><<syntax-single-component>></dfn> = '<' <<syntax-type-name>> '>' | <<ident>>
221+
<dfn><<syntax-type-name>></dfn> = angle | color | custom-ident | image | integer
222+
| length | length-percentage | number
223+
| percentage | resolution | string | time
224+
| url | transform-function
225+
<dfn><<syntax-combinator>></dfn> = '|'
226+
<dfn><<syntax-multiplier>></dfn> = [ '#' | '+' ]
227+
</pre>
228+
229+
A <<syntax-component>> consists of either
230+
a <<syntax-type-name>> between &lt;&gt; (angle brackets),
231+
which maps to one of the [=supported syntax component names=],
232+
or an <<ident>>, which represents any [=keyword=].
233+
Additionally,
234+
a <<syntax-component>> may contain a [[css-properties-values-api-1#multipliers|multiplier]],
235+
which indicates a [=list=] of values.
236+
237+
Note: This means that <code>&lt;length&gt;</code>
238+
and <code>length</code> are two different types:
239+
the former describes a <<length>>,
240+
whereas the latter describes a [=keyword=] <code>length</code>.
241+
242+
Multiple <<syntax-component>>s may be [[css-properties-values-api-1#combinator|combined]]
243+
with a <code>|</code> <<delim-token>>,
244+
causing the syntax components to be matched
245+
against a value
246+
in the specified order.
247+
248+
<div class='example'>
249+
<xmp class='lang-css'>
250+
<percentage> | <number> | auto
251+
</xmp>
252+
253+
The above, when parsed as a <<syntax>>,
254+
would accept <<percentage>> values,
255+
<<number>> values,
256+
as well as the keyword <code>auto</code>.
257+
</div>
258+
259+
<div class='example'>
260+
<xmp class='lang-css'>
261+
red | <color>
262+
</xmp>
263+
264+
The [=syntax definition=] resulting from the above <<syntax>>,
265+
when used as a grammar for [=parse|parsing=],
266+
would match an input <code>red</code> as an [=identifier=],
267+
but would match an input <code>blue</code> as a <<color>>.
268+
</div>
269+
270+
The <code>*</code> <<delim-token>> represents the [=universal syntax definition=].
271+
272+
The <code>&lt;transform-list&gt;</code> production
273+
is a convenience form equivalent to <code>&lt;transform-function&gt;+</code>.
274+
<span class=note>Note that <code>&lt;transform-list&gt;</code> may not
275+
be followed by a <<syntax-multiplier>>.</span>
276+
277+
[=Whitespace=] is not allowed
278+
between the angle bracket <<delim-token>>s (<code>&lt;</code> <code>&gt;</code>)
279+
and the <<syntax-type>> they enclose,
280+
nor is [=whitespace=] allowed to precede a <<syntax-multiplier>>.
281+
282+
Note: The [=whitespace=] restrictions also apply to <code>&lt;transform-list&gt;</code>.
283+
284+
197285
<h2 id="level-4-extensions">
198286
Extensions to Level 4 Value Types</h3>
199287

0 commit comments

Comments
 (0)