pub mod events;
pub mod script_info;
pub mod styles;
pub use events::EventsParser;
pub use script_info::ScriptInfoParser;
pub use styles::StylesParser;
use crate::parser::ast::{Section, SectionType};
use crate::parser::errors::{ParseError, ParseResult};
use alloc::vec::Vec;
#[derive(Clone, Debug)]
pub struct SectionFormats<'a> {
pub styles_format: Option<Vec<&'a str>>,
pub events_format: Option<Vec<&'a str>>,
}
pub fn parse_section_with_context<'a>(
section_type: SectionType,
text: &'a str,
line_offset: u32,
existing_formats: &SectionFormats<'a>,
) -> ParseResult<Section<'a>> {
match section_type {
SectionType::ScriptInfo => {
let parser = ScriptInfoParser::new(text, 0, line_offset as usize);
let (section, ..) = parser.parse()?;
Ok(section)
}
SectionType::Styles => {
let format = existing_formats
.styles_format
.as_ref()
.ok_or(ParseError::MissingFormat)?;
let parser = StylesParser::with_format(text, format, 0, line_offset);
let (section, ..) = parser.parse()?;
Ok(section)
}
SectionType::Events => {
let format = existing_formats
.events_format
.as_ref()
.ok_or(ParseError::MissingFormat)?;
let parser = EventsParser::with_format(text, format, 0, line_offset);
let (section, ..) = parser.parse()?;
Ok(section)
}
SectionType::Fonts | SectionType::Graphics => {
Err(ParseError::UnsupportedSection(section_type))
}
}
}
pub type SectionParseResult<'a> = (
crate::parser::ast::Section<'a>,
Option<Vec<&'a str>>,
Vec<crate::parser::errors::ParseIssue>,
usize,
usize,
);
pub type ScriptInfoParseResult<'a> = (
crate::parser::ast::Section<'a>,
Option<crate::ScriptVersion>,
Vec<crate::parser::errors::ParseIssue>,
usize,
usize,
);