diff --git a/src_v2/parser/parser_internals.nim b/src_v2/parser/parser_internals.nim index cab6997..4839849 100644 --- a/src_v2/parser/parser_internals.nim +++ b/src_v2/parser/parser_internals.nim @@ -114,19 +114,19 @@ proc str*(expectedString: string): parserFnT {.inline.} = # -- Parsing API proc optional*(parserFn: parserFnT): parserFnT {.inline.} = - ## Creates parser function with a nested `parserFn`. - ## Continue on succesful parser + ## Creates parser function with a nested `parserFn`: + ## Continues on succesful parser ## Ignores failing parsers return proc(parser: Parser): ParserResult = let newParser = parserFn(parser) - if newParser.isOk(): newParser else: parser.ok() proc ignore*(parserFn: parserFnT): parserFnT {.inline.} = - ## Parse characters but throw success tokens away + ## Creates parser function with a nested `parserFn`: + ## Parses using the `parserFn` but dont capture the resulting tokens. return proc(parser: Parser): ParserResult = return parserFn(parser) .map((x: Parser) => Parser( @@ -278,3 +278,6 @@ when isMainModule: # Optional assert testParser123.flatMap(optional(ch('1'))).tokensToString() == "1" assert testParser123.flatMap(optional(ch('2'))).tokensToString() == "" + + # Ignore + assert testParser123.flatMap(ignore(ch('1'))).tokensToString() == ""