From f77b36f3d49f974833dc1b9c4dafb3c3fd1562d7 Mon Sep 17 00:00:00 2001 From: Adam <897017+aSemy@users.noreply.github.com> Date: Sun, 7 Jan 2024 11:22:48 +0100 Subject: [PATCH 1/2] add code highlighting in README add `lang="kotlin"` and replace `
` with HTML escape char for newlines. --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 52736ff..c6792d1 100644 --- a/README.md +++ b/README.md @@ -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

Parses: `ab`, `aB` | Procedural:
val ab by regexToken("a[bB]")
override val root by parser {
val abMatch = ab()
abMatch.text
}
Combinator:
val ab by regexToken("a[bB]")
override val root by ab map { it.text }
| -| Parsing two tokens sequentially

Parses: `ab`, `aB` | Procedural:
val a by literalToken("a")
val b by regexToken("[bB]")
override val root by parser {
val aMatch = a()
val bMatch = b()
aMatch.text to bMatch.text
}
Combinator:
val a by literalToken("a")
val b by regexToken("[bB]")
override val root by a and b map
{ (aM, bM) -> aM.text to bM.text }
| -| Parsing one of two tokens

Parses: `a`, `b`, `B` | Procedural:
val a by literalToken("a")
val b by regexToken("[bB]")
override val root by parser {
val abMatch = choose(a, b)
abMatch.text
}
Combinator:
val a by literalToken("a")
val b by regexToken("[bB]")
override val root by a or b map { it.text }
| -| Parsing an optional token

Parses: `ab`, `aB`, `b`, `B` | Procedural:
val a by literalToken("a")
val b by regexToken("[bB]")
override val root by parser {
val aMatch = poll(a)
val bMatch = b()
aMatch?.text to bMatch.text
}
Combinator:
val a by literalToken("a")
val b by regexToken("[bB]")
override val root by maybe(a) and b map
{ (aM, bM) -> aM?.text to bM.text }
| -| Parsing a token and ignoring its value

Parses: `ab`, `aB` | Procedural:
val a by literalToken("a")
val b by regexToken("[bB]")
override val root by parser {
skip(a) // or just a() without using the value
val bMatch = b()
bMatch.text
}
Combinator:
val a by literalToken("a")
val b by regexToken("[bB]")
override val root by -a * b map { it.text }
| +| Parsing a token and getting its text Parses: `ab`, `aB` | Procedural:
val ab by regexToken("a[bB]")
override val root by parser {
    val abMatch = ab()
    abMatch.text
}
Combinator:
val ab by regexToken("a[bB]")
override val root by ab map { it.text }
| +| Parsing two tokens sequentially Parses: `ab`, `aB` | Procedural:
val a by literalToken("a")
val b by regexToken("[bB]")
override val root by parser {
    val aMatch = a()
    val bMatch = b()
    aMatch.text to bMatch.text
}
Combinator:
val a by literalToken("a")
val b by regexToken("[bB]")
override val root by a and b map
    { (aM, bM) -> aM.text to bM.text }
| +| Parsing one of two tokens Parses: `a`, `b`, `B` | Procedural:
val a by literalToken("a")
val b by regexToken("[bB]")
override val root by parser {
    val abMatch = choose(a, b)
    abMatch.text
}
Combinator:
val a by literalToken("a")
val b by regexToken("[bB]")
override val root by a or b map { it.text }
| +| Parsing an optional token Parses: `ab`, `aB`, `b`, `B` | Procedural:
val a by literalToken("a")
val b by regexToken("[bB]")
override val root by parser {
    val aMatch = poll(a)
    val bMatch = b()
    aMatch?.text to bMatch.text
}
Combinator:
val a by literalToken("a")
val b by regexToken("[bB]")
override val root by maybe(a) and b map
    { (aM, bM) -> aM?.text to bM.text }
| +| Parsing a token and ignoring its value Parses: `ab`, `aB` | Procedural:
val a by literalToken("a")
val b by regexToken("[bB]")
override val root by parser {
    skip(a) // or just a() without using the value
    val bMatch = b()
    bMatch.text
}
Combinator:
val a by literalToken("a")
val b by regexToken("[bB]")
override val root by -a * b map { it.text }
| ## Introduction From 77a0951042ddbd75bd425f5cb326be9a94a67776 Mon Sep 17 00:00:00 2001 From: Alex Semin Date: Mon, 15 Jan 2024 22:30:51 +0800 Subject: [PATCH 2/2] Update reference generation --- .../src/main/kotlin/GenerateQuickReferenceMarkdown.kt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/buildSrc/src/main/kotlin/GenerateQuickReferenceMarkdown.kt b/buildSrc/src/main/kotlin/GenerateQuickReferenceMarkdown.kt index 9afc428..64361f3 100644 --- a/buildSrc/src/main/kotlin/GenerateQuickReferenceMarkdown.kt +++ b/buildSrc/src/main/kotlin/GenerateQuickReferenceMarkdown.kt @@ -26,14 +26,14 @@ abstract class GenerateQuickReferenceMarkdown : DefaultTask() { for (entry in entries) { append("| ") append(entry.description) - append("
") - append("
") + append(" ") + append(" ") append("Parses: ") append(entry.testCases.joinToString(", ") { "`$it`" }) append(" | ") - append("Procedural:
") + append("Procedural: ") append(entry.proceduralGrammar.toMultilineMarkdownCodeBlock()) - append("Combinator:
") + append("Combinator: ") append(entry.combinatorGrammar.toMultilineMarkdownCodeBlock()) appendLine(" |") } @@ -42,7 +42,7 @@ abstract class GenerateQuickReferenceMarkdown : DefaultTask() { private fun List.toMultilineMarkdownCodeBlock(): String { // TODO: syntax highlight - return joinToString("
", prefix = "
", postfix = "
") + return joinToString(" ", prefix = "
", postfix = "
") } private data class QuickRefEntry(