| 404 | } |
| 405 | |
| 406 | const nextToken = <A>(): DocTreeParser<DocStream.DocStream<A>, docTreeToken.DocTreeToken<A>> => { |
| 407 | return (stream) => { |
| 408 | switch (stream._tag) { |
| 409 | case "FailedStream": { |
| 410 | throw new Error( |
| 411 | "BUG: DocTree.treeForm - found failed doc stream while parsing" + |
| 412 | " - please report an issue at https://github.com/Effect-TS/printer/issues" |
| 413 | ) |
| 414 | } |
| 415 | case "EmptyStream": { |
| 416 | return Option.none() |
| 417 | } |
| 418 | case "CharStream": { |
| 419 | return Option.some([docTreeToken.char(stream.char), stream.stream] as const) |
| 420 | } |
| 421 | case "TextStream": { |
| 422 | return Option.some([docTreeToken.text(stream.text), stream.stream] as const) |
| 423 | } |
| 424 | case "LineStream": { |
| 425 | return Option.some([docTreeToken.line(stream.indentation), stream.stream] as const) |
| 426 | } |
| 427 | case "PushAnnotationStream": { |
| 428 | return Option.some( |
| 429 | [ |
| 430 | docTreeToken.pushAnnotation(stream.annotation), |
| 431 | stream.stream |
| 432 | ] as const |
| 433 | ) |
| 434 | } |
| 435 | case "PopAnnotationStream": { |
| 436 | return Option.some([docTreeToken.popAnnotation, stream.stream]) |
| 437 | } |
| 438 | } |
| 439 | } |
| 440 | } |
| 441 | |
| 442 | const mergeTrees = <A>(trees: ReadonlyArray<DocTree.DocTree<A>>): DocTree.DocTree<A> => { |
| 443 | if (trees.length === 0) { |