Skip to content

Commit

Permalink
Enhance reasonml#1539
Browse files Browse the repository at this point in the history
  • Loading branch information
chenglou committed Oct 24, 2017
1 parent 38ac8a5 commit fc32d4e
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 8 deletions.
8 changes: 8 additions & 0 deletions formatTest/typeCheckedTests/expected_output/mlSyntax.re
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,16 @@ module EM = {

exception Ealias = EM.E;

let switc = "match";

let switch_ = "match";

let switch__ = "match";

let pub_ = "method";

let pub__ = "method";

let pri_ = "private";

let pri__ = "private";
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,16 @@ module EM = {

exception Ealias = EM.E;

let switc = "match";

let switch_ = "match";

let switch__ = "match";

let pub_ = "method";

let pub__ = "method";

let pri_ = "private";

let pri__ = "private";
6 changes: 4 additions & 2 deletions formatTest/typeCheckedTests/input/mlSyntax.ml
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ end

exception Ealias = EM.E

let switc = "match"
let switch = "match"

let switch_ = "match"
let pub = "method"

let pub_ = "method"
let pri = "private"
let pri_ = "private"
38 changes: 32 additions & 6 deletions src/syntax_util.ml
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,36 @@ let string_drop_suffix x = String.sub x 0 (String.length x - 1)
and ocaml syntax, ocaml `not` converts to `!`, reason `!` converts to
`not`.
In more complicated cases where a keyword exists in one syntax but not the
other these functions translate any potentially conflicting identifier into
the same identifier with a suffix attached, or remove the suffix when
converting back.
In more complicated cases where a reserved keyword exists in one syntax but
not the other, these functions translate any potentially conflicting
identifier into the same identifier with a suffix attached, or remove the
suffix when converting back. Two examples:
reason to ocaml:
pub: invalid in reason to begin with
pub_: pub
pub__: pub_
ocaml to reason:
pub: pub_
pub_: pub__
pub__: pub___
=====
reason to ocaml:
match: match_
match_: match__
match__: match___
ocaml to reason:
match: invalid in ocaml to begin with
match_: match
match__: match_
*)

let reason_to_ml_swap = function
Expand Down Expand Up @@ -259,8 +285,8 @@ let identifier_mapper f super =
in
super.pat mapper pat
end;
signature_item = begin fun mapper signatureItem ->
let signatureItem =
signature_item = begin fun mapper signatureItem ->
let signatureItem =
match signatureItem with
| {psig_desc=Psig_value ({pval_name} as name);
psig_loc} ->
Expand Down

0 comments on commit fc32d4e

Please sign in to comment.