pydocstring 0.1.12

A zero-dependency Rust parser for Python docstrings (Google and NumPy styles) with a unified syntax tree and byte-precise source locations
Documentation
//! Example: Parsing NumPy-style docstrings
//!
//! Shows the raw docstring text, then the detailed parsed AST.

use pydocstring::parse::numpy::{NumPyDocstring, parse_numpy};

fn main() {
    let docstring = r#"
Calculate the area of a rectangle.

This function takes the width and height of a rectangle
and returns its area.

Parameters
----------
width : float
    The width of the rectangle.
height : float
    The height of the rectangle.

Returns
-------
float
    The area of the rectangle.

Raises
------
ValueError
    If width or height is negative.

Examples
--------
>>> calculate_area(5.0, 3.0)
15.0
"#;

    let parsed = parse_numpy(docstring);
    let doc = NumPyDocstring::cast(parsed.root()).unwrap();

    println!("╔══════════════════════════════════════════════════╗");
    println!("║          NumPy-style Docstring Example           ║");
    println!("╚══════════════════════════════════════════════════╝");

    println!();

    // Display: raw source text
    println!("── raw text ────────────────────────────────────────");
    println!("{}", doc.syntax().range().source_text(parsed.source()));

    println!();

    // pretty_print: structured AST
    println!("── parsed AST ──────────────────────────────────────");
    print!("{}", parsed.pretty_print());
}