Class constructor (optional)

This commit is contained in:
2026-05-05 20:11:43 +02:00
parent 8bb5dc3584
commit 9e5d030b0c
5 changed files with 29 additions and 2 deletions
+1
View File
@@ -104,6 +104,7 @@ pub enum Prefix {
Ref, Ref,
RefMut, RefMut,
Deref, Deref,
New,
} }
#[derive(Debug, Clone, Serialize)] #[derive(Debug, Clone, Serialize)]
+2
View File
@@ -167,11 +167,13 @@ prefix = {
deref_px deref_px
| mut_ref_px | mut_ref_px
| ref_px | ref_px
| new_px
} }
deref_px = { "*" } deref_px = { "*" }
mut_ref_px = { "&" ~ mutable } mut_ref_px = { "&" ~ mutable }
ref_px = { "&" } ref_px = { "&" }
new_px = { "new" }
expr = { expr = {
prefix* ~ primary ~ postfix* prefix* ~ primary ~ postfix*
+1
View File
@@ -480,6 +480,7 @@ impl From<pest::iterators::Pair<'_, Rule>> for Prefix {
Rule::deref_px => Self::Deref, Rule::deref_px => Self::Deref,
Rule::mut_ref_px => Self::RefMut, Rule::mut_ref_px => Self::RefMut,
Rule::ref_px => Self::Ref, Rule::ref_px => Self::Ref,
Rule::new_px => Self::New,
_ => unimplemented!("{pair:#?}"), _ => unimplemented!("{pair:#?}"),
} }
} }
+24 -1
View File
@@ -148,7 +148,12 @@ impl GetRust for Expression {
initial, initial,
prefixes, prefixes,
postfixes, postfixes,
} => prefixes.get_rust() + &initial.get_rust() + &postfixes.get_rust(), } => {
prefixes.get_rust()
+ &initial.get_rust()
+ &Some(prefixes).get_rust()
+ &postfixes.get_rust()
}
} }
} }
} }
@@ -159,6 +164,7 @@ impl GetRust for Prefix {
Self::Deref => "*", Self::Deref => "*",
Self::Ref => "&", Self::Ref => "&",
Self::RefMut => "&mut ", Self::RefMut => "&mut ",
Self::New => "",
} }
.to_string() .to_string()
} }
@@ -170,6 +176,23 @@ impl GetRust for [Prefix] {
} }
} }
impl GetRust for Option<&Vec<Prefix>> {
fn get_rust(&self) -> String {
self.map(|prefixes| {
prefixes
.iter()
.last()
.map(|p| match p {
Prefix::New => "::new",
_ => "",
})
.unwrap_or_default()
.to_string()
})
.unwrap_or_default()
}
}
impl GetRust for Postfix { impl GetRust for Postfix {
fn get_rust(&self) -> String { fn get_rust(&self) -> String {
match self { match self {
+1 -1
View File
@@ -7,6 +7,6 @@ class MyClass {
} }
void main() { void main() {
var my_class = MyClass::new("World"); var my_class = new MyClass("World");
println!("{}", my_class.message); println!("{}", my_class.message);
} }