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
/*
* Tackler-NG 2024-2025
* SPDX-License-Identifier: Apache-2.0
*/
use crate::parser::Stream;
use winnow::combinator::{alt, cut_err, peek};
use winnow::stream::AsChar;
use winnow::token::one_of;
use winnow::{ModalResult, Parser, seq};
use winnow::{
ascii::line_ending,
ascii::till_line_ending,
error::{StrContext, StrContextValue},
};
pub(crate) fn p_comment<'s>(is: &mut Stream<'s>) -> ModalResult<&'s str> {
let m = seq!(
_: ';',
cut_err(alt((
// allow totally empty comment ";\n" - this is important for
// txn body comments as some editors removes spaces at the end of line
peek(line_ending).map(|_| {("",)}),
seq!(
// this can not be space1 as we must preserve space for equity and identity reports
_: one_of(AsChar::is_space),
till_line_ending
)
)).map(|x| x.0))
.context(StrContext::Expected(StrContextValue::Description("comment begins with a `;` and a space character"))),
)
.map(|x| x.0)
.parse_next(is)?;
Ok(m)
}
// The line_end handling must work with outer contex,
// so for testing, see txn_comment.rs