| 385 | Option.flatMap(self(stream), ([a, s1]) => f(a)(s1)) |
| 386 | |
| 387 | function many<S, A>(parser: DocTreeParser<S, A>): DocTreeParser<S, ReadonlyArray<A>> { |
| 388 | return (stream) => |
| 389 | pipe( |
| 390 | parser(stream), |
| 391 | Option.map(([head, next]) => { |
| 392 | const output: Array<A> = [head] |
| 393 | let input: S = next |
| 394 | let result = parser(next) |
| 395 | while (result._tag === "Some") { |
| 396 | const [value, nextInput] = result.value |
| 397 | output.push(value) |
| 398 | input = nextInput |
| 399 | result = parser(nextInput) |
| 400 | } |
| 401 | return [output, input] as const |
| 402 | }) |
| 403 | ) |
| 404 | } |
| 405 | |
| 406 | const nextToken = <A>(): DocTreeParser<DocStream.DocStream<A>, docTreeToken.DocTreeToken<A>> => { |
| 407 | return (stream) => { |