Skip to content

Commit

Permalink
Fixup lifetimes of PrattParser (#824)
Browse files Browse the repository at this point in the history
  • Loading branch information
matanui159 committed Mar 18, 2023
1 parent f294ead commit b98805c
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions pest/src/pratt_parser.rs
Expand Up @@ -235,10 +235,10 @@ impl<R: RuleType> PrattParser<R> {
}

/// Maps primary expressions with a closure `primary`.
pub fn map_primary<'pratt, 'i, X, T>(
pub fn map_primary<'pratt, 'a, 'i, X, T>(
&'pratt self,
primary: X,
) -> PrattParserMap<'pratt, 'i, R, X, T>
) -> PrattParserMap<'pratt, 'a, 'i, R, X, T>
where
X: FnMut(Pair<'i, R>) -> T,
R: 'pratt,
Expand All @@ -254,37 +254,37 @@ impl<R: RuleType> PrattParser<R> {
}
}

type PrefixFn<'i, R, T> = Box<dyn FnMut(Pair<'i, R>, T) -> T + 'i>;
type PostfixFn<'i, R, T> = Box<dyn FnMut(T, Pair<'i, R>) -> T + 'i>;
type InfixFn<'i, R, T> = Box<dyn FnMut(T, Pair<'i, R>, T) -> T + 'i>;
type PrefixFn<'a, 'i, R, T> = Box<dyn FnMut(Pair<'i, R>, T) -> T + 'a>;
type PostfixFn<'a, 'i, R, T> = Box<dyn FnMut(T, Pair<'i, R>) -> T + 'a>;
type InfixFn<'a, 'i, R, T> = Box<dyn FnMut(T, Pair<'i, R>, T) -> T + 'a>;

/// Product of calling [`map_primary`] on [`PrattParser`], defines how expressions should
/// be mapped.
///
/// [`map_primary`]: struct.PrattParser.html#method.map_primary
/// [`PrattParser`]: struct.PrattParser.html
pub struct PrattParserMap<'pratt, 'i, R, F, T>
pub struct PrattParserMap<'pratt, 'a, 'i, R, F, T>
where
R: RuleType,
F: FnMut(Pair<'i, R>) -> T,
{
pratt: &'pratt PrattParser<R>,
primary: F,
prefix: Option<PrefixFn<'i, R, T>>,
postfix: Option<PostfixFn<'i, R, T>>,
infix: Option<InfixFn<'i, R, T>>,
prefix: Option<PrefixFn<'a, 'i, R, T>>,
postfix: Option<PostfixFn<'a, 'i, R, T>>,
infix: Option<InfixFn<'a, 'i, R, T>>,
phantom: PhantomData<T>,
}

impl<'pratt, 'i, R, F, T> PrattParserMap<'pratt, 'i, R, F, T>
impl<'pratt, 'a, 'i, R, F, T> PrattParserMap<'pratt, 'a, 'i, R, F, T>
where
R: RuleType + 'pratt,
F: FnMut(Pair<'i, R>) -> T,
{
/// Maps prefix operators with closure `prefix`.
pub fn map_prefix<X>(mut self, prefix: X) -> Self
where
X: FnMut(Pair<'i, R>, T) -> T + 'i,
X: FnMut(Pair<'i, R>, T) -> T + 'a,
{
self.prefix = Some(Box::new(prefix));
self
Expand All @@ -293,7 +293,7 @@ where
/// Maps postfix operators with closure `postfix`.
pub fn map_postfix<X>(mut self, postfix: X) -> Self
where
X: FnMut(T, Pair<'i, R>) -> T + 'i,
X: FnMut(T, Pair<'i, R>) -> T + 'a,
{
self.postfix = Some(Box::new(postfix));
self
Expand All @@ -302,7 +302,7 @@ where
/// Maps infix operators with a closure `infix`.
pub fn map_infix<X>(mut self, infix: X) -> Self
where
X: FnMut(T, Pair<'i, R>, T) -> T + 'i,
X: FnMut(T, Pair<'i, R>, T) -> T + 'a,
{
self.infix = Some(Box::new(infix));
self
Expand Down

0 comments on commit b98805c

Please sign in to comment.