Update: Self param #64

This commit is contained in:
2026-06-05 18:16:37 +02:00
parent d364c41c26
commit 765e2ded93
3 changed files with 19 additions and 3 deletions
+1 -1
View File
@@ -278,7 +278,7 @@ class_field = {
}
self_param = {
"self" ~ mutable? ~ deref_px?
(deref_px ~ lifetime?)? ~ mutable? ~ "self"
}
method_args = _{
+10 -2
View File
@@ -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 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 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 self_ty = TypeExpr::Path(Path(vec![Identifier(String::from("Self"))]), None);
VarDecl {
name: name.clone(),
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 {
self_ty
}),
+8
View File
@@ -7,3 +7,11 @@ struct MyStruct<'a> {
fn add(a i32, b i32) i32 {
a + b
}
class MyClass {
name String;
constructor() {}
fn my_func(*mut self) {}
}