Skip to content

Commit 58d09a5

Browse files
committed
Missing => infix operator escape
This PR applies the same solution that we use for `/\*` and makes `=\>` work fixes reasonml#1941
1 parent f262af7 commit 58d09a5

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

formatTest/unit_tests/expected_output/infix.re

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,3 +1197,8 @@ let (/>/>) = (a, b) => a + b;
11971197
let (><) = (a, b) => a + b;
11981198

11991199
let x = a >< b;
1200+
1201+
/* #1941: infix `=>` */
1202+
let (=\>) = (a, b) => a + b;
1203+
1204+
let x = a =\> b;

formatTest/unit_tests/input/infix.re

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -914,3 +914,8 @@ let (/>/>) = (a, b) => a + b;
914914
let (><) = (a, b) => a + b;
915915

916916
let x = a >< b;
917+
918+
/* #1941: infix `=>` */
919+
let (=\>) = (a, b) => a + b;
920+
921+
let x = a =\> b;

src/reason-parser/reason_lexer.mll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,10 @@ rule token = parse
609609
{ PREFIXOP(lexeme_operator lexbuf) }
610610
| '\\'? ['=' '<' '>' '|' '&' '$'] operator_chars*
611611
{ INFIXOP0(lexeme_operator lexbuf) }
612+
(* `=\>` is treated especially due to conflicts with the function declaration
613+
syntax *)
614+
| '\\'? '=' '\\'? '>' operator_chars*
615+
{ INFIXOP0(lexeme_operator lexbuf) }
612616
| '\\'? '@' operator_chars*
613617
{ INFIXOP1(lexeme_operator lexbuf) }
614618
| '\\'? '^' ('\\' '.')? operator_chars*

src/reason-parser/reason_syntax_util.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,10 +393,12 @@ let identifier_mapper f super =
393393
(** escape_stars_slashes_mapper escapes all stars and slases in an AST *)
394394
let escape_stars_slashes_mapper =
395395
let escape_stars_slashes str =
396-
if String.contains str '/' then
396+
if (String.contains str '/') ||
397+
((String.contains str '=') && (String.contains str '>')) then
397398
replace_string "/*" "/\\*" @@
398399
replace_string "*/" "*\\/" @@
399400
replace_string "//" "/\\/" @@
401+
replace_string "=>" "=\>" @@
400402
str
401403
else
402404
str

0 commit comments

Comments
 (0)