From bb4ab2c56ec284474c5a0e47b4681b40da662ba0 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Sat, 11 Jan 2025 17:14:02 +0100 Subject: [PATCH 1/5] Cleanup pipe: remove `|.u` which is effectively treated the same as `|.`. --- analysis/src/CompletionFrontEnd.ml | 25 +++--- analysis/src/SignatureHelp.ml | 2 +- compiler/frontend/ast_exp_apply.ml | 4 +- compiler/syntax/src/res_comments_table.ml | 2 +- compiler/syntax/src/res_core.ml | 2 +- compiler/syntax/src/res_parsetree_viewer.ml | 15 +--- compiler/syntax/src/res_printer.ml | 15 ++-- .../errors/expressions/expected/block.res.txt | 7 +- .../errors/structure/expected/gh16B.res.txt | 8 +- .../structure/expected/letBinding.res.txt | 4 +- .../expected/UncurriedAlways.res.txt | 4 +- .../expected/UncurriedByDefault.res.txt | 2 +- .../expressions/expected/arrow.res.txt | 2 +- .../expressions/expected/async.res.txt | 6 +- .../expressions/expected/binary.res.txt | 6 +- .../expected/binaryNoEs6Arrow.res.txt | 2 +- .../expressions/expected/block.res.txt | 6 +- .../expected/bracedOrRecord.res.txt | 2 +- .../expressions/expected/bsObject.res.txt | 4 +- .../expected/firstClassModule.res.txt | 21 +++-- .../expressions/expected/infix.res.txt | 2 +- .../grammar/expressions/expected/jsx.res.txt | 10 +-- .../expected/tupleVsDivision.res.txt | 4 +- .../expected/underscoreApply.res.txt | 6 +- .../expressions/expected/while.res.txt | 2 +- .../expected/equalAfterBinaryExpr.res.txt | 85 +++++++++---------- .../expression/expected/infinite.res.txt | 2 +- 27 files changed, 116 insertions(+), 134 deletions(-) diff --git a/analysis/src/CompletionFrontEnd.ml b/analysis/src/CompletionFrontEnd.ml index aa9c1ba80f..a8f4085b45 100644 --- a/analysis/src/CompletionFrontEnd.ml +++ b/analysis/src/CompletionFrontEnd.ml @@ -218,7 +218,7 @@ let rec exprToContextPathInner (e : Parsetree.expression) = (match exprs with | [] -> None | exp :: _ -> exprToContextPath exp)) - | Pexp_ident {txt = Lident ("|." | "|.u")} -> None + | Pexp_ident {txt = Lident "|."} -> None | Pexp_ident {txt; loc} -> Some (CPId {path = Utils.flattenLongIdent txt; completionContext = Value; loc}) @@ -258,7 +258,7 @@ let rec exprToContextPathInner (e : Parsetree.expression) = { funct = { - pexp_desc = Pexp_ident {txt = Lident ("|." | "|.u")}; + pexp_desc = Pexp_ident {txt = Lident "|."}; pexp_loc; pexp_attributes; }; @@ -275,7 +275,7 @@ let rec exprToContextPathInner (e : Parsetree.expression) = } | Pexp_apply { - funct = {pexp_desc = Pexp_ident {txt = Lident ("|." | "|.u")}}; + funct = {pexp_desc = Pexp_ident {txt = Lident "|."}}; args = [ (_, lhs); (_, {pexp_desc = Pexp_ident id; pexp_loc; pexp_attributes}); @@ -328,7 +328,7 @@ let completePipeChain (exp : Parsetree.expression) = Example: someArray->Js.Array2.map(v => v + 2)-> *) | Pexp_apply { - funct = {pexp_desc = Pexp_ident {txt = Lident ("|." | "|.u")}}; + funct = {pexp_desc = Pexp_ident {txt = Lident "|."}}; args = [_; (_, {pexp_desc = Pexp_apply {funct = d}})]; } -> exprToContextPath exp |> Option.map (fun ctxPath -> (ctxPath, d.pexp_loc)) @@ -336,7 +336,7 @@ let completePipeChain (exp : Parsetree.expression) = Example: someArray->filterAllTheGoodStuff-> *) | Pexp_apply { - funct = {pexp_desc = Pexp_ident {txt = Lident ("|." | "|.u")}}; + funct = {pexp_desc = Pexp_ident {txt = Lident "|."}}; args = [_; (_, {pexp_desc = Pexp_ident _; pexp_loc})]; } -> exprToContextPath exp |> Option.map (fun ctxPath -> (ctxPath, pexp_loc)) @@ -1113,8 +1113,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor resetCurrentCtxPath oldCtxPath | Pexp_apply { - funct = - {pexp_desc = Pexp_ident {txt = Lident ("|." | "|.u"); loc = opLoc}}; + funct = {pexp_desc = Pexp_ident {txt = Lident "|."; loc = opLoc}}; args = [ (_, lhs); @@ -1292,7 +1291,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor else iterateJsxProps ~iterator jsxProps | Pexp_apply { - funct = {pexp_desc = Pexp_ident {txt = Lident ("|." | "|.u")}}; + funct = {pexp_desc = Pexp_ident {txt = Lident "|."}}; args = [ (_, lhs); @@ -1304,11 +1303,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor setPipeResult ~lhs ~id |> ignore | Pexp_apply { - funct = - { - pexp_desc = - Pexp_ident {txt = Lident ("|." | "|.u"); loc = opLoc}; - }; + funct = {pexp_desc = Pexp_ident {txt = Lident "|."; loc = opLoc}}; args = [(_, lhs); _]; } when Loc.end_ opLoc = posCursor -> @@ -1316,7 +1311,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor setPipeResult ~lhs ~id:"" |> ignore | Pexp_apply { - funct = {pexp_desc = Pexp_ident {txt = Lident ("|." | "|.u")}}; + funct = {pexp_desc = Pexp_ident {txt = Lident "|."}}; args = [_; (_, {pexp_desc = Pexp_apply {funct = funExpr; args}})]; } when (* Normally named arg completion fires when the cursor is right after the expression. @@ -1352,7 +1347,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor | Some argCompletable -> setResult argCompletable) | Pexp_apply { - funct = {pexp_desc = Pexp_ident {txt = Lident ("|." | "|.u")}}; + funct = {pexp_desc = Pexp_ident {txt = Lident "|."}}; args = [_; _]; } -> (* Ignore any other pipe. *) diff --git a/analysis/src/SignatureHelp.ml b/analysis/src/SignatureHelp.ml index 4b8c4f7f3d..a9a1159a8f 100644 --- a/analysis/src/SignatureHelp.ml +++ b/analysis/src/SignatureHelp.ml @@ -365,7 +365,7 @@ let signatureHelp ~path ~pos ~currentFile ~debug ~allowForConstructorPayloads = pexp_desc = Pexp_apply { - funct = {pexp_desc = Pexp_ident {txt = Lident ("|." | "|.u")}}; + funct = {pexp_desc = Pexp_ident {txt = Lident "|."}}; args = [ _; diff --git a/compiler/frontend/ast_exp_apply.ml b/compiler/frontend/ast_exp_apply.ml index 2763dc4bae..932b096e49 100644 --- a/compiler/frontend/ast_exp_apply.ml +++ b/compiler/frontend/ast_exp_apply.ml @@ -69,11 +69,11 @@ let view_as_app (fn : exp) (s : string list) : app_pattern option = Some {op; loc = fn.pexp_loc; args = check_and_discard args} | _ -> None -let infix_ops = ["|."; "|.u"; "#="; "##"] +let infix_ops = ["|."; "#="; "##"] let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) : exp = match view_as_app e infix_ops with - | Some {op = "|." | "|.u"; args = [a_; f_]; loc} -> ( + | Some {op = "|."; args = [a_; f_]; loc} -> ( (* a |. f a |. f b c [@bs] --> f a b c [@bs] diff --git a/compiler/syntax/src/res_comments_table.ml b/compiler/syntax/src/res_comments_table.ml index 523d1289c8..2fa92cbf7e 100644 --- a/compiler/syntax/src/res_comments_table.ml +++ b/compiler/syntax/src/res_comments_table.ml @@ -1341,7 +1341,7 @@ and walk_expression expr t comments = ( ":=" | "||" | "&&" | "=" | "==" | "<" | ">" | "!=" | "!==" | "<=" | ">=" | "|>" | "+" | "+." | "-" | "-." | "++" | "^" | "*" | "*." | "/" | "/." | "**" | "|." - | "|.u" | "<>" ); + | "<>" ); }; }; args = [(Nolabel, operand1); (Nolabel, operand2)]; diff --git a/compiler/syntax/src/res_core.ml b/compiler/syntax/src/res_core.ml index 313b1c7d2e..91bf9ef84f 100644 --- a/compiler/syntax/src/res_core.ml +++ b/compiler/syntax/src/res_core.ml @@ -391,7 +391,7 @@ let build_longident words = let make_infix_operator (p : Parser.t) token start_pos end_pos = let stringified_token = - if token = Token.MinusGreater then "|.u" + if token = Token.MinusGreater then "|." else if token = Token.PlusPlus then "^" else if token = Token.BangEqual then "<>" else if token = Token.BangEqualEqual then "!=" diff --git a/compiler/syntax/src/res_parsetree_viewer.ml b/compiler/syntax/src/res_parsetree_viewer.ml index 8185bea0a2..d5bcb5da09 100644 --- a/compiler/syntax/src/res_parsetree_viewer.ml +++ b/compiler/syntax/src/res_parsetree_viewer.ml @@ -274,7 +274,7 @@ let operator_precedence operator = | "+" | "+." | "-" | "-." | "^" -> 5 | "*" | "*." | "/" | "/." | "%" -> 6 | "**" -> 7 - | "#" | "##" | "|." | "|.u" -> 8 + | "#" | "##" | "|." -> 8 | _ -> 0 let is_unary_operator operator = @@ -298,7 +298,7 @@ let is_binary_operator operator = match operator with | ":=" | "||" | "&&" | "=" | "==" | "<" | ">" | "!=" | "!==" | "<=" | ">=" | "|>" | "+" | "+." | "-" | "-." | "^" | "*" | "*." | "/" | "/." | "**" | "|." - | "|.u" | "<>" | "%" -> + | "<>" | "%" -> true | _ -> false @@ -714,11 +714,7 @@ let is_single_pipe_expr expr = match expr.pexp_desc with | Pexp_apply { - funct = - { - pexp_desc = - Pexp_ident {txt = Longident.Lident ("|." | "|.u" | "|>")}; - }; + funct = {pexp_desc = Pexp_ident {txt = Longident.Lident ("|." | "|>")}}; args = [(Nolabel, _operand1); (Nolabel, _operand2)]; } -> true @@ -727,10 +723,7 @@ let is_single_pipe_expr expr = match expr.pexp_desc with | Pexp_apply { - funct = - { - pexp_desc = Pexp_ident {txt = Longident.Lident ("|." | "|.u" | "|>")}; - }; + funct = {pexp_desc = Pexp_ident {txt = Longident.Lident ("|." | "|>")}}; args = [(Nolabel, operand1); (Nolabel, _operand2)]; } when not (is_pipe_expr operand1) -> diff --git a/compiler/syntax/src/res_printer.ml b/compiler/syntax/src/res_printer.ml index 6aa9aa809f..abdbdda9c6 100644 --- a/compiler/syntax/src/res_printer.ml +++ b/compiler/syntax/src/res_printer.ml @@ -3664,7 +3664,7 @@ and print_binary_expression ~state (expr : Parsetree.expression) cmt_tbl = let print_binary_operator ~inline_rhs operator = let operator_txt = match operator with - | "|." | "|.u" -> "->" + | "|." -> "->" | "^" -> "++" | "=" -> "==" | "==" -> "===" @@ -3673,12 +3673,12 @@ and print_binary_expression ~state (expr : Parsetree.expression) cmt_tbl = | txt -> txt in let spacing_before_operator = - if operator = "|." || operator = "|.u" then Doc.soft_line + if operator = "|." then Doc.soft_line else if operator = "|>" then Doc.line else Doc.space in let spacing_after_operator = - if operator = "|." || operator = "|.u" then Doc.nil + if operator = "|." then Doc.nil else if operator = "|>" then Doc.space else if inline_rhs then Doc.space else Doc.line @@ -3749,7 +3749,7 @@ and print_binary_expression ~state (expr : Parsetree.expression) cmt_tbl = ] else match operator with - | ("|." | "|.u") when is_multiline -> + | "|." when is_multiline -> (* If the pipe-chain is written over multiple lines, break automatically * `let x = a->b->c -> same line, break when line-width exceeded * `let x = a-> @@ -3855,8 +3855,7 @@ and print_binary_expression ~state (expr : Parsetree.expression) cmt_tbl = { funct = { - pexp_desc = - Pexp_ident {txt = Longident.Lident (("|." | "|.u" | "|>") as op)}; + pexp_desc = Pexp_ident {txt = Longident.Lident (("|." | "|>") as op)}; }; args = [(Nolabel, lhs); (Nolabel, rhs)]; } @@ -3874,8 +3873,8 @@ and print_binary_expression ~state (expr : Parsetree.expression) cmt_tbl = print_attributes ~state expr.pexp_attributes cmt_tbl; lhs_doc; (match (lhs_has_comment_below, op) with - | true, ("|." | "|.u") -> Doc.concat [Doc.soft_line; Doc.text "->"] - | false, ("|." | "|.u") -> Doc.text "->" + | true, "|." -> Doc.concat [Doc.soft_line; Doc.text "->"] + | false, "|." -> Doc.text "->" | true, "|>" -> Doc.concat [Doc.line; Doc.text "|> "] | false, "|>" -> Doc.text " |> " | _ -> Doc.nil); diff --git a/tests/syntax_tests/data/parsing/errors/expressions/expected/block.res.txt b/tests/syntax_tests/data/parsing/errors/expressions/expected/block.res.txt index 516cddbc73..804cd3c299 100644 --- a/tests/syntax_tests/data/parsing/errors/expressions/expected/block.res.txt +++ b/tests/syntax_tests/data/parsing/errors/expressions/expected/block.res.txt @@ -74,15 +74,14 @@ let findThreadByIdLinearScan [arity:2]~threads:((threads)[@res.namedArgLoc ]) otherPersonIDWhichIsAlsoThreadID | Group { id } -> id | Unknown { id } -> - (unknown.id |.u Js.String.make) |.u FBID.ofStringUnsafe in + (unknown.id |. Js.String.make) |. FBID.ofStringUnsafe in thisId == id) [@res.braces ]))) [@res.braces ]) -let x = ((loop 0 (Nil |.u (push doc)))[@res.braces ]) +let x = ((loop 0 (Nil |. (push doc)))[@res.braces ]) ;;match stack with | Empty -> [%rescript.exprhole ] | Cons (doc, rest) -> () - | Join (doc1, doc2) -> - (buffer |.u (Buffer.add_string indentation); loop ()) + | Join (doc1, doc2) -> (buffer |. (Buffer.add_string indentation); loop ()) let pipeline = match scheduler with | Some -> [%rescript.exprhole ] | None -> () \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/errors/structure/expected/gh16B.res.txt b/tests/syntax_tests/data/parsing/errors/structure/expected/gh16B.res.txt index 4303618ce3..073c27df3a 100644 --- a/tests/syntax_tests/data/parsing/errors/structure/expected/gh16B.res.txt +++ b/tests/syntax_tests/data/parsing/errors/structure/expected/gh16B.res.txt @@ -13,7 +13,7 @@ open Ws let wss = Server.make { port = 82 } -let address = wss |.u Server.address +let address = wss |. Server.address let log [arity:1]msg = Js.log (((((({js|> Server: |js})[@res.template ]) ^ msg)[@res.template ]) ^ @@ -21,7 +21,7 @@ let log [arity:1]msg = ;;log (((((((((((((({js|Running on: |js})[@res.template ]) ^ address.address) [@res.template ]) ^ (({js|:|js})[@res.template ])) - [@res.template ]) ^ (address.port |.u string_of_int)) + [@res.template ]) ^ (address.port |. string_of_int)) [@res.template ]) ^ (({js| (|js})[@res.template ])) [@res.template ]) ^ address.family) [@res.template ]) ^ (({js|)|js})[@res.template ]))[@res.template ]) @@ -31,8 +31,8 @@ module ClientSet = (Belt.Id.MakeComparable)(struct type nonrec t = Client.t let cmp [arity:2]a b = - ((compare (a |.u Client.getUniqueId) - (b |.u Client.getUniqueId)) + ((compare (a |. Client.getUniqueId) + (b |. Client.getUniqueId)) [@res.braces ]) end) let empty = Belt.Set.make ~id:(((module T))[@res.namedArgLoc ]) diff --git a/tests/syntax_tests/data/parsing/errors/structure/expected/letBinding.res.txt b/tests/syntax_tests/data/parsing/errors/structure/expected/letBinding.res.txt index 6208a830cd..525c5ca2d5 100644 --- a/tests/syntax_tests/data/parsing/errors/structure/expected/letBinding.res.txt +++ b/tests/syntax_tests/data/parsing/errors/structure/expected/letBinding.res.txt @@ -100,8 +100,8 @@ let rightResource = (ur.resources).find (fun [arity:1]r -> r.account_id == ((connection.left).account).id) -let x = ((let field = p |.u parseFieldDeclaration in field)[@res.braces ]) -let t = ((let (_, _, token) = scanner |.u scan in token)[@res.braces ]) +let x = ((let field = p |. parseFieldDeclaration in field)[@res.braces ]) +let t = ((let (_, _, token) = scanner |. scan in token)[@res.braces ]) let (keyTable : int Belt.Map.String.t) = [%rescript.exprhole ] let foo = [%rescript.exprhole ] let (x : int) = string = y diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/UncurriedAlways.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/UncurriedAlways.res.txt index a306f3cad4..6153d708e6 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/UncurriedAlways.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/UncurriedAlways.res.txt @@ -3,5 +3,5 @@ let foo [arity:2]x y = x + y let z = foo 3 4 let bar [arity:2]x y = x + y let b = bar 3 4 -let w = 3 |.u (foo 4) -let a = 3 |.u (foo 4) \ No newline at end of file +let w = 3 |. (foo 4) +let a = 3 |. (foo 4) \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/UncurriedByDefault.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/UncurriedByDefault.res.txt index 2b8c88feb1..c40f0bd3cf 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/UncurriedByDefault.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/UncurriedByDefault.res.txt @@ -91,7 +91,7 @@ type nonrec uu2 = unit -> unit -> unit (a:2) type nonrec up2 = unit -> unit -> unit (a:2) type nonrec cnested = (string -> unit (a:1)) -> unit (a:1) type nonrec unested = (string -> unit (a:1)) -> unit (a:1) -let pipe1 = 3 |.u f +let pipe1 = 3 |. f let (uannpoly : 'a -> string (a:1)) = xx let (uannint : int -> string (a:1)) = xx let _ = ((fun [arity:1]x -> 34)[@att ]) diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/arrow.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/arrow.res.txt index 08267a2656..7c1f85bad6 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/arrow.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/arrow.res.txt @@ -18,7 +18,7 @@ let f [arity:2](a, b) (c, d) = ((a + b) + c) + d let f [arity:1]exception Terminate = () let f [arity:2]exception Terminate exception Exit = () let f [arity:1][] = () -let f [arity:1](x::xs) = x + (xs |.u Belt.List.length) +let f [arity:1](x::xs) = x + (xs |. Belt.List.length) let f [arity:2](x : int) (y : int) = x + y let f [arity:2]~a:((a)[@res.namedArgLoc ]) ~b:((b)[@res.namedArgLoc ]) = a + b diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/async.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/async.res.txt index 0601fabd7b..7bdc3b6c94 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/async.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/async.res.txt @@ -10,11 +10,11 @@ let fetch2 = [@res.braces ]) let async = ((let f = async () in - () |.u async; + () |. async; async (); async.async; { async = (async.(async)) }; - (result |.u async) |.u (mapAsync (fun [arity:1]a -> doStuff a))) + (result |. async) |. (mapAsync (fun [arity:1]a -> doStuff a))) [@res.braces ]) let f = ((if isPositive @@ -25,7 +25,7 @@ let foo = async ~a:((34)[@res.namedArgLoc ]) let bar async [arity:1]~a:((a)[@res.namedArgLoc ]) = a + 1 let ex1 = ((3)[@res.await ]) + ((4)[@res.await ]) let ex2 = ((3)[@res.await ]) ** ((4)[@res.await ]) -let ex3 = ((foo |.u (bar ~arg:((arg)[@res.namedArgLoc ])))[@res.await ]) +let ex3 = ((foo |. (bar ~arg:((arg)[@res.namedArgLoc ])))[@res.await ]) let ex4 = (((foo.bar).baz)[@res.await ]) let attr1 = ((async fun [arity:1]x -> x + 1)[@a ]) let attr2 = ((fun (type a) -> diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/binary.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/binary.res.txt index 7627d666d6..569c60d23c 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/binary.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/binary.res.txt @@ -1,5 +1,5 @@ -;;node := (if newBalance == 2 then avl |.u (rotateRight node) else node) -;;node := ((if newBalance == 2 then avl |.u (rotateRight node) else node) +;;node := (if newBalance == 2 then avl |. (rotateRight node) else node) +;;node := ((if newBalance == 2 then avl |. (rotateRight node) else node) [@attr ]) let x = (match z with | _ -> false) z let x = ((match z with | _ -> false)[@attr ]) z @@ -19,6 +19,6 @@ let x = a -. b ;;Constructor (a, b) ;;`Constructor (a, b) let _ = ((Constructor (a, b); `Constructor (a, b))[@res.braces ]) -;;(library.getBalance account) |.u +;;(library.getBalance account) |. (Promise.Js.catch (fun [arity:1]_ -> ((Promise.resolved None)[@res.braces ]))) \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/binaryNoEs6Arrow.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/binaryNoEs6Arrow.res.txt index 99d0925970..c6c8d3b38e 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/binaryNoEs6Arrow.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/binaryNoEs6Arrow.res.txt @@ -27,7 +27,7 @@ | Some videoContainerRect -> let newChapter = ({ startTime = (percent *. duration) } : Video.chapter) in - { a; b } |.u onChange + { a; b } |. onChange | _ -> ()) [@res.braces ]))[@res.namedArgLoc ][@res.braces ]) ~children:[] ())[@JSX ]) diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/block.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/block.res.txt index 4c6941882b..3818e8d074 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/block.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/block.res.txt @@ -1,10 +1,10 @@ let b = ((let module Array = Belt.Array in - ([|1;2|] |.u (Array.map (fun [arity:1]x -> x + 1))) |.u Js.log) + ([|1;2|] |. (Array.map (fun [arity:1]x -> x + 1))) |. Js.log) [@res.braces ]) let b = ((let open Belt.Array in - ([|1;2|] |.u (map (fun [arity:1]x -> x + 1))) |.u Js.log) + ([|1;2|] |. (map (fun [arity:1]x -> x + 1))) |. Js.log) [@res.braces ]) let b = ((let exception QuitEarly in raise QuitEarly)[@res.braces ]) let b = ((let a = 1 in let b = 2 in a + b)[@res.braces ]) @@ -20,7 +20,7 @@ let b = let a = 1 in let b = 2 in sideEffect (); - (let x = (1 + 2) |.u (fun [arity:1]x -> x + 1) in + (let x = (1 + 2) |. (fun [arity:1]x -> x + 1) in raise (Terminate x))) [@res.braces ]) let b = ((f (); g (); h (); (let arr = [|1;2;3|] in ()))[@res.braces ]) diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/bracedOrRecord.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/bracedOrRecord.res.txt index 4ce05031bb..f146d83d43 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/bracedOrRecord.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/bracedOrRecord.res.txt @@ -26,4 +26,4 @@ let f = ((fun [arity:1]event -> (event.target).value)[@res.braces ]) let f = ((fun [arity:1]event -> ((event.target).value : string)) [@res.braces ]) let x = ((let a = 1 in let b = 2 in a + b)[@res.braces ]) -;;(([(({js|\n|js} |.u React.string)[@res.braces ])])[@JSX ]) \ No newline at end of file +;;(([(({js|\n|js} |. React.string)[@res.braces ])])[@JSX ]) \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/bsObject.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/bsObject.res.txt index 190921ce0a..ba0778d0b4 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/bsObject.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/bsObject.res.txt @@ -7,9 +7,9 @@ let z = [%obj { \xff = 1; \u2212 = {js|two|js}; \0 = zero; \o123 = {js|o123|js} }] let x = (({js|age|js})[@res.braces ]) let x = (({js|age|js}.(0))[@res.braces ]) -let x = (({js|age|js} |.u Js.log)[@res.braces ]) +let x = (({js|age|js} |. Js.log)[@res.braces ]) let x = ((if {js|age|js} then true else false)[@res.braces ][@res.ternary ]) -let x = (({js|age|js} |.u Js.log; (let foo = 1 in let bar = 2 in foo + bar)) +let x = (({js|age|js} |. Js.log; (let foo = 1 in let bar = 2 in foo + bar)) [@res.braces ]) let x = ((((if {js|age|js} then true else false) diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/firstClassModule.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/firstClassModule.res.txt index cdccb7e78f..99b7424c94 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/firstClassModule.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/firstClassModule.res.txt @@ -44,36 +44,35 @@ let build_dispatch_table [arity:1]handlers = ;;(module Three) ;;((module Three) : (module X_int)) ;;(module Teenager).(0) -;;((module Teenager) |.u age) |.u Js.log -;;((module Teenager).(0)) |.u Js.log -;;((if ((module Teenager) |.u age) |.u isAdult +;;((module Teenager) |. age) |. Js.log +;;((module Teenager).(0)) |. Js.log +;;((if ((module Teenager) |. age) |. isAdult then Js.log {js|has responsibilities|js} else Js.log {js|can play in the playground|js})[@res.ternary ]) -;;((if ((module Streets).(0)) |.u isExpensive +;;((if ((module Streets).(0)) |. isExpensive then Js.log {js|big money|js} else Js.log {js|affordable|js})[@res.ternary ]) -let () = ((((module Teenager) |.u age) |.u Js.log)[@res.braces ]) +let () = ((((module Teenager) |. age) |. Js.log)[@res.braces ]) let () = (((module Teenager).(0))[@res.braces ]) let () = - ((if ((module Teenager) |.u age) |.u isAdult + ((if ((module Teenager) |. age) |. isAdult then Js.log {js|has responsibilities|js} else Js.log {js|can play in the playground|js}) [@res.braces ][@res.ternary ]) let () = - ((if ((module Streets).(0)) |.u isExpensive + ((if ((module Streets).(0)) |. isExpensive then Js.log {js|big money|js} else Js.log {js|affordable|js}) [@res.braces ][@res.ternary ]) let () = ((let a = 1 in - let b = 2 in - (module Teenager).(0); ((module Teenager) |.u age) |.u Js.log) + let b = 2 in (module Teenager).(0); ((module Teenager) |. age) |. Js.log) [@res.braces ]) let () = ((let a = 1 in let b = 2 in - ((module Teenager) |.u age) |.u Js.log; - ((if (((module Teenager).(0)) |.u age) |.u isAdult + ((module Teenager) |. age) |. Js.log; + ((if (((module Teenager).(0)) |. age) |. isAdult then Js.log {js|has responsibilities|js} else Js.log {js|can play in the playground|js}) [@res.ternary ])) diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/infix.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/infix.res.txt index 9daea2caba..0d8bbd28c9 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/infix.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/infix.res.txt @@ -1,4 +1,4 @@ -;;a |.u (f b) +;;a |. (f b) ;;{js|string1|js} ^ {js|string2|js} ;;a <> b ;;a != b diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/jsx.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/jsx.res.txt index fca943b922..c101082eb7 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/jsx.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/jsx.res.txt @@ -524,7 +524,7 @@ let _ = ()) [@JSX ]) let _ = - ((X.createElement ~y:((z |.u (Belt.Option.getWithDefault {js||js})) + ((X.createElement ~y:((z |. (Belt.Option.getWithDefault {js||js})) [@res.namedArgLoc ][@res.braces ]) ~children:[] ()) [@JSX ]) let _ = @@ -533,10 +533,10 @@ let _ = [@JSX ]) let _ = ((div - ~children:[(((let left = limit |.u Int.toString in + ~children:[(((let left = limit |. Int.toString in (((((({js||js})[@res.template ]) ^ left)[@res.template ]) ^ (({js| characters left|js})[@res.template ])) - [@res.template ]) |.u React.string)) + [@res.template ]) |. React.string)) [@res.braces ])] ()) [@JSX ]) let _ = @@ -586,13 +586,13 @@ let _ = ;;((div ~children:((span ~children:[] ())[@JSX ]) ())[@JSX ]) ;;((div ~children:[|a|] ())[@JSX ]) ;;((div ~children:(1, 2) ())[@JSX ]) -;;((div ~children:((array |.u f)[@res.braces ]) ())[@JSX ]) +;;((div ~children:((array |. f)[@res.braces ]) ())[@JSX ]) ;;(([element])[@JSX ]) ;;(([(((fun [arity:1]a -> 1))[@res.braces ])])[@JSX ]) ;;(([((span ~children:[] ())[@JSX ])])[@JSX ]) ;;(([[|a|]])[@JSX ]) ;;(([(1, 2)])[@JSX ]) -;;(([((array |.u f)[@res.braces ])])[@JSX ]) +;;(([((array |. f)[@res.braces ])])[@JSX ]) let _ = ((A.createElement ~x:(({js|y|js})[@res.namedArgLoc ]) ~_spreadProps:((str) [@res.namedArgLoc ]) ~children:[] ()) diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/tupleVsDivision.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/tupleVsDivision.res.txt index 472331b774..e8b3e51a69 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/tupleVsDivision.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/tupleVsDivision.res.txt @@ -1,5 +1,5 @@ ;;(foo ()) / 1 ;;foo () -;;(1, 2) |.u printTuple -let f [arity:1]() = (((foo ()) / 1; foo (); (1, 2) |.u printTuple) +;;(1, 2) |. printTuple +let f [arity:1]() = (((foo ()) / 1; foo (); (1, 2) |. printTuple) [@res.braces ]) \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/underscoreApply.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/underscoreApply.res.txt index fd99198dba..cce859e65a 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/underscoreApply.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/underscoreApply.res.txt @@ -1,8 +1,8 @@ let l = - ([1; 2; 3] |.u (fun [arity:1]__x -> List.map (fun [arity:1]i -> i + 1) __x)) - |.u (fun [arity:1]__x -> List.filter (fun [arity:1]i -> i > 0) __x) + ([1; 2; 3] |. (fun [arity:1]__x -> List.map (fun [arity:1]i -> i + 1) __x)) + |. (fun [arity:1]__x -> List.filter (fun [arity:1]i -> i > 0) __x) let l = - (fun [arity:1]i -> i + 1) |.u (fun [arity:1]__x -> List.map __x [1; 2; 3]) + (fun [arity:1]i -> i + 1) |. (fun [arity:1]__x -> List.map __x [1; 2; 3]) let x [arity:1]__x = List.length __x let nested [arity:1]x [arity:1]__x = List.length __x let incr [arity:1]~v:((v)[@res.namedArgLoc ]) = v + 1 diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/while.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/while.res.txt index 91c85df409..bb1652c1e1 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/while.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/while.res.txt @@ -1,3 +1,3 @@ ;;while not eofReached do - let a = 1 in let b = 2 in Lexbuf.next (); (a + b) |.u Js.log done + let a = 1 in let b = 2 in Lexbuf.next (); (a + b) |. Js.log done ;;while (not (isLineEnding buf)) && true do foo (); next () done \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/infiniteLoops/expected/equalAfterBinaryExpr.res.txt b/tests/syntax_tests/data/parsing/infiniteLoops/expected/equalAfterBinaryExpr.res.txt index 8cca00a285..36557a596d 100644 --- a/tests/syntax_tests/data/parsing/infiniteLoops/expected/equalAfterBinaryExpr.res.txt +++ b/tests/syntax_tests/data/parsing/infiniteLoops/expected/equalAfterBinaryExpr.res.txt @@ -11,44 +11,43 @@ Did you mean `==` here? let rec _addLoop [arity:2]rbt currentNode = - ((if (Some currentNode) == (rbt |.u root) + ((if (Some currentNode) == (rbt |. root) then currentNode.color <- Black else - if (currentNode.parent |.u castNotOption).color == Black + if (currentNode.parent |. castNotOption).color == Black then () else if (((let uncle = uncleOf currentNode in - (uncle != None) && ((uncle |.u castNotOption).color == Red))) + (uncle != None) && ((uncle |. castNotOption).color == Red))) [@res.braces ]) then - ((currentNode.parent |.u castNotOption).color <- Black; - ((uncleOf currentNode) |.u castNotOption).color <- Black; - ((grandParentOf currentNode) |.u castNotOption).color <- Red; - _addLoop rbt ((grandParentOf currentNode) |.u castNotOption)) + ((currentNode.parent |. castNotOption).color <- Black; + ((uncleOf currentNode) |. castNotOption).color <- Black; + ((grandParentOf currentNode) |. castNotOption).color <- Red; + _addLoop rbt ((grandParentOf currentNode) |. castNotOption)) else (let currentNode = if (not (isLeft currentNode)) && - (isLeft (currentNode.parent |.u castNotOption)) + (isLeft (currentNode.parent |. castNotOption)) then - (rotateLeft rbt (currentNode.parent |.u castNotOption); - currentNode.left |.u castNotOption) + (rotateLeft rbt (currentNode.parent |. castNotOption); + currentNode.left |. castNotOption) else if (isLeft currentNode) && - (not (isLeft (currentNode.parent |.u castNotOption))) + (not (isLeft (currentNode.parent |. castNotOption))) then - (rotateRight rbt (currentNode.parent |.u castNotOption); - currentNode.right |.u castNotOption) + (rotateRight rbt (currentNode.parent |. castNotOption); + currentNode.right |. castNotOption) else currentNode in - (currentNode.parent |.u castNotOption).color <- Black; - ((grandParentOf currentNode) |.u castNotOption).color <- Red; + (currentNode.parent |. castNotOption).color <- Black; + ((grandParentOf currentNode) |. castNotOption).color <- Red; if isLeft currentNode then - rotateRight rbt ((grandParentOf currentNode) |.u castNotOption) - else - rotateLeft rbt ((grandParentOf currentNode) |.u castNotOption))) + rotateRight rbt ((grandParentOf currentNode) |. castNotOption) + else rotateLeft rbt ((grandParentOf currentNode) |. castNotOption))) [@res.braces ]) let removeNode [arity:2]rbt node = ((if nodeToRemove.color == Black @@ -56,7 +55,7 @@ let removeNode [arity:2]rbt node = (if successor.color == Red then (successor.color <- Black; - if successor.parent == None then rbt |.u (rootSet (Some successor))) + if successor.parent == None then rbt |. (rootSet (Some successor))) else (let break = ref false in let successorRef = ref successor in @@ -64,30 +63,30 @@ let removeNode [arity:2]rbt node = let successor = successorRef.contents in match successor.parent with | None -> - (rbt |.u (rootSet (Some successor)); break.contents <- true) + (rbt |. (rootSet (Some successor)); break.contents <- true) | Some successorParent -> let sibling = siblingOf successor in (if (sibling != None) && - ((sibling |.u castNotOption).color == Red) + ((sibling |. castNotOption).color == Red) then (successorParent.color <- Red; - (sibling |.u castNotOption).color <- Black; + (sibling |. castNotOption).color <- Black; if isLeft successor then rotateLeft rbt successorParent else rotateRight rbt successorParent); (let sibling = siblingOf successor in - let siblingNN = sibling |.u castNotOption in + let siblingNN = sibling |. castNotOption in if (successorParent.color == Black) && ((sibling == None) || (((siblingNN.color == Black) && ((siblingNN.left == None) || - ((siblingNN.left |.u castNotOption).color == + ((siblingNN.left |. castNotOption).color == Black))) && ((siblingNN.right == None) || - ((siblingNN.right |.u castNotOption).color == + ((siblingNN.right |. castNotOption).color == Black)))) then (if sibling != None then siblingNN.color <- Red; @@ -98,12 +97,12 @@ let removeNode [arity:2]rbt node = ((sibling == None) || (((siblingNN.color == Black) && ((siblingNN.left == None) || - ((siblingNN.left |.u castNotOption).color - == Black))) + ((siblingNN.left |. castNotOption).color == + Black))) && ((siblingNN.right == None) || - ((siblingNN.right |.u castNotOption).color - == Black)))) + ((siblingNN.right |. castNotOption).color == + Black)))) then (if sibling != None then siblingNN.color <- Red; successorParent.color <- Black; @@ -111,49 +110,47 @@ let removeNode [arity:2]rbt node = else if (sibling != None) && - ((sibling |.u castNotOption).color == Black) + ((sibling |. castNotOption).color == Black) then - (let sibling = sibling |.u castNotOption in + (let sibling = sibling |. castNotOption in if (((isLeft successor) && ((sibling.right == None) || - ((sibling.right |.u castNotOption).color == + ((sibling.right |. castNotOption).color == Black))) && (sibling.left != None)) && - ((sibling.left |.u castNotOption).color == Red) + ((sibling.left |. castNotOption).color == Red) then (sibling.color <- Red; - (sibling.left |.u castNotOption).color <- Black; + (sibling.left |. castNotOption).color <- Black; rotateRight rbt sibling) else if (((not (isLeft successor)) && ((sibling.left == None) || - ((sibling.left |.u castNotOption).color - == Black))) + ((sibling.left |. castNotOption).color == + Black))) && (sibling.right != None)) && - ((sibling.right |.u castNotOption).color == - Red) + ((sibling.right |. castNotOption).color == Red) then (sibling.color <- Red; - (sibling.right |.u castNotOption).color <- - Black; + (sibling.right |. castNotOption).color <- Black; rotateLeft rbt sibling); break.contents <- true) else (let sibling = siblingOf successor in - let sibling = sibling |.u castNotOption in + let sibling = sibling |. castNotOption in sibling.color <- (successorParent.color); if isLeft successor then - ((sibling.right |.u castNotOption).color <- Black; + ((sibling.right |. castNotOption).color <- Black; rotateRight rbt successorParent) else - ((sibling.left |.u castNotOption).color <- Black; + ((sibling.left |. castNotOption).color <- Black; rotateLeft rbt successorParent)))) done)); if isLeaf successor - then (if (rbt |.u root) == (Some successor) then (rbt |.u root) = None)) + then (if (rbt |. root) == (Some successor) then (rbt |. root) = None)) [@res.braces ]) \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/recovery/expression/expected/infinite.res.txt b/tests/syntax_tests/data/parsing/recovery/expression/expected/infinite.res.txt index 90da3f773b..f036ffb7a1 100644 --- a/tests/syntax_tests/data/parsing/recovery/expression/expected/infinite.res.txt +++ b/tests/syntax_tests/data/parsing/recovery/expression/expected/infinite.res.txt @@ -1 +1 @@ -let smallest = (heap.compare ()) < (a |.u (f b)) \ No newline at end of file +let smallest = (heap.compare ()) < (a |. (f b)) \ No newline at end of file From 5f66f9a64fc5cafc8698ca8a25d1d21fced00a87 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Sat, 11 Jan 2025 17:29:36 +0100 Subject: [PATCH 2/5] Rename binary operator "|." to "->" in the internal representation. --- .../larger-project/src/res_comments_table.res | 2 +- .../src/res_parsetree_viewer.res | 8 +- .../larger-project/src/res_printer.res | 1 - analysis/src/CompletionFrontEnd.ml | 20 ++--- analysis/src/SignatureHelp.ml | 2 +- compiler/frontend/ast_exp_apply.ml | 6 +- compiler/ml/env.ml | 2 +- compiler/syntax/src/res_comments_table.ml | 2 +- compiler/syntax/src/res_core.ml | 3 +- compiler/syntax/src/res_parens.ml | 2 +- compiler/syntax/src/res_parsetree_viewer.ml | 8 +- compiler/syntax/src/res_printer.ml | 13 ++-- .../errors/expressions/expected/block.res.txt | 6 +- .../errors/structure/expected/gh16B.res.txt | 8 +- .../structure/expected/letBinding.res.txt | 4 +- .../expected/UncurriedAlways.res.txt | 4 +- .../expected/UncurriedByDefault.res.txt | 2 +- .../expressions/expected/arrow.res.txt | 2 +- .../expressions/expected/async.res.txt | 6 +- .../expressions/expected/binary.res.txt | 6 +- .../expected/binaryNoEs6Arrow.res.txt | 2 +- .../expressions/expected/block.res.txt | 6 +- .../expected/bracedOrRecord.res.txt | 2 +- .../expressions/expected/bsObject.res.txt | 4 +- .../expected/firstClassModule.res.txt | 20 ++--- .../expressions/expected/infix.res.txt | 2 +- .../grammar/expressions/expected/jsx.res.txt | 10 +-- .../expected/tupleVsDivision.res.txt | 4 +- .../expected/underscoreApply.res.txt | 6 +- .../expressions/expected/while.res.txt | 2 +- .../expected/equalAfterBinaryExpr.res.txt | 76 +++++++++---------- .../expression/expected/infinite.res.txt | 2 +- 32 files changed, 120 insertions(+), 123 deletions(-) diff --git a/analysis/examples/larger-project/src/res_comments_table.res b/analysis/examples/larger-project/src/res_comments_table.res index f2616345b7..9683e9f28c 100644 --- a/analysis/examples/larger-project/src/res_comments_table.res +++ b/analysis/examples/larger-project/src/res_comments_table.res @@ -1256,7 +1256,7 @@ and walkExpr = (expr, t, comments) => { | "/" | "/." | "**" - | "|." + | "->" | "<>", ), }), diff --git a/analysis/examples/larger-project/src/res_parsetree_viewer.res b/analysis/examples/larger-project/src/res_parsetree_viewer.res index 9070883a7c..619f4930fc 100644 --- a/analysis/examples/larger-project/src/res_parsetree_viewer.res +++ b/analysis/examples/larger-project/src/res_parsetree_viewer.res @@ -270,7 +270,7 @@ let operatorPrecedence = operator => | "+" | "+." | "-" | "-." | "^" => 5 | "*" | "*." | "/" | "/." => 6 | "**" => 7 - | "#" | "##" | "|." => 8 + | "#" | "##" | "->" => 8 | _ => 0 } @@ -312,7 +312,7 @@ let isBinaryOperator = operator => | "/" | "/." | "**" - | "|." + | "->" | "<>" => true | _ => false } @@ -649,7 +649,7 @@ let isSinglePipeExpr = expr => { let isPipeExpr = expr => switch expr.pexp_desc { | Pexp_apply( - {pexp_desc: Pexp_ident({txt: Longident.Lident("|." | "|>")})}, + {pexp_desc: Pexp_ident({txt: Longident.Lident("->" | "|>")})}, list{(Nolabel, _operand1), (Nolabel, _operand2)}, ) => true | _ => false @@ -657,7 +657,7 @@ let isSinglePipeExpr = expr => { switch expr.pexp_desc { | Pexp_apply( - {pexp_desc: Pexp_ident({txt: Longident.Lident("|." | "|>")})}, + {pexp_desc: Pexp_ident({txt: Longident.Lident("->" | "|>")})}, list{(Nolabel, operand1), (Nolabel, _operand2)}, ) if !isPipeExpr(operand1) => true | _ => false diff --git a/analysis/examples/larger-project/src/res_printer.res b/analysis/examples/larger-project/src/res_printer.res index 7dfa5014fe..d8613ef9bf 100644 --- a/analysis/examples/larger-project/src/res_printer.res +++ b/analysis/examples/larger-project/src/res_printer.res @@ -3495,7 +3495,6 @@ and printUnaryExpression = (expr, cmtTbl) => { and printBinaryExpression = (expr: Parsetree.expression, cmtTbl) => { let printBinaryOperator = (~inlineRhs, operator) => { let operatorTxt = switch operator { - | "|." => "->" | "^" => "++" | "=" => "==" | "==" => "===" diff --git a/analysis/src/CompletionFrontEnd.ml b/analysis/src/CompletionFrontEnd.ml index a8f4085b45..dc5fd62a47 100644 --- a/analysis/src/CompletionFrontEnd.ml +++ b/analysis/src/CompletionFrontEnd.ml @@ -218,7 +218,7 @@ let rec exprToContextPathInner (e : Parsetree.expression) = (match exprs with | [] -> None | exp :: _ -> exprToContextPath exp)) - | Pexp_ident {txt = Lident "|."} -> None + | Pexp_ident {txt = Lident "->"} -> None | Pexp_ident {txt; loc} -> Some (CPId {path = Utils.flattenLongIdent txt; completionContext = Value; loc}) @@ -258,7 +258,7 @@ let rec exprToContextPathInner (e : Parsetree.expression) = { funct = { - pexp_desc = Pexp_ident {txt = Lident "|."}; + pexp_desc = Pexp_ident {txt = Lident "->"}; pexp_loc; pexp_attributes; }; @@ -275,7 +275,7 @@ let rec exprToContextPathInner (e : Parsetree.expression) = } | Pexp_apply { - funct = {pexp_desc = Pexp_ident {txt = Lident "|."}}; + funct = {pexp_desc = Pexp_ident {txt = Lident "->"}}; args = [ (_, lhs); (_, {pexp_desc = Pexp_ident id; pexp_loc; pexp_attributes}); @@ -328,7 +328,7 @@ let completePipeChain (exp : Parsetree.expression) = Example: someArray->Js.Array2.map(v => v + 2)-> *) | Pexp_apply { - funct = {pexp_desc = Pexp_ident {txt = Lident "|."}}; + funct = {pexp_desc = Pexp_ident {txt = Lident "->"}}; args = [_; (_, {pexp_desc = Pexp_apply {funct = d}})]; } -> exprToContextPath exp |> Option.map (fun ctxPath -> (ctxPath, d.pexp_loc)) @@ -336,7 +336,7 @@ let completePipeChain (exp : Parsetree.expression) = Example: someArray->filterAllTheGoodStuff-> *) | Pexp_apply { - funct = {pexp_desc = Pexp_ident {txt = Lident "|."}}; + funct = {pexp_desc = Pexp_ident {txt = Lident "->"}}; args = [_; (_, {pexp_desc = Pexp_ident _; pexp_loc})]; } -> exprToContextPath exp |> Option.map (fun ctxPath -> (ctxPath, pexp_loc)) @@ -1113,7 +1113,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor resetCurrentCtxPath oldCtxPath | Pexp_apply { - funct = {pexp_desc = Pexp_ident {txt = Lident "|."; loc = opLoc}}; + funct = {pexp_desc = Pexp_ident {txt = Lident "->"; loc = opLoc}}; args = [ (_, lhs); @@ -1291,7 +1291,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor else iterateJsxProps ~iterator jsxProps | Pexp_apply { - funct = {pexp_desc = Pexp_ident {txt = Lident "|."}}; + funct = {pexp_desc = Pexp_ident {txt = Lident "->"}}; args = [ (_, lhs); @@ -1303,7 +1303,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor setPipeResult ~lhs ~id |> ignore | Pexp_apply { - funct = {pexp_desc = Pexp_ident {txt = Lident "|."; loc = opLoc}}; + funct = {pexp_desc = Pexp_ident {txt = Lident "->"; loc = opLoc}}; args = [(_, lhs); _]; } when Loc.end_ opLoc = posCursor -> @@ -1311,7 +1311,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor setPipeResult ~lhs ~id:"" |> ignore | Pexp_apply { - funct = {pexp_desc = Pexp_ident {txt = Lident "|."}}; + funct = {pexp_desc = Pexp_ident {txt = Lident "->"}}; args = [_; (_, {pexp_desc = Pexp_apply {funct = funExpr; args}})]; } when (* Normally named arg completion fires when the cursor is right after the expression. @@ -1347,7 +1347,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor | Some argCompletable -> setResult argCompletable) | Pexp_apply { - funct = {pexp_desc = Pexp_ident {txt = Lident "|."}}; + funct = {pexp_desc = Pexp_ident {txt = Lident "->"}}; args = [_; _]; } -> (* Ignore any other pipe. *) diff --git a/analysis/src/SignatureHelp.ml b/analysis/src/SignatureHelp.ml index a9a1159a8f..42ca312851 100644 --- a/analysis/src/SignatureHelp.ml +++ b/analysis/src/SignatureHelp.ml @@ -365,7 +365,7 @@ let signatureHelp ~path ~pos ~currentFile ~debug ~allowForConstructorPayloads = pexp_desc = Pexp_apply { - funct = {pexp_desc = Pexp_ident {txt = Lident "|."}}; + funct = {pexp_desc = Pexp_ident {txt = Lident "->"}}; args = [ _; diff --git a/compiler/frontend/ast_exp_apply.ml b/compiler/frontend/ast_exp_apply.ml index 932b096e49..fb5b500db9 100644 --- a/compiler/frontend/ast_exp_apply.ml +++ b/compiler/frontend/ast_exp_apply.ml @@ -69,11 +69,11 @@ let view_as_app (fn : exp) (s : string list) : app_pattern option = Some {op; loc = fn.pexp_loc; args = check_and_discard args} | _ -> None -let infix_ops = ["|."; "#="; "##"] +let infix_ops = ["->"; "#="; "##"] let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) : exp = match view_as_app e infix_ops with - | Some {op = "|."; args = [a_; f_]; loc} -> ( + | Some {op = "->"; args = [a_; f_]; loc} -> ( (* a |. f a |. f b c [@bs] --> f a b c [@bs] @@ -193,7 +193,7 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) : exp = } -> gen_assignment obj name name_loc | _ -> Location.raise_errorf ~loc "invalid #= assignment")) - | Some {op = "|."; loc} -> + | Some {op = "->"; loc} -> Location.raise_errorf ~loc "invalid |. syntax, it can only be used as binary operator" | Some {op = "##"; loc} -> diff --git a/compiler/ml/env.ml b/compiler/ml/env.ml index 474f45d805..1547d3450b 100644 --- a/compiler/ml/env.ml +++ b/compiler/ml/env.ml @@ -1624,7 +1624,7 @@ and check_value_name name loc = (* Note: we could also check here general validity of the identifier, to protect against bad identifiers forged by -pp or -ppx preprocessors. *) - if name = "|." then raise (Error (Illegal_value_name (loc, name))) + if name = "->" then raise (Error (Illegal_value_name (loc, name))) else if String.length name > 0 && name.[0] = '#' then for i = 1 to String.length name - 1 do if name.[i] = '#' then raise (Error (Illegal_value_name (loc, name))) diff --git a/compiler/syntax/src/res_comments_table.ml b/compiler/syntax/src/res_comments_table.ml index 2fa92cbf7e..e21cedd9e4 100644 --- a/compiler/syntax/src/res_comments_table.ml +++ b/compiler/syntax/src/res_comments_table.ml @@ -1340,7 +1340,7 @@ and walk_expression expr t comments = Longident.Lident ( ":=" | "||" | "&&" | "=" | "==" | "<" | ">" | "!=" | "!==" | "<=" | ">=" | "|>" | "+" | "+." | "-" | "-." - | "++" | "^" | "*" | "*." | "/" | "/." | "**" | "|." + | "++" | "^" | "*" | "*." | "/" | "/." | "**" | "->" | "<>" ); }; }; diff --git a/compiler/syntax/src/res_core.ml b/compiler/syntax/src/res_core.ml index 91bf9ef84f..fd3f928138 100644 --- a/compiler/syntax/src/res_core.ml +++ b/compiler/syntax/src/res_core.ml @@ -391,8 +391,7 @@ let build_longident words = let make_infix_operator (p : Parser.t) token start_pos end_pos = let stringified_token = - if token = Token.MinusGreater then "|." - else if token = Token.PlusPlus then "^" + if token = Token.PlusPlus then "^" else if token = Token.BangEqual then "<>" else if token = Token.BangEqualEqual then "!=" else if token = Token.Equal then ( diff --git a/compiler/syntax/src/res_parens.ml b/compiler/syntax/src/res_parens.ml index 3c87e6785e..6b59c67c25 100644 --- a/compiler/syntax/src/res_parens.ml +++ b/compiler/syntax/src/res_parens.ml @@ -192,7 +192,7 @@ let flatten_operand_rhs parent_operator rhs = let binary_operator_inside_await_needs_parens operator = ParsetreeViewer.operator_precedence operator - < ParsetreeViewer.operator_precedence "|." + < ParsetreeViewer.operator_precedence "->" let lazy_or_assert_or_await_expr_rhs ?(in_await = false) expr = let opt_braces, _ = ParsetreeViewer.process_braces_attr expr in diff --git a/compiler/syntax/src/res_parsetree_viewer.ml b/compiler/syntax/src/res_parsetree_viewer.ml index d5bcb5da09..b030426e55 100644 --- a/compiler/syntax/src/res_parsetree_viewer.ml +++ b/compiler/syntax/src/res_parsetree_viewer.ml @@ -274,7 +274,7 @@ let operator_precedence operator = | "+" | "+." | "-" | "-." | "^" -> 5 | "*" | "*." | "/" | "/." | "%" -> 6 | "**" -> 7 - | "#" | "##" | "|." -> 8 + | "#" | "##" | "->" -> 8 | _ -> 0 let is_unary_operator operator = @@ -297,7 +297,7 @@ let is_unary_expression expr = let is_binary_operator operator = match operator with | ":=" | "||" | "&&" | "=" | "==" | "<" | ">" | "!=" | "!==" | "<=" | ">=" - | "|>" | "+" | "+." | "-" | "-." | "^" | "*" | "*." | "/" | "/." | "**" | "|." + | "|>" | "+" | "+." | "-" | "-." | "^" | "*" | "*." | "/" | "/." | "**" | "->" | "<>" | "%" -> true | _ -> false @@ -714,7 +714,7 @@ let is_single_pipe_expr expr = match expr.pexp_desc with | Pexp_apply { - funct = {pexp_desc = Pexp_ident {txt = Longident.Lident ("|." | "|>")}}; + funct = {pexp_desc = Pexp_ident {txt = Longident.Lident ("->" | "|>")}}; args = [(Nolabel, _operand1); (Nolabel, _operand2)]; } -> true @@ -723,7 +723,7 @@ let is_single_pipe_expr expr = match expr.pexp_desc with | Pexp_apply { - funct = {pexp_desc = Pexp_ident {txt = Longident.Lident ("|." | "|>")}}; + funct = {pexp_desc = Pexp_ident {txt = Longident.Lident ("->" | "|>")}}; args = [(Nolabel, operand1); (Nolabel, _operand2)]; } when not (is_pipe_expr operand1) -> diff --git a/compiler/syntax/src/res_printer.ml b/compiler/syntax/src/res_printer.ml index abdbdda9c6..3fae201ba1 100644 --- a/compiler/syntax/src/res_printer.ml +++ b/compiler/syntax/src/res_printer.ml @@ -3664,7 +3664,6 @@ and print_binary_expression ~state (expr : Parsetree.expression) cmt_tbl = let print_binary_operator ~inline_rhs operator = let operator_txt = match operator with - | "|." -> "->" | "^" -> "++" | "=" -> "==" | "==" -> "===" @@ -3673,12 +3672,12 @@ and print_binary_expression ~state (expr : Parsetree.expression) cmt_tbl = | txt -> txt in let spacing_before_operator = - if operator = "|." then Doc.soft_line + if operator = "->" then Doc.soft_line else if operator = "|>" then Doc.line else Doc.space in let spacing_after_operator = - if operator = "|." then Doc.nil + if operator = "->" then Doc.nil else if operator = "|>" then Doc.space else if inline_rhs then Doc.space else Doc.line @@ -3749,7 +3748,7 @@ and print_binary_expression ~state (expr : Parsetree.expression) cmt_tbl = ] else match operator with - | "|." when is_multiline -> + | "->" when is_multiline -> (* If the pipe-chain is written over multiple lines, break automatically * `let x = a->b->c -> same line, break when line-width exceeded * `let x = a-> @@ -3855,7 +3854,7 @@ and print_binary_expression ~state (expr : Parsetree.expression) cmt_tbl = { funct = { - pexp_desc = Pexp_ident {txt = Longident.Lident (("|." | "|>") as op)}; + pexp_desc = Pexp_ident {txt = Longident.Lident (("->" | "|>") as op)}; }; args = [(Nolabel, lhs); (Nolabel, rhs)]; } @@ -3873,8 +3872,8 @@ and print_binary_expression ~state (expr : Parsetree.expression) cmt_tbl = print_attributes ~state expr.pexp_attributes cmt_tbl; lhs_doc; (match (lhs_has_comment_below, op) with - | true, "|." -> Doc.concat [Doc.soft_line; Doc.text "->"] - | false, "|." -> Doc.text "->" + | true, "->" -> Doc.concat [Doc.soft_line; Doc.text "->"] + | false, "->" -> Doc.text "->" | true, "|>" -> Doc.concat [Doc.line; Doc.text "|> "] | false, "|>" -> Doc.text " |> " | _ -> Doc.nil); diff --git a/tests/syntax_tests/data/parsing/errors/expressions/expected/block.res.txt b/tests/syntax_tests/data/parsing/errors/expressions/expected/block.res.txt index 804cd3c299..abb4a962d2 100644 --- a/tests/syntax_tests/data/parsing/errors/expressions/expected/block.res.txt +++ b/tests/syntax_tests/data/parsing/errors/expressions/expected/block.res.txt @@ -74,14 +74,14 @@ let findThreadByIdLinearScan [arity:2]~threads:((threads)[@res.namedArgLoc ]) otherPersonIDWhichIsAlsoThreadID | Group { id } -> id | Unknown { id } -> - (unknown.id |. Js.String.make) |. FBID.ofStringUnsafe in + (unknown.id -> Js.String.make) -> FBID.ofStringUnsafe in thisId == id) [@res.braces ]))) [@res.braces ]) -let x = ((loop 0 (Nil |. (push doc)))[@res.braces ]) +let x = ((loop 0 (Nil -> (push doc)))[@res.braces ]) ;;match stack with | Empty -> [%rescript.exprhole ] | Cons (doc, rest) -> () - | Join (doc1, doc2) -> (buffer |. (Buffer.add_string indentation); loop ()) + | Join (doc1, doc2) -> (buffer -> (Buffer.add_string indentation); loop ()) let pipeline = match scheduler with | Some -> [%rescript.exprhole ] | None -> () \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/errors/structure/expected/gh16B.res.txt b/tests/syntax_tests/data/parsing/errors/structure/expected/gh16B.res.txt index 073c27df3a..8f805a3c59 100644 --- a/tests/syntax_tests/data/parsing/errors/structure/expected/gh16B.res.txt +++ b/tests/syntax_tests/data/parsing/errors/structure/expected/gh16B.res.txt @@ -13,7 +13,7 @@ open Ws let wss = Server.make { port = 82 } -let address = wss |. Server.address +let address = wss -> Server.address let log [arity:1]msg = Js.log (((((({js|> Server: |js})[@res.template ]) ^ msg)[@res.template ]) ^ @@ -21,7 +21,7 @@ let log [arity:1]msg = ;;log (((((((((((((({js|Running on: |js})[@res.template ]) ^ address.address) [@res.template ]) ^ (({js|:|js})[@res.template ])) - [@res.template ]) ^ (address.port |. string_of_int)) + [@res.template ]) ^ (address.port -> string_of_int)) [@res.template ]) ^ (({js| (|js})[@res.template ])) [@res.template ]) ^ address.family) [@res.template ]) ^ (({js|)|js})[@res.template ]))[@res.template ]) @@ -31,8 +31,8 @@ module ClientSet = (Belt.Id.MakeComparable)(struct type nonrec t = Client.t let cmp [arity:2]a b = - ((compare (a |. Client.getUniqueId) - (b |. Client.getUniqueId)) + ((compare (a -> Client.getUniqueId) + (b -> Client.getUniqueId)) [@res.braces ]) end) let empty = Belt.Set.make ~id:(((module T))[@res.namedArgLoc ]) diff --git a/tests/syntax_tests/data/parsing/errors/structure/expected/letBinding.res.txt b/tests/syntax_tests/data/parsing/errors/structure/expected/letBinding.res.txt index 525c5ca2d5..739d1f5329 100644 --- a/tests/syntax_tests/data/parsing/errors/structure/expected/letBinding.res.txt +++ b/tests/syntax_tests/data/parsing/errors/structure/expected/letBinding.res.txt @@ -100,8 +100,8 @@ let rightResource = (ur.resources).find (fun [arity:1]r -> r.account_id == ((connection.left).account).id) -let x = ((let field = p |. parseFieldDeclaration in field)[@res.braces ]) -let t = ((let (_, _, token) = scanner |. scan in token)[@res.braces ]) +let x = ((let field = p -> parseFieldDeclaration in field)[@res.braces ]) +let t = ((let (_, _, token) = scanner -> scan in token)[@res.braces ]) let (keyTable : int Belt.Map.String.t) = [%rescript.exprhole ] let foo = [%rescript.exprhole ] let (x : int) = string = y diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/UncurriedAlways.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/UncurriedAlways.res.txt index 6153d708e6..a966518a11 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/UncurriedAlways.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/UncurriedAlways.res.txt @@ -3,5 +3,5 @@ let foo [arity:2]x y = x + y let z = foo 3 4 let bar [arity:2]x y = x + y let b = bar 3 4 -let w = 3 |. (foo 4) -let a = 3 |. (foo 4) \ No newline at end of file +let w = 3 -> (foo 4) +let a = 3 -> (foo 4) \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/UncurriedByDefault.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/UncurriedByDefault.res.txt index c40f0bd3cf..069776547b 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/UncurriedByDefault.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/UncurriedByDefault.res.txt @@ -91,7 +91,7 @@ type nonrec uu2 = unit -> unit -> unit (a:2) type nonrec up2 = unit -> unit -> unit (a:2) type nonrec cnested = (string -> unit (a:1)) -> unit (a:1) type nonrec unested = (string -> unit (a:1)) -> unit (a:1) -let pipe1 = 3 |. f +let pipe1 = 3 -> f let (uannpoly : 'a -> string (a:1)) = xx let (uannint : int -> string (a:1)) = xx let _ = ((fun [arity:1]x -> 34)[@att ]) diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/arrow.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/arrow.res.txt index 7c1f85bad6..60d6e9da1e 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/arrow.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/arrow.res.txt @@ -18,7 +18,7 @@ let f [arity:2](a, b) (c, d) = ((a + b) + c) + d let f [arity:1]exception Terminate = () let f [arity:2]exception Terminate exception Exit = () let f [arity:1][] = () -let f [arity:1](x::xs) = x + (xs |. Belt.List.length) +let f [arity:1](x::xs) = x + (xs -> Belt.List.length) let f [arity:2](x : int) (y : int) = x + y let f [arity:2]~a:((a)[@res.namedArgLoc ]) ~b:((b)[@res.namedArgLoc ]) = a + b diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/async.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/async.res.txt index 7bdc3b6c94..0c811af33f 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/async.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/async.res.txt @@ -10,11 +10,11 @@ let fetch2 = [@res.braces ]) let async = ((let f = async () in - () |. async; + () -> async; async (); async.async; { async = (async.(async)) }; - (result |. async) |. (mapAsync (fun [arity:1]a -> doStuff a))) + (result -> async) -> (mapAsync (fun [arity:1]a -> doStuff a))) [@res.braces ]) let f = ((if isPositive @@ -25,7 +25,7 @@ let foo = async ~a:((34)[@res.namedArgLoc ]) let bar async [arity:1]~a:((a)[@res.namedArgLoc ]) = a + 1 let ex1 = ((3)[@res.await ]) + ((4)[@res.await ]) let ex2 = ((3)[@res.await ]) ** ((4)[@res.await ]) -let ex3 = ((foo |. (bar ~arg:((arg)[@res.namedArgLoc ])))[@res.await ]) +let ex3 = ((foo -> (bar ~arg:((arg)[@res.namedArgLoc ])))[@res.await ]) let ex4 = (((foo.bar).baz)[@res.await ]) let attr1 = ((async fun [arity:1]x -> x + 1)[@a ]) let attr2 = ((fun (type a) -> diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/binary.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/binary.res.txt index 569c60d23c..4e54e2c4e0 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/binary.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/binary.res.txt @@ -1,5 +1,5 @@ -;;node := (if newBalance == 2 then avl |. (rotateRight node) else node) -;;node := ((if newBalance == 2 then avl |. (rotateRight node) else node) +;;node := (if newBalance == 2 then avl -> (rotateRight node) else node) +;;node := ((if newBalance == 2 then avl -> (rotateRight node) else node) [@attr ]) let x = (match z with | _ -> false) z let x = ((match z with | _ -> false)[@attr ]) z @@ -19,6 +19,6 @@ let x = a -. b ;;Constructor (a, b) ;;`Constructor (a, b) let _ = ((Constructor (a, b); `Constructor (a, b))[@res.braces ]) -;;(library.getBalance account) |. +;;(library.getBalance account) -> (Promise.Js.catch (fun [arity:1]_ -> ((Promise.resolved None)[@res.braces ]))) \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/binaryNoEs6Arrow.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/binaryNoEs6Arrow.res.txt index c6c8d3b38e..14693a33fb 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/binaryNoEs6Arrow.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/binaryNoEs6Arrow.res.txt @@ -27,7 +27,7 @@ | Some videoContainerRect -> let newChapter = ({ startTime = (percent *. duration) } : Video.chapter) in - { a; b } |. onChange + { a; b } -> onChange | _ -> ()) [@res.braces ]))[@res.namedArgLoc ][@res.braces ]) ~children:[] ())[@JSX ]) diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/block.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/block.res.txt index 3818e8d074..48be97d9a8 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/block.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/block.res.txt @@ -1,10 +1,10 @@ let b = ((let module Array = Belt.Array in - ([|1;2|] |. (Array.map (fun [arity:1]x -> x + 1))) |. Js.log) + ([|1;2|] -> (Array.map (fun [arity:1]x -> x + 1))) -> Js.log) [@res.braces ]) let b = ((let open Belt.Array in - ([|1;2|] |. (map (fun [arity:1]x -> x + 1))) |. Js.log) + ([|1;2|] -> (map (fun [arity:1]x -> x + 1))) -> Js.log) [@res.braces ]) let b = ((let exception QuitEarly in raise QuitEarly)[@res.braces ]) let b = ((let a = 1 in let b = 2 in a + b)[@res.braces ]) @@ -20,7 +20,7 @@ let b = let a = 1 in let b = 2 in sideEffect (); - (let x = (1 + 2) |. (fun [arity:1]x -> x + 1) in + (let x = (1 + 2) -> (fun [arity:1]x -> x + 1) in raise (Terminate x))) [@res.braces ]) let b = ((f (); g (); h (); (let arr = [|1;2;3|] in ()))[@res.braces ]) diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/bracedOrRecord.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/bracedOrRecord.res.txt index f146d83d43..d561dd0ad7 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/bracedOrRecord.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/bracedOrRecord.res.txt @@ -26,4 +26,4 @@ let f = ((fun [arity:1]event -> (event.target).value)[@res.braces ]) let f = ((fun [arity:1]event -> ((event.target).value : string)) [@res.braces ]) let x = ((let a = 1 in let b = 2 in a + b)[@res.braces ]) -;;(([(({js|\n|js} |. React.string)[@res.braces ])])[@JSX ]) \ No newline at end of file +;;(([(({js|\n|js} -> React.string)[@res.braces ])])[@JSX ]) \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/bsObject.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/bsObject.res.txt index ba0778d0b4..006c2a2ded 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/bsObject.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/bsObject.res.txt @@ -7,9 +7,9 @@ let z = [%obj { \xff = 1; \u2212 = {js|two|js}; \0 = zero; \o123 = {js|o123|js} }] let x = (({js|age|js})[@res.braces ]) let x = (({js|age|js}.(0))[@res.braces ]) -let x = (({js|age|js} |. Js.log)[@res.braces ]) +let x = (({js|age|js} -> Js.log)[@res.braces ]) let x = ((if {js|age|js} then true else false)[@res.braces ][@res.ternary ]) -let x = (({js|age|js} |. Js.log; (let foo = 1 in let bar = 2 in foo + bar)) +let x = (({js|age|js} -> Js.log; (let foo = 1 in let bar = 2 in foo + bar)) [@res.braces ]) let x = ((((if {js|age|js} then true else false) diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/firstClassModule.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/firstClassModule.res.txt index 99b7424c94..2e7a5a90ed 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/firstClassModule.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/firstClassModule.res.txt @@ -44,35 +44,35 @@ let build_dispatch_table [arity:1]handlers = ;;(module Three) ;;((module Three) : (module X_int)) ;;(module Teenager).(0) -;;((module Teenager) |. age) |. Js.log -;;((module Teenager).(0)) |. Js.log -;;((if ((module Teenager) |. age) |. isAdult +;;((module Teenager) -> age) -> Js.log +;;((module Teenager).(0)) -> Js.log +;;((if ((module Teenager) -> age) -> isAdult then Js.log {js|has responsibilities|js} else Js.log {js|can play in the playground|js})[@res.ternary ]) -;;((if ((module Streets).(0)) |. isExpensive +;;((if ((module Streets).(0)) -> isExpensive then Js.log {js|big money|js} else Js.log {js|affordable|js})[@res.ternary ]) -let () = ((((module Teenager) |. age) |. Js.log)[@res.braces ]) +let () = ((((module Teenager) -> age) -> Js.log)[@res.braces ]) let () = (((module Teenager).(0))[@res.braces ]) let () = - ((if ((module Teenager) |. age) |. isAdult + ((if ((module Teenager) -> age) -> isAdult then Js.log {js|has responsibilities|js} else Js.log {js|can play in the playground|js}) [@res.braces ][@res.ternary ]) let () = - ((if ((module Streets).(0)) |. isExpensive + ((if ((module Streets).(0)) -> isExpensive then Js.log {js|big money|js} else Js.log {js|affordable|js}) [@res.braces ][@res.ternary ]) let () = ((let a = 1 in - let b = 2 in (module Teenager).(0); ((module Teenager) |. age) |. Js.log) + let b = 2 in (module Teenager).(0); ((module Teenager) -> age) -> Js.log) [@res.braces ]) let () = ((let a = 1 in let b = 2 in - ((module Teenager) |. age) |. Js.log; - ((if (((module Teenager).(0)) |. age) |. isAdult + ((module Teenager) -> age) -> Js.log; + ((if (((module Teenager).(0)) -> age) -> isAdult then Js.log {js|has responsibilities|js} else Js.log {js|can play in the playground|js}) [@res.ternary ])) diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/infix.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/infix.res.txt index 0d8bbd28c9..0ceef89259 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/infix.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/infix.res.txt @@ -1,4 +1,4 @@ -;;a |. (f b) +;;a -> (f b) ;;{js|string1|js} ^ {js|string2|js} ;;a <> b ;;a != b diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/jsx.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/jsx.res.txt index c101082eb7..d1a826b477 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/jsx.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/jsx.res.txt @@ -524,7 +524,7 @@ let _ = ()) [@JSX ]) let _ = - ((X.createElement ~y:((z |. (Belt.Option.getWithDefault {js||js})) + ((X.createElement ~y:((z -> (Belt.Option.getWithDefault {js||js})) [@res.namedArgLoc ][@res.braces ]) ~children:[] ()) [@JSX ]) let _ = @@ -533,10 +533,10 @@ let _ = [@JSX ]) let _ = ((div - ~children:[(((let left = limit |. Int.toString in + ~children:[(((let left = limit -> Int.toString in (((((({js||js})[@res.template ]) ^ left)[@res.template ]) ^ (({js| characters left|js})[@res.template ])) - [@res.template ]) |. React.string)) + [@res.template ]) -> React.string)) [@res.braces ])] ()) [@JSX ]) let _ = @@ -586,13 +586,13 @@ let _ = ;;((div ~children:((span ~children:[] ())[@JSX ]) ())[@JSX ]) ;;((div ~children:[|a|] ())[@JSX ]) ;;((div ~children:(1, 2) ())[@JSX ]) -;;((div ~children:((array |. f)[@res.braces ]) ())[@JSX ]) +;;((div ~children:((array -> f)[@res.braces ]) ())[@JSX ]) ;;(([element])[@JSX ]) ;;(([(((fun [arity:1]a -> 1))[@res.braces ])])[@JSX ]) ;;(([((span ~children:[] ())[@JSX ])])[@JSX ]) ;;(([[|a|]])[@JSX ]) ;;(([(1, 2)])[@JSX ]) -;;(([((array |. f)[@res.braces ])])[@JSX ]) +;;(([((array -> f)[@res.braces ])])[@JSX ]) let _ = ((A.createElement ~x:(({js|y|js})[@res.namedArgLoc ]) ~_spreadProps:((str) [@res.namedArgLoc ]) ~children:[] ()) diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/tupleVsDivision.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/tupleVsDivision.res.txt index e8b3e51a69..e82b11e672 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/tupleVsDivision.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/tupleVsDivision.res.txt @@ -1,5 +1,5 @@ ;;(foo ()) / 1 ;;foo () -;;(1, 2) |. printTuple -let f [arity:1]() = (((foo ()) / 1; foo (); (1, 2) |. printTuple) +;;(1, 2) -> printTuple +let f [arity:1]() = (((foo ()) / 1; foo (); (1, 2) -> printTuple) [@res.braces ]) \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/underscoreApply.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/underscoreApply.res.txt index cce859e65a..9a48ac55c2 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/underscoreApply.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/underscoreApply.res.txt @@ -1,8 +1,8 @@ let l = - ([1; 2; 3] |. (fun [arity:1]__x -> List.map (fun [arity:1]i -> i + 1) __x)) - |. (fun [arity:1]__x -> List.filter (fun [arity:1]i -> i > 0) __x) + ([1; 2; 3] -> (fun [arity:1]__x -> List.map (fun [arity:1]i -> i + 1) __x)) + -> (fun [arity:1]__x -> List.filter (fun [arity:1]i -> i > 0) __x) let l = - (fun [arity:1]i -> i + 1) |. (fun [arity:1]__x -> List.map __x [1; 2; 3]) + (fun [arity:1]i -> i + 1) -> (fun [arity:1]__x -> List.map __x [1; 2; 3]) let x [arity:1]__x = List.length __x let nested [arity:1]x [arity:1]__x = List.length __x let incr [arity:1]~v:((v)[@res.namedArgLoc ]) = v + 1 diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/while.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/while.res.txt index bb1652c1e1..a3da177b72 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/while.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/while.res.txt @@ -1,3 +1,3 @@ ;;while not eofReached do - let a = 1 in let b = 2 in Lexbuf.next (); (a + b) |. Js.log done + let a = 1 in let b = 2 in Lexbuf.next (); (a + b) -> Js.log done ;;while (not (isLineEnding buf)) && true do foo (); next () done \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/infiniteLoops/expected/equalAfterBinaryExpr.res.txt b/tests/syntax_tests/data/parsing/infiniteLoops/expected/equalAfterBinaryExpr.res.txt index 36557a596d..bc85040917 100644 --- a/tests/syntax_tests/data/parsing/infiniteLoops/expected/equalAfterBinaryExpr.res.txt +++ b/tests/syntax_tests/data/parsing/infiniteLoops/expected/equalAfterBinaryExpr.res.txt @@ -11,43 +11,43 @@ Did you mean `==` here? let rec _addLoop [arity:2]rbt currentNode = - ((if (Some currentNode) == (rbt |. root) + ((if (Some currentNode) == (rbt -> root) then currentNode.color <- Black else - if (currentNode.parent |. castNotOption).color == Black + if (currentNode.parent -> castNotOption).color == Black then () else if (((let uncle = uncleOf currentNode in - (uncle != None) && ((uncle |. castNotOption).color == Red))) + (uncle != None) && ((uncle -> castNotOption).color == Red))) [@res.braces ]) then - ((currentNode.parent |. castNotOption).color <- Black; - ((uncleOf currentNode) |. castNotOption).color <- Black; - ((grandParentOf currentNode) |. castNotOption).color <- Red; - _addLoop rbt ((grandParentOf currentNode) |. castNotOption)) + ((currentNode.parent -> castNotOption).color <- Black; + ((uncleOf currentNode) -> castNotOption).color <- Black; + ((grandParentOf currentNode) -> castNotOption).color <- Red; + _addLoop rbt ((grandParentOf currentNode) -> castNotOption)) else (let currentNode = if (not (isLeft currentNode)) && - (isLeft (currentNode.parent |. castNotOption)) + (isLeft (currentNode.parent -> castNotOption)) then - (rotateLeft rbt (currentNode.parent |. castNotOption); - currentNode.left |. castNotOption) + (rotateLeft rbt (currentNode.parent -> castNotOption); + currentNode.left -> castNotOption) else if (isLeft currentNode) && - (not (isLeft (currentNode.parent |. castNotOption))) + (not (isLeft (currentNode.parent -> castNotOption))) then - (rotateRight rbt (currentNode.parent |. castNotOption); - currentNode.right |. castNotOption) + (rotateRight rbt (currentNode.parent -> castNotOption); + currentNode.right -> castNotOption) else currentNode in - (currentNode.parent |. castNotOption).color <- Black; - ((grandParentOf currentNode) |. castNotOption).color <- Red; + (currentNode.parent -> castNotOption).color <- Black; + ((grandParentOf currentNode) -> castNotOption).color <- Red; if isLeft currentNode then - rotateRight rbt ((grandParentOf currentNode) |. castNotOption) - else rotateLeft rbt ((grandParentOf currentNode) |. castNotOption))) + rotateRight rbt ((grandParentOf currentNode) -> castNotOption) + else rotateLeft rbt ((grandParentOf currentNode) -> castNotOption))) [@res.braces ]) let removeNode [arity:2]rbt node = ((if nodeToRemove.color == Black @@ -55,7 +55,7 @@ let removeNode [arity:2]rbt node = (if successor.color == Red then (successor.color <- Black; - if successor.parent == None then rbt |. (rootSet (Some successor))) + if successor.parent == None then rbt -> (rootSet (Some successor))) else (let break = ref false in let successorRef = ref successor in @@ -63,30 +63,30 @@ let removeNode [arity:2]rbt node = let successor = successorRef.contents in match successor.parent with | None -> - (rbt |. (rootSet (Some successor)); break.contents <- true) + (rbt -> (rootSet (Some successor)); break.contents <- true) | Some successorParent -> let sibling = siblingOf successor in (if (sibling != None) && - ((sibling |. castNotOption).color == Red) + ((sibling -> castNotOption).color == Red) then (successorParent.color <- Red; - (sibling |. castNotOption).color <- Black; + (sibling -> castNotOption).color <- Black; if isLeft successor then rotateLeft rbt successorParent else rotateRight rbt successorParent); (let sibling = siblingOf successor in - let siblingNN = sibling |. castNotOption in + let siblingNN = sibling -> castNotOption in if (successorParent.color == Black) && ((sibling == None) || (((siblingNN.color == Black) && ((siblingNN.left == None) || - ((siblingNN.left |. castNotOption).color == + ((siblingNN.left -> castNotOption).color == Black))) && ((siblingNN.right == None) || - ((siblingNN.right |. castNotOption).color == + ((siblingNN.right -> castNotOption).color == Black)))) then (if sibling != None then siblingNN.color <- Red; @@ -97,11 +97,11 @@ let removeNode [arity:2]rbt node = ((sibling == None) || (((siblingNN.color == Black) && ((siblingNN.left == None) || - ((siblingNN.left |. castNotOption).color == + ((siblingNN.left -> castNotOption).color == Black))) && ((siblingNN.right == None) || - ((siblingNN.right |. castNotOption).color == + ((siblingNN.right -> castNotOption).color == Black)))) then (if sibling != None then siblingNN.color <- Red; @@ -110,47 +110,47 @@ let removeNode [arity:2]rbt node = else if (sibling != None) && - ((sibling |. castNotOption).color == Black) + ((sibling -> castNotOption).color == Black) then - (let sibling = sibling |. castNotOption in + (let sibling = sibling -> castNotOption in if (((isLeft successor) && ((sibling.right == None) || - ((sibling.right |. castNotOption).color == + ((sibling.right -> castNotOption).color == Black))) && (sibling.left != None)) && - ((sibling.left |. castNotOption).color == Red) + ((sibling.left -> castNotOption).color == Red) then (sibling.color <- Red; - (sibling.left |. castNotOption).color <- Black; + (sibling.left -> castNotOption).color <- Black; rotateRight rbt sibling) else if (((not (isLeft successor)) && ((sibling.left == None) || - ((sibling.left |. castNotOption).color == + ((sibling.left -> castNotOption).color == Black))) && (sibling.right != None)) && - ((sibling.right |. castNotOption).color == Red) + ((sibling.right -> castNotOption).color == Red) then (sibling.color <- Red; - (sibling.right |. castNotOption).color <- Black; + (sibling.right -> castNotOption).color <- Black; rotateLeft rbt sibling); break.contents <- true) else (let sibling = siblingOf successor in - let sibling = sibling |. castNotOption in + let sibling = sibling -> castNotOption in sibling.color <- (successorParent.color); if isLeft successor then - ((sibling.right |. castNotOption).color <- Black; + ((sibling.right -> castNotOption).color <- Black; rotateRight rbt successorParent) else - ((sibling.left |. castNotOption).color <- Black; + ((sibling.left -> castNotOption).color <- Black; rotateLeft rbt successorParent)))) done)); if isLeaf successor - then (if (rbt |. root) == (Some successor) then (rbt |. root) = None)) + then (if (rbt -> root) == (Some successor) then (rbt -> root) = None)) [@res.braces ]) \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/recovery/expression/expected/infinite.res.txt b/tests/syntax_tests/data/parsing/recovery/expression/expected/infinite.res.txt index f036ffb7a1..45277dd114 100644 --- a/tests/syntax_tests/data/parsing/recovery/expression/expected/infinite.res.txt +++ b/tests/syntax_tests/data/parsing/recovery/expression/expected/infinite.res.txt @@ -1 +1 @@ -let smallest = (heap.compare ()) < (a |. (f b)) \ No newline at end of file +let smallest = (heap.compare ()) < (a -> (f b)) \ No newline at end of file From 694b4c11f8f48048f47ec49e66361d2f7102ef0a Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Sat, 11 Jan 2025 17:32:15 +0100 Subject: [PATCH 3/5] Add ppx test for "->" representation. --- tests/tools_tests/ppx/TestPpx.res | 5 +++++ tests/tools_tests/src/expected/TestPpx.res.jsout | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/tests/tools_tests/ppx/TestPpx.res b/tests/tools_tests/ppx/TestPpx.res index 5e01438c9f..33d32f38d1 100644 --- a/tests/tools_tests/ppx/TestPpx.res +++ b/tests/tools_tests/ppx/TestPpx.res @@ -45,3 +45,8 @@ let async_foo = async (x, y) => { let add = (x, y) => x + y let partial_add = add(3, ...) + +module Pipe = { + let plus = (x, y) => x + y + let z = 1->plus(2) +} diff --git a/tests/tools_tests/src/expected/TestPpx.res.jsout b/tests/tools_tests/src/expected/TestPpx.res.jsout index 9249f7fc53..bd20990442 100644 --- a/tests/tools_tests/src/expected/TestPpx.res.jsout +++ b/tests/tools_tests/src/expected/TestPpx.res.jsout @@ -59,6 +59,17 @@ function partial_add(extra) { return 3 + extra | 0; } +function plus(x, y) { + return x + y | 0; +} + +let z = 3; + +let Pipe = { + plus: plus, + z: z +}; + let a = "A"; let b = "B"; @@ -77,4 +88,5 @@ exports.async_succ = async_succ; exports.async_foo = async_foo; exports.add = add; exports.partial_add = partial_add; +exports.Pipe = Pipe; /* Not a pure module */ From ea96a313ed322a37f00b6dcfdda9a9464bfba275 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Sat, 11 Jan 2025 17:33:19 +0100 Subject: [PATCH 4/5] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e5d7b64517..ba8844623c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ - AST cleanup: Remove `expression_desc.Pexp_new`, `expression_desc.Pexp_setinstvar`, `expression_desc.Pexp_override`, `expression_desc.Pexp_poly`, `exp_extra.Texp_poly`, `expression_desc.Texp_new`, `expression_desc.Texp_setinstvar`, `expression_desc.Texp_override` & `expression_desc.Texp_instvar` from AST as it is unused. https://github.com/rescript-lang/rescript/pull/7239 - AST cleanup: Remove `@res.partial` attribute from the internal representation, and add a flag to untyped and typed ASTs instead. https://github.com/rescript-lang/rescript/pull/7238 https://github.com/rescript-lang/rescript/pull/7240 - AST cleanup: Remove `structure_item_desc.Pstr_class`, `signature_item_desc.Psig_class`, `structure_item_desc.Pstr_class_type`, `signature_item_desc.Psig_class_type`, `structure_item_desc.Tstr_class`, `structure_item_desc.Tstr_class_type`, `signature_item_desc.Tsig_class`, `signature_item_desc.Tsig_class_type` from AST as it is unused. https://github.com/rescript-lang/rescript/pull/7242 +- AST cleanup: remove "|." and rename "|." to "->" in the internal representation for the pipe operator. https://github.com/rescript-lang/rescript/pull/7244 # 12.0.0-alpha.7 From afa833b50a67cd578e14b19f55e4775d3824880d Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Tue, 14 Jan 2025 13:12:52 +0100 Subject: [PATCH 5/5] Map between `->` and `|.` in the ppx conversion. --- compiler/ml/ast_mapper_from0.ml | 7 +++++++ compiler/ml/ast_mapper_to0.ml | 12 ++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/compiler/ml/ast_mapper_from0.ml b/compiler/ml/ast_mapper_from0.ml index fbb5194481..0a655877ff 100644 --- a/compiler/ml/ast_mapper_from0.ml +++ b/compiler/ml/ast_mapper_from0.ml @@ -311,6 +311,13 @@ module E = struct (sub.pat sub p) (sub.expr sub e) | Pexp_function _ -> assert false | Pexp_apply (e, l) -> + let e = + match (e.pexp_desc, l) with + | ( Pexp_ident ({txt = Longident.Lident "|."} as lid), + [(Nolabel, _); (Nolabel, _)] ) -> + {e with pexp_desc = Pexp_ident {lid with txt = Longident.Lident "->"}} + | _ -> e + in let process_partial_app_attribute attrs = let rec process partial_app acc attrs = match attrs with diff --git a/compiler/ml/ast_mapper_to0.ml b/compiler/ml/ast_mapper_to0.ml index 9cbd9f3303..1345a40fa9 100644 --- a/compiler/ml/ast_mapper_to0.ml +++ b/compiler/ml/ast_mapper_to0.ml @@ -321,12 +321,20 @@ module E = struct ~attrs:(arity_to_attributes arity) (Location.mkloc (Longident.Lident "Function$") e.pexp_loc) (Some e)) - | Pexp_apply {funct = e; args = l; partial} -> + | Pexp_apply {funct = e; args; partial} -> + let e = + match (e.pexp_desc, args) with + | ( Pexp_ident ({txt = Longident.Lident "->"} as lid), + [(Nolabel, _); (Nolabel, _)] ) -> + {e with pexp_desc = Pexp_ident {lid with txt = Longident.Lident "|."}} + | _ -> e + in let attrs = if partial then (Location.mknoloc "res.partial", Pt.PStr []) :: attrs else [] in - apply ~loc ~attrs (sub.expr sub e) (List.map (map_snd (sub.expr sub)) l) + apply ~loc ~attrs (sub.expr sub e) + (List.map (map_snd (sub.expr sub)) args) | Pexp_match (e, pel) -> match_ ~loc ~attrs (sub.expr sub e) (sub.cases sub pel) | Pexp_try (e, pel) -> try_ ~loc ~attrs (sub.expr sub e) (sub.cases sub pel)