Ragex.Analyzers.MetaASTExtractor (Ragex v0.13.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 -- :container nodes with container_type: :module or :class
  • Functions -- :function_def nodes with name, arity, visibility
  • Calls -- :function_call nodes with caller/callee resolution
  • Imports -- :import nodes 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

Convenience wrapper: parses a file and extracts entities in one step.

Types

acc()

@type acc() :: %{
  modules: [map()],
  functions: [map()],
  calls: [map()],
  imports: [map()]
}

context()

@type context() :: %{
  file: String.t(),
  language: atom(),
  container: term(),
  function: atom() | nil,
  arity: non_neg_integer() | nil
}

Functions

extract(document, file_path)

@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

Examples

{:ok, doc} = Ragex.LanguageSupport.parse_file("lib/my_module.ex")
{:ok, result} = MetaASTExtractor.extract(doc, "lib/my_module.ex")

extract_file(path, opts \\ [])

@spec extract_file(
  String.t(),
  keyword()
) :: {:ok, map()} | {:error, term()}

Convenience wrapper: parses a file and extracts entities in one step.

Examples

{:ok, result} = MetaASTExtractor.extract_file("lib/my_module.ex")