diff --git a/formatTest/unit_tests/expected_output/infix.re b/formatTest/unit_tests/expected_output/infix.re index 839145b60..f3dc5293c 100644 --- a/formatTest/unit_tests/expected_output/infix.re +++ b/formatTest/unit_tests/expected_output/infix.re @@ -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; @@ -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; diff --git a/formatTest/unit_tests/input/infix.re b/formatTest/unit_tests/input/infix.re index 8ee32f76b..ecf550731 100644 --- a/formatTest/unit_tests/input/infix.re +++ b/formatTest/unit_tests/input/infix.re @@ -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; @@ -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; + diff --git a/src/reason-parser/reason_lexer.mll b/src/reason-parser/reason_lexer.mll index d7fb9ef6d..ed028acbd 100644 --- a/src/reason-parser/reason_lexer.mll +++ b/src/reason-parser/reason_lexer.mll @@ -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* diff --git a/src/reason-parser/reason_syntax_util.ml b/src/reason-parser/reason_syntax_util.ml index 2d4456d1e..4d859dad2 100644 --- a/src/reason-parser/reason_syntax_util.ml +++ b/src/reason-parser/reason_syntax_util.ml @@ -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