Trait arithmetic_parser::grammars::Parse[][src]

pub trait Parse<'a> {
    type Base: Grammar<'a>;

    const FEATURES: Features;
    fn parse_statements<I>(input: I) -> Result<Block<'a, Self::Base>, Error<'a>>
    where
        I: IntoInputSpan<'a>,
        Self: Sized
, { ... }
fn parse_streaming_statements<I>(
        input: I
    ) -> Result<Block<'a, Self::Base>, Error<'a>>
    where
        I: IntoInputSpan<'a>,
        Self: Sized
, { ... } }
Expand description

Unites all necessary parsers to form a complete grammar definition.

The two extension points for a Grammar are literals and type annotations. They are defined via Base type. A Grammar also defines a set of supported Features. This allows to customize which constructs are parsed.

Most common sets of Features are covered by Typed and Untyped wrappers; these types allow to not declare Parse impl explicitly. It is still possible to define custom Parse implementations, as shown in the example below.

Examples

#[derive(Debug)]
struct IntegerGrammar;

impl ParseLiteral for IntegerGrammar {
    // Implementation skipped...
}

impl Parse<'_> for IntegerGrammar {
    type Base = Untyped<Self>;
    const FEATURES: Features = Features::empty();
}

// Here's how a grammar can be used.
let program = "x = 1 + 2 * 3 + sin(a^3 / b^2);";
let parsed = IntegerGrammar::parse_statements(program)?;
println!("{:#?}", parsed);

Associated Types

type Base: Grammar<'a>[src]

Base for the grammar providing the literal and type annotation parsers.

Associated Constants

const FEATURES: Features[src]

Features supported by this grammar.

Provided methods

fn parse_statements<I>(input: I) -> Result<Block<'a, Self::Base>, Error<'a>> where
    I: IntoInputSpan<'a>,
    Self: Sized
[src]

Parses a list of statements.

fn parse_streaming_statements<I>(
    input: I
) -> Result<Block<'a, Self::Base>, Error<'a>> where
    I: IntoInputSpan<'a>,
    Self: Sized
[src]

Parses a potentially incomplete list of statements.

Implementors

impl<'a, T: Grammar<'a>> Parse<'a> for Typed<T>[src]

type Base = T

const FEATURES: Features[src]

impl<T: ParseLiteral> Parse<'_> for Untyped<T>[src]

type Base = Self

const FEATURES: Features[src]

impl<T: ParseLiteral, Ty: MockTypes> Parse<'_> for WithMockedTypes<T, Ty>[src]

type Base = Self

const FEATURES: Features[src]