Ragex.Analyzers.MetaASTExtractor
(Ragex v0.8.0)
View Source
Language-agnostic entity extraction from Metastatic MetaAST.
Walks a Metastatic.Document's AST to extract modules, functions,
calls, and imports into the Ragex.Analyzers.Behaviour.analysis_result()
shape. This replaces the native language-specific analyzers for entity
extraction, providing a single code path that works identically for
every language Metastatic supports.
Extracted Entities
- Modules --
:containernodes withcontainer_type: :moduleor:class - Functions --
:function_defnodes with name, arity, visibility - Calls --
:function_callnodes with caller/callee resolution - Imports --
:importnodes with source and import type
Usage
alias Ragex.Analyzers.MetaASTExtractor
alias Metastatic.Document
{:ok, doc} = Ragex.LanguageSupport.parse_file("lib/my_module.ex")
{:ok, result} = MetaASTExtractor.extract(doc, "lib/my_module.ex")
result.modules # => [%{name: "MyModule", file: "lib/my_module.ex", line: 1, ...}]
result.functions # => [%{name: :my_func, arity: 2, module: "MyModule", ...}]
result.calls # => [%{from_module: "MyModule", to_function: :other, ...}]
result.imports # => [%{from_module: "MyModule", to_module: "OtherModule", ...}]
Summary
Functions
Extracts entities from a Metastatic.Document.
Convenience wrapper: parses a file and extracts entities in one step.
Types
Functions
@spec extract(Metastatic.Document.t(), String.t()) :: {:ok, map()} | {:error, term()}
Extracts entities from a Metastatic.Document.
Returns {:ok, analysis_result} with modules, functions, calls, and imports
in the shape expected by Ragex.Analyzers.Behaviour.
Parameters
doc-- aMetastatic.Document(fromRagex.LanguageSupport.parse_file/2)file_path-- path to the source file (used in entity metadata)
Examples
{:ok, doc} = Ragex.LanguageSupport.parse_file("lib/my_module.ex")
{:ok, result} = MetaASTExtractor.extract(doc, "lib/my_module.ex")
Convenience wrapper: parses a file and extracts entities in one step.
Examples
{:ok, result} = MetaASTExtractor.extract_file("lib/my_module.ex")