Trait parsimonious::ParserOf [] [src]

pub trait ParserOf<S> {
    type Output;
    type State: StatefulParserOf<S, Output=Self::Output>;
    fn init(&self) -> Self::State;

    fn boxable(self) -> BoxableParser<Self::State> where Self: Sized { ... }
    fn and_then<P>(self, other: P) -> AndThenParser<Self, P> where Self: Sized, P: ParserOf<S> { ... }
}

A trait for stateless parsers.

Stateful parsers are typically constructed by calling the methods of the library, for example:

let stateless = character_guard(char::is_alphanumeric).star(String::new);

Here, stateless is a ParserOf<&str,Output=String>.

The reason for distinguishing between stateful and stateless parsers is that stateless parsers are usually copyable, whereas stateful parsers are not (they may, for example, have created and partially filled some buffers). Copying parsers is quite common, for example:

let DIGIT = character(char::is_numeric);
let TWO_DIGITS = DIGIT.and_then(DIGIT);
match TWO_DIGITS.init().parse("123") {
   Done(_,result) => assert_eq!(result,(Some('1'),Some('2'))),
   _ => panic!("Can't happen"),
}

Semantically, a parser with input S and output T is a partial function S* → T whose domain is prefix-closed (that is, if s·t is in the domain, then s is in the domain) and non-empty.

Associated Types

type Output

The type of the data being produced by the parser.

type State: StatefulParserOf<S, Output=Self::Output>

The type of the parser state.

Required Methods

fn init(&self) -> Self::State

Create a stateful parser by initializing a stateless parser.

Provided Methods

fn boxable(self) -> BoxableParser<Self::State> where Self: Sized

Make this parser boxable.

fn and_then<P>(self, other: P) -> AndThenParser<Self, P> where Self: Sized, P: ParserOf<S>

Implementors