pub struct StylesParser<'a> { /* private fields */ }Expand description
Parser for [V4+ Styles] section content
Parses format definitions and style entries from the styles section. Uses format mapping to handle different field orderings and missing fields.
§Performance
- Time complexity: O(n * m) for n styles and m fields per style
- Memory: Zero allocations via lifetime-generic spans
- Target: <1ms for typical style sections with 50 styles
Implementations§
Source§impl<'a> StylesParser<'a>
impl<'a> StylesParser<'a>
Sourcepub fn parse_style_line(
line: &'a str,
format: &[&'a str],
line_number: u32,
) -> Result<Style<'a>, ParseError>
pub fn parse_style_line( line: &'a str, format: &[&'a str], line_number: u32, ) -> Result<Style<'a>, ParseError>
Parse a single style line
Parses a single style definition line using the provided format specification. This method is exposed for incremental parsing support.
§Arguments
line- The style line to parse (without “Style:” prefix)format- The format fields from the Format lineline_number- The line number for error reporting
§Returns
Parsed Style or error if the line is malformed
§Errors
Returns ParseError::InsufficientFields if the line has fewer fields than expected by format
Sourcepub fn new(source: &'a str, start_position: usize, start_line: usize) -> Self
pub fn new(source: &'a str, start_position: usize, start_line: usize) -> Self
Create new styles parser for source text
§Arguments
source- Source text to parsestart_position- Starting byte position in sourcestart_line- Starting line number for error reporting
Sourcepub fn with_format(
source: &'a str,
format: &[&'a str],
start_position: usize,
start_line: u32,
) -> Self
pub fn with_format( source: &'a str, format: &[&'a str], start_position: usize, start_line: u32, ) -> Self
Create a new parser with a pre-known format for incremental parsing
Sourcepub fn parse(self) -> ParseResult<SectionParseResult<'a>>
pub fn parse(self) -> ParseResult<SectionParseResult<'a>>
Parse styles section content
Returns the parsed section and any issues encountered during parsing. Handles Format line parsing and style entry validation.
§Returns
Tuple of (parsed_section, format_fields, parse_issues, final_position, final_line)
§Errors
Returns an error if the styles section contains malformed format lines or other unrecoverable syntax errors.