Search documentation of Ragex

# Ragex.Analyzers.Behaviour behaviour (Ragex v0.4.0)

View Source

Defines the behaviour for language-specific code analyzers.

Each analyzer must implement these callbacks to extract code structure and metadata from source files in their respective languages.

## Summary

### Types

analysis_result()
call_info()
function_info()
import_info()
module_info()

### Callbacks

analyze(source, file_path)

Analyzes source code and extracts structure information.

supported_extensions()

Returns the file extensions supported by this analyzer.

## Types

# analysis_result()

    @type analysis_result() :: %{
      modules: [module_info()],
      functions: [function_info()],
      calls: [call_info()],
      imports: [import_info()]
    }

# call_info()

    @type call_info() :: %{
      from_module: String.t() | atom(),
      from_function: atom(),
      from_arity: integer(),
      to_module: String.t() | atom(),
      to_function: atom(),
      to_arity: integer(),
      line: integer()
    }

# function_info()

    @type function_info() :: %{
      name: atom(),
      arity: integer(),
      module: String.t() | atom(),
      file: String.t(),
      line: integer(),
      doc: String.t() | nil,
      visibility: :public | :private,
      metadata: map()
    }

# import_info()

    @type import_info() :: %{
      from_module: String.t() | atom(),
      to_module: String.t() | atom(),
      type: :import | :require | :use | :alias
    }

# module_info()

    @type module_info() :: %{
      name: String.t() | atom(),
      file: String.t(),
      line: integer(),
      doc: String.t() | nil,
      metadata: map()
    }

## Callbacks

# analyze(source, file_path)

    @callback analyze(source :: String.t(), file_path :: String.t()) ::
      {:ok, analysis_result()} | {:error, term()}

Analyzes source code and extracts structure information.

Returns an analysis result containing modules, functions, calls, and imports.

# supported_extensions()

    @callback supported_extensions() :: [String.t()]

Returns the file extensions supported by this analyzer.