Skip to content

Commit

Permalink
These now parse without parens but print with parens
Browse files Browse the repository at this point in the history
  • Loading branch information
ccasin committed Jun 14, 2024
1 parent d2ed09c commit d68154d
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 3 deletions.
7 changes: 7 additions & 0 deletions test/passing/tests/layout_annotation-erased.ml.js-ref
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ let g : (_ : value) -> unit = fun _ -> ()
let f : (_ : immediate) -> (_ : value) = fun _ -> assert false
let g : (_ : value) -> (_ : immediate) = fun _ -> assert false

type ('a : any, 'b : any, 'c : any) t4
type 'a t5 = (('a : float64), int, bool) t4

let f : ('a, (_ : value), bool) t4 -> int = fun _ -> 42

type ('a, 'b, 'c) t6 = ('a, 'b, ('c : bits32)) t4

(********************************************)
(* Test 3: Annotation on types in functions *)

Expand Down
8 changes: 8 additions & 0 deletions test/passing/tests/layout_annotation-erased.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ let f : _ -> _ = fun _ -> assert false

let g : _ -> _ = fun _ -> assert false

type ('a, 'b, 'c) t4

type 'a t5 = ('a, int, bool) t4

let f : ('a, _, bool) t4 -> int = fun _ -> 42

type ('a, 'b, 'c) t6 = ('a, 'b, 'c) t4

(********************************************)
(* Test 3: Annotation on types in functions *)

Expand Down
1 change: 0 additions & 1 deletion test/passing/tests/layout_annotation.ml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ let f : ('a, _ : value, bool) t4 -> int = fun _ -> 42;;

type ('a, 'b, 'c) t6 = ('a, 'b, 'c : bits32) t4;;


(********************************************)
(* Test 3: Annotation on types in functions *)

Expand Down
7 changes: 7 additions & 0 deletions test/passing/tests/layout_annotation.ml.js-ref
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ let g : (_ : value) -> unit = fun _ -> ()
let f : (_ : immediate) -> (_ : value) = fun _ -> assert false
let g : (_ : value) -> (_ : immediate) = fun _ -> assert false

type ('a : any, 'b : any, 'c : any) t4
type 'a t5 = (('a : float64), int, bool) t4

let f : ('a, (_ : value), bool) t4 -> int = fun _ -> 42

type ('a, 'b, 'c) t6 = ('a, 'b, ('c : bits32)) t4

(********************************************)
(* Test 3: Annotation on types in functions *)

Expand Down
8 changes: 8 additions & 0 deletions test/passing/tests/layout_annotation.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ let f : (_ : immediate) -> (_ : value) = fun _ -> assert false

let g : (_ : value) -> (_ : immediate) = fun _ -> assert false

type ('a : any, 'b : any, 'c : any) t4

type 'a t5 = (('a : float64), int, bool) t4

let f : ('a, (_ : value), bool) t4 -> int = fun _ -> 42

type ('a, 'b, 'c) t6 = ('a, 'b, ('c : bits32)) t4

(********************************************)
(* Test 3: Annotation on types in functions *)

Expand Down
14 changes: 13 additions & 1 deletion vendor/parser-extended/parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -4193,10 +4193,22 @@ atomic_type:
{ [] }
| ty = atomic_type
{ [ty] }
| LPAREN tys = separated_nontrivial_llist(COMMA, core_type) RPAREN
| LPAREN
tys = separated_nontrivial_llist(COMMA, one_type_parameter_of_several)
RPAREN
{ tys }
;

(* Layout annotations on type expressions typically require parens, as in [('a :
float64)]. But this is unnecessary when the type expression is used as the
parameter of a tconstr with more than one argument, as in [(int, 'b :
float64) t]. *)
%inline one_type_parameter_of_several:
| core_type { $1 }
| name=mkrhs(tyvar_name_or_underscore) COLON jkind=jkind_annotation
{ let descr = Ptyp_var (name, jkind) in
mktyp ~loc:$sloc descr }

%inline package_core_type: module_type
{ let (lid, cstrs, attrs) = package_type_of_module_type $1 in
let descr = Ptyp_package (lid, cstrs) in
Expand Down
17 changes: 16 additions & 1 deletion vendor/parser-standard/parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -4549,9 +4549,24 @@ atomic_type:
{ [] }
| ty = atomic_type
{ [ty] }
| LPAREN tys = separated_nontrivial_llist(COMMA, core_type) RPAREN
| LPAREN
tys = separated_nontrivial_llist(COMMA, one_type_parameter_of_several)
RPAREN
{ tys }

(* Layout annotations on type expressions typically require parens, as in [('a :
float64)]. But this is unnecessary when the type expression is used as the
parameter of a tconstr with more than one argument, as in [(int, 'b :
float64) t]. *)
%inline one_type_parameter_of_several:
| core_type { $1 }
| QUOTE id=ident COLON jkind=jkind_annotation
{ Jane_syntax.Layouts.type_of ~loc:(make_loc $sloc) @@
Ltyp_var { name = Some id; jkind } }
| UNDERSCORE COLON jkind=jkind_annotation
{ Jane_syntax.Layouts.type_of ~loc:(make_loc $sloc) @@
Ltyp_var { name = None; jkind } }

%inline package_type: module_type
{ let (lid, cstrs, attrs) = package_type_of_module_type $1 in
let descr = Ptyp_package (lid, cstrs) in
Expand Down

0 comments on commit d68154d

Please sign in to comment.