Refrence lifetimes
This commit is contained in:
@@ -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)]
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ path_type = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ref_type = {
|
ref_type = {
|
||||||
mutable? ~ "*"
|
mutable? ~ lifetime? ~ "*"
|
||||||
}
|
}
|
||||||
|
|
||||||
type_expr = {
|
type_expr = {
|
||||||
|
|||||||
+15
-3
@@ -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:#?}"),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user