From 4f606e0e305661861f1d13acd6a8dd285d6f3cb6 Mon Sep 17 00:00:00 2001 From: Brandon Dyck Date: Wed, 5 Jul 2023 10:23:34 -0600 Subject: [PATCH] Allow arbitrary patterns as func params --- AST.cs | 2 +- Parser.cs | 16 ++-------------- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/AST.cs b/AST.cs index a333cb3..41bd7fe 100644 --- a/AST.cs +++ b/AST.cs @@ -54,7 +54,7 @@ public partial record SimplePattern public abstract record Binding(Expr Value); public record VarBinding(Pattern Pattern, Expr Value) : Binding(Value); -public record FuncBinding(Name Name, SimplePattern[] Params, Expr Value) : Binding(Value) +public record FuncBinding(Name Name, Pattern[] Params, Expr Value) : Binding(Value) { public override string ToString() { diff --git a/Parser.cs b/Parser.cs index adefd30..b3ae6af 100644 --- a/Parser.cs +++ b/Parser.cs @@ -264,22 +264,10 @@ class Parser switch (p) { case (SimplePattern(var funcName)) when funcName != null && match(TokenType.LParen): - List funcParams = new List(); + List funcParams = new List(); while (!check(TokenType.RParen)) { - Name? paramName; - if (match(TokenType.Blank)) - { - funcParams.Add(new(null)); - } - else if ((paramName = name()) != null) - { - funcParams.Add(new(paramName)); - } - else - { - throw error(peek(), "Expect identifier or '_' as function parameter."); - } + funcParams.Add(pattern()); if (!match(TokenType.Comma)) { break;