Skip to content

Commit 2dc9037

Browse files
committed
Rename binary operator "|." to "->" in the internal representation.
1 parent f1e2638 commit 2dc9037

32 files changed

+120
-123
lines changed

analysis/examples/larger-project/src/res_comments_table.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1256,7 +1256,7 @@ and walkExpr = (expr, t, comments) => {
12561256
| "/"
12571257
| "/."
12581258
| "**"
1259-
| "|."
1259+
| "->"
12601260
| "<>",
12611261
),
12621262
}),

analysis/examples/larger-project/src/res_parsetree_viewer.res

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ let operatorPrecedence = operator =>
270270
| "+" | "+." | "-" | "-." | "^" => 5
271271
| "*" | "*." | "/" | "/." => 6
272272
| "**" => 7
273-
| "#" | "##" | "|." => 8
273+
| "#" | "##" | "->" => 8
274274
| _ => 0
275275
}
276276

@@ -312,7 +312,7 @@ let isBinaryOperator = operator =>
312312
| "/"
313313
| "/."
314314
| "**"
315-
| "|."
315+
| "->"
316316
| "<>" => true
317317
| _ => false
318318
}
@@ -649,15 +649,15 @@ let isSinglePipeExpr = expr => {
649649
let isPipeExpr = expr =>
650650
switch expr.pexp_desc {
651651
| Pexp_apply(
652-
{pexp_desc: Pexp_ident({txt: Longident.Lident("|." | "|>")})},
652+
{pexp_desc: Pexp_ident({txt: Longident.Lident("->" | "|>")})},
653653
list{(Nolabel, _operand1), (Nolabel, _operand2)},
654654
) => true
655655
| _ => false
656656
}
657657

658658
switch expr.pexp_desc {
659659
| Pexp_apply(
660-
{pexp_desc: Pexp_ident({txt: Longident.Lident("|." | "|>")})},
660+
{pexp_desc: Pexp_ident({txt: Longident.Lident("->" | "|>")})},
661661
list{(Nolabel, operand1), (Nolabel, _operand2)},
662662
) if !isPipeExpr(operand1) => true
663663
| _ => false

analysis/examples/larger-project/src/res_printer.res

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3495,7 +3495,6 @@ and printUnaryExpression = (expr, cmtTbl) => {
34953495
and printBinaryExpression = (expr: Parsetree.expression, cmtTbl) => {
34963496
let printBinaryOperator = (~inlineRhs, operator) => {
34973497
let operatorTxt = switch operator {
3498-
| "|." => "->"
34993498
| "^" => "++"
35003499
| "=" => "=="
35013500
| "==" => "==="

analysis/src/CompletionFrontEnd.ml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ let rec exprToContextPathInner (e : Parsetree.expression) =
218218
(match exprs with
219219
| [] -> None
220220
| exp :: _ -> exprToContextPath exp))
221-
| Pexp_ident {txt = Lident "|."} -> None
221+
| Pexp_ident {txt = Lident "->"} -> None
222222
| Pexp_ident {txt; loc} ->
223223
Some
224224
(CPId {path = Utils.flattenLongIdent txt; completionContext = Value; loc})
@@ -258,7 +258,7 @@ let rec exprToContextPathInner (e : Parsetree.expression) =
258258
{
259259
funct =
260260
{
261-
pexp_desc = Pexp_ident {txt = Lident "|."};
261+
pexp_desc = Pexp_ident {txt = Lident "->"};
262262
pexp_loc;
263263
pexp_attributes;
264264
};
@@ -275,7 +275,7 @@ let rec exprToContextPathInner (e : Parsetree.expression) =
275275
}
276276
| Pexp_apply
277277
{
278-
funct = {pexp_desc = Pexp_ident {txt = Lident "|."}};
278+
funct = {pexp_desc = Pexp_ident {txt = Lident "->"}};
279279
args =
280280
[
281281
(_, lhs); (_, {pexp_desc = Pexp_ident id; pexp_loc; pexp_attributes});
@@ -328,15 +328,15 @@ let completePipeChain (exp : Parsetree.expression) =
328328
Example: someArray->Js.Array2.map(v => v + 2)-> *)
329329
| Pexp_apply
330330
{
331-
funct = {pexp_desc = Pexp_ident {txt = Lident "|."}};
331+
funct = {pexp_desc = Pexp_ident {txt = Lident "->"}};
332332
args = [_; (_, {pexp_desc = Pexp_apply {funct = d}})];
333333
} ->
334334
exprToContextPath exp |> Option.map (fun ctxPath -> (ctxPath, d.pexp_loc))
335335
(* When the left side of the pipe we're completing is an identifier application.
336336
Example: someArray->filterAllTheGoodStuff-> *)
337337
| Pexp_apply
338338
{
339-
funct = {pexp_desc = Pexp_ident {txt = Lident "|."}};
339+
funct = {pexp_desc = Pexp_ident {txt = Lident "->"}};
340340
args = [_; (_, {pexp_desc = Pexp_ident _; pexp_loc})];
341341
} ->
342342
exprToContextPath exp |> Option.map (fun ctxPath -> (ctxPath, pexp_loc))
@@ -1113,7 +1113,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
11131113
resetCurrentCtxPath oldCtxPath
11141114
| Pexp_apply
11151115
{
1116-
funct = {pexp_desc = Pexp_ident {txt = Lident "|."; loc = opLoc}};
1116+
funct = {pexp_desc = Pexp_ident {txt = Lident "->"; loc = opLoc}};
11171117
args =
11181118
[
11191119
(_, lhs);
@@ -1291,7 +1291,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
12911291
else iterateJsxProps ~iterator jsxProps
12921292
| Pexp_apply
12931293
{
1294-
funct = {pexp_desc = Pexp_ident {txt = Lident "|."}};
1294+
funct = {pexp_desc = Pexp_ident {txt = Lident "->"}};
12951295
args =
12961296
[
12971297
(_, lhs);
@@ -1303,15 +1303,15 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
13031303
setPipeResult ~lhs ~id |> ignore
13041304
| Pexp_apply
13051305
{
1306-
funct = {pexp_desc = Pexp_ident {txt = Lident "|."; loc = opLoc}};
1306+
funct = {pexp_desc = Pexp_ident {txt = Lident "->"; loc = opLoc}};
13071307
args = [(_, lhs); _];
13081308
}
13091309
when Loc.end_ opLoc = posCursor ->
13101310
if Debug.verbose () then print_endline "[expr_iter] Case foo->";
13111311
setPipeResult ~lhs ~id:"" |> ignore
13121312
| Pexp_apply
13131313
{
1314-
funct = {pexp_desc = Pexp_ident {txt = Lident "|."}};
1314+
funct = {pexp_desc = Pexp_ident {txt = Lident "->"}};
13151315
args = [_; (_, {pexp_desc = Pexp_apply {funct = funExpr; args}})];
13161316
}
13171317
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
13471347
| Some argCompletable -> setResult argCompletable)
13481348
| Pexp_apply
13491349
{
1350-
funct = {pexp_desc = Pexp_ident {txt = Lident "|."}};
1350+
funct = {pexp_desc = Pexp_ident {txt = Lident "->"}};
13511351
args = [_; _];
13521352
} ->
13531353
(* Ignore any other pipe. *)

analysis/src/SignatureHelp.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ let signatureHelp ~path ~pos ~currentFile ~debug ~allowForConstructorPayloads =
365365
pexp_desc =
366366
Pexp_apply
367367
{
368-
funct = {pexp_desc = Pexp_ident {txt = Lident "|."}};
368+
funct = {pexp_desc = Pexp_ident {txt = Lident "->"}};
369369
args =
370370
[
371371
_;

compiler/frontend/ast_exp_apply.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ let view_as_app (fn : exp) (s : string list) : app_pattern option =
6969
Some {op; loc = fn.pexp_loc; args = check_and_discard args}
7070
| _ -> None
7171

72-
let infix_ops = ["|."; "#="; "##"]
72+
let infix_ops = ["->"; "#="; "##"]
7373

7474
let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) : exp =
7575
match view_as_app e infix_ops with
76-
| Some {op = "|."; args = [a_; f_]; loc} -> (
76+
| Some {op = "->"; args = [a_; f_]; loc} -> (
7777
(*
7878
a |. f
7979
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 =
193193
} ->
194194
gen_assignment obj name name_loc
195195
| _ -> Location.raise_errorf ~loc "invalid #= assignment"))
196-
| Some {op = "|."; loc} ->
196+
| Some {op = "->"; loc} ->
197197
Location.raise_errorf ~loc
198198
"invalid |. syntax, it can only be used as binary operator"
199199
| Some {op = "##"; loc} ->

compiler/ml/env.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1624,7 +1624,7 @@ and check_value_name name loc =
16241624
(* Note: we could also check here general validity of the
16251625
identifier, to protect against bad identifiers forged by -pp or
16261626
-ppx preprocessors. *)
1627-
if name = "|." then raise (Error (Illegal_value_name (loc, name)))
1627+
if name = "->" then raise (Error (Illegal_value_name (loc, name)))
16281628
else if String.length name > 0 && name.[0] = '#' then
16291629
for i = 1 to String.length name - 1 do
16301630
if name.[i] = '#' then raise (Error (Illegal_value_name (loc, name)))

compiler/syntax/src/res_comments_table.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1342,7 +1342,7 @@ and walk_expression expr t comments =
13421342
Longident.Lident
13431343
( ":=" | "||" | "&&" | "=" | "==" | "<" | ">" | "!="
13441344
| "!==" | "<=" | ">=" | "|>" | "+" | "+." | "-" | "-."
1345-
| "++" | "^" | "*" | "*." | "/" | "/." | "**" | "|."
1345+
| "++" | "^" | "*" | "*." | "/" | "/." | "**" | "->"
13461346
| "<>" );
13471347
};
13481348
};

compiler/syntax/src/res_core.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,8 +391,7 @@ let build_longident words =
391391

392392
let make_infix_operator (p : Parser.t) token start_pos end_pos =
393393
let stringified_token =
394-
if token = Token.MinusGreater then "|."
395-
else if token = Token.PlusPlus then "^"
394+
if token = Token.PlusPlus then "^"
396395
else if token = Token.BangEqual then "<>"
397396
else if token = Token.BangEqualEqual then "!="
398397
else if token = Token.Equal then (

compiler/syntax/src/res_parens.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ let flatten_operand_rhs parent_operator rhs =
192192

193193
let binary_operator_inside_await_needs_parens operator =
194194
ParsetreeViewer.operator_precedence operator
195-
< ParsetreeViewer.operator_precedence "|."
195+
< ParsetreeViewer.operator_precedence "->"
196196

197197
let lazy_or_assert_or_await_expr_rhs ?(in_await = false) expr =
198198
let opt_braces, _ = ParsetreeViewer.process_braces_attr expr in

compiler/syntax/src/res_parsetree_viewer.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ let operator_precedence operator =
274274
| "+" | "+." | "-" | "-." | "^" -> 5
275275
| "*" | "*." | "/" | "/." | "%" -> 6
276276
| "**" -> 7
277-
| "#" | "##" | "|." -> 8
277+
| "#" | "##" | "->" -> 8
278278
| _ -> 0
279279

280280
let is_unary_operator operator =
@@ -297,7 +297,7 @@ let is_unary_expression expr =
297297
let is_binary_operator operator =
298298
match operator with
299299
| ":=" | "||" | "&&" | "=" | "==" | "<" | ">" | "!=" | "!==" | "<=" | ">="
300-
| "|>" | "+" | "+." | "-" | "-." | "^" | "*" | "*." | "/" | "/." | "**" | "|."
300+
| "|>" | "+" | "+." | "-" | "-." | "^" | "*" | "*." | "/" | "/." | "**" | "->"
301301
| "<>" | "%" ->
302302
true
303303
| _ -> false
@@ -714,7 +714,7 @@ let is_single_pipe_expr expr =
714714
match expr.pexp_desc with
715715
| Pexp_apply
716716
{
717-
funct = {pexp_desc = Pexp_ident {txt = Longident.Lident ("|." | "|>")}};
717+
funct = {pexp_desc = Pexp_ident {txt = Longident.Lident ("->" | "|>")}};
718718
args = [(Nolabel, _operand1); (Nolabel, _operand2)];
719719
} ->
720720
true
@@ -723,7 +723,7 @@ let is_single_pipe_expr expr =
723723
match expr.pexp_desc with
724724
| Pexp_apply
725725
{
726-
funct = {pexp_desc = Pexp_ident {txt = Longident.Lident ("|." | "|>")}};
726+
funct = {pexp_desc = Pexp_ident {txt = Longident.Lident ("->" | "|>")}};
727727
args = [(Nolabel, operand1); (Nolabel, _operand2)];
728728
}
729729
when not (is_pipe_expr operand1) ->

compiler/syntax/src/res_printer.ml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3666,7 +3666,6 @@ and print_binary_expression ~state (expr : Parsetree.expression) cmt_tbl =
36663666
let print_binary_operator ~inline_rhs operator =
36673667
let operator_txt =
36683668
match operator with
3669-
| "|." -> "->"
36703669
| "^" -> "++"
36713670
| "=" -> "=="
36723671
| "==" -> "==="
@@ -3675,12 +3674,12 @@ and print_binary_expression ~state (expr : Parsetree.expression) cmt_tbl =
36753674
| txt -> txt
36763675
in
36773676
let spacing_before_operator =
3678-
if operator = "|." then Doc.soft_line
3677+
if operator = "->" then Doc.soft_line
36793678
else if operator = "|>" then Doc.line
36803679
else Doc.space
36813680
in
36823681
let spacing_after_operator =
3683-
if operator = "|." then Doc.nil
3682+
if operator = "->" then Doc.nil
36843683
else if operator = "|>" then Doc.space
36853684
else if inline_rhs then Doc.space
36863685
else Doc.line
@@ -3751,7 +3750,7 @@ and print_binary_expression ~state (expr : Parsetree.expression) cmt_tbl =
37513750
]
37523751
else
37533752
match operator with
3754-
| "|." when is_multiline ->
3753+
| "->" when is_multiline ->
37553754
(* If the pipe-chain is written over multiple lines, break automatically
37563755
* `let x = a->b->c -> same line, break when line-width exceeded
37573756
* `let x = a->
@@ -3857,7 +3856,7 @@ and print_binary_expression ~state (expr : Parsetree.expression) cmt_tbl =
38573856
{
38583857
funct =
38593858
{
3860-
pexp_desc = Pexp_ident {txt = Longident.Lident (("|." | "|>") as op)};
3859+
pexp_desc = Pexp_ident {txt = Longident.Lident (("->" | "|>") as op)};
38613860
};
38623861
args = [(Nolabel, lhs); (Nolabel, rhs)];
38633862
}
@@ -3875,8 +3874,8 @@ and print_binary_expression ~state (expr : Parsetree.expression) cmt_tbl =
38753874
print_attributes ~state expr.pexp_attributes cmt_tbl;
38763875
lhs_doc;
38773876
(match (lhs_has_comment_below, op) with
3878-
| true, "|." -> Doc.concat [Doc.soft_line; Doc.text "->"]
3879-
| false, "|." -> Doc.text "->"
3877+
| true, "->" -> Doc.concat [Doc.soft_line; Doc.text "->"]
3878+
| false, "->" -> Doc.text "->"
38803879
| true, "|>" -> Doc.concat [Doc.line; Doc.text "|> "]
38813880
| false, "|>" -> Doc.text " |> "
38823881
| _ -> Doc.nil);

tests/syntax_tests/data/parsing/errors/expressions/expected/block.res.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,14 @@ let findThreadByIdLinearScan [arity:2]~threads:((threads)[@res.namedArgLoc ])
7474
otherPersonIDWhichIsAlsoThreadID
7575
| Group { id } -> id
7676
| Unknown { id } ->
77-
(unknown.id |. Js.String.make) |. FBID.ofStringUnsafe in
77+
(unknown.id -> Js.String.make) -> FBID.ofStringUnsafe in
7878
thisId == id)
7979
[@res.braces ])))
8080
[@res.braces ])
81-
let x = ((loop 0 (Nil |. (push doc)))[@res.braces ])
81+
let x = ((loop 0 (Nil -> (push doc)))[@res.braces ])
8282
;;match stack with
8383
| Empty -> [%rescript.exprhole ]
8484
| Cons (doc, rest) -> ()
85-
| Join (doc1, doc2) -> (buffer |. (Buffer.add_string indentation); loop ())
85+
| Join (doc1, doc2) -> (buffer -> (Buffer.add_string indentation); loop ())
8686
let pipeline =
8787
match scheduler with | Some -> [%rescript.exprhole ] | None -> ()

tests/syntax_tests/data/parsing/errors/structure/expected/gh16B.res.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313

1414
open Ws
1515
let wss = Server.make { port = 82 }
16-
let address = wss |. Server.address
16+
let address = wss -> Server.address
1717
let log [arity:1]msg =
1818
Js.log
1919
(((((({js|> Server: |js})[@res.template ]) ^ msg)[@res.template ]) ^
2020
(({js||js})[@res.template ]))[@res.template ])
2121
;;log
2222
(((((((((((((({js|Running on: |js})[@res.template ]) ^ address.address)
2323
[@res.template ]) ^ (({js|:|js})[@res.template ]))
24-
[@res.template ]) ^ (address.port |. string_of_int))
24+
[@res.template ]) ^ (address.port -> string_of_int))
2525
[@res.template ]) ^ (({js| (|js})[@res.template ]))
2626
[@res.template ]) ^ address.family)
2727
[@res.template ]) ^ (({js|)|js})[@res.template ]))[@res.template ])
@@ -31,8 +31,8 @@ module ClientSet =
3131
(Belt.Id.MakeComparable)(struct
3232
type nonrec t = Client.t
3333
let cmp [arity:2]a b =
34-
((compare (a |. Client.getUniqueId)
35-
(b |. Client.getUniqueId))
34+
((compare (a -> Client.getUniqueId)
35+
(b -> Client.getUniqueId))
3636
[@res.braces ])
3737
end)
3838
let empty = Belt.Set.make ~id:(((module T))[@res.namedArgLoc ])

tests/syntax_tests/data/parsing/errors/structure/expected/letBinding.res.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@
100100
let rightResource =
101101
(ur.resources).find
102102
(fun [arity:1]r -> r.account_id == ((connection.left).account).id)
103-
let x = ((let field = p |. parseFieldDeclaration in field)[@res.braces ])
104-
let t = ((let (_, _, token) = scanner |. scan in token)[@res.braces ])
103+
let x = ((let field = p -> parseFieldDeclaration in field)[@res.braces ])
104+
let t = ((let (_, _, token) = scanner -> scan in token)[@res.braces ])
105105
let (keyTable : int Belt.Map.String.t) = [%rescript.exprhole ]
106106
let foo = [%rescript.exprhole ]
107107
let (x : int) = string = y

tests/syntax_tests/data/parsing/grammar/expressions/expected/UncurriedAlways.res.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ let foo [arity:2]x y = x + y
33
let z = foo 3 4
44
let bar [arity:2]x y = x + y
55
let b = bar 3 4
6-
let w = 3 |. (foo 4)
7-
let a = 3 |. (foo 4)
6+
let w = 3 -> (foo 4)
7+
let a = 3 -> (foo 4)

tests/syntax_tests/data/parsing/grammar/expressions/expected/UncurriedByDefault.res.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ type nonrec uu2 = unit -> unit -> unit (a:2)
9191
type nonrec up2 = unit -> unit -> unit (a:2)
9292
type nonrec cnested = (string -> unit (a:1)) -> unit (a:1)
9393
type nonrec unested = (string -> unit (a:1)) -> unit (a:1)
94-
let pipe1 = 3 |. f
94+
let pipe1 = 3 -> f
9595
let (uannpoly : 'a -> string (a:1)) = xx
9696
let (uannint : int -> string (a:1)) = xx
9797
let _ = ((fun [arity:1]x -> 34)[@att ])

tests/syntax_tests/data/parsing/grammar/expressions/expected/arrow.res.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ let f [arity:2](a, b) (c, d) = ((a + b) + c) + d
1818
let f [arity:1]exception Terminate = ()
1919
let f [arity:2]exception Terminate exception Exit = ()
2020
let f [arity:1][] = ()
21-
let f [arity:1](x::xs) = x + (xs |. Belt.List.length)
21+
let f [arity:1](x::xs) = x + (xs -> Belt.List.length)
2222
let f [arity:2](x : int) (y : int) = x + y
2323
let f [arity:2]~a:((a)[@res.namedArgLoc ]) ~b:((b)[@res.namedArgLoc ]) =
2424
a + b

0 commit comments

Comments
 (0)