Class constructor (optional)
This commit is contained in:
@@ -104,6 +104,7 @@ pub enum Prefix {
|
||||
Ref,
|
||||
RefMut,
|
||||
Deref,
|
||||
New,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
|
||||
@@ -167,11 +167,13 @@ prefix = {
|
||||
deref_px
|
||||
| mut_ref_px
|
||||
| ref_px
|
||||
| new_px
|
||||
}
|
||||
|
||||
deref_px = { "*" }
|
||||
mut_ref_px = { "&" ~ mutable }
|
||||
ref_px = { "&" }
|
||||
new_px = { "new" }
|
||||
|
||||
expr = {
|
||||
prefix* ~ primary ~ postfix*
|
||||
|
||||
@@ -480,6 +480,7 @@ impl From<pest::iterators::Pair<'_, Rule>> for Prefix {
|
||||
Rule::deref_px => Self::Deref,
|
||||
Rule::mut_ref_px => Self::RefMut,
|
||||
Rule::ref_px => Self::Ref,
|
||||
Rule::new_px => Self::New,
|
||||
_ => unimplemented!("{pair:#?}"),
|
||||
}
|
||||
}
|
||||
|
||||
+24
-1
@@ -148,7 +148,12 @@ impl GetRust for Expression {
|
||||
initial,
|
||||
prefixes,
|
||||
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::Ref => "&",
|
||||
Self::RefMut => "&mut ",
|
||||
Self::New => "",
|
||||
}
|
||||
.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 {
|
||||
fn get_rust(&self) -> String {
|
||||
match self {
|
||||
|
||||
+1
-1
@@ -7,6 +7,6 @@ class MyClass {
|
||||
}
|
||||
|
||||
void main() {
|
||||
var my_class = MyClass::new("World");
|
||||
var my_class = new MyClass("World");
|
||||
println!("{}", my_class.message);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user