Add tuple type variable decleration

This commit is contained in:
2026-07-04 19:23:10 +02:00
parent 517a2e5a2b
commit df34c72c97
5 changed files with 21 additions and 11 deletions
+1
View File
@@ -46,6 +46,7 @@ pub struct MatchItem(pub Vec<Pattern>, pub Expression);
pub struct VarDecl {
pub type_: Option<TypeExpr>,
pub name: Pattern,
pub true_type: bool,
pub tuple_names: Vec<Pattern>,
}
+3 -1
View File
@@ -225,9 +225,11 @@ attributes = {
// ======================================================
// DECLARATION HELPERS
// ======================================================
as_kw = { "as" }
var_decl = {
("let" ~ pattern ~ ("," ~ pattern)*)
| type_expr ~ (!tuple_pattern ~ pattern ~ ("," ~ pattern)*)
| type_expr ~ as_kw? ~ (!tuple_pattern ~ pattern ~ ("," ~ pattern)*)
}
field = {
+2 -1
View File
@@ -2,7 +2,7 @@ use crate::{
Rule,
ast::*,
error::{AstError, collect_recovered},
parser::consume_rule,
parser::{consume_rule, listen_rule},
};
impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for VarDeclStmt {
@@ -55,6 +55,7 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for VarDecl {
type_: consume_rule(&mut inner, Rule::type_expr)
.map(TypeExpr::try_from)
.transpose()?,
true_type: listen_rule(&mut inner, Rule::as_kw),
name: Pattern::try_from(inner.next().unwrap())?,
tuple_names: collect_recovered(inner)?,
})