@@ -15,8 +15,11 @@ Default Highlight: css
15
15
16
16
<pre class=link-defaults>
17
17
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
19
20
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;
20
23
</pre>
21
24
22
25
<!-- Big Text: intro
@@ -98,27 +101,46 @@ The ''@function'' rule defines a [=custom function=],
98
101
and its syntax is:
99
102
100
103
<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>> ]?
104
107
{
105
108
<<declaration-rule-list>>
106
109
}
107
110
108
111
<dfn><<function-name>></dfn> = <<dashed-ident>>
109
112
<dfn><<parameter-list>></dfn> = <<parameter>> #
110
113
<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>> ]?
112
116
</pre>
113
117
114
118
The name of the resulting [=custom function=] is given by the <<function-name>> ,
115
119
the [=function parameters=] are optionally given by <<parameter-list>> ,
116
120
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.
118
122
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 <length>) { /* ... */ }
132
+ @function --foo(--a <color>) { /* ... */ }
133
+ @function --foo(--a <length>+) { /* ... */ }
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(<number> | <percentage>)) { /* ... */ }
142
+ </pre>
143
+ </div>
122
144
123
145
Issue: Should duplicates be disallowed <em> across</em> parameters/dependencies
124
146
as well?
@@ -563,3 +585,90 @@ Issue: Should we indeed use {{CSSNestedDeclarations}} for this purpose?
563
585
since only custom properties
564
586
and the '@function/result' descriptor
565
587
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> <length></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
+ <percentage> | <number> | 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 | <color>
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> <transform-list></code> production
665
+ is a convenience form equivalent to <code> <transform-function>+</code> .
666
+ <span class=note> Note that <code> <transform-list></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> <</code> <code> ></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> <transform-list></code> .
0 commit comments