Skip to content

Commit 949d700

Browse files
authored
Rename @ns.* to @res.* in parser/printer and outcome printer. (rescript-lang#5862)
* Rename @ns.optional to @res.optional * Rename `@ns.ternary` to `@res.ternary`. * Rename ns.braces to res.braces * Rename ns.iflet to res.iflet * Rename ns.namedArgLoc to res.namedArgLoc * Rename ns.doc to res.doc.
1 parent 079edea commit 949d700

File tree

78 files changed

+758
-744
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+758
-744
lines changed

jscomp/main/builtin_cmi_datasets.ml

+5-5
Large diffs are not rendered by default.

jscomp/ml/datarepr.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ let constructor_descrs ty_path decl cstrs =
113113
if cd_args = Cstr_tuple [] then incr num_consts else incr num_nonconsts;
114114
if cd_res = None then incr num_normal)
115115
cstrs;
116-
let has_optional attrs = Ext_list.exists attrs (fun ({txt },_) -> txt = "ns.optional") in
116+
let has_optional attrs = Ext_list.exists attrs (fun ({txt },_) -> txt = "res.optional") in
117117
let rec describe_constructors idx_const idx_nonconst = function
118118
[] -> []
119119
| {cd_id; cd_args; cd_res; cd_loc; cd_attributes} :: rem ->

jscomp/ml/printtyp.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,7 @@ and tree_of_constructor cd =
926926
(name, args, Some ret)
927927

928928
and tree_of_label l =
929-
let opt = l.ld_attributes |> List.exists (fun ({txt}, _) -> txt = "ns.optional") in
929+
let opt = l.ld_attributes |> List.exists (fun ({txt}, _) -> txt = "res.optional") in
930930
let typ = match l.ld_type.desc with
931931
| Tconstr (p, [t1], _) when opt && Path.same p Predef.path_option -> t1
932932
| _ -> l.ld_type in

jscomp/ml/typecore.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ let check_optional_attr env ld attrs loc =
322322
raise (Error (loc, env, Field_not_optional (ld.lbl_name, ld.lbl_res)));
323323
true in
324324
Ext_list.exists attrs (fun ({txt}, _) ->
325-
txt = "ns.optional" && check_redundant ())
325+
txt = "res.optional" && check_redundant ())
326326

327327
(* unification inside type_pat*)
328328
let unify_pat_types loc env ty ty' =

jscomp/ml/typedecl.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ let transl_declaration env sdecl id =
358358
| (_,_,loc)::_ ->
359359
Location.prerr_warning loc Warnings.Constraint_on_gadt
360360
end;
361-
let has_optional attrs = Ext_list.exists attrs (fun ({txt },_) -> txt = "ns.optional") in
361+
let has_optional attrs = Ext_list.exists attrs (fun ({txt },_) -> txt = "res.optional") in
362362
let scstrs =
363363
Ext_list.map scstrs (fun ({pcd_args} as cstr) ->
364364
match pcd_args with
@@ -409,7 +409,7 @@ let transl_declaration env sdecl id =
409409
let tcstrs, cstrs = List.split (List.map make_cstr scstrs) in
410410
Ttype_variant tcstrs, Type_variant cstrs
411411
| Ptype_record lbls ->
412-
let has_optional attrs = Ext_list.exists attrs (fun ({txt },_) -> txt = "ns.optional") in
412+
let has_optional attrs = Ext_list.exists attrs (fun ({txt },_) -> txt = "res.optional") in
413413
let optionalLabels =
414414
Ext_list.filter_map lbls
415415
(fun lbl -> if has_optional lbl.pld_attributes then Some lbl.pld_name.txt else None) in

lib/4.06.1/unstable/all_ounit_tests.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -43418,7 +43418,7 @@ let constructor_descrs ty_path decl cstrs =
4341843418
if cd_args = Cstr_tuple [] then incr num_consts else incr num_nonconsts;
4341943419
if cd_res = None then incr num_normal)
4342043420
cstrs;
43421-
let has_optional attrs = Ext_list.exists attrs (fun ({txt },_) -> txt = "ns.optional") in
43421+
let has_optional attrs = Ext_list.exists attrs (fun ({txt },_) -> txt = "res.optional") in
4342243422
let rec describe_constructors idx_const idx_nonconst = function
4342343423
[] -> []
4342443424
| {cd_id; cd_args; cd_res; cd_loc; cd_attributes} :: rem ->

lib/4.06.1/unstable/js_compiler.ml

+44-44
Large diffs are not rendered by default.

lib/4.06.1/unstable/js_playground_compiler.ml

+59-57
Large diffs are not rendered by default.

lib/4.06.1/whole_compiler.ml

+60-58
Large diffs are not rendered by default.

res_syntax/benchmarks/data/Napkinscript.ml

+32-32
Original file line numberDiff line numberDiff line change
@@ -3189,15 +3189,15 @@ end = struct
31893189

31903190
let processBracesAttr expr =
31913191
match expr.pexp_attributes with
3192-
| (({txt = "ns.braces"}, _) as attr)::attrs ->
3192+
| (({txt = "res.braces"}, _) as attr)::attrs ->
31933193
(Some attr, {expr with pexp_attributes = attrs})
31943194
| _ ->
31953195
(None, expr)
31963196

31973197
let filterParsingAttrs attrs =
31983198
List.filter (fun attr ->
31993199
match attr with
3200-
| ({Location.txt = ("ns.ternary" | "ns.braces" | "bs" | "ns.namedArgLoc")}, _) -> false
3200+
| ({Location.txt = ("res.ternary" | "res.braces" | "bs" | "res.namedArgLoc")}, _) -> false
32013201
| _ -> true
32023202
) attrs
32033203

@@ -3301,7 +3301,7 @@ end = struct
33013301

33023302
let hasAttributes attrs =
33033303
List.exists (fun attr -> match attr with
3304-
| ({Location.txt = "bs" | "ns.ternary" | "ns.braces"}, _) -> false
3304+
| ({Location.txt = "bs" | "res.ternary" | "res.braces"}, _) -> false
33053305
| _ -> true
33063306
) attrs
33073307

@@ -3315,7 +3315,7 @@ end = struct
33153315
let rec hasTernaryAttribute attrs =
33163316
match attrs with
33173317
| [] -> false
3318-
| ({Location.txt="ns.ternary"},_)::_ -> true
3318+
| ({Location.txt="res.ternary"},_)::_ -> true
33193319
| _::attrs -> hasTernaryAttribute attrs
33203320

33213321
let isTernaryExpr expr = match expr with
@@ -3346,7 +3346,7 @@ end = struct
33463346

33473347
let filterTernaryAttributes attrs =
33483348
List.filter (fun attr -> match attr with
3349-
|({Location.txt="ns.ternary"},_) -> false
3349+
|({Location.txt="res.ternary"},_) -> false
33503350
| _ -> true
33513351
) attrs
33523352

@@ -3403,13 +3403,13 @@ end = struct
34033403

34043404
let filterPrinteableAttributes attrs =
34053405
List.filter (fun attr -> match attr with
3406-
| ({Location.txt="bs" | "ns.ternary"}, _) -> false
3406+
| ({Location.txt="bs" | "res.ternary"}, _) -> false
34073407
| _ -> true
34083408
) attrs
34093409

34103410
let partitionPrinteableAttributes attrs =
34113411
List.partition (fun attr -> match attr with
3412-
| ({Location.txt="bs" | "ns.ternary"}, _) -> false
3412+
| ({Location.txt="bs" | "res.ternary"}, _) -> false
34133413
| _ -> true
34143414
) attrs
34153415

@@ -5189,7 +5189,7 @@ module CommentTable = struct
51895189
walkList
51905190
~getLoc:(fun (_argLabel, expr) ->
51915191
let loc = match expr.Parsetree.pexp_attributes with
5192-
| ({Location.txt = "ns.namedArgLoc"; loc}, _)::_attrs ->
5192+
| ({Location.txt = "res.namedArgLoc"; loc}, _)::_attrs ->
51935193
{loc with loc_end = expr.pexp_loc.loc_end}
51945194
| _ ->
51955195
expr.pexp_loc
@@ -5207,7 +5207,7 @@ module CommentTable = struct
52075207
~getLoc:(fun (_attrs, _argLbl, exprOpt, pattern) ->
52085208
let open Parsetree in
52095209
let startPos = match pattern.ppat_attributes with
5210-
| ({Location.txt = "ns.namedArgLoc"; loc}, _)::_attrs ->
5210+
| ({Location.txt = "res.namedArgLoc"; loc}, _)::_attrs ->
52115211
loc.loc_start
52125212
| _ ->
52135213
pattern.ppat_loc.loc_start
@@ -5279,7 +5279,7 @@ module CommentTable = struct
52795279

52805280
and walkExprArgument (_argLabel, expr) t comments =
52815281
match expr.Parsetree.pexp_attributes with
5282-
| ({Location.txt = "ns.namedArgLoc"; loc}, _)::_attrs ->
5282+
| ({Location.txt = "res.namedArgLoc"; loc}, _)::_attrs ->
52835283
let (leading, trailing) = partitionLeadingTrailing comments loc in
52845284
attach t.leading loc leading;
52855285
let (afterLabel, rest) = partitionAdjacentTrailing loc trailing in
@@ -7706,7 +7706,7 @@ module Printer = struct
77067706
ParsetreeViewer.isBinaryExpression expr ||
77077707
(match vb.pvb_expr with
77087708
| {
7709-
pexp_attributes = [({Location.txt="ns.ternary"}, _)];
7709+
pexp_attributes = [({Location.txt="res.ternary"}, _)];
77107710
pexp_desc = Pexp_ifthenelse (ifExpr, _, _)
77117711
} ->
77127712
ParsetreeViewer.isBinaryExpression ifExpr || ParsetreeViewer.hasAttributes ifExpr.pexp_attributes
@@ -9250,7 +9250,7 @@ module Printer = struct
92509250
match Parens.binaryExpr {expr with
92519251
pexp_attributes = List.filter (fun attr ->
92529252
match attr with
9253-
| ({Location.txt = ("ns.braces")}, _) -> false
9253+
| ({Location.txt = ("res.braces")}, _) -> false
92549254
| _ -> true
92559255
) expr.pexp_attributes
92569256
} with
@@ -9402,7 +9402,7 @@ module Printer = struct
94029402
ParsetreeViewer.isBinaryExpression targetExpr ||
94039403
(match targetExpr with
94049404
| {
9405-
pexp_attributes = [({Location.txt="ns.ternary"}, _)];
9405+
pexp_attributes = [({Location.txt="res.ternary"}, _)];
94069406
pexp_desc = Pexp_ifthenelse (ifExpr, _, _)
94079407
} ->
94089408
ParsetreeViewer.isBinaryExpression ifExpr || ParsetreeViewer.hasAttributes ifExpr.pexp_attributes
@@ -9599,7 +9599,7 @@ module Printer = struct
95999599
| (
96009600
(Asttypes.Labelled lblTxt | Optional lblTxt) as lbl,
96019601
{
9602-
Parsetree.pexp_attributes = [({Location.txt = "ns.namedArgLoc"; loc = argLoc}, _)];
9602+
Parsetree.pexp_attributes = [({Location.txt = "res.namedArgLoc"; loc = argLoc}, _)];
96039603
pexp_desc = Pexp_ident {txt = Longident.Lident ident}
96049604
}
96059605
) when lblTxt = ident (* jsx punning *) ->
@@ -9631,7 +9631,7 @@ module Printer = struct
96319631
end
96329632
| (lbl, expr) ->
96339633
let (argLoc, expr) = match expr.pexp_attributes with
9634-
| ({Location.txt = "ns.namedArgLoc"; loc}, _)::attrs ->
9634+
| ({Location.txt = "res.namedArgLoc"; loc}, _)::attrs ->
96359635
(loc, {expr with pexp_attributes = attrs})
96369636
| _ ->
96379637
Location.none, expr
@@ -9845,11 +9845,11 @@ module Printer = struct
98459845
| (
98469846
(Asttypes.Labelled lbl),
98479847
({pexp_desc=Pexp_ident {txt = Longident.Lident name};
9848-
pexp_attributes = ([] | [({Location.txt = "ns.namedArgLoc";}, _)])
9848+
pexp_attributes = ([] | [({Location.txt = "res.namedArgLoc";}, _)])
98499849
} as argExpr)
98509850
) when lbl = name && not (ParsetreeViewer.isBracedExpr argExpr) ->
98519851
let loc = match arg.pexp_attributes with
9852-
| ({Location.txt = "ns.namedArgLoc"; loc}, _)::_ -> loc
9852+
| ({Location.txt = "res.namedArgLoc"; loc}, _)::_ -> loc
98539853
| _ -> arg.pexp_loc
98549854
in
98559855
let doc = Doc.concat [
@@ -9866,11 +9866,11 @@ module Printer = struct
98669866
typ
98679867
);
98689868
pexp_loc;
9869-
pexp_attributes = ([] | [({Location.txt = "ns.namedArgLoc";}, _)]) as attrs
9869+
pexp_attributes = ([] | [({Location.txt = "res.namedArgLoc";}, _)]) as attrs
98709870
}
98719871
) when lbl = name && not (ParsetreeViewer.isBracedExpr argExpr) ->
98729872
let loc = match attrs with
9873-
| ({Location.txt = "ns.namedArgLoc"; loc}, _)::_ ->
9873+
| ({Location.txt = "res.namedArgLoc"; loc}, _)::_ ->
98749874
{loc with loc_end = pexp_loc.loc_end}
98759875
| _ -> arg.pexp_loc
98769876
in
@@ -9885,11 +9885,11 @@ module Printer = struct
98859885
| (
98869886
(Asttypes.Optional lbl),
98879887
{pexp_desc=Pexp_ident {txt = Longident.Lident name};
9888-
pexp_attributes = ([] | [({Location.txt = "ns.namedArgLoc";}, _)])
9888+
pexp_attributes = ([] | [({Location.txt = "res.namedArgLoc";}, _)])
98899889
}
98909890
) when lbl = name ->
98919891
let loc = match arg.pexp_attributes with
9892-
| ({Location.txt = "ns.namedArgLoc"; loc}, _)::_ -> loc
9892+
| ({Location.txt = "res.namedArgLoc"; loc}, _)::_ -> loc
98939893
| _ -> arg.pexp_loc
98949894
in
98959895
let doc = Doc.concat [
@@ -9900,7 +9900,7 @@ module Printer = struct
99009900
printComments doc cmtTbl loc
99019901
| (_lbl, expr) ->
99029902
let (argLoc, expr) = match expr.pexp_attributes with
9903-
| ({Location.txt = "ns.namedArgLoc"; loc}, _)::attrs ->
9903+
| ({Location.txt = "res.namedArgLoc"; loc}, _)::attrs ->
99049904
(loc, {expr with pexp_attributes = attrs})
99059905
| _ ->
99069906
expr.pexp_loc, expr
@@ -10095,7 +10095,7 @@ module Printer = struct
1009510095
| (
1009610096
(Asttypes.Labelled lbl | Optional lbl),
1009710097
{ppat_desc = Ppat_var stringLoc;
10098-
ppat_attributes = ([] | [({Location.txt = "ns.namedArgLoc";}, _)])
10098+
ppat_attributes = ([] | [({Location.txt = "res.namedArgLoc";}, _)])
1009910099
}
1010010100
) when lbl = stringLoc.txt ->
1010110101
(* ~d *)
@@ -10106,7 +10106,7 @@ module Printer = struct
1010610106
| (
1010710107
(Asttypes.Labelled lbl | Optional lbl),
1010810108
({ppat_desc = Ppat_constraint ({ ppat_desc = Ppat_var { txt } }, typ);
10109-
ppat_attributes = ([] | [({Location.txt = "ns.namedArgLoc";}, _)])
10109+
ppat_attributes = ([] | [({Location.txt = "res.namedArgLoc";}, _)])
1011010110
})
1011110111
) when lbl = txt ->
1011210112
(* ~d: e *)
@@ -10141,13 +10141,13 @@ module Printer = struct
1014110141
let cmtLoc = match defaultExpr with
1014210142
| None ->
1014310143
begin match pattern.ppat_attributes with
10144-
| ({Location.txt = "ns.namedArgLoc"; loc}, _)::_ ->
10144+
| ({Location.txt = "res.namedArgLoc"; loc}, _)::_ ->
1014510145
{loc with loc_end = pattern.ppat_loc.loc_end}
1014610146
| _ -> pattern.ppat_loc
1014710147
end
1014810148
| Some expr ->
1014910149
let startPos = match pattern.ppat_attributes with
10150-
| ({Location.txt = "ns.namedArgLoc"; loc}, _)::_ ->
10150+
| ({Location.txt = "res.namedArgLoc"; loc}, _)::_ ->
1015110151
loc.loc_start
1015210152
| _ -> pattern.ppat_loc.loc_start
1015310153
in {
@@ -11991,7 +11991,7 @@ module ParsetreeCompatibility = struct
1199111991
{pc_lhs = {ppat_desc = Ppat_construct ({txt = Longident.Lident "false"}, None)}; pc_rhs = elseExpr };
1199211992
]
1199311993
) ->
11994-
let ternaryMarker = (Location.mknoloc "ns.ternary", Parsetree.PStr []) in
11994+
let ternaryMarker = (Location.mknoloc "res.ternary", Parsetree.PStr []) in
1199511995
Ast_helper.Exp.ifthenelse
1199611996
~loc:expr.pexp_loc
1199711997
~attrs:(ternaryMarker::expr.pexp_attributes)
@@ -12322,8 +12322,8 @@ end
1232212322

1232312323
let jsxAttr = (Location.mknoloc "JSX", Parsetree.PStr [])
1232412324
let uncurryAttr = (Location.mknoloc "bs", Parsetree.PStr [])
12325-
let ternaryAttr = (Location.mknoloc "ns.ternary", Parsetree.PStr [])
12326-
let makeBracesAttr loc = (Location.mkloc "ns.braces" loc, Parsetree.PStr [])
12325+
let ternaryAttr = (Location.mknoloc "res.ternary", Parsetree.PStr [])
12326+
let makeBracesAttr loc = (Location.mkloc "res.braces" loc, Parsetree.PStr [])
1232712327

1232812328
type typDefOrExt =
1232912329
| TypeDef of {recFlag: Asttypes.rec_flag; types: Parsetree.type_declaration list}
@@ -13769,7 +13769,7 @@ end
1376913769
| Tilde ->
1377013770
Parser.next p;
1377113771
let (lblName, loc) = parseLident p in
13772-
let propLocAttr = (Location.mkloc "ns.namedArgLoc" loc, Parsetree.PStr []) in
13772+
let propLocAttr = (Location.mkloc "res.namedArgLoc" loc, Parsetree.PStr []) in
1377313773
begin match p.Parser.token with
1377413774
| Comma | Equal | Rparen ->
1377513775
let loc = mkLoc startPos p.prevEndPos in
@@ -14760,7 +14760,7 @@ end
1476014760
| Question | Lident _ ->
1476114761
let optional = Parser.optional p Question in
1476214762
let (name, loc) = parseLident p in
14763-
let propLocAttr = (Location.mkloc "ns.namedArgLoc" loc, Parsetree.PStr []) in
14763+
let propLocAttr = (Location.mkloc "res.namedArgLoc" loc, Parsetree.PStr []) in
1476414764
(* optional punning: <foo ?a /> *)
1476514765
if optional then
1476614766
Some (
@@ -15444,7 +15444,7 @@ end
1544415444
Parser.next p;
1544515445
let endPos = p.prevEndPos in
1544615446
let loc = mkLoc startPos endPos in
15447-
let propLocAttr = (Location.mkloc "ns.namedArgLoc" loc, Parsetree.PStr []) in
15447+
let propLocAttr = (Location.mkloc "res.namedArgLoc" loc, Parsetree.PStr []) in
1544815448
let identExpr = Ast_helper.Exp.ident ~attrs:[propLocAttr] ~loc (
1544915449
Location.mkloc (Longident.Lident ident) loc
1545015450
) in

0 commit comments

Comments
 (0)