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 newline after "one of" #54

Merged
merged 4 commits into from
Apr 2, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/grammar.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -616,10 +616,10 @@ production = BLOCK token:nonTerminal _ defType:(':::'/'::'/':') rhs:productionRH

productionRHS = oneOfRHS / singleRHS / listRHS

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

Expand Down
116 changes: 116 additions & 0 deletions test/productions/ast.json
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,122 @@
}
]
}
},
{
"type": "Paragraph",
"contents": [
{
"type": "Text",
"value": "Multiple definitions can have a newline after it"
}
]
},
{
"type": "Production",
"token": {
"type": "NonTerminal",
"name": "PBJ",
"params": null
},
"defType": 1,
"rhs": {
"type": "ListRHS",
"defs": [
{
"type": "RHS",
"condition": null,
"tokens": [
{
"type": "NonTerminal",
"name": "Bread",
"params": null
},
{
"type": "NonTerminal",
"name": "PeanutButter",
"params": null
},
{
"type": "NonTerminal",
"name": "Jelly",
"params": null
},
{
"type": "NonTerminal",
"name": "Bread",
"params": null
}
]
},
{
"type": "RHS",
"condition": null,
"tokens": [
{
"type": "NonTerminal",
"name": "Bread",
"params": null
},
{
"type": "NonTerminal",
"name": "PeanutButter",
"params": null
},
{
"type": "NonTerminal",
"name": "Jelly",
"params": null
},
{
"type": "NonTerminal",
"name": "Bread",
"params": null
}
]
}
]
}
},
{
"type": "Paragraph",
"contents": [
{
"type": "Text",
"value": "One of can have a newline after it"
}
]
},
{
"type": "Production",
"token": {
"type": "NonTerminal",
"name": "Punc",
"params": null
},
"defType": 1,
"rhs": {
"type": "OneOfRHS",
"rows": [
[
{
"type": "Terminal",
"value": "."
}
],
[
{
"type": "Terminal",
"value": "!"
}
],
[
{
"type": "Terminal",
"value": "?"
}
]
]
}
}
]
},
Expand Down
15 changes: 15 additions & 0 deletions test/productions/input.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,21 @@ PBJ: Bread
Mustard
Bread

Multiple definitions can have a newline after it

PBJ:

- Bread PeanutButter Jelly Bread
- Bread PeanutButter Jelly Bread

One of can have a newline after it

Punc: one of

- `.`
- `!`
- `?`

# Algorithms

An algoritm can have no args
Expand Down
18 changes: 17 additions & 1 deletion test/productions/output.html
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,22 @@ <h1><span class="spec-secid" title="link to this section"><a href="#sec-Grammar"
<div class="spec-production" id="PBJ">
<span class="spec-nt"><a href="#PBJ" data-name="PBJ">PBJ</a></span><div class="spec-rhs"><span class="spec-nt"><span data-name="Bread">Bread</span></span><span class="spec-constrained"><span class="spec-nt"><span data-name="Condiment">Condiment</span></span><span class="spec-butnot"><span class="spec-nt"><span data-name="Ketchup">Ketchup</span></span><span class="spec-nt"><span data-name="Mustard">Mustard</span></span></span></span><span class="spec-nt"><span data-name="Bread">Bread</span></span></div>
</div>
<p>Multiple definitions can have a newline after it</p>
<div class="spec-production" id="PBJ">
<span class="spec-nt"><a href="#PBJ" data-name="PBJ">PBJ</a></span><div class="spec-rhs"><span class="spec-nt"><span data-name="Bread">Bread</span></span><span class="spec-nt"><span data-name="PeanutButter">PeanutButter</span></span><span class="spec-nt"><span data-name="Jelly">Jelly</span></span><span class="spec-nt"><span data-name="Bread">Bread</span></span></div>
<div class="spec-rhs"><span class="spec-nt"><span data-name="Bread">Bread</span></span><span class="spec-nt"><span data-name="PeanutButter">PeanutButter</span></span><span class="spec-nt"><span data-name="Jelly">Jelly</span></span><span class="spec-nt"><span data-name="Bread">Bread</span></span></div>
</div>
<p>One of can have a newline after it</p>
<div class="spec-production" id="Punc">
<span class="spec-nt"><a href="#Punc" data-name="Punc">Punc</a></span><div class="spec-oneof"><div class="spec-oneof-grid"><table>
<tr>
<td class="spec-rhs"><span class="spec-t">.</span></td></tr>
<tr>
<td class="spec-rhs"><span class="spec-t">!</span></td></tr>
<tr>
<td class="spec-rhs"><span class="spec-t">?</span></td></tr>
</table></div></div>
</div>
</section>
<section id="sec-Algorithms" secid="2">
<h1><span class="spec-secid" title="link to this section"><a href="#sec-Algorithms">2</a></span>Algorithms</h1>
Expand Down Expand Up @@ -1103,7 +1119,7 @@ <h1><span class="spec-secid" title="link to this section"><a href="#sec-Algorith
</ol>
</div>
</section>
<section id="index" secid="index" class="spec-index"><h1><span class="spec-secid" title="link to the index"><a href="#index">§</a></span>Index</h1><ol><li><a href="#Algo()">Algo</a></li><li><a href="#PBJ">PBJ</a></li><li><a href="#Sandwich">Sandwich</a></li></ol></section></article>
<section id="index" secid="index" class="spec-index"><h1><span class="spec-secid" title="link to the index"><a href="#index">§</a></span>Index</h1><ol><li><a href="#Algo()">Algo</a></li><li><a href="#PBJ">PBJ</a></li><li><a href="#Punc">Punc</a></li><li><a href="#Sandwich">Sandwich</a></li></ol></section></article>
<footer>
Written in <a href="https://spec-md.com" target="_blank">Spec Markdown</a>.</footer>
<input hidden class="spec-sidebar-toggle" type="checkbox" id="spec-sidebar-toggle" aria-hidden /><label for="spec-sidebar-toggle" aria-hidden><div class="spec-sidebar-button">&#x2630;</div></label>
Expand Down