1pub use crate::parser::pricedb_parser::{pricedb_from_file, pricedb_from_str};
6pub use crate::parser::tackler_txns::git_to_txns;
7pub use crate::parser::tackler_txns::paths_to_txns;
8pub use crate::parser::tackler_txns::string_to_txns;
9use winnow::error::{ErrMode, FromExternalError};
10
11mod error;
12mod pricedb_parser;
13mod tackler_parser;
14mod tackler_txns;
15
16use crate::kernel::settings::Settings;
17use crate::parser::error::TacklerTxnError;
18use winnow::Stateful;
19
20pub(crate) mod parts;
21
22pub(crate) type Stream<'is> = Stateful<&'is str, &'is mut Settings>;
23
24pub(crate) fn make_semantic_error<
25 'is,
26 E: winnow::error::FromExternalError<Stream<'is>, TacklerTxnError>,
27>(
28 is: &mut Stream<'is>,
29 msg: &str,
30) -> ErrMode<E> {
31 ErrMode::from_external_error(is, TacklerTxnError::semantic_error(msg)).cut()
32}
33
34pub(crate) fn from_error<
35 'is,
36 E: winnow::error::FromExternalError<Stream<'is>, TacklerTxnError>,
37 SE: std::error::Error + ?Sized,
38>(
39 is: &mut Stream<'is>,
40 err: &SE,
41) -> ErrMode<E> {
42 ErrMode::from_external_error(
43 is,
44 TacklerTxnError::semantic_error(err.to_string().as_str()),
45 )
46 .cut()
47}
48
49#[inline]
59fn illegal_characters(c: char) -> bool {
60 c == ':' || c.is_whitespace()
61}
62
63fn is_valid_id_start_char(c: char) -> bool {
65 !(c.is_ascii_digit() || c == ':' || c == '-' || c == '_' || c == 'ยท' || c.is_whitespace())
66}
67
68fn is_valid_sub_id_start_char(c: char) -> bool {
70 c.is_numeric() || is_valid_id_start_char(c)
71}
72
73pub fn is_valid_id(token: &str) -> bool {
75 !token.is_empty()
76 && token.starts_with(is_valid_id_start_char)
77 && !token.contains(illegal_characters)
78}
79
80pub fn is_valid_sub_id(token: &str) -> bool {
82 !token.is_empty()
83 && token.starts_with(is_valid_sub_id_start_char)
84 && !token.contains(illegal_characters)
85}
86
87#[cfg(test)]
88mod tests;