Add custom error setter
This commit is contained in:
@@ -320,12 +320,22 @@ proc `+`*(parserFnA: Parser -> ParserResult, parserFnB: Parser -> ParserResult):
|
|||||||
return proc(parser: Parser): ParserResult =
|
return proc(parser: Parser): ParserResult =
|
||||||
parserFnA(parser).flatMap(parserFnB)
|
parserFnA(parser).flatMap(parserFnB)
|
||||||
|
|
||||||
|
proc setErrorExpectedField(err: ParserError, expected: string): ParserError =
|
||||||
|
ParserError(
|
||||||
|
kind: err.kind,
|
||||||
|
unexpected: err.unexpected,
|
||||||
|
expected: expected,
|
||||||
|
index: err.index,
|
||||||
|
parser: err.parser,
|
||||||
|
)
|
||||||
|
|
||||||
let newlineParser = choice(@[
|
let newlineParser = choice(@[
|
||||||
ch(NewLines),
|
ch(NewLines),
|
||||||
endOfStream,
|
endOfStream,
|
||||||
])
|
])
|
||||||
proc newline*(parser: Parser): ParserResult = newlineParser(parser)
|
proc newline*(parser: Parser): ParserResult =
|
||||||
|
newlineParser(parser)
|
||||||
|
.mapErr((x: ParserError) => x.setErrorExpectedField("Newline"))
|
||||||
|
|
||||||
proc parseSeq*(parser: ParserResult, xs: seq[Parser -> ParserResult]): ParserResult =
|
proc parseSeq*(parser: ParserResult, xs: seq[Parser -> ParserResult]): ParserResult =
|
||||||
xs.foldl(a.flatMap(b), parser)
|
xs.foldl(a.flatMap(b), parser)
|
||||||
|
|||||||
Reference in New Issue
Block a user