/** * @since 1.0.0 */ import type * as covariant from "@effect/typeclass/Covariant"; import type * as invariant from "@effect/typeclass/Invariant"; import type * as monoid from "@effect/typeclass/Monoid"; import type * as semigroup from "@effect/typeclass/Semigroup"; import type { Equal } from "effect/Equal"; import type { TypeLambda } from "effect/HKT"; import type * as DocStream from "./DocStream.js"; /** * @since 1.0.0 * @category symbol */ export declare const DocTreeTypeId: unique symbol; /** * @since 1.0.0 * @category symbol */ export type DocTreeTypeId = typeof DocTreeTypeId; /** * Represents a document that has been laid out into a tree-like structure. * * A `DocStream` is a linked list of different annotated cons cells (i.e. * `TextStream` and then some further `DocStream`, `LineStream` and then some * further `DocStream`, etc.). The `DocStream` format is quite suitable as a * target for a layout engine, but is not suitable for rendering to a more * structured format, such as HTML, where we do not want to perform a lookahead * until the end of some pre-defined markup. These formats would benefit more * from a tree-like structure that explicitly marks its contents as annotated. * A `DocTree` is therefore much more suitable for this use case. * * @since 1.0.0 * @category model */ export type DocTree = EmptyTree | CharTree | TextTree | LineTree | AnnotationTree | ConcatTree; /** * @since 1.0.0 */ export declare namespace DocTree { /** * @since 1.0.0 */ interface Variance extends Equal { readonly [DocTreeTypeId]: { readonly _A: (_: never) => A; }; } /** * @since 1.0.0 */ type TypeLambda = DocTreeTypeLambda; } /** * @since 1.0.0 * @category model */ export interface DocTreeTypeLambda extends TypeLambda { readonly type: DocTree; } /** * @since 1.0.0 * @category model */ export interface EmptyTree extends DocTree.Variance { readonly _tag: "EmptyTree"; } /** * @since 1.0.0 * @category model */ export interface CharTree extends DocTree.Variance { readonly _tag: "CharTree"; readonly char: string; } /** * @since 1.0.0 * @category model */ export interface TextTree extends DocTree.Variance { readonly _tag: "TextTree"; readonly text: string; } /** * @since 1.0.0 * @category model */ export interface LineTree extends DocTree.Variance { readonly _tag: "LineTree"; readonly indentation: number; } /** * @since 1.0.0 * @category model */ export interface AnnotationTree extends DocTree.Variance { readonly _tag: "AnnotationTree"; readonly annotation: A; readonly tree: DocTree; } /** * @since 1.0.0 * @category model */ export interface ConcatTree extends DocTree.Variance { readonly _tag: "ConcatTree"; readonly trees: ReadonlyArray>; } /** * Returns `true` if the specified value is a `DocTree`, `false` otherwise. * * @since 1.0.0 * @category refinements */ export declare const isDocTree: (u: unknown) => u is DocTree; /** * Returns `true` if the specified `DocTree` is an `EmptyTree`, `false` otherwise. * * @since 1.0.0 * @category refinements */ export declare const isEmptyTree: (self: DocTree) => self is EmptyTree; /** * Returns `true` if the specified `DocTree` is an `CharTree`, `false` otherwise. * * @since 1.0.0 * @category refinements */ export declare const isCharTree: (self: DocTree) => self is CharTree; /** * Returns `true` if the specified `DocTree` is an `TextTree`, `false` otherwise. * * @since 1.0.0 * @category refinements */ export declare const isTextTree: (self: DocTree) => self is TextTree; /** * Returns `true` if the specified `DocTree` is an `LineTree`, `false` otherwise. * * @since 1.0.0 * @category refinements */ export declare const isLineTree: (self: DocTree) => self is LineTree; /** * Returns `true` if the specified `DocTree` is an `AnnotationTree`, `false` otherwise. * * @since 1.0.0 * @category refinements */ export declare const isAnnotationTree: (self: DocTree) => self is AnnotationTree; /** * Returns `true` if the specified `DocTree` is an `ConcatTree`, `false` otherwise. * * @since 1.0.0 * @category refinements */ export declare const isConcatTree: (self: DocTree) => self is ConcatTree; /** * @since 1.0.0 * @category constructors */ export declare const empty: DocTree; /** * @since 1.0.0 * @category constructors */ export declare const char: (char: string) => DocTree; /** * @since 1.0.0 * @category constructors */ export declare const text: (text: string) => DocTree; /** * @since 1.0.0 * @category constructors */ export declare const line: (indentation: number) => DocTree; /** * Annotate the specified `DocTree` with an annotation of type `A`. * * @since 1.0.0 * @category constructors */ export declare const annotation: { /** * Annotate the specified `DocTree` with an annotation of type `A`. * * @since 1.0.0 * @category constructors */ (annotation: A): (self: DocTree) => DocTree; /** * Annotate the specified `DocTree` with an annotation of type `A`. * * @since 1.0.0 * @category constructors */ (self: DocTree, annotation: B): DocTree; }; /** * Horizontally concatenates multiple `DocTree`s. * * @since 1.0.0 * @category constructors */ export declare const concat: (trees: ReadonlyArray>) => DocTree; /** * Change the annotation of a document to a different annotation, or none at * all. * * @since 1.0.0 * @category annotations */ export declare const alterAnnotations: { /** * Change the annotation of a document to a different annotation, or none at * all. * * @since 1.0.0 * @category annotations */ (f: (a: A) => Iterable): (self: DocTree) => DocTree; /** * Change the annotation of a document to a different annotation, or none at * all. * * @since 1.0.0 * @category annotations */ (self: DocTree, f: (a: A) => Iterable): DocTree; }; /** * Change the annotation of a `DocTree`. * * @since 1.0.0 * @category annotations */ export declare const reAnnotate: { /** * Change the annotation of a `DocTree`. * * @since 1.0.0 * @category annotations */ (f: (a: A) => B): (self: DocTree) => DocTree; /** * Change the annotation of a `DocTree`. * * @since 1.0.0 * @category annotations */ (self: DocTree, f: (a: A) => B): DocTree; }; /** * Remove all annotations from a `DocTree`. * * @since 1.0.0 * @category annotations */ export declare const unAnnotate: (self: DocTree) => DocTree; /** * @since 1.0.0 * @category folding */ export declare const foldMap: { /** * @since 1.0.0 * @category folding */ (M: monoid.Monoid, f: (a: A) => M): (self: DocTree) => M; /** * @since 1.0.0 * @category folding */ (self: DocTree, M: monoid.Monoid, f: (a: A) => M): M; }; /** * The simplest possible tree-based renderer. * * For example, here is a document annotated with `void` and thee behavior is * to surround annotated regions with »>>>« and »<<<«. * * @example * ```ts * import * as assert from "node:assert" * import * as Doc from "@effect/printer/Doc" * import * as DocTree from "@effect/printer/DocTree" * import * as Layout from "@effect/printer/Layout" * import { identity, pipe } from "effect/Function" * import * as String from "@effect/typeclass/data/String" * * const doc: Doc.Doc = Doc.hsep([ * Doc.text("hello"), * pipe( * Doc.text("world"), * Doc.annotate(undefined), * Doc.cat(Doc.char("!")) * ) * ]) * * const tree = DocTree.treeForm(Layout.pretty(Layout.defaultOptions)(doc)) * * const rendered = pipe( * tree, * DocTree.renderSimplyDecorated(String.Monoid, identity, (_, x) => `>>>${x}<<<`) * ) * * assert.strictEqual( * rendered, * "hello >>>world<<>>« and »<<<«. * * @example * ```ts * import * as assert from "node:assert" * import * as Doc from "@effect/printer/Doc" * import * as DocTree from "@effect/printer/DocTree" * import * as Layout from "@effect/printer/Layout" * import { identity, pipe } from "effect/Function" * import * as String from "@effect/typeclass/data/String" * * const doc: Doc.Doc = Doc.hsep([ * Doc.text("hello"), * pipe( * Doc.text("world"), * Doc.annotate(undefined), * Doc.cat(Doc.char("!")) * ) * ]) * * const tree = DocTree.treeForm(Layout.pretty(Layout.defaultOptions)(doc)) * * const rendered = pipe( * tree, * DocTree.renderSimplyDecorated(String.Monoid, identity, (_, x) => `>>>${x}<<<`) * ) * * assert.strictEqual( * rendered, * "hello >>>world<<(M: monoid.Monoid, renderText: (text: string) => M, renderAnnotation: (annotation: A, out: M) => M): (self: DocTree) => M; /** * The simplest possible tree-based renderer. * * For example, here is a document annotated with `void` and thee behavior is * to surround annotated regions with »>>>« and »<<<«. * * @example * ```ts * import * as assert from "node:assert" * import * as Doc from "@effect/printer/Doc" * import * as DocTree from "@effect/printer/DocTree" * import * as Layout from "@effect/printer/Layout" * import { identity, pipe } from "effect/Function" * import * as String from "@effect/typeclass/data/String" * * const doc: Doc.Doc = Doc.hsep([ * Doc.text("hello"), * pipe( * Doc.text("world"), * Doc.annotate(undefined), * Doc.cat(Doc.char("!")) * ) * ]) * * const tree = DocTree.treeForm(Layout.pretty(Layout.defaultOptions)(doc)) * * const rendered = pipe( * tree, * DocTree.renderSimplyDecorated(String.Monoid, identity, (_, x) => `>>>${x}<<<`) * ) * * assert.strictEqual( * rendered, * "hello >>>world<<(self: DocTree, M: monoid.Monoid, renderText: (text: string) => M, renderAnnotation: (annotation: A, out: M) => M): M; }; /** * Converts a `DocStream` into a `DocTree`. * * @since 1.0.0 * @category conversions */ export declare const treeForm: (stream: DocStream.DocStream) => DocTree; /** * @since 1.0.0 * @category instances */ export declare const getSemigroup: (_: void) => semigroup.Semigroup>; /** * @since 1.0.0 * @category instances */ export declare const getMonoid: (_: void) => monoid.Monoid>; /** * @since 1.0.0 * @category instances */ export declare const Covariant: covariant.Covariant; /** * @since 1.0.0 * @category instances */ export declare const Invariant: invariant.Invariant; //# sourceMappingURL=DocTree.d.ts.map