diff --git a/lib/src/main/kotlin/konnik/json/JsonParser.kt b/lib/src/main/kotlin/konnik/json/JsonParser.kt
index 3c9813f..8be48d1 100644
--- a/lib/src/main/kotlin/konnik/json/JsonParser.kt
+++ b/lib/src/main/kotlin/konnik/json/JsonParser.kt
@@ -26,11 +26,11 @@ sealed interface JsonValue {
*/
fun parseJson(input: String): JsonValue? =
when (val result = json(input)) {
- null -> null
- else -> when (result.second) {
- "" -> result.first
- else -> null // it's an error if not all input is consumed
- }
+ null -> null
+ else -> when (result.second) {
+ "" -> result.first
+ else -> null // it's an error if not all input is consumed
+ }
}
@@ -42,13 +42,11 @@ fun parseJson(input: String): JsonValue? =
*/
/**
- * Data type representing a parser that parses a some input string and produces
- * a value of type A.
- *
- * If the parser succeeds the parsed value is returned together with the remainder of the input
- * that has not been consumed.
+ * Type that defines what a parser is.
*
- * If the parser fails null is returned.
+ * A parser is a function that takes some input (String) as it's argument and
+ * if it succeeds returns a value of type A (together with de remaining input),
+ * otherwise it returns null.
*
*/
private typealias Parser = (String) -> Pair?
@@ -56,7 +54,7 @@ private typealias Parser = (String) -> Pair?
/* ----------------------------------------------------------------------------
*
- * COMBINATORS
+ * COMBINATOR FUNCTIONS
*
* ----------------------------------------------------------------------------
*/
@@ -129,7 +127,7 @@ private fun lazy(parser: () -> Parser): Parser = { input ->
* Combine to parsers into one that concatenates the results of the
* individual parsers into one string.
*/
-private operator fun Parser.plus(parserB: Parser): Parser =
+private operator fun Parser.plus(parserB: Parser): Parser =
this.andThen { valueA -> parserB.map { valueB -> valueA.toString() + valueB.toString() } }
@@ -163,7 +161,6 @@ private fun match(test: (Char) -> Boolean): Parser = { input ->
}
-
/* ------------------------------------------------------------------------------------------
* GRAMMAR
*