Skip to content

Commit b3e96b8

Browse files
committed
Specify EOF token handling in all of the parser states.
--HG-- extra : rebase_source : 57e499a0ffed92a060215ec739f7e0314e67f45f
1 parent db8993e commit b3e96b8

2 files changed

Lines changed: 131 additions & 5 deletions

File tree

css3-syntax/Overview.html

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

css3-syntax/Overview.src.html

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2129,9 +2129,6 @@ <h3>
21292129
TODO:
21302130

21312131
<ul>
2132-
<li>
2133-
Handle an eof token in all the states.
2134-
21352132
<li>
21362133
Make sure that I properly handle the case where the top element in the stack isn't a stylesheet,
21372134
such as when parsing the <code>style</code> attribute
@@ -2219,6 +2216,10 @@ <h4>
22192216
and ignore the return value.
22202217
Remain in this state.
22212218

2219+
<dt>EOF token
2220+
<dd>
2221+
<i>Finish parsing</i>.
2222+
22222223
<dt>anything else
22232224
<dd>
22242225
Create a style rule
@@ -2255,6 +2256,10 @@ <h4>
22552256
Switch to the <i>next-block error mode</i>.
22562257
Reconsume the <i>current input token</i>.
22572258

2259+
<dt>EOF token
2260+
<dd>
2261+
<i>Finish parsing</i>.
2262+
22582263
<dt>anything else
22592264
<dd>
22602265
<i>Consume a primitive</i>
@@ -2289,6 +2294,10 @@ <h4>
22892294
and push it onto the <i>stack of open rules</i>.
22902295
Switch to the <i>at-rule mode</i>.
22912296

2297+
<dt>EOF token
2298+
<dd>
2299+
<i>Finish parsing</i>.
2300+
22922301
<dt>anything else
22932302
<dd>
22942303
Create a style rule
@@ -2310,6 +2319,12 @@ <h4>
23102319
<dd>
23112320
Switch to the <i>declaration mode</i>.
23122321

2322+
<dt>EOF token
2323+
<dd>
2324+
Pop the top rule from the <i>stack of open rules</i>
2325+
and discard it.
2326+
<i>Finish parsing</i>.
2327+
23132328
<dt>anything else
23142329
<dd>
23152330
<i>Consume a primitive</i>
@@ -2351,6 +2366,10 @@ <h4>
23512366
with its name set to the value of the <i>current input token</i>.
23522367
Switch to the <i>after-declaration-name mode</i>.
23532368

2369+
<dt>EOF token
2370+
<dd>
2371+
<i>Finish parsing</i>.
2372+
23542373
<dt>anything else
23552374
<dd>
23562375
This is a <i>parse error</i>.
@@ -2381,6 +2400,10 @@ <h4>
23812400
Discard the <i>current declaration</i>.
23822401
<i>Switch to the current rule's content mode</i>.
23832402

2403+
<dt>EOF token
2404+
<dd>
2405+
Discard the <i>current declaration</i>.
2406+
<i>Finish parsing</i>.
23842407

23852408
<dt>anything else
23862409
<dd>
@@ -2428,6 +2451,10 @@ <h4>
24282451
and append it to the value of the new <i>current rule</i>.
24292452
<i>Switch to the current rule's content mode</i>.
24302453

2454+
<dt>EOF token
2455+
<dd>
2456+
<i>Finish parsing</i>.
2457+
24312458
<dt>anything else
24322459
<dd>
24332460
<i>Consume a primitive</i>
@@ -2469,6 +2496,10 @@ <h4>
24692496
and append it to the value of the new <i>current rule</i>.
24702497
<i>Switch to the current rule's content mode</i>.
24712498

2499+
<dt>EOF token
2500+
<dd>
2501+
<i>Finish parsing</i>.
2502+
24722503
<dt>anything else
24732504
<dd>
24742505
This is a <i>parse error</i>.
@@ -2490,6 +2521,10 @@ <h4>
24902521
Ignore the return value.
24912522
<i>Switch to the current rule's content mode</i>.
24922523

2524+
<dt>EOF token
2525+
<dd>
2526+
<i>Finish parsing</i>.
2527+
24932528
<dt>anything else
24942529
<dd>
24952530
<i>Consume a primitive</i>.
@@ -2516,6 +2551,10 @@ <h4>
25162551
Switch to the <i>declaration mode</i>.
25172552
Reprocess the <i>current input token</i>.
25182553

2554+
<dt>EOF token
2555+
<dd>
2556+
<i>Finish parsing</i>.
2557+
25192558
<dt>anything else
25202559
<dd>
25212560
<i>Consume a primitive</i>.
@@ -2633,6 +2672,26 @@ <h4>
26332672
switch to the <i>top-level mode</i>.
26342673

26352674

2675+
<h4>
2676+
<dfn>Finish parsing</dfn></h4>
2677+
2678+
<p>
2679+
This section describes how to <i>finish parsing</i>.
2680+
It is invoked whenever an EOF token is encountered.
2681+
2682+
<p>
2683+
If there is a <i>current declaration</i>,
2684+
append it to the value of the <i>current rule</i>.
2685+
2686+
<p>
2687+
While there's more than one rule on the <i>stack of open rules</i>,
2688+
pop the <i>current rule</i> from the <i>stack of open rules</i>,
2689+
and append it to the value of the new <i>current rule</i>.
2690+
2691+
<p>
2692+
Finally, return the <i>current rule</i> as the result of parsing.
2693+
2694+
26362695
<h3>
26372696
Changes from CSS 2.1 Core Grammar</h3>
26382697

0 commit comments

Comments
 (0)