Skip to content

Commit 1a2fbc5

Browse files
committed
Handle the two different kinds of at-rules. Generalize the declaration mode to accept at-rules as well, so I can just reuse it for rule-filled at-rule contents (and so that future stuff that wants to put at-rules inside of style rules will Just Work).
1 parent 215996d commit 1a2fbc5

2 files changed

Lines changed: 108 additions & 47 deletions

File tree

css3-syntax/Overview.html

Lines changed: 61 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,8 @@ <h2 class="no-num no-toc" id=contents> Table of contents</h2>
281281
<li><a href="#at-rule-mode"><span class=secno>3.6.4. </span> At-rule
282282
mode</a>
283283

284-
<li><a href="#at-rule-block-mode"><span class=secno>3.6.5. </span>
285-
At-rule-block mode</a>
284+
<li><a href="#rule-mode"><span class=secno>3.6.5. </span> Rule
285+
mode</a>
286286

287287
<li><a href="#style-rule-mode"><span class=secno>3.6.6. </span>
288288
Style-rule mode</a>
@@ -2101,6 +2101,23 @@ <h4 id=definitions0><span class=secno>3.6.2. </span> Definitions</h4>
21012101

21022102
<dd> The declaration currently being built. There may or may not be a
21032103
current declaration at any given time, but there is never more than one.
2104+
2105+
<dt><dfn id=rule-filled>rule-filled</dfn>
2106+
2107+
<dd> An at-rule that takes a block, and within that block accepts at-rules
2108+
and/or style rules (or a close variant of style rules, like a keyframe
2109+
rule), is called <a href="#rule-filled"><i>rule-filled</i></a>. Examples
2110+
of <a href="#rule-filled"><i>rule-filled</i></a> at-rules are ‘<code
2111+
class=css>@media</code>’ and ‘<code class=css>@keyframes</code>’.
2112+
2113+
<dt><dfn id=declaration-filled>declaration-filled</dfn>
2114+
2115+
<dd> An at-rule that takes a block, and within that block accepts at-rules
2116+
and/or declarations, is called <a
2117+
href="#declaration-filled"><i>declaration-filled</i></a>. Examples of <a
2118+
href="#declaration-filled"><i>declaration-filled</i></a> at-rules are
2119+
<code class=css>@font-face</code>’ and ‘<code
2120+
class=css>@page</code>’.
21042121
</dl>
21052122

21062123
<h4 id=top-level-mode-><span class=secno>3.6.3. </span> <dfn
@@ -2119,7 +2136,7 @@ <h4 id=top-level-mode-><span class=secno>3.6.3. </span> <dfn
21192136

21202137
<dt>at-keyword token
21212138

2122-
<dd> <i>Create an at-rule</i> with its name set to the value of the <a
2139+
<dd> Create an at-rule with its name set to the value of the <a
21232140
href="#current-input-token"><i>current input token</i></a> and push it
21242141
onto the <a href="#stack-of-open-rules"><i>stack of open rules</i></a>.
21252142
Switch to the <a href="#at-rule-mode0"><i>at-rule mode</i></a>.
@@ -2155,8 +2172,15 @@ <h4 id=at-rule-mode><span class=secno>3.6.4. </span> <dfn
21552172

21562173
<dt><span class=temp>{</span> token
21572174

2158-
<dd> Switch to the <a href="#at-rule-block-mode0"><i>at-rule-block
2159-
mode</i></a>.
2175+
<dd> If the <a href="#current-rule"><i>current rule</i></a> is <a
2176+
href="#rule-filled"><i>rule-filled</i></a>, switch to the <a
2177+
href="#rule-mode0"><i>rule mode</i></a>.
2178+
<p> Otherwise, if the <a href="#current-rule"><i>current rule</i></a> is
2179+
<a href="#declaration-filled"><i>declaration-filled</i></a>, switch to
2180+
the <a href="#declaration-mode0"><i>declaration mode</i></a>.
2181+
2182+
<p> Otherwise, this is a <i>parse error</i>. Switch to the
2183+
<i>next-statement error mode</i>.
21602184

21612185
<dt><span class=temp>[</span> token
21622186

@@ -2181,23 +2205,18 @@ <h4 id=at-rule-mode><span class=secno>3.6.4. </span> <dfn
21812205
rule</i></a> and remain in this mode.
21822206
</dl>
21832207

2184-
<h4 id=at-rule-block-mode><span class=secno>3.6.5. </span> <dfn
2185-
id=at-rule-block-mode0>At-rule-block mode</dfn></h4>
2208+
<h4 id=rule-mode><span class=secno>3.6.5. </span> <dfn id=rule-mode0>Rule
2209+
mode</dfn></h4>
21862210

21872211
<p>Consume the <a href="#next-input-token"><i>next input token</i></a>.
21882212

21892213
<dl>
2190-
<dt>cdo token
2191-
2192-
<dt>cdc token
2193-
21942214
<dt>bad-string token
21952215

21962216
<dt>bad-url token
21972217

21982218
<dd> This is a <i>parse error</i>. Switch to the <a
2199-
href="#next-block-or-statement-error-mode0"><i>next-block-or-statement
2200-
error mode</i></a>.
2219+
href="#next-block-error-mode0"><i>next-block error mode</i></a>.
22012220

22022221
<dt><span class=temp>}</span> token
22032222

@@ -2210,18 +2229,18 @@ <h4 id=at-rule-block-mode><span class=secno>3.6.5. </span> <dfn
22102229

22112230
<dt>at-keyword token
22122231

2213-
<dd> <i>Create an at-rule</i> with its name set to the value of the <a
2232+
<dd> Create an at-rule with its name set to the value of the <a
22142233
href="#current-input-token"><i>current input token</i></a> and push it
22152234
onto the <a href="#stack-of-open-rules"><i>stack of open rules</i></a>.
22162235
Switch to the <a href="#at-rule-mode0"><i>at-rule mode</i></a>.
2217-
</dl>
22182236

2219-
<p class=issue> Not done yet. Every at-rule allows more at-rules in its
2220-
body, but must choose whether it allows declarations or "style rules" in
2221-
its body (things with a selector). Need to decide whether I should just
2222-
specialize on that, or if I should fully specialize on the at-keyword
2223-
name, so that, for example, @keyframes goes down a special parser rule
2224-
that ends up accepting only keyframes.
2237+
<dt>anything else
2238+
2239+
<dd> <i>Create a style rule</i> and push it onto the <a
2240+
href="#stack-of-open-rules"><i>stack of open rules</i></a>. Switch to the
2241+
<a href="#style-rule-mode0"><i>style-rule mode</i></a>. Reprocess the <a
2242+
href="#current-input-token"><i>current input token</i></a>.
2243+
</dl>
22252244

22262245
<h4 id=style-rule-mode><span class=secno>3.6.6. </span> <dfn
22272246
id=style-rule-mode0>Style-rule mode</dfn></h4>
@@ -2277,6 +2296,13 @@ <h4 id=declaration-mode><span class=secno>3.6.7. </span> <dfn
22772296
href="#switch-to-the-current-rules-content-mode0"><i>Switch to the
22782297
current rule's content mode</i></a>.
22792298

2299+
<dt>at-rule token
2300+
2301+
<dd> Create an at-rule with its name set to the value of the <a
2302+
href="#current-input-token"><i>current input token</i></a> and push it
2303+
onto the <a href="#stack-of-open-rules"><i>stack of open rules</i></a>.
2304+
Switch to the <a href="#at-rule-mode0"><i>at-rule mode</i></a>.
2305+
22802306
<dt>ident token
22812307

22822308
<dd> Create a declaration with its name set to the value of the <a
@@ -2598,12 +2624,13 @@ <h4 id=switch-to-the-current-rules-content-mode><span class=secno>3.6.15.
25982624
rule's content mode</i></a>. It is invoked whenever a declaration or rule
25992625
has been successfully completed, or when an error has finished recovery.
26002626

2601-
<p> If the <a href="#current-rule"><i>current rule</i></a> is a style rule,
2627+
<p> If the <a href="#current-rule"><i>current rule</i></a> is a style rule
2628+
or a <a href="#declaration-filled"><i>declaration-filled</i></a> at-rule,
26022629
switch to the <a href="#declaration-mode0"><i>declaration mode</i></a>.
26032630

2604-
<p> If the <a href="#current-rule"><i>current rule</i></a> is an at-rule,
2605-
switch to the <a href="#at-rule-block-mode0"><i>at-rule-block
2606-
mode</i></a>.
2631+
<p> If the <a href="#current-rule"><i>current rule</i></a> is a <a
2632+
href="#rule-filled"><i>rule-filled</i></a> at-rule, switch to the <a
2633+
href="#rule-mode0"><i>rule mode</i></a>.
26072634

26082635
<p> If the <a href="#current-rule"><i>current rule</i></a> is a stylesheet,
26092636
switch to the <a href="#top-level-mode"><i>top-level mode</i></a>.
@@ -2892,9 +2919,6 @@ <h2 class=no-num id=index> Index</h2>
28922919

28932920
<li>at-rule, <a href="#at-rules" title=at-rule><strong>2.</strong></a>
28942921

2895-
<li>At-rule-block mode, <a href="#at-rule-block-mode0"
2896-
title="At-rule-block mode"><strong>3.6.5.</strong></a>
2897-
28982922
<li>At-rule mode, <a href="#at-rule-mode0"
28992923
title="At-rule mode"><strong>3.6.4.</strong></a>
29002924

@@ -2934,6 +2958,9 @@ <h2 class=no-num id=index> Index</h2>
29342958
<li>Declaration-end mode, <a href="#declaration-end-mode0"
29352959
title="Declaration-end mode"><strong>3.6.10.</strong></a>
29362960

2961+
<li>declaration-filled, <a href="#declaration-filled"
2962+
title=declaration-filled><strong>3.6.2.</strong></a>
2963+
29372964
<li>Declaration mode, <a href="#declaration-mode0"
29382965
title="Declaration mode"><strong>3.6.7.</strong></a>
29392966

@@ -3021,6 +3048,12 @@ <h2 class=no-num id=index> Index</h2>
30213048

30223049
<li>rule, <a href="#rule" title=rule><strong>2.</strong></a>
30233050

3051+
<li>rule-filled, <a href="#rule-filled"
3052+
title=rule-filled><strong>3.6.2.</strong></a>
3053+
3054+
<li>Rule mode, <a href="#rule-mode0"
3055+
title="Rule mode"><strong>3.6.5.</strong></a>
3056+
30243057
<li>Sci-notation state, <a href="#sci-notation-state0"
30253058
title="Sci-notation state"><strong>3.4.18.</strong></a>
30263059

css3-syntax/Overview.src.html

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2097,6 +2097,21 @@ <h4>
20972097
The declaration currently being built.
20982098
There may or may not be a current declaration at any given time,
20992099
but there is never more than one.
2100+
2101+
<dt><dfn>rule-filled</dfn>
2102+
<dd>
2103+
An at-rule that takes a block,
2104+
and within that block accepts at-rules and/or style rules
2105+
(or a close variant of style rules, like a keyframe rule),
2106+
is called <i>rule-filled</i>.
2107+
Examples of <i>rule-filled</i> at-rules are ''@media'' and ''@keyframes''.
2108+
2109+
<dt><dfn>declaration-filled</dfn>
2110+
<dd>
2111+
An at-rule that takes a block,
2112+
and within that block accepts at-rules and/or declarations,
2113+
is called <i>declaration-filled</i>.
2114+
Examples of <i>declaration-filled</i> at-rules are ''@font-face'' and ''@page''.
21002115
</dl>
21012116

21022117
<h4>
@@ -2115,7 +2130,7 @@ <h4>
21152130

21162131
<dt>at-keyword token
21172132
<dd>
2118-
<i>Create an at-rule</i>
2133+
Create an at-rule
21192134
with its name set to the value of the <i>current input token</i>
21202135
and push it onto the <i>stack of open rules</i>.
21212136
Switch to the <i>at-rule mode</i>.
@@ -2150,7 +2165,17 @@ <h4>
21502165

21512166
<dt><span class='temp'>{</span> token
21522167
<dd>
2153-
Switch to the <i>at-rule-block mode</i>.
2168+
If the <i>current rule</i> is <i>rule-filled</i>,
2169+
switch to the <i>rule mode</i>.
2170+
2171+
<p>
2172+
Otherwise,
2173+
if the <i>current rule</i> is <i>declaration-filled</i>,
2174+
switch to the <i>declaration mode</i>.
2175+
2176+
<p>
2177+
Otherwise, this is a <i>parse error</i>.
2178+
Switch to the <i>next-statement error mode</i>.
21542179

21552180
<dt><span class='temp'>[</span> token
21562181
<dt><span class='temp'>(</span> token
@@ -2174,18 +2199,16 @@ <h4>
21742199

21752200

21762201
<h4>
2177-
<dfn>At-rule-block mode</dfn></h4>
2202+
<dfn>Rule mode</dfn></h4>
21782203

21792204
<p>Consume the <i>next input token</i>.
21802205

21812206
<dl>
2182-
<dt>cdo token
2183-
<dt>cdc token
21842207
<dt>bad-string token
21852208
<dt>bad-url token
21862209
<dd>
21872210
This is a <i>parse error</i>.
2188-
Switch to the <i>next-block-or-statement error mode</i>.
2211+
Switch to the <i>next-block error mode</i>.
21892212

21902213
<dt><span class='temp'>}</span> token
21912214
<dd>
@@ -2195,21 +2218,19 @@ <h4>
21952218

21962219
<dt>at-keyword token
21972220
<dd>
2198-
<i>Create an at-rule</i>
2221+
Create an at-rule
21992222
with its name set to the value of the <i>current input token</i>
22002223
and push it onto the <i>stack of open rules</i>.
22012224
Switch to the <i>at-rule mode</i>.
22022225

2203-
</dl>
2226+
<dt>anything else
2227+
<dd>
2228+
<i>Create a style rule</i>
2229+
and push it onto the <i>stack of open rules</i>.
2230+
Switch to the <i>style-rule mode</i>.
2231+
Reprocess the <i>current input token</i>.
22042232

2205-
<p class='issue'>
2206-
Not done yet.
2207-
Every at-rule allows more at-rules in its body,
2208-
but must choose whether it allows declarations or "style rules" in its body (things with a selector).
2209-
Need to decide whether I should just specialize on that,
2210-
or if I should fully specialize on the at-keyword name,
2211-
so that, for example, @keyframes goes down a special parser rule
2212-
that ends up accepting only keyframes.
2233+
</dl>
22132234

22142235

22152236
<h4>
@@ -2263,6 +2284,13 @@ <h4>
22632284
and append it to the list of rules for the new <i>current rule</i>.
22642285
<i>Switch to the current rule's content mode</i>.
22652286

2287+
<dt>at-rule token
2288+
<dd>
2289+
Create an at-rule
2290+
with its name set to the value of the <i>current input token</i>
2291+
and push it onto the <i>stack of open rules</i>.
2292+
Switch to the <i>at-rule mode</i>.
2293+
22662294
<dt>ident token
22672295
<dd>
22682296
Create a declaration
@@ -2571,12 +2599,12 @@ <h4>
25712599
or when an error has finished recovery.
25722600

25732601
<p>
2574-
If the <i>current rule</i> is a style rule,
2602+
If the <i>current rule</i> is a style rule or a <i>declaration-filled</i> at-rule,
25752603
switch to the <i>declaration mode</i>.
25762604

25772605
<p>
2578-
If the <i>current rule</i> is an at-rule,
2579-
switch to the <i>at-rule-block mode</i>.
2606+
If the <i>current rule</i> is a <i>rule-filled</i> at-rule,
2607+
switch to the <i>rule mode</i>.
25802608

25812609
<p>
25822610
If the <i>current rule</i> is a stylesheet,

0 commit comments

Comments
 (0)