broadfield-dev commited on
Commit
a0e69b0
·
verified ·
1 Parent(s): d502fb0

Update parser.py

Browse files
Files changed (1) hide show
  1. parser.py +19 -17
parser.py CHANGED
@@ -130,23 +130,25 @@ def parse_node(node, lines, prev_end, level=0, total_lines=None, parent_path=Non
130
  processed_lines.add(start_line)
131
 
132
  # Handle variables in function definitions (input variables)
133
- if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)) and node.args.args:
134
- for arg in node.args.args:
135
- var_start = start_line # Assume args are on the same line as function def for simplicity
136
- if var_start not in processed_lines:
137
- counters['input_variable'] += 1
138
- var_node_id = f"InputVariable[{counters['input_variable']}]"
139
- var_info = {'role': 'input_variable', 'name': arg.arg}
140
- parts.append({
141
- 'category': 'input_variable',
142
- 'source': f" {arg.arg},", # Indented as part of function
143
- 'location': (var_start, var_start),
144
- 'level': level + 1,
145
- 'vector': create_vector('input_variable', level + 1, (var_start, var_start), total_lines, current_path, var_info),
146
- 'parent_path': f"{current_path[0]} -> {var_node_id}",
147
- 'node_id': var_node_id
148
- })
149
- processed_lines.add(var_start)
 
 
150
 
151
  # Process nested bodies
152
  nested_prev_end = start_line
 
130
  processed_lines.add(start_line)
131
 
132
  # Handle variables in function definitions (input variables)
133
+ if isinstance(child, ast.Assign) or isinstance(child, ast.AnnAssign) or isinstance(child, ast.AugAssign):
134
+ targets = child.targets if isinstance(child, ast.Assign) else [child.target]
135
+ for target in targets:
136
+ if isinstance(target, ast.Name):
137
+ var_start = child.lineno
138
+ if var_start not in processed_lines and not is_blank_or_comment(lines[var_start - 1]):
139
+ counters['assigned_variable'] += 1
140
+ var_node_id = f"AssignedVariable[{counters['assigned_variable']}]"
141
+ var_info = {'role': 'assigned_variable', 'name': target.id}
142
+ parts.append({
143
+ 'category': 'assigned_variable',
144
+ 'source': lines[var_start - 1],
145
+ 'location': (var_start, var_start),
146
+ 'level': level + 1,
147
+ 'vector': create_vector('assigned_variable', level + 1, (var_start, var_start), total_lines, current_path, var_info),
148
+ 'parent_path': f"{current_path[0]} -> {var_node_id}",
149
+ 'node_id': var_node_id
150
+ })
151
+ processed_lines.add(var_start)
152
 
153
  # Process nested bodies
154
  nested_prev_end = start_line