Add starOfStream function
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user