@@ -272,11 +272,12 @@ let operator_precedence operator =
272272 | ":=" -> 1
273273 | "||" -> 2
274274 | "&&" -> 3
275- | "==" | "===" | "<" | ">" | "!=" | "<>" | "!==" | "<=" | ">=" | "|>" -> 4
276- | "+" | "+." | "-" | "-." | "++" -> 5
277- | "*" | "*." | "/" | "/." | "%" -> 6
278- | "**" -> 7
279- | "#" | "##" | "->" -> 8
275+ | "^" -> 4
276+ | "==" | "===" | "<" | ">" | "!=" | "<>" | "!==" | "<=" | ">=" | "|>" -> 5
277+ | "+" | "+." | "-" | "-." | "++" -> 6
278+ | "*" | "*." | "/" | "/." | "%" -> 7
279+ | "**" -> 8
280+ | "#" | "##" | "->" -> 9
280281 | _ -> 0
281282
282283let is_unary_operator operator =
@@ -295,15 +296,17 @@ let is_unary_expression expr =
295296 true
296297 | _ -> false
297298
298- (* TODO: tweak this to check for ghost ^ as template literal *)
299299let is_binary_operator operator =
300300 match operator with
301301 | " :=" | " ||" | " &&" | " ==" | " ===" | " <" | " >" | " !=" | " !==" | " <=" | " >="
302302 | " |>" | " +" | " +." | " -" | " -." | " ++" | " *" | " *." | " /" | " /." | " **"
303- | "->" | "<>" | "%" ->
303+ | "->" | "<>" | "%" | "^" ->
304304 true
305305 | _ -> false
306306
307+ let not_ghost_operator operator (loc : Location.t ) =
308+ is_binary_operator operator && not (loc.loc_ghost && operator = " ++" )
309+
307310let is_binary_expression expr =
308311 match expr.pexp_desc with
309312 | Pexp_apply
@@ -315,9 +318,7 @@ let is_binary_expression expr =
315318 };
316319 args = [(Nolabel , _operand1); (Nolabel , _operand2)];
317320 }
318- when is_binary_operator operator
319- && not (operator_loc.loc_ghost && operator = " ++" )
320- (* template literal *) ->
321+ when not_ghost_operator operator operator_loc ->
321322 true
322323 | _ -> false
323324
0 commit comments