Yes
This commit is contained in:
23
src/test.nim
23
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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user