beancount_parser/event.rs
1use nom::character::complete::space1;
2
3use crate::{string, IResult, Span};
4
5/// An event
6///
7/// # Example
8/// ```
9/// # use beancount_parser::{BeancountFile, DirectiveContent};
10/// let input = r#"2023-05-31 event "Location" "Switzerland""#;
11/// let beancount: BeancountFile<f64> = input.parse().unwrap();
12/// let DirectiveContent::Event(ref event) = beancount.directives[0].content else { unreachable!() };
13/// assert_eq!(event.name, "Location");
14/// assert_eq!(event.value, "Switzerland");
15/// ```
16#[derive(Debug, Clone, PartialEq)]
17#[non_exhaustive]
18pub struct Event {
19 /// Name of the event
20 pub name: String,
21 /// Value of the event
22 pub value: String,
23}
24
25pub(super) fn parse(input: Span<'_>) -> IResult<'_, Event> {
26 let (input, name) = string(input)?;
27 let (input, _) = space1(input)?;
28 let (input, value) = string(input)?;
29 Ok((input, Event { name, value }))
30}