34 lines
667 B
Rust
34 lines
667 B
Rust
|
use crate::bnf::Bnf;
|
||
|
use crate::parser::{ParseResult, Parser, ParserInput};
|
||
|
|
||
|
pub struct BoxedParser<'a, I, O, E>
|
||
|
where
|
||
|
I: ParserInput,
|
||
|
{
|
||
|
inner: Box<dyn Parser<I, O, E> + 'a>,
|
||
|
}
|
||
|
|
||
|
impl<'a, I, O, E> BoxedParser<'a, I, O, E>
|
||
|
where
|
||
|
I: ParserInput,
|
||
|
{
|
||
|
pub(crate) fn new<P>(inner: P) -> Self
|
||
|
where
|
||
|
P: Parser<I, O, E> + 'a,
|
||
|
{
|
||
|
BoxedParser {
|
||
|
inner: Box::new(inner),
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
impl<'a, I: ParserInput, O, E> Parser<I, O, E> for BoxedParser<'a, I, O, E> {
|
||
|
fn parse(&self, input: I) -> ParseResult<I, O, E> {
|
||
|
self.inner.parse(input)
|
||
|
}
|
||
|
|
||
|
fn bnf(&self) -> Option<Bnf> {
|
||
|
self.inner.bnf()
|
||
|
}
|
||
|
}
|