Mutable ref
This commit is contained in:
@@ -14,6 +14,7 @@ pub struct Block(pub Vec<Statement>);
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub enum TypePostfix {
|
||||
Ref,
|
||||
RefMut,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
|
||||
@@ -75,7 +75,7 @@ while_stmt = {
|
||||
// ================= EXPRESSIONS =================
|
||||
tuple_type = { "(" ~ (type_expr ~ ("," ~ type_expr)*)? ~ ")" }
|
||||
path_type = { static_path ~ ("<" ~ (type_expr ~ ("," ~ type_expr)*)? ~ ">")? }
|
||||
ref_type = { "*" }
|
||||
ref_type = { mutable? ~ "*" }
|
||||
type_expr = { (path_type | tuple_type) ~ ref_type* }
|
||||
|
||||
primary = {
|
||||
|
||||
+7
-3
@@ -44,9 +44,13 @@ impl From<pest::iterators::Pair<'_, Rule>> for TypeExpr {
|
||||
impl From<pest::iterators::Pair<'_, Rule>> for TypePostfix {
|
||||
fn from(pair: pest::iterators::Pair<'_, Rule>) -> Self {
|
||||
match pair.as_rule() {
|
||||
Rule::ref_type => match pair.as_str().trim() {
|
||||
_ => Self::Ref,
|
||||
},
|
||||
Rule::ref_type => {
|
||||
if pair.into_inner().peek().is_some() {
|
||||
TypePostfix::RefMut
|
||||
} else {
|
||||
TypePostfix::Ref
|
||||
}
|
||||
}
|
||||
_ => unimplemented!("{pair:#?}"),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -345,6 +345,7 @@ impl GetRust for TypePostfix {
|
||||
fn get_rust(&self) -> String {
|
||||
match self {
|
||||
TypePostfix::Ref => format!("&"),
|
||||
TypePostfix::RefMut => format!("&mut "),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user