From ac62dc4e2dae3b7e06527b03c13eb2d3ff4b76eb Mon Sep 17 00:00:00 2001 From: Emi Simpson Date: Sun, 24 Apr 2022 21:56:40 -0400 Subject: [PATCH] Added a universal pattern match --- src/ir/pattern.rs | 2 ++ src/parser/expr.rs | 7 ++++++- src/parser/pattern.rs | 2 ++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/ir/pattern.rs b/src/ir/pattern.rs index fb354d0..e858ef5 100644 --- a/src/ir/pattern.rs +++ b/src/ir/pattern.rs @@ -9,6 +9,7 @@ pub enum Pattern { Literal(Literal), Binding(Identifier), Variant(Identifier, Vec), + Universal, } impl Pattern { @@ -37,6 +38,7 @@ impl Pattern { } else { None }, + (_, Pattern::Universal) => Some(LinkedList::new()), _ => None, } } diff --git a/src/parser/expr.rs b/src/parser/expr.rs index f01ecf8..1095135 100644 --- a/src/parser/expr.rs +++ b/src/parser/expr.rs @@ -104,9 +104,14 @@ impl Expr { .enumerate() .map(|(v, expr)| expr.gen_ir(bindings, &self_ident, v as u32, type_context).map(|expr| - (Pattern::Literal(Literal::Int(v as u64)), expr) + if v == 1 { + (Pattern::Literal(Literal::Int(1)), expr) + } else { + (Pattern::Universal, expr) + } ) ) + .rev() .collect() } }?); diff --git a/src/parser/pattern.rs b/src/parser/pattern.rs index e3e4f03..ce94e44 100644 --- a/src/parser/pattern.rs +++ b/src/parser/pattern.rs @@ -14,6 +14,7 @@ pub enum TightBindingPattern { Literal(Literal), Symbol(String), Group(BindingPattern), + Universal, } impl TightBindingPattern { @@ -28,6 +29,7 @@ impl TightBindingPattern { )) } TightBindingPattern::Group(bp) => bp.gen_ir(scope, parent_ident, index), + TightBindingPattern::Universal => Ok((Vec::new(), Pattern::Universal)), } } }