From fc32d4e8b9a8001e9cb80ce359f9a678341a930c Mon Sep 17 00:00:00 2001 From: Cheng Lou Date: Mon, 23 Oct 2017 22:57:14 -0700 Subject: [PATCH] Enhance #1539 --- .../expected_output/mlSyntax.re | 8 ++++ .../expected_output/mlSyntax.re.4.02.3 | 8 ++++ formatTest/typeCheckedTests/input/mlSyntax.ml | 6 ++- src/syntax_util.ml | 38 ++++++++++++++++--- 4 files changed, 52 insertions(+), 8 deletions(-) diff --git a/formatTest/typeCheckedTests/expected_output/mlSyntax.re b/formatTest/typeCheckedTests/expected_output/mlSyntax.re index 68c98e7a2..c397634f7 100644 --- a/formatTest/typeCheckedTests/expected_output/mlSyntax.re +++ b/formatTest/typeCheckedTests/expected_output/mlSyntax.re @@ -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"; diff --git a/formatTest/typeCheckedTests/expected_output/mlSyntax.re.4.02.3 b/formatTest/typeCheckedTests/expected_output/mlSyntax.re.4.02.3 index f7e37aae7..07a607b06 100644 --- a/formatTest/typeCheckedTests/expected_output/mlSyntax.re.4.02.3 +++ b/formatTest/typeCheckedTests/expected_output/mlSyntax.re.4.02.3 @@ -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"; diff --git a/formatTest/typeCheckedTests/input/mlSyntax.ml b/formatTest/typeCheckedTests/input/mlSyntax.ml index 208b26a96..3ff254e9f 100644 --- a/formatTest/typeCheckedTests/input/mlSyntax.ml +++ b/formatTest/typeCheckedTests/input/mlSyntax.ml @@ -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" diff --git a/src/syntax_util.ml b/src/syntax_util.ml index 268dbbb0e..efc8ee107 100644 --- a/src/syntax_util.ml +++ b/src/syntax_util.ml @@ -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 @@ -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} ->