Skip to content

Commit

Permalink
support non-parenthesized label colon type equal optional in type dec…
Browse files Browse the repository at this point in the history
…larations

fixes reasonml#2056
  • Loading branch information
anmonteiro committed Jul 8, 2018
1 parent 719896d commit c4c23aa
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
3 changes: 3 additions & 0 deletions formatTest/unit_tests/expected_output/syntax.re
Original file line number Diff line number Diff line change
Expand Up @@ -1351,3 +1351,6 @@ foo(~a=?-1);
*/
let z = {<state: 0, x: y>};
let z = {<>};

/* https://github.com/facebook/reason/issues/2056 */
type foo = (~a: bool=?) => int;
15 changes: 9 additions & 6 deletions formatTest/unit_tests/input/syntax.re
Original file line number Diff line number Diff line change
Expand Up @@ -675,18 +675,18 @@ let myOptional (~a=?, ~b=?, ()) = 10;
type named = (~a: int=?, ~b: int=?, unit) => int;
/*F*/
let optionalAlias (~a as aa=?, ~b as bb=?, ()) = 10;
/*G*/
/*G*/
let optionalAnnot (~a as a:int =?, ~b as b:int=?, ()) = 10;
/*H*/
/*H*/
let optionalAliasAnnot (~a as aa:int =?, ~b as bb:int=?, ()) = 10;
/*I: */
/*I: */
let defOptional (~a as a=10, ~b as b=10, ()) = 10;
type named = (~a: int=?, ~b: int=?, unit) => int;
/*J*/
/*J*/
let defOptionalAlias (~a as aa=10, ~b as bb=10, ()) = 10;
/*K*/
/*K*/
let defOptionalAnnot (~a as a:int=10, ~b as b:int=10, ()) = 10;
/*L*/
/*L*/
let defOptionalAliasAnnot(~a as aa:int=10, ~b as bb:int=10, ()) = 10;

/*M: Invoking them - Punned */
Expand Down Expand Up @@ -1177,3 +1177,6 @@ foo(~a=?-1);
*/
let z = {<state: 0, x: y>};
let z = {<>};

/* https://github.com/facebook/reason/issues/2056 */
type foo = ~a:bool=? => int;
10 changes: 8 additions & 2 deletions src/reason-parser/reason_parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -4308,17 +4308,23 @@ unattributed_core_type:
{ $1 }
| arrow_type_parameters EQUALGREATER core_type2
{ List.fold_right mktyp_arrow $1 $3 }
| as_loc(labelled_arrow_type_parameter_optional) EQUALGREATER core_type2
{ mktyp_arrow ($1, false) $3 }
| basic_core_type EQUALGREATER core_type2
{ mktyp (Ptyp_arrow (Nolabel, $1, $3)) }
;

labelled_arrow_type_parameter_optional:
| TILDE LIDENT COLON core_type EQUAL optional
{ ($6 $2, $4) }
;

arrow_type_parameter:
| core_type
{ (Nolabel, $1) }
| TILDE LIDENT COLON core_type
{ (Labelled $2, $4) }
| TILDE LIDENT COLON core_type EQUAL optional
{ ($6 $2, $4) }
| labelled_arrow_type_parameter_optional { $1 }
;

%inline uncurried_arrow_type_parameter:
Expand Down

0 comments on commit c4c23aa

Please sign in to comment.