parse_numpy/
parse_numpy.rs1use pydocstring::parse::parse_numpy;
6use pydocstring::parse::unified::Document;
7
8fn main() {
9 let docstring = r#"
10Calculate the area of a rectangle.
11
12This function takes the width and height of a rectangle
13and returns its area.
14
15Parameters
16----------
17width : float
18 The width of the rectangle.
19height : float
20 The height of the rectangle.
21
22Returns
23-------
24float
25 The area of the rectangle.
26
27Raises
28------
29ValueError
30 If width or height is negative.
31
32Examples
33--------
34>>> calculate_area(5.0, 3.0)
3515.0
36"#;
37
38 let parsed = parse_numpy(docstring);
39 let doc = Document::new(&parsed);
40
41 println!("╔══════════════════════════════════════════════════╗");
42 println!("║ NumPy-style Docstring Example ║");
43 println!("╚══════════════════════════════════════════════════╝");
44
45 println!();
46
47 println!("── raw text ────────────────────────────────────────");
49 println!("{}", doc.syntax().range().source_text(parsed.source()));
50
51 println!();
52
53 println!("── parsed AST ──────────────────────────────────────");
55 print!("{}", parsed.pretty_print());
56}