UNPKG

@taml/ast

Version:

Abstract Syntax Tree types and utilities for TAML (Terminal ANSI Markup Language)

92 lines 2.75 kB
/** * AST node interfaces and factory functions for TAML */ import type { NodeType, TamlTag } from "./types.js"; /** * Base interface for all AST nodes */ export interface TamlNode { /** Node type discriminator */ type: NodeType; /** Start position in source text (0-based) */ start: number; /** End position in source text (0-based) */ end: number; /** Parent node reference (undefined for root) */ parent?: TamlNode | undefined; } /** * Document root node containing all top-level nodes */ export interface DocumentNode extends TamlNode { type: "document"; children: TamlNode[]; } /** * Element node representing a TAML tag with children */ export interface ElementNode extends TamlNode { type: "element"; tagName: TamlTag; children: TamlNode[]; } /** * Text node containing plain text content */ export interface TextNode extends TamlNode { type: "text"; content: string; } /** * Type guard to check if a node is a DocumentNode */ export declare function isDocumentNode(node: TamlNode): node is DocumentNode; /** * Type guard to check if a node is an ElementNode */ export declare function isElementNode(node: TamlNode): node is ElementNode; /** * Type guard to check if a node is a TextNode */ export declare function isTextNode(node: TamlNode): node is TextNode; /** * Factory function to create a document node */ export declare function createDocument(children?: TamlNode[], start?: number, end?: number): DocumentNode; /** * Factory function to create an element node */ export declare function createElement(tagName: TamlTag, children?: TamlNode[], start?: number, end?: number): ElementNode; /** * Factory function to create a text node */ export declare function createText(content: string, start?: number, end?: number): TextNode; /** * Add a child node to a parent node (document or element) */ export declare function appendChild(parent: DocumentNode | ElementNode, child: TamlNode): void; /** * Remove a child node from its parent */ export declare function removeChild(child: TamlNode): void; /** * Replace a child node with a new node */ export declare function replaceChild(parent: DocumentNode | ElementNode, oldChild: TamlNode, newChild: TamlNode): void; /** * Clone a node and its subtree */ export declare function cloneNode(node: TamlNode): TamlNode; /** * Get the root document node for any node */ export declare function getRoot(node: TamlNode): DocumentNode; /** * Get all ancestors of a node (from parent to root) */ export declare function getAncestors(node: TamlNode): TamlNode[]; /** * Get the depth of a node (distance from root) */ export declare function getDepth(node: TamlNode): number; //# sourceMappingURL=nodes.d.ts.map