SnakeBridge.Docs.RstParser (SnakeBridge v0.16.0)

Copy Markdown View Source

Parses Python docstrings in various formats (Google, NumPy, Sphinx, Epytext).

This module detects the docstring format and extracts structured information including parameters, return values, exceptions, and examples.

Supported Formats

  • Google style: Uses Args:, Returns:, Raises: sections
  • NumPy style: Uses underlined section headers (Parameters ----------)
  • Sphinx/reST style: Uses :param:, :type:, :returns: directives
  • Epytext style: Uses @param, @type, @return tags

Summary

Functions

Detects the docstring style based on content patterns.

Parses a Python docstring and returns structured data.

Types

param()

@type param() :: %{
  name: String.t(),
  type_name: String.t() | nil,
  description: String.t() | nil,
  optional: boolean(),
  default: String.t() | nil
}

parsed_doc()

@type parsed_doc() :: %{
  short_description: String.t() | nil,
  long_description: String.t() | nil,
  params: [param()],
  returns: returns() | nil,
  raises: [raises()],
  examples: [String.t()],
  notes: String.t() | nil,
  style: atom()
}

raises()

@type raises() :: %{type_name: String.t(), description: String.t() | nil}

returns()

@type returns() :: %{type_name: String.t() | nil, description: String.t() | nil}

Functions

detect_style(docstring)

@spec detect_style(String.t() | nil) :: atom()

Detects the docstring style based on content patterns.

parse(docstring)

@spec parse(String.t() | nil) :: parsed_doc()

Parses a Python docstring and returns structured data.