import { Statement, CommentWithPosition } from '../../types/Ast.type'; import { Writer } from './Writer'; import { LineIndex } from './LineIndex'; import { Patch, CommentLayout, PrintContext } from './types'; export type { CommentWithPosition, LineIndex, PrintContext }; export { Writer }; /** * CommentLayout - Normalize comment ownership * * Decides, per statement: * - leadingComments: Comment[] (non-inline) * - inlineComment: Comment | null * - leadingGapLines: number (blank lines between last leading comment and statement) * - trailingBlankLinesAfterStandaloneComment: number (only for standalone comment nodes) */ export declare class CommentLayoutNormalizer { /** * Normalize comment layout for a statement */ static normalize(node: Statement, lineIndex: LineIndex): CommentLayout; } /** * PatchApplier - Apply patches to source code * * Sort patches descending (as you do now) and apply. * Optional: validate overlaps and throw in dev mode. */ export declare class PatchApplier { /** * Apply patches to source code * Patches are sorted descending by startOffset and applied from end to start * to prevent character position shifts from affecting subsequent replacements */ static apply(originalScript: string, patches: Patch[]): string; /** * Validate that patches don't overlap * @internal This method is kept for potential future use or manual invocation */ static validatePatches(patches: Patch[]): void; } /** * PatchPlanner - Collect edit operations * * Produces Patch[] = { startOffset, endOffset, replacement }. * Responsible for "range selection" (including blank lines, inline comment removal, etc.) * Must guarantee patches don't overlap (or resolve overlaps deterministically). */ export declare class PatchPlanner { private lineIndex; private patches; private originalScript; private originalAST; /** * Enable defensive validation of extracted code. * When true, extracted code is validated before use and falls back to regeneration if invalid. * Set via ROBINPATH_DEBUG environment variable or constructor option. */ private debugMode; constructor(originalScript: string, options?: { debugMode?: boolean; }); /** * Plan patches for all nodes in the AST * This includes patches for: * - Updated nodes (in modified AST) * - New nodes (in modified AST but not in original) * - Deleted nodes (in original AST but not in modified) */ planPatches(ast: Statement[]): Promise; /** * Plan a patch for a deleted node */ private planPatchForDeletedNode; /** * Plan a patch for a single node */ private planPatchForNode; /** * Plan a patch for a new node (insertion) */ private planPatchForNewNode; /** * Plan patch for leading comments (non-overlapping case) */ private planPatchForLeadingComments; /** * Generate replacement without leading comments (for non-overlapping case) */ private generateReplacementWithoutLeadingComments; /** * Plan patch for a standalone comment node */ private planPatchForCommentNode; /** * Find the stop row for comment blank line inclusion */ private findStopRowForComment; /** * Plan patch to remove existing comments */ private planPatchToRemoveComments; /** * Compute the range for a statement region */ private computeStatementRange; /** * Generate replacement text for a node */ private generateReplacement; /** * Preserve blank lines that were included in the range after the statement */ private preserveBlankLinesInRange; /** * Extract original code from the script if the node hasn't changed * Returns null if the node has changed and needs regeneration * * This preserves all original formatting including: * - Indentation (spaces and tabs) * - Spacing within statements * - Blank lines */ private extractOriginalCode; /** * Validate extracted code by checking if it parses correctly and matches expected type. * Used in debug mode to detect extraction corruption. */ private validateExtractedCode; /** * Find the original node that corresponds to the modified node */ private findOriginalNode; /** * Compare two nodes to see if they're equal (ignoring codePos and metadata) */ private nodesAreEqual; /** * Generate code with preserved indentation and spacing from original * This is used when we must regenerate code but want to preserve formatting */ private generateCodeWithPreservedIndentation; } /** * ASTToCodeConverter - Converts AST nodes back to source code * * This class handles the conversion of AST (Abstract Syntax Tree) nodes * back into RobinPath source code strings. It provides methods for: * - Updating source code based on AST changes * - Reconstructing code from individual AST nodes * - Handling comments, indentation, and code positioning */ export declare class ASTToCodeConverter { /** * Validate that AST node positions are within bounds of the source code. * This helps detect stale AST data from external source modifications. * * @param source The current source code * @param ast The AST to validate * @returns Object with isValid flag and optional error details */ private validateASTPositions; /** * Update source code based on AST changes * Uses precise character-level positions (codePos.startRow/startCol/endRow/endCol) to update code * Nested nodes are reconstructed as part of their parent's code * @param originalScript The original source code * @param ast The modified AST array (top-level nodes only) * @returns Updated source code */ updateCodeFromAST(originalScript: string, ast: Statement[]): Promise; /** * Reconstruct code string from an AST node * @param node The AST node (serialized) * @param indentLevel Indentation level for nested code * @returns Reconstructed code string, or null if cannot be reconstructed */ reconstructCodeFromASTNode(node: Statement, indentLevel?: number): string | null; }