use crate::lex::ast::elements::sequence_marker::{DecorationStyle, Form, Separator};
use crate::lex::lexing::line_classification::parse_seq_marker;
use crate::lex::token::normalization::utilities::{compute_bounding_box, extract_text};
use crate::lex::token::Token;
use std::ops::Range as ByteRange;
#[derive(Debug, Clone)]
pub(in crate::lex::building) struct SessionMarkerData {
pub text: String,
pub byte_range: ByteRange<usize>,
pub style: DecorationStyle,
pub separator: Separator,
pub form: Form,
}
#[derive(Debug, Clone)]
pub(in crate::lex::building) struct SessionData {
pub title_text: String,
pub title_byte_range: ByteRange<usize>,
pub marker: Option<SessionMarkerData>,
}
pub(in crate::lex::building) fn extract_session_data(
tokens: Vec<(Token, ByteRange<usize>)>,
source: &str,
) -> SessionData {
let token_refs: Vec<Token> = tokens.iter().map(|(t, _)| t.clone()).collect();
let parsed_marker = parse_seq_marker(&token_refs);
if let Some(pm) = parsed_marker {
if pm.style != DecorationStyle::Plain {
let marker_tokens = &tokens[pm.marker_start..pm.marker_end];
let marker_byte_range = compute_bounding_box(marker_tokens);
let marker_text = extract_text(marker_byte_range.clone(), source);
let marker_data = SessionMarkerData {
text: marker_text,
byte_range: marker_byte_range,
style: pm.style,
separator: pm.separator,
form: pm.form,
};
let title_byte_range = compute_bounding_box(&tokens);
let title_text = extract_text(title_byte_range.clone(), source);
return SessionData {
title_text,
title_byte_range,
marker: Some(marker_data),
};
}
}
let title_byte_range = compute_bounding_box(&tokens);
let title_text = extract_text(title_byte_range.clone(), source);
SessionData {
title_text,
title_byte_range,
marker: None,
}
}