From 1852d50231f76f5ebcb31e9d5f0ab1c4f730c9eb Mon Sep 17 00:00:00 2001 From: Gabriel Scherer Date: Sat, 23 Dec 2023 01:20:08 +0100 Subject: [PATCH] parser: use braces around tuples, not parentheses This is the syntax we use in the printer. It has the advantage of making the printing (and parsing) of tuple types unambiguous, even for tuples of type 0 or 1: - `(int)` could be `int` or a 1-ary tuple - `{int}` can only be a 1-ary tuple --- src/support/UntypedLexer.mll | 2 ++ src/support/UntypedParser.mly | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/support/UntypedLexer.mll b/src/support/UntypedLexer.mll index e9d9377..a1d24d0 100644 --- a/src/support/UntypedLexer.mll +++ b/src/support/UntypedLexer.mll @@ -34,6 +34,8 @@ rule read = parse | "->" { ARROW } | '(' { LPAR } | ')' { RPAR } + | '{' { LBRACE } + | '}' { RBRACE } | '*' { STAR } | ',' { COMMA } | '=' { EQ } diff --git a/src/support/UntypedParser.mly b/src/support/UntypedParser.mly index 3ad71d0..617a4bf 100644 --- a/src/support/UntypedParser.mly +++ b/src/support/UntypedParser.mly @@ -13,6 +13,8 @@ %token ARROW "->" %token LPAR "(" %token RPAR ")" +%token LBRACE "{" +%token RBRACE "}" %token STAR "*" %token COMMA "," %token EQ "=" @@ -96,7 +98,7 @@ let typ_arrow := let typ_atom := | x = tyvar ; { STLC.Constr (Structure.Var x) } - | "(" ; tys = separated_list ("*", typ) ; ")" ; + | "{" ; tys = separated_list ("*", typ) ; "}" ; { STLC.Constr (Structure.Prod tys) } | "(" ; ~ = typ ; ")" ; <>