Atom

Trait Atom 

Source
pub trait Atom {
    // Required method
    fn parse(&self, st: &str) -> Option<Match>;

    // Provided methods
    fn as_dyn(&self) -> &dyn Atom
       where Self: Sized { ... }
    fn into_tool(self) -> AtomTool<Self>
       where Self: Sized { ... }
}
Expand description

The main parsing trait

Every object which incapsulate a parsing strategy should implement this trait in order to be composed with other atoms.

Required Methods§

Source

fn parse(&self, st: &str) -> Option<Match>

The main parsing algorithm.

§Errors

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

Provided Methods§

Source

fn as_dyn(&self) -> &dyn Atom
where Self: Sized,

Coerce to dyn trait

Source

fn into_tool(self) -> AtomTool<Self>
where Self: Sized,

Converts this atom into a ParseTool.

The generated tool will always return the matched string as data, and the View pointing at the beginning of the string in case of a failed match. More information can be found at the documentation of AtomTool;

Implementations on Foreign Types§

Source§

impl Atom for char

Matches the first character exactly.

use minparser::prelude::MatchHelper;
let view = Into::<MatchHelper>::into("My data");
view.match_atom('M').unwrap().match_atom('y').unwrap();
Source§

fn parse(&self, st: &str) -> Option<Match>

Source§

impl Atom for fn(&char) -> bool

Source§

fn parse(&self, st: &str) -> Option<Match>

Source§

impl Atom for fn(char) -> bool

Source§

fn parse(&self, st: &str) -> Option<Match>

Source§

impl Atom for fn(MatchHelper<'_>) -> Result<MatchHelper<'_>, MatchHelper<'_>>

Source§

fn parse(&self, st: &str) -> Option<Match>

Source§

impl Atom for fn(MatchHelper<'_>) -> MatchHelper<'_>

Source§

fn parse(&self, st: &str) -> Option<Match>

Source§

impl Atom for str

Matches a string exactly

use minparser::prelude::*;
let view = Into::<MatchHelper>::into("My data ");
view.match_atom("My dat").unwrap().match_atom("a ").unwrap();
Source§

fn parse(&self, st: &str) -> Option<Match>

Source§

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

Source§

fn parse(&self, st: &str) -> Option<Match>

Source§

impl<R> Atom for [R]
where R: Atom,

Matches any of the atoms in the slice.

use minparser::prelude::MatchHelper;
let view = Into::<MatchHelper>::into("My data");
view.match_atom(&['M', 'K', 'O']).unwrap().match_atom(&["ser", "ii", "y d"]).unwrap();
Source§

fn parse(&self, st: &str) -> Option<Match>

Source§

impl<R, const N: usize> Atom for [R; N]
where R: Atom,

Matches any of the atoms in the array.

use minparser::atoms::MatchHelper;
let view = Into::<MatchHelper>::into("My data");
view.match_atom(['M', 'K', 'O']).unwrap().match_atom(["ser", "ii", "y d"]).unwrap();
Source§

fn parse(&self, st: &str) -> Option<Match>

Source§

impl<T> Atom for Box<T>
where T: Atom + ?Sized,

Available on crate features alloc only.
Source§

fn parse(&self, st: &str) -> Option<Match>

Implementors§

Source§

impl Atom for AnyChar

Source§

impl Atom for EOFChar

Source§

impl Atom for TrueAtom

Source§

impl Atom for AlphabeticTool

Source§

impl Atom for AlphanumericTool

Source§

impl Atom for AsciiAlphabeticTool

Source§

impl Atom for AsciiAlphanumericTool

Source§

impl Atom for AsciiDigitTool

Source§

impl Atom for AsciiTool

Source§

impl Atom for NumericTool

Source§

impl Atom for WhitespaceTool

Source§

impl Atom for Ident

Source§

impl Atom for Newline

Source§

impl Atom for WhiteSP

Source§

impl<F, S> Atom for Or<F, S>
where F: Atom, S: Atom,

Source§

impl<F, S> Atom for Seq<F, S>
where F: Atom, S: Atom,

Source§

impl<P: Fn(&char) -> bool> Atom for PredicateRefAtom<P>

Source§

impl<P: Fn(char) -> bool> Atom for PredicateAtom<P>

Source§

impl<P: Atom> Atom for NonEmpty<P>

Source§

impl<T> Atom for CheckInvTool<T>
where T: Atom,

Source§

impl<T> Atom for CheckTool<T>
where T: Atom,

Source§

impl<T, SEP> Atom for RepeatAnyAtom<T, SEP>
where T: Atom, SEP: Atom,

Source§

impl<T, SEP> Atom for RepeatAtom<T, SEP>
where T: Atom, SEP: Atom,

Source§

impl<T, SEP, TERM> Atom for LazyRepeatAtom<T, SEP, TERM>
where T: Atom, SEP: Atom, TERM: Atom,