From cdd8023acdad0c3b68275243439774f0a9633dfe Mon Sep 17 00:00:00 2001 From: Benjie Gillam Date: Mon, 11 Mar 2024 16:43:35 +0000 Subject: [PATCH 1/4] Add grammar algorithm checks --- .github/algorithm-format-check.mjs | 63 ++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/.github/algorithm-format-check.mjs b/.github/algorithm-format-check.mjs index 13a31ece9..9343efdc1 100644 --- a/.github/algorithm-format-check.mjs +++ b/.github/algorithm-format-check.mjs @@ -23,6 +23,9 @@ 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) { @@ -84,6 +87,66 @@ for (const filename of filenames) { 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 (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.log(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.log(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.log(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.log(step); + console.log(); + process.exitCode = 1; + } + } } } From 314b18fc0ed7fdd85f04e4c489907f002119466a Mon Sep 17 00:00:00 2001 From: Benjie Gillam Date: Mon, 11 Mar 2024 16:51:23 +0000 Subject: [PATCH 2/4] Use console.dir for alternative formatting of quoted text --- .github/algorithm-format-check.mjs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/algorithm-format-check.mjs b/.github/algorithm-format-check.mjs index 9343efdc1..e22b3c92e 100644 --- a/.github/algorithm-format-check.mjs +++ b/.github/algorithm-format-check.mjs @@ -32,7 +32,7 @@ for (const filename of filenames) { console.log( `Bad whitespace in definition of ${algorithmName} in '${filename}':` ); - console.log(line); + console.dir(line); console.log(); process.exitCode = 1; } @@ -50,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; } @@ -60,7 +60,7 @@ 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; } @@ -68,7 +68,7 @@ for (const filename of filenames) { 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; } @@ -82,7 +82,7 @@ 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; } @@ -110,7 +110,7 @@ for (const filename of filenames) { if (!step.match(/^\s*(-|[0-9]+\.) /)) { if (step !== "") { console.log(`Bad grammar ${grammarName} step in '${filename}':`); - console.log(step); + console.dir(step); console.log(); process.exitCode = 1; } @@ -120,7 +120,7 @@ for (const filename of filenames) { console.log( `Bad formatting for '${grammarName}' step (does not end in '.' or ':') in '${filename}':` ); - console.log(step); + console.dir(step); console.log(); process.exitCode = 1; } @@ -128,7 +128,7 @@ for (const filename of filenames) { console.log( `Bad formatting of '${grammarName}' step (should start with a capital) in '${filename}':` ); - console.log(step); + console.dir(step); console.log(); process.exitCode = 1; } @@ -142,7 +142,7 @@ for (const filename of filenames) { console.log( `Potential bad formatting of '${grammarName}' 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; } From bcbd294f018e2899aac345d4dbac039fab2198b0 Mon Sep 17 00:00:00 2001 From: Benjie Gillam Date: Thu, 6 Jun 2024 14:05:19 +0100 Subject: [PATCH 3/4] Fix indentation --- spec/Section 6 -- Execution.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/spec/Section 6 -- Execution.md b/spec/Section 6 -- Execution.md index c96bda97b..5b8594e30 100644 --- a/spec/Section 6 -- Execution.md +++ b/spec/Section 6 -- Execution.md @@ -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): From 5fda732213d6af1a982640e7dd9e79604a2105c8 Mon Sep 17 00:00:00 2001 From: Benjie Gillam Date: Thu, 6 Jun 2024 14:08:53 +0100 Subject: [PATCH 4/4] Fix bug in grammar header detection --- .github/algorithm-format-check.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/algorithm-format-check.mjs b/.github/algorithm-format-check.mjs index e22b3c92e..592d721de 100644 --- a/.github/algorithm-format-check.mjs +++ b/.github/algorithm-format-check.mjs @@ -94,7 +94,7 @@ for (const filename of filenames) { // Still grammar, not algorithm continue; } - if (lines[i + 1] !== "") { + if (rest.trim() === "" && lines[i + 1] !== "") { console.log( `No empty space after grammar ${grammarName} header in '${filename}'` );