|
1 | 1 | open GenTypeCommon |
2 | 2 |
|
3 | | -type groupedArg = Group of fields | Arg of type_ |
4 | | - |
5 | | -(** |
6 | | - For convenient processing turns consecutive named arguments into a |
7 | | - `NamedArgs` group, and individual non-named arguments into `Arg`s. |
8 | | -*) |
9 | | -let rec groupReversed ~revCurGroup ~revResult labeledTypes = |
10 | | - match (revCurGroup, labeledTypes) with |
11 | | - | [], (Nolabel, type_) :: tl -> |
12 | | - groupReversed ~revCurGroup:[] ~revResult:(Arg type_ :: revResult) tl |
13 | | - | _, (OptLabel name, type_) :: tl -> |
14 | | - (* Add it to the current group, not result. *) |
15 | | - groupReversed |
16 | | - ~revCurGroup: |
17 | | - ({ |
18 | | - mutable_ = Immutable; |
19 | | - nameJS = name; |
20 | | - optional = Optional; |
21 | | - type_; |
22 | | - docString = DocString.empty; |
23 | | - } |
24 | | - :: revCurGroup) |
25 | | - ~revResult tl |
26 | | - | _, (Label name, type_) :: tl -> |
27 | | - groupReversed |
28 | | - ~revCurGroup: |
29 | | - ({ |
30 | | - mutable_ = Immutable; |
31 | | - nameJS = name; |
32 | | - optional = Mandatory; |
33 | | - type_; |
34 | | - docString = DocString.empty; |
35 | | - } |
36 | | - :: revCurGroup) |
37 | | - ~revResult tl |
38 | | - | [], [] -> revResult |
39 | | - | _grpHd :: _grpTl, ([] as _tl) | _grpHd :: _grpTl, (Nolabel, _) :: _tl -> |
40 | | - (* Just form the group, and recurse ignoring the (None, t) in that case. |
41 | | - t will be handled in recursion. *) |
42 | | - groupReversed ~revCurGroup:[] |
43 | | - ~revResult:(Group revCurGroup :: revResult) |
44 | | - labeledTypes |
45 | | - |
46 | | -(** Special reverse that not only reverses the entire list but also the order of |
47 | | - items in the NamedArgs grouping. *) |
48 | | -let rec reverse ?(soFar = []) lst = |
49 | | - match lst with |
50 | | - | [] -> soFar |
51 | | - | [Arg type_] when type_ = unitT && soFar = [] -> |
52 | | - (* treat a single argument of type unit as no argument *) |
53 | | - [] |
54 | | - | Arg type_ :: tl -> reverse ~soFar:({aName = ""; aType = type_} :: soFar) tl |
55 | | - | Group fields :: tl -> |
56 | | - reverse |
57 | | - ~soFar: |
58 | | - ({aName = ""; aType = GroupOfLabeledArgs (List.rev fields)} :: soFar) |
59 | | - tl |
60 | | - |
61 | 3 | let group labeledTypes = |
62 | | - labeledTypes |> groupReversed ~revCurGroup:[] ~revResult:[] |> reverse |
| 4 | + let types = |
| 5 | + Ext_list.map labeledTypes (fun (lbl, aType) -> |
| 6 | + match lbl with |
| 7 | + | Nolabel -> {aName = ""; aType} |
| 8 | + | Label lbl -> {aName = lbl; aType} |
| 9 | + | OptLabel lbl -> {aName = lbl; aType = Option aType}) |
| 10 | + in |
| 11 | + match types with |
| 12 | + | [{aType}] when aType = unitT -> |
| 13 | + [] (* treat a single argument of type unit as no argument *) |
| 14 | + | _ -> types |
0 commit comments