[−][src]Trait lip::Parser
Required methods
fn parse(
&self,
input: &'a str,
location: Location,
state: State
) -> ParseResult<'a, Output, State>
&self,
input: &'a str,
location: Location,
state: State
) -> ParseResult<'a, Output, State>
Run the parser on a given input, starting at a given location and state.
Provided methods
fn map<F, NewOutput>(self, map_fn: F) -> BoxedParser<'a, NewOutput, State> where
Self: Sized + 'a,
Output: 'a,
NewOutput: 'a,
State: 'a,
F: Fn(Output) -> NewOutput + 'a,
Self: Sized + 'a,
Output: 'a,
NewOutput: 'a,
State: 'a,
F: Fn(Output) -> NewOutput + 'a,
Map the output to a new output if parse succeeds. Otherwise, return error as usual.
The only difference from the map
on ParseResult
is that this map
turns one Parser
into another while the map
on ParseResult
turns one ParseResult
into another.
fn map_with_state<F, NewOutput>(
self,
map_fn: F
) -> BoxedParser<'a, NewOutput, State> where
Self: Sized + 'a,
Output: 'a,
NewOutput: 'a,
State: 'a,
F: Fn(Output, State) -> NewOutput + 'a,
self,
map_fn: F
) -> BoxedParser<'a, NewOutput, State> where
Self: Sized + 'a,
Output: 'a,
NewOutput: 'a,
State: 'a,
F: Fn(Output, State) -> NewOutput + 'a,
The map function is supplied both the output and the state of the parser. Otherwise, return error as usual.
The only difference from the map_with_state
on ParseResult
is that this map_with_state
turns one Parser
into another while the map_with_state
on ParseResult
turns one ParseResult
into another.
fn map_err<F>(self, map_fn: F) -> BoxedParser<'a, Output, State> where
Self: Sized + 'a,
Output: 'a,
State: 'a,
F: Fn(String) -> String + 'a,
Self: Sized + 'a,
Output: 'a,
State: 'a,
F: Fn(String) -> String + 'a,
Map the error message to a new message if parse fails. Otherwise, return output as usual.
The only difference from the map_err
on ParseResult
is that this map_err
turns one Parser
into another while the map_err
on ParseResult
turns one ParseResult
into another.
fn and_then<F, NextParser, NewOutput>(
self,
f: F
) -> BoxedParser<'a, NewOutput, State> where
Self: Sized + 'a,
Output: 'a,
NewOutput: 'a,
State: 'a,
NextParser: Parser<'a, NewOutput, State> + 'a,
F: Fn(Output) -> NextParser + 'a,
self,
f: F
) -> BoxedParser<'a, NewOutput, State> where
Self: Sized + 'a,
Output: 'a,
NewOutput: 'a,
State: 'a,
NextParser: Parser<'a, NewOutput, State> + 'a,
F: Fn(Output) -> NextParser + 'a,
Returns a new parser which is given the current output if parse succeeds. Otherwise, return error as usual.
The only difference from the and_then
on ParseResult
is that this and_then
turns one Parser
into another while the and_then
on ParseResult
turns one ParseResult
into another.
fn pred<F>(
self,
predicate: F,
expecting: &'a str
) -> BoxedParser<'a, Output, State> where
Self: Sized + 'a,
Output: Display + 'a,
State: 'a,
F: Fn(&Output) -> bool + 'a,
self,
predicate: F,
expecting: &'a str
) -> BoxedParser<'a, Output, State> where
Self: Sized + 'a,
Output: Display + 'a,
State: 'a,
F: Fn(&Output) -> bool + 'a,
Judge if the output meets the requirement using a predicate function if the parse succeeds. Otherwise, return error as usual.
fn ignore(self) -> BoxedParser<'a, (), State> where
Self: Sized + 'a,
Output: 'a,
State: 'a,
Self: Sized + 'a,
Output: 'a,
State: 'a,
Ignore the parse output and return ()
(emtpy tuple)
fn update_state<F>(self, f: F) -> BoxedParser<'a, Output, State> where
Self: Sized + 'a,
State: 'a,
Output: Clone + 'a,
F: Fn(Output, State) -> State + 'a,
Self: Sized + 'a,
State: 'a,
Output: Clone + 'a,
F: Fn(Output, State) -> State + 'a,
Update the state given the new output and state of the parse if parse succeeds. Otherwise, return error as usual.
fn update<F, NewOutput>(self, f: F) -> BoxedParser<'a, NewOutput, State> where
Self: Sized + 'a,
State: 'a,
Output: Clone + 'a,
NewOutput: Clone + 'a,
F: Fn(&'a str, Output, Location, State) -> ParseResult<'a, NewOutput, State> + 'a,
Self: Sized + 'a,
State: 'a,
Output: Clone + 'a,
NewOutput: Clone + 'a,
F: Fn(&'a str, Output, Location, State) -> ParseResult<'a, NewOutput, State> + 'a,
Update the result of the parser if parse succeeds. Otherwise, return error as usual.
This is the most general and powerful method of the parser.
Think about using simpler methods like map
and map_err
before
choosing update
.
fn end(self) -> BoxedParser<'a, Output, State> where
Self: Sized + 'a,
Output: Clone + 'a,
State: 'a,
Self: Sized + 'a,
Output: Clone + 'a,
State: 'a,
Check if you have reached the end of the input you are parsing.
If you want to parse an input containing only "abc":
succeed( token("abc").end(), "abc", "abc", ); fail( token("abc").end(), "abcd", "I'm expecting the end of input.", );
Implementors
impl<'a, F, Output, State: 'a> Parser<'a, Output, State> for F where
F: Fn(&'a str, Location, State) -> ParseResult<'a, Output, State>,
State: Clone,
[src]
F: Fn(&'a str, Location, State) -> ParseResult<'a, Output, State>,
State: Clone,
fn parse(
&self,
input: &'a str,
location: Location,
state: State
) -> ParseResult<'a, Output, State>
[src]
&self,
input: &'a str,
location: Location,
state: State
) -> ParseResult<'a, Output, State>
impl<'a, Output, State> Parser<'a, Output, State> for BoxedParser<'a, Output, State> where
State: Clone,
[src]
State: Clone,
fn parse(
&self,
input: &'a str,
location: Location,
state: State
) -> ParseResult<'a, Output, State>
[src]
&self,
input: &'a str,
location: Location,
state: State
) -> ParseResult<'a, Output, State>