1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//! # Parser implementation
use crateNode;
use crateResult;
use crateSegments;
/// Parses input.
///
/// # Returns
///
/// Document [Node].
///
/// All nodes parsed from input are children of the document [Node].
///
/// # Errors
///
/// Returns [`DimlError`](crate::DimlError) when parsing fails.
///
/// # Panics
///
/// No panics.
///
/// # Examples
///
/// Input contains the following text:
///
/// ```text
/// .A Ann
/// .B Bob
/// .C Clyde
/// .D Dave
/// ```
///
/// ```
/// use diml::parse;
///
/// # let input = ".A Ann\n .B Bob\n .C Clyde\n .D Dave\n";
/// let doc = parse(input).unwrap();
///
/// let node_a = doc.children().next().unwrap();
/// assert_eq!(1, node_a.line());
/// assert_eq!("A", node_a.name());
/// assert_eq!("Ann", node_a.content().trim());
///
/// let mut children_a = node_a.children();
/// let node_b = children_a.next().unwrap();
/// assert_eq!(2, node_b.line());
/// assert_eq!("B", node_b.name());
/// assert_eq!("Bob", node_b.content().trim());
///
/// let node_c = children_a.next().unwrap();
/// assert_eq!(3, node_c.line());
/// assert_eq!("C", node_c.name());
/// assert_eq!("Clyde", node_c.content().trim());
///
/// let node_d = node_c.children().next().unwrap();
/// assert_eq!(4, node_d.line());
/// assert_eq!("D", node_d.name());
/// assert_eq!("Dave", node_d.content().trim());
/// ```