From 7cfa4ae31d95c31e34e71bd2d2cc2cb74cfd8631 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Thu, 20 Jan 2022 17:00:00 +0100 Subject: [PATCH] Yes --- src/test.nim | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/test.nim b/src/test.nim index f48266a..7aeaf2f 100644 --- a/src/test.nim +++ b/src/test.nim @@ -2,6 +2,7 @@ import std/options import std/strutils import std/strformat import std/collections/sequtils +import std/sugar import results import fusion/matching import fp/maybe @@ -35,26 +36,26 @@ type proc indentKey(x: string, count: int): string = var y = x.indent(count) - y.delete(0, count - 1) + y.delete(0..count - 1) y proc `$`*(x: Token): string = &"""Token( - value: {x.value}, + value: {x.value}, )""" proc `$`*(x: ParserState): string = &"""ParserState( - stream: {x.stream}, - position: {x.position}, - lastPosition: {x.lastPosition}, + stream: "{x.stream}", + position: {x.position}, + lastPosition: {x.lastPosition}, )""" proc `$`*(x: Parser): string = &"""Parser( - state: {indentKey($x.state, 4)}, - tokens: {x.tokens} - )""" + state: {indentKey($x.state, 2)}, + tokens: {indentKey($x.tokens, 2)}, +)""" proc initParser(str: string): ParserResult = Parser( @@ -79,13 +80,17 @@ proc ch(parser: Parser, c: char): ParserResult = tokens: parser.tokens & Token(value: c) ).ok() else: - err((parser, "Foo")) + err((parser, &"Expected {c}")) # type R = Result[int, string] # echo R.ok 4 + echo initParser("Foo") + .flatMap((x: Parser) => ch(x, c = 'F')) + .flatMap((x: Parser) => ch(x, c = 'o')) + .flatMap((x: Parser) => ch(x, c = 'o')) # proc parseStars