@@ -1870,6 +1870,9 @@ CSS Parsing Results</h3>
1870
1870
(or lists of these):
1871
1871
1872
1872
<dl export dfn-for=CSS>
1873
+ : [=stylesheet=]
1874
+ :: A stylesheet has a list of [=rules=] .
1875
+
1873
1876
: <dfn>rule</dfn>
1874
1877
:: A [=rule=] is either an [=at-rule=]
1875
1878
or a [=qualified rule=] .
@@ -2091,20 +2094,28 @@ Parser Entry Points</h3>
2091
2094
for parsing stylesheets.
2092
2095
2093
2096
<li>
2094
- "<a>Parse a list of rules</a> " is intended for the content of at-rules such as ''@media'' .
2095
- It differs from "<a>Parse a stylesheet</a> " in the handling of <<CDO-token>> and <<CDC-token>> .
2097
+ "<a>Parse a stylesheet's contents</a> " is intended for use by the
2098
+ {{CSSStyleSheet/replace()|CSSStyleSheet replace()}} method,
2099
+ and similar,
2100
+ which parse text into the contents
2101
+ of an existing stylesheet.
2096
2102
2097
2103
<li>
2098
- "<a>Parse a rule</a> " is intended for use by the <code> CSSStyleSheet#insertRule</code> method,
2104
+ "<a>Parse a rule</a> " is intended for use by the
2105
+ {{CSSStyleSheet/insertRule()|CSSStyleSheet insertRule()}} method,
2106
+ and similar,
2107
+ which parse text into a single rule.
2108
+ <code> CSSStyleSheet#insertRule</code> method,
2099
2109
and similar functions which might exist,
2100
2110
which parse text into a single rule.
2101
2111
2102
2112
<li>
2103
2113
"<a>Parse a declaration</a> " is used in ''@supports'' conditions. [[CSS3-CONDITIONAL]]
2104
2114
2105
2115
<li>
2106
- "<a>Parse a list of declarations</a> " is for the contents of a <code> style</code> attribute,
2107
- which parses text into the contents of a single style rule.
2116
+ "<a>Parse a block's contents</a> " is inteded for parsing the contents of any block in CSS
2117
+ (including things like the style attribute},
2118
+ and APIs such as {{CSSStyleDeclaration/cssText|the CSSStyleDeclaration cssText attribute}} .
2108
2119
2109
2120
<li>
2110
2121
"<a>Parse a component value</a> " is for things that need to consume a single value,
@@ -2199,7 +2210,7 @@ Parse A Comma-Separated List According To A CSS Grammar</h4>
2199
2210
as described in the [=CSS/parse=] algorithm).
2200
2211
2201
2212
<div algorithm>
2202
- To <dfn export lt="parse a comma-separated list according to a CSS grammar|parse a list|parsing a list " for=CSS>parse a comma-separated list according to a CSS grammar</dfn>
2213
+ To <dfn export lt="parse a comma-separated list according to a CSS grammar|parse a list" for=CSS>parse a comma-separated list according to a CSS grammar</dfn>
2203
2214
(aka [=CSS/parse a list=] )
2204
2215
given an |input|
2205
2216
and a CSS |grammar| production:
@@ -2251,32 +2262,45 @@ Parse a stylesheet</h4>
2251
2262
(or null, if |location| was not passed).
2252
2263
2253
2264
<li>
2254
- <a>Consume a list of rules</a> from |input|,
2255
- with the <var ignore> top-level flag</var> set,
2256
- and set the stylesheet's value to the result.
2265
+ <a>Consume a stylesheet's contents</a> from |input|,
2266
+ and set the stylesheet's rules to the result.
2257
2267
2258
2268
<li>
2259
2269
Return the stylesheet.
2260
2270
</ol>
2261
2271
</div>
2262
2272
2263
- <h4 id="parse-list-of-rules">
2264
- Parse a list of rules </h4>
2273
+ <h4 id="parse-stylesheet-contents" oldids="parse- list-of-rules">
2274
+ Parse a stylesheet's contents </h4>
2265
2275
2266
2276
<div algorithm>
2267
- To <dfn export>parse a list of rules </dfn> from |input|:
2277
+ To <dfn export>parse a stylesheet's contents </dfn> from |input|:
2268
2278
2269
2279
<ol>
2270
2280
<li>
2271
2281
[=Normalize=] |input|,
2272
2282
and set |input| to the result.
2273
2283
2274
2284
<li>
2275
- <a>Consume a list of rules</a> from the |input|,
2276
- with the <var ignore> top-level flag</var> unset.
2285
+ <a>Consume a stylesheet's contents</a> from |input|,
2286
+ and return the result.
2287
+ </ol>
2288
+ </div>
2289
+
2290
+ <h4 id="parse-block-contents" oldids="parse-list-of-declarations">
2291
+ Parse a list of declarations</h4>
2292
+
2293
+ <div algorithm>
2294
+ To <dfn export>parse a block's contents</dfn> from |input|:
2295
+
2296
+ <ol>
2297
+ <li>
2298
+ [=Normalize=] |input|,
2299
+ and set |input| to the result.
2277
2300
2278
2301
<li>
2279
- Return the returned list.
2302
+ <a>Consume a block's contents</a> from |input|,
2303
+ and return the result.
2280
2304
</ol>
2281
2305
</div>
2282
2306
@@ -2402,7 +2426,7 @@ Parse a comma-separated list of component values</h4>
2402
2426
2403
2427
3. While |input| is not [=token stream/empty=] :
2404
2428
2405
- 1 [=Consume a list of component values=] from |input|,
2429
+ 1. [=Consume a list of component values=] from |input|,
2406
2430
with <<comma-token>> as the stop token,
2407
2431
and append the result to |groups|.
2408
2432
2. [=Discard a token=] from |input|.
@@ -2435,12 +2459,11 @@ Parser Algorithms</h3>
2435
2459
to enable validity-checking.
2436
2460
2437
2461
2438
- <h4 id="consume-list-of-rules">
2439
- Consume a list of rules </h4>
2462
+ <h4 id="consume-stylesheet-contents" oldids="consume- list-of-rules">
2463
+ Consume a stylesheet's contents </h4>
2440
2464
2441
- To <dfn>consume a list of rules</dfn>
2442
- from a [=token stream=] |input|,
2443
- given an optional bool |top-level| (default false):
2465
+ To <dfn>consume a stylesheet's contents</dfn>
2466
+ from a [=token stream=] |input|:
2444
2467
2445
2468
Let |rules| be an initially empty [=list=] of rules.
2446
2469
@@ -2458,8 +2481,7 @@ Consume a list of rules</h4>
2458
2481
<dt> <<CDO-token>>
2459
2482
<dt> <<CDC-token>>
2460
2483
<dd>
2461
- If |top-level| is true,
2462
- [=discard a token=] from |input|.
2484
+ [=Discard a token=] from |input|.
2463
2485
2464
2486
<details class=note>
2465
2487
<summary> What's this for?</summary>
@@ -2481,11 +2503,6 @@ Consume a list of rules</h4>
2481
2503
for the same reason.
2482
2504
</details>
2483
2505
2484
- Otherwise,
2485
- [=consume a qualified rule=] from |input|.
2486
- If anything is returned,
2487
- append it to |rules|.
2488
-
2489
2506
<dt> <<at-keyword-token>>
2490
2507
<dd>
2491
2508
<a>Consume an at-rule</a> from |input|.
@@ -3429,142 +3446,74 @@ Defining Grammars for Rules and Other Values</h2>
3429
3446
<h3 id='declaration-rule-list'>
3430
3447
Defining Block Contents: the <<declaration-list>>, <<rule-list>>, and <<stylesheet>> productions</h3>
3431
3448
3432
- The CSS parser is agnostic as to the contents of blocks,
3433
- such as those that come at the end of some at-rules.
3434
- Defining the generic grammar of the blocks in terms of tokens is non-trivial,
3435
- but there are dedicated and unambiguous algorithms defined for parsing this.
3436
-
3437
- <div class=issue>
3438
- Need to rewrite these productions into a more useful hierarchy:
3439
-
3440
- * allows declarations and at-rules (qualified rules are parsed, but invalid by default)
3441
- * allows declarations, qualified rules, and at-rules
3442
- * allows qualified rules and at-rules (declarations are parsed, but invalid by default)
3443
- </div>
3444
-
3445
- The <dfn><declaration-list></dfn> production represents a list of declarations and/or rules.
3446
- It may only be used in grammars as the sole value in a block,
3447
- and represents that the contents of the block must be parsed using the <a>consume a list of declarations</a> algorithm.
3448
-
3449
- Similarly, the <dfn><rule-list></dfn> production represents a list of rules,
3450
- and may only be used in grammars as the sole value in a block.
3451
- It represents that the contents of the block must be parsed using the <a>consume a list of rules</a> algorithm.
3452
-
3453
- Finally, the <dfn><stylesheet></dfn> production represents a list of rules.
3454
- It is identical to <<rule-list>> ,
3455
- except that blocks using it default to accepting all rules
3456
- that aren't otherwise limited to a particular context.
3457
-
3458
- <div class=note>
3459
- These productions are pretty similar to each other,
3460
- so this table summarizes what they accept
3461
- and lists some example instances of each:
3462
-
3463
- <table class=data>
3464
- <thead>
3465
- <tr>
3466
- <td>
3467
- <th> Allows [=declarations=]
3468
- <th> Allows [=nested style rules=]
3469
- <th> Allow arbitrary [=qualified rules=]
3470
- <th> Allows [=at-rules=]
3471
- <th> Examples
3472
- </thead>
3473
- <tr>
3474
- <th> <<declaration-list>>
3475
- <td> ✓<td> ✗<td> ✗<td> ✓
3476
- <td> ''@font'' , ''@counter-style'' , ''@page'' , ''@keyframes'' child rules
3477
- <tr>
3478
- <th> <<rule-list>>
3479
- <td> ✗<td> ✗<td> ✓<td> ✓
3480
- <td> ''@keyframes'' , ''@font-feature-values''
3481
- <tr>
3482
- <th> <<stylesheet>>
3483
- <td> ✗<td> ✗<td> ✓<td> ✓
3484
- <td> stylesheets, non-nested [=conditional group rules=]
3485
- </table>
3486
-
3487
- If a given context is <em> only</em> intended to accept [=at-rules=] ,
3488
- such as in ''@font-features-values'' ,
3489
- it doesn't actually matter which production is used,
3490
- but <<rule-list>> is preferred for its more straightforward name.
3449
+ The CSS parser is agnostic as to the contents of blocks--
3450
+ they're all parsed with the same algorithm,
3451
+ and differentiate themselves solely by what constructs are valid.
3452
+
3453
+ When writing a rule grammar,
3454
+ <dfn><block-contents></dfn> represents this agnostic parsing.
3455
+ It must only be used as the sole value in a block,
3456
+ and represents that no restrictions are implicitly placed
3457
+ on what the block can contain.
3458
+
3459
+ Accompanying prose must define what is valid and invalid in this context.
3460
+ If any [=declarations=] are valid,
3461
+ and are [=property declarations=] ,
3462
+ it must define whether they interact with the cascade;
3463
+ if they do, it must define their specificity
3464
+ and how they use <code> !important</code> .
3465
+
3466
+ In many cases, however,
3467
+ a block can't validly contain <em> any</em> constructs of a given type.
3468
+ To represent these cases more explicitly,
3469
+ the following productions may be used
3470
+
3471
+ * <dfn><declaration-list></dfn> :
3472
+ [=at-rules=] and [=qualified rules=] are automatically invalid.
3473
+ * <dfn><qualified-rule-list></dfn> :
3474
+ [=declarations=] and [=at-rules=] are automatically invalid.
3475
+ * <dfn><declaration-rule-list></dfn> :
3476
+ [=at-rules=] are automatically invalid.
3477
+ * <dfn><rule-list></dfn> :
3478
+ [=declarations=] are automatically invalid.
3479
+
3480
+ All of these are exactly equivalent to <<block-contents>> in terms of parsing,
3481
+ but the accompanying prose only has to define validity
3482
+ for the categories that aren't automatically invalid.
3483
+
3484
+ <div class=example>
3485
+ Some examples of the various productions:
3486
+
3487
+ * A top-level ''@media'' uses <<rule-list>> for its block,
3488
+ while a nested one [[CSS-NESTING-1]] uses <<block-contents>> .
3489
+ * [=Style rules=] use <<block-contents>> .
3490
+ * ''@font-face'' uses <<declaration-list>> .
3491
+ * ''@page'' uses <<declaration-rule-list>> .
3492
+ * ''@keyframes'' uses <<rule-list>>
3491
3493
</div>
3492
3494
3493
- <div class='example'>
3494
- For example, the ''@font-face'' rule is defined to have an empty prelude,
3495
- and to contain a list of declarations.
3496
- This is expressed with the following grammar:
3497
-
3498
- <pre> @font-face { <<declaration-list>> }</pre>
3499
-
3500
- This is a complete and sufficient definition of the rule's grammar.
3495
+ <div class=example>
3496
+ For example, the grammar for ''@font-face'' can be written as:
3501
3497
3502
- For another example,
3503
- ''@keyframes'' rules are more complex,
3504
- interpreting their prelude as a name and containing keyframes rules in their block
3505
- Their grammar is:
3498
+ <pre> <<@font-face>> = @font-face { <<declaration-list>> }</pre>
3506
3499
3507
- <pre> @keyframes <<keyframes-name>> { <<rule-list>> } </pre>
3508
- </div>
3500
+ and then accompanying prose defines the valid [=descriptors=]
3501
+ allowed in the block.
3509
3502
3510
- For rules that use <<style-block>> or <<declaration-list>> ,
3511
- the spec for the rule must define which properties, descriptors, and/or at-rules are valid inside the rule;
3512
- this may be as simple as saying "The @foo rule accepts the properties/descriptors defined in this specification/section.",
3513
- and extension specs may simply say "The @foo rule additionally accepts the following properties/descriptors.".
3514
- Any declarations or at-rules found inside the block that are not defined as valid
3515
- must be removed from the rule's value.
3516
-
3517
- Within a <<style-block>> or <<declaration-list>> ,
3518
- <code> !important</code> is automatically invalid on any descriptors.
3519
- If the rule accepts properties,
3520
- the spec for the rule must define whether the properties interact with the cascade,
3521
- and with what specificity.
3522
- If they don't interact with the cascade,
3523
- properties containing <code> !important</code> are automatically invalid;
3524
- otherwise using <code> !important</code> is valid
3525
- and causes the declaration to be [=important=]
3526
- for the purposes of the [=cascade=] .
3527
- See [[!CSS-CASCADE-3]] .
3503
+ The grammar for ''@keyframes'' can be written as:
3528
3504
3529
- <div class='example'>
3530
- For example, the grammar for ''@font-face'' in the previous example must,
3531
- in addition to what is written there,
3532
- define that the allowed declarations are the descriptors defined in the Fonts spec.
3533
- </div>
3534
-
3535
- For rules that use <<rule-list>> ,
3536
- the spec for the rule must define what types of rules are valid inside the rule,
3537
- same as <<declaration-list>> ,
3538
- and unrecognized rules must similarly be removed from the rule's value.
3539
-
3540
- <div class='example'>
3541
- For example, the grammar for ''@keyframes'' in the previous example must,
3542
- in addition to what is written there,
3543
- define that the only allowed rules are <<keyframe-rule>> s,
3544
- which are defined as:
3545
-
3546
- <pre> <<keyframe-rule>> = <<keyframe-selector>> { <<declaration-list>> }</pre>
3505
+ <pre>
3506
+ <<@keyframes>> = @keyframes { <<rule-list>> }
3507
+ <<keyframe-rule>> = <<keyframe-selector>> { <<declaration-list>> }
3508
+ </pre>
3547
3509
3548
- Keyframe rules, then,
3549
- must further define that they accept as declarations all animatable CSS properties,
3510
+ and then accompanying prose defines that only <<keyframe-rule>> s
3511
+ are allowed in ''@keyframes'' ,
3512
+ and that <<keyframe-rule>> s accept all animatable CSS properties,
3550
3513
plus the 'animation-timing-function' property,
3551
- but that they do not interact with the cascade.
3514
+ but they do not interact with the cascade.
3552
3515
</div>
3553
3516
3554
- For rules that use <<stylesheet>> ,
3555
- all rules are allowed by default,
3556
- but the spec for the rule may define what types of rules are <em> invalid</em> inside the rule.
3557
-
3558
- <div class='example'>
3559
- For example, the ''@media'' rule accepts anything that can be placed in a stylesheet,
3560
- except more ''@media'' rules.
3561
- As such, its grammar is:
3562
-
3563
- <pre> @media <<media-query-list>> { <<stylesheet>> }</pre>
3564
-
3565
- It additionally defines a restriction that the <<stylesheet>> can not contain ''@media'' rules,
3566
- which causes them to be dropped from the outer rule's value if they appear.
3567
- </div>
3568
3517
3569
3518
<h3 id="any-value">
3570
3519
Defining Arbitrary Contents: the <<declaration-value>> and <<any-value>> productions</h3>
0 commit comments