Refrence lifetimes

This commit is contained in:
2026-05-10 00:35:14 +02:00
parent 910657c755
commit 3e25bf0456
4 changed files with 21 additions and 5 deletions
+2
View File
@@ -16,6 +16,8 @@ pub struct Block(pub Vec<Statement>);
pub enum TypePostfix { pub enum TypePostfix {
Ref, Ref,
RefMut, RefMut,
RefLifetime(Identifier),
RefMutLifetime(Identifier),
} }
#[derive(Debug, Clone, Serialize)] #[derive(Debug, Clone, Serialize)]
+1 -1
View File
@@ -71,7 +71,7 @@ path_type = {
} }
ref_type = { ref_type = {
mutable? ~ "*" mutable? ~ lifetime? ~ "*"
} }
type_expr = { type_expr = {
+15 -3
View File
@@ -49,15 +49,27 @@ impl From<pest::iterators::Pair<'_, Rule>> for TypeExpr {
impl From<pest::iterators::Pair<'_, Rule>> for TypePostfix { impl From<pest::iterators::Pair<'_, Rule>> for TypePostfix {
fn from(pair: pest::iterators::Pair<'_, Rule>) -> Self { fn from(pair: pest::iterators::Pair<'_, Rule>) -> Self {
let rule = pair.as_rule(); let rule = pair.as_rule();
let inner = pair.into_inner(); let mut inner = pair.into_inner();
match rule { match rule {
Rule::ref_type => { Rule::ref_type => {
if inner.peek().is_some() { let mutable = listen_rule(&mut inner, Rule::mutable);
TypePostfix::RefMut let lifetime = consume_rule(&mut inner, Rule::lifetime)
.map(|pair| Identifier::from(pair.into_inner().next().unwrap()));
if mutable {
if let Some(lifetime) = lifetime {
TypePostfix::RefMutLifetime(lifetime)
} else { } else {
TypePostfix::Ref TypePostfix::Ref
} }
} else {
if let Some(lifetime) = lifetime {
TypePostfix::RefLifetime(lifetime)
} else {
TypePostfix::RefMut
}
}
} }
_ => unimplemented!("{rule:#?}"), _ => unimplemented!("{rule:#?}"),
} }
+2
View File
@@ -634,6 +634,8 @@ impl GetRust for TypePostfix {
match self { match self {
TypePostfix::Ref => format!("&"), TypePostfix::Ref => format!("&"),
TypePostfix::RefMut => format!("&mut "), TypePostfix::RefMut => format!("&mut "),
TypePostfix::RefLifetime(lifetime) => format!("&'{} ", lifetime.get_rust()),
TypePostfix::RefMutLifetime(lifetime) => format!("&'{} mut ", lifetime.get_rust()),
} }
} }
} }