From f8285f7ff79b381a2e0f8874f448c51f9600e6ce Mon Sep 17 00:00:00 2001 From: swpa Date: Thu, 28 May 2026 13:28:39 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=B0=8D=20CMTS=20=E8=A8=AD=E5=AE=9A?= =?UTF-8?q?=E9=9A=8E=E5=B1=A4=E5=AF=A6=E6=96=BD=E5=BC=B7=E5=8C=96=E6=8E=92?= =?UTF-8?q?=E6=9F=A5=E6=A9=9F=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shared.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/shared.py b/shared.py index f1ee0c4..dcaff08 100644 --- a/shared.py +++ b/shared.py @@ -75,27 +75,27 @@ def parse_cli_to_tree(cli_text: str) -> dict: stripped = line.strip() indent = len(line) - len(line.lstrip()) - # 🌟 嚴格判斷 1:如果遇到縮排退回 (包含縮排退回的 !),代表當前深度的區塊已結束 - if indent < current_indent: + # 🌟 嚴格判斷 1:遇到「真實指令」縮排退回,才代表區塊結束 + # (加上 stripped != '!',防止設備偶發的「0 縮排 !」導致區塊被誤殺) + if indent < current_indent and stripped != '!': return nodes, i - # 🌟 嚴格判斷 2:處理同層級的 ! + # 🌟 嚴格判斷 2:處理 ! (無論縮排多少,都當純分隔符消耗掉) if stripped == '!': - # 能走到這裡,代表 indent >= current_indent - # 這是對應當前層級的結束符號或分隔符,我們將其消耗掉並繼續,絕對不提早 return i += 1 continue - # 探測是否有子節點 + # 🌟 探測是否有子節點 (強化版:往下尋找第一個「非 !」的真實指令來判斷) has_children = False - if i + 1 < len(lines): - next_line = lines[i+1] - next_stripped = next_line.strip() - # 只有當下一行不是 ! 且縮排大於當前行時,才判定為有子節點 - if next_stripped != '!': - next_indent = len(next_line) - len(next_line.lstrip()) - if next_indent > indent: - has_children = True + next_i = i + 1 + while next_i < len(lines) and lines[next_i].strip() == '!': + next_i += 1 + + if next_i < len(lines): + next_line = lines[next_i] + next_indent = len(next_line) - len(next_line.lstrip()) + if next_indent > indent: + has_children = True if has_children: children, next_i = build_raw_tree(i + 1, next_indent)