@@ -314,6 +314,9 @@ <h2 class="no-num no-toc" id=contents> Table of contents</h2>
314314 < li > < a href ="#switch-to-the-current-rules-content-mode "> < span
315315 class =secno > 3.6.15. </ span > Switch to the current rule's content
316316 mode</ a >
317+
318+ < li > < a href ="#finish-parsing "> < span class =secno > 3.6.16. </ span > Finish
319+ parsing</ a >
317320 </ ul >
318321
319322 < li > < a href ="#changes-from-css-2.1-core-grammar "> < span class =secno > 3.7.
@@ -2107,8 +2110,6 @@ <h3 id=tree-construction><span class=secno>3.6. </span> Tree Construction</h3>
21072110 < p > TODO:
21082111
21092112 < ul >
2110- < li > Handle an eof token in all the states.
2111-
21122113 < li > Make sure that I properly handle the case where the top element in
21132114 the stack isn't a stylesheet, such as when parsing the
21142115 < code > style</ code > attribute (there, the top element is a style rule,
@@ -2197,6 +2198,10 @@ <h4 id=top-level-mode-><span class=secno>3.6.2. </span> <dfn
21972198 href ="#consume-a-primitive "> < i > Consume a primitive</ i > </ a > and ignore the
21982199 return value. Remain in this state.
21992200
2201+ < dt > EOF token
2202+
2203+ < dd > < a href ="#finish-parsing0 "> < i > Finish parsing</ i > </ a > .
2204+
22002205 < dt > anything else
22012206
22022207 < dd > Create a style rule and push it onto the < a
@@ -2233,6 +2238,10 @@ <h4 id=at-rule-mode><span class=secno>3.6.3. </span> <dfn
22332238 Reconsume the < a href ="#current-input-token "> < i > current input
22342239 token</ i > </ a > .
22352240
2241+ < dt > EOF token
2242+
2243+ < dd > < a href ="#finish-parsing0 "> < i > Finish parsing</ i > </ a > .
2244+
22362245 < dt > anything else
22372246
22382247 < dd > < a href ="#consume-a-primitive "> < i > Consume a primitive</ i > </ a > and
@@ -2268,6 +2277,10 @@ <h4 id=rule-mode><span class=secno>3.6.4. </span> <dfn id=rule-mode0>Rule
22682277 onto the < a href ="#stack-of-open-rules "> < i > stack of open rules</ i > </ a > .
22692278 Switch to the < a href ="#at-rule-mode0 "> < i > at-rule mode</ i > </ a > .
22702279
2280+ < dt > EOF token
2281+
2282+ < dd > < a href ="#finish-parsing0 "> < i > Finish parsing</ i > </ a > .
2283+
22712284 < dt > anything else
22722285
22732286 < dd > Create a style rule and push it onto the < a
@@ -2287,6 +2300,12 @@ <h4 id=selector-mode><span class=secno>3.6.5. </span> <dfn
22872300 < dd > Switch to the < a href ="#declaration-mode0 "> < i > declaration
22882301 mode</ i > </ a > .
22892302
2303+ < dt > EOF token
2304+
2305+ < dd > Pop the top rule from the < a href ="#stack-of-open-rules "> < i > stack of
2306+ open rules</ i > </ a > and discard it. < a href ="#finish-parsing0 "> < i > Finish
2307+ parsing</ i > </ a > .
2308+
22902309 < dt > anything else
22912310
22922311 < dd > < a href ="#consume-a-primitive "> < i > Consume a primitive</ i > </ a > and
@@ -2329,6 +2348,10 @@ <h4 id=declaration-mode><span class=secno>3.6.6. </span> <dfn
23292348 < a href ="#after-declaration-name-mode0 "> < i > after-declaration-name
23302349 mode</ i > </ a > .
23312350
2351+ < dt > EOF token
2352+
2353+ < dd > < a href ="#finish-parsing0 "> < i > Finish parsing</ i > </ a > .
2354+
23322355 < dt > anything else
23332356
23342357 < dd > This is a < i > parse error</ i > . Switch to the < a
@@ -2358,6 +2381,12 @@ <h4 id=after-declaration-name-mode><span class=secno>3.6.7. </span> <dfn
23582381 href ="#switch-to-the-current-rules-content-mode0 "> < i > Switch to the
23592382 current rule's content mode</ i > </ a > .
23602383
2384+ < dt > EOF token
2385+
2386+ < dd > Discard the < a href ="#current-declaration "> < i > current
2387+ declaration</ i > </ a > . < a href ="#finish-parsing0 "> < i > Finish
2388+ parsing</ i > </ a > .
2389+
23612390 < dt > anything else
23622391
23632392 < dd > This is a < i > parse error</ i > . Switch to the < a
@@ -2404,6 +2433,10 @@ <h4 id=declaration-value-mode><span class=secno>3.6.8. </span> <dfn
24042433 < a href ="#switch-to-the-current-rules-content-mode0 "> < i > Switch to the
24052434 current rule's content mode</ i > </ a > .
24062435
2436+ < dt > EOF token
2437+
2438+ < dd > < a href ="#finish-parsing0 "> < i > Finish parsing</ i > </ a > .
2439+
24072440 < dt > anything else
24082441
24092442 < dd > < a href ="#consume-a-primitive "> < i > Consume a primitive</ i > </ a > and
@@ -2446,6 +2479,10 @@ <h4 id=declaration-end-mode><span class=secno>3.6.9. </span> <dfn
24462479 < a href ="#switch-to-the-current-rules-content-mode0 "> < i > Switch to the
24472480 current rule's content mode</ i > </ a > .
24482481
2482+ < dt > EOF token
2483+
2484+ < dd > < a href ="#finish-parsing0 "> < i > Finish parsing</ i > </ a > .
2485+
24492486 < dt > anything else
24502487
24512488 < dd > This is a < i > parse error</ i > . Discard the < a
@@ -2467,6 +2504,10 @@ <h4 id=next-block-error-mode><span class=secno>3.6.10. </span> <dfn
24672504 href ="#switch-to-the-current-rules-content-mode0 "> < i > Switch to the
24682505 current rule's content mode</ i > </ a > .
24692506
2507+ < dt > EOF token
2508+
2509+ < dd > < a href ="#finish-parsing0 "> < i > Finish parsing</ i > </ a > .
2510+
24702511 < dt > anything else
24712512
24722513 < dd > < a href ="#consume-a-primitive "> < i > Consume a primitive</ i > </ a > . Ignore
@@ -2490,6 +2531,10 @@ <h4 id=next-declaration-error-mode><span class=secno>3.6.11. </span> <dfn
24902531 mode</ i > </ a > . Reprocess the < a href ="#current-input-token "> < i > current
24912532 input token</ i > </ a > .
24922533
2534+ < dt > EOF token
2535+
2536+ < dd > < a href ="#finish-parsing0 "> < i > Finish parsing</ i > </ a > .
2537+
24932538 < dt > anything else
24942539
24952540 < dd > < a href ="#consume-a-primitive "> < i > Consume a primitive</ i > </ a > . Ignore
@@ -2597,6 +2642,25 @@ <h4 id=switch-to-the-current-rules-content-mode><span class=secno>3.6.15.
25972642 < p > If the < a href ="#current-rule "> < i > current rule</ i > </ a > is a stylesheet,
25982643 switch to the < a href ="#top-level-mode "> < i > top-level mode</ i > </ a > .
25992644
2645+ < h4 id =finish-parsing > < span class =secno > 3.6.16. </ span > < dfn
2646+ id =finish-parsing0 > Finish parsing</ dfn > </ h4 >
2647+
2648+ < p > This section describes how to < a href ="#finish-parsing0 "> < i > finish
2649+ parsing</ i > </ a > . It is invoked whenever an EOF token is encountered.
2650+
2651+ < p > If there is a < a href ="#current-declaration "> < i > current
2652+ declaration</ i > </ a > , append it to the value of the < a
2653+ href ="#current-rule "> < i > current rule</ i > </ a > .
2654+
2655+ < p > While there's more than one rule on the < a
2656+ href ="#stack-of-open-rules "> < i > stack of open rules</ i > </ a > , pop the < a
2657+ href ="#current-rule "> < i > current rule</ i > </ a > from the < a
2658+ href ="#stack-of-open-rules "> < i > stack of open rules</ i > </ a > , and append it
2659+ to the value of the new < a href ="#current-rule "> < i > current rule</ i > </ a > .
2660+
2661+ < p > Finally, return the < a href ="#current-rule "> < i > current rule</ i > </ a > as
2662+ the result of parsing.
2663+
26002664 < h3 id =changes-from-css-2.1-core-grammar > < span class =secno > 3.7. </ span >
26012665 Changes from CSS 2.1 Core Grammar</ h3 >
26022666
@@ -2949,6 +3013,9 @@ <h2 class=no-num id=index> Index</h2>
29493013 < li > end of the range, < a href ="#end-of-the-range "
29503014 title ="end of the range "> < strong > 3.4.27.</ strong > </ a >
29513015
3016+ < li > Finish parsing, < a href ="#finish-parsing0 "
3017+ title ="Finish parsing "> < strong > 3.6.16.</ strong > </ a >
3018+
29523019 < li > Hash-rest state, < a href ="#hash-rest-state0 "
29533020 title ="Hash-rest state "> < strong > 3.4.7.</ strong > </ a >
29543021
0 commit comments