Skip to content

Commit 96ef15c

Browse files
committed
Represent equality as == and ===.
1 parent cda76d2 commit 96ef15c

37 files changed

+172
-151
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
@@ -1236,8 +1236,8 @@ and walkExpr = (expr, t, comments) => {
12361236
":="
12371237
| "||"
12381238
| "&&"
1239-
| "="
12401239
| "=="
1240+
| "==="
12411241
| "<"
12421242
| ">"
12431243
| "!="

analysis/src/Xform.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,15 @@ module IfThenElse = struct
9393
{
9494
pexp_desc =
9595
Pexp_ident
96-
{txt = Longident.Lident (("=" | "<>") as op)};
96+
{txt = Longident.Lident (("==" | "!=") as op)};
9797
};
9898
args = [(Nolabel, arg1); (Nolabel, arg2)];
9999
};
100100
},
101101
e1,
102102
Some e2 )
103103
when Loc.hasPos ~pos e.pexp_loc -> (
104-
let e1, e2 = if op = "=" then (e1, e2) else (e2, e1) in
104+
let e1, e2 = if op = "==" then (e1, e2) else (e2, e1) in
105105
let mkMatch ~arg ~pat =
106106
let cases =
107107
[

compiler/ml/ast_mapper_from0.ml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,19 @@ module E = struct
324324
{e with pexp_desc = Pexp_ident {lid with txt = Longident.Lident "!="}}
325325
| ( Pexp_ident ({txt = Longident.Lident "!="} as lid),
326326
[(Nolabel, _); (Nolabel, _)] ) ->
327-
{e with pexp_desc = Pexp_ident {lid with txt = Longident.Lident "!=="}}
327+
{
328+
e with
329+
pexp_desc = Pexp_ident {lid with txt = Longident.Lident "!=="};
330+
}
331+
| ( Pexp_ident ({txt = Longident.Lident "="} as lid),
332+
[(Nolabel, _); (Nolabel, _)] ) ->
333+
{e with pexp_desc = Pexp_ident {lid with txt = Longident.Lident "=="}}
334+
| ( Pexp_ident ({txt = Longident.Lident "=="} as lid),
335+
[(Nolabel, _); (Nolabel, _)] ) ->
336+
{
337+
e with
338+
pexp_desc = Pexp_ident {lid with txt = Longident.Lident "==="};
339+
}
328340
| _ -> e
329341
in
330342
let process_partial_app_attribute attrs =

compiler/ml/ast_mapper_to0.ml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,12 @@ module E = struct
336336
| ( Pexp_ident ({txt = Longident.Lident "!=="} as lid),
337337
[(Nolabel, _); (Nolabel, _)] ) ->
338338
{e with pexp_desc = Pexp_ident {lid with txt = Longident.Lident "!="}}
339+
| ( Pexp_ident ({txt = Longident.Lident "==="} as lid),
340+
[(Nolabel, _); (Nolabel, _)] ) ->
341+
{e with pexp_desc = Pexp_ident {lid with txt = Longident.Lident "=="}}
342+
| ( Pexp_ident ({txt = Longident.Lident "=="} as lid),
343+
[(Nolabel, _); (Nolabel, _)] ) ->
344+
{e with pexp_desc = Pexp_ident {lid with txt = Longident.Lident "="}}
339345
| _ -> e
340346
in
341347
let attrs =

compiler/ml/error_message_utils.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ let type_clash_context_from_function sexp sfunct =
204204
in
205205
match sfunct.Parsetree.pexp_desc with
206206
| Pexp_ident
207-
{txt = Lident ("=" | "==" | "<>" | "!=" | ">" | ">=" | "<" | "<=")} ->
207+
{txt = Lident ("==" | "===" | "!=" | "!==" | ">" | ">=" | "<" | "<=")} ->
208208
Some ComparisonOperator
209209
| Pexp_ident {txt = Lident "++"} -> Some StringConcat
210210
| Pexp_ident {txt = Lident (("/." | "*." | "+." | "-.") as operator)} ->

compiler/syntax/src/res_comments_table.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1338,7 +1338,7 @@ and walk_expression expr t comments =
13381338
{
13391339
txt =
13401340
Longident.Lident
1341-
( ":=" | "||" | "&&" | "=" | "==" | "<" | ">" | "!="
1341+
( ":=" | "||" | "&&" | "==" | "===" | "<" | ">" | "!="
13421342
| "!==" | "<=" | ">=" | "|>" | "+" | "+." | "-" | "-."
13431343
| "++" | "^" | "*" | "*." | "/" | "/." | "**" | "->"
13441344
| "<>" );

compiler/syntax/src/res_core.ml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,6 @@ let make_infix_operator (p : Parser.t) token start_pos end_pos =
396396
Parser.err ~start_pos ~end_pos p
397397
(Diagnostics.message "Did you mean `==` here?");
398398
"=")
399-
else if token = Token.EqualEqual then "="
400-
else if token = Token.EqualEqualEqual then "=="
401399
else Token.to_string token
402400
in
403401
let loc = mk_loc start_pos end_pos in

compiler/syntax/src/res_parsetree_viewer.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ let operator_precedence operator =
270270
| ":=" -> 1
271271
| "||" -> 2
272272
| "&&" -> 3
273-
| "=" | "==" | "<" | ">" | "!=" | "<>" | "!==" | "<=" | ">=" | "|>" -> 4
273+
| "==" | "===" | "<" | ">" | "!=" | "<>" | "!==" | "<=" | ">=" | "|>" -> 4
274274
| "+" | "+." | "-" | "-." | "++" -> 5
275275
| "*" | "*." | "/" | "/." | "%" -> 6
276276
| "**" -> 7
@@ -296,7 +296,7 @@ let is_unary_expression expr =
296296
(* TODO: tweak this to check for ghost ^ as template literal *)
297297
let is_binary_operator operator =
298298
match operator with
299-
| ":=" | "||" | "&&" | "=" | "==" | "<" | ">" | "!=" | "!==" | "<=" | ">="
299+
| ":=" | "||" | "&&" | "==" | "===" | "<" | ">" | "!=" | "!==" | "<=" | ">="
300300
| "|>" | "+" | "+." | "-" | "-." | "++" | "*" | "*." | "/" | "/." | "**"
301301
| "->" | "<>" | "%" ->
302302
true
@@ -321,7 +321,7 @@ let is_binary_expression expr =
321321

322322
let is_equality_operator operator =
323323
match operator with
324-
| "=" | "==" | "!=" | "!==" -> true
324+
| "==" | "===" | "!=" | "!==" -> true
325325
| _ -> false
326326

327327
let is_rhs_binary_operator operator =

compiler/syntax/src/res_printer.ml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3662,12 +3662,6 @@ and print_unary_expression ~state expr cmt_tbl =
36623662

36633663
and print_binary_expression ~state (expr : Parsetree.expression) cmt_tbl =
36643664
let print_binary_operator ~inline_rhs operator =
3665-
let operator_txt =
3666-
match operator with
3667-
| "=" -> "=="
3668-
| "==" -> "==="
3669-
| txt -> txt
3670-
in
36713665
let spacing_before_operator =
36723666
if operator = "->" then Doc.soft_line
36733667
else if operator = "|>" then Doc.line
@@ -3680,7 +3674,7 @@ and print_binary_expression ~state (expr : Parsetree.expression) cmt_tbl =
36803674
else Doc.line
36813675
in
36823676
Doc.concat
3683-
[spacing_before_operator; Doc.text operator_txt; spacing_after_operator]
3677+
[spacing_before_operator; Doc.text operator; spacing_after_operator]
36843678
in
36853679
let print_operand ~is_lhs ~is_multiline expr parent_operator =
36863680
let rec flatten ~is_lhs ~is_multiline expr parent_operator =

runtime/Pervasives.res

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ external mod: ('a, 'a) => 'a = "%mod"
5555
/* Comparisons */
5656
/* Note: Later comparisons will be converted to unified operations too */
5757

58-
external \"=": ('a, 'a) => bool = "%equal"
58+
external \"==": ('a, 'a) => bool = "%equal"
5959
external \"!=": ('a, 'a) => bool = "%notequal"
6060
external \"<": ('a, 'a) => bool = "%lessthan"
6161
external \">": ('a, 'a) => bool = "%greaterthan"
@@ -64,7 +64,7 @@ external \">=": ('a, 'a) => bool = "%greaterequal"
6464
external compare: ('a, 'a) => int = "%compare"
6565
external min: ('a, 'a) => 'a = "%min"
6666
external max: ('a, 'a) => 'a = "%max"
67-
external \"==": ('a, 'a) => bool = "%eq"
67+
external \"===": ('a, 'a) => bool = "%eq"
6868
external \"!==": ('a, 'a) => bool = "%noteq"
6969

7070
/* Boolean operations */

0 commit comments

Comments
 (0)