/** * 正则表达式解析器 * * @module RegexEditor/validation/parser * @description 基于 regexp-tree 的正则表达式解析器,提供 AST 解析和遍历功能 * * @remarks * 该模块封装了 regexp-tree 库,提供类型安全的解析和遍历功能。 * 主要功能: * - 将正则表达式字符串解析为抽象语法树(AST) * - 统一的错误处理和转换 * - AST 节点遍历工具 * * @see https://github.com/DmitrySoshnikov/regexp-tree */ import type { ParseResult, ASTNode } from './types'; /** * 解析正则表达式 * * @param pattern - 正则表达式字符串 * @param flags - 可选的正则表达式标志(g, i, m, s, u, y) * @returns {ParseResult} 解析结果,包含 AST 或错误信息 * * @example * ```typescript * const result = parseRegex('^LOT\\d{6}$'); * if (result.success) { * console.log('AST:', result.ast); * } else { * console.error('Error:', result.error); * } * ``` */ export declare const parseRegex: (pattern: string, flags?: string) => ParseResult; /** * 遍历 AST 节点 * * @param ast - 抽象语法树节点 * @param handlers - 节点类型处理器映射 * * @example * ```typescript * const result = parseRegex('(\\d+)'); * const groups: any[] = []; * * traverseAST(result.ast!, { * Group(path) { * groups.push(path.node); * } * }); * ``` */ export declare const traverseAST: (ast: ASTNode | undefined, handlers: Record void>) => void;