Document & Test optional
This commit is contained in:
@@ -114,7 +114,9 @@ proc str*(expectedString: string): parserFnT {.inline.} =
|
||||
# -- Parsing API
|
||||
|
||||
proc optional*(parserFn: parserFnT): parserFnT {.inline.} =
|
||||
## Create a
|
||||
## Creates parser function with a nested `parserFn`.
|
||||
## Continue on succesful parser
|
||||
## Ignores failing parsers
|
||||
return proc(parser: Parser): ParserResult =
|
||||
let newParser = parserFn(parser)
|
||||
|
||||
@@ -271,3 +273,8 @@ when isMainModule:
|
||||
assert initParserResult("12").flatMap(ch1).isStreamCompleted() == false
|
||||
assert initParserResult("").flatMap(ch1).isStreamCompleted() == false
|
||||
assert testParser123.flatMap(str("123")).isStreamCompleted() == true
|
||||
|
||||
block testParsingApi:
|
||||
# Optional
|
||||
assert testParser123.flatMap(optional(ch('1'))).tokensToString() == "1"
|
||||
assert testParser123.flatMap(optional(ch('2'))).tokensToString() == ""
|
||||
|
||||
Reference in New Issue
Block a user