Skip to content

Commit 22c5888

Browse files
authored
Merge branch 'main' into benjie/incremental-common
2 parents 9c4a529 + ac483bd commit 22c5888

12 files changed

+636
-77
lines changed

.github/algorithm-format-check.mjs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ for (const filename of filenames) {
2828
const matches = line.match(/^([a-z0-9A-Z]+)(\s*)\(([^)]*)\)(\s*):(\s*)$/);
2929
const grammarMatches =
3030
filename === "Section 2 -- Language.md" &&
31-
line.match(/^([A-Za-z0-9]+) :\s+((\S).*)$/);
31+
line.match(/^([A-Za-z0-9]+) ::?\s+((\S).*)$/);
3232
if (matches) {
3333
const [, algorithmName, ns1, _args, ns2, ns3] = matches;
3434
if (ns1 || ns2 || ns3) {
@@ -67,14 +67,23 @@ for (const filename of filenames) {
6767
console.log();
6868
process.exitCode = 1;
6969
}
70-
if (step.match(/^\s*(-|[0-9]\.)\s+[a-z]/)) {
70+
if (step.match(/^\s*(-|[0-9]+\.)\s+[a-z]/)) {
7171
console.log(
7272
`Bad formatting of '${algorithmName}' step (should start with a capital) in '${filename}':`
7373
);
7474
console.dir(step);
7575
console.log();
7676
process.exitCode = 1;
7777
}
78+
const assertMatch = step.match(/^\s*(-|[0-9]+\.)\s*Assert([^:])/);
79+
if (assertMatch) {
80+
console.log(
81+
`Bad formatting of '${algorithmName}' step (Assert should be immediately followed by ':'; found '${assertMatch[2]}') in '${filename}':`
82+
);
83+
console.dir(step);
84+
console.log();
85+
process.exitCode = 1;
86+
}
7887

7988
const stepWithoutValueLiterals = step.replace(
8089
valueLiteralsRegexp,
@@ -131,6 +140,10 @@ for (const filename of filenames) {
131140
console.log();
132141
process.exitCode = 1;
133142
}
143+
while (lines[i + 1].trim() !== "") {
144+
// Continuation of definition
145+
i++;
146+
}
134147
if (!lines[i + 2].startsWith("- ")) {
135148
// Not an algorithm; probably more grammar
136149
continue;
@@ -176,6 +189,15 @@ for (const filename of filenames) {
176189
console.log();
177190
process.exitCode = 1;
178191
}
192+
const assertMatch = step.match(/^\s*(-|[0-9]+\.)\s*Assert([^:])/);
193+
if (assertMatch) {
194+
console.log(
195+
`Bad formatting of '${grammarName}' step (Assert should be immediately followed by ':'; found '${assertMatch[2]}') in '${filename}':`
196+
);
197+
console.dir(step);
198+
console.log();
199+
process.exitCode = 1;
200+
}
179201
}
180202
}
181203
}

package-lock.json

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@
2121
"suggest:format": "echo \"\nTo resolve this, run: $(tput bold)npm run format$(tput sgr0)\" && exit 1",
2222
"build": "./build.sh",
2323
"test:build": "spec-md --metadata spec/metadata.json spec/GraphQL.md > /dev/null",
24-
"watch": "nodemon -e json,md --exec \"npm run build\""
24+
"watch": "nodemon -e json,md --exec \"npm run build\"",
25+
"update-appendix-c": "node scripts/update-appendix-c.mjs; prettier --write \"spec/Appendix C -- Built-in Definitions.md\""
2526
},
2627
"devDependencies": {
2728
"cspell": "5.9.1",
2829
"nodemon": "2.0.20",
2930
"prettier": "2.8.2",
30-
"spec-md": "3.1.0"
31+
"spec-md": "3.1.0",
32+
"graphql": "^17.0.0-alpha.8"
3133
},
3234
"prettier": {
3335
"proseWrap": "always",

scripts/update-appendix-c.mjs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { writeFile } from 'node:fs/promises';
2+
import { printIntrospectionSchema, buildSchema, specifiedScalarTypes, printType } from 'graphql';
3+
4+
const FILE = './spec/Appendix C -- Specified Definitions.md';
5+
function printSpecifiedScalars() {
6+
return specifiedScalarTypes
7+
.map((type) => printType(type))
8+
.join('\n\n');
9+
}
10+
11+
const introspectionSchema = printIntrospectionSchema(buildSchema(`type Query { i: Int }`));
12+
const prefix = `
13+
# C. Appendix: Type System Definitions
14+
15+
This appendix lists the specified type system definitions.
16+
17+
The descriptions are non-normative. Implementations are recommended to use them
18+
for consistency but different descriptions are allowed.
19+
20+
The order of types, fields, arguments, values and directives is non-normative.
21+
22+
\`\`\`graphql
23+
`
24+
25+
const suffix = `
26+
\`\`\`
27+
`
28+
await writeFile(FILE, prefix + printSpecifiedScalars() + '\n\n' + introspectionSchema + suffix);

0 commit comments

Comments
 (0)