@@ -545,6 +545,43 @@ def _swift_extra_walk(node, source: bytes, file_nid: str, stem: str, str_path: s
545545)
546546
547547
548+ def _import_lua (node , source : bytes , file_nid : str , stem : str , edges : list , str_path : str ) -> None :
549+ """Extract require('module') from Lua variable_declaration nodes."""
550+ text = _read_text (node , source )
551+ import re
552+ m = re .search (r"""require\s*[\('"]\s*['"]?([^'")\s]+)""" , text )
553+ if m :
554+ module_name = m .group (1 ).split ("." )[- 1 ]
555+ if module_name :
556+ edges .append ({
557+ "source" : file_nid ,
558+ "target" : module_name ,
559+ "relation" : "imports" ,
560+ "confidence" : "EXTRACTED" ,
561+ "confidence_score" : 1.0 ,
562+ "source_file" : str_path ,
563+ "source_location" : str (node .start_point [0 ] + 1 ),
564+ "weight" : 1.0 ,
565+ })
566+
567+
568+ _LUA_CONFIG = LanguageConfig (
569+ ts_module = "tree_sitter_lua" ,
570+ ts_language_fn = "language" ,
571+ class_types = frozenset (),
572+ function_types = frozenset ({"function_declaration" }),
573+ import_types = frozenset ({"variable_declaration" }),
574+ call_types = frozenset ({"function_call" }),
575+ call_function_field = "name" ,
576+ call_accessor_node_types = frozenset ({"method_index_expression" }),
577+ call_accessor_field = "name" ,
578+ name_fallback_child_types = ("identifier" , "method_index_expression" ),
579+ body_fallback_child_types = ("block" ,),
580+ function_boundary_types = frozenset ({"function_declaration" }),
581+ import_handler = _import_lua ,
582+ )
583+
584+
548585def _import_swift (node , source : bytes , file_nid : str , stem : str , edges : list , str_path : str ) -> None :
549586 for child in node .children :
550587 if child .type == "identifier" :
@@ -1078,6 +1115,11 @@ def extract_php(path: Path) -> dict:
10781115 return _extract_generic (path , _PHP_CONFIG )
10791116
10801117
1118+ def extract_lua (path : Path ) -> dict :
1119+ """Extract functions, methods, require() imports, and calls from a .lua file."""
1120+ return _extract_generic (path , _LUA_CONFIG )
1121+
1122+
10811123def extract_swift (path : Path ) -> dict :
10821124 """Extract classes, structs, protocols, functions, imports, and calls from a .swift file."""
10831125 return _extract_generic (path , _SWIFT_CONFIG )
@@ -1623,6 +1665,8 @@ def extract(paths: list[Path]) -> dict:
16231665 ".scala" : extract_scala ,
16241666 ".php" : extract_php ,
16251667 ".swift" : extract_swift ,
1668+ ".lua" : extract_lua ,
1669+ ".toc" : extract_lua ,
16261670 }
16271671
16281672 for path in paths :
@@ -1665,6 +1709,7 @@ def collect_files(target: Path) -> list[Path]:
16651709 "*.py" , "*.js" , "*.ts" , "*.tsx" , "*.go" , "*.rs" ,
16661710 "*.java" , "*.c" , "*.h" , "*.cpp" , "*.cc" , "*.cxx" , "*.hpp" ,
16671711 "*.rb" , "*.cs" , "*.kt" , "*.kts" , "*.scala" , "*.php" , "*.swift" ,
1712+ "*.lua" , "*.toc" ,
16681713 )
16691714 results : list [Path ] = []
16701715 for pattern in _EXTENSIONS :
0 commit comments