@@ -1870,6 +1870,9 @@ CSS Parsing Results</h3>
18701870 (or lists of these):
18711871
18721872 <dl export dfn-for=CSS>
1873+ : [=stylesheet=]
1874+ :: A stylesheet has a list of [=rules=] .
1875+
18731876 : <dfn>rule</dfn>
18741877 :: A [=rule=] is either an [=at-rule=]
18751878 or a [=qualified rule=] .
@@ -2091,20 +2094,28 @@ Parser Entry Points</h3>
20912094 for parsing stylesheets.
20922095
20932096 <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.
20962102
20972103 <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,
20992109 and similar functions which might exist,
21002110 which parse text into a single rule.
21012111
21022112 <li>
21032113 "<a>Parse a declaration</a> " is used in ''@supports'' conditions. [[CSS3-CONDITIONAL]]
21042114
21052115 <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}} .
21082119
21092120 <li>
21102121 "<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>
21992210 as described in the [=CSS/parse=] algorithm).
22002211
22012212 <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>
22032214 (aka [=CSS/parse a list=] )
22042215 given an |input|
22052216 and a CSS |grammar| production:
@@ -2251,32 +2262,45 @@ Parse a stylesheet</h4>
22512262 (or null, if |location| was not passed).
22522263
22532264 <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.
22572267
22582268 <li>
22592269 Return the stylesheet.
22602270 </ol>
22612271 </div>
22622272
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>
22652275
22662276 <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|:
22682278
22692279 <ol>
22702280 <li>
22712281 [=Normalize=] |input|,
22722282 and set |input| to the result.
22732283
22742284 <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.
22772300
22782301 <li>
2279- Return the returned list.
2302+ <a>Consume a block's contents</a> from |input|,
2303+ and return the result.
22802304 </ol>
22812305 </div>
22822306
@@ -2402,7 +2426,7 @@ Parse a comma-separated list of component values</h4>
24022426
24032427 3. While |input| is not [=token stream/empty=] :
24042428
2405- 1 [=Consume a list of component values=] from |input|,
2429+ 1. [=Consume a list of component values=] from |input|,
24062430 with <<comma-token>> as the stop token,
24072431 and append the result to |groups|.
24082432 2. [=Discard a token=] from |input|.
@@ -2435,12 +2459,11 @@ Parser Algorithms</h3>
24352459 to enable validity-checking.
24362460
24372461
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>
24402464
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|:
24442467
24452468 Let |rules| be an initially empty [=list=] of rules.
24462469
@@ -2458,8 +2481,7 @@ Consume a list of rules</h4>
24582481 <dt> <<CDO-token>>
24592482 <dt> <<CDC-token>>
24602483 <dd>
2461- If |top-level| is true,
2462- [=discard a token=] from |input|.
2484+ [=Discard a token=] from |input|.
24632485
24642486 <details class=note>
24652487 <summary> What's this for?</summary>
@@ -2481,11 +2503,6 @@ Consume a list of rules</h4>
24812503 for the same reason.
24822504 </details>
24832505
2484- Otherwise,
2485- [=consume a qualified rule=] from |input|.
2486- If anything is returned,
2487- append it to |rules|.
2488-
24892506 <dt> <<at-keyword-token>>
24902507 <dd>
24912508 <a>Consume an at-rule</a> from |input|.
@@ -3429,142 +3446,74 @@ Defining Grammars for Rules and Other Values</h2>
34293446<h3 id='declaration-rule-list'>
34303447Defining Block Contents: the <<declaration-list>>, <<rule-list>>, and <<stylesheet>> productions</h3>
34313448
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>>
34913493 </div>
34923494
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:
35013497
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>
35063499
3507- <pre> @keyframes <<keyframes-name>> { <<rule-list>> } </pre>
3508- </div>
3500+ and then accompanying prose defines the valid [=descriptors=]
3501+ allowed in the block.
35093502
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:
35283504
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>
35473509
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,
35503513 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.
35523515 </div>
35533516
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>
35683517
35693518<h3 id="any-value">
35703519Defining Arbitrary Contents: the <<declaration-value>> and <<any-value>> productions</h3>
0 commit comments