use crate::parser::format_parser::FormatParser;
use formatparse_core::{FieldSpec, FieldType};
use pyo3::prelude::*;
use std::collections::HashMap;
use std::sync::Arc;
pub(crate) fn capture_string_for_match_storage(spec: &FieldSpec, raw: &str) -> String {
if matches!(
spec.field_type,
FieldType::Multiline | FieldType::IndentBlock
) {
formatparse_core::normalize_input_line_continuations(raw)
} else {
raw.to_string()
}
}
pub struct FieldCaptureSlices<'a> {
pub field_specs: &'a [FieldSpec],
pub field_names: &'a [Option<String>],
pub normalized_names: &'a [Option<String>],
pub custom_type_groups: &'a [usize],
pub has_nested_dict_fields: &'a [bool],
pub nested_parsers: &'a [Option<Arc<FormatParser>>],
}
impl<'a> FieldCaptureSlices<'a> {
pub fn from_parser(parser: &'a FormatParser) -> Self {
parser.fields.capture_slices()
}
}
pub struct CapturedMatchContext<'a> {
pub pattern: &'a str,
pub fields: FieldCaptureSlices<'a>,
pub py: Python<'a>,
pub custom_converters: &'a HashMap<String, PyObject>,
pub evaluate_result: bool,
}
pub struct RegexMatchContext<'a> {
pub string: &'a str,
pub pattern: &'a str,
pub field_specs: &'a [FieldSpec],
pub field_names: &'a [Option<String>],
pub normalized_names: &'a [Option<String>],
pub nested_parsers: &'a [Option<Arc<FormatParser>>],
pub py: Python<'a>,
pub custom_converters: &'a HashMap<String, PyObject>,
pub evaluate_result: bool,
}
mod capture;
mod custom_type;
mod nested_dict;
mod py_match;
mod raw;
pub use custom_type::validate_custom_type_pattern;
pub use nested_dict::insert_nested_dict;
pub use py_match::{match_empty_default_string_parse, match_with_captures, match_with_regex};
pub use raw::match_with_captures_raw;