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] 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