Skip to content

Commit e5bddd9

Browse files
authored
Fix punctuation in grammar rule (#1084)
1 parent a80f9ff commit e5bddd9

File tree

2 files changed

+73
-10
lines changed

2 files changed

+73
-10
lines changed

.github/algorithm-format-check.mjs

+68-5
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,16 @@ for (const filename of filenames) {
2323
{
2424
// Is it an algorithm definition?
2525
const matches = line.match(/^([a-z0-9A-Z]+)(\s*)\(([^)]*)\)(\s*):(\s*)$/);
26+
const grammarMatches =
27+
filename === "Section 2 -- Language.md" &&
28+
line.match(/^([A-Za-z0-9]+) :\s+((\S).*)$/);
2629
if (matches) {
2730
const [, algorithmName, ns1, _args, ns2, ns3] = matches;
2831
if (ns1 || ns2 || ns3) {
2932
console.log(
3033
`Bad whitespace in definition of ${algorithmName} in '${filename}':`
3134
);
32-
console.log(line);
35+
console.dir(line);
3336
console.log();
3437
process.exitCode = 1;
3538
}
@@ -47,7 +50,7 @@ for (const filename of filenames) {
4750
console.log(
4851
`Bad algorithm ${algorithmName} step in '${filename}':`
4952
);
50-
console.log(step);
53+
console.dir(step);
5154
console.log();
5255
process.exitCode = 1;
5356
}
@@ -57,15 +60,15 @@ for (const filename of filenames) {
5760
console.log(
5861
`Bad formatting for '${algorithmName}' step (does not end in '.' or ':') in '${filename}':`
5962
);
60-
console.log(step);
63+
console.dir(step);
6164
console.log();
6265
process.exitCode = 1;
6366
}
6467
if (step.match(/^\s*(-|[0-9]\.)\s+[a-z]/)) {
6568
console.log(
6669
`Bad formatting of '${algorithmName}' step (should start with a capital) in '${filename}':`
6770
);
68-
console.log(step);
71+
console.dir(step);
6972
console.log();
7073
process.exitCode = 1;
7174
}
@@ -79,7 +82,67 @@ for (const filename of filenames) {
7982
console.log(
8083
`Potential bad formatting of '${algorithmName}' step (true/false/null should be wrapped in curly braces, e.g. '{true}') in '${filename}':`
8184
);
82-
console.log(step);
85+
console.dir(step);
86+
console.log();
87+
process.exitCode = 1;
88+
}
89+
}
90+
} else if (grammarMatches) {
91+
// This is super loosey-goosey
92+
const [, grammarName, rest] = grammarMatches;
93+
if (rest.trim() === "one of") {
94+
// Still grammar, not algorithm
95+
continue;
96+
}
97+
if (rest.trim() === "" && lines[i + 1] !== "") {
98+
console.log(
99+
`No empty space after grammar ${grammarName} header in '${filename}'`
100+
);
101+
console.log();
102+
process.exitCode = 1;
103+
}
104+
if (!lines[i + 2].startsWith("- ")) {
105+
// Not an algorithm; probably more grammar
106+
continue;
107+
}
108+
for (let j = i + 2; j < l; j++) {
109+
const step = lines[j];
110+
if (!step.match(/^\s*(-|[0-9]+\.) /)) {
111+
if (step !== "") {
112+
console.log(`Bad grammar ${grammarName} step in '${filename}':`);
113+
console.dir(step);
114+
console.log();
115+
process.exitCode = 1;
116+
}
117+
break;
118+
}
119+
if (!step.match(/[.:]$/)) {
120+
console.log(
121+
`Bad formatting for '${grammarName}' step (does not end in '.' or ':') in '${filename}':`
122+
);
123+
console.dir(step);
124+
console.log();
125+
process.exitCode = 1;
126+
}
127+
if (step.match(/^\s*(-|[0-9]\.)\s+[a-z]/)) {
128+
console.log(
129+
`Bad formatting of '${grammarName}' step (should start with a capital) in '${filename}':`
130+
);
131+
console.dir(step);
132+
console.log();
133+
process.exitCode = 1;
134+
}
135+
const trimmedInnerLine = step.replace(/\s+/g, " ");
136+
if (
137+
trimmedInnerLine.match(
138+
/(?:[rR]eturn|is (?:not )?)(true|false|null)\b/
139+
) &&
140+
!trimmedInnerLine.match(/null or empty/)
141+
) {
142+
console.log(
143+
`Potential bad formatting of '${grammarName}' step (true/false/null should be wrapped in curly braces, e.g. '{true}') in '${filename}':`
144+
);
145+
console.dir(step);
83146
console.log();
84147
process.exitCode = 1;
85148
}

spec/Section 6 -- Execution.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -293,11 +293,11 @@ subscription _selection set_ using that event as a root value.
293293
MapSourceToResponseEvent(sourceStream, subscription, schema, variableValues):
294294

295295
- Return a new event stream {responseStream} which yields events as follows:
296-
- For each {event} on {sourceStream}:
297-
- Let {response} be the result of running
298-
{ExecuteSubscriptionEvent(subscription, schema, variableValues, event)}.
299-
- Yield an event containing {response}.
300-
- When {sourceStream} completes: complete {responseStream}.
296+
- For each {event} on {sourceStream}:
297+
- Let {response} be the result of running
298+
{ExecuteSubscriptionEvent(subscription, schema, variableValues, event)}.
299+
- Yield an event containing {response}.
300+
- When {sourceStream} completes: complete {responseStream}.
301301

302302
ExecuteSubscriptionEvent(subscription, schema, variableValues, initialValue):
303303

0 commit comments

Comments
 (0)