Feat/agent mode #1

Closed
tmm621 wants to merge 85 commits from feat/agent-mode into main
2 changed files with 24 additions and 3 deletions
Showing only changes of commit 0b0a013f51 - Show all commits
+7 -1
View File
@@ -372,7 +372,7 @@ def extract_structure(cobol_source: str) -> dict:
file_sec = parse_file_section(preprocessed)
open_dir = scan_open_statements(proc_div) if proc_div else {}
from .models import BrIf, BrEval, BrSeq, BrPerform, Assign, CondAnd, CondOr
from .models import BrIf, BrEval, BrSeq, BrPerform, BrSearch, Assign, CondAnd, CondOr
decision_points = []
total_branches = 0
@@ -403,6 +403,12 @@ def extract_structure(cobol_source: str) -> dict:
elif isinstance(node, BrSeq):
for child in node.children:
_walk(child, counter)
elif isinstance(node, BrPerform):
_walk(node.body_seq, counter)
elif isinstance(node, BrSearch):
_walk(node.at_end_seq, counter)
for _, seq in node.when_list:
_walk(seq, counter)
if branch_tree:
_walk(branch_tree, [0])
+17 -2
View File
@@ -211,11 +211,21 @@ class _BrParser:
seq.add(Assign(tgt, info))
self.advance()
# 跳过 READ 语句剩余行(AT END / NOT AT END / END-READ
# 遇到新的语句关键词时停止,避免贪婪吞咽后续内容
_stmt_boundary = re.compile(
r'^(IF |EVALUATE |PERFORM |SEARCH |INITIALIZE |STRING |'
r'UNSTRING |CALL |ACCEPT |READ |WRITE |REWRITE |SET |'
r'INSPECT |MOVE |COMPUTE |ADD |SUBTRACT |MULTIPLY |DIVIDE |'
r'GO\s+TO |GOBACK |STOP\s+RUN|EXIT\s|CLOSE |OPEN |DISPLAY |'
r'DELETE |START |'
r'END-IF|END-PERFORM|END-EVALUATE|END-READ)', re.IGNORECASE)
while self.pos < len(self.lines):
cl = self.clean()
if cl in ('END-READ', 'END-READ.'):
self.advance()
break
if _stmt_boundary.match(cl):
break
self.advance()
continue
m_set_false = re.match(r'^SET\s+(\w[\w-]*)\s+TO\s+FALSE\s*$', line, re.IGNORECASE)
@@ -658,8 +668,13 @@ class _BrParser:
node = BrIf(cond_text)
node.cond_tree = parse_compound_condition(node.condition, self.fields)
node.true_seq = self.parse_seq(['ELSE', 'END-IF'])
if self.clean() == 'ELSE':
self.advance()
clean = self.clean()
if clean.startswith('ELSE'):
self.advance() # consume ELSE keyword
rest = clean[4:].strip() if len(clean) > 4 else ''
# ELSE IF → reinsert IF statement as next line for recursive parse
if rest.upper().startswith('IF '):
self.lines.insert(self.pos, rest)
node.false_seq = self.parse_seq(['END-IF'])
if self.clean() == 'END-IF':
self.advance()