Yes
This commit is contained in:
15
src/test.nim
15
src/test.nim
@@ -2,6 +2,7 @@ import std/options
|
|||||||
import std/strutils
|
import std/strutils
|
||||||
import std/strformat
|
import std/strformat
|
||||||
import std/collections/sequtils
|
import std/collections/sequtils
|
||||||
|
import std/sugar
|
||||||
import results
|
import results
|
||||||
import fusion/matching
|
import fusion/matching
|
||||||
import fp/maybe
|
import fp/maybe
|
||||||
@@ -35,7 +36,7 @@ type
|
|||||||
|
|
||||||
proc indentKey(x: string, count: int): string =
|
proc indentKey(x: string, count: int): string =
|
||||||
var y = x.indent(count)
|
var y = x.indent(count)
|
||||||
y.delete(0, count - 1)
|
y.delete(0..count - 1)
|
||||||
y
|
y
|
||||||
|
|
||||||
proc `$`*(x: Token): string =
|
proc `$`*(x: Token): string =
|
||||||
@@ -45,15 +46,15 @@ proc `$`*(x: Token): string =
|
|||||||
|
|
||||||
proc `$`*(x: ParserState): string =
|
proc `$`*(x: ParserState): string =
|
||||||
&"""ParserState(
|
&"""ParserState(
|
||||||
stream: {x.stream},
|
stream: "{x.stream}",
|
||||||
position: {x.position},
|
position: {x.position},
|
||||||
lastPosition: {x.lastPosition},
|
lastPosition: {x.lastPosition},
|
||||||
)"""
|
)"""
|
||||||
|
|
||||||
proc `$`*(x: Parser): string =
|
proc `$`*(x: Parser): string =
|
||||||
&"""Parser(
|
&"""Parser(
|
||||||
state: {indentKey($x.state, 4)},
|
state: {indentKey($x.state, 2)},
|
||||||
tokens: {x.tokens}
|
tokens: {indentKey($x.tokens, 2)},
|
||||||
)"""
|
)"""
|
||||||
|
|
||||||
proc initParser(str: string): ParserResult =
|
proc initParser(str: string): ParserResult =
|
||||||
@@ -79,13 +80,17 @@ proc ch(parser: Parser, c: char): ParserResult =
|
|||||||
tokens: parser.tokens & Token(value: c)
|
tokens: parser.tokens & Token(value: c)
|
||||||
).ok()
|
).ok()
|
||||||
else:
|
else:
|
||||||
err((parser, "Foo"))
|
err((parser, &"Expected {c}"))
|
||||||
|
|
||||||
# type R = Result[int, string]
|
# type R = Result[int, string]
|
||||||
|
|
||||||
# echo R.ok 4
|
# echo R.ok 4
|
||||||
|
|
||||||
|
|
||||||
echo initParser("Foo")
|
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
|
# proc parseStars
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user