Skip to content

Commit 38f8ef4

Browse files
committed
[css-syntax] OMG, fix all the current/next token bugs in the parse/consume algos, and make the structures more consistent in general.
1 parent 582f5d8 commit 38f8ef4

2 files changed

Lines changed: 54 additions & 36 deletions

File tree

css-syntax/Overview.bs

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2164,8 +2164,7 @@ Parse a rule</h4>
21642164

21652165
Otherwise,
21662166
if the <a>next input token</a> is an <<at-keyword-token>>,
2167-
consume it
2168-
and <a>consume an at-rule</a>,
2167+
<a>consume an at-rule</a>,
21692168
and let <var>rule</var> be the return value.
21702169

21712170
Otherwise,
@@ -2340,6 +2339,7 @@ Consume an at-rule</h4>
23402339

23412340
To <dfn>consume an at-rule</dfn>:
23422341

2342+
<a>Consume the next input token</a>.
23432343
Create a new at-rule
23442344
with its name set to the value of the <a>current input token</a>,
23452345
its prelude initially set to an empty list,
@@ -2355,6 +2355,7 @@ Consume an at-rule</h4>
23552355

23562356
<dt><a href="#tokendef-open-curly">&lt;{-token></a>
23572357
<dd>
2358+
<a>Reconsume the current input token</a>.
23582359
<a>Consume a simple block</a>
23592360
and assign it to the at-rule's block.
23602361
Return the at-rule.
@@ -2391,6 +2392,7 @@ Consume a qualified rule</h4>
23912392

23922393
<dt><a href="#tokendef-open-curly">&lt;{-token></a>
23932394
<dd>
2395+
<a>Reconsume the current input token</a>.
23942396
<a>Consume a simple block</a>
23952397
and assign it to the qualified rule's block.
23962398
Return the qualified rule.
@@ -2429,56 +2431,57 @@ Consume a list of declarations</h4>
24292431

24302432
<dt><<at-keyword-token>>
24312433
<dd>
2434+
<a>Reconsume the current input token</a>.
24322435
<a>Consume an at-rule</a>.
24332436
Append the returned rule to the list of declarations.
24342437

24352438
<dt><<ident-token>>
24362439
<dd>
24372440
Initialize a temporary list initially filled with the <a>current input token</a>.
2438-
<a>Consume the next input token</a>.
2439-
While the <a>current input token</a> is anything other than a <<semicolon-token>> or <<EOF-token>>,
2440-
append it to the temporary list
2441-
and <a>consume the next input token</a>.
2441+
As long as the <a>next input token</a> is anything other than a <<semicolon-token>> or <<EOF-token>>,
2442+
<a>consume the next input token</a> and append it to the temporary list.
24422443
<a>Consume a declaration</a> from the temporary list.
24432444
If anything was returned,
24442445
append it to the list of declarations.
24452446

24462447
<dt>anything else</dd>
24472448
<dd>
24482449
This is a <a>parse error</a>.
2449-
Repeatedly <a>consume a component value</a>
2450-
until it is a <<semicolon-token>> or <<EOF-token>>.
2450+
<a>Reconsume the current input token</a>.
2451+
As long as the <a>next input token</a> is anything other than a <<semicolon-token>> or <<EOF-token>>,
2452+
<a>consume a component value</a>
2453+
and throw away the returned value.
24512454
</dl>
24522455

24532456

24542457
<h4 id="consume-a-declaration">
24552458
Consume a declaration</h4>
24562459

2460+
Note: This algorithm assumes that the <a>next input token</a> has already been checked to be an <<ident-token>>.
2461+
24572462
To <dfn>consume a declaration</dfn>:
24582463

2464+
<a>Consume the next input token</a>.
24592465
Create a new declaration
24602466
with its name set to the value of the <a>current input token</a>
24612467
and its value initially set to the empty list.
24622468

24632469
<ol>
24642470
<li>
2465-
<a>Consume the next input token</a>.
2466-
2467-
<li>
2468-
While the <a>current input token</a> is a <<whitespace-token>>,
2471+
While the <a>next input token</a> is a <<whitespace-token>>,
24692472
<a>consume the next input token</a>.
24702473

24712474
<li>
2472-
If the <a>current input token</a> is anything other than a <<colon-token>>,
2475+
If the <a>next input token</a> is anything other than a <<colon-token>>,
24732476
this is a <a>parse error</a>.
24742477
Return nothing.
24752478

24762479
Otherwise, <a>consume the next input token</a>.
24772480

24782481
<li>
2479-
While the <a>current input token</a> is anything other than an <<EOF-token>>,
2480-
append it to the declaration's value
2481-
and <a>consume the next input token</a>.
2482+
As long as the <a>next input token</a> is anything other than an <<EOF-token>>,
2483+
<a>consume a component value</a>
2484+
and append it to the declaration's value.
24822485

24832486
<li>
24842487
If the last two non-<<whitespace-token>>s in the declaration's value are
@@ -2515,8 +2518,11 @@ Consume a component value</h4>
25152518
<h4 id="consume-a-simple-block">
25162519
Consume a simple block</h4>
25172520

2521+
Note: This algorithm assumes that the <a>next input token</a> has already been checked to be an <a href="#tokendef-open-curly">&lt;{-token></a>, <a href="#tokendef-open-square">&lt;[-token></a>, or <a href="#tokendef-open-paren">&lt;(-token></a>.
2522+
25182523
To <dfn>consume a simple block</dfn>:
25192524

2525+
<a>Consume the next input token</a>.
25202526
The <dfn>ending token</dfn> is the mirror variant of the <a>current input token</a>.
25212527
(E.g. if it was called with <a href="#tokendef-open-square">&lt;[-token></a>, the <a>ending token</a> is <a href="#tokendef-close-square">&lt;]-token></a>.)
25222528

@@ -2542,8 +2548,11 @@ Consume a simple block</h4>
25422548
<h4 id="consume-a-function">
25432549
Consume a function</h4>
25442550

2551+
Note: This algorithm assumes that the <a>next input token</a> has already been checked to be a <<function-token>>.
2552+
25452553
To <dfn>consume a function</dfn>:
25462554

2555+
<a>Consume the next input token</a>.
25472556
Create a function with a name equal to the value of the <a>current input token</a>,
25482557
and with a value which is initially an empty list.
25492558

css-syntax/Overview.html

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3677,8 +3677,7 @@ <h4 class="heading settled heading" data-level=5.3.3 id=parse-a-rule><span class
36773677

36783678
<p> Otherwise,
36793679
if the <a data-link-type=dfn href=#next-input-token title="next input token">next input token</a> is an <a class="production css-code" data-link-type=type href=#typedef-at-keyword-token title="<at-keyword-token>">&lt;at-keyword-token&gt;</a>,
3680-
consume it
3681-
and <a data-link-type=dfn href=#consume-an-at-rule0 title="consume an at-rule">consume an at-rule</a>,
3680+
<a data-link-type=dfn href=#consume-an-at-rule0 title="consume an at-rule">consume an at-rule</a>,
36823681
and let <var>rule</var> be the return value.
36833682

36843683
<p> Otherwise,
@@ -3853,7 +3852,8 @@ <h4 class="heading settled heading" data-level=5.4.2 id=consume-an-at-rule><span
38533852

38543853
<p> To <dfn data-dfn-type=dfn data-noexport="" id=consume-an-at-rule0>consume an at-rule<a class=self-link href=#consume-an-at-rule0></a></dfn>:
38553854

3856-
<p> Create a new at-rule
3855+
<p> <a data-link-type=dfn href=#consume-the-next-input-token title="consume the next input token">Consume the next input token</a>.
3856+
Create a new at-rule
38573857
with its name set to the value of the <a data-link-type=dfn href=#current-input-token title="current input token">current input token</a>,
38583858
its prelude initially set to an empty list,
38593859
and its value initially set to nothing.
@@ -3868,6 +3868,7 @@ <h4 class="heading settled heading" data-level=5.4.2 id=consume-an-at-rule><span
38683868

38693869
<dt><a href=#tokendef-open-curly>&lt;{-token&gt;</a>
38703870
<dd>
3871+
<a data-link-type=dfn href=#reconsume-the-current-input-token title="reconsume the current input token">Reconsume the current input token</a>.
38713872
<a data-link-type=dfn href=#consume-a-simple-block0 title="consume a simple block">Consume a simple block</a>
38723873
and assign it to the at-rule’s block.
38733874
Return the at-rule.
@@ -3904,6 +3905,7 @@ <h4 class="heading settled heading" data-level=5.4.3 id=consume-a-qualified-rule
39043905

39053906
<dt><a href=#tokendef-open-curly>&lt;{-token&gt;</a>
39063907
<dd>
3908+
<a data-link-type=dfn href=#reconsume-the-current-input-token title="reconsume the current input token">Reconsume the current input token</a>.
39073909
<a data-link-type=dfn href=#consume-a-simple-block0 title="consume a simple block">Consume a simple block</a>
39083910
and assign it to the qualified rule’s block.
39093911
Return the qualified rule.
@@ -3942,56 +3944,57 @@ <h4 class="heading settled heading" data-level=5.4.4 id=consume-a-list-of-declar
39423944

39433945
<dt><a class="production css-code" data-link-type=type href=#typedef-at-keyword-token title="<at-keyword-token>">&lt;at-keyword-token&gt;</a>
39443946
<dd>
3947+
<a data-link-type=dfn href=#reconsume-the-current-input-token title="reconsume the current input token">Reconsume the current input token</a>.
39453948
<a data-link-type=dfn href=#consume-an-at-rule0 title="consume an at-rule">Consume an at-rule</a>.
39463949
Append the returned rule to the list of declarations.
39473950

39483951
<dt><a class="production css-code" data-link-type=type href=#typedef-ident-token title="<ident-token>">&lt;ident-token&gt;</a>
39493952
<dd>
39503953
Initialize a temporary list initially filled with the <a data-link-type=dfn href=#current-input-token title="current input token">current input token</a>.
3951-
<a data-link-type=dfn href=#consume-the-next-input-token title="consume the next input token">Consume the next input token</a>.
3952-
While the <a data-link-type=dfn href=#current-input-token title="current input token">current input token</a> is anything other than a <a class="production css-code" data-link-type=type href=#typedef-semicolon-token title="<semicolon-token>">&lt;semicolon-token&gt;</a> or <a class="production css-code" data-link-type=type href=#typedef-eof-token title="<eof-token>">&lt;EOF-token&gt;</a>,
3953-
append it to the temporary list
3954-
and <a data-link-type=dfn href=#consume-the-next-input-token title="consume the next input token">consume the next input token</a>.
3954+
As long as the <a data-link-type=dfn href=#next-input-token title="next input token">next input token</a> is anything other than a <a class="production css-code" data-link-type=type href=#typedef-semicolon-token title="<semicolon-token>">&lt;semicolon-token&gt;</a> or <a class="production css-code" data-link-type=type href=#typedef-eof-token title="<eof-token>">&lt;EOF-token&gt;</a>,
3955+
<a data-link-type=dfn href=#consume-the-next-input-token title="consume the next input token">consume the next input token</a> and append it to the temporary list.
39553956
<a data-link-type=dfn href=#consume-a-declaration0 title="consume a declaration">Consume a declaration</a> from the temporary list.
39563957
If anything was returned,
39573958
append it to the list of declarations.
39583959

39593960
<dt>anything else
39603961
<dd>
39613962
This is a <a data-link-type=dfn href=#parse-error title="parse error">parse error</a>.
3962-
Repeatedly <a data-link-type=dfn href=#consume-a-component-value0 title="consume a component value">consume a component value</a>
3963-
until it is a <a class="production css-code" data-link-type=type href=#typedef-semicolon-token title="<semicolon-token>">&lt;semicolon-token&gt;</a> or <a class="production css-code" data-link-type=type href=#typedef-eof-token title="<eof-token>">&lt;EOF-token&gt;</a>.
3963+
<a data-link-type=dfn href=#reconsume-the-current-input-token title="reconsume the current input token">Reconsume the current input token</a>.
3964+
As long as the <a data-link-type=dfn href=#next-input-token title="next input token">next input token</a> is anything other than a <a class="production css-code" data-link-type=type href=#typedef-semicolon-token title="<semicolon-token>">&lt;semicolon-token&gt;</a> or <a class="production css-code" data-link-type=type href=#typedef-eof-token title="<eof-token>">&lt;EOF-token&gt;</a>,
3965+
<a data-link-type=dfn href=#consume-a-component-value0 title="consume a component value">consume a component value</a>
3966+
and throw away the returned value.
39643967
</dl>
39653968

39663969

39673970
<h4 class="heading settled heading" data-level=5.4.5 id=consume-a-declaration><span class=secno>5.4.5 </span><span class=content>
39683971
Consume a declaration</span><a class=self-link href=#consume-a-declaration></a></h4>
39693972

3973+
<p class=note> Note: This algorithm assumes that the <a data-link-type=dfn href=#next-input-token title="next input token">next input token</a> has already been checked to be an <a class="production css-code" data-link-type=type href=#typedef-ident-token title="<ident-token>">&lt;ident-token&gt;</a>.
3974+
39703975
<p> To <dfn data-dfn-type=dfn data-noexport="" id=consume-a-declaration0>consume a declaration<a class=self-link href=#consume-a-declaration0></a></dfn>:
39713976

3972-
<p> Create a new declaration
3977+
<p> <a data-link-type=dfn href=#consume-the-next-input-token title="consume the next input token">Consume the next input token</a>.
3978+
Create a new declaration
39733979
with its name set to the value of the <a data-link-type=dfn href=#current-input-token title="current input token">current input token</a>
39743980
and its value initially set to the empty list.
39753981

39763982
<ol>
39773983
<li>
3978-
<a data-link-type=dfn href=#consume-the-next-input-token title="consume the next input token">Consume the next input token</a>.
3979-
3980-
<li>
3981-
While the <a data-link-type=dfn href=#current-input-token title="current input token">current input token</a> is a <a class="production css-code" data-link-type=type href=#typedef-whitespace-token title="<whitespace-token>">&lt;whitespace-token&gt;</a>,
3984+
While the <a data-link-type=dfn href=#next-input-token title="next input token">next input token</a> is a <a class="production css-code" data-link-type=type href=#typedef-whitespace-token title="<whitespace-token>">&lt;whitespace-token&gt;</a>,
39823985
<a data-link-type=dfn href=#consume-the-next-input-token title="consume the next input token">consume the next input token</a>.
39833986

39843987
<li>
3985-
If the <a data-link-type=dfn href=#current-input-token title="current input token">current input token</a> is anything other than a <a class="production css-code" data-link-type=type href=#typedef-colon-token title="<colon-token>">&lt;colon-token&gt;</a>,
3988+
If the <a data-link-type=dfn href=#next-input-token title="next input token">next input token</a> is anything other than a <a class="production css-code" data-link-type=type href=#typedef-colon-token title="<colon-token>">&lt;colon-token&gt;</a>,
39863989
this is a <a data-link-type=dfn href=#parse-error title="parse error">parse error</a>.
39873990
Return nothing.
39883991

39893992
<p> Otherwise, <a data-link-type=dfn href=#consume-the-next-input-token title="consume the next input token">consume the next input token</a>.
39903993

39913994
<li>
3992-
While the <a data-link-type=dfn href=#current-input-token title="current input token">current input token</a> is anything other than an <a class="production css-code" data-link-type=type href=#typedef-eof-token title="<eof-token>">&lt;EOF-token&gt;</a>,
3993-
append it to the declaration’s value
3994-
and <a data-link-type=dfn href=#consume-the-next-input-token title="consume the next input token">consume the next input token</a>.
3995+
As long as the <a data-link-type=dfn href=#next-input-token title="next input token">next input token</a> is anything other than an <a class="production css-code" data-link-type=type href=#typedef-eof-token title="<eof-token>">&lt;EOF-token&gt;</a>,
3996+
<a data-link-type=dfn href=#consume-a-component-value0 title="consume a component value">consume a component value</a>
3997+
and append it to the declaration’s value.
39953998

39963999
<li>
39974000
If the last two non-<a class="production css-code" data-link-type=type href=#typedef-whitespace-token title="<whitespace-token>">&lt;whitespace-token&gt;</a>s in the declaration’s value are
@@ -4028,9 +4031,12 @@ <h4 class="heading settled heading" data-level=5.4.6 id=consume-a-component-valu
40284031
<h4 class="heading settled heading" data-level=5.4.7 id=consume-a-simple-block><span class=secno>5.4.7 </span><span class=content>
40294032
Consume a simple block</span><a class=self-link href=#consume-a-simple-block></a></h4>
40304033

4034+
<p class=note> Note: This algorithm assumes that the <a data-link-type=dfn href=#next-input-token title="next input token">next input token</a> has already been checked to be an <a href=#tokendef-open-curly>&lt;{-token&gt;</a>, <a href=#tokendef-open-square>&lt;[-token&gt;</a>, or <a href=#tokendef-open-paren>&lt;(-token&gt;</a>.
4035+
40314036
<p> To <dfn data-dfn-type=dfn data-noexport="" id=consume-a-simple-block0>consume a simple block<a class=self-link href=#consume-a-simple-block0></a></dfn>:
40324037

4033-
<p> The <dfn data-dfn-type=dfn data-noexport="" id=ending-token>ending token<a class=self-link href=#ending-token></a></dfn> is the mirror variant of the <a data-link-type=dfn href=#current-input-token title="current input token">current input token</a>.
4038+
<p> <a data-link-type=dfn href=#consume-the-next-input-token title="consume the next input token">Consume the next input token</a>.
4039+
The <dfn data-dfn-type=dfn data-noexport="" id=ending-token>ending token<a class=self-link href=#ending-token></a></dfn> is the mirror variant of the <a data-link-type=dfn href=#current-input-token title="current input token">current input token</a>.
40344040
(E.g. if it was called with <a href=#tokendef-open-square>&lt;[-token&gt;</a>, the <a data-link-type=dfn href=#ending-token title="ending token">ending token</a> is <a href=#tokendef-close-square>&lt;]-token&gt;</a>.)
40354041

40364042
<p> Create a <a data-link-type=dfn href=#simple-block title="simple block">simple block</a> with its associated token set to the <a data-link-type=dfn href=#current-input-token title="current input token">current input token</a>
@@ -4055,9 +4061,12 @@ <h4 class="heading settled heading" data-level=5.4.7 id=consume-a-simple-block><
40554061
<h4 class="heading settled heading" data-level=5.4.8 id=consume-a-function><span class=secno>5.4.8 </span><span class=content>
40564062
Consume a function</span><a class=self-link href=#consume-a-function></a></h4>
40574063

4064+
<p class=note> Note: This algorithm assumes that the <a data-link-type=dfn href=#next-input-token title="next input token">next input token</a> has already been checked to be a <a class="production css-code" data-link-type=type href=#typedef-function-token title="<function-token>">&lt;function-token&gt;</a>.
4065+
40584066
<p> To <dfn data-dfn-type=dfn data-noexport="" id=consume-a-function0>consume a function<a class=self-link href=#consume-a-function0></a></dfn>:
40594067

4060-
<p> Create a function with a name equal to the value of the <a data-link-type=dfn href=#current-input-token title="current input token">current input token</a>,
4068+
<p> <a data-link-type=dfn href=#consume-the-next-input-token title="consume the next input token">Consume the next input token</a>.
4069+
Create a function with a name equal to the value of the <a data-link-type=dfn href=#current-input-token title="current input token">current input token</a>,
40614070
and with a value which is initially an empty list.
40624071

40634072
<p> Repeatedly consume the <a data-link-type=dfn href=#next-input-token title="next input token">next input token</a> and process it as follows:

0 commit comments

Comments
 (0)