Update: Self param #64
This commit is contained in:
@@ -278,7 +278,7 @@ class_field = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
self_param = {
|
self_param = {
|
||||||
"self" ~ mutable? ~ deref_px?
|
(deref_px ~ lifetime?)? ~ mutable? ~ "self"
|
||||||
}
|
}
|
||||||
|
|
||||||
method_args = _{
|
method_args = _{
|
||||||
|
|||||||
@@ -22,15 +22,23 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for FunctionDecl {
|
|||||||
|
|
||||||
let self_param = consume_rule(&mut inner, Rule::self_param).map(|param| {
|
let self_param = consume_rule(&mut inner, Rule::self_param).map(|param| {
|
||||||
let mut param_inner = param.into_inner();
|
let mut param_inner = param.into_inner();
|
||||||
let mutable = listen_rule(&mut param_inner, Rule::mutable);
|
|
||||||
let is_ref = listen_rule(&mut param_inner, Rule::deref_px);
|
let is_ref = listen_rule(&mut param_inner, Rule::deref_px);
|
||||||
|
let lifetime = consume_rule(&mut param_inner, Rule::lifetime);
|
||||||
|
let mutable = listen_rule(&mut param_inner, Rule::mutable);
|
||||||
let name = Pattern::Path(mutable && !is_ref, Path(vec![Identifier(String::from("self"))]));
|
let name = Pattern::Path(mutable && !is_ref, Path(vec![Identifier(String::from("self"))]));
|
||||||
let self_ty = TypeExpr::Path(Path(vec![Identifier(String::from("Self"))]), None);
|
let self_ty = TypeExpr::Path(Path(vec![Identifier(String::from("Self"))]), None);
|
||||||
|
|
||||||
VarDecl {
|
VarDecl {
|
||||||
name: name.clone(),
|
name: name.clone(),
|
||||||
type_: Some(if is_ref {
|
type_: Some(if is_ref {
|
||||||
TypeExpr::Ref { lifetime: None, mutable, ty: Box::new(self_ty) }
|
TypeExpr::Ref {
|
||||||
|
lifetime:
|
||||||
|
lifetime.map(|v| Identifier::try_from(v.into_inner().next().unwrap()))
|
||||||
|
.transpose()
|
||||||
|
.expect("Failed to get lifetime identifier"),
|
||||||
|
mutable,
|
||||||
|
ty: Box::new(self_ty)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
self_ty
|
self_ty
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -7,3 +7,11 @@ struct MyStruct<'a> {
|
|||||||
fn add(a i32, b i32) i32 {
|
fn add(a i32, b i32) i32 {
|
||||||
a + b
|
a + b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class MyClass {
|
||||||
|
name String;
|
||||||
|
|
||||||
|
constructor() {}
|
||||||
|
|
||||||
|
fn my_func(*mut self) {}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user