ass_core/parser/script/
container.rs1use alloc::vec::Vec;
8
9use crate::parser::ast::{Section, SectionType};
10use crate::parser::errors::ParseIssue;
11use crate::ScriptVersion;
12
13use super::types::ChangeTracker;
14
15#[derive(Debug, Clone, PartialEq, Eq)]
20#[cfg_attr(feature = "serde", derive(serde::Serialize))]
21pub struct Script<'a> {
22 pub(super) source: &'a str,
24
25 pub(super) version: ScriptVersion,
27
28 pub(super) sections: Vec<Section<'a>>,
30
31 #[cfg_attr(feature = "serde", serde(skip))]
37 pub(super) issues: Vec<ParseIssue>,
38
39 pub(super) styles_format: Option<Vec<&'a str>>,
41
42 pub(super) events_format: Option<Vec<&'a str>>,
44
45 #[cfg_attr(feature = "serde", serde(skip))]
49 pub(super) change_tracker: ChangeTracker<'a>,
50}
51
52impl<'a> Script<'a> {
53 #[must_use]
55 pub const fn version(&self) -> ScriptVersion {
56 self.version
57 }
58
59 #[must_use]
61 #[allow(clippy::missing_const_for_fn)]
62 pub fn sections(&self) -> &[Section<'a>] {
63 &self.sections
64 }
65
66 #[must_use]
68 #[allow(clippy::missing_const_for_fn)]
69 pub fn issues(&self) -> &[ParseIssue] {
70 &self.issues
71 }
72
73 #[must_use]
75 pub const fn source(&self) -> &'a str {
76 self.source
77 }
78
79 #[must_use]
81 pub fn styles_format(&self) -> Option<&[&'a str]> {
82 self.styles_format.as_deref()
83 }
84
85 #[must_use]
87 pub fn events_format(&self) -> Option<&[&'a str]> {
88 self.events_format.as_deref()
89 }
90
91 #[must_use]
93 pub fn find_section(&self, section_type: SectionType) -> Option<&Section<'a>> {
94 self.sections
95 .iter()
96 .find(|s| s.section_type() == section_type)
97 }
98
99 pub(in crate::parser) fn from_parts(
101 source: &'a str,
102 version: ScriptVersion,
103 sections: Vec<Section<'a>>,
104 issues: Vec<ParseIssue>,
105 styles_format: Option<Vec<&'a str>>,
106 events_format: Option<Vec<&'a str>>,
107 ) -> Self {
108 Self {
109 source,
110 version,
111 sections,
112 issues,
113 styles_format,
114 events_format,
115 change_tracker: ChangeTracker::default(),
116 }
117 }
118}