Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixup lifetimes of PrattParser #824

Merged
merged 1 commit into from
Mar 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions pest/src/pratt_parser.rs
Original file line number Diff line number Diff line change
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