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
use nom::{
bytes::complete::tag,
character::complete::space1,
combinator::map,
sequence::{separated_pair, tuple},
IResult,
};
use crate::{account::account, date::date, Account, Date};
#[cfg(all(test, feature = "unstable"))]
use crate::pest_parser::Pair;
#[derive(Debug, Clone)]
pub struct Close<'a> {
pub(crate) date: Date,
pub(crate) account: Account<'a>,
}
impl<'a> Close<'a> {
#[must_use]
pub fn date(&self) -> Date {
self.date
}
#[must_use]
pub fn account(&self) -> &Account<'a> {
&self.account
}
#[cfg(all(test, feature = "unstable"))]
pub(crate) fn from_pair(pair: Pair<'_>) -> Close<'_> {
let mut inner = pair.into_inner();
let date = Date::from_pair(inner.next().expect("no date in close directive"));
let account = Account::from_pair(inner.next().expect("no account in close directive"));
Close { date, account }
}
}
pub(crate) fn close(input: &str) -> IResult<&str, Close<'_>> {
map(
separated_pair(date, tuple((space1, tag("close"), space1)), account),
|(date, account)| Close { date, account },
)(input)
}