@@ -24493,6 +24493,10 @@ val as_config_record_and_process :
24493
24493
Location.t ->
24494
24494
t -> action list
24495
24495
24496
+ val ident_or_record_as_config :
24497
+ Location.t ->
24498
+ t -> action list
24499
+
24496
24500
val assert_bool_lit : Parsetree.expression -> bool
24497
24501
24498
24502
val empty : t
@@ -24569,7 +24573,7 @@ let as_core_type loc x =
24569
24573
match x with
24570
24574
| Parsetree.PTyp x -> x
24571
24575
| _ -> Location.raise_errorf ~loc "except a core type"
24572
-
24576
+
24573
24577
let as_ident (x : t ) =
24574
24578
match x with
24575
24579
| PStr [
@@ -24578,7 +24582,7 @@ let as_ident (x : t ) =
24578
24582
{
24579
24583
pexp_desc =
24580
24584
Pexp_ident ident
24581
-
24585
+
24582
24586
} , _)
24583
24587
}
24584
24588
] -> Some ident
@@ -24587,7 +24591,7 @@ open Ast_helper
24587
24591
24588
24592
let raw_string_payload loc (s : string) : t =
24589
24593
PStr [ Str.eval ~loc (Exp.constant ~loc (Const_string (s,None) ))]
24590
-
24594
+
24591
24595
let as_empty_structure (x : t ) =
24592
24596
match x with
24593
24597
| PStr ([]) -> true
@@ -24597,7 +24601,7 @@ type lid = string Asttypes.loc
24597
24601
type label_expr = lid * Parsetree.expression
24598
24602
24599
24603
type action =
24600
- lid * Parsetree.expression option
24604
+ lid * Parsetree.expression option
24601
24605
(** None means punning is hit
24602
24606
{[ { x } ]}
24603
24607
otherwise it comes with a payload
@@ -24607,6 +24611,7 @@ type action =
24607
24611
let as_config_record_and_process
24608
24612
loc
24609
24613
(x : Parsetree.payload)
24614
+ : ( string Location.loc * Parsetree.expression option) list
24610
24615
=
24611
24616
match x with
24612
24617
| PStr
@@ -24616,32 +24621,77 @@ let as_config_record_and_process
24616
24621
}]
24617
24622
->
24618
24623
begin match with_obj with
24619
- | None ->
24620
- List.map
24621
- (fun (x,y) ->
24622
- match (x,y) with
24623
- | ({Asttypes. txt = Longident. Lident name; loc} ) ,
24624
- ({Parsetree.pexp_desc = Pexp_ident{txt = Lident name2}} )
24625
- when name2 = name ->
24626
- ({Asttypes.txt = name ; loc}, None)
24627
- | ({Asttypes. txt = Longident. Lident name; loc} ), y
24628
- ->
24629
- ({Asttypes.txt = name ; loc}, Some y)
24630
- | _ ->
24631
- Location.raise_errorf ~loc "Qualified label is not allood"
24632
- )
24633
- label_exprs
24634
- | Some _ ->
24635
- Location.raise_errorf ~loc "with is not supported"
24624
+ | None ->
24625
+ List.map
24626
+ (fun (( x,y) : (Longident.t Asttypes.loc * _) ) ->
24627
+ match (x,y) with
24628
+ | ({txt = Lident name; loc} ) ,
24629
+ ({Parsetree.pexp_desc = Pexp_ident{txt = Lident name2}} )
24630
+ when name2 = name ->
24631
+ ({Asttypes.txt = name ; loc}, None)
24632
+ | ({txt = Lident name; loc} ), y
24633
+ ->
24634
+ ({Asttypes.txt = name ; loc}, Some y)
24635
+ | _ ->
24636
+ Location.raise_errorf ~loc "Qualified label is not allood"
24637
+ )
24638
+ label_exprs
24639
+ | Some _ ->
24640
+ Location.raise_errorf ~loc "with is not supported"
24636
24641
end
24637
24642
| Parsetree.PStr [] -> []
24638
24643
| _ ->
24639
24644
Location.raise_errorf ~loc "this is not a valid record config"
24640
24645
24646
+ let ident_or_record_as_config
24647
+ loc
24648
+ (x : Parsetree.payload)
24649
+ : ( string Location.loc * Parsetree.expression option) list
24650
+ =
24651
+ match x with
24652
+ | PStr
24653
+ [ {pstr_desc = Pstr_eval
24654
+ ({pexp_desc = Pexp_record (label_exprs, with_obj) ; pexp_loc = loc}, _);
24655
+ _
24656
+ }]
24657
+ ->
24658
+ begin match with_obj with
24659
+ | None ->
24660
+ List.map
24661
+ (fun ((x,y) : (Longident.t Asttypes.loc * _) ) ->
24662
+ match (x,y) with
24663
+ | ({txt = Lident name; loc} ) ,
24664
+ ({Parsetree.pexp_desc = Pexp_ident{txt = Lident name2}} )
24665
+ when name2 = name ->
24666
+ ({Asttypes.txt = name ; loc}, None)
24667
+ | ({txt = Lident name; loc} ), y
24668
+ ->
24669
+ ({Asttypes.txt = name ; loc}, Some y)
24670
+ | _ ->
24671
+ Location.raise_errorf ~loc "Qualified label is not allood"
24672
+ )
24673
+ label_exprs
24674
+ | Some _ ->
24675
+ Location.raise_errorf ~loc "with is not supported"
24676
+ end
24677
+ | PStr [
24678
+ {pstr_desc =
24679
+ Pstr_eval (
24680
+ {
24681
+ pexp_desc =
24682
+ Pexp_ident ({loc = lloc; txt = Lident txt});
24683
+
24684
+ } , _)
24685
+ }
24686
+ ] -> [ {Asttypes.txt ; loc = lloc}, None]
24687
+ | PStr [] -> []
24688
+ | _ ->
24689
+ Location.raise_errorf ~loc "this is not a valid record config"
24690
+
24641
24691
24642
24692
24643
24693
let assert_strings loc (x : t) : string list
24644
- =
24694
+ =
24645
24695
let module M = struct exception Not_str end in
24646
24696
match x with
24647
24697
| PStr [ {pstr_desc =
@@ -24652,7 +24702,7 @@ let assert_strings loc (x : t) : string list
24652
24702
pstr_loc = loc ;
24653
24703
_}] ->
24654
24704
(try
24655
- strs |> List.map (fun e ->
24705
+ strs |> List.map (fun e ->
24656
24706
match (e : Parsetree.expression) with
24657
24707
| {pexp_desc = Pexp_constant (Const_string (name,_)); _} ->
24658
24708
name
@@ -24687,7 +24737,7 @@ let empty : t = Parsetree.PStr []
24687
24737
24688
24738
24689
24739
let table_dispatch table (action : action)
24690
- =
24740
+ =
24691
24741
match action with
24692
24742
| {txt = name; loc }, y ->
24693
24743
begin match String_map.find_exn name table with
@@ -25674,44 +25724,45 @@ let process_method_attributes_rev (attrs : t) =
25674
25724
->
25675
25725
let result =
25676
25726
List.fold_left
25677
- (fun
25678
- (null, undefined)
25679
- (({txt ; loc}, opt_expr) : Ast_payload.action) ->
25680
- if txt = "null" then
25681
- (match opt_expr with
25682
- | None -> true
25683
- | Some e ->
25684
- Ast_payload.assert_bool_lit e), undefined
25685
-
25686
- else if txt = "undefined" then
25687
- null,
25688
- (match opt_expr with
25689
- | None -> true
25690
- | Some e ->
25691
- Ast_payload.assert_bool_lit e)
25692
-
25693
- else Bs_syntaxerr.err loc Unsupported_predicates
25694
- ) (false, false) (Ast_payload.as_config_record_and_process loc payload) in
25727
+ (fun
25728
+ (null, undefined)
25729
+ (({txt ; loc}, opt_expr) : Ast_payload.action) ->
25730
+ if txt = "null" then
25731
+ (match opt_expr with
25732
+ | None -> true
25733
+ | Some e ->
25734
+ Ast_payload.assert_bool_lit e), undefined
25735
+
25736
+ else if txt = "undefined" then
25737
+ null,
25738
+ (match opt_expr with
25739
+ | None -> true
25740
+ | Some e ->
25741
+ Ast_payload.assert_bool_lit e)
25742
+
25743
+ else Bs_syntaxerr.err loc Unsupported_predicates
25744
+ ) (false, false)
25745
+ (Ast_payload.as_config_record_and_process loc payload) in
25695
25746
25696
25747
({st with get = Some result}, acc )
25697
25748
25698
25749
| "bs.set"
25699
25750
->
25700
25751
let result =
25701
25752
List.fold_left
25702
- (fun st (({txt ; loc}, opt_expr) : Ast_payload.action) ->
25703
- if txt = "no_get" then
25704
- match opt_expr with
25705
- | None -> `No_get
25706
- | Some e ->
25707
- if Ast_payload.assert_bool_lit e then
25708
- `No_get
25709
- else `Get
25710
- else Bs_syntaxerr.err loc Unsupported_predicates
25711
- ) `Get (Ast_payload.as_config_record_and_process loc payload) in
25753
+ (fun st (({txt ; loc}, opt_expr) : Ast_payload.action) ->
25754
+ if txt = "no_get" then
25755
+ match opt_expr with
25756
+ | None -> `No_get
25757
+ | Some e ->
25758
+ if Ast_payload.assert_bool_lit e then
25759
+ `No_get
25760
+ else `Get
25761
+ else Bs_syntaxerr.err loc Unsupported_predicates
25762
+ ) `Get (Ast_payload.as_config_record_and_process loc payload) in
25712
25763
(* properties -- void
25713
25764
[@@bs.set{only}]
25714
- *)
25765
+ *)
25715
25766
{st with set = Some result }, acc
25716
25767
| _ ->
25717
25768
(st, attr::acc )
@@ -25777,7 +25828,7 @@ let process_derive_type attrs =
25777
25828
->
25778
25829
{st with
25779
25830
bs_deriving = `Has_deriving
25780
- (Ast_payload.as_config_record_and_process loc payload)}, acc
25831
+ (Ast_payload.ident_or_record_as_config loc payload)}, acc
25781
25832
| {bs_deriving = `Has_deriving _}, "bs.deriving"
25782
25833
->
25783
25834
Bs_syntaxerr.err loc Duplicated_bs_deriving
@@ -25807,10 +25858,10 @@ let process_bs_string_int_unwrap_uncurry attrs =
25807
25858
-> `Unwrap, attrs
25808
25859
| "bs.uncurry", `Nothing
25809
25860
->
25810
- `Uncurry (Ast_payload.is_single_int payload), attrs
25811
- (* Don't allow duplicated [bs.uncurry] since
25812
- it may introduce inconsistency in arity
25813
- *)
25861
+ `Uncurry (Ast_payload.is_single_int payload), attrs
25862
+ (* Don't allow duplicated [bs.uncurry] since
25863
+ it may introduce inconsistency in arity
25864
+ *)
25814
25865
| "bs.int", _
25815
25866
| "bs.string", _
25816
25867
| "bs.ignore", _
@@ -25834,7 +25885,7 @@ let process_bs_string_as attrs =
25834
25885
end
25835
25886
| "bs.as", _
25836
25887
->
25837
- Bs_syntaxerr.err loc Duplicated_bs_as
25888
+ Bs_syntaxerr.err loc Duplicated_bs_as
25838
25889
| _ , _ -> (st, attr::attrs)
25839
25890
) (None, []) attrs
25840
25891
@@ -25866,10 +25917,10 @@ let process_bs_string_or_int_as attrs =
25866
25917
begin match Ast_payload.is_single_int payload with
25867
25918
| None ->
25868
25919
begin match Ast_payload.is_single_string payload with
25869
- | Some (s,None) -> (Some (`Str (s)), attrs)
25870
- | Some (s, Some "json") -> (Some (`Json_str s ), attrs)
25871
- | None | Some (_, Some _) ->
25872
- Bs_syntaxerr.err loc Expect_int_or_string_or_json_literal
25920
+ | Some (s,None) -> (Some (`Str (s)), attrs)
25921
+ | Some (s, Some "json") -> (Some (`Json_str s ), attrs)
25922
+ | None | Some (_, Some _) ->
25923
+ Bs_syntaxerr.err loc Expect_int_or_string_or_json_literal
25873
25924
25874
25925
end
25875
25926
| Some v-> (Some (`Int v), attrs)
0 commit comments