Skip to content

Commit ecc9428

Browse files
committed
Remove dotted processing.
1 parent 89f91a6 commit ecc9428

File tree

5 files changed

+20
-64
lines changed

5 files changed

+20
-64
lines changed

jscomp/syntax/src/res_core.ml

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,7 @@ let tagged_template_literal_attr =
182182

183183
let spread_attr = (Location.mknoloc "res.spread", Parsetree.PStr [])
184184

185-
type argument = {
186-
dotted: bool;
187-
label: Asttypes.arg_label;
188-
expr: Parsetree.expression;
189-
}
185+
type argument = {label: Asttypes.arg_label; expr: Parsetree.expression}
190186

191187
type type_parameter = {
192188
attrs: Ast_helper.attrs;
@@ -3574,7 +3570,6 @@ and parse_argument p : argument option =
35743570
then
35753571
match p.Parser.token with
35763572
| Dot -> (
3577-
let dotted = true in
35783573
Parser.next p;
35793574
match p.token with
35803575
(* apply(.) *)
@@ -3584,12 +3579,12 @@ and parse_argument p : argument option =
35843579
(Location.mknoloc (Longident.Lident "()"))
35853580
None
35863581
in
3587-
Some {dotted; label = Asttypes.Nolabel; expr = unit_expr}
3588-
| _ -> parse_argument2 p ~dotted)
3589-
| _ -> parse_argument2 p ~dotted:false
3582+
Some {label = Asttypes.Nolabel; expr = unit_expr}
3583+
| _ -> parse_argument2 p)
3584+
| _ -> parse_argument2 p
35903585
else None
35913586

3592-
and parse_argument2 p ~dotted : argument option =
3587+
and parse_argument2 p : argument option =
35933588
match p.Parser.token with
35943589
(* foo(_), do not confuse with foo(_ => x), TODO: performance *)
35953590
| Underscore when not (is_es6_arrow_expression ~in_ternary:false p) ->
@@ -3598,7 +3593,7 @@ and parse_argument2 p ~dotted : argument option =
35983593
let expr =
35993594
Ast_helper.Exp.ident ~loc (Location.mkloc (Longident.Lident "_") loc)
36003595
in
3601-
Some {dotted; label = Nolabel; expr}
3596+
Some {label = Nolabel; expr}
36023597
| Tilde -> (
36033598
Parser.next p;
36043599
(* TODO: nesting of pattern matches not intuitive for error recovery *)
@@ -3618,7 +3613,7 @@ and parse_argument2 p ~dotted : argument option =
36183613
match p.Parser.token with
36193614
| Question ->
36203615
Parser.next p;
3621-
Some {dotted; label = Optional ident; expr = ident_expr}
3616+
Some {label = Optional ident; expr = ident_expr}
36223617
| Equal ->
36233618
Parser.next p;
36243619
let label =
@@ -3639,21 +3634,20 @@ and parse_argument2 p ~dotted : argument option =
36393634
let expr = parse_constrained_or_coerced_expr p in
36403635
{expr with pexp_attributes = prop_loc_attr :: expr.pexp_attributes}
36413636
in
3642-
Some {dotted; label; expr}
3637+
Some {label; expr}
36433638
| Colon ->
36443639
Parser.next p;
36453640
let typ = parse_typ_expr p in
36463641
let loc = mk_loc start_pos p.prev_end_pos in
36473642
let expr =
36483643
Ast_helper.Exp.constraint_ ~attrs:[prop_loc_attr] ~loc ident_expr typ
36493644
in
3650-
Some {dotted; label = Labelled ident; expr}
3651-
| _ -> Some {dotted; label = Labelled ident; expr = ident_expr})
3645+
Some {label = Labelled ident; expr}
3646+
| _ -> Some {label = Labelled ident; expr = ident_expr})
36523647
| t ->
36533648
Parser.err p (Diagnostics.lident t);
3654-
Some {dotted; label = Nolabel; expr = Recover.default_expr ()})
3655-
| _ ->
3656-
Some {dotted; label = Nolabel; expr = parse_constrained_or_coerced_expr p}
3649+
Some {label = Nolabel; expr = Recover.default_expr ()})
3650+
| _ -> Some {label = Nolabel; expr = parse_constrained_or_coerced_expr p}
36573651

36583652
and parse_call_expr p fun_expr =
36593653
Parser.expect Lparen p;
@@ -3682,7 +3676,6 @@ and parse_call_expr p fun_expr =
36823676
(* No args -> unit sugar: `foo()` *)
36833677
[
36843678
{
3685-
dotted = false;
36863679
label = Nolabel;
36873680
expr =
36883681
Ast_helper.Exp.construct ~loc
@@ -3692,7 +3685,6 @@ and parse_call_expr p fun_expr =
36923685
]
36933686
| [
36943687
{
3695-
dotted = true;
36963688
label = Nolabel;
36973689
expr =
36983690
{
@@ -3718,7 +3710,6 @@ and parse_call_expr p fun_expr =
37183710
*)
37193711
[
37203712
{
3721-
dotted = true;
37223713
label = Nolabel;
37233714
expr =
37243715
Ast_helper.Exp.let_ Asttypes.Nonrecursive
@@ -3736,19 +3727,14 @@ and parse_call_expr p fun_expr =
37363727
let loc = {fun_expr.pexp_loc with loc_end = p.prev_end_pos} in
37373728
let args =
37383729
match args with
3739-
| {dotted = d; label = lbl; expr} :: args ->
3740-
let group (grp, acc) {dotted; label = lbl; expr} =
3741-
let _d, grp = grp in
3742-
if dotted == true then ((true, [(lbl, expr)]), (_d, List.rev grp) :: acc)
3743-
else ((_d, (lbl, expr) :: grp), acc)
3744-
in
3745-
let (_d, grp), acc = List.fold_left group ((d, [(lbl, expr)]), []) args in
3746-
List.rev ((_d, List.rev grp) :: acc)
3730+
| {label = lbl; expr} :: args ->
3731+
let group (grp, acc) {label = lbl; expr} = ((lbl, expr) :: grp, acc) in
3732+
let grp, acc = List.fold_left group ([(lbl, expr)], []) args in
3733+
List.rev (List.rev grp :: acc)
37473734
| [] -> []
37483735
in
37493736
let apply =
3750-
Ext_list.fold_left args fun_expr (fun call_body group ->
3751-
let _, args = group in
3737+
Ext_list.fold_left args fun_expr (fun call_body args ->
37523738
let args, wrap = process_underscore_application args in
37533739
let exp =
37543740
let attrs = [uncurried_app_attr] in

jscomp/syntax/src/res_parsetree_viewer.ml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,6 @@ let functor_type modtype =
4848
in
4949
process [] modtype
5050

51-
let process_bs_attribute attrs =
52-
let rec process bs_spotted acc attrs =
53-
match attrs with
54-
| [] -> (bs_spotted, List.rev acc)
55-
| ({Location.txt = "bs"}, _) :: rest -> process true acc rest
56-
| attr :: rest -> process bs_spotted (attr :: acc) rest
57-
in
58-
process false [] attrs
59-
6051
let process_uncurried_app_attribute attrs =
6152
let rec process uncurried_app acc attrs =
6253
match attrs with

jscomp/syntax/src/res_parsetree_viewer.mli

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ val functor_type :
1414
list
1515
* Parsetree.module_type
1616

17-
(* filters @bs out of the provided attributes *)
18-
val process_bs_attribute : Parsetree.attributes -> bool * Parsetree.attributes
19-
2017
val process_uncurried_app_attribute :
2118
Parsetree.attributes -> bool * Parsetree.attributes
2219

jscomp/syntax/src/res_printer.ml

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,12 +1547,6 @@ and print_typ_expr ~(state : State.t) (typ_expr : Parsetree.core_type) cmt_tbl =
15471547
let attrs_before, args, return_type =
15481548
ParsetreeViewer.arrow_type ~arity typ_expr
15491549
in
1550-
let dotted, attrs_before =
1551-
let dotted = false in
1552-
(* Converting .ml code to .res requires processing uncurried attributes *)
1553-
let has_bs, attrs = ParsetreeViewer.process_bs_attribute attrs_before in
1554-
(dotted || has_bs, attrs)
1555-
in
15561550
let return_type_needs_parens =
15571551
match return_type.ptyp_desc with
15581552
| Ptyp_alias _ -> true
@@ -1565,7 +1559,7 @@ and print_typ_expr ~(state : State.t) (typ_expr : Parsetree.core_type) cmt_tbl =
15651559
in
15661560
match args with
15671561
| [] -> Doc.nil
1568-
| [([], Nolabel, n)] when not dotted ->
1562+
| [([], Nolabel, n)] ->
15691563
let has_attrs_before = not (attrs_before = []) in
15701564
let attrs =
15711565
if has_attrs_before then
@@ -1607,7 +1601,6 @@ and print_typ_expr ~(state : State.t) (typ_expr : Parsetree.core_type) cmt_tbl =
16071601
(Doc.concat
16081602
[
16091603
Doc.soft_line;
1610-
(if dotted then Doc.concat [Doc.dot; Doc.space] else Doc.nil);
16111604
Doc.join
16121605
~sep:(Doc.concat [Doc.comma; Doc.line])
16131606
(List.map
@@ -1901,8 +1894,6 @@ and print_object_field ~state (field : Parsetree.object_field) cmt_tbl =
19011894
* i.e. ~foo: string, ~bar: float *)
19021895
and print_type_parameter ~state (attrs, lbl, typ) cmt_tbl =
19031896
(* Converting .ml code to .res requires processing uncurried attributes *)
1904-
let has_bs, attrs = ParsetreeViewer.process_bs_attribute attrs in
1905-
let dotted = if has_bs then Doc.concat [Doc.dot; Doc.space] else Doc.nil in
19061897
let attrs = print_attributes ~state attrs cmt_tbl in
19071898
let label =
19081899
match lbl with
@@ -1927,13 +1918,7 @@ and print_type_parameter ~state (attrs, lbl, typ) cmt_tbl =
19271918
let doc =
19281919
Doc.group
19291920
(Doc.concat
1930-
[
1931-
dotted;
1932-
attrs;
1933-
label;
1934-
print_typ_expr ~state typ cmt_tbl;
1935-
optional_indicator;
1936-
])
1921+
[attrs; label; print_typ_expr ~state typ cmt_tbl; optional_indicator])
19371922
in
19381923
print_comments doc cmt_tbl loc
19391924

@@ -5100,8 +5085,6 @@ and print_exp_fun_parameter ~state parameter cmt_tbl =
51005085
lbls);
51015086
])
51025087
| Parameter {attrs; lbl; default_expr; pat = pattern} ->
5103-
let has_bs, attrs = ParsetreeViewer.process_bs_attribute attrs in
5104-
let dotted = if has_bs then Doc.concat [Doc.dot; Doc.space] else Doc.nil in
51055088
let attrs = print_attributes ~state attrs cmt_tbl in
51065089
(* =defaultValue *)
51075090
let default_expr_doc =
@@ -5160,7 +5143,6 @@ and print_exp_fun_parameter ~state parameter cmt_tbl =
51605143
Doc.group
51615144
(Doc.concat
51625145
[
5163-
dotted;
51645146
attrs;
51655147
label_with_pattern;
51665148
default_expr_doc;

jscomp/syntax/tests/parsing/grammar/expressions/expected/uncurried.res.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ let f =
2727
fun ((b)[@attr2 ]) -> fun ((c)[@attr3 ]) -> fun ((d)[@attr4 ]) -> ()))
2828
[@res.arity 4])
2929
;;((add 1 2)[@res.uapp ])
30-
;;((((((add 2 3 4)[@res.uapp ]) 5 6 7)[@res.uapp ]) 8 9 10)[@res.uapp ])
30+
;;((add 2 3 4 5 6 7 8 9 10)[@res.uapp ])

0 commit comments

Comments
 (0)