Skip to content

Commit

Permalink
Make external... = "" optional in reason syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
romanschejbal committed Oct 10, 2019
1 parent aea245a commit 84a5b69
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
File "reservedRecordPunned.re", line 1, characters 22-26:
Error: 3411: type is a reserved keyword, it cannot be used as an identifier. Try `type_` or `_type` instead
Error: 3417: type is a reserved keyword, it cannot be used as an identifier. Try `type_` or `_type` instead
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
File "reservedRecordPunned.re", line 1, characters 22-26:
1 | let foo = { ...other, type };
^^^^
Error: 3411: type is a reserved keyword, it cannot be used as an identifier. Try `type_` or `_type` instead
Error: 3417: type is a reserved keyword, it cannot be used as an identifier. Try `type_` or `_type` instead

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
File "reservedRecordPunned.re", line 1, characters 22-26:
1 | let foo = { ...other, type };
^^^^
Error: 3411: type is a reserved keyword, it cannot be used as an identifier. Try `type_` or `_type` instead
Error: 3417: type is a reserved keyword, it cannot be used as an identifier. Try `type_` or `_type` instead

27 changes: 12 additions & 15 deletions formatTest/typeCheckedTests/expected_output/attributes.re
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ external add_nat: (int, int) => int =
[@ocaml.deprecated
"Use bar instead. It's a much cooler function. This string needs to be a little long"
]
external foo: bool => bool = "";
external foo: bool => bool;

/* Attributes on an entire polymorphic variant leaf */
[@bs.module "fs"]
Expand All @@ -439,8 +439,7 @@ external readFileSync:
| [@bs.as "ascii"] `my_name
]
) =>
string =
"";
string;

[@bs.module "fs"]
external readFileSync2:
Expand All @@ -451,35 +450,34 @@ external readFileSync2:
| [@bs.as "ascii"] `my_name
]
) =>
string =
"";
string;

/* Ensure that attributes on extensions are printed */
[@test
[@attr]
[%%extension]
];

external debounce: (int, [@bs.meth] unit) => unit =
"";
external debounce:
(int, [@bs.meth] unit) => unit;

external debounce:
(int, [@bs.meth] unit) => unit;

external debounce:
int => [@bs.meth] (unit => unit) =
"";
int => [@bs.meth] (unit => unit);

external debounce:
(int, [@bs.meth] (unit => unit)) =>
[@bs.meth] (unit => unit) =
"";
[@bs.meth] (unit => unit);

external debounce:
(
int,
[@bs.meth] (unit => unit),
[@bs.meth] (unit => unit)
) =>
[@bs.meth] (unit => unit) =
"";
[@bs.meth] (unit => unit);

external debounce:
(
Expand All @@ -489,8 +487,7 @@ external debounce:
unit => [@bs.meth] (unit => unit)
)
) =>
[@bs.meth] (unit => unit) =
"";
[@bs.meth] (unit => unit);

let x = "hi";

Expand Down
2 changes: 1 addition & 1 deletion formatTest/typeCheckedTests/expected_output/attributes.rei
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ external createClassInternalHack:
"createClass";

[@bs.send.pipe: array('a)]
external map: (. ('a => 'b)) => array('b) = "";
external map: (. ('a => 'b)) => array('b);

[@bs.val] [@bs.module "react"]
external createClassInternalHack:
Expand Down
4 changes: 2 additions & 2 deletions formatTest/typeCheckedTests/expected_output/mlSyntax.re
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ let pub__ = "method";
let pri_ = "private";
let pri__ = "private";

external private: unit => unit = "";
external pri_: unit => unit = "";
external private: unit => unit;
external pri_: unit => unit;

type pub_ = int;
type pub__ = int;
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ let pub__ = "method";
let pri_ = "private";
let pri__ = "private";

external private: unit => unit = "";
external pri_: unit => unit = "";
external private: unit => unit;
external pri_: unit => unit;

type pub_ = int;
type pub__ = int;
8 changes: 4 additions & 4 deletions formatTest/typeCheckedTests/expected_output/reasonComments.re
Original file line number Diff line number Diff line change
Expand Up @@ -731,20 +731,20 @@ let r = {

/** doc comment */
[@bs.send]
external url: t => string = "";
external url: t => string;

/**
* Short multiline doc comment
*/
[@bs.send]
external url: t => string = "";
external url: t => string;

/** Longer doc comment before an attribute on an external. */
[@bs.send]
external url: t => string = "";
external url: t => string;

/* normal comment */
[@bs.send] external url: t => string = "";
[@bs.send] external url: t => string;

/** doc type */
type q = {
Expand Down
2 changes: 2 additions & 0 deletions formatTest/typeCheckedTests/input/attributes.re
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,8 @@ external readFileSync2 : (
/* Ensure that attributes on extensions are printed */
[@test [@attr] [%%extension]];

external debounce : (int, [@bs.meth] unit) => unit;

external debounce : (int, [@bs.meth] unit) => unit = "";

external debounce : int => ([@bs.meth] (unit => unit)) = "";
Expand Down
2 changes: 1 addition & 1 deletion formatTest/typeCheckedTests/input/attributes.rei
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type reactElement;
[@bs.val] [@bs.module "React"]
external createClassInternalHack : (t('classSpec)) => reactClass = "createClass";

[@bs.send.pipe : array('a)] external map : [@bs] (('a) => 'b) => array('b) = "";
[@bs.send.pipe : array('a)] external map: [@bs] (('a) => 'b) => array('b) = "";

[@bs.val] [@bs.module "react"]
external createClassInternalHack : (t('classSpec)) => reactClass =
Expand Down
9 changes: 9 additions & 0 deletions src/reason-parser/reason_parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -1705,6 +1705,10 @@ structure_item:
EXTERNAL as_loc(val_ident) COLON core_type EQUAL primitive_declaration
{ let loc = mklocation $symbolstartpos $endpos in
mkstr (Pstr_primitive (Val.mk $3 $5 ~prim:$7 ~attrs:$1 ~loc)) }
| item_attributes
EXTERNAL as_loc(val_ident) COLON core_type SEMI
{ let loc = mklocation $symbolstartpos $endpos in
mkstr (Pstr_primitive (Val.mk $3 $5 ~prim:[""] ~attrs:$1 ~loc)) }
| type_declarations
{ let (nonrec_flag, tyl) = $1 in mkstr(Pstr_type (nonrec_flag, tyl)) }
| str_type_extension
Expand Down Expand Up @@ -1912,6 +1916,11 @@ signature_item:
{ let loc = mklocation $symbolstartpos $endpos in
Psig_value (Val.mk $3 $5 ~prim:$7 ~attrs:$1 ~loc)
}
| item_attributes
EXTERNAL as_loc(val_ident) COLON core_type SEMI
{ let loc = mklocation $symbolstartpos $endpos in
Psig_value (Val.mk $3 $5 ~prim:[""] ~attrs:$1 ~loc)
}
| type_declarations
{ let (nonrec_flag, tyl) = $1 in Psig_type (nonrec_flag, tyl) }
| sig_type_extension
Expand Down
10 changes: 7 additions & 3 deletions src/reason-parser/reason_pprint_ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6487,9 +6487,13 @@ let printer = object(self:'self)
[(makeList ~postSpace:true [atom "external"; protectIdentifier vd.pval_name.txt]); (atom ":")])
(self#core_type vd.pval_type)
in
let frstHalf = makeList ~postSpace:true [lblBefore; atom "="] in
let sndHalf = makeSpacedBreakableInlineList (List.map self#constant_string vd.pval_prim) in
let primDecl = label ~space:true frstHalf sndHalf in
let primDecl = match vd.pval_prim with
| [""] -> lblBefore
| _ ->
let frstHalf = makeList ~postSpace:true [lblBefore; atom "="] in
let sndHalf = makeSpacedBreakableInlineList (List.map self#constant_string vd.pval_prim) in
label ~space:true frstHalf sndHalf
in
match vd.pval_attributes with
| [] -> primDecl
| attrs ->
Expand Down

0 comments on commit 84a5b69

Please sign in to comment.