diff --git a/README.md b/README.md index 0a21ecb..89b4603 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 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(