Skip to main content

parse_google/
parse_google.rs

1//! Example: Parsing Google-style docstrings
2//!
3//! Shows the raw docstring text, then the detailed parsed AST.
4
5use pydocstring::parse::parse_google;
6
7fn main() {
8    let docstring = r#"
9Calculate the area of a rectangle.
10
11This function takes the width and height of a rectangle
12and returns its area.
13
14Args:
15    width (float): The width of the rectangle.
16    height (float): The height of the rectangle.
17
18Returns:
19    float: The area of the rectangle.
20
21Raises:
22    ValueError: If width or height is negative.
23"#;
24
25    let parsed = parse_google(docstring);
26
27    println!("╔══════════════════════════════════════════════════╗");
28    println!("║          Google-style Docstring Example          ║");
29    println!("╚══════════════════════════════════════════════════╝");
30
31    println!();
32
33    // Display: raw source text
34    println!("── raw text ────────────────────────────────────────");
35    println!("{}", parsed.source());
36
37    println!();
38
39    // pretty_print: structured AST
40    println!("── parsed AST ──────────────────────────────────────");
41    print!("{}", parsed.pretty_print());
42}