Skip to content

Commit 7c1a037

Browse files
committed
AST: represent concatenation internally as "++" instead of "^".
1 parent 43389c9 commit 7c1a037

File tree

19 files changed

+86
-87
lines changed

19 files changed

+86
-87
lines changed

compiler/syntax/src/res_core.ml

Lines changed: 2 additions & 3 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.PlusPlus then "^"
395-
else if token = Token.BangEqual then "<>"
394+
if token = Token.BangEqual then "<>"
396395
else if token = Token.BangEqualEqual then "!="
397396
else if token = Token.Equal then (
398397
(* TODO: could have a totally different meaning like x->fooSet(y)*)
@@ -2327,7 +2326,7 @@ and parse_template_expr ?prefix p =
23272326
in
23282327

23292328
let hidden_operator =
2330-
let op = Location.mknoloc (Longident.Lident "^") in
2329+
let op = Location.mknoloc (Longident.Lident "++") in
23312330
Ast_helper.Exp.ident op
23322331
in
23332332
let concat (e1 : Parsetree.expression) (e2 : Parsetree.expression) =

compiler/syntax/src/res_parens.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ let rhs_binary_expr_operand parent_operator rhs =
162162
args = [(_, _left); (_, _right)];
163163
}
164164
when ParsetreeViewer.is_binary_operator operator
165-
&& not (operator_loc.loc_ghost && operator = "^") ->
165+
&& not (operator_loc.loc_ghost && operator = "++") ->
166166
let prec_parent = ParsetreeViewer.operator_precedence parent_operator in
167167
let prec_child = ParsetreeViewer.operator_precedence operator in
168168
prec_parent == prec_child
@@ -180,7 +180,7 @@ let flatten_operand_rhs parent_operator rhs =
180180
args = [(_, _left); (_, _right)];
181181
}
182182
when ParsetreeViewer.is_binary_operator operator
183-
&& not (operator_loc.loc_ghost && operator = "^") ->
183+
&& not (operator_loc.loc_ghost && operator = "++") ->
184184
let prec_parent = ParsetreeViewer.operator_precedence parent_operator in
185185
let prec_child = ParsetreeViewer.operator_precedence operator in
186186
prec_parent >= prec_child || rhs.pexp_attributes <> []

compiler/syntax/src/res_parsetree_viewer.ml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ let operator_precedence operator =
271271
| "||" -> 2
272272
| "&&" -> 3
273273
| "=" | "==" | "<" | ">" | "!=" | "<>" | "!==" | "<=" | ">=" | "|>" -> 4
274-
| "+" | "+." | "-" | "-." | "^" -> 5
274+
| "+" | "+." | "-" | "-." | "++" -> 5
275275
| "*" | "*." | "/" | "/." | "%" -> 6
276276
| "**" -> 7
277277
| "#" | "##" | "->" -> 8
@@ -297,8 +297,8 @@ let is_unary_expression expr =
297297
let is_binary_operator operator =
298298
match operator with
299299
| ":=" | "||" | "&&" | "=" | "==" | "<" | ">" | "!=" | "!==" | "<=" | ">="
300-
| "|>" | "+" | "+." | "-" | "-." | "^" | "*" | "*." | "/" | "/." | "**" | "->"
301-
| "<>" | "%" ->
300+
| "|>" | "+" | "+." | "-" | "-." | "++" | "*" | "*." | "/" | "/." | "**"
301+
| "->" | "<>" | "%" ->
302302
true
303303
| _ -> false
304304

@@ -314,7 +314,7 @@ let is_binary_expression expr =
314314
args = [(Nolabel, _operand1); (Nolabel, _operand2)];
315315
}
316316
when is_binary_operator operator
317-
&& not (operator_loc.loc_ghost && operator = "^")
317+
&& not (operator_loc.loc_ghost && operator = "++")
318318
(* template literal *) ->
319319
true
320320
| _ -> false
@@ -643,7 +643,7 @@ let is_template_literal expr =
643643
match expr.pexp_desc with
644644
| Pexp_apply
645645
{
646-
funct = {pexp_desc = Pexp_ident {txt = Longident.Lident "^"}};
646+
funct = {pexp_desc = Pexp_ident {txt = Longident.Lident "++"}};
647647
args = [(Nolabel, _); (Nolabel, _)];
648648
}
649649
when has_template_literal_attr expr.pexp_attributes ->

compiler/syntax/src/res_printer.ml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3557,7 +3557,7 @@ and print_template_literal ~state expr cmt_tbl =
35573557
match expr.pexp_desc with
35583558
| Pexp_apply
35593559
{
3560-
funct = {pexp_desc = Pexp_ident {txt = Longident.Lident "^"}};
3560+
funct = {pexp_desc = Pexp_ident {txt = Longident.Lident "++"}};
35613561
args = [(Nolabel, arg1); (Nolabel, arg2)];
35623562
} ->
35633563
let lhs = walk_expr arg1 in
@@ -3664,7 +3664,6 @@ and print_binary_expression ~state (expr : Parsetree.expression) cmt_tbl =
36643664
let print_binary_operator ~inline_rhs operator =
36653665
let operator_txt =
36663666
match operator with
3667-
| "^" -> "++"
36683667
| "=" -> "=="
36693668
| "==" -> "==="
36703669
| "<>" -> "!="
@@ -3800,7 +3799,7 @@ and print_binary_expression ~state (expr : Parsetree.expression) cmt_tbl =
38003799
match expr.pexp_desc with
38013800
| Pexp_apply
38023801
{
3803-
funct = {pexp_desc = Pexp_ident {txt = Longident.Lident "^"; loc}};
3802+
funct = {pexp_desc = Pexp_ident {txt = Longident.Lident "++"; loc}};
38043803
args = [(Nolabel, _); (Nolabel, _)];
38053804
}
38063805
when loc.loc_ghost ->

runtime/Pervasives.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ let classify_float = (x: float): fpclass =>
230230

231231
/* String and byte sequence operations -- more in modules String and Bytes */
232232

233-
external \"^": (string, string) => string = "%string_concat"
233+
external \"++": (string, string) => string = "%string_concat"
234234

235235
/* Character operations -- more in module Char */
236236

runtime/Pervasives_mini.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ external \"/.": (float, float) => float = "%divfloat"
7878

7979
/* String operations */
8080

81-
external \"^": (string, string) => string = "%string_concat"
81+
external \"++": (string, string) => string = "%string_concat"
8282

8383
/* Unit operations */
8484

tests/build_tests/super_errors/expected/primitives2.res.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
3 │
88

99
This has type: int
10-
But this function argument is expecting: string
10+
But it's expected to have type: string
1111

1212
You can convert int to string with Belt.Int.toString.

tests/build_tests/super_errors/expected/unicode_location.res.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
3 │
99

1010
This has type: int
11-
But this function argument is expecting: string
11+
But it's expected to have type: string
1212

1313
You can convert int to string with Belt.Int.toString.

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ let wss = Server.make { port = 82 }
1616
let address = wss -> Server.address
1717
let log [arity:1]msg =
1818
Js.log
19-
(((((({js|> Server: |js})[@res.template ]) ^ msg)[@res.template ]) ^
19+
(((((({js|> Server: |js})[@res.template ]) ++ msg)[@res.template ]) ++
2020
(({js||js})[@res.template ]))[@res.template ])
2121
;;log
22-
(((((((((((((({js|Running on: |js})[@res.template ]) ^ address.address)
23-
[@res.template ]) ^ (({js|:|js})[@res.template ]))
24-
[@res.template ]) ^ (address.port -> string_of_int))
25-
[@res.template ]) ^ (({js| (|js})[@res.template ]))
26-
[@res.template ]) ^ address.family)
27-
[@res.template ]) ^ (({js|)|js})[@res.template ]))[@res.template ])
22+
(((((((((((((({js|Running on: |js})[@res.template ]) ++ address.address)
23+
[@res.template ]) ++ (({js|:|js})[@res.template ]))
24+
[@res.template ]) ++ (address.port -> string_of_int))
25+
[@res.template ]) ++ (({js| (|js})[@res.template ]))
26+
[@res.template ]) ++ address.family)
27+
[@res.template ]) ++ (({js|)|js})[@res.template ]))[@res.template ])
2828
module ClientSet =
2929
struct
3030
module T =

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
let greetUser async [arity:1]userId =
22
((let name = ((getUserName userId)[@res.await ]) in
3-
({js|Hello |js} ^ name) ^ {js|!|js})
3+
({js|Hello |js} ++ name) ++ {js|!|js})
44
[@res.braces ])
55
;;async fun [arity:1]() -> 123
66
let fetch = ((async fun [arity:1]url -> browserFetch url)[@res.braces ])

0 commit comments

Comments
 (0)