From e3602c80fcc709e73cd1841d8c969c29105e8312 Mon Sep 17 00:00:00 2001
From: Stephane Del Pino <stephane.delpino44@gmail.com>
Date: Thu, 19 Sep 2019 15:21:35 +0200
Subject: [PATCH] Allow function definition for compound types

For instance, following constructions are syntactically correct
``
let f : R*R -> R*R, (x,y) -> (y, x);
let g : R*R -> R,   (x,y) -> x+y;
let h : R   -> R*R,  x    -> (x, x*x);
``
Semantic remains to be defined.

Also,
``
let f : R*R -> R*R, x -> x;
``
is a correct construction, but one will require `x[0]` and `x[1]` to be defined
to make this syntax useful.
---
 src/language/ASTBuilder.cpp | 2 ++
 src/language/PEGGrammar.hpp | 6 +++++-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/language/ASTBuilder.cpp b/src/language/ASTBuilder.cpp
index 239da703c..9ab4cd7a6 100644
--- a/src/language/ASTBuilder.cpp
+++ b/src/language/ASTBuilder.cpp
@@ -209,6 +209,8 @@ using selector =
                                                      real,
                                                      literal,
                                                      name,
+                                                     name_list,
+                                                     expression_list,
                                                      B_set,
                                                      N_set,
                                                      Z_set,
diff --git a/src/language/PEGGrammar.hpp b/src/language/PEGGrammar.hpp
index 646842bf3..f45d46ccb 100644
--- a/src/language/PEGGrammar.hpp
+++ b/src/language/PEGGrammar.hpp
@@ -206,7 +206,11 @@ struct declaration : if_must< TYPESPECIFIER, NAME, opt< if_must< seq< one< '=' >
 struct type_expression : list_must< TYPESPECIFIER, one< '*' > >{};
 
 struct type_mapping : seq< type_expression, RIGHT_ARROW, type_expression >{};
-struct function_definition : seq< NAME, RIGHT_ARROW, expression >{};
+
+struct name_list : seq< open_parent, list_must< NAME, COMMA >, close_parent >{};
+struct expression_list : seq< open_parent, list_must< expression, COMMA >, close_parent >{};
+
+struct function_definition : seq< sor< name_list, NAME >, RIGHT_ARROW, sor< expression_list, expression > >{};
 
 struct let_declaration : if_must< LET, NAME, COLUMN, type_mapping, COMMA, function_definition >{};
 
-- 
GitLab