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 Jun 3, 2018
1 parent fe79b90 commit d3bf722
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
5 changes: 5 additions & 0 deletions formatTest/unit_tests/expected_output/infix.re
Original file line number Diff line number Diff line change
Expand Up @@ -1201,3 +1201,8 @@ let x = a >< b;
let (=-) = (a, b) => a + b;

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

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

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

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

/* #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 @@ -593,13 +593,15 @@ rule token = parse
| '\\'? ['~' '?' '!'] operator_chars+
{ PREFIXOP(lexeme_operator lexbuf) }
| '\\'? ['<' '>' '|' '&' '$'] operator_chars*
{
INFIXOP0(lexeme_operator lexbuf)
}
{ INFIXOP0(lexeme_operator lexbuf) }
| "\\=" operator_chars*
{ INFIXOP0(lexeme_operator lexbuf) }
| '=' operator_chars+
{ INFIXOP_WITH_EQUAL(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 @@ -393,10 +393,12 @@ let identifier_mapper f super =
(** escape_stars_slashes_mapper escapes all stars and slases 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 d3bf722

Please sign in to comment.