Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup pipe: remove |.u and change "|." to "->" to represent pipe. #7244

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
- AST cleanup: Remove `@res.async` attribute from the internal representation, and add a flag to untyped and typed ASTs instead. https://github.com/rescript-lang/rescript/pull/7234
- 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 "|." and rename "|." to "->" in the internal representation for the pipe operator. https://github.com/rescript-lang/rescript/pull/7244

# 12.0.0-alpha.7

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1256,7 +1256,7 @@ and walkExpr = (expr, t, comments) => {
| "/"
| "/."
| "**"
| "|."
| "->"
| "<>",
),
}),
Expand Down
8 changes: 4 additions & 4 deletions analysis/examples/larger-project/src/res_parsetree_viewer.res
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ let operatorPrecedence = operator =>
| "+" | "+." | "-" | "-." | "^" => 5
| "*" | "*." | "/" | "/." => 6
| "**" => 7
| "#" | "##" | "|." => 8
| "#" | "##" | "->" => 8
| _ => 0
}

Expand Down Expand Up @@ -312,7 +312,7 @@ let isBinaryOperator = operator =>
| "/"
| "/."
| "**"
| "|."
| "->"
| "<>" => true
| _ => false
}
Expand Down Expand Up @@ -649,15 +649,15 @@ 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
}

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
Expand Down
1 change: 0 additions & 1 deletion analysis/examples/larger-project/src/res_printer.res
Original file line number Diff line number Diff line change
Expand Up @@ -3495,7 +3495,6 @@ and printUnaryExpression = (expr, cmtTbl) => {
and printBinaryExpression = (expr: Parsetree.expression, cmtTbl) => {
let printBinaryOperator = (~inlineRhs, operator) => {
let operatorTxt = switch operator {
| "|." => "->"
| "^" => "++"
| "=" => "=="
| "==" => "==="
Expand Down
25 changes: 10 additions & 15 deletions analysis/src/CompletionFrontEnd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down Expand Up @@ -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;
};
Expand All @@ -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});
Expand Down Expand Up @@ -328,15 +328,15 @@ 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))
(* When the left side of the pipe we're completing is an identifier application.
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))
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -1304,19 +1303,15 @@ 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 ->
if Debug.verbose () then print_endline "[expr_iter] Case foo->";
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.
Expand Down Expand Up @@ -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. *)
Expand Down
2 changes: 1 addition & 1 deletion analysis/src/SignatureHelp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
[
_;
Expand Down
6 changes: 3 additions & 3 deletions compiler/frontend/ast_exp_apply.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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} ->
Expand Down
2 changes: 1 addition & 1 deletion compiler/ml/env.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
4 changes: 2 additions & 2 deletions compiler/syntax/src/res_comments_table.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1342,8 +1342,8 @@ and walk_expression expr t comments =
Longident.Lident
( ":=" | "||" | "&&" | "=" | "==" | "<" | ">" | "!="
| "!==" | "<=" | ">=" | "|>" | "+" | "+." | "-" | "-."
| "++" | "^" | "*" | "*." | "/" | "/." | "**" | "|."
| "|.u" | "<>" );
| "++" | "^" | "*" | "*." | "/" | "/." | "**" | "->"
| "<>" );
};
};
args = [(Nolabel, operand1); (Nolabel, operand2)];
Expand Down
3 changes: 1 addition & 2 deletions compiler/syntax/src/res_core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 "|.u"
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 (
Expand Down
2 changes: 1 addition & 1 deletion compiler/syntax/src/res_parens.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 5 additions & 12 deletions compiler/syntax/src/res_parsetree_viewer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ let operator_precedence operator =
| "+" | "+." | "-" | "-." | "^" -> 5
| "*" | "*." | "/" | "/." | "%" -> 6
| "**" -> 7
| "#" | "##" | "|." | "|.u" -> 8
| "#" | "##" | "->" -> 8
| _ -> 0

let is_unary_operator operator =
Expand All @@ -297,8 +297,8 @@ let is_unary_expression expr =
let is_binary_operator operator =
match operator with
| ":=" | "||" | "&&" | "=" | "==" | "<" | ">" | "!=" | "!==" | "<=" | ">="
| "|>" | "+" | "+." | "-" | "-." | "^" | "*" | "*." | "/" | "/." | "**" | "|."
| "|.u" | "<>" | "%" ->
| "|>" | "+" | "+." | "-" | "-." | "^" | "*" | "*." | "/" | "/." | "**" | "->"
| "<>" | "%" ->
true
| _ -> false

Expand Down Expand Up @@ -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
Expand All @@ -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) ->
Expand Down
14 changes: 6 additions & 8 deletions compiler/syntax/src/res_printer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3666,7 +3666,6 @@ and print_binary_expression ~state (expr : Parsetree.expression) cmt_tbl =
let print_binary_operator ~inline_rhs operator =
let operator_txt =
match operator with
| "|." | "|.u" -> "->"
| "^" -> "++"
| "=" -> "=="
| "==" -> "==="
Expand All @@ -3675,12 +3674,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
Expand Down Expand Up @@ -3751,7 +3750,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->
Expand Down Expand Up @@ -3857,8 +3856,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)];
}
Expand All @@ -3876,8 +3874,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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 -> ()
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@

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 ]) ^
(({js||js})[@res.template ]))[@res.template ])
;;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 ])
Expand All @@ -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 ])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
let w = 3 -> (foo 4)
let a = 3 -> (foo 4)
Loading
Loading