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
This commit is contained in:
Gabriel Scherer 2023-12-23 01:20:08 +01:00
parent e848910039
commit 1852d50231
2 changed files with 5 additions and 1 deletions

View File

@ -34,6 +34,8 @@ rule read = parse
| "->" { ARROW } | "->" { ARROW }
| '(' { LPAR } | '(' { LPAR }
| ')' { RPAR } | ')' { RPAR }
| '{' { LBRACE }
| '}' { RBRACE }
| '*' { STAR } | '*' { STAR }
| ',' { COMMA } | ',' { COMMA }
| '=' { EQ } | '=' { EQ }

View File

@ -13,6 +13,8 @@
%token ARROW "->" %token ARROW "->"
%token LPAR "(" %token LPAR "("
%token RPAR ")" %token RPAR ")"
%token LBRACE "{"
%token RBRACE "}"
%token STAR "*" %token STAR "*"
%token COMMA "," %token COMMA ","
%token EQ "=" %token EQ "="
@ -96,7 +98,7 @@ let typ_arrow :=
let typ_atom := let typ_atom :=
| x = tyvar ; | x = tyvar ;
{ STLC.Constr (Structure.Var x) } { STLC.Constr (Structure.Var x) }
| "(" ; tys = separated_list ("*", typ) ; ")" ; | "{" ; tys = separated_list ("*", typ) ; "}" ;
{ STLC.Constr (Structure.Prod tys) } { STLC.Constr (Structure.Prod tys) }
| "(" ; ~ = typ ; ")" ; <> | "(" ; ~ = typ ; ")" ; <>