diff --git a/src/parser/parser.nim b/src/parser/parser.nim index aefa906..10dc27d 100644 --- a/src/parser/parser.nim +++ b/src/parser/parser.nim @@ -251,6 +251,10 @@ func choice*(parsers: seq[Parser -> ParserResult]): (Parser -> ParserResult) {.i proc(x: ParserResult): ParserResult = x, ) +proc `+`*(parserFnA: Parser -> ParserResult, parserFnB: Parser -> ParserResult): (Parser -> ParserResult) {.inline.} = + ## Parse characters and ignore failure + return proc(parser: Parser): ParserResult = + parserFnA(parser).flatMap(parserFnB) proc parseSeq*(parser: ParserResult, xs: seq[Parser -> ParserResult]): ParserResult = xs.foldl(a.flatMap(b), parser) @@ -325,3 +329,10 @@ when isMainModule: echo initParserResult("_ABC").parseSeq(optionalPrefixParser) echo initParserResult("ABC").parseSeq(optionalPrefixParser) + + let andParsers = @[ + (ch('A') + ch('B')), + ch('C'), + ] + + echo initParserResult("ABC").parseSeq(andParsers)