pub trait Parser<I: InputType, O, E: ParserExtras<I>> {
Show 17 methods
// Required methods
fn parse<'parse>(
&self,
input: Input<'parse, I, E>,
) -> IResult<'parse, I, E, O>;
fn check<'parse>(
&self,
input: Input<'parse, I, E>,
) -> IResult<'parse, I, E, ()>;
// Provided methods
fn parse_from<'parse>(
&self,
input: &'parse I,
) -> ParseResult<'parse, I, O, E>
where E: ParserExtras<I, Context = ()> { ... }
fn or<P: Parser<I, O, E>>(self, other: P) -> Or<Self, P>
where Self: Sized { ... }
fn map<U, F: Fn(O) -> U>(self, mapper: F) -> Map<Self, O, F, U>
where Self: Sized { ... }
fn to<U>(self, value: U) -> To<Self, O, U>
where Self: Sized { ... }
fn ignored(self) -> Ignored<Self, O>
where Self: Sized { ... }
fn try_map<F: Fn(U) -> Result<U, E::Error>, U>(
self,
f: F,
) -> TryMap<Self, F, O, U>
where Self: Sized { ... }
fn try_map_with_span<F: Fn(U, Range<I::Offset>) -> Result<U, E::Error>, U>(
self,
f: F,
) -> TryMapWithSpan<Self, F, O, U>
where Self: Sized { ... }
fn filter<F: Fn(&O) -> bool>(self, f: F) -> FilterParser<Self, F, O>
where Self: Sized { ... }
fn repeated(self) -> Repeated<Self, O, Vec<O>>
where Self: Sized { ... }
fn repeated_custom<V: FromIterator<O>>(self) -> Repeated<Self, O, V>
where Self: Sized { ... }
fn slice<'a>(self) -> Slice<'a, I, E, O, Self>
where I: SliceInput<'a>,
Self: Sized { ... }
fn then<O2, P: Parser<I, O2, E>>(
self,
other: P,
) -> Then<O, O2, Self, P, true, false>
where Self: Sized { ... }
fn ignore_then<O2, P: Parser<I, O2, E>>(
self,
other: P,
) -> Then<O, O2, Self, P, false, true>
where Self: Sized { ... }
fn then_ignore<O2, P: Parser<I, O2, E>>(
self,
other: P,
) -> Then<O, O2, Self, P, false, false>
where Self: Sized { ... }
fn optional(self) -> Maybe<Self>
where Self: Sized { ... }
}
Required Methods§
Provided Methods§
fn parse_from<'parse>(&self, input: &'parse I) -> ParseResult<'parse, I, O, E>where
E: ParserExtras<I, Context = ()>,
fn or<P: Parser<I, O, E>>(self, other: P) -> Or<Self, P>where
Self: Sized,
Sourcefn map<U, F: Fn(O) -> U>(self, mapper: F) -> Map<Self, O, F, U>where
Self: Sized,
fn map<U, F: Fn(O) -> U>(self, mapper: F) -> Map<Self, O, F, U>where
Self: Sized,
Transforms this parser’s output with the mapper
function.
The mapper
function cannot return an error. If you want to, consider using Parser::try_map
§Example
let input = "hisnameisjuan";
#[aott::derive::parser]
fn parser(input: &str) -> (&'a str, &'a str) {
tuple((
choice((just("his"), just("her"))),
just("name"), just("is"),
any.repeated().slice(),
end
)).map(|(pronoun, _, _, name, _)| (pronoun, name)).parse(input)
}
let (pronoun, name) = parser.parse_from(&input).into_result().unwrap();
assert_eq!(pronoun, "his");
assert_eq!(name, "juan");
fn to<U>(self, value: U) -> To<Self, O, U>where
Self: Sized,
fn ignored(self) -> Ignored<Self, O>where
Self: Sized,
fn try_map<F: Fn(U) -> Result<U, E::Error>, U>(
self,
f: F,
) -> TryMap<Self, F, O, U>where
Self: Sized,
fn try_map_with_span<F: Fn(U, Range<I::Offset>) -> Result<U, E::Error>, U>(
self,
f: F,
) -> TryMapWithSpan<Self, F, O, U>where
Self: Sized,
fn filter<F: Fn(&O) -> bool>(self, f: F) -> FilterParser<Self, F, O>where
Self: Sized,
Sourcefn repeated(self) -> Repeated<Self, O, Vec<O>>where
Self: Sized,
fn repeated(self) -> Repeated<Self, O, Vec<O>>where
Self: Sized,
§Example
use aott::text::Char;
let parser = filter::<&str, extra::Err<&str>>(|c: &char| c.is_ident_start()).then(filter(|c: &char| c.is_ident_continue()).repeated());
assert_eq!(parser.parse_from(&"hello").into_result(), Ok(('h', "ello".chars().collect())));