/**
 * Excel range parsing utilities.
 *
 * Parses <Workbook:Sheet!Range> notation from execute_code descriptions.
 */
/**
 * Extract Excel location from the <...> bracket in a description string.
 * Returns null if no bracketed reference is found.
 */
export function parseExcelLocation(description) {
    const m = description.match(/<([^>]+)>/);
    if (!m)
        return null;
    const ref = m[1].trim();
    // Workbook:Sheet!Range
    const full = ref.match(/^([^:]+):([^!]+)!(.+)$/);
    if (full) {
        return { workbook: full[1].trim(), sheet: full[2].trim(), range: full[3].trim() };
    }
    // Sheet!Range
    const sr = ref.match(/^([^!]+)!(.+)$/);
    if (sr) {
        return { sheet: sr[1].trim(), range: sr[2].trim() };
    }
    // Bare range (e.g. A1:D10, A1) - check before Workbook:Sheet since "A1:D10" has a colon
    if (/^[A-Z]{1,3}\d+(?::[A-Z]{1,3}\d+)?$/.test(ref)) {
        return { range: ref };
    }
    // Workbook:Sheet (no range)
    const ws = ref.match(/^([^:]+):(.+)$/);
    if (ws) {
        return { workbook: ws[1].trim(), sheet: ws[2].trim() };
    }
    return ref ? { sheet: ref } : null;
}
/**
 * Reconstruct the original notation: Workbook:Sheet!Range.
 * Used for string replacement in renderCall labels.
 */
export function formatNotation(loc) {
    let s = '';
    if (loc.workbook)
        s += loc.workbook;
    if (loc.sheet)
        s += (s ? ':' : '') + loc.sheet;
    if (loc.range)
        s += (s ? '!' : '') + loc.range;
    return s;
}
//# sourceMappingURL=excel-range.js.map