use std::collections::HashSet;
use crate::cache::Cache;
use crate::error::ParserError;
#[cfg(feature = "parser-trace")]
use crate::trace::TraceState;
pub struct ParserContext<'src> {
pub cache: Cache<'src>,
pub error_sink: Vec<ParserError>,
pub registered_error_set: HashSet<(usize, usize)>,
pub error_stack: Vec<ParserError>,
pub is_in_error_recovery: bool,
#[cfg(feature = "parser-trace")]
pub(crate) trace: Option<TraceState>,
_marker: std::marker::PhantomData<&'src ()>,
}
impl<'src> ParserContext<'src> {
#[inline]
pub fn new() -> Self {
Self {
cache: Cache::new(),
error_sink: Vec::new(),
registered_error_set: HashSet::new(),
error_stack: Vec::new(),
is_in_error_recovery: false,
#[cfg(feature = "parser-trace")]
trace: None,
_marker: std::marker::PhantomData,
}
}
#[inline]
pub fn get_errors(mut self) -> Vec<ParserError> {
self.error_sink.extend(self.error_stack);
self.error_sink
}
#[inline]
pub fn push_stack_error(&mut self, error: ParserError) {
self.error_stack.push(error);
}
}