Skip to content

Commit 59ad4b7

Browse files
committed
Merge branch 'main' into oneof-v2
2 parents 9bec236 + fca6653 commit 59ad4b7

15 files changed

+1034
-311
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);

spec/Appendix A -- Notation Conventions.md

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,5 +214,36 @@ Fibonacci(number):
214214
- Return {Fibonacci(previousNumber)} + {Fibonacci(previousPreviousNumber)}.
215215

216216
Note: Algorithms described in this document are written to be easy to
217-
understand. Implementers are encouraged to include equivalent but optimized
218-
implementations.
217+
understand. Implementers are encouraged to include observably equivalent but
218+
optimized implementations.
219+
220+
## Data Collections
221+
222+
Algorithms within this specification refer to abstract data collection types to
223+
express normative structural, uniqueness, and ordering requirements. Temporary
224+
data collections internal to an algorithm use these types to best describe
225+
expected behavior, but implementers are encouraged to provide observably
226+
equivalent but optimized implementations. Implementations may use any data
227+
structure as long as the expected requirements are met.
228+
229+
**List**
230+
231+
:: A _list_ is an ordered collection of values which may contain duplicates. A
232+
value added to a list is ordered after existing values.
233+
234+
**Set**
235+
236+
:: A _set_ is a collection of values which must not contain duplicates.
237+
238+
:: An _ordered set_ is a set which has a defined order. A value added to an
239+
ordered set, which does not already contain that value, is ordered after
240+
existing values.
241+
242+
**Map**
243+
244+
:: A _map_ is a collection of entries, each of which has a key and value. Each
245+
entry has a unique key, and can be directly referenced by that key.
246+
247+
:: An _ordered map_ is a map which has a defined order. An entry added to an
248+
ordered map, which does not have an entry with that key, is ordered after
249+
existing entries.

spec/Appendix B -- Grammar Summary.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ lines and uniform indentation with {BlockStringValue()}.
133133

134134
## Document Syntax
135135

136+
Description : StringValue
137+
136138
Document : Definition+
137139

138140
Definition :
@@ -149,7 +151,7 @@ ExecutableDefinition :
149151

150152
OperationDefinition :
151153

152-
- OperationType Name? VariablesDefinition? Directives? SelectionSet
154+
- Description? OperationType Name? VariablesDefinition? Directives? SelectionSet
153155
- SelectionSet
154156

155157
OperationType : one of `query` `mutation` `subscription`
@@ -174,8 +176,8 @@ FragmentSpread : ... FragmentName Directives?
174176

175177
InlineFragment : ... TypeCondition? Directives? SelectionSet
176178

177-
FragmentDefinition : fragment FragmentName TypeCondition Directives?
178-
SelectionSet
179+
FragmentDefinition : Description? fragment FragmentName TypeCondition
180+
Directives? SelectionSet
179181

180182
FragmentName : Name but not `on`
181183

@@ -213,7 +215,8 @@ ObjectField[Const] : Name : Value[?Const]
213215

214216
VariablesDefinition : ( VariableDefinition+ )
215217

216-
VariableDefinition : Variable : Type DefaultValue? Directives[Const]?
218+
VariableDefinition : Description? Variable : Type DefaultValue?
219+
Directives[Const]?
217220

218221
Variable : $ Name
219222

@@ -268,8 +271,6 @@ SchemaExtension :
268271

269272
RootOperationTypeDefinition : OperationType : NamedType
270273

271-
Description : StringValue
272-
273274
TypeDefinition :
274275

275276
- ScalarTypeDefinition

0 commit comments

Comments
 (0)