Add starOfStream function

This commit is contained in:
Florian Schroedl
2022-08-28 18:19:42 +02:00
parent 0cf8f6791d
commit bc7525e353
2 changed files with 25 additions and 0 deletions

View File

@@ -112,6 +112,21 @@ proc str*(expectedString: string): parserFnT {.inline.} =
res = res.flatMap(ch(c))
return res
proc startOfStream*(parser: Parser): ParserResult =
## Check if the following character is the end of the stream.
## Errors when the end of stream was already reached.
let position = parser.state.position
if position == 0 or position == -1:
ok(parser)
else:
err(ParserError(
kind: startOfStringErr,
expected: "startOfStream",
index: position,
parser: parser,
))
proc endOfStream*(parser: Parser): ParserResult =
## Check if the following character is the end of the stream.
## Errors when the end of stream was already reached.