diff --git a/parser/src/ast.rs b/parser/src/ast.rs index fabb675..8ba217a 100644 --- a/parser/src/ast.rs +++ b/parser/src/ast.rs @@ -14,6 +14,7 @@ pub struct Block(pub Vec); #[derive(Debug, Clone, Serialize)] pub enum TypePostfix { Ref, + RefMut, } #[derive(Debug, Clone, Serialize)] diff --git a/parser/src/grammar.pest b/parser/src/grammar.pest index 035791b..e60b11b 100644 --- a/parser/src/grammar.pest +++ b/parser/src/grammar.pest @@ -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 = { diff --git a/parser/src/lib.rs b/parser/src/lib.rs index aa07769..584c832 100644 --- a/parser/src/lib.rs +++ b/parser/src/lib.rs @@ -44,9 +44,13 @@ impl From> for TypeExpr { impl From> 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:#?}"), } } diff --git a/src/codegen.rs b/src/codegen.rs index 63bbdf1..0830a5f 100644 --- a/src/codegen.rs +++ b/src/codegen.rs @@ -345,6 +345,7 @@ impl GetRust for TypePostfix { fn get_rust(&self) -> String { match self { TypePostfix::Ref => format!("&"), + TypePostfix::RefMut => format!("&mut "), } } }