Skip to content

Commit 1aace69

Browse files
committed
Abstract the act of popping+appending the current rule, add syntax validation to the process.
--HG-- extra : rebase_source : 9ea9722eaa61d97c456c66a529ab46611478d21d
1 parent 0db1ca9 commit 1aace69

2 files changed

Lines changed: 84 additions & 64 deletions

File tree

css3-syntax/Overview.html

Lines changed: 50 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,10 @@ <h2 class="no-num no-toc" id=contents> Table of contents</h2>
315315
class=secno>3.6.15. </span> Switch to the current rule's content
316316
mode</a>
317317

318-
<li><a href="#finish-parsing"><span class=secno>3.6.16. </span> Finish
318+
<li><a href="#pop-the-current-rule"><span class=secno>3.6.16. </span>
319+
Pop the current rule</a>
320+
321+
<li><a href="#finish-parsing"><span class=secno>3.6.17. </span> Finish
319322
parsing</a>
320323
</ul>
321324

@@ -2218,10 +2221,8 @@ <h4 id=at-rule-mode><span class=secno>3.6.3. </span> <dfn
22182221
<dl>
22192222
<dt>semicolon token
22202223

2221-
<dd> Pop the <a href="#current-rule"><i>current rule</i></a> from the <a
2222-
href="#stack-of-open-rules"><i>stack of open rules</i></a> and append it
2223-
to the value of the new <a href="#current-rule"><i>current rule</i></a>.
2224-
<a href="#switch-to-the-current-rules-content-mode0"><i>Switch to the
2224+
<dd> <a href="#pop-the-current-rule0"><i>Pop the current rule</i></a>. <a
2225+
href="#switch-to-the-current-rules-content-mode0"><i>Switch to the
22252226
current rule's content mode.</i></a>
22262227

22272228
<dt>{ token
@@ -2257,10 +2258,8 @@ <h4 id=rule-mode><span class=secno>3.6.4. </span> <dfn id=rule-mode0>Rule
22572258
<dl>
22582259
<dt>} token
22592260

2260-
<dd> Pop the <a href="#current-rule"><i>current rule</i></a> from the <a
2261-
href="#stack-of-open-rules"><i>stack of open rules</i></a>, and append it
2262-
to the value of the new <a href="#current-rule"><i>current rule</i></a>.
2263-
<a href="#switch-to-the-current-rules-content-mode0"><i>Switch to the
2261+
<dd> <a href="#pop-the-current-rule0"><i>Pop the current rule</i></a>. <a
2262+
href="#switch-to-the-current-rules-content-mode0"><i>Switch to the
22642263
current rule's content mode</i></a>.
22652264

22662265
<dt>at-keyword token
@@ -2295,9 +2294,8 @@ <h4 id=selector-mode><span class=secno>3.6.5. </span> <dfn
22952294

22962295
<dt>EOF token
22972296

2298-
<dd> Pop the top rule from the <a href="#stack-of-open-rules"><i>stack of
2299-
open rules</i></a> and discard it. <a href="#finish-parsing0"><i>Finish
2300-
parsing</i></a>.
2297+
<dd> Discard the <a href="#current-rule"><i>current rule</i></a>. <a
2298+
href="#finish-parsing0"><i>Finish parsing</i></a>.
23012299

23022300
<dt>anything else
23032301

@@ -2320,10 +2318,7 @@ <h4 id=declaration-mode><span class=secno>3.6.6. </span> <dfn
23202318

23212319
<dt>} token
23222320

2323-
<dd> Pop the <a href="#current-rule"><i>current rule</i></a> from the <a
2324-
href="#stack-of-open-rules"><i>stack of open rules</i></a>, and append it
2325-
to the list of rules for the new <a href="#current-rule"><i>current
2326-
rule</i></a>. <a
2321+
<dd> <a href="#pop-the-current-rule0"><i>Pop the current rule</i></a>. <a
23272322
href="#switch-to-the-current-rules-content-mode0"><i>Switch to the
23282323
current rule's content mode</i></a>.
23292324

@@ -2409,21 +2404,19 @@ <h4 id=declaration-value-mode><span class=secno>3.6.8. </span> <dfn
24092404

24102405
<dt>semicolon token
24112406

2412-
<dd> Append the <a href="#current-declaration"><i>current
2413-
declaration</i></a> to the value of the <a
2407+
<dd> If the <a href="#current-declaration"><i>current declaration</i></a>
2408+
is grammatically valid, append it to the value of the <a
24142409
href="#current-rule"><i>current rule</i></a>. <a
24152410
href="#switch-to-the-current-rules-content-mode0"><i>Switch to the
24162411
current rule's content mode</i></a>.
24172412

24182413
<dt>} token
24192414

2420-
<dd> Append the <a href="#current-declaration"><i>current
2421-
declaration</i></a> to the value of the <a
2422-
href="#current-rule"><i>current rule</i></a>. Pop the <a
2423-
href="#current-rule"><i>current rule</i></a> from the <a
2424-
href="#stack-of-open-rules"><i>stack of open rules</i></a>, and append it
2425-
to the value of the new <a href="#current-rule"><i>current rule</i></a>.
2426-
<a href="#switch-to-the-current-rules-content-mode0"><i>Switch to the
2415+
<dd> If the <a href="#current-declaration"><i>current declaration</i></a>
2416+
is grammatically valid, append it to the value of the <a
2417+
href="#current-rule"><i>current rule</i></a>. <a
2418+
href="#pop-the-current-rule0"><i>Pop the current rule</i></a>. <a
2419+
href="#switch-to-the-current-rules-content-mode0"><i>Switch to the
24272420
current rule's content mode</i></a>.
24282421

24292422
<dt>EOF token
@@ -2455,21 +2448,19 @@ <h4 id=declaration-end-mode><span class=secno>3.6.9. </span> <dfn
24552448

24562449
<dt>semicolon token
24572450

2458-
<dd> Append the <a href="#current-declaration"><i>current
2459-
declaration</i></a> to the value of the <a
2451+
<dd> If the <a href="#current-declaration"><i>current declaration</i></a>
2452+
is grammatically valid, append it to the value of the <a
24602453
href="#current-rule"><i>current rule</i></a>. <a
24612454
href="#switch-to-the-current-rules-content-mode0"><i>Switch to the
24622455
current rule's content mode</i></a>.
24632456

24642457
<dt>} token
24652458

2466-
<dd> Append the <a href="#current-declaration"><i>current
2467-
declaration</i></a> to the value of the <a
2468-
href="#current-rule"><i>current rule</i></a>. Pop the <a
2469-
href="#current-rule"><i>current rule</i></a> from the <a
2470-
href="#stack-of-open-rules"><i>stack of open rules</i></a>, and append it
2471-
to the value of the new <a href="#current-rule"><i>current rule</i></a>.
2472-
<a href="#switch-to-the-current-rules-content-mode0"><i>Switch to the
2459+
<dd> If the <a href="#current-declaration"><i>current declaration</i></a>
2460+
is grammatically valid, append it to the value of the <a
2461+
href="#current-rule"><i>current rule</i></a>. <a
2462+
href="#pop-the-current-rule0"><i>Pop the current rule.</i></a> <a
2463+
href="#switch-to-the-current-rules-content-mode0"><i>Switch to the
24732464
current rule's content mode</i></a>.
24742465

24752466
<dt>EOF token
@@ -2635,21 +2626,35 @@ <h4 id=switch-to-the-current-rules-content-mode><span class=secno>3.6.15.
26352626
<p> If the <a href="#current-rule"><i>current rule</i></a> is a stylesheet,
26362627
switch to the <a href="#top-level-mode"><i>top-level mode</i></a>.
26372628

2638-
<h4 id=finish-parsing><span class=secno>3.6.16. </span> <dfn
2629+
<h4 id=pop-the-current-rule><span class=secno>3.6.16. </span> <dfn
2630+
id=pop-the-current-rule0>Pop the current rule</dfn></h4>
2631+
2632+
<p> This section describes how to <a href="#pop-the-current-rule0"><i>pop
2633+
the current rule</i></a>. It is invoked whenever a rule is "finished"
2634+
parsing and can be made part of its parent rule.
2635+
2636+
<p> First, validate the <a href="#current-rule"><i>current rule</i></a>
2637+
according to the appropriate grammar rules. If the rule does not match its
2638+
required grammar, discard it.
2639+
2640+
<p> Otherwise, pop the <a href="#current-rule"><i>current rule</i></a> from
2641+
the <a href="#stack-of-open-rules"><i>stack of open rules</i></a> and
2642+
append it to the value of the new <a href="#current-rule"><i>current
2643+
rule</i></a>.
2644+
2645+
<h4 id=finish-parsing><span class=secno>3.6.17. </span> <dfn
26392646
id=finish-parsing0>Finish parsing</dfn></h4>
26402647

26412648
<p> This section describes how to <a href="#finish-parsing0"><i>finish
26422649
parsing</i></a>. It is invoked whenever an EOF token is encountered.
26432650

26442651
<p> If there is a <a href="#current-declaration"><i>current
2645-
declaration</i></a>, append it to the value of the <a
2646-
href="#current-rule"><i>current rule</i></a>.
2652+
declaration</i></a>, and it is grammatically valid, append it to the value
2653+
of the <a href="#current-rule"><i>current rule</i></a>.
26472654

26482655
<p> While there's more than one rule on the <a
2649-
href="#stack-of-open-rules"><i>stack of open rules</i></a>, pop the <a
2650-
href="#current-rule"><i>current rule</i></a> from the <a
2651-
href="#stack-of-open-rules"><i>stack of open rules</i></a>, and append it
2652-
to the value of the new <a href="#current-rule"><i>current rule</i></a>.
2656+
href="#stack-of-open-rules"><i>stack of open rules</i></a>, <a
2657+
href="#pop-the-current-rule0"><i>pop the current rule</i></a>.
26532658

26542659
<p> Finally, return the <a href="#current-rule"><i>current rule</i></a> as
26552660
the result of parsing.
@@ -3007,7 +3012,7 @@ <h2 class=no-num id=index> Index</h2>
30073012
title="end of the range"><strong>3.4.27.</strong></a>
30083013

30093014
<li>Finish parsing, <a href="#finish-parsing0"
3010-
title="Finish parsing"><strong>3.6.16.</strong></a>
3015+
title="Finish parsing"><strong>3.6.17.</strong></a>
30113016

30123017
<li>Hash-rest state, <a href="#hash-rest-state0"
30133018
title="Hash-rest state"><strong>3.4.7.</strong></a>
@@ -3067,6 +3072,9 @@ <h2 class=no-num id=index> Index</h2>
30673072
<li>Number state, <a href="#number-state0"
30683073
title="Number state"><strong>3.4.14.</strong></a>
30693074

3075+
<li>Pop the current rule, <a href="#pop-the-current-rule0"
3076+
title="Pop the current rule"><strong>3.6.16.</strong></a>
3077+
30703078
<li>renderer, <a href="#renderer" title=renderer><strong>4.2.</strong></a>
30713079

30723080

css3-syntax/Overview.src.html

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2237,8 +2237,7 @@ <h4>
22372237
<dl>
22382238
<dt>semicolon token
22392239
<dd>
2240-
Pop the <i>current rule</i> from the <i>stack of open rules</i>
2241-
and append it to the value of the new <i>current rule</i>.
2240+
<i>Pop the current rule</i>.
22422241
<i>Switch to the current rule's content mode.</i>
22432242

22442243
<dt>{ token
@@ -2277,8 +2276,7 @@ <h4>
22772276
<dl>
22782277
<dt>} token
22792278
<dd>
2280-
Pop the <i>current rule</i> from the <i>stack of open rules</i>,
2281-
and append it to the value of the new <i>current rule</i>.
2279+
<i>Pop the current rule</i>.
22822280
<i>Switch to the current rule's content mode</i>.
22832281

22842282
<dt>at-keyword token
@@ -2315,8 +2313,7 @@ <h4>
23152313

23162314
<dt>EOF token
23172315
<dd>
2318-
Pop the top rule from the <i>stack of open rules</i>
2319-
and discard it.
2316+
Discard the <i>current rule</i>.
23202317
<i>Finish parsing</i>.
23212318

23222319
<dt>anything else
@@ -2343,8 +2340,7 @@ <h4>
23432340

23442341
<dt>} token
23452342
<dd>
2346-
Pop the <i>current rule</i> from the <i>stack of open rules</i>,
2347-
and append it to the list of rules for the new <i>current rule</i>.
2343+
<i>Pop the current rule</i>.
23482344
<i>Switch to the current rule's content mode</i>.
23492345

23502346
<dt>at-rule token
@@ -2433,16 +2429,15 @@ <h4>
24332429

24342430
<dt>semicolon token
24352431
<dd>
2436-
Append the <i>current declaration</i>
2437-
to the value of the <i>current rule</i>.
2432+
If the <i>current declaration</i> is grammatically valid,
2433+
append it to the value of the <i>current rule</i>.
24382434
<i>Switch to the current rule's content mode</i>.
24392435

24402436
<dt>} token
24412437
<dd>
2442-
Append the <i>current declaration</i>
2443-
to the value of the <i>current rule</i>.
2444-
Pop the <i>current rule</i> from the <i>stack of open rules</i>,
2445-
and append it to the value of the new <i>current rule</i>.
2438+
If the <i>current declaration</i> is grammatically valid,
2439+
append it to the value of the <i>current rule</i>.
2440+
<i>Pop the current rule</i>.
24462441
<i>Switch to the current rule's content mode</i>.
24472442

24482443
<dt>EOF token
@@ -2478,16 +2473,15 @@ <h4>
24782473

24792474
<dt>semicolon token
24802475
<dd>
2481-
Append the <i>current declaration</i>
2482-
to the value of the <i>current rule</i>.
2476+
If the <i>current declaration</i> is grammatically valid,
2477+
append it to the value of the <i>current rule</i>.
24832478
<i>Switch to the current rule's content mode</i>.
24842479

24852480
<dt>} token
24862481
<dd>
2487-
Append the <i>current declaration</i>
2488-
to the value of the <i>current rule</i>.
2489-
Pop the <i>current rule</i> from the <i>stack of open rules</i>,
2490-
and append it to the value of the new <i>current rule</i>.
2482+
If the <i>current declaration</i> is grammatically valid,
2483+
append it to the value of the <i>current rule</i>.
2484+
<i>Pop the current rule.</i>
24912485
<i>Switch to the current rule's content mode</i>.
24922486

24932487
<dt>EOF token
@@ -2666,6 +2660,24 @@ <h4>
26662660
switch to the <i>top-level mode</i>.
26672661

26682662

2663+
<h4>
2664+
<dfn>Pop the current rule</dfn></h4>
2665+
2666+
<p>
2667+
This section describes how to <i>pop the current rule</i>.
2668+
It is invoked whenever a rule is "finished" parsing
2669+
and can be made part of its parent rule.
2670+
2671+
<p>
2672+
First, validate the <i>current rule</i> according to the appropriate grammar rules.
2673+
If the rule does not match its required grammar,
2674+
discard it.
2675+
2676+
<p>
2677+
Otherwise, pop the <i>current rule</i> from the <i>stack of open rules</i>
2678+
and append it to the value of the new <i>current rule</i>.
2679+
2680+
26692681
<h4>
26702682
<dfn>Finish parsing</dfn></h4>
26712683

@@ -2675,12 +2687,12 @@ <h4>
26752687

26762688
<p>
26772689
If there is a <i>current declaration</i>,
2690+
and it is grammatically valid,
26782691
append it to the value of the <i>current rule</i>.
26792692

26802693
<p>
26812694
While there's more than one rule on the <i>stack of open rules</i>,
2682-
pop the <i>current rule</i> from the <i>stack of open rules</i>,
2683-
and append it to the value of the new <i>current rule</i>.
2695+
<i>pop the current rule</i>.
26842696

26852697
<p>
26862698
Finally, return the <i>current rule</i> as the result of parsing.

0 commit comments

Comments
 (0)