@taml/ast
Version:
Abstract Syntax Tree types and utilities for TAML (Terminal ANSI Markup Language)
86 lines • 2.76 kB
TypeScript
/**
* Tree traversal utilities for TAML AST
*/
import type { ElementNode, TamlNode, TextNode } from "./nodes.js";
import type { TamlTag } from "./types.js";
/**
* Walk through all nodes in the tree (depth-first, pre-order)
*/
export declare function walk(node: TamlNode, callback: (node: TamlNode) => void): void;
/**
* Walk through all nodes asynchronously
*/
export declare function walkAsync(node: TamlNode, callback: (node: TamlNode) => Promise<void>): Promise<void>;
/**
* Find all nodes that match a predicate
*/
export declare function findAll(root: TamlNode, predicate: (node: TamlNode) => boolean): TamlNode[];
/**
* Find the first node that matches a predicate
*/
export declare function findFirst(root: TamlNode, predicate: (node: TamlNode) => boolean): TamlNode | null;
/**
* Filter nodes by predicate (alias for findAll)
*/
export declare function filter(root: TamlNode, predicate: (node: TamlNode) => boolean): TamlNode[];
/**
* Get all text content from a node and its descendants
*/
export declare function getAllText(root: TamlNode): string;
/**
* Get all element nodes with a specific tag name
*/
export declare function getElementsWithTag(root: TamlNode, tagName: TamlTag): ElementNode[];
/**
* Get all text nodes
*/
export declare function getTextNodes(root: TamlNode): TextNode[];
/**
* Get all element nodes
*/
export declare function getElementNodes(root: TamlNode): ElementNode[];
/**
* Check if a node contains another node
*/
export declare function contains(ancestor: TamlNode, descendant: TamlNode): boolean;
/**
* Get the common ancestor of two nodes
*/
export declare function getCommonAncestor(node1: TamlNode, node2: TamlNode): TamlNode | null;
/**
* Get siblings of a node (nodes with the same parent)
*/
export declare function getSiblings(node: TamlNode): TamlNode[];
/**
* Get the previous sibling of a node
*/
export declare function getPreviousSibling(node: TamlNode): TamlNode | null;
/**
* Get the next sibling of a node
*/
export declare function getNextSibling(node: TamlNode): TamlNode | null;
/**
* Check if a node is empty (has no children or only empty text)
*/
export declare function isEmpty(node: TamlNode): boolean;
/**
* Count nodes by type
*/
export declare function countNodes(root: TamlNode): {
document: number;
element: number;
text: number;
};
/**
* Get the maximum depth of the tree
*/
export declare function getMaxDepth(root: TamlNode): number;
/**
* Flatten the tree into an array of nodes (depth-first order)
*/
export declare function flatten(root: TamlNode): TamlNode[];
/**
* Create a map from node to its depth in the tree
*/
export declare function createDepthMap(root: TamlNode): Map<TamlNode, number>;
//# sourceMappingURL=traversal.d.ts.map