artichoke_core::parser

Trait Parser

Source
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 Contexts which are modified as successive sources are parsed, for example as a set of nested requires.

Required Associated Types§

Source

type Context

Concrete type for parser context.

Source

type Error

Error type for Parser APIs.

Required Methods§

Source

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.

Source

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.

Source

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.

Source

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.

Source

fn pop_context(&mut self) -> Result<Option<Self::Context>, Self::Error>

Remove the current active context and return it.

§Errors

If the parser state is inaccessible, an error is returned.

Source

fn peek_context(&self) -> Result<Option<&Self::Context>, Self::Error>

Return a reference to the currently active context.

§Errors

If the parser state is inaccessible, an error is returned.

Implementors§