Skip to content

Commit 826a192

Browse files
andruudmirisuzanne
andauthored
[css-mixins-1] Use the <syntax> Production for param types (#10496)
* [css-mixins-1] Use the <syntax> Production for param types * Whitespace (again). Co-authored-by: Miriam Suzanne <miriam@oddbird.net> --------- Co-authored-by: Miriam Suzanne <miriam@oddbird.net>
1 parent 5d578a9 commit 826a192

File tree

1 file changed

+118
-9
lines changed

1 file changed

+118
-9
lines changed

css-mixins-1/Overview.bs

Lines changed: 118 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ Default Highlight: css
1515

1616
<pre class=link-defaults>
1717
spec:infra; type:dfn; text:list
18-
spec:css-properties-values-api; type:dfn; text:syntax string
18+
spec:css-properties-values-api; type:dfn; text:supported syntax component name
19+
spec:css-properties-values-api; type:dfn; text:syntax component
1920
spec:css-syntax-3; type:dfn; text:descriptor;
21+
spec:css-values-4; type:dfn; text:keyword;
22+
spec:css-values-4; type:dfn; text:identifier;
2023
</pre>
2124

2225
<!-- Big Text: intro
@@ -98,27 +101,46 @@ The ''@function'' rule defines a [=custom function=],
98101
and its syntax is:
99102

100103
<pre class="prod def" nohighlight>
101-
@function <<function-name>> [( <<parameter-list>> )]?
102-
[using (<<dependency-list>>)]?
103-
[returns type(<<string>>)]?
104+
@function <<function-name>> [ ( <<parameter-list>> ) ]?
105+
[ using ( <<dependency-list>> ) ]?
106+
[ returns <<type>> ]?
104107
{
105108
<<declaration-rule-list>>
106109
}
107110
108111
<dfn><<function-name>></dfn> = <<dashed-ident>>
109112
<dfn><<parameter-list>></dfn> = <<parameter>>#
110113
<dfn><<dependency-list>></dfn> = <<parameter>>#
111-
<dfn><<parameter>></dfn> = <<custom-property-name>> type(<<string>>)? [ : <<declaration-value>> ]?
114+
<dfn><<type>></dfn> = <<syntax-component>> | type( <<syntax>> )
115+
<dfn><<parameter>></dfn> = <<custom-property-name>> <<type>>? [ : <<declaration-value>> ]?
112116
</pre>
113117

114118
The name of the resulting [=custom function=] is given by the <<function-name>>,
115119
the [=function parameters=] are optionally given by <<parameter-list>>,
116120
the [=function dependencies=] are optionally given by <<dependency-list>>,
117-
and the [=return type=] is optionally given by the type string following the "returns" keyword.
121+
and the [=return type=] is optionally given by the <<type>> following the "returns" keyword.
118122

119-
If a [=syntax string=] provided for a [=function parameter=] or [=function dependency=] is unrecognized,
120-
or the [=syntax string=] provided for the [=return type=] is unrecognized,
121-
then the ''@function'' rule is invalid.
123+
<div class='example'>
124+
If the <<type>> of a [=function parameter=],
125+
[=function dependency=],
126+
or [=custom function=] return value
127+
can be described by a single <<syntax-component>>,
128+
then the <code>type()</code> function may be omitted:
129+
130+
<pre class='lang-css'>
131+
@function --foo(--a &lt;length&gt;) { /* ... */ }
132+
@function --foo(--a &lt;color&gt;) { /* ... */ }
133+
@function --foo(--a &lt;length&gt;+) { /* ... */ }
134+
</pre>
135+
136+
However,
137+
any <<syntax>> that requires a <<combinator>>
138+
needs to be wrapped in the <code>type()</code> function:
139+
140+
<pre class='lang-css'>
141+
@function --foo(--a type(&lt;number&gt; | &lt;percentage&gt;)) { /* ... */ }
142+
</pre>
143+
</div>
122144

123145
Issue: Should duplicates be disallowed <em>across</em> parameters/dependencies
124146
as well?
@@ -563,3 +585,90 @@ Issue: Should we indeed use {{CSSNestedDeclarations}} for this purpose?
563585
since only custom properties
564586
and the '@function/result' descriptor
565587
are relevant.
588+
589+
<!-- Big Text: appendix
590+
591+
███▌ ████▌ ████▌ █████▌ █ █▌ ████▌ ████ █ █
592+
▐█ ▐█ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ ▐▌ █ █
593+
█▌ █▌ █▌ █▌ █▌ █▌ █▌ ██▌ █▌ █▌ █▌ ▐▌ █ █
594+
█▌ █▌ ████▌ ████▌ ████ █▌▐█ █▌ █▌ █▌ ▐▌ █
595+
█████▌ █▌ █▌ █▌ █▌ ██▌ █▌ █▌ ▐▌ █ █
596+
█▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ ▐▌ █ █
597+
█▌ █▌ █▌ █▌ █████▌ █▌ ▐▌ ████▌ ████ █ █
598+
-->
599+
600+
Appendix: The <<syntax>> Production {#syntax}
601+
=============================================
602+
603+
The <<syntax>> production represents a [=syntax definition=],
604+
which may be used to impose a type
605+
on [=function parameters=],
606+
[=function dependencies=],
607+
or [=custom function=] return values.
608+
609+
<pre class="prod def" nohighlight>
610+
611+
<dfn><<type-name>></dfn> = angle | color | custom-ident | image | integer |
612+
length | length-percentage | number |
613+
percentage | resolution | string | time |
614+
url | transform-function
615+
<dfn><<combinator>></dfn> = '|'
616+
<dfn><<multiplier>></dfn> = [ '#' | '+' ]
617+
<dfn><<syntax-component-name>></dfn> = '<' <<type-name>> '>' | <<custom-ident>>
618+
<dfn><<syntax-component>></dfn> = <<syntax-component-name>> <<multiplier>>? |
619+
'<' transform-list '>'
620+
<dfn><<syntax>></dfn> = '*' | <<syntax-component>> [ <<combinator>> <<syntax-component>> ]+
621+
622+
</pre>
623+
624+
A <<syntax-component>> consists of either a <<type-name>>,
625+
which maps to one of the [=supported syntax component names=];
626+
or a <<custom-ident>>, which represents any [=keyword=].
627+
Additionally,
628+
a <<syntax-component>> may contain a [[css-properties-values-api-1#multipliers|multiplier]],
629+
which indicates a [=list=] of values.
630+
631+
Note: This means that <code>&lt;length&gt;</code>
632+
and <code>length</code> are two different types:
633+
the former describes a <<length>>,
634+
whereas the latter describes a [=keyword=] <code>length</code>.
635+
636+
Multiple <<syntax-component>>s may be [[css-properties-values-api-1#combinator|combined]]
637+
with a <code>|</code> <<delim-token>>,
638+
causing the syntax components to be matched
639+
against a value
640+
in the specified order.
641+
642+
<div class='example'>
643+
<pre class='lang-css'>
644+
&lt;percentage&gt; | &lt;number&gt; | auto
645+
</pre>
646+
The above, when parsed as a <<syntax>>,
647+
would accept <<percentage>> values,
648+
<<number>> values,
649+
as well as the keyword <code>auto</code>.
650+
</div>
651+
652+
<div class='example'>
653+
<pre class='lang-css'>
654+
red | &lt;color&gt;
655+
</pre>
656+
The [=syntax definition=] resulting from the above <<syntax>>,
657+
when used as a grammar for [=parse|parsing=],
658+
would match an input <code>red</code> as an [=identifier=],
659+
but would match an input <code>blue</code> as a <<color>>.
660+
</div>
661+
662+
The <code>*</code> <<delim-token>> represents the [=universal syntax definition=].
663+
664+
The <code>&lt;transform-list&gt;</code> production
665+
is a convenience form equivalent to <code>&lt;transform-function&gt;+</code>.
666+
<span class=note>Note that <code>&lt;transform-list&gt;</code> may not
667+
be followed by a <<multiplier>>.</span>
668+
669+
[=Whitespace=] is not allowed
670+
between the angle bracket <<delim-token>>s (<code>&lt;</code> <code>&gt;</code>)
671+
and the <<type-name>> they enclose,
672+
nor is [=whitespace=] allowed to precede a <<multiplier>>.
673+
674+
Note: The [=whitespace=] restrictions also apply to <code>&lt;transform-list&gt;</code>.

0 commit comments

Comments
 (0)