mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 23:31:12 +00:00
Parse basic operators
This commit is contained in:
parent
8fcc9504af
commit
9863268793
4 changed files with 64 additions and 37 deletions
|
@ -190,21 +190,6 @@ pub trait Parser<'a, Output> {
|
|||
fn parse(&self, &'a Bump, State<'a>) -> ParseResult<'a, Output>;
|
||||
}
|
||||
|
||||
pub struct BoxedParser<'a, Output> {
|
||||
parser: &'a (dyn Parser<'a, Output> + 'a),
|
||||
}
|
||||
|
||||
impl<'a, Output> BoxedParser<'a, Output> {
|
||||
fn new<P>(arena: &'a Bump, parser: P) -> Self
|
||||
where
|
||||
P: Parser<'a, Output> + 'a,
|
||||
{
|
||||
BoxedParser {
|
||||
parser: arena.alloc(parser),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, F, Output> Parser<'a, Output> for F
|
||||
where
|
||||
F: Fn(&'a Bump, State<'a>) -> ParseResult<'a, Output>,
|
||||
|
@ -221,15 +206,6 @@ where
|
|||
move |_, state| Ok((value.clone(), state))
|
||||
}
|
||||
|
||||
/// Needed for recursive parsers
|
||||
pub fn lazy<'a, F, P, Val>(get_parser: F) -> impl Parser<'a, Val>
|
||||
where
|
||||
F: Fn() -> P,
|
||||
P: Parser<'a, Val>,
|
||||
{
|
||||
move |arena, state| get_parser().parse(arena, state)
|
||||
}
|
||||
|
||||
pub fn map<'a, P, F, Before, After>(parser: P, transform: F) -> impl Parser<'a, After>
|
||||
where
|
||||
P: Parser<'a, Before>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue