From 2c762b04114d6bca572e93aae539c7c4a07a930e Mon Sep 17 00:00:00 2001 From: hypercross Date: Mon, 13 Jul 2026 10:49:40 +0800 Subject: [PATCH] refactor: move block scanning logic to shared module Import `FENCED_BLOCK_RE` and `parseBlockAttrs` from `block-scanner.js` instead of defining them locally in `declare-parser.ts`. --- src/cli/completions/declare-parser.ts | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/src/cli/completions/declare-parser.ts b/src/cli/completions/declare-parser.ts index 711dea2..45e92b0 100644 --- a/src/cli/completions/declare-parser.ts +++ b/src/cli/completions/declare-parser.ts @@ -15,25 +15,7 @@ */ import { parse } from "csv-parse/browser/esm/sync"; - -// --------------------------------------------------------------------------- -// Shared block scanning — used by both CLI (block-processor) and client -// (completions.ts) so there's a single source of truth for declare parsing. -// --------------------------------------------------------------------------- - -/** Matches fenced code blocks with an info string. */ -const FENCED_BLOCK_RE = /^```(\w*)\s+(\S.*?)\s*\n([\s\S]*?)```\s*$/gm; - -/** Parse key="value" and key=value pairs from an attribute string. */ -function parseBlockAttrs(info: string): Record { - const attrs: Record = {}; - const re = /(\w+)\s*=\s*("[^"]*"|\S+)/g; - let m: RegExpExecArray | null; - while ((m = re.exec(info)) !== null) { - attrs[m[1]] = m[2].replace(/^"|"$/g, ""); - } - return attrs; -} +import { FENCED_BLOCK_RE, parseBlockAttrs } from "./block-scanner.js"; /** * Scan markdown content for ```csv role=declare blocks and return