diff --git a/src_v2/parser/parser_internals.nim b/src_v2/parser/parser_internals.nim index 3eafe14..1e355ac 100644 --- a/src_v2/parser/parser_internals.nim +++ b/src_v2/parser/parser_internals.nim @@ -189,8 +189,11 @@ proc choice*(parserFns: seq[parserFnT]): parserFnT {.inline} = proc(x: ParserResult): ParserResult = x, ) -proc parseSeq*(parser: ParserResult, xs: seq[parserFnT]): ParserResult {.inline.} = - xs.foldl(a.flatMap(b), parser) +proc following*(parserFns: seq[parserFnT]): parserFnT {.inline.} = + ## Checks a sequence of `parserFns`. + ## All of them need to be `ParserResult.ok` + return proc(parser: Parser): ParserResult {.closure.} = + parserFns.foldl(a.flatMap(b), parser.ok) # -- Parsing Aliases @@ -282,3 +285,6 @@ when isMainModule: # choice assert testAbc1Parser.flatMap(choice(@[digit, ch('a')])).tokensToString() == "a" assert testAbc1Parser.flatMap(choice(@[digit])).error().kind == choiceMismatchErr + + # parse + assert testAbc1Parser.flatMap(following(@[ch('a'), str("bc"), digit])).tokensToString() == "abc1"