Skip to main content

ass_core/parser/streaming/state/
context.rs

1//! Streaming parser context tracking line numbers, sections, and formats.
2//!
3//! Defines [`StreamingContext`], maintaining parsing context including line
4//! tracking, current section, and format information for incremental processing.
5
6use alloc::string::String;
7
8use super::SectionKind;
9
10/// Context for streaming parser state
11///
12/// Maintains parsing context including line tracking, current section,
13/// and format information for proper incremental processing.
14#[derive(Debug, Clone)]
15pub struct StreamingContext {
16    /// Current line number (1-based)
17    pub line_number: usize,
18    /// Currently active section
19    pub current_section: Option<SectionKind>,
20    /// Events format fields
21    pub events_format: Option<String>,
22    /// Styles format fields
23    pub styles_format: Option<String>,
24}
25
26impl StreamingContext {
27    /// Create new context with default values
28    #[must_use]
29    pub const fn new() -> Self {
30        Self {
31            line_number: 0,
32            current_section: None,
33            events_format: None,
34            styles_format: None,
35        }
36    }
37
38    /// Advance to next line
39    pub fn next_line(&mut self) {
40        self.line_number += 1;
41    }
42
43    /// Enter new section
44    pub fn enter_section(&mut self, kind: SectionKind) {
45        self.current_section = Some(kind);
46    }
47
48    /// Exit current section
49    pub fn exit_section(&mut self) {
50        self.current_section = None;
51    }
52
53    /// Set format for events section
54    pub fn set_events_format(&mut self, format: String) {
55        self.events_format = Some(format);
56    }
57
58    /// Set format for styles section
59    pub fn set_styles_format(&mut self, format: String) {
60        self.styles_format = Some(format);
61    }
62
63    /// Reset context for new parsing session
64    pub fn reset(&mut self) {
65        self.line_number = 0;
66        self.current_section = None;
67        self.events_format = None;
68        self.styles_format = None;
69    }
70}
71
72impl Default for StreamingContext {
73    fn default() -> Self {
74        Self::new()
75    }
76}