Skip to content

Commit

Permalink
Merge pull request #27 from aSemy/patch-1
Browse files Browse the repository at this point in the history
add code highlighting in README table
  • Loading branch information
alllex committed Jan 15, 2024
2 parents d12fa51 + 77a0951 commit 687f6bf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
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

0 comments on commit 687f6bf

Please sign in to comment.