Var definition without type

This commit is contained in:
2026-05-05 18:11:17 +02:00
parent 6aa851fcf9
commit a8b6ff4789
3 changed files with 10 additions and 3 deletions
+2 -1
View File
@@ -15,7 +15,8 @@ static_path = { identifier ~ ("::" ~ identifier)* }
export = { "public" }
mutable = { "mut" }
sharp = _{ "#" }
var_decl = { type_expr ~ mutable? ~ identifier }
var = { "var" }
var_decl = { (var | type_expr) ~ mutable? ~ identifier }
semicolon = _{ ";" }
// ================= TOP LEVEL =================
+7 -1
View File
@@ -516,7 +516,13 @@ impl From<pest::iterators::Pair<'_, Rule>> for VarDecl {
Rule::var_decl => {
let mut inner = pair.into_inner();
let type_ = Some(inner.next().map(TypeExpr::from).unwrap());
let type_ = inner.next().and_then(|pair| {
if pair.as_str().trim() == "var" {
None
} else {
Some(TypeExpr::from(pair))
}
});
let mutable = if inner.peek().unwrap().as_rule() == Rule::mutable {
inner.next();
true