Skip to content

Commit

Permalink
Fix punctuation in grammar rule (#1084)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjie authored Jun 7, 2024
1 parent a80f9ff commit e5bddd9
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 10 deletions.
73 changes: 68 additions & 5 deletions .github/algorithm-format-check.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@ for (const filename of filenames) {
{
// Is it an algorithm definition?
const matches = line.match(/^([a-z0-9A-Z]+)(\s*)\(([^)]*)\)(\s*):(\s*)$/);
const grammarMatches =
filename === "Section 2 -- Language.md" &&
line.match(/^([A-Za-z0-9]+) :\s+((\S).*)$/);
if (matches) {
const [, algorithmName, ns1, _args, ns2, ns3] = matches;
if (ns1 || ns2 || ns3) {
console.log(
`Bad whitespace in definition of ${algorithmName} in '${filename}':`
);
console.log(line);
console.dir(line);
console.log();
process.exitCode = 1;
}
Expand All @@ -47,7 +50,7 @@ for (const filename of filenames) {
console.log(
`Bad algorithm ${algorithmName} step in '${filename}':`
);
console.log(step);
console.dir(step);
console.log();
process.exitCode = 1;
}
Expand All @@ -57,15 +60,15 @@ for (const filename of filenames) {
console.log(
`Bad formatting for '${algorithmName}' step (does not end in '.' or ':') in '${filename}':`
);
console.log(step);
console.dir(step);
console.log();
process.exitCode = 1;
}
if (step.match(/^\s*(-|[0-9]\.)\s+[a-z]/)) {
console.log(
`Bad formatting of '${algorithmName}' step (should start with a capital) in '${filename}':`
);
console.log(step);
console.dir(step);
console.log();
process.exitCode = 1;
}
Expand All @@ -79,7 +82,67 @@ for (const filename of filenames) {
console.log(
`Potential bad formatting of '${algorithmName}' step (true/false/null should be wrapped in curly braces, e.g. '{true}') in '${filename}':`
);
console.log(step);
console.dir(step);
console.log();
process.exitCode = 1;
}
}
} else if (grammarMatches) {
// This is super loosey-goosey
const [, grammarName, rest] = grammarMatches;
if (rest.trim() === "one of") {
// Still grammar, not algorithm
continue;
}
if (rest.trim() === "" && lines[i + 1] !== "") {
console.log(
`No empty space after grammar ${grammarName} header in '${filename}'`
);
console.log();
process.exitCode = 1;
}
if (!lines[i + 2].startsWith("- ")) {
// Not an algorithm; probably more grammar
continue;
}
for (let j = i + 2; j < l; j++) {
const step = lines[j];
if (!step.match(/^\s*(-|[0-9]+\.) /)) {
if (step !== "") {
console.log(`Bad grammar ${grammarName} step in '${filename}':`);
console.dir(step);
console.log();
process.exitCode = 1;
}
break;
}
if (!step.match(/[.:]$/)) {
console.log(
`Bad formatting for '${grammarName}' step (does not end in '.' or ':') in '${filename}':`
);
console.dir(step);
console.log();
process.exitCode = 1;
}
if (step.match(/^\s*(-|[0-9]\.)\s+[a-z]/)) {
console.log(
`Bad formatting of '${grammarName}' step (should start with a capital) in '${filename}':`
);
console.dir(step);
console.log();
process.exitCode = 1;
}
const trimmedInnerLine = step.replace(/\s+/g, " ");
if (
trimmedInnerLine.match(
/(?:[rR]eturn|is (?:not )?)(true|false|null)\b/
) &&
!trimmedInnerLine.match(/null or empty/)
) {
console.log(
`Potential bad formatting of '${grammarName}' step (true/false/null should be wrapped in curly braces, e.g. '{true}') in '${filename}':`
);
console.dir(step);
console.log();
process.exitCode = 1;
}
Expand Down
10 changes: 5 additions & 5 deletions spec/Section 6 -- Execution.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,11 @@ subscription _selection set_ using that event as a root value.
MapSourceToResponseEvent(sourceStream, subscription, schema, variableValues):

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

ExecuteSubscriptionEvent(subscription, schema, variableValues, initialValue):

Expand Down

0 comments on commit e5bddd9

Please sign in to comment.