pub trait Parser {
type Context;
type Error;
// Required methods
fn reset_parser(&mut self) -> Result<(), Self::Error>;
fn fetch_lineno(&self) -> Result<usize, Self::Error>;
fn add_fetch_lineno(&mut self, val: usize) -> Result<usize, Self::Error>;
fn push_context(
&mut self,
context: Self::Context,
) -> Result<(), Self::Error>;
fn pop_context(&mut self) -> Result<Option<Self::Context>, Self::Error>;
fn peek_context(&self) -> Result<Option<&Self::Context>, Self::Error>;
}
Expand description
Manage parser state, active filename context, and line number metadata.
Parsers maintain a stack of Context
s which are modified as successive
sources are parsed, for example as a set of nested require
s.
Required Associated Types§
Required Methods§
Sourcefn reset_parser(&mut self) -> Result<(), Self::Error>
fn reset_parser(&mut self) -> Result<(), Self::Error>
Reset parser state to initial values.
§Errors
If the parser state is inaccessible, an error is returned.
Sourcefn fetch_lineno(&self) -> Result<usize, Self::Error>
fn fetch_lineno(&self) -> Result<usize, Self::Error>
Fetch the current line number from the parser state.
§Errors
If the parser state is inaccessible, an error is returned.
Sourcefn add_fetch_lineno(&mut self, val: usize) -> Result<usize, Self::Error>
fn add_fetch_lineno(&mut self, val: usize) -> Result<usize, Self::Error>
Increment line number and return the new value.
§Errors
If the parser state is inaccessible, an error is returned.
This function returns IncrementLinenoError
if the increment results
in an overflow of the internal parser line number counter.
Sourcefn push_context(&mut self, context: Self::Context) -> Result<(), Self::Error>
fn push_context(&mut self, context: Self::Context) -> Result<(), Self::Error>
Set the currently active context by modifying the parser stack.
§Errors
If the parser state is inaccessible, an error is returned.