Skip to content

Commit

Permalink
Missing => infix operator escape
Browse files Browse the repository at this point in the history
This PR applies the same solution that we use for `/\*` and makes `=\>` work

fixes reasonml#1941
  • Loading branch information
anmonteiro committed Oct 11, 2018
1 parent af651a6 commit 79ff78d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
6 changes: 6 additions & 0 deletions formatTest/unit_tests/expected_output/infix.re
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,7 @@ let (=-) = (a, b) => a + b;

let foo = (a, b) => a =- b;

<<<<<<< HEAD
let (=><) = (a, b) => a + b;
let x = a =>< b;

Expand Down Expand Up @@ -1311,3 +1312,8 @@ let not = x => !x;
let other = x => not(x);

let derefInsideArray = [|a^|];

/* #1941: infix `=>` */
let (=\>) = (a, b) => a + b;

let x = a =\> b;
7 changes: 7 additions & 0 deletions formatTest/unit_tests/input/infix.re
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,7 @@ let (=-) = (a, b) => a + b;

let foo = (a, b) => a =- b;

<<<<<<< HEAD
let (=><) = (a, b) => a + b;
let x = a =>< b;

Expand Down Expand Up @@ -1004,3 +1005,9 @@ let not = (x) => !x;
let other = (x) => not(x);

let derefInsideArray = [|a^|];

/* #1941: infix `=>` */
let (=\>) = (a, b) => a + b;

let x = a =\> b;

8 changes: 5 additions & 3 deletions src/reason-parser/reason_lexer.mll
Original file line number Diff line number Diff line change
Expand Up @@ -612,9 +612,11 @@ rule token = parse
| '\\'? ['~' '?' '!'] operator_chars+
{ PREFIXOP(lexeme_operator lexbuf) }
| '\\'? ['=' '<' '>' '|' '&' '$'] operator_chars*
{
INFIXOP0(lexeme_operator lexbuf)
}
{ INFIXOP0(lexeme_operator lexbuf) }
(* `=\>` is treated especially due to conflicts with the function declaration
syntax *)
| '\\'? '=' '\\'? '>' operator_chars*
{ INFIXOP0(lexeme_operator lexbuf) }
| '\\'? '@' operator_chars*
{ INFIXOP1(lexeme_operator lexbuf) }
| '\\'? '^' ('\\' '.')? operator_chars*
Expand Down
4 changes: 3 additions & 1 deletion src/reason-parser/reason_syntax_util.ml
Original file line number Diff line number Diff line change
Expand Up @@ -396,10 +396,12 @@ let remove_literal_attrs_mapper =
(** escape_stars_slashes_mapper escapes all stars and slashes in an AST *)
let escape_stars_slashes_mapper =
let escape_stars_slashes str =
if String.contains str '/' then
if (String.contains str '/') ||
((String.contains str '=') && (String.contains str '>')) then
replace_string "/*" "/\\*" @@
replace_string "*/" "*\\/" @@
replace_string "//" "/\\/" @@
replace_string "=>" "=\>" @@
str
else
str
Expand Down

0 comments on commit 79ff78d

Please sign in to comment.