Skip to content

Commit 80621f1

Browse files
committed
Meta: fix the grammar post processor on Review Drafts
Closes #1195 by using a new attribute, grammar-fill-with="", which won't get removed by Bikeshed's "slim build artifact" setting. Closes #815 since the new version of webidl-grammar-post-processor includes the appropriate nonterminal fix.
1 parent 7eea897 commit 80621f1

File tree

4 files changed

+162
-125
lines changed

4 files changed

+162
-125
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ local: index.bs
2020

2121
deploy: index.bs
2222
curl --remote-name --fail https://resources.whatwg.org/build/deploy.sh
23-
POST_BUILD_STEP='node ./check-grammar.js "$$DIR/index.html" && npm run pp-webidl -- --input "$$DIR/index.html"' \
23+
POST_BUILD_STEP='node ./check-grammar.js "$$DIR/index.html" && npm run webidl-grammar-post-processor -- --input "$$DIR/index.html"' \
2424
bash ./deploy.sh
2525

2626
review: index.bs

index.bs

Lines changed: 78 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,15 +1249,15 @@ No [=extended attributes=] defined in this specification are applicable to [=inc
12491249

12501250
</div>
12511251

1252-
<div data-fill-with="grammar-CallbackOrInterfaceOrMixin"></div>
1252+
<div grammar-fill-with="CallbackOrInterfaceOrMixin"></div>
12531253

1254-
<div data-fill-with="grammar-CallbackRestOrInterfaceOrMixin"></div>
1254+
<div grammar-fill-with="CallbackRestOrInterfaceOrMixin"></div>
12551255

1256-
<div data-fill-with="grammar-InterfaceOrMixin"></div>
1256+
<div grammar-fill-with="InterfaceOrMixin"></div>
12571257

1258-
<div data-fill-with="grammar-Partial"></div>
1258+
<div grammar-fill-with="Partial"></div>
12591259

1260-
<div data-fill-with="grammar-PartialDefinition"></div>
1260+
<div grammar-fill-with="PartialDefinition"></div>
12611261

12621262
<pre class="grammar" id="prod-MixinRest">
12631263
MixinRest :
@@ -2449,7 +2449,7 @@ Note: When defining [=method steps=], you implicitly have access to [=this=].
24492449
ε
24502450
</pre>
24512451

2452-
<div data-fill-with="grammar-ArgumentNameKeyword"></div>
2452+
<div grammar-fill-with="ArgumentNameKeyword"></div>
24532453

24542454
<h5 id="idl-tojson-operation">toJSON</h5>
24552455

@@ -2631,13 +2631,13 @@ See [[#interface-object]] for details on how a [=constructor operation=] is to b
26312631
"constructor" "(" ArgumentList ")" ";"
26322632
</pre>
26332633

2634-
<div data-fill-with="grammar-ArgumentList"></div>
2635-
<div data-fill-with="grammar-Arguments"></div>
2636-
<div data-fill-with="grammar-Argument"></div>
2637-
<div data-fill-with="grammar-ArgumentRest"></div>
2638-
<div data-fill-with="grammar-ArgumentName"></div>
2639-
<div data-fill-with="grammar-Ellipsis"></div>
2640-
<div data-fill-with="grammar-ArgumentNameKeyword"></div>
2634+
<div grammar-fill-with="ArgumentList"></div>
2635+
<div grammar-fill-with="Arguments"></div>
2636+
<div grammar-fill-with="Argument"></div>
2637+
<div grammar-fill-with="ArgumentRest"></div>
2638+
<div grammar-fill-with="ArgumentName"></div>
2639+
<div grammar-fill-with="Ellipsis"></div>
2640+
<div grammar-fill-with="ArgumentNameKeyword"></div>
26412641

26422642

26432643
<h4 id="idl-stringifiers">Stringifiers</h4>
@@ -4483,9 +4483,9 @@ an [=asynchronously iterable declaration=],
44834483
a [=setlike declaration=], or
44844484
an [=indexed property getter=].
44854485

4486-
<div data-fill-with="grammar-ReadOnlyMember"></div>
4486+
<div grammar-fill-with="ReadOnlyMember"></div>
44874487

4488-
<div data-fill-with="grammar-ReadOnlyMemberRest"></div>
4488+
<div grammar-fill-with="ReadOnlyMemberRest"></div>
44894489

44904490
<pre class="grammar" id="prod-ReadWriteMaplike">
44914491
ReadWriteMaplike :
@@ -4573,9 +4573,9 @@ an [=asynchronously iterable declaration=],
45734573
a [=maplike declaration=], or
45744574
an [=indexed property getter=].
45754575

4576-
<div data-fill-with="grammar-ReadOnlyMember"></div>
4576+
<div grammar-fill-with="ReadOnlyMember"></div>
45774577

4578-
<div data-fill-with="grammar-ReadOnlyMemberRest"></div>
4578+
<div grammar-fill-with="ReadOnlyMemberRest"></div>
45794579

45804580
<pre class="grammar" id="prod-ReadWriteSetlike">
45814581
ReadWriteSetlike :
@@ -4640,9 +4640,9 @@ Of the extended attributes defined in this specification, only the [{{CrossOrigi
46404640

46414641
[=Namespaces=] must be annotated with the [{{Exposed}}] [=extended attribute=].
46424642

4643-
<div data-fill-with="grammar-Partial"></div>
4643+
<div grammar-fill-with="Partial"></div>
46444644

4645-
<div data-fill-with="grammar-PartialDefinition"></div>
4645+
<div grammar-fill-with="PartialDefinition"></div>
46464646

46474647
<pre class="grammar" id="prod-Namespace">
46484648
Namespace :
@@ -4978,9 +4978,9 @@ on that dictionary's [=inherited dictionaries=].
49784978

49794979
No [=extended attributes=] are applicable to dictionaries.
49804980

4981-
<div data-fill-with="grammar-Partial"></div>
4981+
<div grammar-fill-with="Partial"></div>
49824982

4983-
<div data-fill-with="grammar-PartialDefinition"></div>
4983+
<div grammar-fill-with="PartialDefinition"></div>
49844984

49854985
<pre class="grammar" id="prod-Dictionary">
49864986
Dictionary :
@@ -5015,9 +5015,9 @@ No [=extended attributes=] are applicable to dictionaries.
50155015
ε
50165016
</pre>
50175017

5018-
<div data-fill-with="grammar-DefaultValue"></div>
5018+
<div grammar-fill-with="DefaultValue"></div>
50195019

5020-
<div data-fill-with="grammar-Inheritance"></div>
5020+
<div grammar-fill-with="Inheritance"></div>
50215021

50225022
<div class="example" id="example-f7efabfd">
50235023

@@ -5474,9 +5474,9 @@ be used as the type of a [=constant=].
54745474
The following extended attribute is applicable to callback functions:
54755475
[{{LegacyTreatNonObjectAsNull}}].
54765476

5477-
<div data-fill-with="grammar-CallbackOrInterfaceOrMixin"></div>
5477+
<div grammar-fill-with="CallbackOrInterfaceOrMixin"></div>
54785478

5479-
<div data-fill-with="grammar-CallbackRestOrInterfaceOrMixin"></div>
5479+
<div grammar-fill-with="CallbackRestOrInterfaceOrMixin"></div>
54805480

54815481
<pre class="grammar" id="prod-CallbackRest">
54825482
CallbackRest :
@@ -5718,7 +5718,7 @@ are known as <dfn id="dfn-object-type" export>object types</dfn>.
57185718
"undefined" Null
57195719
</pre>
57205720

5721-
<div data-fill-with="grammar-ConstType"></div>
5721+
<div grammar-fill-with="ConstType"></div>
57225722

57235723
<pre class="grammar" id="prod-PrimitiveType">
57245724
PrimitiveType :
@@ -6384,13 +6384,13 @@ in IDL are represented in the same way that constant values of their
63846384
[=member types=] would be
63856385
represented.
63866386

6387-
<div data-fill-with="grammar-UnionType"></div>
6387+
<div grammar-fill-with="UnionType"></div>
63886388

6389-
<div data-fill-with="grammar-UnionMemberType"></div>
6389+
<div grammar-fill-with="UnionMemberType"></div>
63906390

6391-
<div data-fill-with="grammar-UnionMemberTypes"></div>
6391+
<div grammar-fill-with="UnionMemberTypes"></div>
63926392

6393-
<div data-fill-with="grammar-DistinguishableType"></div>
6393+
<div grammar-fill-with="DistinguishableType"></div>
63946394

63956395

63966396
<h4 id="idl-annotated-types">Annotated types</h4>
@@ -14925,7 +14925,7 @@ in the input text being parsed. Such <emu-t class="regex"><a href="#prod-whites
1492514925
The following LL(1) grammar, starting with <emu-nt><a href="#prod-Definitions">Definitions</a></emu-nt>,
1492614926
matches an [=IDL fragment=]:
1492714927

14928-
<div data-fill-with="grammar-index"></div>
14928+
<div grammar-fill-with="index"></div>
1492914929

1493014930
Note: The <emu-nt><a href="#prod-Other">Other</a></emu-nt>
1493114931
non-terminal matches any single terminal symbol except for
@@ -15053,33 +15053,51 @@ which is available under the
1505315053
<a href=https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document>W3C Software and Document License</a>.
1505415054

1505515055

15056-
<script class="remove">
15057-
// Grammar
15058-
(function() {
15059-
function wrap(s) { return "<pre class=grammar>" + s + "</pre>"; }
15060-
var output = "";
15061-
[].forEach.call(document.querySelectorAll("pre.grammar"), pre => {
15062-
var html = pre.textContent.replace(/("[^"]+")|([a-zA-Z]+)|(:)/g, m => {
15063-
if (/^"/.test(m)) { return "<emu-t>" + m.replace(/^"|"$/g, "") + "</emu-t>"; }
15064-
if (/^(integer|decimal|identifier|string|whitespace|comment|other)$/.test(m)) {
15065-
return "<emu-t class=\"regex\"><a href=\"#prod-" + m + "\">" + m + "</a></emu-t>";
15066-
}
15067-
if (m == ":") { return "::"; }
15068-
if (document.querySelector("#prod-" + m)) {
15069-
return "<emu-nt><a href=\"#prod-" + m + "\">" + m + "</a></emu-nt>";
15070-
}
15071-
return "<emu-nt>" + m + "</emu-nt>"
15072-
});
15073-
15074-
pre.innerHTML = html;
15075-
var fillWith = document.querySelectorAll("div[data-fill-with=\"grammar-" + pre.id.replace("prod-", "") + "\"]");
15076-
[].forEach.call(fillWith, div => div.innerHTML = wrap(html));
15077-
15078-
if (!(/\bno-index\b/).test(pre.className)) {
15079-
output += html.replace(/<emu-nt>/, "<emu-nt id=\"" + pre.id.replace("prod-", "index-prod-") + "\">")
15080-
.replace(/#prod-([^a-z])/g, "#index-prod-$1") + "\n";
15081-
}
15082-
});
15083-
document.querySelector("div[data-fill-with=\"grammar-index\"]").innerHTML = wrap(output);
15084-
})();
15056+
<script type="module" class="remove">
15057+
// This is a copy of the script from webidl-grammar-post-processor. It will fill in the various
15058+
// `grammar-fill-with=""` parts of the document at runtime, allowing local development to just use
15059+
// `bikeshed` instead of the whole `make` process. In fully-built versions, it is removed by
15060+
// webidl-grammar-post-processor.
15061+
15062+
let output = "";
15063+
for (const pre of document.querySelectorAll("pre.grammar")) {
15064+
const html = pre.textContent.replace(/("[^"]+")|([a-zA-Z]+)|(:)/g, m => {
15065+
if (/^"/.test(m)) {
15066+
return `<emu-t>${m.replace(/^"|"$/g, "")}</emu-t>`;
15067+
}
15068+
if (/^(integer|decimal|identifier|string|whitespace|comment|other)$/.test(m)) {
15069+
return `<emu-t class="regex"><a href="#prod-${m}">${m}</a></emu-t>`;
15070+
}
15071+
if (m == ":") {
15072+
return "::";
15073+
}
15074+
if (document.querySelector(`#prod-${m}`)) {
15075+
return `<emu-nt><a href="#prod-${m}">${m}</a></emu-nt>`;
15076+
}
15077+
return `<emu-nt>${m}</emu-nt>`;
15078+
});
15079+
15080+
pre.innerHTML = html;
15081+
15082+
const fillWith = document.querySelectorAll(`div[grammar-fill-with="${pre.id.replace("prod-", "")}"]`);
15083+
for (const div of fillWith) {
15084+
div.innerHTML = wrap(html);
15085+
}
15086+
15087+
if (!pre.classList.contains("no-index")) {
15088+
output += html
15089+
.replace(/<emu-nt>/, `<emu-nt id="${pre.id.replace("prod-", "index-prod-")}">`)
15090+
.replace(/#prod-([^a-z])/g, "#index-prod-$1") + "\n";
15091+
}
15092+
}
15093+
15094+
document.querySelector("div[grammar-fill-with=\"index\"]").innerHTML = wrap(output);
15095+
15096+
for (const el of document.querySelectorAll("[grammar-fill-with]")) {
15097+
el.removeAttribute("grammar-fill-with");
15098+
}
15099+
15100+
function wrap(s) {
15101+
return `<pre class=grammar>${s}</pre>`;
15102+
}
1508515103
</script>

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"private": true,
3-
"description": "Checks that the WebIDL grammar is LL(1)",
3+
"description": "Checks that the WebIDL grammar is LL(1) and performs postprocessing",
44
"devDependencies": {
5-
"jsdom": "^11.3.0",
5+
"jsdom": "^20.0.0",
66
"syntax-cli": "0.0.97",
7-
"webidl-grammar-post-processor": "^0.4.0"
7+
"webidl-grammar-post-processor": "^1.0.0"
88
},
99
"scripts": {
10-
"pp-webidl": "pp-webidl"
10+
"webidl-grammar-post-processor": "webidl-grammar-post-processor"
1111
}
1212
}

0 commit comments

Comments
 (0)