Trait parce::parser::Parse[][src]

pub trait Parse<O: Parseable>: ToString {
    fn parse_max(&self) -> Result<(O, ParseCompletion), ParceError>;
fn parse_all(&self) -> Result<O, ParceError>; }
Expand description

Trait for parsing types that implement ToString into types that implement Parseable.

NOTE most users will just want to use the FromStr trait, which is implemented for all parsers. Unfortunately that is difficult to document because it cannot be done with a blanket implementation due to orphan rules. The generated FromStr implementation just delegates directly to Parse::parse_all.

This is implemented by default for all types that implement ToString, you do not need to implement it yourself.

Example

use parce::prelude::*;

#[lexer(MyLexer)]
enum MyLexemes {
    A = "'a'",
    B = "'b'"
}

#[parser(MyLexer)] // generates a Parseable implementation for MyGrammar
enum MyGrammar {
    Rule = "A B"
}

fn main() {
    let parsed: MyGrammar = "ab".parse_all().unwrap();
}

Required methods

Parses the production that matches the most number of lexemes. Might not use the entire set of lexemes.

If successful, returns a tuple (rule, completion) where completion indicates how many lexemes were used. If unsuccessful, returns ParceError.

Parses a rule and requires that it uses all of the input lexemes. Returns an error if no productions use all of the input.

Implementors