Tool

Trait Tool 

Source
pub trait Tool<'a> {
    type Error;
    type Data;

    // Required method
    fn parse(
        &self,
        st: View<'a>,
    ) -> Result<(Self::Data, usize, View<'a>), Self::Error>;
}
Expand description

Parsing tool trait.

An object implementing this trait represents a parsing rule that are applied to string prefixes. If any prefix of a string satisfy this rule then the match is successful and additional data parsed from the matching prefix is returned. If instead no prefix satisfies the rule then an error is returned.

Required Associated Types§

Source

type Error

Error type.

Source

type Data

Associated data type.

Required Methods§

Source

fn parse( &self, st: View<'a>, ) -> Result<(Self::Data, usize, View<'a>), Self::Error>

The main parsing algorithm.

On a successful match, it additionally returns the parsed data and the length of the match in bytes.

§Errors

If no prefix of st satisfies this parsing strategy then Error is returned.

Implementations on Foreign Types§

Source§

impl<'a> Tool<'a> for char

Matches exactly the first character.

Source§

type Error = View<'a>

Source§

type Data = char

Source§

fn parse( &self, st: View<'a>, ) -> Result<(Self::Data, usize, View<'a>), Self::Error>

Source§

impl<'a> Tool<'a> for str

Matches exactly the string prefix.

Source§

type Error = View<'a>

Source§

type Data = &'a str

Source§

fn parse( &self, st: View<'a>, ) -> Result<(Self::Data, usize, View<'a>), Self::Error>

Source§

impl<'a, T> Tool<'a> for &T
where T: Tool<'a> + ?Sized,

Source§

type Error = <T as Tool<'a>>::Error

Source§

type Data = <T as Tool<'a>>::Data

Source§

fn parse( &self, st: View<'a>, ) -> Result<(Self::Data, usize, View<'a>), Self::Error>

Source§

impl<'a, T> Tool<'a> for [T]
where T: Tool<'a>,

Matches any tool in the given slice.

Tools are evaluated with increasing index ordering, so a later tool would not be tested is a previous tool has already matched.

Source§

type Error = Option<<T as Tool<'a>>::Error>

Only the last error is returned.

If you want to keep track of every returned error, use instead multiple nested instances of Or tool.

Source§

type Data = (usize, <T as Tool<'a>>::Data)

Source§

fn parse( &self, st: View<'a>, ) -> Result<(Self::Data, usize, View<'a>), Self::Error>

Source§

impl<'a, T, const N: usize> Tool<'a> for [T; N]
where T: Tool<'a>,

Matches any tool in the given array.

Tools are evaluated with increasing index ordering, so a later tool would not be tested is a previous tool has already matched.

Source§

type Error = Option<<T as Tool<'a>>::Error>

Only the last error is returned.

If you want to keep track of every returned error, use instead multiple nested instances of Or tool.

Source§

type Data = (usize, <T as Tool<'a>>::Data)

Source§

fn parse( &self, st: View<'a>, ) -> Result<(Self::Data, usize, View<'a>), Self::Error>

Implementors§

Source§

impl<'a> Tool<'a> for AsciiNumber

Source§

impl<'a> Tool<'a> for Ident

Source§

type Data = &'a str

Source§

type Error = View<'a>

Source§

impl<'a> Tool<'a> for Newline

Source§

impl<'a> Tool<'a> for PfxAsciiNumber

Source§

impl<'a> Tool<'a> for WhiteSP

Source§

impl<'a> Tool<'a> for AnyChar

Source§

impl<'a> Tool<'a> for EOFTool

Source§

impl<'a> Tool<'a> for TrueTool

Source§

impl<'a, D, P: Fn(char) -> Option<D>> Tool<'a> for PredicateData<P>

Source§

type Data = D

Source§

type Error = View<'a>

Source§

impl<'a, F, S> Tool<'a> for Or<F, S>
where F: Tool<'a>, S: Tool<'a>,

Source§

type Data = Either<<F as Tool<'a>>::Data, <S as Tool<'a>>::Data>

Source§

type Error = (<F as Tool<'a>>::Error, <S as Tool<'a>>::Error)

Source§

impl<'a, F, S> Tool<'a> for Seq<F, S>
where F: Tool<'a>, S: Tool<'a>,

Source§

type Data = (<F as Tool<'a>>::Data, <S as Tool<'a>>::Data)

Source§

type Error = Either<<F as Tool<'a>>::Error, <S as Tool<'a>>::Error>

Source§

impl<'a, P> Tool<'a> for NonEmpty<P>
where P: Tool<'a>,

Source§

type Data = <P as Tool<'a>>::Data

Source§

type Error = Option<<P as Tool<'a>>::Error>

Source§

impl<'a, P: Fn(char) -> bool> Tool<'a> for Predicate<P>

Source§

impl<'a, T> Tool<'a> for Check<T>
where T: Tool<'a>,

Source§

type Error = <T as Tool<'a>>::Error

Source§

type Data = <T as Tool<'a>>::Data

Source§

impl<'a, T> Tool<'a> for CheckInv<T>
where T: Tool<'a>,

Source§

type Error = <T as Tool<'a>>::Data

Source§

type Data = <T as Tool<'a>>::Error

Source§

impl<'a, T, D, E, FD, FE> Tool<'a> for MapTool<T, FD, FE>
where T: Tool<'a>, FD: Fn(T::Data) -> D, FE: Fn(T::Error) -> E,

Source§

type Data = D

Source§

type Error = E

Source§

impl<'a, T, E> Tool<'a> for SetError<T, E>
where T: AlwaysTool<'a>,

Source§

type Error = E

Source§

type Data = <T as Tool<'a>>::Data

Source§

impl<'a, T, SEP> Tool<'a> for RepeatAny<T, SEP>
where T: Tool<'a>, SEP: Tool<'a>,

Source§

impl<'a, T, SEP, E> Tool<'a> for Repeat<T, SEP>
where T: Tool<'a, Error = E>, SEP: Tool<'a, Error = E>,

Source§

impl<'a, T, SEP, TERM> Tool<'a> for LazyRepeatAny<T, SEP, TERM>
where T: Tool<'a>, SEP: Tool<'a>, TERM: Tool<'a>,

Source§

type Data = usize

Source§

type Error = <TERM as Tool<'a>>::Error

Source§

impl<'a, T, SEP, TERM, E> Tool<'a> for LazyRepeat<T, SEP, TERM>
where T: Tool<'a, Error = E>, SEP: Tool<'a, Error = E>, TERM: Tool<'a, Error = E>,