diff --git a/parser/src/ast/expr.rs b/parser/src/ast/expr.rs index f89da9a..ae6e96b 100644 --- a/parser/src/ast/expr.rs +++ b/parser/src/ast/expr.rs @@ -80,7 +80,7 @@ pub enum Prefix { Ref, RefMut, Deref, - New, + New(Option), Not, Neg, RangeInclusive, diff --git a/parser/src/grammar.pest b/parser/src/grammar.pest index 2003dc6..b955b95 100644 --- a/parser/src/grammar.pest +++ b/parser/src/grammar.pest @@ -515,7 +515,7 @@ postfix = { deref_px = { "*" } mut_ref_px = { "&" ~ mutable } ref_px = { "&" } -new_px = { "new" } +new_px = { "new" ~ generics? } not_px = { "!" } neg_px = { "-" } range_start_inc_px = { "..=" } diff --git a/parser/src/parser/common/expr.rs b/parser/src/parser/common/expr.rs index 68c858c..8abf3f6 100644 --- a/parser/src/parser/common/expr.rs +++ b/parser/src/parser/common/expr.rs @@ -134,7 +134,12 @@ impl<'a> TryFrom> for Prefix { Rule::deref_px => Self::Deref, Rule::mut_ref_px => Self::RefMut, Rule::ref_px => Self::Ref, - Rule::new_px => Self::New, + Rule::new_px => Self::New( + pair.into_inner() + .next() + .map(|v| v.try_into().get()) + .transpose()?, + ), Rule::not_px => Self::Not, Rule::neg_px => Self::Neg, Rule::range_start_inc_px => Self::RangeInclusive, diff --git a/src/codegen.rs b/src/codegen.rs index 6cea264..932a260 100644 --- a/src/codegen.rs +++ b/src/codegen.rs @@ -204,7 +204,7 @@ impl GetRust for Prefix { Self::Ref => "&", Self::RefMut => "&mut ", Self::Not => "!", - Self::New => "", + Self::New(_) => "", Self::Neg => "-", Self::RangeInclusive => "..=", Self::RangeExclusive => "..", @@ -249,8 +249,14 @@ impl GetRust for Option<&Vec> { .iter() .last() .map(|p| match p { - Prefix::New => "::new", - _ => "", + Prefix::New(generics) => format!( + "::new{}", + generics + .as_ref() + .map(|v| format!("::{}", v.get_rust())) + .unwrap_or_default(), + ), + _ => String::new(), }) .unwrap_or_default() .to_string()