Refrence lifetimes
This commit is contained in:
@@ -16,6 +16,8 @@ pub struct Block(pub Vec<Statement>);
|
||||
pub enum TypePostfix {
|
||||
Ref,
|
||||
RefMut,
|
||||
RefLifetime(Identifier),
|
||||
RefMutLifetime(Identifier),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
|
||||
@@ -71,7 +71,7 @@ path_type = {
|
||||
}
|
||||
|
||||
ref_type = {
|
||||
mutable? ~ "*"
|
||||
mutable? ~ lifetime? ~ "*"
|
||||
}
|
||||
|
||||
type_expr = {
|
||||
|
||||
+16
-4
@@ -49,14 +49,26 @@ impl From<pest::iterators::Pair<'_, Rule>> for TypeExpr {
|
||||
impl From<pest::iterators::Pair<'_, Rule>> for TypePostfix {
|
||||
fn from(pair: pest::iterators::Pair<'_, Rule>) -> Self {
|
||||
let rule = pair.as_rule();
|
||||
let inner = pair.into_inner();
|
||||
let mut inner = pair.into_inner();
|
||||
|
||||
match rule {
|
||||
Rule::ref_type => {
|
||||
if inner.peek().is_some() {
|
||||
TypePostfix::RefMut
|
||||
let mutable = listen_rule(&mut inner, Rule::mutable);
|
||||
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 {
|
||||
TypePostfix::Ref
|
||||
}
|
||||
} else {
|
||||
TypePostfix::Ref
|
||||
if let Some(lifetime) = lifetime {
|
||||
TypePostfix::RefLifetime(lifetime)
|
||||
} else {
|
||||
TypePostfix::RefMut
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => unimplemented!("{rule:#?}"),
|
||||
|
||||
Reference in New Issue
Block a user