Skip to content

Commit c8ec9a4

Browse files
authored
Merge pull request #44 from FalkorDB/capture
Fix #43 Fix error when no function or struct in code
2 parents 0c1bc5b + a5f882d commit c8ec9a4

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

api/analyzers/c/analyzer.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -369,21 +369,24 @@ def first_pass(self, path: Path, f: io.TextIOWrapper, graph:Graph) -> None:
369369
# ]
370370
# }
371371

372-
functions = captures['function']
373-
for node in functions:
374-
self.process_function_definition(file, node, path, graph, source_code)
372+
if 'function' in captures:
373+
functions = captures['function']
374+
for node in functions:
375+
self.process_function_definition(file, node, path, graph, source_code)
375376

376377
# Process struct definitions
377378
query = C_LANGUAGE.query("(struct_specifier) @struct")
378379
captures = query.captures(tree.root_node)
379-
structs = captures['struct']
380-
# captures: {'struct':
381-
# [
382-
# <Node type=struct_specifier, start_point=(9, 0), end_point=(13, 1)>
383-
# ]
384-
# }
385-
for node in structs:
386-
self.process_struct_specifier(file, node, path, graph)
380+
381+
if 'struct' in captures:
382+
structs = captures['struct']
383+
# captures: {'struct':
384+
# [
385+
# <Node type=struct_specifier, start_point=(9, 0), end_point=(13, 1)>
386+
# ]
387+
# }
388+
for node in structs:
389+
self.process_struct_specifier(file, node, path, graph)
387390

388391
def second_pass(self, path: Path, f: io.TextIOWrapper, graph: Graph) -> None:
389392
"""

0 commit comments

Comments
 (0)