Mutable ref

This commit is contained in:
2026-05-04 18:00:50 +02:00
parent a057c50a53
commit 860f51ea06
4 changed files with 10 additions and 4 deletions
+1
View File
@@ -14,6 +14,7 @@ pub struct Block(pub Vec<Statement>);
#[derive(Debug, Clone, Serialize)] #[derive(Debug, Clone, Serialize)]
pub enum TypePostfix { pub enum TypePostfix {
Ref, Ref,
RefMut,
} }
#[derive(Debug, Clone, Serialize)] #[derive(Debug, Clone, Serialize)]
+1 -1
View File
@@ -75,7 +75,7 @@ while_stmt = {
// ================= EXPRESSIONS ================= // ================= EXPRESSIONS =================
tuple_type = { "(" ~ (type_expr ~ ("," ~ type_expr)*)? ~ ")" } tuple_type = { "(" ~ (type_expr ~ ("," ~ type_expr)*)? ~ ")" }
path_type = { static_path ~ ("<" ~ (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* } type_expr = { (path_type | tuple_type) ~ ref_type* }
primary = { primary = {
+7 -3
View File
@@ -44,9 +44,13 @@ impl From<pest::iterators::Pair<'_, Rule>> for TypeExpr {
impl From<pest::iterators::Pair<'_, Rule>> for TypePostfix { impl From<pest::iterators::Pair<'_, Rule>> for TypePostfix {
fn from(pair: pest::iterators::Pair<'_, Rule>) -> Self { fn from(pair: pest::iterators::Pair<'_, Rule>) -> Self {
match pair.as_rule() { match pair.as_rule() {
Rule::ref_type => match pair.as_str().trim() { Rule::ref_type => {
_ => Self::Ref, if pair.into_inner().peek().is_some() {
}, TypePostfix::RefMut
} else {
TypePostfix::Ref
}
}
_ => unimplemented!("{pair:#?}"), _ => unimplemented!("{pair:#?}"),
} }
} }
+1
View File
@@ -345,6 +345,7 @@ impl GetRust for TypePostfix {
fn get_rust(&self) -> String { fn get_rust(&self) -> String {
match self { match self {
TypePostfix::Ref => format!("&"), TypePostfix::Ref => format!("&"),
TypePostfix::RefMut => format!("&mut "),
} }
} }
} }