Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow bulleted lists in "one of" productions #51

Merged
merged 1 commit into from
Jan 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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