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
25impl Event {
26 /// Create a new event
27 #[must_use]
28 pub fn new(name: String, value: String) -> Event {
29 Event { name, value }
30 }
31}
32
33pub(super) fn parse(input: Span<'_>) -> IResult<'_, Event> {
34 let (input, name) = string(input)?;
35 let (input, _) = space1(input)?;
36 let (input, value) = string(input)?;
37 Ok((input, Event { name, value }))
38}