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

add code highlighting in README table #27

Merged
merged 2 commits into from
Jan 15, 2024
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
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ You can pick and choose the style for each parser and sub-parser, as there are n

| Description | Grammars |
| ----------- | -------- |
| Parsing a token and getting its text<br/><br/>Parses: `ab`, `aB` | Procedural:<br/><pre>val ab by regexToken("a[bB]")<br/>override val root by parser {<br/> val abMatch = ab()<br/> abMatch.text<br/>}</pre>Combinator:<br/><pre>val ab by regexToken("a[bB]")<br/>override val root by ab map { it.text }</pre> |
| Parsing two tokens sequentially<br/><br/>Parses: `ab`, `aB` | Procedural:<br/><pre>val a by literalToken("a")<br/>val b by regexToken("[bB]")<br/>override val root by parser {<br/> val aMatch = a()<br/> val bMatch = b()<br/> aMatch.text to bMatch.text<br/>}</pre>Combinator:<br/><pre>val a by literalToken("a")<br/>val b by regexToken("[bB]")<br/>override val root by a and b map<br/> { (aM, bM) -> aM.text to bM.text }</pre> |
| Parsing one of two tokens<br/><br/>Parses: `a`, `b`, `B` | Procedural:<br/><pre>val a by literalToken("a")<br/>val b by regexToken("[bB]")<br/>override val root by parser {<br/> val abMatch = choose(a, b)<br/> abMatch.text<br/>}</pre>Combinator:<br/><pre>val a by literalToken("a")<br/>val b by regexToken("[bB]")<br/>override val root by a or b map { it.text }</pre> |
| Parsing an optional token<br/><br/>Parses: `ab`, `aB`, `b`, `B` | Procedural:<br/><pre>val a by literalToken("a")<br/>val b by regexToken("[bB]")<br/>override val root by parser {<br/> val aMatch = poll(a)<br/> val bMatch = b()<br/> aMatch?.text to bMatch.text<br/>}</pre>Combinator:<br/><pre>val a by literalToken("a")<br/>val b by regexToken("[bB]")<br/>override val root by maybe(a) and b map<br/> { (aM, bM) -> aM?.text to bM.text }</pre> |
| Parsing a token and ignoring its value<br/><br/>Parses: `ab`, `aB` | Procedural:<br/><pre>val a by literalToken("a")<br/>val b by regexToken("[bB]")<br/>override val root by parser {<br/> skip(a) // or just a() without using the value<br/> val bMatch = b()<br/> bMatch.text<br/>}</pre>Combinator:<br/><pre>val a by literalToken("a")<br/>val b by regexToken("[bB]")<br/>override val root by -a * b map { it.text }</pre> |
| Parsing a token and getting its text&#13;&#13;Parses: `ab`, `aB` | Procedural:&#13;<pre lang="kotlin">val ab by regexToken("a[bB]")&#13;override val root by parser {&#13; val abMatch = ab()&#13; abMatch.text&#13;}</pre>Combinator:&#13;<pre lang="kotlin">val ab by regexToken("a[bB]")&#13;override val root by ab map { it.text }</pre> |
| Parsing two tokens sequentially&#13;&#13;Parses: `ab`, `aB` | Procedural:&#13;<pre lang="kotlin">val a by literalToken("a")&#13;val b by regexToken("[bB]")&#13;override val root by parser {&#13; val aMatch = a()&#13; val bMatch = b()&#13; aMatch.text to bMatch.text&#13;}</pre>Combinator:&#13;<pre lang="kotlin">val a by literalToken("a")&#13;val b by regexToken("[bB]")&#13;override val root by a and b map&#13; { (aM, bM) -> aM.text to bM.text }</pre> |
| Parsing one of two tokens&#13;&#13;Parses: `a`, `b`, `B` | Procedural:&#13;<pre lang="kotlin">val a by literalToken("a")&#13;val b by regexToken("[bB]")&#13;override val root by parser {&#13; val abMatch = choose(a, b)&#13; abMatch.text&#13;}</pre>Combinator:&#13;<pre lang="kotlin">val a by literalToken("a")&#13;val b by regexToken("[bB]")&#13;override val root by a or b map { it.text }</pre> |
| Parsing an optional token&#13;&#13;Parses: `ab`, `aB`, `b`, `B` | Procedural:&#13;<pre lang="kotlin">val a by literalToken("a")&#13;val b by regexToken("[bB]")&#13;override val root by parser {&#13; val aMatch = poll(a)&#13; val bMatch = b()&#13; aMatch?.text to bMatch.text&#13;}</pre>Combinator:&#13;<pre lang="kotlin">val a by literalToken("a")&#13;val b by regexToken("[bB]")&#13;override val root by maybe(a) and b map&#13; { (aM, bM) -> aM?.text to bM.text }</pre> |
| Parsing a token and ignoring its value&#13;&#13;Parses: `ab`, `aB` | Procedural:&#13;<pre lang="kotlin">val a by literalToken("a")&#13;val b by regexToken("[bB]")&#13;override val root by parser {&#13; skip(a) // or just a() without using the value&#13; val bMatch = b()&#13; bMatch.text&#13;}</pre>Combinator:&#13;<pre lang="kotlin">val a by literalToken("a")&#13;val b by regexToken("[bB]")&#13;override val root by -a * b map { it.text }</pre> |

## Introduction

Expand Down
10 changes: 5 additions & 5 deletions buildSrc/src/main/kotlin/GenerateQuickReferenceMarkdown.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ abstract class GenerateQuickReferenceMarkdown : DefaultTask() {
for (entry in entries) {
append("| ")
append(entry.description)
append("<br/>")
append("<br/>")
append("&#13;")
append("&#13;")
append("Parses: ")
append(entry.testCases.joinToString(", ") { "`$it`" })
append(" | ")
append("Procedural:<br/>")
append("Procedural:&#13;")
append(entry.proceduralGrammar.toMultilineMarkdownCodeBlock())
append("Combinator:<br/>")
append("Combinator:&#13;")
append(entry.combinatorGrammar.toMultilineMarkdownCodeBlock())
appendLine(" |")
}
Expand All @@ -42,7 +42,7 @@ abstract class GenerateQuickReferenceMarkdown : DefaultTask() {

private fun List<String>.toMultilineMarkdownCodeBlock(): String {
// TODO: syntax highlight
return joinToString("<br/>", prefix = "<pre>", postfix = "</pre>")
return joinToString("&#13;", prefix = "<pre lang=\"kotlin\">", postfix = "</pre>")
}

private data class QuickRefEntry(
Expand Down