parse_numpy/
parse_numpy.rs1use pydocstring::parse::numpy::{NumPyDocstring, parse_numpy};
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
14Parameters
15----------
16width : float
17 The width of the rectangle.
18height : float
19 The height of the rectangle.
20
21Returns
22-------
23float
24 The area of the rectangle.
25
26Raises
27------
28ValueError
29 If width or height is negative.
30
31Examples
32--------
33>>> calculate_area(5.0, 3.0)
3415.0
35"#;
36
37 let parsed = parse_numpy(docstring);
38 let doc = NumPyDocstring::cast(parsed.root()).unwrap();
39
40 println!("╔══════════════════════════════════════════════════╗");
41 println!("║ NumPy-style Docstring Example ║");
42 println!("╚══════════════════════════════════════════════════╝");
43
44 println!();
45
46 println!("── raw text ────────────────────────────────────────");
48 println!("{}", doc.syntax().range().source_text(parsed.source()));
49
50 println!();
51
52 println!("── parsed AST ──────────────────────────────────────");
54 print!("{}", parsed.pretty_print());
55}