Skip to content

Commit

Permalink
Allow bulleted lists in "one of" productions
Browse files Browse the repository at this point in the history
To help resolve the issue raised in graphql/graphql-spec#726, this allows each line of a grid of "one of" tokens to start with a line bullet.

The spec-md rendered results are equivalent, however in other tools the content should be much easier to read.
  • Loading branch information
leebyron committed Jan 10, 2021
1 parent 05fdfe5 commit cf72d25
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 34 deletions.
40 changes: 21 additions & 19 deletions spec/Spec Additions.md
Original file line number Diff line number Diff line change
Expand Up @@ -496,33 +496,35 @@ Produces the following:
AssignmentOperator : one of *= `/=` %= += -= <<= >>= >>>= &= ^= |=


"one of" can also be followed by a line break and multiple lines of tokens
"one of" can also be followed by a line break and multiple lines of tokens.
To improve legibility in other tools, each line may optionally begin with
a bullet.

```
Keyword : one of
break do in typeof
case else instanceof var
catch export new void
class extends return while
const finally super with
continue for switch yield
debugger function this
default if throw
delete import try
- break do in typeof
- case else instanceof var
- catch export new void
- class extends return while
- const finally super with
- continue for switch yield
- debugger function this
- default if throw
- delete import try
```

Produces the following:

Keyword : one of
break do in typeof
case else instanceof var
catch export new void
class extends return while
const finally super with
continue for switch yield
debugger function this
default if throw
delete import try
- break do in typeof
- case else instanceof var
- catch export new void
- class extends return while
- const finally super with
- continue for switch yield
- debugger function this
- default if throw
- delete import try


### Non Terminal Token
Expand Down
6 changes: 3 additions & 3 deletions src/grammar.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ variable = name:localName {

// Grammar productions

semantic = BLOCK name:nonTerminal _ defType:(':::'/'::'/':') __ tokens:tokens steps:list {
semantic = BLOCK name:nonTerminal _ defType:(':::'/'::'/':') __ !'one of' tokens:tokens steps:list {
return {
type: 'Semantic',
name: name,
Expand All @@ -592,14 +592,14 @@ production = BLOCK token:nonTerminal _ defType:(':::'/'::'/':') rhs:productionRH

productionRHS = oneOfRHS / singleRHS / listRHS

oneOfRHS = !(LINE listBullet) __ 'one of' rows:(_ NL? (_ token)+)+ {
oneOfRHS = !(LINE listBullet) __ 'one of' WB _ rows:(_ (NL _ listBullet?)? (_ token)+)+ {
return {
type: 'OneOfRHS',
rows: rows.map(row => row[2].map(tokens => tokens[1]))
};
}

singleRHS = !(LINE listBullet) __ condition:(condition __)? tokens:tokens {
singleRHS = !(LINE listBullet / 'one of') __ condition:(condition __)? tokens:tokens {
return {
type: 'RHS',
condition: condition ? condition[0] : null,
Expand Down
4 changes: 2 additions & 2 deletions test/readme/ast.json
Original file line number Diff line number Diff line change
Expand Up @@ -3610,7 +3610,7 @@
"contents": [
{
"type": "Text",
"value": "\"one of\" can also be followed by a line break and multiple lines of tokens"
"value": "\"one of\" can also be followed by a line break and multiple lines of tokens.\nTo improve legibility in other tools, each line may optionally begin with\na bullet."
}
]
},
Expand All @@ -3620,7 +3620,7 @@
"lang": null,
"example": false,
"counter": false,
"code": "Keyword : one of\n break do in typeof\n case else instanceof var\n catch export new void\n class extends return while\n const finally super with\n continue for switch yield\n debugger function this\n default if throw\n delete import try\n"
"code": "Keyword : one of\n - break do in typeof\n - case else instanceof var\n - catch export new void\n - class extends return while\n - const finally super with\n - continue for switch yield\n - debugger function this\n - default if throw\n - delete import try\n"
},
{
"type": "Paragraph",
Expand Down
20 changes: 10 additions & 10 deletions test/readme/output.html
Original file line number Diff line number Diff line change
Expand Up @@ -1751,17 +1751,17 @@ <h3><span class="spec-secid" title="link to this section"><a href="#sec-One-of">
<td class="spec-rhs"><span class="spec-t">*=</span></td><td class="spec-rhs"><span class="spec-t">/=</span></td><td class="spec-rhs"><span class="spec-t">%=</span></td><td class="spec-rhs"><span class="spec-t">+=</span></td><td class="spec-rhs"><span class="spec-t">-=</span></td><td class="spec-rhs"><span class="spec-t">&lt;&lt;=</span></td><td class="spec-rhs"><span class="spec-t">&gt;&gt;=</span></td><td class="spec-rhs"><span class="spec-t">&gt;&gt;&gt;=</span></td><td class="spec-rhs"><span class="spec-t">&amp;=</span></td><td class="spec-rhs"><span class="spec-t">^=</span></td><td class="spec-rhs"><span class="spec-t">|=</span></td></tr>
</table></div></div>
</div>
<p>&ldquo;one of&rdquo; can also be followed by a line break and multiple lines of tokens</p>
<p>&ldquo;one of&rdquo; can also be followed by a line break and multiple lines of tokens. To improve legibility in other tools, each line may optionally begin with a bullet.</p>
<pre><code>Keyword : one of
break do in typeof
case else instanceof var
catch export new void
class extends return while
const finally super with
continue for switch yield
debugger function this
default if throw
delete import try
- break do in typeof
- case else instanceof var
- catch export new void
- class extends return while
- const finally super with
- continue for switch yield
- debugger function this
- default if throw
- delete import try
</code></pre>
<p>Produces the following:</p>
<div class="spec-production" id="Keyword">
Expand Down

0 comments on commit cf72d25

Please sign in to comment.