Skip to content

Commit 3286c4d

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

File tree

23 files changed

+97
-87
lines changed

23 files changed

+97
-87
lines changed

compiler/ml/ast_mapper_from0.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,9 @@ module E = struct
316316
| ( Pexp_ident ({txt = Longident.Lident "|."} as lid),
317317
[(Nolabel, _); (Nolabel, _)] ) ->
318318
{e with pexp_desc = Pexp_ident {lid with txt = Longident.Lident "->"}}
319+
| ( Pexp_ident ({txt = Longident.Lident "^"} as lid),
320+
[(Nolabel, _); (Nolabel, _)] ) ->
321+
{e with pexp_desc = Pexp_ident {lid with txt = Longident.Lident "++"}}
319322
| _ -> e
320323
in
321324
let process_partial_app_attribute attrs =

compiler/ml/ast_mapper_to0.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,9 @@ module E = struct
327327
| ( Pexp_ident ({txt = Longident.Lident "->"} as lid),
328328
[(Nolabel, _); (Nolabel, _)] ) ->
329329
{e with pexp_desc = Pexp_ident {lid with txt = Longident.Lident "|."}}
330+
| ( Pexp_ident ({txt = Longident.Lident "++"} as lid),
331+
[(Nolabel, _); (Nolabel, _)] ) ->
332+
{e with pexp_desc = Pexp_ident {lid with txt = Longident.Lident "^"}}
330333
| _ -> e
331334
in
332335
let attrs =

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.

0 commit comments

Comments
 (0)