mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 08:11:12 +00:00
Revert "try some boxed stuff"
This reverts commit 101048a6b33b726cf956bbdfcdb266084d13bb55.
This commit is contained in:
parent
3f81845de5
commit
8fcc9504af
1 changed files with 7 additions and 22 deletions
|
@ -188,23 +188,10 @@ impl Keyword {
|
||||||
|
|
||||||
pub trait Parser<'a, Output> {
|
pub trait Parser<'a, Output> {
|
||||||
fn parse(&self, &'a Bump, State<'a>) -> ParseResult<'a, Output>;
|
fn parse(&self, &'a Bump, State<'a>) -> ParseResult<'a, Output>;
|
||||||
|
|
||||||
fn arena(&self) -> &'a Bump;
|
|
||||||
|
|
||||||
fn map<F, NewOutput>(self, transform: F) -> BoxedParser<'a, NewOutput>
|
|
||||||
where
|
|
||||||
Self: Sized + 'a,
|
|
||||||
Output: 'a,
|
|
||||||
NewOutput: 'a,
|
|
||||||
F: Fn(Output) -> NewOutput + 'a,
|
|
||||||
{
|
|
||||||
BoxedParser::new(self.arena(), map(self, transform))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct BoxedParser<'a, Output> {
|
pub struct BoxedParser<'a, Output> {
|
||||||
parser: &'a (dyn Parser<'a, Output> + 'a),
|
parser: &'a (dyn Parser<'a, Output> + 'a),
|
||||||
arena: &'a Bump,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Output> BoxedParser<'a, Output> {
|
impl<'a, Output> BoxedParser<'a, Output> {
|
||||||
|
@ -214,18 +201,16 @@ impl<'a, Output> BoxedParser<'a, Output> {
|
||||||
{
|
{
|
||||||
BoxedParser {
|
BoxedParser {
|
||||||
parser: arena.alloc(parser),
|
parser: arena.alloc(parser),
|
||||||
arena,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Output> Parser<'a, Output> for BoxedParser<'a, Output> {
|
impl<'a, F, Output> Parser<'a, Output> for F
|
||||||
|
where
|
||||||
|
F: Fn(&'a Bump, State<'a>) -> ParseResult<'a, Output>,
|
||||||
|
{
|
||||||
fn parse(&self, arena: &'a Bump, state: State<'a>) -> ParseResult<'a, Output> {
|
fn parse(&self, arena: &'a Bump, state: State<'a>) -> ParseResult<'a, Output> {
|
||||||
self.parser.parse(arena, state)
|
self(arena, state)
|
||||||
}
|
|
||||||
|
|
||||||
fn arena(&self) -> &'a Bump {
|
|
||||||
self.arena
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -245,7 +230,7 @@ where
|
||||||
move |arena, state| get_parser().parse(arena, state)
|
move |arena, state| get_parser().parse(arena, state)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn map<'a, P, F, Before, After>(parser: P, transform: F) -> impl Parser<'a, After>
|
pub fn map<'a, P, F, Before, After>(parser: P, transform: F) -> impl Parser<'a, After>
|
||||||
where
|
where
|
||||||
P: Parser<'a, Before>,
|
P: Parser<'a, Before>,
|
||||||
F: Fn(Before) -> After,
|
F: Fn(Before) -> After,
|
||||||
|
@ -257,7 +242,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn map_with_arena<'a, P, F, Before, After>(parser: P, transform: F) -> impl Parser<'a, After>
|
pub fn map_with_arena<'a, P, F, Before, After>(parser: P, transform: F) -> impl Parser<'a, After>
|
||||||
where
|
where
|
||||||
P: Parser<'a, Before>,
|
P: Parser<'a, Before>,
|
||||||
F: Fn(&'a Bump, Before) -> After,
|
F: Fn(&'a Bump, Before) -> After,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue