From 26f8baacfb8b7d70ec18bbdeb49a411a11ef1c29 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Fri, 26 Aug 2022 16:42:05 +0200 Subject: [PATCH] Add ignore tests --- src_v2/parser/parser_internals.nim | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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() == ""